@trpc/server 11.0.0-rc.474 → 11.0.0-rc.475

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 (38) hide show
  1. package/dist/@trpc/server/index.d.ts +5 -1
  2. package/dist/@trpc/server/index.d.ts.map +1 -1
  3. package/dist/adapters/ws.d.ts.map +1 -1
  4. package/dist/adapters/ws.js +36 -6
  5. package/dist/adapters/ws.mjs +37 -7
  6. package/dist/bundle-analysis.json +112 -97
  7. package/dist/index.js +3 -2
  8. package/dist/index.mjs +1 -1
  9. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +2 -2
  10. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
  11. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +8 -0
  12. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
  13. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -1
  14. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +6 -2
  15. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +6 -2
  16. package/dist/unstable-core-do-not-import/stream/sse.d.ts +2 -30
  17. package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
  18. package/dist/unstable-core-do-not-import/stream/sse.js +4 -20
  19. package/dist/unstable-core-do-not-import/stream/sse.mjs +5 -19
  20. package/dist/unstable-core-do-not-import/stream/tracked.d.ts +31 -0
  21. package/dist/unstable-core-do-not-import/stream/tracked.d.ts.map +1 -0
  22. package/dist/unstable-core-do-not-import/stream/tracked.js +29 -0
  23. package/dist/unstable-core-do-not-import/stream/tracked.mjs +25 -0
  24. package/dist/unstable-core-do-not-import/transformer.d.ts +1 -0
  25. package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -1
  26. package/dist/unstable-core-do-not-import.d.ts +1 -0
  27. package/dist/unstable-core-do-not-import.d.ts.map +1 -1
  28. package/dist/unstable-core-do-not-import.js +4 -2
  29. package/dist/unstable-core-do-not-import.mjs +2 -1
  30. package/package.json +2 -2
  31. package/src/@trpc/server/index.ts +4 -0
  32. package/src/adapters/ws.ts +42 -6
  33. package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -2
  34. package/src/unstable-core-do-not-import/rpc/envelopes.ts +18 -2
  35. package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +5 -1
  36. package/src/unstable-core-do-not-import/stream/sse.ts +21 -65
  37. package/src/unstable-core-do-not-import/stream/tracked.ts +55 -0
  38. package/src/unstable-core-do-not-import.ts +1 -0
