@mmstack/resource 19.6.5 → 19.6.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 +106 -104
- package/fesm2022/mmstack-resource.mjs.map +1 -1
- package/lib/mutation-resource.d.ts +39 -10
- package/package.json +1 -1
|
@@ -2,15 +2,28 @@ import { type HttpResourceRequest } from '@angular/common/http';
|
|
|
2
2
|
import { type Provider, type Signal, type ValueEqualityFn } from '@angular/core';
|
|
3
3
|
import { type QueryResourceOptions, type QueryResourceRef } from './query-resource';
|
|
4
4
|
/**
|
|
5
|
-
* @
|
|
6
|
-
*
|
|
5
|
+
* Why a {@link MutationResourceRef.mutateAsync} promise was cancelled — a closed
|
|
6
|
+
* set so consumers can branch on the cause without parsing the message:
|
|
7
|
+
* - `'superseded'`: a newer mutation replaced it (latest-wins).
|
|
8
|
+
* - `'queue-cleared'`: dropped from the queue by `clearQueue()`.
|
|
9
|
+
* - `'queue-key-changed'`: dropped from the queue by a reactive `key` change.
|
|
10
|
+
* - `'destroyed'`: the resource was destroyed while it was pending/in flight.
|
|
11
|
+
* - `'no-request'`: `request()` returned `undefined`, so nothing was sent.
|
|
7
12
|
*/
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
export type MutationCancellationReason = 'superseded' | 'queue-cleared' | 'queue-key-changed' | 'destroyed' | 'no-request';
|
|
14
|
+
/**
|
|
15
|
+
* Rejection reason for a {@link MutationResourceRef.mutateAsync} promise whose
|
|
16
|
+
* mutation never completed. The {@link MutationCancelledError.type} discriminant
|
|
17
|
+
* carries the cause ({@link MutationCancellationReason}); the message is a
|
|
18
|
+
* human-readable elaboration of it.
|
|
19
|
+
*
|
|
20
|
+
* Only `mutateAsync` promises reject with this; plain `mutate()` calls have no
|
|
21
|
+
* promise and so produce no (potentially unhandled) rejection.
|
|
22
|
+
*/
|
|
23
|
+
export declare class MutationCancelledError extends Error {
|
|
24
|
+
readonly type: MutationCancellationReason;
|
|
25
|
+
constructor(type: MutationCancellationReason, message: string);
|
|
26
|
+
}
|
|
14
27
|
/**
|
|
15
28
|
* Object form of the `queue` option. Enabling the queue serializes mutations
|
|
16
29
|
* into a FIFO that runs one-at-a-time.
|
|
@@ -134,6 +147,18 @@ export type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Om
|
|
|
134
147
|
* @param ctx An optional initial context value that will be passed to the `onMutate` callback.
|
|
135
148
|
*/
|
|
136
149
|
mutate: (value: TMutation, ctx?: TICTX) => void;
|
|
150
|
+
/**
|
|
151
|
+
* Executes the mutation and returns a `Promise`
|
|
152
|
+
*
|
|
153
|
+
* If the mutation never completes — superseded by a newer `mutate`/`mutateAsync`
|
|
154
|
+
* (latest-wins), dropped from the queue (`clearQueue` / queue `key` change),
|
|
155
|
+
* abandoned on `destroy()`, or its `request()` returned `undefined` — the
|
|
156
|
+
* promise rejects with a {@link MutationCancelledError}.
|
|
157
|
+
*
|
|
158
|
+
* @param value The mutation value (usually the request body).
|
|
159
|
+
* @param ctx An optional initial context value that will be passed to the `onMutate` callback.
|
|
160
|
+
*/
|
|
161
|
+
mutateAsync: (value: TMutation, ctx?: TICTX) => Promise<TResult>;
|
|
137
162
|
/**
|
|
138
163
|
* A signal that holds the current mutation request, or `null` if no mutation is in progress.
|
|
139
164
|
* This can be useful for tracking the state of the mutation or for displaying loading indicators.
|
|
@@ -194,5 +219,9 @@ export type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Om
|
|
|
194
219
|
* );
|
|
195
220
|
* ```
|
|
196
221
|
*/
|
|
197
|
-
export declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX
|
|
198
|
-
|
|
222
|
+
export declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX>(request: (params: TMutation) => (Omit<HttpResourceRequest, 'body' | 'method'> & {
|
|
223
|
+
method: 'DELETE' | 'delete';
|
|
224
|
+
}) | undefined | void, options0?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
|
|
225
|
+
export declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX>(request: (params: TMutation) => (Omit<HttpResourceRequest, 'body'> & {
|
|
226
|
+
body: TMutation;
|
|
227
|
+
}) | undefined | void, options0?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
|