mobx-tanstack-query-api 0.41.1 → 0.42.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/index.cjs CHANGED
@@ -6,11 +6,9 @@ const mobx = require("mobx");
6
6
  const mobxTanstackQuery = require("mobx-tanstack-query");
7
7
  const mobx$1 = require("yummies/mobx");
8
8
  const qs = require("qs");
9
- class EndpointQuery extends mobxTanstackQuery.Query {
9
+ class EndpointInfiniteQuery extends mobxTanstackQuery.InfiniteQuery {
10
10
  /**
11
- * Creates `EndpointQuery` instance.
12
- *
13
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#constructor)
11
+ * Creates `EndpointInfiniteQuery` instance.
14
12
  */
15
13
  constructor(endpoint, inputQueryClient, queryOptionsInput) {
16
14
  const isQueryOptionsInputFn = typeof queryOptionsInput === "function";
@@ -21,6 +19,7 @@ class EndpointQuery extends mobxTanstackQuery.Query {
21
19
  params,
22
20
  onDone: onDoneInput,
23
21
  queryClient: overridedQueryClient,
22
+ mergePageParam,
24
23
  ...queryOptions
25
24
  } = unpackedQueryOptionsInput;
26
25
  const queryClient = overridedQueryClient ?? inputQueryClient;
@@ -28,7 +27,9 @@ class EndpointQuery extends mobxTanstackQuery.Query {
28
27
  params: null,
29
28
  dynamicOptions: void 0,
30
29
  response: null,
31
- uniqKey: unpackedQueryOptionsInput.uniqKey
30
+ uniqKey: unpackedQueryOptionsInput.uniqKey,
31
+ transform: transformResponse,
32
+ mergePageParam
32
33
  };
33
34
  if (!isQueryOptionsInputFn && typeof params !== "function") {
34
35
  if ("params" in unpackedQueryOptionsInput) {
@@ -41,7 +42,9 @@ class EndpointQuery extends mobxTanstackQuery.Query {
41
42
  mobx.makeObservable(_observableData, {
42
43
  params: mobx.observable.ref,
43
44
  response: mobx.observable.ref,
44
- dynamicOptions: mobx.observable
45
+ dynamicOptions: mobx.observable,
46
+ transform: mobx.observable.ref,
47
+ mergePageParam: mobx.observable.ref
45
48
  });
46
49
  const onDone = onDoneInput && ((...args) => {
47
50
  onDoneInput(...args);
@@ -52,7 +55,7 @@ class EndpointQuery extends mobxTanstackQuery.Query {
52
55
  queryClient,
53
56
  meta: endpoint.toQueryMeta(queryOptions.meta),
54
57
  options: () => {
55
- const builtOptions = buildOptionsFromParams(
58
+ const builtOptions = buildInfiniteOptionsFromParams(
56
59
  endpoint,
57
60
  _observableData.params,
58
61
  _observableData.uniqKey
@@ -75,7 +78,13 @@ class EndpointQuery extends mobxTanstackQuery.Query {
75
78
  _observableData.params = params2;
76
79
  }
77
80
  });
78
- let requestParams = params2.requestParams;
81
+ const mergedParams = mergeInfiniteQueryPageParam(
82
+ params2,
83
+ ctx.pageParam ?? queryOptions.initialPageParam,
84
+ ctx,
85
+ _observableData.mergePageParam
86
+ );
87
+ let requestParams = mergedParams.requestParams;
79
88
  if (requestParams) {
80
89
  if (!requestParams.signal) {
81
90
  requestParams.signal = ctx.signal;
@@ -84,14 +93,14 @@ class EndpointQuery extends mobxTanstackQuery.Query {
84
93
  requestParams = { signal: ctx.signal };
85
94
  }
86
95
  const fixedInput = {
87
- ...params2,
96
+ ...mergedParams,
88
97
  requestParams
89
98
  };
90
99
  const response = await endpoint.request(fixedInput);
91
100
  mobx.runInAction(() => {
92
101
  _observableData.response = response;
93
102
  });
94
- return await transformResponse?.(response) ?? response.data;
103
+ return await _observableData.transform?.(response) ?? response.data;
95
104
  }
96
105
  });
97
106
  this.endpoint = endpoint;
@@ -104,6 +113,8 @@ class EndpointQuery extends mobxTanstackQuery.Query {
104
113
  () => {
105
114
  let outDynamicOptions;
106
115
  let outParams;
116
+ let outTransform;
117
+ let outMergePageParam;
107
118
  let uniqKey2;
108
119
  if (isQueryOptionsInputFn) {
109
120
  const result = queryOptionsInput();
@@ -116,9 +127,14 @@ class EndpointQuery extends mobxTanstackQuery.Query {
116
127
  onInit,
117
128
  enableOnDemand,
118
129
  uniqKey: _uniqKey,
130
+ transform,
131
+ mergePageParam: mergePageParam2,
132
+ queryClient: queryClient2,
119
133
  ...dynamicOptions
120
134
  } = result;
121
135
  uniqKey2 = _uniqKey;
136
+ outTransform = transform;
137
+ outMergePageParam = mergePageParam2;
122
138
  if ("params" in result) {
123
139
  outParams = result.params;
124
140
  } else {
@@ -128,22 +144,30 @@ class EndpointQuery extends mobxTanstackQuery.Query {
128
144
  } else if ("params" in unpackedQueryOptionsInput) {
129
145
  outParams = unpackedQueryOptionsInput.params;
130
146
  uniqKey2 = unpackedQueryOptionsInput.uniqKey;
147
+ outTransform = unpackedQueryOptionsInput.transform;
148
+ outMergePageParam = unpackedQueryOptionsInput.mergePageParam;
131
149
  } else {
132
150
  outParams = {};
133
151
  uniqKey2 = unpackedQueryOptionsInput.uniqKey;
152
+ outTransform = unpackedQueryOptionsInput.transform;
153
+ outMergePageParam = unpackedQueryOptionsInput.mergePageParam;
134
154
  }
135
155
  return {
136
156
  params: common.callFunction(outParams),
137
157
  dynamicOptions: outDynamicOptions,
138
- uniqKey: uniqKey2
158
+ uniqKey: uniqKey2,
159
+ transform: outTransform,
160
+ mergePageParam: outMergePageParam
139
161
  };
140
162
  },
141
- ({ params: params2, dynamicOptions, uniqKey: uniqKey2 }) => {
163
+ ({ params: params2, dynamicOptions, uniqKey: uniqKey2, transform, mergePageParam: mergePageParam2 }) => {
142
164
  mobx.runInAction(() => {
143
165
  _observableData.initialized = true;
144
166
  _observableData.params = params2;
145
167
  _observableData.dynamicOptions = dynamicOptions;
146
168
  _observableData.uniqKey = uniqKey2;
169
+ _observableData.transform = transform;
170
+ _observableData.mergePageParam = mergePageParam2;
147
171
  });
148
172
  },
149
173
  {
@@ -167,75 +191,59 @@ class EndpointQuery extends mobxTanstackQuery.Query {
167
191
  }
168
192
  _observableData;
169
193
  /**
170
- * Current endpoint params used by this query.
171
- *
172
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#params)
194
+ * Current base endpoint params used for `queryKey`.
173
195
  */
174
196
  get params() {
175
197
  return this._observableData.params;
176
198
  }
177
199
  /**
178
200
  * Last raw HTTP response returned by endpoint.
179
- *
180
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#response)
181
201
  */
182
202
  get response() {
183
203
  return this._observableData.response;
184
204
  }
185
205
  /**
186
- * Updates query options and optionally params.
187
- *
188
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#update)
206
+ * Updates query options and optionally base params.
189
207
  */
190
208
  update(updateParams) {
191
209
  if ("params" in updateParams) {
192
210
  const { params, ...options } = updateParams;
193
- mobx.runInAction(() => {
194
- this._observableData.params = params;
195
- });
196
- return super.update({
197
- ...buildOptionsFromParams(
198
- this.endpoint,
199
- params,
200
- this._observableData.uniqKey
201
- ),
202
- ...options
203
- });
204
- } else if (this._observableData) {
211
+ if (this._observableData) {
212
+ mobx.runInAction(() => {
213
+ this._observableData.params = params;
214
+ });
215
+ return super.update({
216
+ ...buildInfiniteOptionsFromParams(
217
+ this.endpoint,
218
+ params,
219
+ this._observableData.uniqKey
220
+ ),
221
+ ...options
222
+ });
223
+ }
224
+ return super.update(options);
225
+ }
226
+ if (this._observableData) {
205
227
  return super.update({
206
- ...buildOptionsFromParams(
228
+ ...buildInfiniteOptionsFromParams(
207
229
  this.endpoint,
208
230
  this._observableData.params,
209
231
  this._observableData.uniqKey
210
232
  ),
211
233
  ...updateParams
212
234
  });
213
- } else {
214
- return super.update(updateParams);
215
- }
216
- }
217
- /**
218
- * Refetches query when params are initialized.
219
- *
220
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#refetch)
221
- */
222
- refetch(options) {
223
- if (this.params) {
224
- return super.refetch(options);
225
235
  }
226
- return Promise.resolve(this.queryObserver.getCurrentResult());
236
+ return super.update(updateParams);
227
237
  }
228
238
  /**
229
- * Sets params and starts query execution.
230
- *
231
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#start)
239
+ * Sets base params and starts the infinite query execution.
232
240
  */
233
241
  async start(params) {
234
242
  mobx.runInAction(() => {
235
243
  this._observableData.params = params;
236
244
  });
237
245
  return await super.start(
238
- buildOptionsFromParams(
246
+ buildInfiniteOptionsFromParams(
239
247
  this.endpoint,
240
248
  params,
241
249
  this._observableData.uniqKey
@@ -247,13 +255,60 @@ class EndpointQuery extends mobxTanstackQuery.Query {
247
255
  mobx.runInAction(() => {
248
256
  this._observableData.params = void 0;
249
257
  this._observableData.dynamicOptions = void 0;
258
+ this._observableData.transform = void 0;
259
+ this._observableData.mergePageParam = void 0;
250
260
  });
251
261
  }
252
262
  }
253
- const getParamsFromContext = (ctx) => {
254
- return ctx.queryKey.at(-2) || {};
255
- };
256
- const buildOptionsFromParams = (endpoint, params, uniqKey) => {
263
+ function ensureObjectPageParam(pageParam, mergePageParam) {
264
+ if (typeof pageParam === "object" && pageParam !== null && !Array.isArray(pageParam)) {
265
+ return pageParam;
266
+ }
267
+ throw new Error(
268
+ `[mobx-tanstack-query-api] "${mergePageParam}" mergePageParam expects an object pageParam. Use a custom mergePageParam function for primitive page params.`
269
+ );
270
+ }
271
+ function mergeInfiniteQueryPageParam(params, pageParam, ctx, mergePageParam) {
272
+ if (pageParam == null || !mergePageParam) {
273
+ return params;
274
+ }
275
+ if (typeof mergePageParam === "function") {
276
+ return mergePageParam(params, pageParam, ctx) || {};
277
+ }
278
+ const objectPageParam = ensureObjectPageParam(pageParam, mergePageParam);
279
+ switch (mergePageParam) {
280
+ case "params":
281
+ return {
282
+ ...params,
283
+ ...objectPageParam
284
+ };
285
+ case "body":
286
+ return {
287
+ ...params,
288
+ body: {
289
+ ...params.body,
290
+ ...objectPageParam
291
+ }
292
+ };
293
+ case "query":
294
+ return {
295
+ ...params,
296
+ query: {
297
+ ...params.query,
298
+ ...objectPageParam
299
+ }
300
+ };
301
+ case "headers":
302
+ return {
303
+ ...params,
304
+ headers: {
305
+ ...params.headers,
306
+ ...objectPageParam
307
+ }
308
+ };
309
+ }
310
+ }
311
+ const buildInfiniteOptionsFromParams = (endpoint, params, uniqKey) => {
257
312
  const { requiredParams } = endpoint.configuration;
258
313
  let hasRequiredParams = false;
259
314
  if (requiredParams.length > 0) {
@@ -263,99 +318,9 @@ const buildOptionsFromParams = (endpoint, params, uniqKey) => {
263
318
  }
264
319
  return {
265
320
  enabled: hasRequiredParams,
266
- queryKey: endpoint.toQueryKey(params || {}, uniqKey)
321
+ queryKey: endpoint.toInfiniteQueryKey(params || {}, uniqKey)
267
322
  };
268
323
  };
269
- class EndpointInfiniteQuery extends mobxTanstackQuery.InfiniteQuery {
270
- constructor(endpoint, queryClient, queryOptionsInput) {
271
- const {
272
- uniqKey,
273
- transform: transformResponse,
274
- params: paramsFn,
275
- ...queryOptions
276
- } = typeof queryOptionsInput === "function" ? queryOptionsInput() : queryOptionsInput;
277
- super({
278
- ...queryOptions,
279
- queryClient,
280
- meta: endpoint.toQueryMeta(queryOptions.meta),
281
- options: (query) => {
282
- const extraOptions = {};
283
- let willEnableManually;
284
- let params;
285
- const pageParam = query.options.initialPageParam;
286
- if (typeof queryOptionsInput === "function") {
287
- Object.assign(extraOptions, queryOptionsInput());
288
- params = paramsFn(pageParam);
289
- willEnableManually = false;
290
- } else {
291
- willEnableManually = queryOptionsInput.enabled === false;
292
- params = paramsFn(pageParam);
293
- }
294
- const builtOptions = buildOptionsFromParams(endpoint, params, uniqKey);
295
- let isEnabled = false;
296
- if (willEnableManually) ;
297
- else {
298
- isEnabled = builtOptions.enabled;
299
- }
300
- return {
301
- ...query.options,
302
- ...builtOptions,
303
- // ...dynamicOuterOptions,
304
- enabled: isEnabled,
305
- ...extraOptions
306
- };
307
- },
308
- queryFn: async (ctx) => {
309
- const params = paramsFn(
310
- ctx.pageParam ?? queryOptions.initialPageParam
311
- );
312
- mobx.runInAction(() => {
313
- this.response = null;
314
- this.params = params;
315
- });
316
- let requestParams = params.request;
317
- if (requestParams) {
318
- if (!requestParams.signal) {
319
- requestParams.signal = ctx.signal;
320
- }
321
- } else {
322
- requestParams = { signal: ctx.signal };
323
- }
324
- const fixedInput = {
325
- ...params,
326
- request: requestParams
327
- };
328
- const response = await endpoint.request(fixedInput);
329
- mobx.runInAction(() => {
330
- this.response = response;
331
- });
332
- return await transformResponse?.(response) ?? response.data;
333
- }
334
- });
335
- this.endpoint = endpoint;
336
- this.uniqKey = uniqKey;
337
- mobx.observable.ref(this, "response");
338
- mobx.observable.ref(this, "params");
339
- mobx.makeObservable(this);
340
- }
341
- response = null;
342
- params = null;
343
- uniqKey;
344
- update({
345
- params,
346
- ...options
347
- }) {
348
- return super.update({
349
- ...buildOptionsFromParams(this.endpoint, params, this.uniqKey),
350
- ...options
351
- });
352
- }
353
- async start(params) {
354
- return await super.start(
355
- buildOptionsFromParams(this.endpoint, params, this.uniqKey)
356
- );
357
- }
358
- }
359
324
  class EndpointMutation extends mobxTanstackQuery.Mutation {
360
325
  /**
361
326
  * Creates `EndpointMutation` instance.
@@ -426,6 +391,266 @@ class EndpointMutation extends mobxTanstackQuery.Mutation {
426
391
  });
427
392
  }
428
393
  }
394
+ class EndpointQuery extends mobxTanstackQuery.Query {
395
+ /**
396
+ * Creates `EndpointQuery` instance.
397
+ *
398
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#constructor)
399
+ */
400
+ constructor(endpoint, inputQueryClient, queryOptionsInput) {
401
+ const isQueryOptionsInputFn = typeof queryOptionsInput === "function";
402
+ const unpackedQueryOptionsInput = isQueryOptionsInputFn ? queryOptionsInput() : queryOptionsInput;
403
+ const {
404
+ uniqKey,
405
+ transform: transformResponse,
406
+ params,
407
+ onDone: onDoneInput,
408
+ queryClient: overridedQueryClient,
409
+ ...queryOptions
410
+ } = unpackedQueryOptionsInput;
411
+ const queryClient = overridedQueryClient ?? inputQueryClient;
412
+ const _observableData = {
413
+ params: null,
414
+ dynamicOptions: void 0,
415
+ response: null,
416
+ uniqKey: unpackedQueryOptionsInput.uniqKey
417
+ };
418
+ if (!isQueryOptionsInputFn && typeof params !== "function") {
419
+ if ("params" in unpackedQueryOptionsInput) {
420
+ _observableData.params = params;
421
+ } else {
422
+ _observableData.params = {};
423
+ }
424
+ _observableData.initialized = true;
425
+ }
426
+ mobx.makeObservable(_observableData, {
427
+ params: mobx.observable.ref,
428
+ response: mobx.observable.ref,
429
+ dynamicOptions: mobx.observable
430
+ });
431
+ const onDone = onDoneInput && ((...args) => {
432
+ onDoneInput(...args);
433
+ });
434
+ super({
435
+ ...queryOptions,
436
+ onDone,
437
+ queryClient,
438
+ meta: endpoint.toQueryMeta(queryOptions.meta),
439
+ options: () => {
440
+ const builtOptions = buildOptionsFromParams(
441
+ endpoint,
442
+ _observableData.params,
443
+ _observableData.uniqKey
444
+ );
445
+ let isEnabled = !!_observableData.initialized && builtOptions.enabled;
446
+ if (typeof queryOptionsInput !== "function" && queryOptionsInput.enabled === false) {
447
+ isEnabled = false;
448
+ }
449
+ return {
450
+ ...builtOptions,
451
+ enabled: isEnabled,
452
+ ..._observableData.dynamicOptions
453
+ };
454
+ },
455
+ queryFn: async (ctx) => {
456
+ const params2 = endpoint.getParamsFromContext(ctx);
457
+ mobx.runInAction(() => {
458
+ _observableData.response = null;
459
+ if (!mobx.comparer.structural(params2, _observableData.params)) {
460
+ _observableData.params = params2;
461
+ }
462
+ });
463
+ let requestParams = params2.requestParams;
464
+ if (requestParams) {
465
+ if (!requestParams.signal) {
466
+ requestParams.signal = ctx.signal;
467
+ }
468
+ } else {
469
+ requestParams = { signal: ctx.signal };
470
+ }
471
+ const fixedInput = {
472
+ ...params2,
473
+ requestParams
474
+ };
475
+ const response = await endpoint.request(fixedInput);
476
+ mobx.runInAction(() => {
477
+ _observableData.response = response;
478
+ });
479
+ return await transformResponse?.(response) ?? response.data;
480
+ }
481
+ });
482
+ this.endpoint = endpoint;
483
+ const parentAtom = mobx$1.getMobxAdministration(this);
484
+ mobx.computed.struct(this, "params");
485
+ mobx.computed.struct(this, "response");
486
+ mobx.makeObservable(this);
487
+ if (isQueryOptionsInputFn || typeof params === "function") {
488
+ const createParamsReaction = () => mobx.reaction(
489
+ () => {
490
+ let outDynamicOptions;
491
+ let outParams;
492
+ let uniqKey2;
493
+ if (isQueryOptionsInputFn) {
494
+ const result = queryOptionsInput();
495
+ const {
496
+ params: params2,
497
+ abortSignal,
498
+ select,
499
+ onDone: onDone2,
500
+ onError,
501
+ onInit,
502
+ enableOnDemand,
503
+ uniqKey: _uniqKey,
504
+ ...dynamicOptions
505
+ } = result;
506
+ uniqKey2 = _uniqKey;
507
+ if ("params" in result) {
508
+ outParams = result.params;
509
+ } else {
510
+ outParams = {};
511
+ }
512
+ outDynamicOptions = Object.keys(dynamicOptions).length > 0 ? dynamicOptions : void 0;
513
+ } else if ("params" in unpackedQueryOptionsInput) {
514
+ outParams = unpackedQueryOptionsInput.params;
515
+ uniqKey2 = unpackedQueryOptionsInput.uniqKey;
516
+ } else {
517
+ outParams = {};
518
+ uniqKey2 = unpackedQueryOptionsInput.uniqKey;
519
+ }
520
+ return {
521
+ params: common.callFunction(outParams),
522
+ dynamicOptions: outDynamicOptions,
523
+ uniqKey: uniqKey2
524
+ };
525
+ },
526
+ ({ params: params2, dynamicOptions, uniqKey: uniqKey2 }) => {
527
+ mobx.runInAction(() => {
528
+ _observableData.initialized = true;
529
+ _observableData.params = params2;
530
+ _observableData.dynamicOptions = dynamicOptions;
531
+ _observableData.uniqKey = uniqKey2;
532
+ });
533
+ },
534
+ {
535
+ fireImmediately: true
536
+ }
537
+ );
538
+ if (this.features.lazy) {
539
+ mobx$1.lazyObserve({
540
+ property: parentAtom.values_.get("_result"),
541
+ onStart: createParamsReaction,
542
+ onEnd: (disposeFn) => disposeFn()
543
+ });
544
+ } else {
545
+ this.abortController.signal.addEventListener(
546
+ "abort",
547
+ createParamsReaction()
548
+ );
549
+ }
550
+ }
551
+ this._observableData = _observableData;
552
+ }
553
+ _observableData;
554
+ /**
555
+ * Current endpoint params used by this query.
556
+ *
557
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#params)
558
+ */
559
+ get params() {
560
+ return this._observableData.params;
561
+ }
562
+ /**
563
+ * Last raw HTTP response returned by endpoint.
564
+ *
565
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#response)
566
+ */
567
+ get response() {
568
+ return this._observableData.response;
569
+ }
570
+ /**
571
+ * Updates query options and optionally params.
572
+ *
573
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#update)
574
+ */
575
+ update(updateParams) {
576
+ if ("params" in updateParams) {
577
+ const { params, ...options } = updateParams;
578
+ mobx.runInAction(() => {
579
+ this._observableData.params = params;
580
+ });
581
+ return super.update({
582
+ ...buildOptionsFromParams(
583
+ this.endpoint,
584
+ params,
585
+ this._observableData.uniqKey
586
+ ),
587
+ ...options
588
+ });
589
+ } else if (this._observableData) {
590
+ return super.update({
591
+ ...buildOptionsFromParams(
592
+ this.endpoint,
593
+ this._observableData.params,
594
+ this._observableData.uniqKey
595
+ ),
596
+ ...updateParams
597
+ });
598
+ } else {
599
+ return super.update(updateParams);
600
+ }
601
+ }
602
+ /**
603
+ * Refetches query when params are initialized.
604
+ *
605
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#refetch)
606
+ */
607
+ refetch(options) {
608
+ if (this.params) {
609
+ return super.refetch(options);
610
+ }
611
+ return Promise.resolve(this.queryObserver.getCurrentResult());
612
+ }
613
+ /**
614
+ * Sets params and starts query execution.
615
+ *
616
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/#start)
617
+ */
618
+ async start(params) {
619
+ mobx.runInAction(() => {
620
+ this._observableData.params = params;
621
+ });
622
+ return await super.start(
623
+ buildOptionsFromParams(
624
+ this.endpoint,
625
+ params,
626
+ this._observableData.uniqKey
627
+ )
628
+ );
629
+ }
630
+ handleDestroy() {
631
+ super.handleDestroy();
632
+ mobx.runInAction(() => {
633
+ this._observableData.params = void 0;
634
+ this._observableData.dynamicOptions = void 0;
635
+ });
636
+ }
637
+ }
638
+ const getParamsFromContext = (ctx) => {
639
+ return ctx.queryKey.at(-2) || {};
640
+ };
641
+ const buildOptionsFromParams = (endpoint, params, uniqKey) => {
642
+ const { requiredParams } = endpoint.configuration;
643
+ let hasRequiredParams = false;
644
+ if (requiredParams.length > 0) {
645
+ hasRequiredParams = !!params && requiredParams.every((param) => param in params);
646
+ } else {
647
+ hasRequiredParams = !!params;
648
+ }
649
+ return {
650
+ enabled: hasRequiredParams,
651
+ queryKey: endpoint.toQueryKey(params || {}, uniqKey)
652
+ };
653
+ };
429
654
  const emptyStatusCodesSet = /* @__PURE__ */ new Set([204, 205, 304]);
430
655
  class HttpResponse {
431
656
  constructor(originalResponse, request) {
@@ -489,6 +714,65 @@ function isContractOptionEnabled(option, key) {
489
714
  return option === true || typeof option === "object" && option !== null && option[key] === true;
490
715
  }
491
716
  class Endpoint {
717
+ /**
718
+ * Unique runtime identifier of the endpoint instance.
719
+ *
720
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#endpointid)
721
+ */
722
+ endpointId;
723
+ /**
724
+ * Mutable presets used by helper factory methods like `toMutation()`.
725
+ *
726
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#presets)
727
+ */
728
+ presets = {
729
+ mutations: {}
730
+ };
731
+ /**
732
+ * Type-only helper that exposes endpoint params shape.
733
+ *
734
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#__params)
735
+ */
736
+ __params;
737
+ /**
738
+ * Type-only helper that exposes endpoint response shape.
739
+ *
740
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#__response)
741
+ */
742
+ __response;
743
+ /**
744
+ * Custom metadata attached to the endpoint configuration.
745
+ *
746
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#meta)
747
+ */
748
+ meta;
749
+ /**
750
+ * Endpoint configuration generated from the contract/codegen layer.
751
+ *
752
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#configuration)
753
+ */
754
+ configuration;
755
+ /**
756
+ * Query client used by query and mutation helpers.
757
+ *
758
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#queryclient)
759
+ */
760
+ queryClient;
761
+ /**
762
+ * HTTP client used to build URLs and execute requests.
763
+ *
764
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#httpclient)
765
+ */
766
+ httpClient;
767
+ validateParams = false;
768
+ validateData = false;
769
+ throwParams = false;
770
+ throwData = false;
771
+ /**
772
+ * Creates a callable `Endpoint` instance.
773
+ *
774
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#constructor)
775
+ */
492
776
  constructor(configuration, queryClient, httpClient) {
493
777
  this.configuration = configuration;
494
778
  this.queryClient = queryClient;
@@ -513,43 +797,77 @@ class Endpoint {
513
797
  });
514
798
  return callable;
515
799
  }
516
- endpointId;
517
- presets = {
518
- mutations: {}
519
- };
520
- __params;
521
- __response;
522
- meta;
523
- validateParams = false;
524
- validateData = false;
525
- throwParams = false;
526
- throwData = false;
800
+ /**
801
+ * Returns a fully resolved request URL for the provided params.
802
+ *
803
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#getfullurl)
804
+ */
527
805
  getFullUrl(...args) {
528
806
  const params = this.configuration.params(args[0] ?? {});
529
807
  return this.httpClient.buildUrl(params);
530
808
  }
809
+ /**
810
+ * Returns the resolved request path without the base URL.
811
+ *
812
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#getpath)
813
+ */
531
814
  getPath(...args) {
532
815
  const params = this.configuration.params(args[0] ?? {});
533
816
  return params.path;
534
817
  }
818
+ /**
819
+ * Extracts endpoint params from TanStack Query function context.
820
+ *
821
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#getparamsfromcontext)
822
+ */
535
823
  getParamsFromContext(ctx) {
536
824
  return ctx.queryKey.at(-2) || {};
537
825
  }
826
+ /**
827
+ * Tags declared for the endpoint.
828
+ *
829
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#tags)
830
+ */
538
831
  get tags() {
539
832
  return this.configuration.tags;
540
833
  }
834
+ /**
835
+ * Path segments declared for the endpoint.
836
+ *
837
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#path)
838
+ */
541
839
  get path() {
542
840
  return this.configuration.path;
543
841
  }
842
+ /**
843
+ * Slash-joined path declaration for the endpoint.
844
+ *
845
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#pathdeclaration)
846
+ */
544
847
  get pathDeclaration() {
545
848
  return this.path.join("/");
546
849
  }
850
+ /**
851
+ * Operation identifier from the endpoint configuration.
852
+ *
853
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#operationid)
854
+ */
547
855
  get operationId() {
548
856
  return this.configuration.operationId;
549
857
  }
858
+ /**
859
+ * Optional endpoint group.
860
+ *
861
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#group)
862
+ */
550
863
  get group() {
551
864
  return this.configuration.group;
552
865
  }
866
+ /**
867
+ * Optional endpoint namespace.
868
+ *
869
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#namespace)
870
+ */
553
871
  get namespace() {
554
872
  return this.configuration.namespace;
555
873
  }
@@ -588,6 +906,11 @@ class Endpoint {
588
906
  }
589
907
  }
590
908
  }
909
+ /**
910
+ * Performs the HTTP request and optionally validates contracts.
911
+ *
912
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#request)
913
+ */
591
914
  async request(...args) {
592
915
  const rawParams = args[0] ?? {};
593
916
  const contract = this.configuration.contract;
@@ -614,6 +937,11 @@ class Endpoint {
614
937
  }
615
938
  return response;
616
939
  }
940
+ /**
941
+ * Builds query metadata payload enriched with endpoint fields.
942
+ *
943
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#toquerymeta)
944
+ */
617
945
  toQueryMeta = (meta) => ({
618
946
  ...meta,
619
947
  tags: this.tags,
@@ -623,6 +951,11 @@ class Endpoint {
623
951
  endpointId: this.endpointId,
624
952
  endpointQuery: true
625
953
  });
954
+ /**
955
+ * Builds a stable TanStack Query key for a regular query.
956
+ *
957
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#toquerykey)
958
+ */
626
959
  toQueryKey(params, uniqKey) {
627
960
  return [
628
961
  ...this.configuration.path,
@@ -631,6 +964,11 @@ class Endpoint {
631
964
  common.callFunction(uniqKey)
632
965
  ];
633
966
  }
967
+ /**
968
+ * Builds a stable TanStack Query key for an infinite query.
969
+ *
970
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#toinfinitequerykey)
971
+ */
634
972
  toInfiniteQueryKey(params, uniqKey) {
635
973
  return [
636
974
  { infiniteQuery: true },
@@ -640,6 +978,11 @@ class Endpoint {
640
978
  common.callFunction(uniqKey)
641
979
  ];
642
980
  }
981
+ /**
982
+ * Invalidates the exact query produced by this endpoint.
983
+ *
984
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#invalidatequery)
985
+ */
643
986
  invalidateQuery(...args) {
644
987
  this.queryClient.invalidateQueries(
645
988
  {
@@ -650,6 +993,11 @@ class Endpoint {
650
993
  args[2]
651
994
  );
652
995
  }
996
+ /**
997
+ * Creates an `EndpointMutation` bound to this endpoint.
998
+ *
999
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#tomutation)
1000
+ */
653
1001
  toMutation(options) {
654
1002
  return new EndpointMutation(
655
1003
  this,
@@ -660,6 +1008,11 @@ class Endpoint {
660
1008
  }
661
1009
  );
662
1010
  }
1011
+ /**
1012
+ * Creates an `EndpointQuery` bound to this endpoint.
1013
+ *
1014
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#toquery)
1015
+ */
663
1016
  toQuery(options) {
664
1017
  return new EndpointQuery(
665
1018
  this,
@@ -667,12 +1020,13 @@ class Endpoint {
667
1020
  options
668
1021
  );
669
1022
  }
1023
+ /**
1024
+ * Creates an `EndpointInfiniteQuery` bound to this endpoint.
1025
+ *
1026
+ * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/#toinfinitequery)
1027
+ */
670
1028
  toInfiniteQuery(options) {
671
- return new EndpointInfiniteQuery(
672
- this,
673
- this.queryClient,
674
- options
675
- );
1029
+ return new EndpointInfiniteQuery(this, this.queryClient, options);
676
1030
  }
677
1031
  }
678
1032
  class EndpointQueryClient extends mobxTanstackQuery.QueryClient {
@@ -933,16 +1287,19 @@ class HttpClient {
933
1287
  }
934
1288
  exports.ContentType = ContentType;
935
1289
  exports.Endpoint = Endpoint;
1290
+ exports.EndpointInfiniteQuery = EndpointInfiniteQuery;
936
1291
  exports.EndpointMutation = EndpointMutation;
937
1292
  exports.EndpointQuery = EndpointQuery;
938
1293
  exports.EndpointQueryClient = EndpointQueryClient;
939
1294
  exports.HttpClient = HttpClient;
940
1295
  exports.HttpResponse = HttpResponse;
1296
+ exports.buildInfiniteOptionsFromParams = buildInfiniteOptionsFromParams;
941
1297
  exports.buildOptionsFromParams = buildOptionsFromParams;
942
1298
  exports.emptyStatusCodesSet = emptyStatusCodesSet;
943
1299
  exports.getParamsFromContext = getParamsFromContext;
944
1300
  exports.isHttpBadResponse = isHttpBadResponse;
945
1301
  exports.isHttpResponse = isHttpResponse;
1302
+ exports.mergeInfiniteQueryPageParam = mergeInfiniteQueryPageParam;
946
1303
  Object.keys(queryCore).forEach((k) => {
947
1304
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
948
1305
  enumerable: true,