@nkzw/fate 0.0.1
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/LICENSE +21 -0
- package/README.md +995 -0
- package/lib/cli.d.mts +1 -0
- package/lib/cli.mjs +195 -0
- package/lib/index.d.mts +585 -0
- package/lib/index.mjs +1842 -0
- package/lib/record-DnhZuvUe.mjs +5 -0
- package/lib/server.d.mts +163 -0
- package/lib/server.mjs +439 -0
- package/package.json +55 -0
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import { TRPCClient } from "@trpc/client";
|
|
2
|
+
import { AnyRouter } from "@trpc/server";
|
|
3
|
+
|
|
4
|
+
//#region src/mask.d.ts
|
|
5
|
+
type FieldMask = {
|
|
6
|
+
all: boolean;
|
|
7
|
+
children: Map<string, FieldMask>;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/types.d.ts
|
|
11
|
+
/** Canonical runtime name for an entity type as returned by the server. */
|
|
12
|
+
type TypeName = string;
|
|
13
|
+
/** Globally unique identifier for an entity in the normalized cache (`<TypeName>:<id>` format). */
|
|
14
|
+
type EntityId = string;
|
|
15
|
+
/** Internal marker added to objects that represent a view payload. */
|
|
16
|
+
declare const ViewKind: unique symbol;
|
|
17
|
+
/** Symbol used to attach the set of view tags that were spread into a ref or masked record. */
|
|
18
|
+
declare const ViewsTag: unique symbol;
|
|
19
|
+
/** Symbol attached to connection results so pagination helpers can find their metadata. */
|
|
20
|
+
declare const ConnectionTag: unique symbol;
|
|
21
|
+
declare const __FateEntityBrand: unique symbol;
|
|
22
|
+
declare const __FateSelectionBrand: unique symbol;
|
|
23
|
+
declare const __FateMutationEntityBrand: unique symbol;
|
|
24
|
+
declare const __FateMutationInputBrand: unique symbol;
|
|
25
|
+
declare const __FateMutationResultBrand: unique symbol;
|
|
26
|
+
type __ViewEntityAnchor<T$1 extends Entity> = {
|
|
27
|
+
readonly [__FateEntityBrand]?: T$1;
|
|
28
|
+
};
|
|
29
|
+
type __ViewSelectionAnchor<S$1> = {
|
|
30
|
+
[__FateSelectionBrand]?: S$1;
|
|
31
|
+
};
|
|
32
|
+
type __MutationEntityAnchor<T$1 extends Entity> = {
|
|
33
|
+
readonly [__FateMutationEntityBrand]?: T$1;
|
|
34
|
+
};
|
|
35
|
+
type __MutationInputAnchor<I$1> = {
|
|
36
|
+
readonly [__FateMutationInputBrand]?: I$1;
|
|
37
|
+
};
|
|
38
|
+
type __MutationResultAnchor<R$1> = {
|
|
39
|
+
readonly [__FateMutationResultBrand]?: R$1;
|
|
40
|
+
};
|
|
41
|
+
/** Unique key that identifies a view composition entry inside a selection or reference. */
|
|
42
|
+
type ViewTag = `__fate-view__${string}`;
|
|
43
|
+
/** Determines whether a property key is a fate view tag. */
|
|
44
|
+
declare function isViewTag(key: string): key is ViewTag;
|
|
45
|
+
/** Alias for a loose record used throughout the fate's internals. */
|
|
46
|
+
type AnyRecord = Record<string, unknown>;
|
|
47
|
+
type SelectionArgs = Readonly<{
|
|
48
|
+
args: AnyRecord;
|
|
49
|
+
}>;
|
|
50
|
+
/** Metadata stored alongside connection results to power pagination and cache updates. */
|
|
51
|
+
type ConnectionMetadata = Readonly<{
|
|
52
|
+
args?: AnyRecord;
|
|
53
|
+
field: string;
|
|
54
|
+
hash?: string;
|
|
55
|
+
key: string;
|
|
56
|
+
owner: EntityId;
|
|
57
|
+
procedure: string;
|
|
58
|
+
root?: boolean;
|
|
59
|
+
type: string;
|
|
60
|
+
}>;
|
|
61
|
+
/** Reference to a normalized entity instance that can be resolved against one or more view tags. */
|
|
62
|
+
type ViewRef<TName extends string> = Readonly<{
|
|
63
|
+
__typename: TName;
|
|
64
|
+
id: string | number;
|
|
65
|
+
[ViewsTag]: Set<string>;
|
|
66
|
+
}>;
|
|
67
|
+
/** Describes how a field relates to another entity for normalization. */
|
|
68
|
+
type RelationDescriptor = /** Field stores a scalar value that does not link to another type. */
|
|
69
|
+
'scalar'
|
|
70
|
+
/** Field points to a single entity of the given type. */ | {
|
|
71
|
+
type: string;
|
|
72
|
+
}
|
|
73
|
+
/** Field holds a list of entities of the given type. */ | {
|
|
74
|
+
listOf: string;
|
|
75
|
+
};
|
|
76
|
+
/** Configuration for a server entity type used by the client cache. */
|
|
77
|
+
type TypeConfig = {
|
|
78
|
+
fields?: Record<string, RelationDescriptor>;
|
|
79
|
+
getId: (record: unknown) => string | number;
|
|
80
|
+
type: string;
|
|
81
|
+
};
|
|
82
|
+
/** Pagination state returned alongside connection lists. */
|
|
83
|
+
type Pagination = {
|
|
84
|
+
hasNext: boolean;
|
|
85
|
+
hasPrevious: boolean;
|
|
86
|
+
nextCursor?: string;
|
|
87
|
+
previousCursor?: string;
|
|
88
|
+
};
|
|
89
|
+
/** Ref for a connection, including pagination metadata. */
|
|
90
|
+
type ConnectionRef<TName extends string> = Readonly<{
|
|
91
|
+
items: ReadonlyArray<{
|
|
92
|
+
cursor?: string;
|
|
93
|
+
node: ViewRef<TName>;
|
|
94
|
+
}>;
|
|
95
|
+
pagination?: Pagination;
|
|
96
|
+
}>;
|
|
97
|
+
/** Base shape shared by all entities fetched by fate. */
|
|
98
|
+
type Entity = {
|
|
99
|
+
__typename: string;
|
|
100
|
+
};
|
|
101
|
+
type PlainObjectSelectionField<V> = V extends Array<infer U> ? PlainObjectSelectionField<U> | true : V extends AnyRecord ? PlainObjectSelection<V> | true : true;
|
|
102
|
+
type PlainObjectSelection<T$1> = { [K in keyof T$1]?: PlainObjectSelectionField<T$1[K]> };
|
|
103
|
+
type ConnectionSelectionBase<T$1 extends Entity> = Readonly<{
|
|
104
|
+
items: Readonly<{
|
|
105
|
+
cursor?: true;
|
|
106
|
+
node: Selection<T$1> | View<T$1, Selection<T$1>>;
|
|
107
|
+
}>;
|
|
108
|
+
pagination?: Readonly<{
|
|
109
|
+
hasNext?: true;
|
|
110
|
+
hasPrevious?: true;
|
|
111
|
+
nextCursor?: true;
|
|
112
|
+
previousCursor?: true;
|
|
113
|
+
}>;
|
|
114
|
+
}>;
|
|
115
|
+
/** Selection shape for a connection-style list, including pagination metadata and optional arguments. */
|
|
116
|
+
type ConnectionSelection<T$1 extends Entity> = ConnectionSelectionBase<T$1> | (SelectionArgs & ConnectionSelectionBase<T$1>);
|
|
117
|
+
type BaseSelectionFieldValue<T$1 extends Entity, K$1 extends keyof T$1> = NonNullable<T$1[K$1]> extends Array<infer U extends Entity> ? true | Selection<U> | ConnectionSelection<U> | View<U, Selection<U>> : NonNullable<T$1[K$1]> extends Entity ? true | Selection<NonNullable<T$1[K$1]>> | View<NonNullable<T$1[K$1]>, Selection<NonNullable<T$1[K$1]>>> : NonNullable<T$1[K$1]> extends AnyRecord ? PlainObjectSelection<NonNullable<T$1[K$1]>> : true;
|
|
118
|
+
type SelectionFieldValue<T$1 extends Entity, K$1 extends keyof T$1> = BaseSelectionFieldValue<T$1, K$1> | SelectionArgs | (SelectionArgs & Extract<BaseSelectionFieldValue<T$1, K$1>, object>);
|
|
119
|
+
type SelectionShape<T$1 extends Entity> = { [K in keyof T$1 as K extends '__typename' ? never : K]?: SelectionFieldValue<T$1, K> } & {
|
|
120
|
+
__typename?: true;
|
|
121
|
+
};
|
|
122
|
+
type SelectionViewSpread<T$1 extends Entity> = { readonly [K in ViewTag]?: Readonly<{
|
|
123
|
+
select: Selection<T$1>;
|
|
124
|
+
[ViewKind]: true;
|
|
125
|
+
}> };
|
|
126
|
+
/** Declarative selection of the fields a view needs from an entity. */
|
|
127
|
+
type Selection<T$1 extends Entity> = SelectionShape<T$1> & SelectionViewSpread<T$1>;
|
|
128
|
+
/** View payload stored on a view tag containing the raw selection used to mask data. */
|
|
129
|
+
type ViewPayload<T$1 extends Entity, S$1 extends Selection<T$1> = Selection<T$1>> = Readonly<{
|
|
130
|
+
select: S$1;
|
|
131
|
+
[ViewKind]: true;
|
|
132
|
+
}>;
|
|
133
|
+
/** Definition of a view over an entity type, including the selection of fields. */
|
|
134
|
+
type View<T$1 extends Entity, S$1 extends Selection<T$1> = Selection<T$1>> = Readonly<{
|
|
135
|
+
[viewTag: ViewTag]: ViewPayload<T$1, S$1>;
|
|
136
|
+
}> & __ViewEntityAnchor<T$1> & __ViewSelectionAnchor<S$1>;
|
|
137
|
+
type HasViewTag<S$1> = S$1 extends { [K in ViewTag]?: infer P } ? P extends {
|
|
138
|
+
[ViewKind]: true;
|
|
139
|
+
} ? true : false : false;
|
|
140
|
+
/**
|
|
141
|
+
* Data returned from a resolved view with masking applied and view tags
|
|
142
|
+
* attached for downstream composition.
|
|
143
|
+
*/
|
|
144
|
+
type ViewData<T$1 extends Entity, S$1 extends Selection<T$1>> = Readonly<(S$1 extends Selection<T$1> ? Mask<T$1, S$1> : T$1) & {
|
|
145
|
+
[ViewsTag]: Set<string>;
|
|
146
|
+
}>;
|
|
147
|
+
/**
|
|
148
|
+
* Snapshot returned by the cache for a view, including the masked data and all
|
|
149
|
+
* referenced entity IDs.
|
|
150
|
+
*/
|
|
151
|
+
type ViewSnapshot<T$1 extends Entity, S$1 extends Selection<T$1>> = Readonly<{
|
|
152
|
+
coverage: ReadonlyArray<readonly [id: EntityId, paths: ReadonlySet<string>]>;
|
|
153
|
+
data: ViewData<T$1, S$1>;
|
|
154
|
+
}>;
|
|
155
|
+
type ConnectionMask<T$1 extends Entity, S$1> = S$1 extends {
|
|
156
|
+
items: infer ItemSelection;
|
|
157
|
+
pagination?: infer PaginationSelection;
|
|
158
|
+
} ? {
|
|
159
|
+
items: ItemSelection extends {
|
|
160
|
+
cursor?: infer CursorSelection;
|
|
161
|
+
node: unknown;
|
|
162
|
+
} ? Array<(CursorSelection extends true ? {
|
|
163
|
+
cursor: string;
|
|
164
|
+
} : Record<string, never>) & {
|
|
165
|
+
node: ViewRef<T$1['__typename']>;
|
|
166
|
+
}> : Array<{
|
|
167
|
+
node: ViewRef<T$1['__typename']>;
|
|
168
|
+
}>;
|
|
169
|
+
} & (PaginationSelection extends object ? {
|
|
170
|
+
pagination: { [K in keyof PaginationSelection]: Pagination[K & keyof Pagination] };
|
|
171
|
+
} : Record<string, never>) : Array<T$1>;
|
|
172
|
+
type EntityName<T$1> = T$1 extends {
|
|
173
|
+
__typename: infer N extends string;
|
|
174
|
+
} ? N : never;
|
|
175
|
+
/** Recursively applies a view selection to an entity to mask fields that aren't selected. */
|
|
176
|
+
type Mask<T$1, S$1> = T$1 extends Array<infer U extends Entity> ? S$1 extends true ? Array<U> : S$1 extends ConnectionSelection<U> ? ConnectionMask<U, S$1> : HasViewTag<S$1> extends true ? Array<ViewRef<U['__typename']>> : Array<Mask<U, S$1>> : S$1 extends true ? T$1 : S$1 extends object ? HasViewTag<S$1> extends true ? ViewRef<EntityName<NonNullable<T$1>>> : { [K in keyof S$1 as K extends 'args' ? never : K]: S$1[K] extends true ? NonNullable<T$1>[Extract<K, keyof T$1>] : Mask<NonNullable<T$1>[Extract<K, keyof T$1>], Extract<S$1[K], object>> } & (T$1 extends Entity ? Pick<NonNullable<T$1>, '__typename'> : Record<never, never>) : T$1;
|
|
177
|
+
/** Entity type captured from a view definition. */
|
|
178
|
+
type ViewEntity<V> = V extends View<infer T, any> ? T : never;
|
|
179
|
+
/** Name of the entity type captured from a view definition. */
|
|
180
|
+
type ViewEntityName<V> = ViewEntity<V>['__typename'] & string;
|
|
181
|
+
/** Selection captured from a view definition. */
|
|
182
|
+
type ViewSelection<V> = V extends {
|
|
183
|
+
readonly [__FateSelectionBrand]?: infer S;
|
|
184
|
+
} ? S : never;
|
|
185
|
+
/** Definition of a list request for fetching data from the backend. */
|
|
186
|
+
type ListItem<V extends View<any, any>> = Readonly<{
|
|
187
|
+
args?: Record<string, unknown>;
|
|
188
|
+
root: V;
|
|
189
|
+
type: ViewEntityName<V>;
|
|
190
|
+
}>;
|
|
191
|
+
/** Definition of a node request with one explicit ID for fetching data from the backend. */
|
|
192
|
+
type NodeItem<V extends View<any, any>> = Readonly<{
|
|
193
|
+
id: string | number;
|
|
194
|
+
root: V;
|
|
195
|
+
type: ViewEntityName<V>;
|
|
196
|
+
}>;
|
|
197
|
+
/** Definition of a node request with explicit IDs for fetching data from the backend. */
|
|
198
|
+
type NodesItem<V extends View<any, any>> = Readonly<{
|
|
199
|
+
ids: ReadonlyArray<string | number>;
|
|
200
|
+
root: V;
|
|
201
|
+
type: ViewEntityName<V>;
|
|
202
|
+
}>;
|
|
203
|
+
type RequestItem = ListItem<View<any, any>> | NodeItem<View<any, any>> | NodesItem<View<any, any>>;
|
|
204
|
+
/** Collection of node and list requests describing the data a screen needs. */
|
|
205
|
+
type Request = Record<string, RequestItem>;
|
|
206
|
+
type AnyView = View<any, any>;
|
|
207
|
+
type AnyListItem = ListItem<AnyView>;
|
|
208
|
+
type AnyNodeItem = NodeItem<AnyView>;
|
|
209
|
+
type AnyNodesItem = NodesItem<AnyView>;
|
|
210
|
+
type AnyRequestItem = AnyListItem | AnyNodeItem | AnyNodesItem;
|
|
211
|
+
type AnyRequest = Record<string, AnyRequestItem>;
|
|
212
|
+
/**
|
|
213
|
+
* Typed result returned by `useRequest` and `FateClient.request`, mapping each
|
|
214
|
+
* request key to an array of view refs for the requested type.
|
|
215
|
+
*/
|
|
216
|
+
type ConnectionNodeType<Root> = Root extends {
|
|
217
|
+
items?: {
|
|
218
|
+
node?: infer Node;
|
|
219
|
+
};
|
|
220
|
+
} ? ViewEntityName<Node & View<any, any>> : never;
|
|
221
|
+
type ListResult<Item extends AnyRequestItem> = Item extends AnyNodeItem ? ViewRef<Item['type']> : Item extends AnyNodesItem ? Array<ViewRef<Item['type']>> : Item extends AnyListItem ? Item['root'] extends {
|
|
222
|
+
items?: {
|
|
223
|
+
node?: View<any, any>;
|
|
224
|
+
};
|
|
225
|
+
} ? Readonly<{
|
|
226
|
+
items: ReadonlyArray<{
|
|
227
|
+
cursor?: string | undefined;
|
|
228
|
+
node: ViewRef<ConnectionNodeType<Item['root']>>;
|
|
229
|
+
}>;
|
|
230
|
+
pagination?: Pagination;
|
|
231
|
+
}> : Array<ViewRef<Item['type']>> : never;
|
|
232
|
+
/**
|
|
233
|
+
* The result of a `FateClient.request` and `useRequest` call, mapping each
|
|
234
|
+
* request key to its corresponding result.
|
|
235
|
+
*/
|
|
236
|
+
type RequestResult<Q extends AnyRequest> = { [K in keyof Q]: ListResult<Q[K]> };
|
|
237
|
+
/** Brand used on mutation definitions to mark their identity in the d.ts output. */
|
|
238
|
+
declare const MutationKind = "__fate__mutation";
|
|
239
|
+
/** Metadata describing a mutation for a particular entity, input, and output. */
|
|
240
|
+
type MutationDefinition<T$1 extends Entity, I$1, R$1> = Readonly<{
|
|
241
|
+
entity: T$1['__typename'];
|
|
242
|
+
[MutationKind]: true;
|
|
243
|
+
}> & __MutationEntityAnchor<T$1> & __MutationInputAnchor<I$1> & __MutationResultAnchor<R$1>;
|
|
244
|
+
type MutationIdentifier<T$1 extends Entity, I$1, R$1> = MutationDefinition<T$1, I$1, R$1> & Readonly<{
|
|
245
|
+
key: string;
|
|
246
|
+
}>;
|
|
247
|
+
/** Extracts the input type from a mutation definition or identifier. */
|
|
248
|
+
type MutationInput<M> = M extends __MutationInputAnchor<infer I> ? I : never;
|
|
249
|
+
/** Extracts the result type from a mutation definition or identifier. */
|
|
250
|
+
type MutationResult<M> = M extends __MutationResultAnchor<infer R> ? R : never;
|
|
251
|
+
/** Extracts the entity type from a mutation definition or identifier. */
|
|
252
|
+
type MutationEntity<M> = M extends __MutationEntityAnchor<infer E> ? E : never;
|
|
253
|
+
/** Minimal mutation description used for transport typing. */
|
|
254
|
+
type MutationShape = {
|
|
255
|
+
input: unknown;
|
|
256
|
+
output: unknown;
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Convenience helper that maps mutation definitions to their input/output
|
|
260
|
+
* shapes for use by transports.
|
|
261
|
+
*/
|
|
262
|
+
type MutationMapFromDefinitions<D extends Record<string, MutationDefinition<any, any, any>>> = { [K in keyof D]: {
|
|
263
|
+
input: MutationInput<D[K]>;
|
|
264
|
+
output: MutationResult<D[K]>;
|
|
265
|
+
} };
|
|
266
|
+
type Nullish<T$1> = Extract<T$1, null | undefined>;
|
|
267
|
+
type NonNullish<T$1> = Exclude<T$1, null | undefined>;
|
|
268
|
+
type OptimisticUpdateValue<T$1> = T$1 extends ReadonlyArray<infer U> ? Array<OptimisticUpdateValue<U>> : NonNullish<T$1> extends AnyRecord ? OptimisticUpdate<NonNullish<T$1>> | Nullish<T$1> : NonNullish<T$1> | Nullish<T$1>;
|
|
269
|
+
/** Shape used to describe optimistic updates for mutations. */
|
|
270
|
+
type OptimisticUpdate<T$1> = { [K in keyof T$1]?: OptimisticUpdateValue<T$1[K]> };
|
|
271
|
+
/** Snapshot captured before mutating the cache, used to roll back on errors. */
|
|
272
|
+
type Snapshot = Readonly<{
|
|
273
|
+
mask?: FieldMask;
|
|
274
|
+
record?: AnyRecord;
|
|
275
|
+
}>;
|
|
276
|
+
/** Promise-like value returned by cache reads that already have a resolved payload for React `use`. */
|
|
277
|
+
interface FateThenable<T$1> extends PromiseLike<T$1> {
|
|
278
|
+
status: 'fulfilled';
|
|
279
|
+
value: T$1;
|
|
280
|
+
}
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/mutation.d.ts
|
|
283
|
+
/**
|
|
284
|
+
* Defines a mutation for a given entity type, preserving the input and output
|
|
285
|
+
* types for transports.
|
|
286
|
+
*/
|
|
287
|
+
declare function mutation<T$1 extends Entity, I$1, R$1>(entity: T$1['__typename']): MutationDefinition<T$1, I$1, R$1>;
|
|
288
|
+
/**
|
|
289
|
+
* Options accepted by a mutation invocation, including optimistic updates and
|
|
290
|
+
* optional selection for the returned payload.
|
|
291
|
+
*/
|
|
292
|
+
type MutationOptions<Identifier extends MutationIdentifier<any, any, any>> = {
|
|
293
|
+
/** Optional arguments to pass to the mutation resolver. */
|
|
294
|
+
args?: Record<string, unknown>;
|
|
295
|
+
/** If true, deletes the record with the ID specified in the input. */
|
|
296
|
+
delete?: boolean;
|
|
297
|
+
/** Input data for the mutation. */
|
|
298
|
+
input: Omit<MutationInput<Identifier>, 'select'>;
|
|
299
|
+
/** Optional optimistic update to apply immediately. */
|
|
300
|
+
optimistic?: OptimisticUpdate<MutationResult<Identifier>>;
|
|
301
|
+
/** Optional view specifying which fields to select from the server. */
|
|
302
|
+
view?: View<MutationEntity<Identifier>, Selection<MutationEntity<Identifier>>>;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Callable mutation entry point returned on the client that resolves to either
|
|
306
|
+
* a successful result or an error.
|
|
307
|
+
*/
|
|
308
|
+
type MutationFunction<I$1 extends MutationIdentifier<any, any, any>> = (options: MutationOptions<I$1>) => Promise<{
|
|
309
|
+
error: undefined;
|
|
310
|
+
result: MutationResult<I$1>;
|
|
311
|
+
} | {
|
|
312
|
+
error: Error;
|
|
313
|
+
result: undefined;
|
|
314
|
+
}>;
|
|
315
|
+
/**
|
|
316
|
+
* React action-compatible wrapper that can be passed directly to form actions
|
|
317
|
+
* or transitions.
|
|
318
|
+
*/
|
|
319
|
+
type MutationAction<I$1 extends MutationIdentifier<any, any, any>> = (previousState: unknown,
|
|
320
|
+
/**
|
|
321
|
+
* Mutation options or 'reset' to reset the action state.
|
|
322
|
+
*/
|
|
323
|
+
options: MutationOptions<I$1> | 'reset') => Promise<{
|
|
324
|
+
error: undefined;
|
|
325
|
+
result: MutationResult<I$1>;
|
|
326
|
+
} | {
|
|
327
|
+
error: Error;
|
|
328
|
+
result: undefined;
|
|
329
|
+
}>;
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/selection.d.ts
|
|
332
|
+
/**
|
|
333
|
+
* Representation of a composed selection including hashed args and the
|
|
334
|
+
* flat set of field paths to read or fetch.
|
|
335
|
+
*/
|
|
336
|
+
type SelectionPlan = {
|
|
337
|
+
readonly args: Map<string, Readonly<{
|
|
338
|
+
hash: string;
|
|
339
|
+
ignoreKeys?: ReadonlySet<string>;
|
|
340
|
+
value: AnyRecord;
|
|
341
|
+
}>>;
|
|
342
|
+
readonly paths: Set<string>;
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Flattens a view into a `SelectionPlan`, expanding composed views and
|
|
346
|
+
* partitioning nested args so the client can fetch exactly what is declared.
|
|
347
|
+
*/
|
|
348
|
+
declare const getSelectionPlan: <T$1 extends Entity, S$1 extends Selection<T$1>, V extends View<T$1, S$1>>(viewComposition: V, ref: ViewRef<T$1["__typename"]> | null) => SelectionPlan;
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/cache.d.ts
|
|
351
|
+
declare class ViewDataCache {
|
|
352
|
+
private cache;
|
|
353
|
+
private rootDependencies;
|
|
354
|
+
private dependencyIndex;
|
|
355
|
+
get<T$1 extends Entity, S$1 extends Selection<T$1>, V extends View<T$1, S$1>>(entityId: EntityId, view: V, ref: ViewRef<T$1['__typename']>): FateThenable<ViewSnapshot<T$1, S$1>> | null;
|
|
356
|
+
set<T$1 extends Entity, S$1 extends Selection<T$1>, V extends View<T$1, S$1>>(entityId: EntityId, view: V, ref: ViewRef<T$1['__typename']>, thenable: FateThenable<ViewSnapshot<T$1, S$1>>, dependencies: ReadonlySet<EntityId>): void;
|
|
357
|
+
invalidate(entityId: EntityId): void;
|
|
358
|
+
private invalidateDependents;
|
|
359
|
+
private delete;
|
|
360
|
+
}
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/store.d.ts
|
|
363
|
+
type List = Readonly<{
|
|
364
|
+
cursors?: ReadonlyArray<string | undefined>;
|
|
365
|
+
ids: ReadonlyArray<EntityId>;
|
|
366
|
+
pagination?: Pagination;
|
|
367
|
+
}>;
|
|
368
|
+
declare class Store {
|
|
369
|
+
private coverage;
|
|
370
|
+
private lists;
|
|
371
|
+
private records;
|
|
372
|
+
private subscriptions;
|
|
373
|
+
private listSubscriptions;
|
|
374
|
+
read(id: EntityId): AnyRecord | undefined;
|
|
375
|
+
merge(id: EntityId, partial: AnyRecord, paths: Iterable<string>): void;
|
|
376
|
+
private mergeInternal;
|
|
377
|
+
deleteRecord(id: EntityId): void;
|
|
378
|
+
missingForSelection(id: EntityId, paths: Iterable<string>): Set<string>;
|
|
379
|
+
subscribe(id: EntityId, selection: ReadonlySet<string> | null, fn: () => void): () => void;
|
|
380
|
+
subscribe(id: EntityId, fn: () => void): () => void;
|
|
381
|
+
private notify;
|
|
382
|
+
private notifyListSubscribers;
|
|
383
|
+
getList(key: string): ReadonlyArray<EntityId> | undefined;
|
|
384
|
+
getListState(key: string): List | undefined;
|
|
385
|
+
getListsForField(ownerId: EntityId, field: string): Array<readonly [string, List]>;
|
|
386
|
+
setList(key: string, state: List): void;
|
|
387
|
+
restoreList(key: string, list?: List): void;
|
|
388
|
+
subscribeList(key: string, fn: () => void): () => void;
|
|
389
|
+
removeReferencesTo(targetId: EntityId, viewDataCache: ViewDataCache, snapshots?: Map<EntityId, Snapshot>, listSnapshots?: Map<string, List>): void;
|
|
390
|
+
snapshot(id: EntityId): Snapshot;
|
|
391
|
+
restore(id: EntityId, snapshot: Snapshot): void;
|
|
392
|
+
}
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/transport.d.ts
|
|
395
|
+
/**
|
|
396
|
+
* Normalized representation of args passed to a transport.
|
|
397
|
+
*/
|
|
398
|
+
type ResolvedArgsPayload = AnyRecord;
|
|
399
|
+
type TransportMutations = Record<string, MutationShape>;
|
|
400
|
+
type EmptyTransportMutations = Record<never, MutationShape>;
|
|
401
|
+
/**
|
|
402
|
+
* Contract the fate client expects from a network transport. The transport is
|
|
403
|
+
* responsible for fetching records by ID, fetching lists, and executing
|
|
404
|
+
* mutations with the provided selections.
|
|
405
|
+
*/
|
|
406
|
+
interface Transport<Mutations extends TransportMutations = EmptyTransportMutations> {
|
|
407
|
+
fetchById(type: string, ids: Array<string | number>, select: Iterable<string>, args?: ResolvedArgsPayload): Promise<Array<unknown>>;
|
|
408
|
+
fetchList?(proc: string, select: Iterable<string>, args?: ResolvedArgsPayload): Promise<{
|
|
409
|
+
items: Array<{
|
|
410
|
+
cursor: string | undefined;
|
|
411
|
+
node: unknown;
|
|
412
|
+
}>;
|
|
413
|
+
pagination: Pagination;
|
|
414
|
+
}>;
|
|
415
|
+
mutate?<K$1 extends Extract<keyof Mutations, string>>(proc: K$1, input: Mutations[K$1]['input'], select: Set<string>): Promise<Mutations[K$1]['output']>;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Mapping of entity type to tRPC procedures used for fetching entities by ID.
|
|
419
|
+
*/
|
|
420
|
+
type TRPCByIdResolvers<AppRouter extends AnyRouter> = Record<string, (client: TRPCClient<AppRouter>) => (input: {
|
|
421
|
+
args?: ResolvedArgsPayload;
|
|
422
|
+
ids: Array<string | number>;
|
|
423
|
+
select: Array<string>;
|
|
424
|
+
}) => Promise<Array<unknown>>>;
|
|
425
|
+
/**
|
|
426
|
+
* Mapping of list procedure name to a tRPC resolver factory.
|
|
427
|
+
*/
|
|
428
|
+
type TRPCListResolvers<AppRouter extends AnyRouter> = Record<string, (client: TRPCClient<AppRouter>) => (input: {
|
|
429
|
+
args?: ResolvedArgsPayload;
|
|
430
|
+
select: Array<string>;
|
|
431
|
+
}) => Promise<{
|
|
432
|
+
items: Array<{
|
|
433
|
+
cursor: string | undefined;
|
|
434
|
+
node: unknown;
|
|
435
|
+
}>;
|
|
436
|
+
pagination: Pagination;
|
|
437
|
+
}>>;
|
|
438
|
+
/**
|
|
439
|
+
* Mapping of a mutation procedure name to a tRPC resolver factory.
|
|
440
|
+
*/
|
|
441
|
+
type MutationResolver<AppRouter extends AnyRouter> = (client: TRPCClient<AppRouter>) => (input: any) => Promise<any>;
|
|
442
|
+
type TRPCMutationResolvers<AppRouter extends AnyRouter> = Record<string, MutationResolver<AppRouter>>;
|
|
443
|
+
type MutationMapFromResolvers<R$1 extends Record<string, MutationResolver<any>>> = { [K in keyof R$1]: R$1[K] extends ((client: any) => (input: infer Input) => Promise<infer Output>) ? {
|
|
444
|
+
input: Input;
|
|
445
|
+
output: Output;
|
|
446
|
+
} : never };
|
|
447
|
+
type EmptyMutationResolvers<AppRouter extends AnyRouter> = Record<never, MutationResolver<AppRouter>>;
|
|
448
|
+
/**
|
|
449
|
+
* Builds a `Transport` backed by a tRPC client using the configured resolvers
|
|
450
|
+
* for by-id queries, lists, and mutations.
|
|
451
|
+
*/
|
|
452
|
+
declare function createTRPCTransport<AppRouter extends AnyRouter, Mutations extends TRPCMutationResolvers<AppRouter> = EmptyMutationResolvers<AppRouter>>({
|
|
453
|
+
byId,
|
|
454
|
+
client,
|
|
455
|
+
lists,
|
|
456
|
+
mutations
|
|
457
|
+
}: {
|
|
458
|
+
byId: TRPCByIdResolvers<AppRouter>;
|
|
459
|
+
client: TRPCClient<AppRouter>;
|
|
460
|
+
lists?: TRPCListResolvers<AppRouter>;
|
|
461
|
+
mutations?: Mutations;
|
|
462
|
+
}): Transport<MutationMapFromResolvers<Mutations>>;
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/client.d.ts
|
|
465
|
+
/**
|
|
466
|
+
* Strategy used when resolving a request.
|
|
467
|
+
*/
|
|
468
|
+
type RequestMode = /** (default) Use cached data if present, otherwise fetch. */
|
|
469
|
+
'cache-first'
|
|
470
|
+
/** Show cached data immediately and refresh in the background. */ | 'stale-while-revalidate'
|
|
471
|
+
/** Always fetch from the network and ignore cached entries. */ | 'network-only';
|
|
472
|
+
/**
|
|
473
|
+
* Request options that affect how requests are fetched and retained.
|
|
474
|
+
*/
|
|
475
|
+
type RequestOptions = Readonly<{
|
|
476
|
+
mode?: RequestMode;
|
|
477
|
+
}>;
|
|
478
|
+
type MutationIdentifierFor<K$1 extends string, Def extends MutationDefinition<any, any, any>> = Def extends MutationDefinition<infer T, infer I, infer R> ? MutationIdentifier<T, I, R> & Readonly<{
|
|
479
|
+
key: K$1;
|
|
480
|
+
}> : never;
|
|
481
|
+
type MutationTransport<Mutations extends Record<string, MutationDefinition<any, any, any>>> = MutationMapFromDefinitions<Mutations>;
|
|
482
|
+
type UnionToIntersection<U$1> = (U$1 extends any ? (k: U$1) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
483
|
+
type NestedValue<Path extends string, Value> = Path extends `${infer Head}.${infer Tail}` ? { [K in Head]: NestedValue<Tail, Value> } : { [K in Path]: Value };
|
|
484
|
+
type MutationTreeFromRecord<Mutations extends Record<string, MutationDefinition<any, any, any>>, ValueMap extends Record<string, unknown>> = [keyof Mutations] extends [never] ? object : UnionToIntersection<{ [K in keyof Mutations & string]: NestedValue<K, ValueMap[K]> }[keyof Mutations & string]>;
|
|
485
|
+
type MutationFunctionsFor<Mutations extends Record<string, MutationDefinition<any, any, any>>> = MutationTreeFromRecord<Mutations, { [K in keyof Mutations & string]: MutationFunction<MutationIdentifierFor<K, Mutations[K]>> }>;
|
|
486
|
+
type MutationActionsFor<Mutations extends Record<string, MutationDefinition<any, any, any>>> = MutationTreeFromRecord<Mutations, { [K in keyof Mutations & string]: MutationAction<MutationIdentifierFor<K, Mutations[K]>> }>;
|
|
487
|
+
type EmptyMutations = Record<never, MutationDefinition<any, any, any>>;
|
|
488
|
+
type FateClientOptions<Mutations extends Record<string, MutationDefinition<any, any, any>> = EmptyMutations> = {
|
|
489
|
+
mutations?: Mutations;
|
|
490
|
+
transport: Transport<MutationTransport<Mutations>>;
|
|
491
|
+
types: ReadonlyArray<Omit<TypeConfig, 'getId'> & Partial<{
|
|
492
|
+
getId: TypeConfig['getId'];
|
|
493
|
+
}>>;
|
|
494
|
+
};
|
|
495
|
+
/**
|
|
496
|
+
* Core client that normalizes records, manages the view cache, and coordinates
|
|
497
|
+
* data fetching.
|
|
498
|
+
*/
|
|
499
|
+
declare class FateClient<Mutations extends Record<string, MutationDefinition<any, any, any>> = EmptyMutations> {
|
|
500
|
+
private readonly mutationMap;
|
|
501
|
+
private readonly parentLists;
|
|
502
|
+
private readonly pending;
|
|
503
|
+
private readonly optimisticMasks;
|
|
504
|
+
private readonly optimisticByEntity;
|
|
505
|
+
private optimisticTokenCounter;
|
|
506
|
+
private readonly requests;
|
|
507
|
+
private readonly stalledRequests;
|
|
508
|
+
readonly store: Store;
|
|
509
|
+
private readonly types;
|
|
510
|
+
private readonly transport;
|
|
511
|
+
private readonly viewDataCache;
|
|
512
|
+
readonly mutations: MutationFunctionsFor<Mutations>;
|
|
513
|
+
readonly actions: MutationActionsFor<Mutations>;
|
|
514
|
+
constructor(options: FateClientOptions<Mutations>);
|
|
515
|
+
private initializeParentLists;
|
|
516
|
+
getTypeConfig(type: string): TypeConfig;
|
|
517
|
+
executeMutation(key: string, input: unknown, select: Set<string>, options?: {
|
|
518
|
+
args?: AnyRecord;
|
|
519
|
+
plan?: SelectionPlan;
|
|
520
|
+
}): Promise<unknown>;
|
|
521
|
+
write(type: string, data: AnyRecord, select: ReadonlySet<string>, snapshots?: Map<EntityId, Snapshot>, plan?: SelectionPlan, pathPrefix?: string | null, blockedMask?: FieldMask | null): string;
|
|
522
|
+
deleteRecord(type: string, id: string | number, snapshots?: Map<EntityId, Snapshot>, listSnapshots?: Map<string, List>): void;
|
|
523
|
+
restore(id: EntityId, snapshot: Snapshot): void;
|
|
524
|
+
restoreList(name: string, list?: List): void;
|
|
525
|
+
ref<T$1 extends Entity>(type: T$1['__typename'], id: string | number, view: View<T$1, Selection<T$1>>): ViewRef<T$1['__typename']>;
|
|
526
|
+
rootListRef(entityId: EntityId, rootView: View<any, any>): Readonly<{
|
|
527
|
+
__typename: string;
|
|
528
|
+
id: string | number;
|
|
529
|
+
[ViewsTag]: Set<string>;
|
|
530
|
+
}>;
|
|
531
|
+
readView<T$1 extends Entity, S$1 extends Selection<T$1>, V extends View<T$1, S$1>>(view: V, ref: ViewRef<T$1['__typename']>): FateThenable<ViewSnapshot<T$1, S$1>>;
|
|
532
|
+
private mergeListState;
|
|
533
|
+
registerOptimisticUpdate(entityId: EntityId | null, select: ReadonlySet<string>): number | null;
|
|
534
|
+
clearOptimisticUpdate(token: number | null): void;
|
|
535
|
+
getPendingOptimisticMask(entityId: EntityId | null, options?: {
|
|
536
|
+
excludeToken?: number | null;
|
|
537
|
+
}): FieldMask | null;
|
|
538
|
+
filterSelectionForPendingOptimistics(entityId: EntityId | null, select: Set<string>, options?: {
|
|
539
|
+
excludeToken?: number | null;
|
|
540
|
+
}): Set<string>;
|
|
541
|
+
loadConnection<V extends View<any, any>>(view: V, connection: ConnectionMetadata, args: Record<string, unknown>, options?: {
|
|
542
|
+
direction?: 'forward' | 'backward';
|
|
543
|
+
}): Promise<Readonly<{
|
|
544
|
+
cursors?: ReadonlyArray<string | undefined>;
|
|
545
|
+
ids: ReadonlyArray<EntityId>;
|
|
546
|
+
pagination?: Pagination;
|
|
547
|
+
}> | undefined>;
|
|
548
|
+
request<R$1 extends Request>(request: R$1, options?: RequestOptions): Promise<RequestResult<R$1>>;
|
|
549
|
+
releaseRequest(request: Request, mode: RequestMode): void;
|
|
550
|
+
private handleStoreAndNetworkRequest;
|
|
551
|
+
private executeRequest;
|
|
552
|
+
private hasRequestData;
|
|
553
|
+
getRequestResult<R$1 extends Request>(request: R$1): RequestResult<R$1>;
|
|
554
|
+
private fetchByIdAndNormalize;
|
|
555
|
+
private fetchListAndNormalize;
|
|
556
|
+
private resolveListSelection;
|
|
557
|
+
private writeEntity;
|
|
558
|
+
private linkParentLists;
|
|
559
|
+
private readViewSelection;
|
|
560
|
+
private clearStalledRequestsForEntity;
|
|
561
|
+
private pendingPrefix;
|
|
562
|
+
private pendingKey;
|
|
563
|
+
}
|
|
564
|
+
declare function createClient<Mutations extends Record<string, MutationDefinition<any, any, any>> = EmptyMutations>(options: FateClientOptions<Mutations>): FateClient<Mutations>;
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region src/ref.d.ts
|
|
567
|
+
/**
|
|
568
|
+
* Builds the canonical cache ID for an entity.
|
|
569
|
+
*/
|
|
570
|
+
declare const toEntityId: (type: TypeName, rawId: string | number) => EntityId;
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region src/view.d.ts
|
|
573
|
+
type SelectionValidation<T$1 extends Entity, S$1 extends Selection<T$1>> = Exclude<keyof Omit<S$1, typeof __FateEntityBrand | typeof __FateSelectionBrand>, keyof Selection<T$1>> extends never ? unknown : never;
|
|
574
|
+
/**
|
|
575
|
+
* Creates a reusable view for an object using the declared selection.
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* const PostView = view<Post>()({
|
|
579
|
+
* id: true,
|
|
580
|
+
* title: true,
|
|
581
|
+
* });
|
|
582
|
+
*/
|
|
583
|
+
declare function view<T$1 extends Entity>(): <S$1 extends Selection<T$1>>(select: S$1 & SelectionValidation<T$1, S$1>) => View<T$1, S$1>;
|
|
584
|
+
//#endregion
|
|
585
|
+
export { type ConnectionMetadata, type ConnectionRef, ConnectionTag, type Entity, type EntityId, FateClient, type AnyRecord as FateRecord, type ListItem, type Mask, type MutationDefinition, type MutationEntity, type MutationIdentifier, type MutationInput, type MutationResult, type NodesItem, type Pagination, type Request, type RequestMode, type RequestOptions, type RequestResult, type Selection, type Snapshot, type Transport, type TypeConfig, type View, type ViewData, type ViewEntity, type ViewEntityName, type ViewRef, type ViewSelection, type ViewSnapshot, type ViewTag, createClient, createTRPCTransport, getSelectionPlan, isViewTag, mutation, toEntityId, view };
|