Skip to content

Commit a151d38

Browse files
committed
docs: document SortRelatedRecordsMutation and the Mutation union
1 parent 78cb16b commit a151d38

1 file changed

Lines changed: 43 additions & 15 deletions

File tree

warp-drive-packages/core/src/types/cache/mutations.ts

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2+
import type { Cache } from '../cache.ts';
13
import type { ResourceKey } from '../identifier.ts';
4+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5+
import type { Operation } from './operations.ts';
26

37
export interface AddToResourceRelationshipMutation {
48
op: 'add';
@@ -43,27 +47,51 @@ export interface ReplaceRelatedRecordsMutation {
4347
index?: number;
4448
}
4549

50+
/**
51+
* Reorders the local (uncommitted) state of a `to-many` relationship.
52+
*/
4653
export interface SortRelatedRecordsMutation {
54+
/**
55+
* The name of the mutation
56+
*/
4757
op: 'sortRelatedRecords';
58+
/**
59+
* The cache key for the resource whose relationship is being reordered
60+
*/
4861
record: ResourceKey;
62+
/**
63+
* The name of the relationship to reorder
64+
*/
4965
field: string;
66+
/**
67+
* The relationship's members in their new order
68+
*/
5069
value: ResourceKey[];
5170
}
52-
// A Mutation is an action that updates
53-
// the local state of the Cache in some
54-
// manner.
55-
// Most Mutations are in theory also
56-
// Operations; with the difference being
57-
// that the change should be applied as
58-
// "local" or "dirty" state instead of
59-
// as "remote" or "clean" state.
60-
//
61-
// Note: this RFC does not publicly surface
62-
// any of the mutations listed here as
63-
// "operations", though the (private) Graph
64-
// already expects and utilizes these.
65-
// and we look forward to an RFC that makes
66-
// the Graph a fully public API.
71+
72+
/**
73+
* A `Mutation` is an action that updates the local (uncommitted or "dirty")
74+
* state of the {@link Cache} in some manner.
75+
*
76+
* Most Mutations are in theory also {@link Operation | Operations}; the
77+
* difference is that the change should be applied as local/dirty state
78+
* instead of as remote/clean state.
79+
*
80+
* Mutations are applied via {@link Cache.mutate}.
81+
*
82+
* See also:
83+
* - {@link ReplaceRelatedRecordsMutation}
84+
* - {@link ReplaceRelatedRecordMutation}
85+
* - {@link RemoveFromResourceRelationshipMutation}
86+
* - {@link AddToResourceRelationshipMutation}
87+
* - {@link SortRelatedRecordsMutation}
88+
*
89+
* @privateRemarks
90+
* Note: this RFC does not publicly surface any of the mutations listed
91+
* here as "operations", though the (private) Graph already expects and
92+
* utilizes these, and we look forward to an RFC that makes the Graph a
93+
* fully public API.
94+
*/
6795
export type Mutation =
6896
| ReplaceRelatedRecordsMutation
6997
| ReplaceRelatedRecordMutation

0 commit comments

Comments
 (0)