@@ -2,7 +2,11 @@ export { TRPCError,
2
2
  /**
3
3
  * @deprecated use `experimental_trpcMiddleware` instead
4
4
  */
5
- experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, initTRPC, callProcedure as callTRPCProcedure, getTRPCErrorFromUnknown, transformTRPCResponse, createFlatProxy as createTRPCFlatProxy, type inferProcedureInput, type inferProcedureOutput, type inferProcedureBuilderResolverOptions, type inferRouterError, type inferRouterInputs, type inferRouterOutputs, type inferRouterContext, type inferClientTypes as inferTRPCClientTypes, type AnyClientTypes as AnyTRPCClientTypes, type inferTransformedProcedureOutput, type inferTransformedSubscriptionOutput, type AnyProcedure as AnyTRPCProcedure, type AnyRouter as AnyTRPCRouter, type AnyMiddlewareFunction as AnyTRPCMiddlewareFunction, type CombinedDataTransformer as TRPCCombinedDataTransformer, type ProcedureType as TRPCProcedureType, type AnyMutationProcedure as AnyTRPCMutationProcedure, type AnyQueryProcedure as AnyTRPCQueryProcedure, type RouterRecord as TRPCRouterRecord, type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure, type ProcedureOptions as TRPCProcedureOptions, type CreateContextCallback, type MutationProcedure as TRPCMutationProcedure, type QueryProcedure as TRPCQueryProcedure, type SubscriptionProcedure as TRPCSubscriptionProcedure, type TRPCBuilder, sse, } from '../../unstable-core-do-not-import';
5
+ experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, initTRPC, callProcedure as callTRPCProcedure, getTRPCErrorFromUnknown, transformTRPCResponse, createFlatProxy as createTRPCFlatProxy, type inferProcedureInput, type inferProcedureOutput, type inferProcedureBuilderResolverOptions, type inferRouterError, type inferRouterInputs, type inferRouterOutputs, type inferRouterContext, type inferClientTypes as inferTRPCClientTypes, type AnyClientTypes as AnyTRPCClientTypes, type inferTransformedProcedureOutput, type inferTransformedSubscriptionOutput, type AnyProcedure as AnyTRPCProcedure, type AnyRouter as AnyTRPCRouter, type AnyMiddlewareFunction as AnyTRPCMiddlewareFunction, type CombinedDataTransformer as TRPCCombinedDataTransformer, type ProcedureType as TRPCProcedureType, type AnyMutationProcedure as AnyTRPCMutationProcedure, type AnyQueryProcedure as AnyTRPCQueryProcedure, type RouterRecord as TRPCRouterRecord, type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure, type ProcedureOptions as TRPCProcedureOptions, type CreateContextCallback, type MutationProcedure as TRPCMutationProcedure, type QueryProcedure as TRPCQueryProcedure, type SubscriptionProcedure as TRPCSubscriptionProcedure, type TRPCBuilder,
6
+ /**
7
+ * @deprecated use `tracked(id, data)` instead
8
+ */
9
+ sse, tracked, } from '../../unstable-core-do-not-import';
6
10
  export type {
7
11
  /**
8
12
  * @deprecated use `AnyTRPCProcedure` instead
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS;AACT;;GAEG;AACH,iCAAiC,EACjC,iCAAiC,IAAI,2BAA2B,EAChE,QAAQ,EAER,aAAa,IAAI,iBAAiB,EAClC,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,IAAI,mBAAmB,EACtC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oCAAoC,EACzC,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,gBA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AM,MAAM,0BAA0B,CAAC,OAAO,SAAS,SAAS,IAC9D,kBAAkB,CAAC,OAAO,EAAE,eAAe,CAAC,GAC1C,qBAAqB,CACnB,kBAAkB,CAAC,OAAO,CAAC,EAC3B,kBAAkB,CAAC,OAAO,CAAC,CAC5B,CAAC;AAEN;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,OAAO,SAAS,SAAS,IACrD,0BAA0B,CAAC,OAAO,CAAC,GAAG;IACpC,GAAG,EAAE,EAAE,CAAC,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE;QACV;;;WAGG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;;WAGG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB;;;WAGG;QACH,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAGJ,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,SAAS,EAC9D,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,YAKnB,EAAE,CAAC,SAAS,OAAO,eAAe,mBAuWzD;AAiCD,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EACvD,IAAI,EAAE,iBAAiB,CAAC,OAAO,CAAC;;EA+BjC"}
@@ -6,6 +6,7 @@ var utils = require('../unstable-core-do-not-import/utils.js');
6
6
  var parseConnectionParams = require('../unstable-core-do-not-import/http/parseConnectionParams.js');
7
7
  var parseTRPCMessage = require('../unstable-core-do-not-import/rpc/parseTRPCMessage.js');
8
8
  var observable = require('../observable/observable.js');
9
+ var tracked = require('../unstable-core-do-not-import/stream/tracked.js');
9
10
  var transformer = require('../unstable-core-do-not-import/transformer.js');
10
11
  var toURL = require('../unstable-core-do-not-import/http/toURL.js');
11
12
  require('../unstable-core-do-not-import/rootConfig.js');
@@ -87,9 +88,22 @@ function getWSConnectionHandler(opts) {
87
88
  clientSubscriptions.get(id)?.abort();
88
89
  return;
89
90
  }
90
- const { path , input } = msg.params;
91
+ const { path , lastEventId } = msg.params;
92
+ let { input } = msg.params;
91
93
  const type = msg.method;
92
94
  try {
95
+ if (lastEventId !== undefined) {
96
+ if (utils.isObject(input)) {
97
+ input = {
98
+ ...input,
99
+ lastEventId: lastEventId
100
+ };
101
+ } else {
102
+ input ?? (input = {
103
+ lastEventId: lastEventId
104
+ });
105
+ }
106
+ }
93
107
  await ctxPromise; // asserts context has been set
94
108
  const result = await router.callProcedure({
95
109
  procedures: router$1._def.procedures,
@@ -98,7 +112,14 @@ function getWSConnectionHandler(opts) {
98
112
  ctx,
99
113
  type
100
114
  });
115
+ const isIterableResult = utils.isAsyncIterable(result) || observable.isObservable(result);
101
116
  if (type !== 'subscription') {
117
+ if (isIterableResult) {
118
+ throw new TRPCError.TRPCError({
119
+ code: 'UNSUPPORTED_MEDIA_TYPE',
120
+ message: `Cannot return an async iterable or observable from a ${type} procedure with WebSockets`
121
+ });
122
+ }
102
123
  // send the value as data if the method is not a subscription
103
124
  respond({
104
125
  id,
@@ -110,7 +131,7 @@ function getWSConnectionHandler(opts) {
110
131
  });
111
132
  return;
112
133
  }
113
- if (!observable.isObservable(result) && !utils.isAsyncIterable(result)) {
134
+ if (!isIterableResult) {
114
135
  throw new TRPCError.TRPCError({
115
136
  message: `Subscription ${path} did not return an observable or a AsyncGenerator`,
116
137
  code: 'INTERNAL_SERVER_ERROR'
@@ -171,13 +192,22 @@ function getWSConnectionHandler(opts) {
171
192
  if (next.done) {
172
193
  break;
173
194
  }
195
+ const result = {
196
+ type: 'data',
197
+ data: next.value
198
+ };
199
+ if (tracked.isTrackedEnvelope(next.value)) {
200
+ const [id1, data] = next.value;
201
+ result.id = id1;
202
+ result.data = {
203
+ id: id1,
204
+ data
205
+ };
206
+ }
174
207
  respond({
175
208
  id,
176
209
  jsonrpc,
177
- result: {
178
- type: 'data',
179
- data: next.value
180
- }
210
+ result
181
211
  });
182
212
  }
183
213
  await iterator.return?.();
@@ -1,9 +1,10 @@
1
1
  import { getErrorShape } from '../unstable-core-do-not-import/error/getErrorShape.mjs';
2
2
  import { TRPCError, getTRPCErrorFromUnknown } from '../unstable-core-do-not-import/error/TRPCError.mjs';
3
- import { run, isAsyncIterable, isObject } from '../unstable-core-do-not-import/utils.mjs';
3
+ import { run, isObject, isAsyncIterable } from '../unstable-core-do-not-import/utils.mjs';
4
4
  import { parseConnectionParamsFromUnknown } from '../unstable-core-do-not-import/http/parseConnectionParams.mjs';
5
5
  import { parseTRPCMessage } from '../unstable-core-do-not-import/rpc/parseTRPCMessage.mjs';
6
6
  import { isObservable, observableToAsyncIterable } from '../observable/observable.mjs';
7
+ import { isTrackedEnvelope } from '../unstable-core-do-not-import/stream/tracked.mjs';
7
8
  import { transformTRPCResponse } from '../unstable-core-do-not-import/transformer.mjs';
8
9
  import { toURL } from '../unstable-core-do-not-import/http/toURL.mjs';
9
10
  import '../unstable-core-do-not-import/rootConfig.mjs';
@@ -85,9 +86,22 @@ function getWSConnectionHandler(opts) {
85
86
  clientSubscriptions.get(id)?.abort();
86
87
  return;
87
88
  }
88
- const { path , input } = msg.params;
89
+ const { path , lastEventId } = msg.params;
90
+ let { input } = msg.params;
89
91
  const type = msg.method;
90
92
  try {
93
+ if (lastEventId !== undefined) {
94
+ if (isObject(input)) {
95
+ input = {
96
+ ...input,
97
+ lastEventId: lastEventId
98
+ };
99
+ } else {
100
+ input ?? (input = {
101
+ lastEventId: lastEventId
102
+ });
103
+ }
104
+ }
91
105
  await ctxPromise; // asserts context has been set
92
106
  const result = await callProcedure({
93
107
  procedures: router._def.procedures,
@@ -96,7 +110,14 @@ function getWSConnectionHandler(opts) {
96
110
  ctx,
97
111
  type
98
112
  });
113
+ const isIterableResult = isAsyncIterable(result) || isObservable(result);
99
114
  if (type !== 'subscription') {
115
+ if (isIterableResult) {
116
+ throw new TRPCError({
117
+ code: 'UNSUPPORTED_MEDIA_TYPE',
118
+ message: `Cannot return an async iterable or observable from a ${type} procedure with WebSockets`
119
+ });
120
+ }
100
121
  // send the value as data if the method is not a subscription
101
122
  respond({
102
123
  id,
@@ -108,7 +129,7 @@ function getWSConnectionHandler(opts) {
108
129
  });
109
130
  return;
110
131
  }
111
- if (!isObservable(result) && !isAsyncIterable(result)) {
132
+ if (!isIterableResult) {
112
133
  throw new TRPCError({
113
134
  message: `Subscription ${path} did not return an observable or a AsyncGenerator`,
114
135
  code: 'INTERNAL_SERVER_ERROR'
@@ -169,13 +190,22 @@ function getWSConnectionHandler(opts) {
169
190
  if (next.done) {
170
191
  break;
171
192
  }
193
+ const result = {
194
+ type: 'data',
195
+ data: next.value
196
+ };
197
+ if (isTrackedEnvelope(next.value)) {
198
+ const [id1, data] = next.value;
199
+ result.id = id1;
200
+ result.data = {
201
+ id: id1,
202
+ data
203
+ };
204
+ }
172
205
  respond({
173
206
  id,
174
207
  jsonrpc,
175
- result: {
176
- type: 'data',
177
- data: next.value
178
- }
208
+ result
179
209
  });
180
210
  }
181
211
  await iterator.return?.();