@mmstack/resource 22.1.5 → 22.1.6

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.5",
3
+ "version": "22.1.6",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -1049,15 +1049,28 @@ declare function manualQueryResource<TResult, TRaw = TResult>(request: () => Htt
1049
1049
  declare function manualQueryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | string | undefined | void, options?: QueryResourceOptions<TResult, TRaw>): ManualQueryResourceRef<TResult | undefined>;
1050
1050
 
1051
1051
  /**
1052
- * @internal
1053
- * Helper type for inferring the request body type based on the HTTP method.
1052
+ * Why a {@link MutationResourceRef.mutateAsync} promise was cancelled — a closed
1053
+ * set so consumers can branch on the cause without parsing the message:
1054
+ * - `'superseded'`: a newer mutation replaced it (latest-wins).
1055
+ * - `'queue-cleared'`: dropped from the queue by `clearQueue()`.
1056
+ * - `'queue-key-changed'`: dropped from the queue by a reactive `key` change.
1057
+ * - `'destroyed'`: the resource was destroyed while it was pending/in flight.
1058
+ * - `'no-request'`: `request()` returned `undefined`, so nothing was sent.
1054
1059
  */
1055
- type NextRequest<TMethod extends HttpResourceRequest['method'], TMutation> = TMethod extends 'DELETE' | 'delete' ? Omit<HttpResourceRequest, 'body' | 'method'> & {
1056
- method: TMethod;
1057
- } : Omit<HttpResourceRequest, 'body' | 'method'> & {
1058
- body: TMutation;
1059
- method: TMethod;
1060
- };
1060
+ type MutationCancellationReason = 'superseded' | 'queue-cleared' | 'queue-key-changed' | 'destroyed' | 'no-request';
1061
+ /**
1062
+ * Rejection reason for a {@link MutationResourceRef.mutateAsync} promise whose
1063
+ * mutation never completed. The {@link MutationCancelledError.type} discriminant
1064
+ * carries the cause ({@link MutationCancellationReason}); the message is a
1065
+ * human-readable elaboration of it.
1066
+ *
1067
+ * Only `mutateAsync` promises reject with this; plain `mutate()` calls have no
1068
+ * promise and so produce no (potentially unhandled) rejection.
1069
+ */
1070
+ declare class MutationCancelledError extends Error {
1071
+ readonly type: MutationCancellationReason;
1072
+ constructor(type: MutationCancellationReason, message: string);
1073
+ }
1061
1074
  /**
1062
1075
  * Object form of the `queue` option. Enabling the queue serializes mutations
1063
1076
  * into a FIFO that runs one-at-a-time.
@@ -1181,6 +1194,18 @@ type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Omit<Quer
1181
1194
  * @param ctx An optional initial context value that will be passed to the `onMutate` callback.
1182
1195
  */
1183
1196
  mutate: (value: TMutation, ctx?: TICTX) => void;
1197
+ /**
1198
+ * Executes the mutation and returns a `Promise`
1199
+ *
1200
+ * If the mutation never completes — superseded by a newer `mutate`/`mutateAsync`
1201
+ * (latest-wins), dropped from the queue (`clearQueue` / queue `key` change),
1202
+ * abandoned on `destroy()`, or its `request()` returned `undefined` — the
1203
+ * promise rejects with a {@link MutationCancelledError}.
1204
+ *
1205
+ * @param value The mutation value (usually the request body).
1206
+ * @param ctx An optional initial context value that will be passed to the `onMutate` callback.
1207
+ */
1208
+ mutateAsync: (value: TMutation, ctx?: TICTX) => Promise<TResult>;
1184
1209
  /**
1185
1210
  * A signal that holds the current mutation request, or `null` if no mutation is in progress.
1186
1211
  * This can be useful for tracking the state of the mutation or for displaying loading indicators.
@@ -1241,7 +1266,12 @@ type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Omit<Quer
1241
1266
  * );
1242
1267
  * ```
1243
1268
  */
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>;
1269
+ declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX>(request: (params: TMutation) => (Omit<HttpResourceRequest, 'body' | 'method'> & {
1270
+ method: 'DELETE' | 'delete';
1271
+ }) | undefined | void, options0?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
1272
+ declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX>(request: (params: TMutation) => (Omit<HttpResourceRequest, 'body'> & {
1273
+ body: TMutation;
1274
+ }) | undefined | void, options0?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
1245
1275
 
1246
- export { Cache, PAUSED, applyResourceRegistration, createCacheInterceptor, createCircuitBreaker, createDedupeRequestsInterceptor, hashRequest, infiniteQueryResource, injectQueryCache, injectResourceOptions, manualQueryResource, mutationResource, noDedupe, provideCircuitBreakerDefaultOptions, provideMutationResourceOptions, provideQueryCache, provideQueryResourceOptions, provideResourceOptions, provideTypedResourceOptions, queryResource };
1247
- export type { CacheEntry, CleanupType, CommonResourceOptions, DisabledReason, InfiniteQueryResourceOptions, InfiniteQueryResourceRef, InfiniteRequestContext, ManualQueryResourceRef, MutationQueueOptions, MutationResourceOptions, MutationResourceRef, QueryResourceOptions, QueryResourceRef, RefreshOptions, RequestContext, ResourceCacheOptions, ResourceRequestFn, TransitionRegistration };
1276
+ export { Cache, MutationCancelledError, PAUSED, applyResourceRegistration, createCacheInterceptor, createCircuitBreaker, createDedupeRequestsInterceptor, hashRequest, infiniteQueryResource, injectQueryCache, injectResourceOptions, manualQueryResource, mutationResource, noDedupe, provideCircuitBreakerDefaultOptions, provideMutationResourceOptions, provideQueryCache, provideQueryResourceOptions, provideResourceOptions, provideTypedResourceOptions, queryResource };
1277
+ export type { CacheEntry, CleanupType, CommonResourceOptions, DisabledReason, InfiniteQueryResourceOptions, InfiniteQueryResourceRef, InfiniteRequestContext, ManualQueryResourceRef, MutationCancellationReason, MutationQueueOptions, MutationResourceOptions, MutationResourceRef, QueryResourceOptions, QueryResourceRef, RefreshOptions, RequestContext, ResourceCacheOptions, ResourceRequestFn, TransitionRegistration };