@mmstack/resource 22.1.4 → 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/README.md +50 -5
- package/fesm2022/mmstack-resource.mjs +118 -109
- package/fesm2022/mmstack-resource.mjs.map +1 -1
- package/package.json +1 -1
- package/types/mmstack-resource.d.ts +61 -12
package/package.json
CHANGED
|
@@ -1049,14 +1049,38 @@ 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
|
-
* @
|
|
1053
|
-
*
|
|
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
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
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
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Object form of the `queue` option. Enabling the queue serializes mutations
|
|
1076
|
+
* into a FIFO that runs one-at-a-time.
|
|
1077
|
+
*/
|
|
1078
|
+
type MutationQueueOptions = {
|
|
1079
|
+
/**
|
|
1080
|
+
* Reactive queue key. When its returned value changes, the *pending* (not-yet-fired)
|
|
1081
|
+
* queued mutations are dropped; an in-flight mutation is unaffected. e.g. `key: () => selectedId()`.
|
|
1082
|
+
*/
|
|
1083
|
+
key?: () => string | number;
|
|
1060
1084
|
};
|
|
1061
1085
|
/**
|
|
1062
1086
|
* Options for configuring a `mutationResource`. Inherits from
|
|
@@ -1109,10 +1133,13 @@ type MutationResourceOptions<TResult, TRaw = TResult, TMutation = TResult, TCTX
|
|
|
1109
1133
|
*/
|
|
1110
1134
|
onSettled?: (ctx: NoInfer<TCTX>) => void;
|
|
1111
1135
|
/**
|
|
1112
|
-
*
|
|
1136
|
+
* Queue mutations and run them one-at-a-time in series, instead of latest-wins
|
|
1137
|
+
* superseding (e.g. while offline or the circuit breaker is open). Pass
|
|
1138
|
+
* {@link MutationQueueOptions} for a reactive `key` that resets the pending queue.
|
|
1139
|
+
* The pending queue can also be cleared via `ref.clearQueue()`.
|
|
1113
1140
|
* @default false
|
|
1114
1141
|
*/
|
|
1115
|
-
queue?: boolean;
|
|
1142
|
+
queue?: boolean | MutationQueueOptions;
|
|
1116
1143
|
/**
|
|
1117
1144
|
* Cache entries to invalidate after a SUCCESSFUL mutation — the declarative
|
|
1118
1145
|
* alternative to calling `injectQueryCache().invalidatePrefix(...)` in `onSuccess`.
|
|
@@ -1167,11 +1194,28 @@ type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Omit<Quer
|
|
|
1167
1194
|
* @param ctx An optional initial context value that will be passed to the `onMutate` callback.
|
|
1168
1195
|
*/
|
|
1169
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>;
|
|
1170
1209
|
/**
|
|
1171
1210
|
* A signal that holds the current mutation request, or `null` if no mutation is in progress.
|
|
1172
1211
|
* This can be useful for tracking the state of the mutation or for displaying loading indicators.
|
|
1173
1212
|
*/
|
|
1174
1213
|
current: Signal<TMutation | null>;
|
|
1214
|
+
/**
|
|
1215
|
+
* Drops all *pending* queued mutations; an in-flight mutation is unaffected.
|
|
1216
|
+
* Noops when `queue` is not enabled.
|
|
1217
|
+
*/
|
|
1218
|
+
clearQueue: () => void;
|
|
1175
1219
|
};
|
|
1176
1220
|
/**
|
|
1177
1221
|
* Creates a resource for performing mutations (e.g., POST, PUT, PATCH, DELETE requests).
|
|
@@ -1222,7 +1266,12 @@ type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Omit<Quer
|
|
|
1222
1266
|
* );
|
|
1223
1267
|
* ```
|
|
1224
1268
|
*/
|
|
1225
|
-
declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX
|
|
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>;
|
|
1226
1275
|
|
|
1227
|
-
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 };
|
|
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 };
|