@loozo/angular-launch 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -22
- package/client.d.ts +33 -15
- package/client.js +31 -14
- package/generation/index.d.ts +8 -1
- package/generation/index.js +17 -5
- package/index.d.ts +1 -0
- package/input-issues.d.ts +56 -0
- package/input-issues.js +78 -0
- package/package.json +16 -2
- package/server/backend.d.ts +3 -3
- package/server/backend.js +7 -7
- package/server/definitions.d.ts +18 -2
- package/server/dispatch.d.ts +10 -7
- package/server/dispatch.js +22 -11
- package/tanstack-query/README.md +168 -0
- package/tanstack-query/generated.d.ts +5 -0
- package/tanstack-query/generated.js +127 -0
- package/tanstack-query/hydration.d.ts +46 -0
- package/tanstack-query/hydration.js +70 -0
- package/tanstack-query/index.d.ts +2 -0
- package/tanstack-query/index.js +1 -0
- package/tanstack-query/queries.d.ts +124 -0
- package/tanstack-query/queries.js +1 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { CreateMutationOptions, DataTag, QueryKeyWithDataTag, SkipToken, UndefinedInitialDataOptions } from "@tanstack/angular-query";
|
|
2
|
+
import type { Group, Procedure, Schema } from "../server/definitions.js";
|
|
3
|
+
type GroupKey<Namespace> = readonly ["launch", Namespace];
|
|
4
|
+
type ProcedureKey<Namespace, Name> = readonly ["launch", Namespace, Name];
|
|
5
|
+
type InputKey<Namespace, Name, Input> = readonly ["launch", Namespace, Name, Input];
|
|
6
|
+
type QueryOverrides<Output, Data, Key extends readonly unknown[]> = Omit<UndefinedInitialDataOptions<Output, unknown, Data, Key>, "queryKey" | "queryFn">;
|
|
7
|
+
type QueryOptions<Output, Data, Key extends readonly unknown[]> = UndefinedInitialDataOptions<Output, unknown, Data, Key> & QueryKeyWithDataTag<Key, Output, unknown>;
|
|
8
|
+
type QueryProcedure<Namespace, Name, Input, Output> = Input extends Schema<infer Caller, unknown> ? {
|
|
9
|
+
/**
|
|
10
|
+
* Query options for `injectQuery`, `QueryClient.fetchQuery` and the like.
|
|
11
|
+
*
|
|
12
|
+
* @param input - The procedure's input, as you would pass it to the callable.
|
|
13
|
+
* @param overrides - Any other query options; they replace the defaults.
|
|
14
|
+
* @returns Options keyed `["launch", namespace, procedure, input]`, with the key
|
|
15
|
+
* tagged with the procedure's output type.
|
|
16
|
+
*/
|
|
17
|
+
queryOptions<Data = Output>(input: Caller, overrides?: QueryOverrides<Output, Data, InputKey<Namespace, Name, Caller>>): QueryOptions<Output, Data, InputKey<Namespace, Name, Caller>>;
|
|
18
|
+
/**
|
|
19
|
+
* Query options for `injectQuery`, `QueryClient.fetchQuery` and the like, or
|
|
20
|
+
* disabled options for `skipToken`.
|
|
21
|
+
*
|
|
22
|
+
* @param input - The procedure's input, or `skipToken` to disable the query. A
|
|
23
|
+
* disabled query is keyed `["launch", namespace, procedure]` and never fetches.
|
|
24
|
+
* @param overrides - Any other query options; they replace the defaults.
|
|
25
|
+
* @returns Options keyed `["launch", namespace, procedure, input]`, or
|
|
26
|
+
* `["launch", namespace, procedure]` for `skipToken`, with the key tagged with the
|
|
27
|
+
* procedure's output type.
|
|
28
|
+
*/
|
|
29
|
+
queryOptions<Data = Output>(input: Caller | SkipToken, overrides?: QueryOverrides<Output, Data, InputKey<Namespace, Name, Caller> | ProcedureKey<Namespace, Name>>): QueryOptions<Output, Data, InputKey<Namespace, Name, Caller> | ProcedureKey<Namespace, Name>>;
|
|
30
|
+
/**
|
|
31
|
+
* The key of every query of this procedure, whatever its input.
|
|
32
|
+
*
|
|
33
|
+
* @returns `["launch", namespace, procedure]`.
|
|
34
|
+
*/
|
|
35
|
+
key(): ProcedureKey<Namespace, Name>;
|
|
36
|
+
/**
|
|
37
|
+
* The key of this procedure's query for one input.
|
|
38
|
+
*
|
|
39
|
+
* @param input - The procedure's input.
|
|
40
|
+
* @returns `["launch", namespace, procedure, input]`, tagged with the procedure's
|
|
41
|
+
* output type.
|
|
42
|
+
*/
|
|
43
|
+
key(input: Caller): DataTag<InputKey<Namespace, Name, Caller>, Output, unknown>;
|
|
44
|
+
} : {
|
|
45
|
+
/**
|
|
46
|
+
* Query options for `injectQuery`, `QueryClient.fetchQuery` and the like.
|
|
47
|
+
*
|
|
48
|
+
* @param overrides - Any other query options; they replace the defaults.
|
|
49
|
+
* @returns Options keyed `["launch", namespace, procedure]`, with the key tagged
|
|
50
|
+
* with the procedure's output type.
|
|
51
|
+
*/
|
|
52
|
+
queryOptions<Data = Output>(overrides?: QueryOverrides<Output, Data, ProcedureKey<Namespace, Name>>): QueryOptions<Output, Data, ProcedureKey<Namespace, Name>>;
|
|
53
|
+
/**
|
|
54
|
+
* The key of this procedure's query.
|
|
55
|
+
*
|
|
56
|
+
* @returns `["launch", namespace, procedure]`, tagged with the procedure's output
|
|
57
|
+
* type.
|
|
58
|
+
*/
|
|
59
|
+
key(): DataTag<ProcedureKey<Namespace, Name>, Output, unknown>;
|
|
60
|
+
};
|
|
61
|
+
type MutationOverrides<Output, Variables, OnMutateResult> = Omit<CreateMutationOptions<Output, unknown, Variables, OnMutateResult>, "mutationKey" | "mutationFn">;
|
|
62
|
+
type MutationProcedure<Namespace, Name, Input, Output> = {
|
|
63
|
+
/**
|
|
64
|
+
* Mutation options for `injectMutation`. The mutation's variables are the procedure's
|
|
65
|
+
* input; a procedure without input takes none.
|
|
66
|
+
*
|
|
67
|
+
* @param overrides - Any other mutation options.
|
|
68
|
+
* @returns Options keyed `["launch", namespace, procedure]`.
|
|
69
|
+
*/
|
|
70
|
+
mutationOptions<OnMutateResult = unknown>(overrides?: MutationOverrides<Output, Variables<Input>, OnMutateResult>): CreateMutationOptions<Output, unknown, Variables<Input>, OnMutateResult> & {
|
|
71
|
+
/** `["launch", namespace, procedure]`. */
|
|
72
|
+
mutationKey: ProcedureKey<Namespace, Name>;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* The key of this procedure's mutations.
|
|
76
|
+
*
|
|
77
|
+
* @returns `["launch", namespace, procedure]`.
|
|
78
|
+
*/
|
|
79
|
+
key(): ProcedureKey<Namespace, Name>;
|
|
80
|
+
};
|
|
81
|
+
type Variables<Input> = Input extends Schema<infer Caller, unknown> ? Caller : void;
|
|
82
|
+
type ProcedureQueries<Namespace, Name, Value> = Value extends Procedure<infer Input, infer Output, infer Kind, infer _Errors> ? Kind extends "query" ? QueryProcedure<Namespace, Name, Input, Awaited<Output>> : MutationProcedure<Namespace, Name, Input, Awaited<Output>> : never;
|
|
83
|
+
/**
|
|
84
|
+
* The TanStack Query factories for an RPC group: query or mutation options and keys per
|
|
85
|
+
* procedure, plus the group's key.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* The type of one namespace of a generated `injectQueries()`, which generation writes
|
|
89
|
+
* when its `tanstackQuery` option is on. Keys are `["launch", namespace]` for the group,
|
|
90
|
+
* `["launch", namespace, procedure]` for a procedure and
|
|
91
|
+
* `["launch", namespace, procedure, input]` for one input, so invalidating a shorter key
|
|
92
|
+
* also invalidates the longer ones under it. Queries call the procedure with the query's
|
|
93
|
+
* `signal` and `transferCache: false`, since TanStack transfers the data itself. Errors are
|
|
94
|
+
* typed `unknown`: narrow them with the callable's `isError`.
|
|
95
|
+
*
|
|
96
|
+
* Query options default `retry` to never for an `RpcError` and to your `QueryClient`
|
|
97
|
+
* default, or three retries, for anything else, and `refetchOnMount` to `false` while the
|
|
98
|
+
* app hydrates and to your `QueryClient` default, or `true`, after. Overrides replace
|
|
99
|
+
* either default.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { injectQueries } from "./rpc.generated";
|
|
104
|
+
*
|
|
105
|
+
* const queries = injectQueries();
|
|
106
|
+
*
|
|
107
|
+
* injectQuery(() => queries.todos.list.queryOptions());
|
|
108
|
+
* injectMutation(() => queries.todos.add.mutationOptions());
|
|
109
|
+
* client.invalidateQueries({ queryKey: queries.todos.$key() });
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @typeParam Value - A group created by `defineRpc`.
|
|
113
|
+
*/
|
|
114
|
+
export type RpcQueries<Value> = Value extends Group<infer Namespace, infer Procedures> ? {
|
|
115
|
+
/**
|
|
116
|
+
* The key of every query and mutation of the group.
|
|
117
|
+
*
|
|
118
|
+
* @returns `["launch", namespace]`.
|
|
119
|
+
*/
|
|
120
|
+
$key(): GroupKey<Namespace>;
|
|
121
|
+
} & {
|
|
122
|
+
readonly [Name in keyof Procedures]: ProcedureQueries<Namespace, Name, Procedures[Name]>;
|
|
123
|
+
} : never;
|
|
124
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|