@mmstack/resource 22.1.4 → 22.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/resource",
3
- "version": "22.1.4",
3
+ "version": "22.1.5",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -1058,6 +1058,17 @@ type NextRequest<TMethod extends HttpResourceRequest['method'], TMutation> = TMe
1058
1058
  body: TMutation;
1059
1059
  method: TMethod;
1060
1060
  };
1061
+ /**
1062
+ * Object form of the `queue` option. Enabling the queue serializes mutations
1063
+ * into a FIFO that runs one-at-a-time.
1064
+ */
1065
+ type MutationQueueOptions = {
1066
+ /**
1067
+ * Reactive queue key. When its returned value changes, the *pending* (not-yet-fired)
1068
+ * queued mutations are dropped; an in-flight mutation is unaffected. e.g. `key: () => selectedId()`.
1069
+ */
1070
+ key?: () => string | number;
1071
+ };
1061
1072
  /**
1062
1073
  * Options for configuring a `mutationResource`. Inherits from
1063
1074
  * `QueryResourceOptions` (minus options that don't apply to mutations:
@@ -1109,10 +1120,13 @@ type MutationResourceOptions<TResult, TRaw = TResult, TMutation = TResult, TCTX
1109
1120
  */
1110
1121
  onSettled?: (ctx: NoInfer<TCTX>) => void;
1111
1122
  /**
1112
- * Whether to queue the mutation requests and execute them in series. For example if network is unavailable or circuit breaker is open.
1123
+ * Queue mutations and run them one-at-a-time in series, instead of latest-wins
1124
+ * superseding (e.g. while offline or the circuit breaker is open). Pass
1125
+ * {@link MutationQueueOptions} for a reactive `key` that resets the pending queue.
1126
+ * The pending queue can also be cleared via `ref.clearQueue()`.
1113
1127
  * @default false
1114
1128
  */
1115
- queue?: boolean;
1129
+ queue?: boolean | MutationQueueOptions;
1116
1130
  /**
1117
1131
  * Cache entries to invalidate after a SUCCESSFUL mutation — the declarative
1118
1132
  * alternative to calling `injectQueryCache().invalidatePrefix(...)` in `onSuccess`.
@@ -1172,6 +1186,11 @@ type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Omit<Quer
1172
1186
  * This can be useful for tracking the state of the mutation or for displaying loading indicators.
1173
1187
  */
1174
1188
  current: Signal<TMutation | null>;
1189
+ /**
1190
+ * Drops all *pending* queued mutations; an in-flight mutation is unaffected.
1191
+ * Noops when `queue` is not enabled.
1192
+ */
1193
+ clearQueue: () => void;
1175
1194
  };
1176
1195
  /**
1177
1196
  * Creates a resource for performing mutations (e.g., POST, PUT, PATCH, DELETE requests).
@@ -1225,4 +1244,4 @@ type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Omit<Quer
1225
1244
  declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX, TMethod extends HttpResourceRequest['method'] = HttpResourceRequest['method']>(request: (params: TMutation) => Omit<NextRequest<TMethod, TMutation>, 'body'> | undefined | void, options0?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
1226
1245
 
1227
1246
  export { Cache, PAUSED, applyResourceRegistration, createCacheInterceptor, createCircuitBreaker, createDedupeRequestsInterceptor, hashRequest, infiniteQueryResource, injectQueryCache, injectResourceOptions, manualQueryResource, mutationResource, noDedupe, provideCircuitBreakerDefaultOptions, provideMutationResourceOptions, provideQueryCache, provideQueryResourceOptions, provideResourceOptions, provideTypedResourceOptions, queryResource };
1228
- export type { CacheEntry, CleanupType, CommonResourceOptions, DisabledReason, InfiniteQueryResourceOptions, InfiniteQueryResourceRef, InfiniteRequestContext, ManualQueryResourceRef, MutationResourceOptions, MutationResourceRef, QueryResourceOptions, QueryResourceRef, RefreshOptions, RequestContext, ResourceCacheOptions, ResourceRequestFn, TransitionRegistration };
1247
+ export type { CacheEntry, CleanupType, CommonResourceOptions, DisabledReason, InfiniteQueryResourceOptions, InfiniteQueryResourceRef, InfiniteRequestContext, ManualQueryResourceRef, MutationQueueOptions, MutationResourceOptions, MutationResourceRef, QueryResourceOptions, QueryResourceRef, RefreshOptions, RequestContext, ResourceCacheOptions, ResourceRequestFn, TransitionRegistration };