@trpc/server 11.0.0-alpha-tmp-export-from-main-nuke-core.219 → 11.0.0-alpha-tmp-export-from-main.211

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 (209) hide show
  1. package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +9 -0
  2. package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +1 -0
  3. package/dist/@trpc-server/http.d.ts +1 -1
  4. package/dist/@trpc-server/http.d.ts.map +1 -1
  5. package/dist/@trpc-server.d.ts +3 -3
  6. package/dist/@trpc-server.d.ts.map +1 -1
  7. package/dist/adapters/aws-lambda/index.d.ts +1 -1
  8. package/dist/adapters/aws-lambda/index.js +7 -13
  9. package/dist/adapters/aws-lambda/index.mjs +3 -9
  10. package/dist/adapters/aws-lambda/utils.d.ts +1 -1
  11. package/dist/adapters/express.d.ts +1 -1
  12. package/dist/adapters/express.d.ts.map +1 -1
  13. package/dist/adapters/express.js +2 -9
  14. package/dist/adapters/express.mjs +2 -9
  15. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
  16. package/dist/adapters/fastify/index.js +4 -13
  17. package/dist/adapters/fastify/index.mjs +2 -11
  18. package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -1
  19. package/dist/adapters/fetch/index.js +4 -11
  20. package/dist/adapters/fetch/index.mjs +2 -9
  21. package/dist/adapters/fetch/types.d.ts +1 -1
  22. package/dist/adapters/next.d.ts +1 -1
  23. package/dist/adapters/next.js +5 -12
  24. package/dist/adapters/next.mjs +3 -10
  25. package/dist/adapters/node-http/content-type/json/index.js +3 -6
  26. package/dist/adapters/node-http/content-type/json/index.mjs +1 -4
  27. package/dist/adapters/node-http/index.js +2 -9
  28. package/dist/adapters/node-http/index.mjs +2 -9
  29. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
  30. package/dist/adapters/node-http/types.d.ts +2 -2
  31. package/dist/adapters/node-http/types.d.ts.map +1 -1
  32. package/dist/adapters/standalone.d.ts +1 -1
  33. package/dist/adapters/standalone.js +2 -9
  34. package/dist/adapters/standalone.mjs +2 -9
  35. package/dist/adapters/ws.d.ts +1 -2
  36. package/dist/adapters/ws.d.ts.map +1 -1
  37. package/dist/adapters/ws.js +26 -32
  38. package/dist/adapters/ws.mjs +1 -7
  39. package/dist/http.d.ts +6 -6
  40. package/dist/http.d.ts.map +1 -1
  41. package/dist/http.js +21 -13
  42. package/dist/http.mjs +1 -8
  43. package/dist/index.js +41 -16
  44. package/dist/index.mjs +1 -6
  45. package/dist/{nodeHTTPRequestHandler-d8558115.mjs → nodeHTTPRequestHandler-2d5c8791.mjs} +2 -4
  46. package/dist/{nodeHTTPRequestHandler-0bc1dc41.js → nodeHTTPRequestHandler-55f05150.js} +4 -6
  47. package/dist/{nodeHTTPRequestHandler-c7d41cde.js → nodeHTTPRequestHandler-7691fc79.js} +1 -3
  48. package/dist/observable.d.ts +3 -0
  49. package/dist/observable.d.ts.map +1 -0
  50. package/dist/observable.js +32 -0
  51. package/dist/observable.mjs +1 -0
  52. package/dist/rpc.d.ts +2 -2
  53. package/dist/rpc.d.ts.map +1 -1
  54. package/dist/rpc.js +13 -6
  55. package/dist/rpc.mjs +1 -3
  56. package/dist/shared.js +9 -5
  57. package/dist/shared.mjs +1 -3
  58. package/package.json +125 -53
  59. package/src/@trpc-core-unstable-do-not-import-this-please.ts +9 -0
  60. package/src/@trpc-server/http.ts +1 -2
  61. package/src/@trpc-server.ts +3 -3
  62. package/src/adapters/aws-lambda/index.ts +1 -1
  63. package/src/adapters/aws-lambda/utils.ts +1 -1
  64. package/src/adapters/express.ts +2 -1
  65. package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
  66. package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
  67. package/src/adapters/fetch/fetchRequestHandler.ts +1 -1
  68. package/src/adapters/fetch/types.ts +1 -1
  69. package/src/adapters/next.ts +1 -1
  70. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +1 -1
  71. package/src/adapters/node-http/types.ts +3 -2
  72. package/src/adapters/standalone.ts +1 -1
  73. package/src/adapters/ws.ts +10 -9
  74. package/src/http.ts +6 -6
  75. package/src/observable.ts +16 -0
  76. package/src/rpc.ts +2 -2
  77. package/dist/TRPCError-57838b33.js +0 -67
  78. package/dist/TRPCError-af754aba.mjs +0 -63
  79. package/dist/TRPCError-ebbde27d.js +0 -61
  80. package/dist/batchStreamFormatter-1971db27.js +0 -32
  81. package/dist/batchStreamFormatter-378277dc.mjs +0 -30
  82. package/dist/batchStreamFormatter-4375dc8b.js +0 -31
  83. package/dist/bundle-analysis.json +0 -770
  84. package/dist/contentType-9756da28.js +0 -59
  85. package/dist/contentType-b31eab56.js +0 -54
  86. package/dist/contentType-f93c6ba8.mjs +0 -52
  87. package/dist/createProxy-7293f632.mjs +0 -121
  88. package/dist/createProxy-c5cd21e8.js +0 -127
  89. package/dist/createProxy-f6960c7b.js +0 -116
  90. package/dist/initTRPC-6c16fa27.mjs +0 -377
  91. package/dist/initTRPC-8b5714ea.js +0 -385
  92. package/dist/initTRPC-b65b35e2.js +0 -372
  93. package/dist/observable/index.d.ts +0 -5
  94. package/dist/observable/index.d.ts.map +0 -1
  95. package/dist/observable/index.js +0 -111
  96. package/dist/observable/index.mjs +0 -102
  97. package/dist/observable/observable.d.ts +0 -13
  98. package/dist/observable/observable.d.ts.map +0 -1
  99. package/dist/observable/operators.d.ts +0 -8
  100. package/dist/observable/operators.d.ts.map +0 -1
  101. package/dist/observable/types.d.ts +0 -26
  102. package/dist/observable/types.d.ts.map +0 -1
  103. package/dist/observable-7233bd21.mjs +0 -121
  104. package/dist/observable-7865c812.js +0 -125
  105. package/dist/observable-cbbc588a.js +0 -125
  106. package/dist/parseTRPCMessage-3ae1b295.js +0 -67
  107. package/dist/parseTRPCMessage-abbd6862.mjs +0 -62
  108. package/dist/parseTRPCMessage-c6022e94.js +0 -65
  109. package/dist/resolveHTTPResponse-3133d603.js +0 -265
  110. package/dist/resolveHTTPResponse-80c99f62.mjs +0 -291
  111. package/dist/resolveHTTPResponse-9e260431.js +0 -293
  112. package/dist/rootConfig-a1ad09d0.js +0 -48
  113. package/dist/rootConfig-db88d377.js +0 -44
  114. package/dist/rootConfig-f741a4e7.mjs +0 -40
  115. package/dist/router-68063d64.mjs +0 -252
  116. package/dist/router-7a7bb4fd.js +0 -262
  117. package/dist/router-c5bd7780.js +0 -259
  118. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +0 -6
  119. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +0 -1
  120. package/dist/unstable-core-do-not-import/createProxy.d.ts +0 -19
  121. package/dist/unstable-core-do-not-import/createProxy.d.ts.map +0 -1
  122. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +0 -13
  123. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +0 -1
  124. package/dist/unstable-core-do-not-import/error/formatter.d.ts +0 -33
  125. package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +0 -1
  126. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +0 -15
  127. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +0 -1
  128. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
  129. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
  130. package/dist/unstable-core-do-not-import/http/contentType.d.ts +0 -29
  131. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +0 -1
  132. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +0 -5
  133. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +0 -1
  134. package/dist/unstable-core-do-not-import/http/index.d.ts +0 -7
  135. package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
  136. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
  137. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
  138. package/dist/unstable-core-do-not-import/http/types.d.ts +0 -96
  139. package/dist/unstable-core-do-not-import/http/types.d.ts.map +0 -1
  140. package/dist/unstable-core-do-not-import/index.d.ts +0 -34
  141. package/dist/unstable-core-do-not-import/index.d.ts.map +0 -1
  142. package/dist/unstable-core-do-not-import/index.js +0 -44
  143. package/dist/unstable-core-do-not-import/index.mjs +0 -10
  144. package/dist/unstable-core-do-not-import/initTRPC.d.ts +0 -96
  145. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +0 -1
  146. package/dist/unstable-core-do-not-import/middleware.d.ts +0 -105
  147. package/dist/unstable-core-do-not-import/middleware.d.ts.map +0 -1
  148. package/dist/unstable-core-do-not-import/parser.d.ts +0 -30
  149. package/dist/unstable-core-do-not-import/parser.d.ts.map +0 -1
  150. package/dist/unstable-core-do-not-import/procedure.d.ts +0 -72
  151. package/dist/unstable-core-do-not-import/procedure.d.ts.map +0 -1
  152. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +0 -101
  153. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +0 -1
  154. package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -75
  155. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +0 -1
  156. package/dist/unstable-core-do-not-import/router.d.ts +0 -85
  157. package/dist/unstable-core-do-not-import/router.d.ts.map +0 -1
  158. package/dist/unstable-core-do-not-import/rpc/codes.d.ts +0 -51
  159. package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +0 -1
  160. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +0 -97
  161. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +0 -1
  162. package/dist/unstable-core-do-not-import/rpc/index.d.ts +0 -5
  163. package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +0 -1
  164. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +0 -5
  165. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +0 -1
  166. package/dist/unstable-core-do-not-import/serialize.d.ts +0 -62
  167. package/dist/unstable-core-do-not-import/serialize.d.ts.map +0 -1
  168. package/dist/unstable-core-do-not-import/transformer.d.ts +0 -107
  169. package/dist/unstable-core-do-not-import/transformer.d.ts.map +0 -1
  170. package/dist/unstable-core-do-not-import/types.d.ts +0 -98
  171. package/dist/unstable-core-do-not-import/types.d.ts.map +0 -1
  172. package/dist/unstable-core-do-not-import/utils.d.ts +0 -31
  173. package/dist/unstable-core-do-not-import/utils.d.ts.map +0 -1
  174. package/dist/utils-42a3ba6d.js +0 -50
  175. package/dist/utils-cf6178ec.mjs +0 -44
  176. package/dist/utils-e1d51fac.js +0 -49
  177. package/src/observable/index.ts +0 -10
  178. package/src/observable/observable.ts +0 -155
  179. package/src/observable/operators.ts +0 -119
  180. package/src/observable/types.ts +0 -76
  181. package/src/unstable-core-do-not-import/TRPCInferrable.ts +0 -9
  182. package/src/unstable-core-do-not-import/createProxy.ts +0 -59
  183. package/src/unstable-core-do-not-import/error/TRPCError.ts +0 -82
  184. package/src/unstable-core-do-not-import/error/formatter.ts +0 -51
  185. package/src/unstable-core-do-not-import/error/getErrorShape.ts +0 -36
  186. package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
  187. package/src/unstable-core-do-not-import/http/contentType.ts +0 -99
  188. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +0 -57
  189. package/src/unstable-core-do-not-import/http/index.ts +0 -23
  190. package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -458
  191. package/src/unstable-core-do-not-import/http/types.ts +0 -111
  192. package/src/unstable-core-do-not-import/index.ts +0 -107
  193. package/src/unstable-core-do-not-import/initTRPC.ts +0 -206
  194. package/src/unstable-core-do-not-import/middleware.ts +0 -233
  195. package/src/unstable-core-do-not-import/parser.ts +0 -94
  196. package/src/unstable-core-do-not-import/procedure.ts +0 -108
  197. package/src/unstable-core-do-not-import/procedureBuilder.ts +0 -458
  198. package/src/unstable-core-do-not-import/rootConfig.ts +0 -90
  199. package/src/unstable-core-do-not-import/router.ts +0 -370
  200. package/src/unstable-core-do-not-import/rpc/codes.ts +0 -44
  201. package/src/unstable-core-do-not-import/rpc/envelopes.ts +0 -136
  202. package/src/unstable-core-do-not-import/rpc/index.ts +0 -21
  203. package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +0 -85
  204. package/src/unstable-core-do-not-import/serialize.ts +0 -122
  205. package/src/unstable-core-do-not-import/transformer.ts +0 -202
  206. package/src/unstable-core-do-not-import/types.ts +0 -151
  207. package/src/unstable-core-do-not-import/utils.ts +0 -66
  208. package/unstable-core-do-not-import/index.d.ts +0 -1
  209. package/unstable-core-do-not-import/index.js +0 -1
