@trpc/react-query 11.0.0-alpha-tmp-subscription-connection-state.488 → 11.0.0-alpha-tmp-12-06-react.665

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.
Files changed (73) hide show
  1. package/dist/bundle-analysis.json +59 -76
  2. package/dist/createTRPCReact.d.ts +47 -17
  3. package/dist/createTRPCReact.d.ts.map +1 -1
  4. package/dist/internals/context.d.ts +43 -21
  5. package/dist/internals/context.d.ts.map +1 -1
  6. package/dist/internals/getQueryKey.d.ts +2 -2
  7. package/dist/internals/getQueryKey.js +3 -3
  8. package/dist/internals/getQueryKey.mjs +3 -3
  9. package/dist/internals/trpcResult.d.ts +18 -0
  10. package/dist/internals/trpcResult.d.ts.map +1 -0
  11. package/dist/internals/trpcResult.js +63 -0
  12. package/dist/internals/trpcResult.mjs +40 -0
  13. package/dist/internals/useQueries.d.ts +1 -1
  14. package/dist/internals/useQueries.d.ts.map +1 -1
  15. package/dist/rsc.d.ts +1 -1
  16. package/dist/rsc.d.ts.map +1 -1
  17. package/dist/rsc.js +4 -4
  18. package/dist/rsc.mjs +4 -4
  19. package/dist/server/ssgProxy.d.ts +7 -24
  20. package/dist/server/ssgProxy.d.ts.map +1 -1
  21. package/dist/server/ssgProxy.js +21 -4
  22. package/dist/server/ssgProxy.mjs +21 -4
  23. package/dist/shared/hooks/createHooksInternal.d.ts +4 -2
  24. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
  25. package/dist/shared/hooks/createHooksInternal.js +160 -93
  26. package/dist/shared/hooks/createHooksInternal.mjs +156 -89
  27. package/dist/shared/hooks/types.d.ts +38 -159
  28. package/dist/shared/hooks/types.d.ts.map +1 -1
  29. package/dist/shared/index.js +0 -7
  30. package/dist/shared/index.mjs +0 -1
  31. package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
  32. package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
  33. package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
  34. package/dist/shared/proxy/decorationProxy.js +1 -1
  35. package/dist/shared/proxy/decorationProxy.mjs +1 -1
  36. package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
  37. package/dist/shared/proxy/utilsProxy.d.ts +45 -20
  38. package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
  39. package/dist/shared/proxy/utilsProxy.js +4 -0
  40. package/dist/shared/proxy/utilsProxy.mjs +4 -0
  41. package/dist/shared/types.d.ts +60 -2
  42. package/dist/shared/types.d.ts.map +1 -1
  43. package/dist/utils/createUtilityFunctions.d.ts +2 -2
  44. package/dist/utils/createUtilityFunctions.d.ts.map +1 -1
  45. package/dist/utils/createUtilityFunctions.js +69 -3
  46. package/dist/utils/createUtilityFunctions.mjs +69 -3
  47. package/dist/utils/inferReactQueryProcedure.d.ts +2 -2
  48. package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
  49. package/package.json +22 -19
  50. package/src/createTRPCReact.tsx +276 -65
  51. package/src/internals/context.tsx +105 -24
  52. package/src/internals/getQueryKey.ts +2 -2
  53. package/src/internals/trpcResult.ts +55 -0
  54. package/src/internals/useQueries.ts +36 -31
  55. package/src/rsc.tsx +6 -6
  56. package/src/server/ssgProxy.ts +23 -66
  57. package/src/shared/hooks/createHooksInternal.tsx +222 -151
  58. package/src/shared/hooks/types.ts +64 -348
  59. package/src/shared/polymorphism/mutationLike.ts +8 -6
  60. package/src/shared/polymorphism/queryLike.ts +12 -14
  61. package/src/shared/polymorphism/routerLike.ts +4 -4
  62. package/src/shared/proxy/useQueriesProxy.ts +4 -4
  63. package/src/shared/proxy/utilsProxy.ts +153 -25
  64. package/src/shared/types.ts +229 -1
  65. package/src/utils/createUtilityFunctions.ts +90 -2
  66. package/src/utils/inferReactQueryProcedure.ts +8 -6
  67. package/dist/internals/useHookResult.d.ts +0 -8
  68. package/dist/internals/useHookResult.d.ts.map +0 -1
  69. package/dist/internals/useHookResult.js +0 -35
  70. package/dist/internals/useHookResult.mjs +0 -14
  71. package/dist/shared/hooks/types.js +0 -133
  72. package/dist/shared/hooks/types.mjs +0 -126
  73. package/src/internals/useHookResult.ts +0 -17
