@orchestrator-ui/orchestrator-ui-components 5.8.1 → 5.9.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.js CHANGED
@@ -26801,7 +26801,7 @@ var PolicyResource = /* @__PURE__ */ ((PolicyResource2) => {
26801
26801
  })(PolicyResource || {});
26802
26802
 
26803
26803
  // src/configuration/version.ts
26804
- var ORCHESTRATOR_UI_LIBRARY_VERSION = "5.8.1";
26804
+ var ORCHESTRATOR_UI_LIBRARY_VERSION = "5.9.0";
26805
26805
 
26806
26806
  // src/types/types.ts
26807
26807
  var EngineStatus = /* @__PURE__ */ ((EngineStatus3) => {
@@ -29066,6 +29066,21 @@ function executeReducerBuilderCallback(builderCallback) {
29066
29066
  actionsMap[type] = reducer;
29067
29067
  return builder;
29068
29068
  },
29069
+ addAsyncThunk(asyncThunk, reducers) {
29070
+ if (process.env.NODE_ENV !== "production") {
29071
+ if (defaultCaseReducer) {
29072
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage2(43) : "`builder.addAsyncThunk` should only be called before calling `builder.addDefaultCase`");
29073
+ }
29074
+ }
29075
+ if (reducers.pending) actionsMap[asyncThunk.pending.type] = reducers.pending;
29076
+ if (reducers.rejected) actionsMap[asyncThunk.rejected.type] = reducers.rejected;
29077
+ if (reducers.fulfilled) actionsMap[asyncThunk.fulfilled.type] = reducers.fulfilled;
29078
+ if (reducers.settled) actionMatchers.push({
29079
+ matcher: asyncThunk.settled,
29080
+ reducer: reducers.settled
29081
+ });
29082
+ return builder;
29083
+ },
29069
29084
  addMatcher(matcher, reducer) {
29070
29085
  if (process.env.NODE_ENV !== "production") {
29071
29086
  if (defaultCaseReducer) {
@@ -29817,6 +29832,11 @@ function getOrInsert(map, key, value) {
29817
29832
  if (map.has(key)) return map.get(key);
29818
29833
  return map.set(key, value).get(key);
29819
29834
  }
29835
+ function getOrInsertComputed2(map, key, compute) {
29836
+ if (map.has(key)) return map.get(key);
29837
+ return map.set(key, compute(key)).get(key);
29838
+ }
29839
+ var createNewMap = () => /* @__PURE__ */ new Map();
29820
29840
  var defaultFetchFn = (...args) => fetch(...args);
29821
29841
  var defaultValidateStatus = (response) => response.status >= 200 && response.status <= 299;
29822
29842
  var defaultIsJsonContentType = (headers) => (
@@ -30028,10 +30048,13 @@ function buildInitiate({
30028
30048
  infiniteQueryThunk,
30029
30049
  mutationThunk,
30030
30050
  api,
30031
- context
30051
+ context,
30052
+ internalState
30032
30053
  }) {
30033
- const runningQueries = /* @__PURE__ */ new Map();
30034
- const runningMutations = /* @__PURE__ */ new Map();
30054
+ const {
30055
+ runningQueries,
30056
+ runningMutations
30057
+ } = internalState;
30035
30058
  const {
30036
30059
  unsubscribeQueryResult,
30037
30060
  removeMutationResult,
@@ -30266,6 +30289,7 @@ var NamedSchemaError = class extends SchemaError {
30266
30289
  this._bqMeta = _bqMeta;
30267
30290
  }
30268
30291
  };
30292
+ var shouldSkip = (skipSchemaValidation, schemaName) => Array.isArray(skipSchemaValidation) ? skipSchemaValidation.includes(schemaName) : !!skipSchemaValidation;
30269
30293
  async function parseWithSchema(schema, data, schemaName, bqMeta) {
30270
30294
  const result = await schema["~standard"].validate(data);
30271
30295
  if (result.issues) {
@@ -30397,7 +30421,7 @@ function buildThunks({
30397
30421
  skipSchemaValidation = globalSkipSchemaValidation
30398
30422
  } = endpointDefinition;
30399
30423
  try {
30400
- let transformResponse = getTransformCallbackForEndpoint(endpointDefinition, "transformResponse");
30424
+ let transformResponse = defaultTransformResponse;
30401
30425
  const baseQueryApi = {
30402
30426
  signal,
30403
30427
  abort,
@@ -30439,7 +30463,7 @@ function buildThunks({
30439
30463
  rawResponseSchema,
30440
30464
  responseSchema
30441
30465
  } = endpointDefinition;
30442
- if (argSchema && !skipSchemaValidation) {
30466
+ if (argSchema && !shouldSkip(skipSchemaValidation, "arg")) {
30443
30467
  finalQueryArg = await parseWithSchema(
30444
30468
  argSchema,
30445
30469
  finalQueryArg,
@@ -30451,6 +30475,7 @@ function buildThunks({
30451
30475
  if (forceQueryFn) {
30452
30476
  result = forceQueryFn();
30453
30477
  } else if (endpointDefinition.query) {
30478
+ transformResponse = getTransformCallbackForEndpoint(endpointDefinition, "transformResponse");
30454
30479
  result = await baseQuery(endpointDefinition.query(finalQueryArg), baseQueryApi, extraOptions);
30455
30480
  } else {
30456
30481
  result = await endpointDefinition.queryFn(finalQueryArg, baseQueryApi, extraOptions, (arg2) => baseQuery(arg2, baseQueryApi, extraOptions));
@@ -30485,11 +30510,11 @@ function buildThunks({
30485
30510
  let {
30486
30511
  data
30487
30512
  } = result;
30488
- if (rawResponseSchema && !skipSchemaValidation) {
30513
+ if (rawResponseSchema && !shouldSkip(skipSchemaValidation, "rawResponse")) {
30489
30514
  data = await parseWithSchema(rawResponseSchema, result.data, "rawResponseSchema", result.meta);
30490
30515
  }
30491
30516
  let transformedResponse = await transformResponse(data, result.meta, finalQueryArg);
30492
- if (responseSchema && !skipSchemaValidation) {
30517
+ if (responseSchema && !shouldSkip(skipSchemaValidation, "response")) {
30493
30518
  transformedResponse = await parseWithSchema(responseSchema, transformedResponse, "responseSchema", result.meta);
30494
30519
  }
30495
30520
  return {
@@ -30518,7 +30543,7 @@ function buildThunks({
30518
30543
  if ("direction" in arg && arg.direction && existingData.pages.length) {
30519
30544
  const previous = arg.direction === "backward";
30520
30545
  const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
30521
- const param = pageParamFn(infiniteQueryOptions, existingData);
30546
+ const param = pageParamFn(infiniteQueryOptions, existingData, arg.originalArgs);
30522
30547
  result = await fetchPage(existingData, param, maxPages, previous);
30523
30548
  } else {
30524
30549
  const {
@@ -30534,7 +30559,7 @@ function buildThunks({
30534
30559
  };
30535
30560
  }
30536
30561
  for (let i = 1; i < totalPages; i++) {
30537
- const param = getNextPageParam(infiniteQueryOptions, result.data);
30562
+ const param = getNextPageParam(infiniteQueryOptions, result.data, arg.originalArgs);
30538
30563
  result = await fetchPage(result.data, param, maxPages);
30539
30564
  }
30540
30565
  }
@@ -30542,7 +30567,7 @@ function buildThunks({
30542
30567
  } else {
30543
30568
  finalQueryReturnValue = await executeRequest(arg.originalArgs);
30544
30569
  }
30545
- if (metaSchema && !skipSchemaValidation && finalQueryReturnValue.meta) {
30570
+ if (metaSchema && !shouldSkip(skipSchemaValidation, "meta") && finalQueryReturnValue.meta) {
30546
30571
  finalQueryReturnValue.meta = await parseWithSchema(metaSchema, finalQueryReturnValue.meta, "metaSchema", finalQueryReturnValue.meta);
30547
30572
  }
30548
30573
  return fulfillWithValue(finalQueryReturnValue.data, addShouldAutoBatch({
@@ -30562,14 +30587,14 @@ function buildThunks({
30562
30587
  meta
30563
30588
  } = caughtError;
30564
30589
  try {
30565
- if (rawErrorResponseSchema && !skipSchemaValidation) {
30590
+ if (rawErrorResponseSchema && !shouldSkip(skipSchemaValidation, "rawErrorResponse")) {
30566
30591
  value = await parseWithSchema(rawErrorResponseSchema, value, "rawErrorResponseSchema", meta);
30567
30592
  }
30568
- if (metaSchema && !skipSchemaValidation) {
30593
+ if (metaSchema && !shouldSkip(skipSchemaValidation, "meta")) {
30569
30594
  meta = await parseWithSchema(metaSchema, meta, "metaSchema", meta);
30570
30595
  }
30571
30596
  let transformedErrorResponse = await transformErrorResponse(value, meta, arg.originalArgs);
30572
- if (errorResponseSchema && !skipSchemaValidation) {
30597
+ if (errorResponseSchema && !shouldSkip(skipSchemaValidation, "errorResponse")) {
30573
30598
  transformedErrorResponse = await parseWithSchema(errorResponseSchema, transformedErrorResponse, "errorResponseSchema", meta);
30574
30599
  }
30575
30600
  return rejectWithValue(transformedErrorResponse, addShouldAutoBatch({
@@ -30731,15 +30756,15 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
30731
30756
  function getNextPageParam(options, {
30732
30757
  pages,
30733
30758
  pageParams
30734
- }) {
30759
+ }, queryArg) {
30735
30760
  const lastIndex = pages.length - 1;
30736
- return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams);
30761
+ return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams, queryArg);
30737
30762
  }
30738
30763
  function getPreviousPageParam(options, {
30739
30764
  pages,
30740
30765
  pageParams
30741
- }) {
30742
- return options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams);
30766
+ }, queryArg) {
30767
+ return options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams, queryArg);
30743
30768
  }
30744
30769
  function calculateProvidedByThunk(action, type, endpointDefinitions, assertTagType) {
30745
30770
  return calculateProvidedBy(endpointDefinitions[action.meta.arg.endpointName][type], isFulfilled(action) ? action.payload : void 0, isRejectedWithValue(action) ? action.payload : void 0, action.meta.arg.originalArgs, "baseQueryMeta" in action.meta ? action.meta.baseQueryMeta : void 0, assertTagType);
@@ -31084,7 +31109,7 @@ function buildSlice({
31084
31109
  const {
31085
31110
  provided
31086
31111
  } = extractRehydrationInfo(action);
31087
- for (const [type, incomingTags] of Object.entries(provided)) {
31112
+ for (const [type, incomingTags] of Object.entries(provided.tags ?? {})) {
31088
31113
  for (const [id, cacheKeys] of Object.entries(incomingTags)) {
31089
31114
  const subscribedQueries = (_b = (_a = draft.tags)[type] ?? (_a[type] = {}))[_c = id || "__internal_without_id"] ?? (_b[_c] = []);
31090
31115
  for (const queryCacheKey of cacheKeys) {
@@ -31092,6 +31117,7 @@ function buildSlice({
31092
31117
  if (!alreadySubscribed) {
31093
31118
  subscribedQueries.push(queryCacheKey);
31094
31119
  }
31120
+ draft.keys[queryCacheKey] = provided.keys[queryCacheKey];
31095
31121
  }
31096
31122
  }
31097
31123
  }
@@ -31308,8 +31334,8 @@ function buildSelectors({
31308
31334
  const isBackward = direction === "backward";
31309
31335
  return {
31310
31336
  ...stateWithRequestFlags,
31311
- hasNextPage: getHasNextPage(infiniteQueryOptions, stateWithRequestFlags.data),
31312
- hasPreviousPage: getHasPreviousPage(infiniteQueryOptions, stateWithRequestFlags.data),
31337
+ hasNextPage: getHasNextPage(infiniteQueryOptions, stateWithRequestFlags.data, stateWithRequestFlags.originalArgs),
31338
+ hasPreviousPage: getHasPreviousPage(infiniteQueryOptions, stateWithRequestFlags.data, stateWithRequestFlags.originalArgs),
31313
31339
  isFetchingNextPage: isLoading && isForward,
31314
31340
  isFetchingPreviousPage: isLoading && isBackward,
31315
31341
  isFetchNextPageError: isError2 && isForward,
@@ -31365,13 +31391,13 @@ function buildSelectors({
31365
31391
  /* uninitialized */
31366
31392
  ).map((entry) => entry.originalArgs);
31367
31393
  }
31368
- function getHasNextPage(options, data) {
31394
+ function getHasNextPage(options, data, queryArg) {
31369
31395
  if (!data) return false;
31370
- return getNextPageParam(options, data) != null;
31396
+ return getNextPageParam(options, data, queryArg) != null;
31371
31397
  }
31372
- function getHasPreviousPage(options, data) {
31398
+ function getHasPreviousPage(options, data, queryArg) {
31373
31399
  if (!data || !options.getPreviousPageParam) return false;
31374
- return getPreviousPageParam(options, data) != null;
31400
+ return getPreviousPageParam(options, data, queryArg) != null;
31375
31401
  }
31376
31402
  }
31377
31403
  var cache = WeakMap ? /* @__PURE__ */ new WeakMap() : void 0;
@@ -31539,7 +31565,8 @@ function safeAssign(target, ...args) {
31539
31565
  var buildBatchedActionsHandler = ({
31540
31566
  api,
31541
31567
  queryThunk,
31542
- internalState
31568
+ internalState,
31569
+ mwApi
31543
31570
  }) => {
31544
31571
  const subscriptionsPrefix = `${api.reducerPath}/subscriptions`;
31545
31572
  let previousSubscriptions = null;
@@ -31548,16 +31575,16 @@ var buildBatchedActionsHandler = ({
31548
31575
  updateSubscriptionOptions,
31549
31576
  unsubscribeQueryResult
31550
31577
  } = api.internalActions;
31551
- const actuallyMutateSubscriptions = (mutableState, action) => {
31552
- var _a, _b;
31578
+ const actuallyMutateSubscriptions = (currentSubscriptions, action) => {
31553
31579
  if (updateSubscriptionOptions.match(action)) {
31554
31580
  const {
31555
31581
  queryCacheKey,
31556
31582
  requestId,
31557
31583
  options
31558
31584
  } = action.payload;
31559
- if (mutableState?.[queryCacheKey]?.[requestId]) {
31560
- mutableState[queryCacheKey][requestId] = options;
31585
+ const sub = currentSubscriptions.get(queryCacheKey);
31586
+ if (sub?.has(requestId)) {
31587
+ sub.set(requestId, options);
31561
31588
  }
31562
31589
  return true;
31563
31590
  }
@@ -31566,13 +31593,14 @@ var buildBatchedActionsHandler = ({
31566
31593
  queryCacheKey,
31567
31594
  requestId
31568
31595
  } = action.payload;
31569
- if (mutableState[queryCacheKey]) {
31570
- delete mutableState[queryCacheKey][requestId];
31596
+ const sub = currentSubscriptions.get(queryCacheKey);
31597
+ if (sub) {
31598
+ sub.delete(requestId);
31571
31599
  }
31572
31600
  return true;
31573
31601
  }
31574
31602
  if (api.internalActions.removeQueryResult.match(action)) {
31575
- delete mutableState[action.payload.queryCacheKey];
31603
+ currentSubscriptions.delete(action.payload.queryCacheKey);
31576
31604
  return true;
31577
31605
  }
31578
31606
  if (queryThunk.pending.match(action)) {
@@ -31582,20 +31610,13 @@ var buildBatchedActionsHandler = ({
31582
31610
  requestId
31583
31611
  }
31584
31612
  } = action;
31585
- const substate = mutableState[_a = arg.queryCacheKey] ?? (mutableState[_a] = {});
31586
- substate[`${requestId}_running`] = {};
31613
+ const substate = getOrInsertComputed2(currentSubscriptions, arg.queryCacheKey, createNewMap);
31587
31614
  if (arg.subscribe) {
31588
- substate[requestId] = arg.subscriptionOptions ?? substate[requestId] ?? {};
31615
+ substate.set(requestId, arg.subscriptionOptions ?? substate.get(requestId) ?? {});
31589
31616
  }
31590
31617
  return true;
31591
31618
  }
31592
31619
  let mutated = false;
31593
- if (queryThunk.fulfilled.match(action) || queryThunk.rejected.match(action)) {
31594
- const state = mutableState[action.meta.arg.queryCacheKey] || {};
31595
- const key = `${action.meta.requestId}_running`;
31596
- mutated || (mutated = !!state[key]);
31597
- delete state[key];
31598
- }
31599
31620
  if (queryThunk.rejected.match(action)) {
31600
31621
  const {
31601
31622
  meta: {
@@ -31605,8 +31626,8 @@ var buildBatchedActionsHandler = ({
31605
31626
  }
31606
31627
  } = action;
31607
31628
  if (condition && arg.subscribe) {
31608
- const substate = mutableState[_b = arg.queryCacheKey] ?? (mutableState[_b] = {});
31609
- substate[requestId] = arg.subscriptionOptions ?? substate[requestId] ?? {};
31629
+ const substate = getOrInsertComputed2(currentSubscriptions, arg.queryCacheKey, createNewMap);
31630
+ substate.set(requestId, arg.subscriptionOptions ?? substate.get(requestId) ?? {});
31610
31631
  mutated = true;
31611
31632
  }
31612
31633
  }
@@ -31615,24 +31636,28 @@ var buildBatchedActionsHandler = ({
31615
31636
  const getSubscriptions = () => internalState.currentSubscriptions;
31616
31637
  const getSubscriptionCount = (queryCacheKey) => {
31617
31638
  const subscriptions = getSubscriptions();
31618
- const subscriptionsForQueryArg = subscriptions[queryCacheKey] ?? {};
31619
- return countObjectKeys(subscriptionsForQueryArg);
31639
+ const subscriptionsForQueryArg = subscriptions.get(queryCacheKey);
31640
+ return subscriptionsForQueryArg?.size ?? 0;
31620
31641
  };
31621
31642
  const isRequestSubscribed = (queryCacheKey, requestId) => {
31622
31643
  const subscriptions = getSubscriptions();
31623
- return !!subscriptions?.[queryCacheKey]?.[requestId];
31644
+ return !!subscriptions?.get(queryCacheKey)?.get(requestId);
31624
31645
  };
31625
31646
  const subscriptionSelectors = {
31626
31647
  getSubscriptions,
31627
31648
  getSubscriptionCount,
31628
31649
  isRequestSubscribed
31629
31650
  };
31630
- return (action, mwApi) => {
31651
+ function serializeSubscriptions(currentSubscriptions) {
31652
+ return JSON.parse(JSON.stringify(Object.fromEntries([...currentSubscriptions].map(([k, v]) => [k, Object.fromEntries(v)]))));
31653
+ }
31654
+ return (action, mwApi2) => {
31631
31655
  if (!previousSubscriptions) {
31632
- previousSubscriptions = JSON.parse(JSON.stringify(internalState.currentSubscriptions));
31656
+ previousSubscriptions = serializeSubscriptions(internalState.currentSubscriptions);
31633
31657
  }
31634
31658
  if (api.util.resetApiState.match(action)) {
31635
- previousSubscriptions = internalState.currentSubscriptions = {};
31659
+ previousSubscriptions = {};
31660
+ internalState.currentSubscriptions.clear();
31636
31661
  updateSyncTimer = null;
31637
31662
  return [true, false];
31638
31663
  }
@@ -31641,12 +31666,15 @@ var buildBatchedActionsHandler = ({
31641
31666
  }
31642
31667
  const didMutate = actuallyMutateSubscriptions(internalState.currentSubscriptions, action);
31643
31668
  let actionShouldContinue = true;
31669
+ if (process.env.NODE_ENV === "test" && typeof action.type === "string" && action.type === `${api.reducerPath}/getPolling`) {
31670
+ return [false, internalState.currentPolls];
31671
+ }
31644
31672
  if (didMutate) {
31645
31673
  if (!updateSyncTimer) {
31646
31674
  updateSyncTimer = setTimeout(() => {
31647
- const newSubscriptions = JSON.parse(JSON.stringify(internalState.currentSubscriptions));
31675
+ const newSubscriptions = serializeSubscriptions(internalState.currentSubscriptions);
31648
31676
  const [, patches] = produceWithPatches(previousSubscriptions, () => newSubscriptions);
31649
- mwApi.next(api.internalActions.subscriptionsUpdated(patches));
31677
+ mwApi2.next(api.internalActions.subscriptionsUpdated(patches));
31650
31678
  previousSubscriptions = newSubscriptions;
31651
31679
  updateSyncTimer = null;
31652
31680
  }, 500);
@@ -31658,12 +31686,6 @@ var buildBatchedActionsHandler = ({
31658
31686
  return [actionShouldContinue, false];
31659
31687
  };
31660
31688
  };
31661
- function isObjectEmpty(obj) {
31662
- for (const k in obj) {
31663
- return false;
31664
- }
31665
- return true;
31666
- }
31667
31689
  var THIRTY_TWO_BIT_MAX_TIMER_SECONDS = 2147483647 / 1e3 - 1;
31668
31690
  var buildCacheCollectionHandler = ({
31669
31691
  reducerPath,
@@ -31674,21 +31696,29 @@ var buildCacheCollectionHandler = ({
31674
31696
  selectors: {
31675
31697
  selectQueryEntry,
31676
31698
  selectConfig
31677
- }
31699
+ },
31700
+ getRunningQueryThunk,
31701
+ mwApi
31678
31702
  }) => {
31679
31703
  const {
31680
31704
  removeQueryResult,
31681
31705
  unsubscribeQueryResult,
31682
31706
  cacheEntriesUpserted
31683
31707
  } = api.internalActions;
31708
+ const runningQueries = internalState.runningQueries.get(mwApi.dispatch);
31684
31709
  const canTriggerUnsubscribe = isAnyOf(unsubscribeQueryResult.match, queryThunk.fulfilled, queryThunk.rejected, cacheEntriesUpserted.match);
31685
31710
  function anySubscriptionsRemainingForKey(queryCacheKey) {
31686
- const subscriptions = internalState.currentSubscriptions[queryCacheKey];
31687
- return !!subscriptions && !isObjectEmpty(subscriptions);
31711
+ const subscriptions = internalState.currentSubscriptions.get(queryCacheKey);
31712
+ if (!subscriptions) {
31713
+ return false;
31714
+ }
31715
+ const hasSubscriptions = subscriptions.size > 0;
31716
+ const isRunning = runningQueries?.[queryCacheKey] !== void 0;
31717
+ return hasSubscriptions || isRunning;
31688
31718
  }
31689
31719
  const currentRemovalTimeouts = {};
31690
- const handler = (action, mwApi, internalState2) => {
31691
- const state = mwApi.getState();
31720
+ const handler = (action, mwApi2, internalState2) => {
31721
+ const state = mwApi2.getState();
31692
31722
  const config = selectConfig(state);
31693
31723
  if (canTriggerUnsubscribe(action)) {
31694
31724
  let queryCacheKeys;
@@ -31700,7 +31730,7 @@ var buildCacheCollectionHandler = ({
31700
31730
  } = unsubscribeQueryResult.match(action) ? action.payload : action.meta.arg;
31701
31731
  queryCacheKeys = [queryCacheKey];
31702
31732
  }
31703
- handleUnsubscribeMany(queryCacheKeys, mwApi, config);
31733
+ handleUnsubscribeMany(queryCacheKeys, mwApi2, config);
31704
31734
  }
31705
31735
  if (api.util.resetApiState.match(action)) {
31706
31736
  for (const [key, timeout] of Object.entries(currentRemovalTimeouts)) {
@@ -31712,14 +31742,16 @@ var buildCacheCollectionHandler = ({
31712
31742
  const {
31713
31743
  queries
31714
31744
  } = context.extractRehydrationInfo(action);
31715
- handleUnsubscribeMany(Object.keys(queries), mwApi, config);
31745
+ handleUnsubscribeMany(Object.keys(queries), mwApi2, config);
31716
31746
  }
31717
31747
  };
31718
31748
  function handleUnsubscribeMany(cacheKeys, api2, config) {
31719
31749
  const state = api2.getState();
31720
31750
  for (const queryCacheKey of cacheKeys) {
31721
31751
  const entry = selectQueryEntry(state, queryCacheKey);
31722
- handleUnsubscribe(queryCacheKey, entry?.endpointName, api2, config);
31752
+ if (entry?.endpointName) {
31753
+ handleUnsubscribe(queryCacheKey, entry.endpointName, api2, config);
31754
+ }
31723
31755
  }
31724
31756
  }
31725
31757
  function handleUnsubscribe(queryCacheKey, endpointName, api2, config) {
@@ -31736,6 +31768,11 @@ var buildCacheCollectionHandler = ({
31736
31768
  }
31737
31769
  currentRemovalTimeouts[queryCacheKey] = setTimeout(() => {
31738
31770
  if (!anySubscriptionsRemainingForKey(queryCacheKey)) {
31771
+ const entry = selectQueryEntry(api2.getState(), queryCacheKey);
31772
+ if (entry?.endpointName) {
31773
+ const runningQuery = api2.dispatch(getRunningQueryThunk(entry.endpointName, entry.originalArgs));
31774
+ runningQuery?.abort();
31775
+ }
31739
31776
  api2.dispatch(removeQueryResult({
31740
31777
  queryCacheKey
31741
31778
  }));
@@ -31940,9 +31977,9 @@ var buildInvalidationByTagsHandler = ({
31940
31977
  queryCacheKey
31941
31978
  } of valuesArray) {
31942
31979
  const querySubState = state.queries[queryCacheKey];
31943
- const subscriptionSubState = internalState.currentSubscriptions[queryCacheKey] ?? {};
31980
+ const subscriptionSubState = getOrInsertComputed2(internalState.currentSubscriptions, queryCacheKey, createNewMap);
31944
31981
  if (querySubState) {
31945
- if (countObjectKeys(subscriptionSubState) === 0) {
31982
+ if (subscriptionSubState.size === 0) {
31946
31983
  mwApi.dispatch(removeQueryResult({
31947
31984
  queryCacheKey
31948
31985
  }));
@@ -31962,25 +31999,49 @@ var buildPollingHandler = ({
31962
31999
  refetchQuery,
31963
32000
  internalState
31964
32001
  }) => {
31965
- const currentPolls = {};
32002
+ const {
32003
+ currentPolls,
32004
+ currentSubscriptions
32005
+ } = internalState;
32006
+ const pendingPollingUpdates = /* @__PURE__ */ new Set();
32007
+ let pollingUpdateTimer = null;
31966
32008
  const handler = (action, mwApi) => {
31967
32009
  if (api.internalActions.updateSubscriptionOptions.match(action) || api.internalActions.unsubscribeQueryResult.match(action)) {
31968
- updatePollingInterval(action.payload, mwApi);
32010
+ schedulePollingUpdate(action.payload.queryCacheKey, mwApi);
31969
32011
  }
31970
32012
  if (queryThunk.pending.match(action) || queryThunk.rejected.match(action) && action.meta.condition) {
31971
- updatePollingInterval(action.meta.arg, mwApi);
32013
+ schedulePollingUpdate(action.meta.arg.queryCacheKey, mwApi);
31972
32014
  }
31973
32015
  if (queryThunk.fulfilled.match(action) || queryThunk.rejected.match(action) && !action.meta.condition) {
31974
32016
  startNextPoll(action.meta.arg, mwApi);
31975
32017
  }
31976
32018
  if (api.util.resetApiState.match(action)) {
31977
32019
  clearPolls();
32020
+ if (pollingUpdateTimer) {
32021
+ clearTimeout(pollingUpdateTimer);
32022
+ pollingUpdateTimer = null;
32023
+ }
32024
+ pendingPollingUpdates.clear();
31978
32025
  }
31979
32026
  };
32027
+ function schedulePollingUpdate(queryCacheKey, api2) {
32028
+ pendingPollingUpdates.add(queryCacheKey);
32029
+ if (!pollingUpdateTimer) {
32030
+ pollingUpdateTimer = setTimeout(() => {
32031
+ for (const key of pendingPollingUpdates) {
32032
+ updatePollingInterval({
32033
+ queryCacheKey: key
32034
+ }, api2);
32035
+ }
32036
+ pendingPollingUpdates.clear();
32037
+ pollingUpdateTimer = null;
32038
+ }, 0);
32039
+ }
32040
+ }
31980
32041
  function getCacheEntrySubscriptions(queryCacheKey, api2) {
31981
32042
  const state = api2.getState()[reducerPath];
31982
32043
  const querySubState = state.queries[queryCacheKey];
31983
- const subscriptions = internalState.currentSubscriptions[queryCacheKey];
32044
+ const subscriptions = currentSubscriptions.get(queryCacheKey);
31984
32045
  if (!querySubState || querySubState.status === "uninitialized") return;
31985
32046
  return subscriptions;
31986
32047
  }
@@ -31989,20 +32050,20 @@ var buildPollingHandler = ({
31989
32050
  }, api2) {
31990
32051
  const state = api2.getState()[reducerPath];
31991
32052
  const querySubState = state.queries[queryCacheKey];
31992
- const subscriptions = internalState.currentSubscriptions[queryCacheKey];
32053
+ const subscriptions = currentSubscriptions.get(queryCacheKey);
31993
32054
  if (!querySubState || querySubState.status === "uninitialized") return;
31994
32055
  const {
31995
32056
  lowestPollingInterval,
31996
32057
  skipPollingIfUnfocused
31997
32058
  } = findLowestPollingInterval(subscriptions);
31998
32059
  if (!Number.isFinite(lowestPollingInterval)) return;
31999
- const currentPoll = currentPolls[queryCacheKey];
32060
+ const currentPoll = currentPolls.get(queryCacheKey);
32000
32061
  if (currentPoll?.timeout) {
32001
32062
  clearTimeout(currentPoll.timeout);
32002
32063
  currentPoll.timeout = void 0;
32003
32064
  }
32004
32065
  const nextPollTimestamp = Date.now() + lowestPollingInterval;
32005
- currentPolls[queryCacheKey] = {
32066
+ currentPolls.set(queryCacheKey, {
32006
32067
  nextPollTimestamp,
32007
32068
  pollingInterval: lowestPollingInterval,
32008
32069
  timeout: setTimeout(() => {
@@ -32013,25 +32074,30 @@ var buildPollingHandler = ({
32013
32074
  queryCacheKey
32014
32075
  }, api2);
32015
32076
  }, lowestPollingInterval)
32016
- };
32077
+ });
32017
32078
  }
32018
32079
  function updatePollingInterval({
32019
32080
  queryCacheKey
32020
32081
  }, api2) {
32021
32082
  const state = api2.getState()[reducerPath];
32022
32083
  const querySubState = state.queries[queryCacheKey];
32023
- const subscriptions = internalState.currentSubscriptions[queryCacheKey];
32084
+ const subscriptions = currentSubscriptions.get(queryCacheKey);
32024
32085
  if (!querySubState || querySubState.status === "uninitialized") {
32025
32086
  return;
32026
32087
  }
32027
32088
  const {
32028
32089
  lowestPollingInterval
32029
32090
  } = findLowestPollingInterval(subscriptions);
32091
+ if (process.env.NODE_ENV === "test") {
32092
+ const updateCounters = currentPolls.pollUpdateCounters ?? (currentPolls.pollUpdateCounters = {});
32093
+ updateCounters[queryCacheKey] ?? (updateCounters[queryCacheKey] = 0);
32094
+ updateCounters[queryCacheKey]++;
32095
+ }
32030
32096
  if (!Number.isFinite(lowestPollingInterval)) {
32031
32097
  cleanupPollForKey(queryCacheKey);
32032
32098
  return;
32033
32099
  }
32034
- const currentPoll = currentPolls[queryCacheKey];
32100
+ const currentPoll = currentPolls.get(queryCacheKey);
32035
32101
  const nextPollTimestamp = Date.now() + lowestPollingInterval;
32036
32102
  if (!currentPoll || nextPollTimestamp < currentPoll.nextPollTimestamp) {
32037
32103
  startNextPoll({
@@ -32040,24 +32106,24 @@ var buildPollingHandler = ({
32040
32106
  }
32041
32107
  }
32042
32108
  function cleanupPollForKey(key) {
32043
- const existingPoll = currentPolls[key];
32109
+ const existingPoll = currentPolls.get(key);
32044
32110
  if (existingPoll?.timeout) {
32045
32111
  clearTimeout(existingPoll.timeout);
32046
32112
  }
32047
- delete currentPolls[key];
32113
+ currentPolls.delete(key);
32048
32114
  }
32049
32115
  function clearPolls() {
32050
- for (const key of Object.keys(currentPolls)) {
32116
+ for (const key of currentPolls.keys()) {
32051
32117
  cleanupPollForKey(key);
32052
32118
  }
32053
32119
  }
32054
- function findLowestPollingInterval(subscribers = {}) {
32120
+ function findLowestPollingInterval(subscribers = /* @__PURE__ */ new Map()) {
32055
32121
  let skipPollingIfUnfocused = false;
32056
32122
  let lowestPollingInterval = Number.POSITIVE_INFINITY;
32057
- for (let key in subscribers) {
32058
- if (!!subscribers[key].pollingInterval) {
32059
- lowestPollingInterval = Math.min(subscribers[key].pollingInterval, lowestPollingInterval);
32060
- skipPollingIfUnfocused = subscribers[key].skipPollingIfUnfocused || skipPollingIfUnfocused;
32123
+ for (const entry of subscribers.values()) {
32124
+ if (!!entry.pollingInterval) {
32125
+ lowestPollingInterval = Math.min(entry.pollingInterval, lowestPollingInterval);
32126
+ skipPollingIfUnfocused = entry.skipPollingIfUnfocused || skipPollingIfUnfocused;
32061
32127
  }
32062
32128
  }
32063
32129
  return {
@@ -32158,13 +32224,14 @@ var buildWindowEventHandler = ({
32158
32224
  const queries = state.queries;
32159
32225
  const subscriptions = internalState.currentSubscriptions;
32160
32226
  context.batch(() => {
32161
- for (const queryCacheKey of Object.keys(subscriptions)) {
32227
+ for (const queryCacheKey of subscriptions.keys()) {
32162
32228
  const querySubState = queries[queryCacheKey];
32163
- const subscriptionSubState = subscriptions[queryCacheKey];
32229
+ const subscriptionSubState = subscriptions.get(queryCacheKey);
32164
32230
  if (!subscriptionSubState || !querySubState) continue;
32165
- const shouldRefetch = Object.values(subscriptionSubState).some((sub) => sub[type] === true) || Object.values(subscriptionSubState).every((sub) => sub[type] === void 0) && state.config[type];
32231
+ const values = [...subscriptionSubState.values()];
32232
+ const shouldRefetch = values.some((sub) => sub[type] === true) || values.every((sub) => sub[type] === void 0) && state.config[type];
32166
32233
  if (shouldRefetch) {
32167
- if (countObjectKeys(subscriptionSubState) === 0) {
32234
+ if (subscriptionSubState.size === 0) {
32168
32235
  api2.dispatch(removeQueryResult({
32169
32236
  queryCacheKey
32170
32237
  }));
@@ -32182,7 +32249,8 @@ function buildMiddleware(input) {
32182
32249
  reducerPath,
32183
32250
  queryThunk,
32184
32251
  api,
32185
- context
32252
+ context,
32253
+ internalState
32186
32254
  } = input;
32187
32255
  const {
32188
32256
  apiUid
@@ -32194,14 +32262,12 @@ function buildMiddleware(input) {
32194
32262
  const handlerBuilders = [buildDevCheckHandler, buildCacheCollectionHandler, buildInvalidationByTagsHandler, buildPollingHandler, buildCacheLifecycleHandler, buildQueryLifecycleHandler];
32195
32263
  const middleware = (mwApi) => {
32196
32264
  let initialized2 = false;
32197
- const internalState = {
32198
- currentSubscriptions: {}
32199
- };
32200
32265
  const builderArgs = {
32201
32266
  ...input,
32202
32267
  internalState,
32203
32268
  refetchQuery,
32204
- isThisApiSliceAction
32269
+ isThisApiSliceAction,
32270
+ mwApi
32205
32271
  };
32206
32272
  const handlers = handlerBuilders.map((build) => build(builderArgs));
32207
32273
  const batchedActionsHandler = buildBatchedActionsHandler(builderArgs);
@@ -32356,24 +32422,12 @@ var coreModule = ({
32356
32422
  upsertQueryEntries: sliceActions.cacheEntriesUpserted
32357
32423
  });
32358
32424
  safeAssign(api.internalActions, sliceActions);
32359
- const {
32360
- middleware,
32361
- actions: middlewareActions
32362
- } = buildMiddleware({
32363
- reducerPath,
32364
- context,
32365
- queryThunk,
32366
- mutationThunk,
32367
- infiniteQueryThunk,
32368
- api,
32369
- assertTagType,
32370
- selectors
32371
- });
32372
- safeAssign(api.util, middlewareActions);
32373
- safeAssign(api, {
32374
- reducer,
32375
- middleware
32376
- });
32425
+ const internalState = {
32426
+ currentSubscriptions: /* @__PURE__ */ new Map(),
32427
+ currentPolls: /* @__PURE__ */ new Map(),
32428
+ runningQueries: /* @__PURE__ */ new Map(),
32429
+ runningMutations: /* @__PURE__ */ new Map()
32430
+ };
32377
32431
  const {
32378
32432
  buildInitiateQuery,
32379
32433
  buildInitiateInfiniteQuery,
@@ -32388,7 +32442,8 @@ var coreModule = ({
32388
32442
  infiniteQueryThunk,
32389
32443
  api,
32390
32444
  serializeQueryArgs,
32391
- context
32445
+ context,
32446
+ internalState
32392
32447
  });
32393
32448
  safeAssign(api.util, {
32394
32449
  getRunningMutationThunk,
@@ -32396,6 +32451,26 @@ var coreModule = ({
32396
32451
  getRunningQueryThunk,
32397
32452
  getRunningQueriesThunk
32398
32453
  });
32454
+ const {
32455
+ middleware,
32456
+ actions: middlewareActions
32457
+ } = buildMiddleware({
32458
+ reducerPath,
32459
+ context,
32460
+ queryThunk,
32461
+ mutationThunk,
32462
+ infiniteQueryThunk,
32463
+ api,
32464
+ assertTagType,
32465
+ selectors,
32466
+ getRunningQueryThunk,
32467
+ internalState
32468
+ });
32469
+ safeAssign(api.util, middlewareActions);
32470
+ safeAssign(api, {
32471
+ reducer,
32472
+ middleware
32473
+ });
32399
32474
  return {
32400
32475
  name: coreModuleName,
32401
32476
  injectEndpoint(endpointName, definition) {
@@ -32463,22 +32538,15 @@ function safeAssign2(target, ...args) {
32463
32538
  return Object.assign(target, ...args);
32464
32539
  }
32465
32540
  var UNINITIALIZED_VALUE = Symbol();
32466
- function useStableQueryArgs(queryArgs, serialize, endpointDefinition, endpointName) {
32467
- const incoming = useMemo(() => ({
32468
- queryArgs,
32469
- serialized: typeof queryArgs == "object" ? serialize({
32470
- queryArgs,
32471
- endpointDefinition,
32472
- endpointName
32473
- }) : queryArgs
32474
- }), [queryArgs, serialize, endpointDefinition, endpointName]);
32475
- const cache2 = useRef(incoming);
32541
+ function useStableQueryArgs(queryArgs) {
32542
+ const cache2 = useRef(queryArgs);
32543
+ const copy = useMemo(() => copyWithStructuralSharing(cache2.current, queryArgs), [queryArgs]);
32476
32544
  useEffect(() => {
32477
- if (cache2.current.serialized !== incoming.serialized) {
32478
- cache2.current = incoming;
32545
+ if (cache2.current !== copy) {
32546
+ cache2.current = copy;
32479
32547
  }
32480
- }, [incoming]);
32481
- return cache2.current.serialized === incoming.serialized ? cache2.current.queryArgs : queryArgs;
32548
+ }, [copy]);
32549
+ return copy;
32482
32550
  }
32483
32551
  function useShallowStableValue(value) {
32484
32552
  const cache2 = useRef2(value);
@@ -32631,17 +32699,7 @@ function buildHooks({
32631
32699
  }
32632
32700
  subscriptionSelectorsRef.current = returnedValue;
32633
32701
  }
32634
- const stableArg = useStableQueryArgs(
32635
- skip ? skipToken : arg,
32636
- // Even if the user provided a per-endpoint `serializeQueryArgs` with
32637
- // a consistent return value, _here_ we want to use the default behavior
32638
- // so we can tell if _anything_ actually changed. Otherwise, we can end up
32639
- // with a case where the query args did change but the serialization doesn't,
32640
- // and then we never try to initiate a refetch.
32641
- defaultSerializeQueryArgs,
32642
- context.endpointDefinitions[endpointName],
32643
- endpointName
32644
- );
32702
+ const stableArg = useStableQueryArgs(skip ? skipToken : arg);
32645
32703
  const stableSubscriptionOptions = useShallowStableValue({
32646
32704
  refetchOnReconnect,
32647
32705
  refetchOnFocus,
@@ -32700,7 +32758,7 @@ function buildHooks({
32700
32758
  const {
32701
32759
  select
32702
32760
  } = api.endpoints[endpointName];
32703
- const stableArg = useStableQueryArgs(skip ? skipToken : arg, serializeQueryArgs, context.endpointDefinitions[endpointName], endpointName);
32761
+ const stableArg = useStableQueryArgs(skip ? skipToken : arg);
32704
32762
  const lastValue = useRef3(void 0);
32705
32763
  const selectDefaultResult = useMemo2(() => (
32706
32764
  // Normally ts-ignores are bad and should be avoided, but we're
@@ -32872,17 +32930,7 @@ function buildHooks({
32872
32930
  return promise;
32873
32931
  }, [promiseRef, dispatch, initiate]);
32874
32932
  usePromiseRefUnsubscribeOnUnmount(promiseRef);
32875
- const stableArg = useStableQueryArgs(
32876
- options.skip ? skipToken : arg,
32877
- // Even if the user provided a per-endpoint `serializeQueryArgs` with
32878
- // a consistent return value, _here_ we want to use the default behavior
32879
- // so we can tell if _anything_ actually changed. Otherwise, we can end up
32880
- // with a case where the query args did change but the serialization doesn't,
32881
- // and then we never try to initiate a refetch.
32882
- defaultSerializeQueryArgs,
32883
- context.endpointDefinitions[endpointName],
32884
- endpointName
32885
- );
32933
+ const stableArg = useStableQueryArgs(options.skip ? skipToken : arg);
32886
32934
  const refetch = useCallback(() => refetchOrErrorIfUnmounted(promiseRef), [promiseRef]);
32887
32935
  return useMemo2(() => {
32888
32936
  const fetchNextPage = () => {