@@ -1,107 +0,0 @@
1
- import type { AnyRootConfig } from './rootConfig';
2
- import type { AnyRouter, inferRouterError } from './router';
3
- import type { TRPCResponse, TRPCResponseMessage, TRPCResultMessage } from './rpc';
4
- /**
5
- * @public
6
- */
7
- export interface DataTransformer {
8
- serialize: (object: any) => any;
9
- deserialize: (object: any) => any;
10
- }
11
- interface InputDataTransformer extends DataTransformer {
12
- /**
13
- * This function runs **on the client** before sending the data to the server.
14
- */
15
- serialize: (object: any) => any;
16
- /**
17
- * This function runs **on the server** to transform the data before it is passed to the resolver
18
- */
19
- deserialize: (object: any) => any;
20
- }
21
- interface OutputDataTransformer extends DataTransformer {
22
- /**
23
- * This function runs **on the server** before sending the data to the client.
24
- */
25
- serialize: (object: any) => any;
26
- /**
27
- * This function runs **only on the client** to transform the data sent from the server.
28
- */
29
- deserialize: (object: any) => any;
30
- }
31
- /**
32
- * @public
33
- */
34
- export interface CombinedDataTransformer {
35
- /**
36
- * Specify how the data sent from the client to the server should be transformed.
37
- */
38
- input: InputDataTransformer;
39
- /**
40
- * Specify how the data sent from the server to the client should be transformed.
41
- */
42
- output: OutputDataTransformer;
43
- }
44
- /**
45
- * @public
46
- */
47
- export type CombinedDataTransformerClient = {
48
- input: Pick<CombinedDataTransformer['input'], 'serialize'>;
49
- output: Pick<CombinedDataTransformer['output'], 'deserialize'>;
50
- };
51
- /**
52
- * @public
53
- */
54
- export type DataTransformerOptions = CombinedDataTransformer | DataTransformer;
55
- /**
56
- * @internal
57
- */
58
- export declare function getDataTransformer(transformer: DataTransformerOptions): CombinedDataTransformer;
59
- /**
60
- * @internal
61
- */
62
- export type DefaultDataTransformer = CombinedDataTransformer & {
63
- _default: true;
64
- };
65
- /**
66
- * @internal
67
- */
68
- export declare const defaultTransformer: DefaultDataTransformer;
69
- /**
70
- * Takes a unserialized `TRPCResponse` and serializes it with the router's transformers
71
- **/
72
- export declare function transformTRPCResponse<TResponse extends TRPCResponse | TRPCResponse[] | TRPCResponseMessage | TRPCResponseMessage[]>(config: AnyRootConfig, itemOrItems: TResponse): import("./rpc").TRPCErrorResponse<import("./rpc").TRPCErrorShape<import("./rpc").TRPC_ERROR_CODE_NUMBER, Record<string, unknown>>> | import("./rpc").TRPCSuccessResponse<unknown> | ({
73
- id: import("./rpc").JSONRPC2.RequestId;
74
- } & TRPCResultMessage<unknown>) | (TRPCResponse | TRPCResponseMessage)[];
75
- /** @internal */
76
- declare function transformResultInner<TRouter extends AnyRouter, TOutput>(response: TRPCResponse<TOutput, inferRouterError<TRouter>> | TRPCResponseMessage<TOutput, inferRouterError<TRouter>>, transformer: DataTransformer): {
77
- readonly ok: false;
78
- readonly error: {
79
- readonly error: inferRouterError<TRouter>;
80
- readonly id?: import("./rpc").JSONRPC2.RequestId | undefined;
81
- readonly jsonrpc?: "2.0" | undefined;
82
- } | {
83
- readonly error: inferRouterError<TRouter>;
84
- readonly id: string | number | null;
85
- readonly jsonrpc?: "2.0" | undefined;
86
- };
87
- readonly result?: undefined;
88
- } | {
89
- readonly ok: true;
90
- readonly result: {
91
- type: "started";
92
- data?: undefined;
93
- } | {
94
- type: "stopped";
95
- data?: undefined;
96
- } | (import("./rpc").TRPCResult<TOutput> & {
97
- type: "data";
98
- });
99
- readonly error?: undefined;
100
- };
101
- /**
102
- * Transforms and validates that the result is a valid TRPCResponse
103
- * @internal
104
- */
105
- export declare function transformResult<TRouter extends AnyRouter, TOutput>(response: TRPCResponse<TOutput, inferRouterError<TRouter>> | TRPCResponseMessage<TOutput, inferRouterError<TRouter>>, transformer: DataTransformer): ReturnType<typeof transformResultInner>;
106
- export {};
107
- //# sourceMappingURL=transformer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,OAAO,CAAC;AAGf;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAChC,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;CACnC;AAED,UAAU,oBAAqB,SAAQ,eAAe;IACpD;;OAEG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAChC;;OAEG;IACH,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;CACnC;AAED,UAAU,qBAAsB,SAAQ,eAAe;IACrD;;OAEG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAChC;;OAEG;IACH,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,KAAK,EAAE,oBAAoB,CAAC;IAC5B;;OAEG;IACH,MAAM,EAAE,qBAAqB,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,KAAK,EAAE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
2
- * ================================
3
- * Useful utility types that doesn't have anything to do with tRPC in particular
4
- * ================================
5
- */
6
- /**
7
- * @public
8
- */
9
- export type Maybe<TType> = TType | null | undefined;
10
- /**
11
- * @internal
12
- * @link https://github.com/ianstormtaylor/superstruct/blob/7973400cd04d8ad92bbdc2b6f35acbfb3c934079/src/utils.ts#L323-L325
13
- */
14
- export type Simplify<TType> = TType extends any[] | Date ? TType : {
15
- [K in keyof TType]: TType[K];
16
- };
17
- /**
18
- * @public
19
- */
20
- export type Dict<TType> = Record<string, TType | undefined>;
21
- /**
22
- * @public
23
- */
24
- export type MaybePromise<TType> = Promise<TType> | TType;
25
- export type FilterKeys<TObj extends object, TFilter> = {
26
- [TKey in keyof TObj]: TObj[TKey] extends TFilter ? TKey : never;
27
- }[keyof TObj];
28
- /**
29
- * @internal
30
- */
31
- export type Filter<TObj extends object, TFilter> = Pick<TObj, FilterKeys<TObj, TFilter>>;
32
- /**
33
- * Unwrap return type if the type is a function (sync or async), else use the type as is
34
- * @internal
35
- */
36
- export type Unwrap<TType> = TType extends (...args: any[]) => infer R ? Awaited<R> : TType;
37
- /**
38
- * Makes the object recursively optional
39
- * @internal
40
- */
41
- export type DeepPartial<TObject> = TObject extends object ? {
42
- [P in keyof TObject]?: DeepPartial<TObject[P]>;
43
- } : TObject;
44
- /**
45
- * Omits the key without removing a potential union
46
- * @internal
47
- */
48
- export type DistributiveOmit<TObj, TKey extends keyof any> = TObj extends any ? Omit<TObj, TKey> : never;
49
- /**
50
- * See https://github.com/microsoft/TypeScript/issues/41966#issuecomment-758187996
51
- * Fixes issues with iterating over keys of objects with index signatures.
52
- * Without this, iterations over keys of objects with index signatures will lose
53
- * type information about the keys and only the index signature will remain.
54
- * @internal
55
- */
56
- export type WithoutIndexSignature<TObj> = {
57
- [K in keyof TObj as string extends K ? never : number extends K ? never : K]: TObj[K];
58
- };
59
- /**
60
- * @internal
61
- * Overwrite properties in `TType` with properties in `TWith`
62
- * Only overwrites properties when the type to be overwritten
63
- * is an object. Otherwise it will just use the type from `TWith`.
64
- */
65
- export type Overwrite<TType, TWith> = TWith extends any ? TType extends object ? {
66
- [K in keyof WithoutIndexSignature<TType> | keyof WithoutIndexSignature<TWith>]: K extends keyof TWith ? TWith[K] : K extends keyof TType ? TType[K] : never;
67
- } & (string extends keyof TWith ? {
68
- [key: string]: TWith[string];
69
- } : number extends keyof TWith ? {
70
- [key: number]: TWith[number];
71
- } : {}) : TWith : never;
72
- /**
73
- * @internal
74
- */
75
- export type ValidateShape<TActualShape, TExpectedShape> = TActualShape extends TExpectedShape ? Exclude<keyof TActualShape, keyof TExpectedShape> extends never ? TActualShape : TExpectedShape : never;
76
- /**
77
- * @internal
78
- */
79
- export type PickFirstDefined<TType, TPick> = undefined extends TType ? undefined extends TPick ? never : TPick : TType;
80
- /**
81
- * ================================
82
- * tRPC specific types
83
- * ================================
84
- */
85
- /**
86
- * @internal
87
- */
88
- export type IntersectionError<TKey extends string> = `The property '${TKey}' in your router collides with a built-in method, rename this router or procedure on your backend.`;
89
- /**
90
- * @internal
91
- */
92
- export type ProtectedIntersection<TType, TWith> = keyof TType & keyof TWith extends never ? TType & TWith : IntersectionError<string & keyof TType & keyof TWith>;
93
- /**
94
- * @internal
95
- * Returns the raw input type of a procedure
96
- */
97
- export type GetRawInputFn = () => Promise<unknown>;
98
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI,KAAK,SAAS,GAAG,EAAE,GAAG,IAAI,GACpD,KAAK,GACL;KAAG,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;CAAE,CAAC;A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AM,KAAK,SAAS,KAAK,GACvB,KAAK,GAAG,KAAK,GACb,iBAAiB,CAAC,MAAM,GAAG,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC"}
@@ -1,31 +0,0 @@
1
- type KeyFromValue<TValue, TType extends Record<PropertyKey, PropertyKey>> = {
2
- [K in keyof TType]: TValue extends TType[K] ? K : never;
3
- }[keyof TType];
4
- type Invert<TType extends Record<PropertyKey, PropertyKey>> = {
5
- [TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
6
- };
7
- /**
8
- * @internal
9
- */
10
- export declare function invert<TRecord extends Record<PropertyKey, PropertyKey>>(obj: TRecord): Invert<TRecord>;
11
- /**
12
- * Ensures there are no duplicate keys when building a procedure.
13
- * @internal
14
- */
15
- export declare function mergeWithoutOverrides<TType extends Record<string, unknown>>(obj1: TType, ...objs: Partial<TType>[]): TType;
16
- /**
17
- * Check that value is object
18
- * @internal
19
- */
20
- export declare function isObject(value: unknown): value is Record<string, unknown>;
21
- /**
22
- * Create an object without inheriting anything from `Object.prototype`
23
- * @internal
24
- */
25
- export declare function omitPrototype<TObj extends Record<string, unknown>>(obj: TObj): TObj;
26
- /**
27
- * @internal
28
- */
29
- export declare function identity<TType>(x: TType): TType;
30
- export {};
31
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/utils.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,CAAC,MAAM,EAAE,KAAK,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI;KACzE,CAAC,IAAI,MAAM,KAAK,GAAG,MAAM,SAAS,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACxD,CAAC,MAAM,KAAK,CAAC,CAAC;AAEf,KAAK,MAAM,CAAC,KAAK,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI;KAC3D,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;CAC5D,CAAC;AACF;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,EACrE,GAAG,EAAE,OAAO,GACX,MAAM,CAAC,OAAO,CAAC,CAOjB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzE,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,GACxB,KAAK,CAYP;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,GAAG,EAAE,IAAI,GACR,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAE/C"}
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * @internal
5
- */ function invert(obj) {
6
- const newObj = Object.create(null);
7
- for(const key in obj){
8
- const v = obj[key];
9
- newObj[v] = key;
10
- }
11
- return newObj;
12
- }
13
- /**
14
- * Ensures there are no duplicate keys when building a procedure.
15
- * @internal
16
- */ function mergeWithoutOverrides(obj1, ...objs) {
17
- const newObj = Object.assign(Object.create(null), obj1);
18
- for (const overrides of objs){
19
- for(const key in overrides){
20
- if (key in newObj && newObj[key] !== overrides[key]) {
21
- throw new Error(`Duplicate key ${key}`);
22
- }
23
- newObj[key] = overrides[key];
24
- }
25
- }
26
- return newObj;
27
- }
28
- /**
29
- * Check that value is object
30
- * @internal
31
- */ function isObject(value) {
32
- return !!value && !Array.isArray(value) && typeof value === 'object';
33
- }
34
- /**
35
- * Create an object without inheriting anything from `Object.prototype`
36
- * @internal
37
- */ function omitPrototype(obj) {
38
- return Object.assign(Object.create(null), obj);
39
- }
40
- /**
41
- * @internal
42
- */ function identity(x) {
43
- return x;
44
- }
45
-
46
- exports.identity = identity;
47
- exports.invert = invert;
48
- exports.isObject = isObject;
49
- exports.mergeWithoutOverrides = mergeWithoutOverrides;
50
- exports.omitPrototype = omitPrototype;
@@ -1,44 +0,0 @@
1
- /**
2
- * @internal
3
- */ function invert(obj) {
4
- const newObj = Object.create(null);
5
- for(const key in obj){
6
- const v = obj[key];
7
- newObj[v] = key;
8
- }
9
- return newObj;
10
- }
11
- /**
12
- * Ensures there are no duplicate keys when building a procedure.
13
- * @internal
14
- */ function mergeWithoutOverrides(obj1, ...objs) {
15
- const newObj = Object.assign(Object.create(null), obj1);
16
- for (const overrides of objs){
17
- for(const key in overrides){
18
- if (key in newObj && newObj[key] !== overrides[key]) {
19
- throw new Error(`Duplicate key ${key}`);
20
- }
21
- newObj[key] = overrides[key];
22
- }
23
- }
24
- return newObj;
25
- }
26
- /**
27
- * Check that value is object
28
- * @internal
29
- */ function isObject(value) {
30
- return !!value && !Array.isArray(value) && typeof value === 'object';
31
- }
32
- /**
33
- * Create an object without inheriting anything from `Object.prototype`
34
- * @internal
35
- */ function omitPrototype(obj) {
36
- return Object.assign(Object.create(null), obj);
37
- }
38
- /**
39
- * @internal
40
- */ function identity(x) {
41
- return x;
42
- }
43
-
44
- export { isObject as a, identity as b, invert as i, mergeWithoutOverrides as m, omitPrototype as o };
@@ -1,49 +0,0 @@
1
- /**
2
- * @internal
3
- */
4
- function invert(obj) {
5
- const newObj = Object.create(null);
6
- for (const key in obj) {
7
- const v = obj[key];
8
- newObj[v] = key;
9
- }
10
- return newObj;
11
- }
12
- /**
13
- * Ensures there are no duplicate keys when building a procedure.
14
- * @internal
15
- */
16
- function mergeWithoutOverrides(obj1, ...objs) {
17
- const newObj = Object.assign(Object.create(null), obj1);
18
- for (const overrides of objs) {
19
- for (const key in overrides) {
20
- if (key in newObj && newObj[key] !== overrides[key]) {
21
- throw new Error(`Duplicate key ${key}`);
22
- }
23
- newObj[key] = overrides[key];
24
- }
25
- }
26
- return newObj;
27
- }
28
- /**
29
- * Check that value is object
30
- * @internal
31
- */
32
- function isObject(value) {
33
- return !!value && !Array.isArray(value) && typeof value === 'object';
34
- }
35
- /**
36
- * Create an object without inheriting anything from `Object.prototype`
37
- * @internal
38
- */
39
- function omitPrototype(obj) {
40
- return Object.assign(Object.create(null), obj);
41
- }
42
- /**
43
- * @internal
44
- */
45
- function identity(x) {
46
- return x;
47
- }
48
-
49
- export { isObject as a, identity as b, invert as i, mergeWithoutOverrides as m, omitPrototype as o };
@@ -1,10 +0,0 @@
1
- export type { inferObservableValue } from './observable';
2
- export { isObservable, observable, observableToPromise } from './observable';
3
- export { map, share, tap } from './operators';
4
- export type {
5
- Observable,
6
- Observer,
7
- TeardownLogic,
8
- Unsubscribable,
9
- UnsubscribeFn,
10
- } from './types';
@@ -1,155 +0,0 @@
1
- import { identity } from '../unstable-core-do-not-import/utils';
2
- import type {
3
- Observable,
4
- Observer,
5
- OperatorFunction,
6
- TeardownLogic,
7
- UnaryFunction,
8
- } from './types';
9
-
10
- /** @public */
11
- export type inferObservableValue<TObservable> = TObservable extends Observable<
12
- infer TValue,
13
- unknown
14
- >
15
- ? TValue
16
- : never;
17
-
18
- /** @public */
19
- export function isObservable(x: unknown): x is Observable<unknown, unknown> {
20
- return typeof x === 'object' && x !== null && 'subscribe' in x;
21
- }
22
-
23
- /** @public */
24
- export function observable<TValue, TError = unknown>(
25
- subscribe: (observer: Observer<TValue, TError>) => TeardownLogic,
26
- ): Observable<TValue, TError> {
27
- const self: Observable<TValue, TError> = {
28
- subscribe(observer) {
29
- let teardownRef: TeardownLogic | null = null;
30
- let isDone = false;
31
- let unsubscribed = false;
32
- let teardownImmediately = false;
33
- function unsubscribe() {
34
- if (teardownRef === null) {
35
- teardownImmediately = true;
36
- return;
37
- }
38
- if (unsubscribed) {
39
- return;
40
- }
41
- unsubscribed = true;
42
-
43
- if (typeof teardownRef === 'function') {
44
- teardownRef();
45
- } else if (teardownRef) {
46
- teardownRef.unsubscribe();
47
- }
48
- }
49
- teardownRef = subscribe({
50
- next(value) {
51
- if (isDone) {
52
- return;
53
- }
54
- observer.next?.(value);
55
- },
56
- error(err) {
57
- if (isDone) {
58
- return;
59
- }
60
- isDone = true;
61
- observer.error?.(err);
62
- unsubscribe();
63
- },
64
- complete() {
65
- if (isDone) {
66
- return;
67
- }
68
- isDone = true;
69
- observer.complete?.();
70
- unsubscribe();
71
- },
72
- });
73
- if (teardownImmediately) {
74
- unsubscribe();
75
- }
76
- return {
77
- unsubscribe,
78
- };
79
- },
80
- pipe(
81
- ...operations: OperatorFunction<any, any, any, any>[]
82
- ): Observable<any, any> {
83
- return pipeFromArray(operations)(self) as any;
84
- },
85
- };
86
- return self;
87
- }
88
-
89
- function pipeFromArray<TSource, TReturn>(
90
- fns: UnaryFunction<TSource, TReturn>[],
91
- ): UnaryFunction<TSource, TReturn> {
92
- if (fns.length === 0) {
93
- return identity as UnaryFunction<any, any>;
94
- }
95
-
96
- if (fns.length === 1) {
97
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
98
- return fns[0]!;
99
- }
100
-
101
- return function piped(input: TSource): TReturn {
102
- return fns.reduce(
103
- (prev: any, fn: UnaryFunction<TSource, TReturn>) => fn(prev),
104
- input as any,
105
- );
106
- };
107
- }
108
-
109
- class ObservableAbortError extends Error {
110
- constructor(message: string) {
111
- super(message);
112
- this.name = 'ObservableAbortError';
113
- Object.setPrototypeOf(this, ObservableAbortError.prototype);
114
- }
115
- }
116
-
117
- /** @internal */
118
- export function observableToPromise<TValue>(
119
- observable: Observable<TValue, unknown>,
120
- ) {
121
- let abort: () => void;
122
- const promise = new Promise<TValue>((resolve, reject) => {
123
- let isDone = false;
124
- function onDone() {
125
- if (isDone) {
126
- return;
127
- }
128
- isDone = true;
129
- reject(new ObservableAbortError('This operation was aborted.'));
130
- obs$.unsubscribe();
131
- }
132
- const obs$ = observable.subscribe({
133
- next(data) {
134
- isDone = true;
135
- resolve(data);
136
- onDone();
137
- },
138
- error(data) {
139
- isDone = true;
140
- reject(data);
141
- onDone();
142
- },
143
- complete() {
144
- isDone = true;
145
- onDone();
146
- },
147
- });
148
- abort = onDone;
149
- });
150
- return {
151
- promise,
152
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
153
- abort: abort!,
154
- };
155
- }
@@ -1,119 +0,0 @@
1
- import type {
2
- MonoTypeOperatorFunction,
3
- Observer,
4
- OperatorFunction,
5
- Unsubscribable,
6
- } from './types';
7
-
8
- export function map<TValueBefore, TError, TValueAfter>(
9
- project: (value: TValueBefore, index: number) => TValueAfter,
10
- ): OperatorFunction<TValueBefore, TError, TValueAfter, TError> {
11
- return (originalObserver) => {
12
- return {
13
- subscribe(observer) {
14
- let index = 0;
15
- const subscription = originalObserver.subscribe({
16
- next(value) {
17
- observer.next?.(project(value, index++));
18
- },
19
- error(error) {
20
- observer.error?.(error);
21
- },
22
- complete() {
23
- observer.complete?.();
24
- },
25
- });
26
- return subscription;
27
- },
28
- };
29
- };
30
- }
31
-
32
- interface ShareConfig {}
33
- export function share<TValue, TError>(
34
- _opts?: ShareConfig,
35
- ): MonoTypeOperatorFunction<TValue, TError> {
36
- return (originalObserver) => {
37
- let refCount = 0;
38
-
39
- let subscription: Unsubscribable | null = null;
40
- const observers: Partial<Observer<TValue, TError>>[] = [];
41
-
42
- function startIfNeeded() {
43
- if (subscription) {
44
- return;
45
- }
46
- subscription = originalObserver.subscribe({
47
- next(value) {
48
- for (const observer of observers) {
49
- observer.next?.(value);
50
- }
51
- },
52
- error(error) {
53
- for (const observer of observers) {
54
- observer.error?.(error);
55
- }
56
- },
57
- complete() {
58
- for (const observer of observers) {
59
- observer.complete?.();
60
- }
61
- },
62
- });
63
- }
64
- function resetIfNeeded() {
65
- // "resetOnRefCountZero"
66
- if (refCount === 0 && subscription) {
67
- const _sub = subscription;
68
- subscription = null;
69
- _sub.unsubscribe();
70
- }
71
- }
72
-
73
- return {
74
- subscribe(observer) {
75
- refCount++;
76
-
77
- observers.push(observer);
78
- startIfNeeded();
79
- return {
80
- unsubscribe() {
81
- refCount--;
82
- resetIfNeeded();
83
-
84
- const index = observers.findIndex((v) => v === observer);
85
-
86
- if (index > -1) {
87
- observers.splice(index, 1);
88
- }
89
- },
90
- };
91
- },
92
- };
93
- };
94
- }
95
-
96
- export function tap<TValue, TError>(
97
- observer: Partial<Observer<TValue, TError>>,
98
- ): MonoTypeOperatorFunction<TValue, TError> {
99
- return (originalObserver) => {
100
- return {
101
- subscribe(observer2) {
102
- return originalObserver.subscribe({
103
- next(v) {
104
- observer.next?.(v);
105
- observer2.next?.(v);
106
- },
107
- error(v) {
108
- observer.error?.(v);
109
- observer2.error?.(v);
110
- },
111
- complete() {
112
- observer.complete?.();
113
- observer2.complete?.();
114
- },
115
- });
116
- },
117
- };
118
- };
119
- }