@@ -30,7 +30,7 @@ export type InferQueryOptions<
30
30
  TRPCClientErrorLike<TRoot>,
31
31
  TData
32
32
  >,
33
- 'select'
33
+ 'select' | 'queryFn'
34
34
  >;
35
35
 
36
36
  /**
@@ -39,10 +39,12 @@ export type InferQueryOptions<
39
39
  export type InferMutationOptions<
40
40
  TRoot extends AnyRootTypes,
41
41
  TProcedure extends AnyProcedure,
42
+ TMeta = unknown,
42
43
  > = UseTRPCMutationOptions<
43
44
  inferProcedureInput<TProcedure>,
44
45
  TRPCClientErrorLike<TRoot>,
45
- inferTransformedProcedureOutput<TRoot, TProcedure>
46
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
47
+ TMeta
46
48
  >;
47
49
 
48
50
  /**
@@ -78,10 +80,10 @@ type inferReactQueryProcedureOptionsInner<
78
80
  ? $Value extends RouterRecord
79
81
  ? inferReactQueryProcedureOptionsInner<TRoot, $Value>
80
82
  : $Value extends AnyMutationProcedure
81
- ? InferMutationOptions<TRoot, $Value>
82
- : $Value extends AnyQueryProcedure
83
- ? InferQueryOptions<TRoot, $Value>
84
- : never
83
+ ? InferMutationOptions<TRoot, $Value>
84
+ : $Value extends AnyQueryProcedure
85
+ ? InferQueryOptions<TRoot, $Value>
86
+ : never
85
87
  : never;
86
88
  };
87
89
 
@@ -1,8 +0,0 @@
1
- import type { TRPCHookResult } from '../shared/hooks/types';
2
- /**
3
- * Makes a stable reference of the `trpc` prop
4
- */
5
- export declare function useHookResult(value: {
6
- path: readonly string[];
7
- }): TRPCHookResult['trpc'];
8
- //# sourceMappingURL=useHookResult.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHookResult.d.ts","sourceRoot":"","sources":["../../src/internals/useHookResult.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB,GAAG,cAAc,CAAC,MAAM,CAAC,CAQzB"}
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
-
5
- function _interopNamespaceDefault(e) {
6
- var n = Object.create(null);
7
- if (e) {
8
- Object.keys(e).forEach(function (k) {
9
- if (k !== 'default') {
10
- var d = Object.getOwnPropertyDescriptor(e, k);
11
- Object.defineProperty(n, k, d.get ? d : {
12
- enumerable: true,
13
- get: function () { return e[k]; }
14
- });
15
- }
16
- });
17
- }
18
- n.default = e;
19
- return Object.freeze(n);
20
- }
21
-
22
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
-
24
- /**
25
- * Makes a stable reference of the `trpc` prop
26
- */ function useHookResult(value) {
27
- const path = value.path.join('.');
28
- return React__namespace.useMemo(()=>({
29
- path
30
- }), [
31
- path
32
- ]);
33
- }
34
-
35
- exports.useHookResult = useHookResult;
@@ -1,14 +0,0 @@
1
- import * as React from 'react';
2
-
3
- /**
4
- * Makes a stable reference of the `trpc` prop
5
- */ function useHookResult(value) {
6
- const path = value.path.join('.');
7
- return React.useMemo(()=>({
8
- path
9
- }), [
10
- path
11
- ]);
12
- }
13
-
14
- export { useHookResult };
@@ -1,133 +0,0 @@
1
- 'use strict';
2
-
3
- const defaultIdleResult = {
4
- data: null,
5
- connectionStartedAt: 0,
6
- initialConnectionStartedAt: 0,
7
- error: null,
8
- errorUpdatedAt: 0,
9
- connectionError: null,
10
- connectionAttemptCount: 0,
11
- isStarting: false,
12
- isStarted: false,
13
- isConnecting: false,
14
- isPending: false,
15
- isReconnecting: false,
16
- isError: false,
17
- connectionErrorUpdatedAt: 0,
18
- status: 'idle'
19
- };
20
- const getIdleResult = ()=>{
21
- return {
22
- ...defaultIdleResult,
23
- data: null
24
- };
25
- };
26
- const getStartingResult = (// restart: restartSubscriptionFn<TInput>,
27
- previous, error)=>{
28
- const now = Date.now();
29
- if (previous) {
30
- return {
31
- ...defaultIdleResult,
32
- ...previous,
33
- data: null,
34
- connectionError: error ?? null,
35
- isStarting: true,
36
- isConnecting: true,
37
- errorUpdatedAt: 0,
38
- connectionAttemptCount: previous.connectionAttemptCount + 1,
39
- connectionErrorUpdatedAt: error ? now : 0,
40
- connectionStartedAt: 0,
41
- initialConnectionStartedAt: 0,
42
- error: null,
43
- isStarted: false,
44
- isError: false,
45
- status: 'connecting'
46
- };
47
- }
48
- return {
49
- ...getIdleResult(),
50
- connectionError: error ?? null,
51
- isStarting: true,
52
- isConnecting: true,
53
- errorUpdatedAt: 0,
54
- connectionAttemptCount: 0,
55
- connectionErrorUpdatedAt: error ? now : 0,
56
- status: 'connecting'
57
- };
58
- };
59
- const getPendingResult = (previous, data)=>{
60
- const time = Date.now();
61
- if (previous.isStarting) {
62
- return {
63
- ...previous,
64
- error: null,
65
- isStarting: false,
66
- isStarted: true,
67
- isConnecting: false,
68
- isReconnecting: false,
69
- isPending: true,
70
- status: 'pending',
71
- connectionStartedAt: time,
72
- connectionAttemptCount: 0,
73
- connectionError: null,
74
- initialConnectionStartedAt: time
75
- };
76
- }
77
- return {
78
- ...previous,
79
- data: data ?? previous.data,
80
- error: null,
81
- isError: false,
82
- isStarting: false,
83
- isStarted: true,
84
- isConnecting: false,
85
- isReconnecting: false,
86
- isPending: true,
87
- status: 'pending',
88
- connectionStartedAt: time,
89
- connectionAttemptCount: 0,
90
- connectionError: null
91
- };
92
- };
93
- const getReconnectingResult = (previous, error)=>{
94
- return {
95
- ...previous,
96
- isStarting: false,
97
- isStarted: true,
98
- isConnecting: true,
99
- isReconnecting: true,
100
- isPending: false,
101
- status: 'connecting',
102
- connectionError: error,
103
- connectionAttemptCount: previous.connectionAttemptCount + 1
104
- };
105
- };
106
- const getConnectingResult = (previous, error)=>{
107
- if (previous.isReconnecting || previous.isPending) {
108
- if (!error) throw new Error('Reconnecting without error?');
109
- return getReconnectingResult(previous, error);
110
- }
111
- return getStartingResult(/*previous.restart, */ previous, error);
112
- };
113
- const getErrorResult = (previous, error)=>{
114
- return {
115
- ...previous,
116
- isStarting: false,
117
- isStarted: true,
118
- isConnecting: false,
119
- isReconnecting: false,
120
- isPending: false,
121
- isError: true,
122
- status: 'error',
123
- error,
124
- errorUpdatedAt: Date.now()
125
- };
126
- };
127
-
128
- exports.getConnectingResult = getConnectingResult;
129
- exports.getErrorResult = getErrorResult;
130
- exports.getIdleResult = getIdleResult;
131
- exports.getPendingResult = getPendingResult;
132
- exports.getReconnectingResult = getReconnectingResult;
133
- exports.getStartingResult = getStartingResult;
@@ -1,126 +0,0 @@
1
- const defaultIdleResult = {
2
- data: null,
3
- connectionStartedAt: 0,
4
- initialConnectionStartedAt: 0,
5
- error: null,
6
- errorUpdatedAt: 0,
7
- connectionError: null,
8
- connectionAttemptCount: 0,
9
- isStarting: false,
10
- isStarted: false,
11
- isConnecting: false,
12
- isPending: false,
13
- isReconnecting: false,
14
- isError: false,
15
- connectionErrorUpdatedAt: 0,
16
- status: 'idle'
17
- };
18
- const getIdleResult = ()=>{
19
- return {
20
- ...defaultIdleResult,
21
- data: null
22
- };
23
- };
24
- const getStartingResult = (// restart: restartSubscriptionFn<TInput>,
25
- previous, error)=>{
26
- const now = Date.now();
27
- if (previous) {
28
- return {
29
- ...defaultIdleResult,
30
- ...previous,
31
- data: null,
32
- connectionError: error ?? null,
33
- isStarting: true,
34
- isConnecting: true,
35
- errorUpdatedAt: 0,
36
- connectionAttemptCount: previous.connectionAttemptCount + 1,
37
- connectionErrorUpdatedAt: error ? now : 0,
38
- connectionStartedAt: 0,
39
- initialConnectionStartedAt: 0,
40
- error: null,
41
- isStarted: false,
42
- isError: false,
43
- status: 'connecting'
44
- };
45
- }
46
- return {
47
- ...getIdleResult(),
48
- connectionError: error ?? null,
49
- isStarting: true,
50
- isConnecting: true,
51
- errorUpdatedAt: 0,
52
- connectionAttemptCount: 0,
53
- connectionErrorUpdatedAt: error ? now : 0,
54
- status: 'connecting'
55
- };
56
- };
57
- const getPendingResult = (previous, data)=>{
58
- const time = Date.now();
59
- if (previous.isStarting) {
60
- return {
61
- ...previous,
62
- error: null,
63
- isStarting: false,
64
- isStarted: true,
65
- isConnecting: false,
66
- isReconnecting: false,
67
- isPending: true,
68
- status: 'pending',
69
- connectionStartedAt: time,
70
- connectionAttemptCount: 0,
71
- connectionError: null,
72
- initialConnectionStartedAt: time
73
- };
74
- }
75
- return {
76
- ...previous,
77
- data: data ?? previous.data,
78
- error: null,
79
- isError: false,
80
- isStarting: false,
81
- isStarted: true,
82
- isConnecting: false,
83
- isReconnecting: false,
84
- isPending: true,
85
- status: 'pending',
86
- connectionStartedAt: time,
87
- connectionAttemptCount: 0,
88
- connectionError: null
89
- };
90
- };
91
- const getReconnectingResult = (previous, error)=>{
92
- return {
93
- ...previous,
94
- isStarting: false,
95
- isStarted: true,
96
- isConnecting: true,
97
- isReconnecting: true,
98
- isPending: false,
99
- status: 'connecting',
100
- connectionError: error,
101
- connectionAttemptCount: previous.connectionAttemptCount + 1
102
- };
103
- };
104
- const getConnectingResult = (previous, error)=>{
105
- if (previous.isReconnecting || previous.isPending) {
106
- if (!error) throw new Error('Reconnecting without error?');
107
- return getReconnectingResult(previous, error);
108
- }
109
- return getStartingResult(/*previous.restart, */ previous, error);
110
- };
111
- const getErrorResult = (previous, error)=>{
112
- return {
113
- ...previous,
114
- isStarting: false,
115
- isStarted: true,
116
- isConnecting: false,
117
- isReconnecting: false,
118
- isPending: false,
119
- isError: true,
120
- status: 'error',
121
- error,
122
- errorUpdatedAt: Date.now()
123
- };
124
- };
125
-
126
- export { getConnectingResult, getErrorResult, getIdleResult, getPendingResult, getReconnectingResult, getStartingResult };
@@ -1,17 +0,0 @@
1
- import * as React from 'react';
2
- import type { TRPCHookResult } from '../shared/hooks/types';
3
-
4
- /**
5
- * Makes a stable reference of the `trpc` prop
6
- */
7
- export function useHookResult(value: {
8
- path: readonly string[];
9
- }): TRPCHookResult['trpc'] {
10
- const path = value.path.join('.');
11
- return React.useMemo(
12
- () => ({
13
- path,
14
- }),
15
- [path],
16
- );
17
- }