@nkzw/fate 0.1.2 → 0.1.3
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/lib/cli.mjs +11 -11
- package/lib/index.d.mts +1 -2
- package/lib/index.mjs +4 -4
- package/lib/server.d.mts +21 -22
- package/lib/server.mjs +16 -16
- package/lib/{types-Djlh7mMH.d.mts → types-HECWvGpd.d.mts} +116 -138
- package/package.json +3 -3
package/lib/cli.mjs
CHANGED
|
@@ -130,22 +130,22 @@ const generate = async () => {
|
|
|
130
130
|
});
|
|
131
131
|
continue;
|
|
132
132
|
}
|
|
133
|
-
for (const [queryName, root
|
|
134
|
-
if (root
|
|
135
|
-
if (procedureName === root
|
|
133
|
+
for (const [queryName, root] of routerRoots) {
|
|
134
|
+
if (root.kind !== "query") continue;
|
|
135
|
+
if (procedureName === root.procedure && type === "query") queryEntries.push({
|
|
136
136
|
name: queryName,
|
|
137
|
-
procedure: root
|
|
137
|
+
procedure: root.procedure,
|
|
138
138
|
router,
|
|
139
|
-
type: root
|
|
139
|
+
type: root.type
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
-
for (const [listName, root
|
|
143
|
-
if (root
|
|
144
|
-
if (procedureName === root
|
|
142
|
+
for (const [listName, root] of routerRoots) {
|
|
143
|
+
if (root.kind !== "list") continue;
|
|
144
|
+
if (procedureName === root.procedure && type === "query") listEntries.push({
|
|
145
145
|
list: listName,
|
|
146
|
-
procedure: root
|
|
146
|
+
procedure: root.procedure,
|
|
147
147
|
router,
|
|
148
|
-
type: root
|
|
148
|
+
type: root.type
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
}
|
|
@@ -203,7 +203,7 @@ const generate = async () => {
|
|
|
203
203
|
const source = `// @generated by \`pnpm fate generate\`
|
|
204
204
|
${typeImports}
|
|
205
205
|
import { createTRPCProxyClient } from '@trpc/client';
|
|
206
|
-
import { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
206
|
+
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
207
207
|
import { clientRoot, createClient, createTRPCTransport, mutation } from 'react-fate';
|
|
208
208
|
|
|
209
209
|
type TRPCClientType = ReturnType<typeof createTRPCProxyClient<AppRouter>>;
|
package/lib/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { A as ViewSelection, B as RequestOptions, C as TypeConfig, D as ViewEntity, E as ViewData, F as isViewTag, G as getSelectionPlan, H as Transport, I as FateMutations, L as mutation, M as ViewTag, N as __FateEntityBrand, O as ViewEntityName, P as __FateSelectionBrand, R as FateClient, S as Snapshot, T as View, U as createTRPCTransport, V as createClient, _ as Pagination, a as Entity, b as RootDefinition, c as FateThenable, d as MutationDefinition, f as MutationEntity, g as NodesItem, h as MutationResult, i as ConnectionTag, j as ViewSnapshot, k as ViewRef, l as ListItem, m as MutationInput, n as ConnectionMetadata, o as EntityId, p as MutationIdentifier, r as ConnectionRef, s as FateRoots, t as AnyRecord, u as Mask, v as Request, w as TypeName, x as Selection, y as RequestResult, z as RequestMode } from "./types-
|
|
1
|
+
import { A as ViewSelection, B as RequestOptions, C as TypeConfig, D as ViewEntity, E as ViewData, F as isViewTag, G as getSelectionPlan, H as Transport, I as FateMutations, L as mutation, M as ViewTag, N as __FateEntityBrand, O as ViewEntityName, P as __FateSelectionBrand, R as FateClient, S as Snapshot, T as View, U as createTRPCTransport, V as createClient, _ as Pagination, a as Entity, b as RootDefinition, c as FateThenable, d as MutationDefinition, f as MutationEntity, g as NodesItem, h as MutationResult, i as ConnectionTag, j as ViewSnapshot, k as ViewRef, l as ListItem, m as MutationInput, n as ConnectionMetadata, o as EntityId, p as MutationIdentifier, r as ConnectionRef, s as FateRoots, t as AnyRecord, u as Mask, v as Request, w as TypeName, x as Selection, y as RequestResult, z as RequestMode } from "./types-HECWvGpd.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/root.d.ts
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Defines a root query for an entity type, capturing the response shape.
|
|
7
6
|
*/
|
package/lib/index.mjs
CHANGED
|
@@ -432,17 +432,17 @@ const MutationKind = "__fate__mutation";
|
|
|
432
432
|
/**
|
|
433
433
|
* Collects all view payloads that apply to the given ref.
|
|
434
434
|
*/
|
|
435
|
-
const getViewPayloads = (view
|
|
435
|
+
const getViewPayloads = (view, ref) => {
|
|
436
436
|
const result = [];
|
|
437
|
-
for (const [key, value] of Object.entries(view
|
|
437
|
+
for (const [key, value] of Object.entries(view)) if (isViewTag(key) && (!ref || ref[ViewsTag]?.has(key))) result.push(value);
|
|
438
438
|
return result;
|
|
439
439
|
};
|
|
440
440
|
/**
|
|
441
441
|
* Returns the set of view tags defined on a view composition.
|
|
442
442
|
*/
|
|
443
|
-
const getViewNames = (view
|
|
443
|
+
const getViewNames = (view) => {
|
|
444
444
|
const result = /* @__PURE__ */ new Set();
|
|
445
|
-
for (const key of Object.keys(view
|
|
445
|
+
for (const key of Object.keys(view)) if (isViewTag(key)) result.add(key);
|
|
446
446
|
return result;
|
|
447
447
|
};
|
|
448
448
|
/**
|
package/lib/server.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { W as QueryProcedure, t as AnyRecord } from "./types-
|
|
1
|
+
import { W as QueryProcedure, t as AnyRecord } from "./types-HECWvGpd.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/server/dataView.d.ts
|
|
@@ -10,18 +10,18 @@ type ResolverSelect<Context> = AnyRecord | ((options: {
|
|
|
10
10
|
type Bivariant<Fn extends (...args: Array<any>) => unknown> = {
|
|
11
11
|
bivariance(...args: Parameters<Fn>): ReturnType<Fn>;
|
|
12
12
|
}['bivariance'];
|
|
13
|
-
type ResolverResolve<Item
|
|
14
|
-
type ResolverAuthorize<Item
|
|
13
|
+
type ResolverResolve<Item extends AnyRecord, Result, Context> = Bivariant<(item: Item, context?: Context, args?: AnyRecord) => Promise<Result> | Result>;
|
|
14
|
+
type ResolverAuthorize<Item extends AnyRecord, Context> = Bivariant<(item: Item, context?: Context, args?: AnyRecord) => Promise<boolean> | boolean>;
|
|
15
15
|
/**
|
|
16
16
|
* Field configuration for selecting and resolving a computed value on the backend.
|
|
17
17
|
*/
|
|
18
|
-
type ResolverField<Item
|
|
19
|
-
authorize?: ResolverAuthorize<Item
|
|
18
|
+
type ResolverField<Item extends AnyRecord, Result, Context> = {
|
|
19
|
+
authorize?: ResolverAuthorize<Item, Context>;
|
|
20
20
|
kind: 'resolver';
|
|
21
|
-
resolve: ResolverResolve<Item
|
|
21
|
+
resolve: ResolverResolve<Item, Result, Context>;
|
|
22
22
|
select?: ResolverSelect<Context>;
|
|
23
23
|
};
|
|
24
|
-
type DataField<Item
|
|
24
|
+
type DataField<Item extends AnyRecord> = true | DataView<AnyRecord> | ResolverField<Item, any, any>;
|
|
25
25
|
/**
|
|
26
26
|
* Recursively serializes resolver results for transport across the network.
|
|
27
27
|
*/
|
|
@@ -30,15 +30,15 @@ type Serializable<T> = T extends Date ? string : T extends Array<infer U> ? Arra
|
|
|
30
30
|
* Server-side mirror of a view definition describing how to select and resolve
|
|
31
31
|
* fields when fulfilling a client request.
|
|
32
32
|
*/
|
|
33
|
-
type DataView<Item
|
|
34
|
-
fields: Record<string, DataField<Item
|
|
33
|
+
type DataView<Item extends AnyRecord> = {
|
|
34
|
+
fields: Record<string, DataField<Item>>;
|
|
35
35
|
kind?: 'resolver' | 'list';
|
|
36
36
|
typeName: string;
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
39
|
* Convenience type for declaring the fields of a server data view.
|
|
40
40
|
*/
|
|
41
|
-
type DataViewConfig<Item
|
|
41
|
+
type DataViewConfig<Item extends AnyRecord> = Record<string, DataField<Item>>;
|
|
42
42
|
/**
|
|
43
43
|
* Declares a server data view that exposes an object's available fields to the client.
|
|
44
44
|
*
|
|
@@ -48,27 +48,27 @@ type DataViewConfig<Item$1 extends AnyRecord> = Record<string, DataField<Item$1>
|
|
|
48
48
|
* title: true,
|
|
49
49
|
* });
|
|
50
50
|
*/
|
|
51
|
-
declare function dataView<Item
|
|
51
|
+
declare function dataView<Item extends AnyRecord>(typeName: string): <Fields extends DataViewConfig<Item>>(fields: Fields) => DataView<Item> & {
|
|
52
52
|
readonly [dataViewFieldsKey]: Fields;
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
55
55
|
* Marks a data view as a list resolver so the server can respond with
|
|
56
56
|
* connection information.
|
|
57
57
|
*/
|
|
58
|
-
declare const list: <Item
|
|
58
|
+
declare const list: <Item extends AnyRecord>(view: DataView<Item>) => {
|
|
59
59
|
kind: "list";
|
|
60
|
-
fields: Record<string, DataField<Item
|
|
60
|
+
fields: Record<string, DataField<Item>>;
|
|
61
61
|
typeName: string;
|
|
62
62
|
};
|
|
63
63
|
/**
|
|
64
64
|
* Declares a resolver field inside a data view, optionally providing a
|
|
65
65
|
* selection for any data dependencies.
|
|
66
66
|
*/
|
|
67
|
-
declare function resolver<Item
|
|
68
|
-
authorize?: ResolverAuthorize<Item
|
|
69
|
-
resolve: ResolverResolve<Item
|
|
67
|
+
declare function resolver<Item extends AnyRecord, Result = unknown, Context = unknown>(config: {
|
|
68
|
+
authorize?: ResolverAuthorize<Item, Context>;
|
|
69
|
+
resolve: ResolverResolve<Item, Result, Context>;
|
|
70
70
|
select?: ResolverSelect<Context>;
|
|
71
|
-
}): ResolverField<Item
|
|
71
|
+
}): ResolverField<Item, Result, Context>;
|
|
72
72
|
type NonNullish<T> = Exclude<T, null | undefined>;
|
|
73
73
|
type WithNullish<Original, Value> = null extends Original ? undefined extends Original ? Value | null | undefined : Value | null : undefined extends Original ? Value | undefined : Value;
|
|
74
74
|
type ResolverResult<Field> = Field extends ResolverField<AnyRecord, any, any> ? Field['authorize'] extends ResolverAuthorize<any, any> ? Awaited<ReturnType<Field['resolve']>> | null : Awaited<ReturnType<Field['resolve']>> : never;
|
|
@@ -76,7 +76,7 @@ type RelationResult<ItemField, V extends DataView<AnyRecord>> = NonNullish<ItemF
|
|
|
76
76
|
type ViewFieldConfig<V extends DataView<AnyRecord>> = V extends {
|
|
77
77
|
readonly [dataViewFieldsKey]: infer Fields;
|
|
78
78
|
} ? Fields : V['fields'];
|
|
79
|
-
type RawFieldResult<Item
|
|
79
|
+
type RawFieldResult<Item extends AnyRecord, Key extends PropertyKey, Field extends DataField<Item>> = Field extends true ? Key extends keyof Item ? Item[Key] : never : Field extends DataView<infer ChildItem> ? Key extends keyof Item ? RelationResult<Item[Key], DataView<ChildItem>> : never : Field extends ResolverField<Item, any, any> ? ResolverResult<Field> : never;
|
|
80
80
|
type RawDataViewResult<V extends DataView<AnyRecord>> = V extends DataView<infer Item> ? { [K in keyof ViewFieldConfig<V>]: RawFieldResult<Item, K, ViewFieldConfig<V>[K]> } : never;
|
|
81
81
|
type DataViewResult<V extends DataView<AnyRecord>> = Serializable<RawDataViewResult<V>>;
|
|
82
82
|
type WithTypename<T, Name extends string> = T & {
|
|
@@ -90,7 +90,7 @@ type Entity<TView extends DataView<AnyRecord>, Name extends string, Replacements
|
|
|
90
90
|
* Builds a resolver that applies a client's selection to a server data view,
|
|
91
91
|
* filtering fields, running nested resolvers, and shaping selects.
|
|
92
92
|
*/
|
|
93
|
-
declare function createResolver<Item
|
|
93
|
+
declare function createResolver<Item extends AnyRecord, Context = unknown>({
|
|
94
94
|
args,
|
|
95
95
|
ctx,
|
|
96
96
|
select: initialSelect,
|
|
@@ -99,9 +99,9 @@ declare function createResolver<Item$1 extends AnyRecord, Context = unknown>({
|
|
|
99
99
|
args?: AnyRecord;
|
|
100
100
|
ctx?: Context;
|
|
101
101
|
select: Iterable<string>;
|
|
102
|
-
view: DataView<Item
|
|
102
|
+
view: DataView<Item>;
|
|
103
103
|
}): {
|
|
104
|
-
resolve: (item: Item
|
|
104
|
+
resolve: (item: Item) => Promise<AnyRecord>;
|
|
105
105
|
resolveMany: (items: Array<AnyRecord>) => Promise<Array<AnyRecord>>;
|
|
106
106
|
select: Record<string, unknown>;
|
|
107
107
|
};
|
|
@@ -178,7 +178,6 @@ declare const connectionInput: z.ZodObject<{
|
|
|
178
178
|
* Converts an array of nodes into a list view connection result the client
|
|
179
179
|
* can normalize.
|
|
180
180
|
*/
|
|
181
|
-
|
|
182
181
|
/**
|
|
183
182
|
* Wraps a tRPC procedure to handle cursor-based pagination with consistent
|
|
184
183
|
* connection semantics.
|
package/lib/server.mjs
CHANGED
|
@@ -80,14 +80,14 @@ const paginationArgsSchema = z.strictObject({
|
|
|
80
80
|
first: z.number().int().positive().optional(),
|
|
81
81
|
last: z.number().int().positive().optional()
|
|
82
82
|
}).partial().refine(({ after, before }) => !(after && before), "Connection args can't include both 'after' and 'before'.").refine(({ first, last }) => !(first && last), "Connection args can't include both 'first' and 'last'.").refine(({ before, last }) => !last || before !== void 0, "Connection args using 'last' must also include 'before'.");
|
|
83
|
-
const extractPaginationArgs = (args
|
|
83
|
+
const extractPaginationArgs = (args) => args ? Object.fromEntries(Object.entries(args).filter(([key]) => paginationArgKeys.has(key))) : {};
|
|
84
84
|
/**
|
|
85
85
|
* Converts an array of nodes into a list view connection result the client
|
|
86
86
|
* can normalize.
|
|
87
87
|
*/
|
|
88
|
-
function arrayToConnection(nodes, { args
|
|
88
|
+
function arrayToConnection(nodes, { args, getCursor = (node) => String(node.id) } = {}) {
|
|
89
89
|
if (!nodes) return;
|
|
90
|
-
const paginationArgs = paginationArgsSchema.parse(extractPaginationArgs(args
|
|
90
|
+
const paginationArgs = paginationArgsSchema.parse(extractPaginationArgs(args));
|
|
91
91
|
if (Object.keys(paginationArgs).length === 0) return {
|
|
92
92
|
items: nodes.map((node) => ({
|
|
93
93
|
cursor: getCursor(node),
|
|
@@ -130,7 +130,7 @@ const assignIfChanged = (current, key, next, existing) => {
|
|
|
130
130
|
current[key] = next;
|
|
131
131
|
return current;
|
|
132
132
|
};
|
|
133
|
-
function toConnectionResult({ args
|
|
133
|
+
function toConnectionResult({ args, item, path, view }) {
|
|
134
134
|
if (!isRecord$1(item)) return item;
|
|
135
135
|
let result = null;
|
|
136
136
|
const base = () => result ? {
|
|
@@ -144,17 +144,17 @@ function toConnectionResult({ args: args$1, item, path, view }) {
|
|
|
144
144
|
if (config.kind === "list") {
|
|
145
145
|
if (!Array.isArray(current)) continue;
|
|
146
146
|
const connection = arrayToConnection(current.map((item$1) => toConnectionResult({
|
|
147
|
-
args
|
|
147
|
+
args,
|
|
148
148
|
item: item$1,
|
|
149
149
|
path: nextPath,
|
|
150
150
|
view: config
|
|
151
|
-
})), { args: getScopedArgs(args
|
|
151
|
+
})), { args: getScopedArgs(args, nextPath) });
|
|
152
152
|
result = assignIfChanged(result, field, connection, current);
|
|
153
153
|
continue;
|
|
154
154
|
}
|
|
155
155
|
if (Array.isArray(current)) {
|
|
156
156
|
const wrapped = current.map((entry) => toConnectionResult({
|
|
157
|
-
args
|
|
157
|
+
args,
|
|
158
158
|
item: entry,
|
|
159
159
|
path: nextPath,
|
|
160
160
|
view: config
|
|
@@ -164,7 +164,7 @@ function toConnectionResult({ args: args$1, item, path, view }) {
|
|
|
164
164
|
}
|
|
165
165
|
if (isRecord$1(current)) {
|
|
166
166
|
const wrapped = toConnectionResult({
|
|
167
|
-
args
|
|
167
|
+
args,
|
|
168
168
|
item: current,
|
|
169
169
|
path: nextPath,
|
|
170
170
|
view: config
|
|
@@ -362,12 +362,12 @@ const assignPath = (node, segments, path, selectedPaths, view, allowedPaths) =>
|
|
|
362
362
|
}
|
|
363
363
|
};
|
|
364
364
|
const collectResolvers = (node, select, args$1, context) => {
|
|
365
|
-
for (const resolver
|
|
366
|
-
if (!resolver
|
|
367
|
-
const addition = typeof resolver
|
|
365
|
+
for (const resolver of node.resolvers.values()) {
|
|
366
|
+
if (!resolver.select) continue;
|
|
367
|
+
const addition = typeof resolver.select === "function" ? resolver.select({
|
|
368
368
|
args: args$1,
|
|
369
369
|
context
|
|
370
|
-
}) : resolver
|
|
370
|
+
}) : resolver.select;
|
|
371
371
|
if (addition && isRecord$1(addition)) mergeObject(ensureRelationSelect(select, node.path), addition);
|
|
372
372
|
}
|
|
373
373
|
for (const relation of node.relations.values()) collectResolvers(relation, select, args$1, context);
|
|
@@ -380,14 +380,14 @@ const resolveNode = async ({ item, node, options: resolverOptions }) => {
|
|
|
380
380
|
result[key] = value;
|
|
381
381
|
};
|
|
382
382
|
const getItem = () => result ?? item;
|
|
383
|
-
for (const [field, resolver
|
|
384
|
-
if (resolver
|
|
385
|
-
if (!await resolver
|
|
383
|
+
for (const [field, resolver] of node.resolvers) {
|
|
384
|
+
if (resolver.authorize) {
|
|
385
|
+
if (!await resolver.authorize(getItem(), resolverOptions.context, resolverOptions.args)) {
|
|
386
386
|
assign(field, null);
|
|
387
387
|
continue;
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
|
-
const value = await resolver
|
|
390
|
+
const value = await resolver.resolve(getItem(), resolverOptions.context, resolverOptions.args);
|
|
391
391
|
if (value !== void 0) assign(field, value);
|
|
392
392
|
}
|
|
393
393
|
for (const [field, relationNode] of node.relations) {
|
|
@@ -23,15 +23,15 @@ type SelectionPlan = {
|
|
|
23
23
|
* Flattens a view into a `SelectionPlan`, expanding composed views and
|
|
24
24
|
* partitioning nested args so the client can fetch exactly what is declared.
|
|
25
25
|
*/
|
|
26
|
-
declare const getSelectionPlan: <T
|
|
26
|
+
declare const getSelectionPlan: <T extends Entity, S extends Selection<T>, V extends View<T, S>>(viewComposition: V, ref: ViewRef<T["__typename"]> | null) => SelectionPlan;
|
|
27
27
|
//#endregion
|
|
28
28
|
//#region src/cache.d.ts
|
|
29
29
|
declare class ViewDataCache {
|
|
30
30
|
private cache;
|
|
31
31
|
private rootDependencies;
|
|
32
32
|
private dependencyIndex;
|
|
33
|
-
get<T
|
|
34
|
-
set<T
|
|
33
|
+
get<T extends Entity, S extends Selection<T>, V extends View<T, S>>(entityId: EntityId, view: V, ref: ViewRef<T['__typename']>): FateThenable<ViewSnapshot<T, S>> | null;
|
|
34
|
+
set<T extends Entity, S extends Selection<T>, V extends View<T, S>>(entityId: EntityId, view: V, ref: ViewRef<T['__typename']>, thenable: FateThenable<ViewSnapshot<T, S>>, dependencies: ReadonlySet<EntityId>): void;
|
|
35
35
|
invalidate(entityId: EntityId): void;
|
|
36
36
|
private invalidateDependents;
|
|
37
37
|
private delete;
|
|
@@ -74,19 +74,19 @@ declare class Store {
|
|
|
74
74
|
interface Unsubscribable {
|
|
75
75
|
unsubscribe(): void;
|
|
76
76
|
}
|
|
77
|
-
interface Subscribable<TValue
|
|
78
|
-
subscribe(observer: Partial<Observer<TValue
|
|
77
|
+
interface Subscribable<TValue, TError> {
|
|
78
|
+
subscribe(observer: Partial<Observer<TValue, TError>>): Unsubscribable;
|
|
79
79
|
}
|
|
80
|
-
interface Observable<TValue
|
|
81
|
-
pipe(): Observable<TValue
|
|
82
|
-
pipe<TValue1, TError1>(op1: OperatorFunction<TValue
|
|
83
|
-
pipe<TValue1, TError1, TValue2, TError2>(op1: OperatorFunction<TValue
|
|
84
|
-
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3>(op1: OperatorFunction<TValue
|
|
85
|
-
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3, TValue4, TError4>(op1: OperatorFunction<TValue
|
|
86
|
-
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3, TValue4, TError4, TValue5, TError5>(op1: OperatorFunction<TValue
|
|
80
|
+
interface Observable<TValue, TError> extends Subscribable<TValue, TError> {
|
|
81
|
+
pipe(): Observable<TValue, TError>;
|
|
82
|
+
pipe<TValue1, TError1>(op1: OperatorFunction<TValue, TError, TValue1, TError1>): Observable<TValue1, TError1>;
|
|
83
|
+
pipe<TValue1, TError1, TValue2, TError2>(op1: OperatorFunction<TValue, TError, TValue1, TError1>, op2: OperatorFunction<TValue1, TError1, TValue2, TError2>): Observable<TValue2, TError2>;
|
|
84
|
+
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3>(op1: OperatorFunction<TValue, TError, TValue1, TError1>, op2: OperatorFunction<TValue1, TError1, TValue2, TError2>, op3: OperatorFunction<TValue2, TError2, TValue3, TError3>): Observable<TValue2, TError2>;
|
|
85
|
+
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3, TValue4, TError4>(op1: OperatorFunction<TValue, TError, TValue1, TError1>, op2: OperatorFunction<TValue1, TError1, TValue2, TError2>, op3: OperatorFunction<TValue2, TError2, TValue3, TError3>, op4: OperatorFunction<TValue3, TError3, TValue4, TError4>): Observable<TValue2, TError2>;
|
|
86
|
+
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3, TValue4, TError4, TValue5, TError5>(op1: OperatorFunction<TValue, TError, TValue1, TError1>, op2: OperatorFunction<TValue1, TError1, TValue2, TError2>, op3: OperatorFunction<TValue2, TError2, TValue3, TError3>, op4: OperatorFunction<TValue3, TError3, TValue4, TError4>, op5: OperatorFunction<TValue4, TError4, TValue5, TError5>): Observable<TValue2, TError2>;
|
|
87
87
|
}
|
|
88
|
-
interface Observer<TValue
|
|
89
|
-
next: (value: TValue
|
|
88
|
+
interface Observer<TValue, TError> {
|
|
89
|
+
next: (value: TValue) => void;
|
|
90
90
|
error: (err: TError) => void;
|
|
91
91
|
complete: () => void;
|
|
92
92
|
}
|
|
@@ -148,7 +148,6 @@ type TRPC_ERROR_CODE_KEY = keyof typeof TRPC_ERROR_CODES_BY_KEY;
|
|
|
148
148
|
* tRPC error codes that are considered retryable
|
|
149
149
|
* With out of the box SSE, the client will reconnect when these errors are encountered
|
|
150
150
|
*/
|
|
151
|
-
|
|
152
151
|
declare class TRPCError extends Error {
|
|
153
152
|
readonly cause?: Error;
|
|
154
153
|
readonly code: "PARSE_ERROR" | "BAD_REQUEST" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_SUPPORTED" | "TIMEOUT" | "CONFLICT" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "UNSUPPORTED_MEDIA_TYPE" | "UNPROCESSABLE_CONTENT" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST";
|
|
@@ -157,8 +156,7 @@ declare class TRPCError extends Error {
|
|
|
157
156
|
code: TRPC_ERROR_CODE_KEY;
|
|
158
157
|
cause?: unknown;
|
|
159
158
|
});
|
|
160
|
-
}
|
|
161
|
-
//# sourceMappingURL=TRPCError.d.ts.map
|
|
159
|
+
} //# sourceMappingURL=TRPCError.d.ts.map
|
|
162
160
|
//#endregion
|
|
163
161
|
//#region src/vendor/standard-schema-v1/spec.d.ts
|
|
164
162
|
/**
|
|
@@ -166,28 +164,28 @@ declare class TRPCError extends Error {
|
|
|
166
164
|
* @see https://github.com/standard-schema/standard-schema/blob/main/packages/spec/src/index.ts
|
|
167
165
|
*/
|
|
168
166
|
/** The Standard Schema interface. */
|
|
169
|
-
interface StandardSchemaV1<Input
|
|
167
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
170
168
|
/** The Standard Schema properties. */
|
|
171
|
-
readonly '~standard': StandardSchemaV1.Props<Input
|
|
169
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
172
170
|
}
|
|
173
171
|
declare namespace StandardSchemaV1 {
|
|
174
172
|
/** The Standard Schema properties interface. */
|
|
175
|
-
interface Props<Input
|
|
173
|
+
interface Props<Input = unknown, Output = Input> {
|
|
176
174
|
/** The version number of the standard. */
|
|
177
175
|
readonly version: 1;
|
|
178
176
|
/** The vendor name of the schema library. */
|
|
179
177
|
readonly vendor: string;
|
|
180
178
|
/** Validates unknown input values. */
|
|
181
|
-
readonly validate: (value: unknown) => Result<Output
|
|
179
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
182
180
|
/** Inferred types associated with the schema. */
|
|
183
|
-
readonly types?: Types<Input
|
|
181
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
184
182
|
}
|
|
185
183
|
/** The result interface of the validate function. */
|
|
186
|
-
type Result<Output
|
|
184
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
187
185
|
/** The result interface if validation succeeds. */
|
|
188
|
-
interface SuccessResult<Output
|
|
186
|
+
interface SuccessResult<Output> {
|
|
189
187
|
/** The typed output value. */
|
|
190
|
-
readonly value: Output
|
|
188
|
+
readonly value: Output;
|
|
191
189
|
/** The non-existent issues. */
|
|
192
190
|
readonly issues?: undefined;
|
|
193
191
|
}
|
|
@@ -209,18 +207,17 @@ declare namespace StandardSchemaV1 {
|
|
|
209
207
|
readonly key: PropertyKey;
|
|
210
208
|
}
|
|
211
209
|
/** The Standard Schema types interface. */
|
|
212
|
-
interface Types<Input
|
|
210
|
+
interface Types<Input = unknown, Output = Input> {
|
|
213
211
|
/** The input type of the schema. */
|
|
214
|
-
readonly input: Input
|
|
212
|
+
readonly input: Input;
|
|
215
213
|
/** The output type of the schema. */
|
|
216
|
-
readonly output: Output
|
|
214
|
+
readonly output: Output;
|
|
217
215
|
}
|
|
218
216
|
/** Infers the input type of a Standard Schema. */
|
|
219
217
|
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
220
218
|
/** Infers the output type of a Standard Schema. */
|
|
221
219
|
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
222
|
-
}
|
|
223
|
-
//# sourceMappingURL=spec.d.ts.map
|
|
220
|
+
} //# sourceMappingURL=spec.d.ts.map
|
|
224
221
|
//#endregion
|
|
225
222
|
//#region src/unstable-core-do-not-import/parser.d.ts
|
|
226
223
|
type ParserZodEsque<TInput, TParsedInput> = {
|
|
@@ -259,15 +256,14 @@ type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
|
|
|
259
256
|
/**
|
|
260
257
|
* @internal
|
|
261
258
|
*/
|
|
262
|
-
interface ProcedureCallOptions<TContext
|
|
263
|
-
ctx: TContext
|
|
259
|
+
interface ProcedureCallOptions<TContext> {
|
|
260
|
+
ctx: TContext;
|
|
264
261
|
getRawInput: GetRawInputFn;
|
|
265
262
|
input?: unknown;
|
|
266
263
|
path: string;
|
|
267
264
|
type: ProcedureType;
|
|
268
265
|
signal: AbortSignal | undefined;
|
|
269
|
-
}
|
|
270
|
-
//#endregion
|
|
266
|
+
} //#endregion
|
|
271
267
|
//#region src/unstable-core-do-not-import/procedure.d.ts
|
|
272
268
|
declare const procedureTypes: readonly ["query", "mutation", "subscription"];
|
|
273
269
|
/**
|
|
@@ -331,19 +327,17 @@ type inferProcedureOutput<TProcedure> = inferProcedureParams<TProcedure>['$types
|
|
|
331
327
|
/**
|
|
332
328
|
* @internal
|
|
333
329
|
*/
|
|
334
|
-
interface ErrorHandlerOptions<TContext
|
|
330
|
+
interface ErrorHandlerOptions<TContext> {
|
|
335
331
|
error: TRPCError;
|
|
336
332
|
type: ProcedureType | 'unknown';
|
|
337
333
|
path: string | undefined;
|
|
338
334
|
input: unknown;
|
|
339
|
-
ctx: TContext
|
|
340
|
-
}
|
|
341
|
-
//#endregion
|
|
335
|
+
ctx: TContext | undefined;
|
|
336
|
+
} //#endregion
|
|
342
337
|
//#region src/unstable-core-do-not-import/http/types.d.ts
|
|
343
338
|
/**
|
|
344
339
|
* @deprecated use `Headers` instead, this will be removed in v12
|
|
345
340
|
*/
|
|
346
|
-
|
|
347
341
|
//#endregion
|
|
348
342
|
//#region src/unstable-core-do-not-import/rpc/envelopes.d.ts
|
|
349
343
|
/**
|
|
@@ -357,7 +351,6 @@ interface TRPCErrorShape<TData extends object = object> {
|
|
|
357
351
|
/**
|
|
358
352
|
* JSON-RPC 2.0 Specification
|
|
359
353
|
*/
|
|
360
|
-
|
|
361
354
|
//# sourceMappingURL=envelopes.d.ts.map
|
|
362
355
|
//#endregion
|
|
363
356
|
//#region src/unstable-core-do-not-import/transformer.d.ts
|
|
@@ -404,20 +397,18 @@ interface CombinedDataTransformer {
|
|
|
404
397
|
/**
|
|
405
398
|
* @public
|
|
406
399
|
*/
|
|
407
|
-
|
|
408
400
|
//# sourceMappingURL=parseTRPCMessage.d.ts.map
|
|
409
|
-
|
|
410
401
|
//#endregion
|
|
411
402
|
//#region src/unstable-core-do-not-import/error/formatter.d.ts
|
|
412
403
|
/**
|
|
413
404
|
* @internal
|
|
414
405
|
*/
|
|
415
|
-
type ErrorFormatter<TContext
|
|
406
|
+
type ErrorFormatter<TContext, TShape extends TRPCErrorShape> = (opts: {
|
|
416
407
|
error: TRPCError;
|
|
417
408
|
type: ProcedureType | 'unknown';
|
|
418
409
|
path: string | undefined;
|
|
419
410
|
input: unknown;
|
|
420
|
-
ctx: TContext
|
|
411
|
+
ctx: TContext | undefined;
|
|
421
412
|
shape: DefaultErrorShape;
|
|
422
413
|
}) => TShape;
|
|
423
414
|
/**
|
|
@@ -468,7 +459,6 @@ interface JSONLProducerOptions {
|
|
|
468
459
|
* JSON Lines stream producer
|
|
469
460
|
* @see https://jsonlines.org/
|
|
470
461
|
*/
|
|
471
|
-
|
|
472
462
|
//# sourceMappingURL=sse.types.d.ts.map
|
|
473
463
|
//#endregion
|
|
474
464
|
//#region src/unstable-core-do-not-import/stream/sse.d.ts
|
|
@@ -495,9 +485,9 @@ interface SSEClientOptions {
|
|
|
495
485
|
*/
|
|
496
486
|
reconnectAfterInactivityMs?: number;
|
|
497
487
|
}
|
|
498
|
-
interface SSEStreamProducerOptions<TValue
|
|
488
|
+
interface SSEStreamProducerOptions<TValue = unknown> {
|
|
499
489
|
serialize?: Serialize$1;
|
|
500
|
-
data: AsyncIterable<TValue
|
|
490
|
+
data: AsyncIterable<TValue>;
|
|
501
491
|
maxDepth?: number;
|
|
502
492
|
ping?: SSEPingOptions;
|
|
503
493
|
/**
|
|
@@ -524,7 +514,6 @@ interface SSEStreamProducerOptions<TValue$1 = unknown> {
|
|
|
524
514
|
*
|
|
525
515
|
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
526
516
|
*/
|
|
527
|
-
|
|
528
517
|
//#endregion
|
|
529
518
|
//#region src/unstable-core-do-not-import/rootConfig.d.ts
|
|
530
519
|
/**
|
|
@@ -540,7 +529,6 @@ interface RootTypes {
|
|
|
540
529
|
/**
|
|
541
530
|
* The default check to see if we're in a server
|
|
542
531
|
*/
|
|
543
|
-
|
|
544
532
|
/**
|
|
545
533
|
* The tRPC root config
|
|
546
534
|
* @internal
|
|
@@ -621,7 +609,7 @@ type DecorateRouterRecord<TRecord extends RouterRecord> = { [TKey in keyof TReco
|
|
|
621
609
|
/**
|
|
622
610
|
* @internal
|
|
623
611
|
*/
|
|
624
|
-
type RouterCallerErrorHandler<TContext
|
|
612
|
+
type RouterCallerErrorHandler<TContext> = (opts: ErrorHandlerOptions<TContext>) => void;
|
|
625
613
|
/**
|
|
626
614
|
* @internal
|
|
627
615
|
*/
|
|
@@ -631,6 +619,7 @@ type RouterCaller<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = (
|
|
|
631
619
|
* If passing a function, we recommend it's a cached function
|
|
632
620
|
* e.g. wrapped in `React.cache` to avoid unnecessary computations
|
|
633
621
|
*/
|
|
622
|
+
|
|
634
623
|
ctx: TRoot['ctx'] | (() => MaybePromise<TRoot['ctx']>), options?: {
|
|
635
624
|
onError?: RouterCallerErrorHandler<TRoot['ctx']>;
|
|
636
625
|
signal?: AbortSignal;
|
|
@@ -644,7 +633,6 @@ type LazyLoader<TAny> = {
|
|
|
644
633
|
* Lazy load a router
|
|
645
634
|
* @see https://trpc.io/docs/server/merging-routers#lazy-load
|
|
646
635
|
*/
|
|
647
|
-
|
|
648
636
|
/**
|
|
649
637
|
* @internal
|
|
650
638
|
*/
|
|
@@ -690,7 +678,7 @@ interface Transport<Mutations extends TransportMutations = EmptyTransportMutatio
|
|
|
690
678
|
pagination: Pagination;
|
|
691
679
|
}>;
|
|
692
680
|
fetchQuery?(proc: string, select: Iterable<string>, args?: ResolvedArgsPayload): Promise<unknown>;
|
|
693
|
-
mutate?<K
|
|
681
|
+
mutate?<K extends Extract<keyof Mutations, string>>(proc: K, input: Mutations[K]['input'], select: Set<string>): Promise<Mutations[K]['output']>;
|
|
694
682
|
}
|
|
695
683
|
/**
|
|
696
684
|
* Mapping of entity type to tRPC procedures used for fetching entities by ID.
|
|
@@ -722,7 +710,7 @@ type TRPCQueryResolvers<AppRouter extends AnyRouter> = Record<string, (client: T
|
|
|
722
710
|
*/
|
|
723
711
|
type MutationResolver<AppRouter extends AnyRouter> = (client: TRPCClient<AppRouter>) => (input: any) => Promise<any>;
|
|
724
712
|
type TRPCMutationResolvers<AppRouter extends AnyRouter> = Record<string, MutationResolver<AppRouter>>;
|
|
725
|
-
type MutationMapFromResolvers<R
|
|
713
|
+
type MutationMapFromResolvers<R extends Record<string, MutationResolver<any>>> = { [K in keyof R]: R[K] extends ((client: any) => (input: infer Input) => Promise<infer Output>) ? {
|
|
726
714
|
input: Input;
|
|
727
715
|
output: Output;
|
|
728
716
|
} : never };
|
|
@@ -749,10 +737,7 @@ declare function createTRPCTransport<AppRouter extends AnyRouter, Mutations exte
|
|
|
749
737
|
/**
|
|
750
738
|
* Strategy used when resolving a request.
|
|
751
739
|
*/
|
|
752
|
-
type RequestMode = /** (default) Use cached data if present, otherwise fetch. */
|
|
753
|
-
'cache-first'
|
|
754
|
-
/** Show cached data immediately and refresh in the background. */ | 'stale-while-revalidate'
|
|
755
|
-
/** Always fetch from the network and ignore cached entries. */ | 'network-only';
|
|
740
|
+
type RequestMode = /** (default) Use cached data if present, otherwise fetch. */'cache-first' /** Show cached data immediately and refresh in the background. */ | 'stale-while-revalidate' /** Always fetch from the network and ignore cached entries. */ | 'network-only';
|
|
756
741
|
/**
|
|
757
742
|
* Request options that affect how requests are fetched and retained.
|
|
758
743
|
*/
|
|
@@ -804,13 +789,13 @@ declare class FateClient<Roots extends FateRoots, Mutations extends FateMutation
|
|
|
804
789
|
deleteRecord(type: string, id: string | number, snapshots?: Map<EntityId, Snapshot>, listSnapshots?: Map<string, List>): void;
|
|
805
790
|
restore(id: EntityId, snapshot: Snapshot): void;
|
|
806
791
|
restoreList(name: string, list?: List): void;
|
|
807
|
-
ref<T
|
|
792
|
+
ref<T extends Entity>(type: T['__typename'], id: string | number, view: View<T, Selection<T>>): ViewRef<T['__typename']>;
|
|
808
793
|
rootListRef(entityId: EntityId, rootView: View<any, any>): Readonly<{
|
|
809
794
|
__typename: string;
|
|
810
795
|
id: string | number;
|
|
811
796
|
[ViewsTag]: Set<string>;
|
|
812
797
|
}>;
|
|
813
|
-
readView<T
|
|
798
|
+
readView<T extends Entity, S extends Selection<T>, V extends View<T, S>>(view: V, ref: ViewRef<T['__typename']>): FateThenable<ViewSnapshot<T, S>>;
|
|
814
799
|
private mergeListState;
|
|
815
800
|
registerPendingOptimisticMutation(entityId: EntityId, promise: Promise<unknown>): void;
|
|
816
801
|
resolveOptimisticEntity(optimisticEntityId: EntityId, resolvedEntityId: EntityId): void;
|
|
@@ -830,13 +815,13 @@ declare class FateClient<Roots extends FateRoots, Mutations extends FateMutation
|
|
|
830
815
|
ids: ReadonlyArray<EntityId>;
|
|
831
816
|
pagination?: Pagination;
|
|
832
817
|
}> | undefined>;
|
|
833
|
-
request<R
|
|
818
|
+
request<R extends Request$1>(request: R, options?: RequestOptions): Promise<RequestResult<Roots, R>>;
|
|
834
819
|
releaseRequest(request: Request$1, mode: RequestMode): void;
|
|
835
820
|
private handleStoreAndNetworkRequest;
|
|
836
821
|
private getRootType;
|
|
837
822
|
private executeRequest;
|
|
838
823
|
private hasRequestData;
|
|
839
|
-
getRequestResult<R
|
|
824
|
+
getRequestResult<R extends Request$1>(request: R): RequestResult<Roots, R>;
|
|
840
825
|
private fetchByIdAndNormalize;
|
|
841
826
|
private fetchQueryAndNormalize;
|
|
842
827
|
private fetchListAndNormalize;
|
|
@@ -848,14 +833,14 @@ declare class FateClient<Roots extends FateRoots, Mutations extends FateMutation
|
|
|
848
833
|
private pendingPrefix;
|
|
849
834
|
private pendingKey;
|
|
850
835
|
}
|
|
851
|
-
declare function createClient<T
|
|
836
|
+
declare function createClient<T extends [FateRoots, FateMutations] = [Record<never, RootDefinition<any, any>>, Record<never, MutationDefinition<any, any, any>>]>(options: FateClientOptions<T[0], T[1]>): FateClient<T[0], T[1]>;
|
|
852
837
|
//#endregion
|
|
853
838
|
//#region src/mutation.d.ts
|
|
854
839
|
/**
|
|
855
840
|
* Defines a mutation for a given entity type, preserving the input and output
|
|
856
841
|
* types for transports.
|
|
857
842
|
*/
|
|
858
|
-
declare function mutation<T
|
|
843
|
+
declare function mutation<T extends Entity, I, R>(entity: T['__typename']): MutationDefinition<T, I, R>;
|
|
859
844
|
/** Where (or if) to insert the resulting record into relevant lists. */
|
|
860
845
|
type InsertPosition = 'after' | 'before' | 'none';
|
|
861
846
|
/**
|
|
@@ -863,25 +848,20 @@ type InsertPosition = 'after' | 'before' | 'none';
|
|
|
863
848
|
* optional selection for the returned payload.
|
|
864
849
|
*/
|
|
865
850
|
type MutationOptions<Identifier extends MutationIdentifier<any, any, any>> = {
|
|
866
|
-
/** Optional arguments to pass to the mutation resolver. */
|
|
867
|
-
|
|
868
|
-
/** If true, deletes the record with the ID specified in the input. */
|
|
869
|
-
delete?: boolean;
|
|
870
|
-
/** Input data for the mutation. */
|
|
851
|
+
/** Optional arguments to pass to the mutation resolver. */args?: Record<string, unknown>; /** If true, deletes the record with the ID specified in the input. */
|
|
852
|
+
delete?: boolean; /** Input data for the mutation. */
|
|
871
853
|
input: Omit<MutationInput<Identifier>, 'select'>;
|
|
872
|
-
insert?: InsertPosition;
|
|
873
|
-
/** Optional
|
|
874
|
-
optimistic?: OptimisticUpdate<MutationResult<Identifier>>;
|
|
875
|
-
/** Optional view specifying which fields to select from the server. */
|
|
854
|
+
insert?: InsertPosition; /** Optional optimistic update to apply immediately. */
|
|
855
|
+
optimistic?: OptimisticUpdate<MutationResult<Identifier>>; /** Optional view specifying which fields to select from the server. */
|
|
876
856
|
view?: View<MutationEntity<Identifier>, Selection<MutationEntity<Identifier>>>;
|
|
877
857
|
};
|
|
878
858
|
/**
|
|
879
859
|
* Callable mutation entry point returned on the client that resolves to either
|
|
880
860
|
* a successful result or an error.
|
|
881
861
|
*/
|
|
882
|
-
type MutationFunction<I
|
|
862
|
+
type MutationFunction<I extends MutationIdentifier<any, any, any>> = (options: MutationOptions<I>) => Promise<{
|
|
883
863
|
error: undefined;
|
|
884
|
-
result: MutationResult<I
|
|
864
|
+
result: MutationResult<I>;
|
|
885
865
|
} | {
|
|
886
866
|
error: Error;
|
|
887
867
|
result: undefined;
|
|
@@ -890,21 +870,22 @@ type MutationFunction<I$1 extends MutationIdentifier<any, any, any>> = (options:
|
|
|
890
870
|
* React action-compatible wrapper that can be passed directly to form actions
|
|
891
871
|
* or transitions.
|
|
892
872
|
*/
|
|
893
|
-
type MutationAction<I
|
|
873
|
+
type MutationAction<I extends MutationIdentifier<any, any, any>> = (previousState: unknown,
|
|
894
874
|
/**
|
|
895
875
|
* Mutation options or 'reset' to reset the action state.
|
|
896
876
|
*/
|
|
897
|
-
|
|
877
|
+
|
|
878
|
+
options: MutationOptions<I> | 'reset') => Promise<{
|
|
898
879
|
error: undefined;
|
|
899
|
-
result: MutationResult<I
|
|
880
|
+
result: MutationResult<I>;
|
|
900
881
|
} | {
|
|
901
882
|
error: Error;
|
|
902
883
|
result: undefined;
|
|
903
884
|
}>;
|
|
904
|
-
type MutationIdentifierFor<K
|
|
905
|
-
key: K
|
|
885
|
+
type MutationIdentifierFor<K extends string, Def extends MutationDefinition<any, any, any>> = Def extends MutationDefinition<infer T, infer I, infer R> ? MutationIdentifier<T, I, R> & Readonly<{
|
|
886
|
+
key: K;
|
|
906
887
|
}> : never;
|
|
907
|
-
type UnionToIntersection<U
|
|
888
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
908
889
|
type NestedValue<Path extends string, Value> = Path extends `${infer Head}.${infer Tail}` ? { [K in Head]: NestedValue<Tail, Value> } : { [K in Path]: Value };
|
|
909
890
|
/**
|
|
910
891
|
* Base type for client mutations.
|
|
@@ -932,26 +913,26 @@ declare const __FateMutationInputBrand: unique symbol;
|
|
|
932
913
|
declare const __FateMutationResultBrand: unique symbol;
|
|
933
914
|
declare const __FateRootResultBrand: unique symbol;
|
|
934
915
|
declare const __FateRootTypeBrand: unique symbol;
|
|
935
|
-
type __ViewEntityAnchor<T
|
|
936
|
-
readonly [__FateEntityBrand]?: T
|
|
916
|
+
type __ViewEntityAnchor<T extends Entity> = {
|
|
917
|
+
readonly [__FateEntityBrand]?: T;
|
|
937
918
|
};
|
|
938
919
|
type __ViewSelectionAnchor<S> = {
|
|
939
920
|
[__FateSelectionBrand]?: S;
|
|
940
921
|
};
|
|
941
|
-
type __MutationEntityAnchor<T
|
|
942
|
-
readonly [__FateMutationEntityBrand]?: T
|
|
922
|
+
type __MutationEntityAnchor<T extends Entity> = {
|
|
923
|
+
readonly [__FateMutationEntityBrand]?: T;
|
|
943
924
|
};
|
|
944
|
-
type __MutationInputAnchor<I
|
|
945
|
-
readonly [__FateMutationInputBrand]?: I
|
|
925
|
+
type __MutationInputAnchor<I> = {
|
|
926
|
+
readonly [__FateMutationInputBrand]?: I;
|
|
946
927
|
};
|
|
947
|
-
type __MutationResultAnchor<R
|
|
948
|
-
readonly [__FateMutationResultBrand]?: R
|
|
928
|
+
type __MutationResultAnchor<R> = {
|
|
929
|
+
readonly [__FateMutationResultBrand]?: R;
|
|
949
930
|
};
|
|
950
|
-
type __RootResultAnchor<R
|
|
951
|
-
readonly [__FateRootResultBrand]?: R
|
|
931
|
+
type __RootResultAnchor<R> = {
|
|
932
|
+
readonly [__FateRootResultBrand]?: R;
|
|
952
933
|
};
|
|
953
|
-
type __RootTypeAnchor<T
|
|
954
|
-
readonly [__FateRootTypeBrand]?: T
|
|
934
|
+
type __RootTypeAnchor<T extends TypeName> = {
|
|
935
|
+
readonly [__FateRootTypeBrand]?: T;
|
|
955
936
|
};
|
|
956
937
|
/** Unique key that identifies a view composition entry inside a selection or reference. */
|
|
957
938
|
type ViewTag = `__fate-view__${string}`;
|
|
@@ -959,9 +940,9 @@ type ViewTag = `__fate-view__${string}`;
|
|
|
959
940
|
declare function isViewTag(key: string): key is ViewTag;
|
|
960
941
|
/** Alias for a loose record used throughout the fate's internals. */
|
|
961
942
|
type AnyRecord = Record<string, unknown>;
|
|
962
|
-
type Nullish<T
|
|
963
|
-
type NonNullish<T
|
|
964
|
-
type WithNullish<T
|
|
943
|
+
type Nullish<T> = Extract<T, null | undefined>;
|
|
944
|
+
type NonNullish<T> = Exclude<T, null | undefined>;
|
|
945
|
+
type WithNullish<T, R> = R | Nullish<T>;
|
|
965
946
|
type SelectionArgs = Readonly<{
|
|
966
947
|
args: AnyRecord;
|
|
967
948
|
}>;
|
|
@@ -983,12 +964,9 @@ type ViewRef<TName extends string> = Readonly<{
|
|
|
983
964
|
[ViewsTag]: Set<string>;
|
|
984
965
|
}>;
|
|
985
966
|
/** Describes how a field relates to another entity for normalization. */
|
|
986
|
-
type RelationDescriptor = /** Field stores a scalar value that does not link to another type. */
|
|
987
|
-
'scalar'
|
|
988
|
-
/** Field points to a single entity of the given type. */ | {
|
|
967
|
+
type RelationDescriptor = /** Field stores a scalar value that does not link to another type. */'scalar' /** Field points to a single entity of the given type. */ | {
|
|
989
968
|
type: string;
|
|
990
|
-
}
|
|
991
|
-
/** Field holds a list of entities of the given type. */ | {
|
|
969
|
+
} /** Field holds a list of entities of the given type. */ | {
|
|
992
970
|
listOf: string;
|
|
993
971
|
};
|
|
994
972
|
/** Configuration for a server entity type used by the client cache. */
|
|
@@ -1017,11 +995,11 @@ type Entity = {
|
|
|
1017
995
|
__typename: string;
|
|
1018
996
|
};
|
|
1019
997
|
type PlainObjectSelectionField<V> = V extends Array<infer U> ? PlainObjectSelectionField<U> | true : V extends AnyRecord ? PlainObjectSelection<V> | true : true;
|
|
1020
|
-
type PlainObjectSelection<T
|
|
1021
|
-
type ConnectionSelectionBase<T
|
|
998
|
+
type PlainObjectSelection<T> = { [K in keyof T]?: PlainObjectSelectionField<T[K]> };
|
|
999
|
+
type ConnectionSelectionBase<T extends Entity> = Readonly<{
|
|
1022
1000
|
items: Readonly<{
|
|
1023
1001
|
cursor?: true;
|
|
1024
|
-
node: Selection<T
|
|
1002
|
+
node: Selection<T> | View<T, Selection<T>>;
|
|
1025
1003
|
}>;
|
|
1026
1004
|
pagination?: Readonly<{
|
|
1027
1005
|
hasNext?: true;
|
|
@@ -1031,27 +1009,27 @@ type ConnectionSelectionBase<T$1 extends Entity> = Readonly<{
|
|
|
1031
1009
|
}>;
|
|
1032
1010
|
}>;
|
|
1033
1011
|
/** Selection shape for a connection-style list, including pagination metadata and optional arguments. */
|
|
1034
|
-
type ConnectionSelection<T
|
|
1035
|
-
type BaseSelectionFieldValue<T
|
|
1036
|
-
type SelectionFieldValue<T
|
|
1037
|
-
type SelectionShape<T
|
|
1012
|
+
type ConnectionSelection<T extends Entity> = ConnectionSelectionBase<T> | (SelectionArgs & ConnectionSelectionBase<T>);
|
|
1013
|
+
type BaseSelectionFieldValue<T extends Entity, K extends keyof T> = NonNullable<T[K]> extends Array<infer U extends Entity> ? true | Selection<U> | ConnectionSelection<U> | View<U, Selection<U>> : NonNullable<T[K]> extends Entity ? true | Selection<NonNullable<T[K]>> | View<NonNullable<T[K]>, Selection<NonNullable<T[K]>>> : NonNullable<T[K]> extends AnyRecord ? PlainObjectSelection<NonNullable<T[K]>> : true;
|
|
1014
|
+
type SelectionFieldValue<T extends Entity, K extends keyof T> = BaseSelectionFieldValue<T, K> | SelectionArgs | (SelectionArgs & Extract<BaseSelectionFieldValue<T, K>, object>);
|
|
1015
|
+
type SelectionShape<T extends Entity> = { [K in keyof T as K extends '__typename' ? never : K]?: SelectionFieldValue<T, K> } & {
|
|
1038
1016
|
__typename?: true;
|
|
1039
1017
|
};
|
|
1040
|
-
type SelectionViewSpread<T
|
|
1041
|
-
select: Selection<T
|
|
1018
|
+
type SelectionViewSpread<T extends Entity> = { readonly [K in ViewTag]?: Readonly<{
|
|
1019
|
+
select: Selection<T>;
|
|
1042
1020
|
[ViewKind]: true;
|
|
1043
1021
|
}> };
|
|
1044
1022
|
/** Declarative selection of the fields a view needs from an entity. */
|
|
1045
|
-
type Selection<T
|
|
1023
|
+
type Selection<T extends Entity> = SelectionShape<T> & SelectionViewSpread<T>;
|
|
1046
1024
|
/** View payload stored on a view tag containing the raw selection used to mask data. */
|
|
1047
|
-
type ViewPayload<T
|
|
1025
|
+
type ViewPayload<T extends Entity, S extends Selection<T> = Selection<T>> = Readonly<{
|
|
1048
1026
|
select: S;
|
|
1049
1027
|
[ViewKind]: true;
|
|
1050
1028
|
}>;
|
|
1051
1029
|
/** Definition of a view over an entity type, including the selection of fields. */
|
|
1052
|
-
type View<T
|
|
1053
|
-
[viewTag: ViewTag]: ViewPayload<T
|
|
1054
|
-
}> & __ViewEntityAnchor<T
|
|
1030
|
+
type View<T extends Entity, S extends Selection<T> = Selection<T>> = Readonly<{
|
|
1031
|
+
[viewTag: ViewTag]: ViewPayload<T, S>;
|
|
1032
|
+
}> & __ViewEntityAnchor<T> & __ViewSelectionAnchor<S>;
|
|
1055
1033
|
type HasViewTag<S> = S extends { [K in ViewTag]?: infer P } ? P extends {
|
|
1056
1034
|
[ViewKind]: true;
|
|
1057
1035
|
} ? true : false : false;
|
|
@@ -1059,18 +1037,18 @@ type HasViewTag<S> = S extends { [K in ViewTag]?: infer P } ? P extends {
|
|
|
1059
1037
|
* Data returned from a resolved view with masking applied and view tags
|
|
1060
1038
|
* attached for downstream composition.
|
|
1061
1039
|
*/
|
|
1062
|
-
type ViewData<T
|
|
1040
|
+
type ViewData<T extends Entity, S extends Selection<T>> = Readonly<(S extends Selection<T> ? Mask<T, S> : T) & {
|
|
1063
1041
|
[ViewsTag]: Set<string>;
|
|
1064
1042
|
}>;
|
|
1065
1043
|
/**
|
|
1066
1044
|
* Snapshot returned by the cache for a view, including the masked data and all
|
|
1067
1045
|
* referenced entity IDs.
|
|
1068
1046
|
*/
|
|
1069
|
-
type ViewSnapshot<T
|
|
1047
|
+
type ViewSnapshot<T extends Entity, S extends Selection<T>> = Readonly<{
|
|
1070
1048
|
coverage: ReadonlyArray<readonly [id: EntityId, paths: ReadonlySet<string>]>;
|
|
1071
|
-
data: ViewData<T
|
|
1049
|
+
data: ViewData<T, S>;
|
|
1072
1050
|
}>;
|
|
1073
|
-
type ConnectionMask<T
|
|
1051
|
+
type ConnectionMask<T extends Entity, S> = S extends {
|
|
1074
1052
|
items: infer ItemSelection;
|
|
1075
1053
|
pagination?: infer PaginationSelection;
|
|
1076
1054
|
} ? {
|
|
@@ -1080,19 +1058,19 @@ type ConnectionMask<T$1 extends Entity, S> = S extends {
|
|
|
1080
1058
|
} ? Array<(CursorSelection extends true ? {
|
|
1081
1059
|
cursor: string;
|
|
1082
1060
|
} : Record<string, never>) & {
|
|
1083
|
-
node: ViewRef<T
|
|
1061
|
+
node: ViewRef<T['__typename']>;
|
|
1084
1062
|
}> : Array<{
|
|
1085
|
-
node: ViewRef<T
|
|
1063
|
+
node: ViewRef<T['__typename']>;
|
|
1086
1064
|
}>;
|
|
1087
1065
|
} & (PaginationSelection extends object ? {
|
|
1088
1066
|
pagination: { [K in keyof PaginationSelection]: Pagination[K & keyof Pagination] };
|
|
1089
|
-
} : Record<string, never>) : Array<T
|
|
1090
|
-
type EntityName<T
|
|
1067
|
+
} : Record<string, never>) : Array<T>;
|
|
1068
|
+
type EntityName<T> = T extends {
|
|
1091
1069
|
__typename: infer N extends string;
|
|
1092
1070
|
} ? N : never;
|
|
1093
1071
|
/** Recursively applies a view selection to an entity to mask fields that aren't selected. */
|
|
1094
|
-
type MaskNonNullish<T
|
|
1095
|
-
type Mask<T
|
|
1072
|
+
type MaskNonNullish<T, S> = T extends Array<infer U extends Entity> ? S extends true ? Array<U> : S extends ConnectionSelection<U> ? ConnectionMask<U, S> : HasViewTag<S> extends true ? Array<ViewRef<U['__typename']>> : Array<Mask<U, S>> : S extends true ? T : S extends object ? HasViewTag<S> extends true ? NonNullish<T> extends Entity ? ViewRef<EntityName<NonNullish<T>>> : ViewRef<EntityName<NonNullable<T>>> : { [K in keyof S as K extends 'args' ? never : K]: S[K] extends true ? NonNullish<T>[Extract<K, keyof T>] : Mask<NonNullish<T>[Extract<K, keyof T>], Extract<S[K], object>> } & (T extends Entity ? Pick<NonNullish<T>, '__typename'> : Record<never, never>) : T;
|
|
1073
|
+
type Mask<T, S> = WithNullish<T, MaskNonNullish<NonNullish<T>, S>>;
|
|
1096
1074
|
/** Entity type captured from a view definition. */
|
|
1097
1075
|
type ViewEntity<V> = V extends View<infer T, any> ? T : never;
|
|
1098
1076
|
/** Name of the entity type captured from a view definition. */
|
|
@@ -1140,7 +1118,7 @@ type ConnectionNodeType<Root> = Root extends {
|
|
|
1140
1118
|
node?: infer Node;
|
|
1141
1119
|
};
|
|
1142
1120
|
} ? ViewEntityName<Node & View<any, any>> : never;
|
|
1143
|
-
type ListResult<Item extends AnyRequestItem, Type extends TypeName, Result
|
|
1121
|
+
type ListResult<Item extends AnyRequestItem, Type extends TypeName, Result> = Item extends AnyNodeItem ? ViewRef<Type> : Item extends AnyNodesItem ? Array<ViewRef<Type>> : Item extends AnyQueryItem ? Result extends null ? ViewRef<Type> | null : ViewRef<Type> : Item extends AnyListItem ? Item['list'] extends {
|
|
1144
1122
|
items?: {
|
|
1145
1123
|
node?: View<any, any>;
|
|
1146
1124
|
};
|
|
@@ -1155,28 +1133,28 @@ type ListResult<Item extends AnyRequestItem, Type extends TypeName, Result$1> =
|
|
|
1155
1133
|
* The result of a `FateClient.request` and `useRequest` call, mapping each
|
|
1156
1134
|
* request key to its corresponding result.
|
|
1157
1135
|
*/
|
|
1158
|
-
type RequestResult<R
|
|
1136
|
+
type RequestResult<R extends FateRoots, Q extends AnyRequest> = { [K in keyof Q]: K extends keyof R ? ListResult<Q[K], RootType<R[K]>, RootResult<R[K]>> : never };
|
|
1159
1137
|
/** Brand used on root definitions to mark their identity in the d.ts output. */
|
|
1160
1138
|
declare const RootKind = "__fate__root";
|
|
1161
1139
|
/** Brand used on mutation definitions to mark their identity in the d.ts output. */
|
|
1162
1140
|
declare const MutationKind = "__fate__mutation";
|
|
1163
1141
|
/** Metadata describing a root query for a particular entity and result shape. */
|
|
1164
|
-
type RootDefinition<Type extends TypeName, Result
|
|
1142
|
+
type RootDefinition<Type extends TypeName, Result> = Readonly<{
|
|
1165
1143
|
[RootKind]: true;
|
|
1166
1144
|
type: Type;
|
|
1167
|
-
}> & __RootResultAnchor<Result
|
|
1145
|
+
}> & __RootResultAnchor<Result> & __RootTypeAnchor<Type>;
|
|
1168
1146
|
/** Minimal root description used for typing root maps. */
|
|
1169
1147
|
type FateRoots = Record<string, RootDefinition<TypeName, unknown>>;
|
|
1170
1148
|
/** Extracts the entity type name from a root definition. */
|
|
1171
|
-
type RootType<R
|
|
1149
|
+
type RootType<R> = R extends __RootTypeAnchor<infer T> ? T : never;
|
|
1172
1150
|
/** Extracts the result type from a root definition. */
|
|
1173
|
-
type RootResult<R
|
|
1151
|
+
type RootResult<R> = R extends __RootResultAnchor<infer Data> ? Data : never;
|
|
1174
1152
|
/** Metadata describing a mutation for a particular entity, input, and output. */
|
|
1175
|
-
type MutationDefinition<T
|
|
1176
|
-
entity: T
|
|
1153
|
+
type MutationDefinition<T extends Entity, I, R> = Readonly<{
|
|
1154
|
+
entity: T['__typename'];
|
|
1177
1155
|
[MutationKind]: true;
|
|
1178
|
-
}> & __MutationEntityAnchor<T
|
|
1179
|
-
type MutationIdentifier<T
|
|
1156
|
+
}> & __MutationEntityAnchor<T> & __MutationInputAnchor<I> & __MutationResultAnchor<R>;
|
|
1157
|
+
type MutationIdentifier<T extends Entity, I, R> = MutationDefinition<T, I, R> & Readonly<{
|
|
1180
1158
|
key: string;
|
|
1181
1159
|
}>;
|
|
1182
1160
|
/** Extracts the input type from a mutation definition or identifier. */
|
|
@@ -1198,18 +1176,18 @@ type MutationMapFromDefinitions<D extends FateMutations> = { [K in keyof D]: {
|
|
|
1198
1176
|
input: MutationInput<D[K]>;
|
|
1199
1177
|
output: MutationResult<D[K]>;
|
|
1200
1178
|
} };
|
|
1201
|
-
type OptimisticUpdateValue<T
|
|
1179
|
+
type OptimisticUpdateValue<T> = T extends ReadonlyArray<infer U> ? Array<OptimisticUpdateValue<U>> : NonNullish<T> extends AnyRecord ? OptimisticUpdate<NonNullish<T>> | Nullish<T> : NonNullish<T> | Nullish<T>;
|
|
1202
1180
|
/** Shape used to describe optimistic updates for mutations. */
|
|
1203
|
-
type OptimisticUpdate<T
|
|
1181
|
+
type OptimisticUpdate<T> = { [K in keyof T]?: OptimisticUpdateValue<T[K]> };
|
|
1204
1182
|
/** Snapshot captured before mutating the cache, used to roll back on errors. */
|
|
1205
1183
|
type Snapshot = Readonly<{
|
|
1206
1184
|
mask?: FieldMask;
|
|
1207
1185
|
record?: AnyRecord;
|
|
1208
1186
|
}>;
|
|
1209
1187
|
/** Promise-like value returned by cache reads that already have a resolved payload for React `use`. */
|
|
1210
|
-
interface FateThenable<T
|
|
1188
|
+
interface FateThenable<T> extends PromiseLike<T> {
|
|
1211
1189
|
status: 'fulfilled';
|
|
1212
|
-
value: T
|
|
1190
|
+
value: T;
|
|
1213
1191
|
}
|
|
1214
1192
|
//#endregion
|
|
1215
1193
|
export { ViewSelection as A, RequestOptions as B, TypeConfig as C, ViewEntity as D, ViewData as E, isViewTag as F, getSelectionPlan as G, Transport as H, FateMutations as I, mutation as L, ViewTag as M, __FateEntityBrand as N, ViewEntityName as O, __FateSelectionBrand as P, FateClient as R, Snapshot as S, View as T, createTRPCTransport as U, createClient as V, QueryProcedure as W, Pagination as _, Entity as a, RootDefinition as b, FateThenable as c, MutationDefinition as d, MutationEntity as f, NodesItem as g, MutationResult as h, ConnectionTag as i, ViewSnapshot as j, ViewRef as k, ListItem as l, MutationInput as m, ConnectionMetadata as n, EntityId as o, MutationIdentifier as p, ConnectionRef as r, FateRoots as s, AnyRecord as t, Mask as u, Request$1 as v, TypeName as w, Selection as x, RequestResult as y, RequestMode as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nkzw/fate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "fate is a modern data client for React.",
|
|
5
5
|
"homepage": "https://github.com/nkzw-tech/fate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"superjson": "^2.2.6",
|
|
43
|
-
"zod": "^4.3.
|
|
43
|
+
"zod": "^4.3.6"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@trpc/client": "^11.8.1",
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"@trpc/client": "^11.6.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"build": "
|
|
53
|
+
"build": "vite lib -d lib --target=node24 src/index.ts src/server.ts src/cli.ts"
|
|
54
54
|
}
|
|
55
55
|
}
|