@trpc/server 11.0.0-next-beta.304 → 11.0.0-next-beta.305

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.
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 93191,
3
- "bundleOrigSize": 148516,
4
- "bundleReduction": 37.25,
2
+ "bundleSize": 92666,
3
+ "bundleOrigSize": 147947,
4
+ "bundleReduction": 37.37,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/adapters/ws.ts",
@@ -15,7 +15,7 @@
15
15
  "dependents": [
16
16
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
17
17
  ],
18
- "percent": 10.91,
18
+ "percent": 10.97,
19
19
  "reduction": 0
20
20
  },
21
21
  {
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "removedExports": [],
29
29
  "dependents": [],
30
- "percent": 10.07,
30
+ "percent": 10.13,
31
31
  "reduction": 21.23
32
32
  },
33
33
  {
@@ -46,7 +46,7 @@
46
46
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts",
47
47
  "/src/unstable-core-do-not-import/initTRPC.ts"
48
48
  ],
49
- "percent": 6.51,
49
+ "percent": 6.55,
50
50
  "reduction": 38.58
51
51
  },
52
52
  {
@@ -62,7 +62,7 @@
62
62
  "/src/unstable-core-do-not-import.ts",
63
63
  "/src/unstable-core-do-not-import/initTRPC.ts"
64
64
  ],
65
- "percent": 6.12,
65
+ "percent": 6.16,
66
66
  "reduction": 58.57
67
67
  },
68
68
  {
@@ -78,7 +78,7 @@
78
78
  "dependents": [
79
79
  "/src/adapters/node-http/content-type/form-data/index.ts"
80
80
  ],
81
- "percent": 5.34,
81
+ "percent": 5.37,
82
82
  "reduction": 36.77
83
83
  },
84
84
  {
@@ -92,7 +92,7 @@
92
92
  ],
93
93
  "removedExports": [],
94
94
  "dependents": [],
95
- "percent": 4.74,
95
+ "percent": 4.77,
96
96
  "reduction": 32.71
97
97
  },
98
98
  {
@@ -106,7 +106,7 @@
106
106
  "dependents": [
107
107
  "/src/adapters/node-http/index.ts"
108
108
  ],
109
- "percent": 4.22,
109
+ "percent": 4.24,
110
110
  "reduction": 13.56
111
111
  },
112
112
  {
@@ -120,25 +120,9 @@
120
120
  "dependents": [
121
121
  "/src/adapters/fetch/index.ts"
122
122
  ],
123
- "percent": 3.81,
123
+ "percent": 3.84,
124
124
  "reduction": 9.5
125
125
  },
126
- {
127
- "id": "/src/observable/observable.ts",
128
- "size": 3430,
129
- "origSize": 3627,
130
- "renderedExports": [
131
- "isObservable",
132
- "observable",
133
- "observableToPromise"
134
- ],
135
- "removedExports": [],
136
- "dependents": [
137
- "/src/observable/index.ts"
138
- ],
139
- "percent": 3.68,
140
- "reduction": 5.43
141
- },
142
126
  {
143
127
  "id": "/src/adapters/aws-lambda/utils.ts",
144
128
  "size": 3308,
@@ -155,13 +139,30 @@
155
139
  "dependents": [
156
140
  "/src/adapters/aws-lambda/index.ts"
157
141
  ],
158
- "percent": 3.55,
142
+ "percent": 3.57,
159
143
  "reduction": 36.48
160
144
  },
145
+ {
146
+ "id": "/src/observable/observable.ts",
147
+ "size": 3129,
148
+ "origSize": 3150,
149
+ "renderedExports": [
150
+ "isObservable",
151
+ "observable",
152
+ "observableToPromise"
153
+ ],
154
+ "removedExports": [],
155
+ "dependents": [
156
+ "/src/observable/index.ts",
157
+ "/src/observable/operators.ts"
158
+ ],
159
+ "percent": 3.38,
160
+ "reduction": 0.67
161
+ },
161
162
  {
162
163
  "id": "/src/observable/operators.ts",
163
- "size": 2980,
164
- "origSize": 2812,
164
+ "size": 2756,
165
+ "origSize": 2720,
165
166
  "renderedExports": [
166
167
  "map",
167
168
  "share",
@@ -171,7 +172,7 @@
171
172
  "dependents": [
172
173
  "/src/observable/index.ts"
173
174
  ],
174
- "percent": 3.2,
175
+ "percent": 2.97,
175
176
  "reduction": 0
176
177
  },
177
178
  {
@@ -191,7 +192,7 @@
191
192
  "/src/unstable-core-do-not-import/router.ts",
192
193
  "/src/unstable-core-do-not-import/initTRPC.ts"
193
194
  ],
194
- "percent": 2.94,
195
+ "percent": 2.96,
195
196
  "reduction": 45.94
196
197
  },
197
198
  {
@@ -205,7 +206,7 @@
205
206
  "dependents": [
206
207
  "/src/unstable-core-do-not-import.ts"
207
208
  ],
208
- "percent": 2.93,
209
+ "percent": 2.94,
209
210
  "reduction": 39.13
210
211
  },
211
212
  {
@@ -225,7 +226,7 @@
225
226
  "/src/unstable-core-do-not-import/initTRPC.ts",
226
227
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
227
228
  ],
228
- "percent": 2.82,
229
+ "percent": 2.83,
229
230
  "reduction": 55.5
230
231
  },
231
232
  {
@@ -240,7 +241,7 @@
240
241
  "/src/adapters/fastify/index.ts",
241
242
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
242
243
  ],
243
- "percent": 2.78,
244
+ "percent": 2.79,
244
245
  "reduction": 35.33
245
246
  },
246
247
  {
@@ -252,7 +253,7 @@
252
253
  ],
253
254
  "removedExports": [],
254
255
  "dependents": [],
255
- "percent": 2.73,
256
+ "percent": 2.74,
256
257
  "reduction": 31.37
257
258
  },
258
259
  {
@@ -273,7 +274,7 @@
273
274
  "/src/unstable-core-do-not-import/middleware.ts",
274
275
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
275
276
  ],
276
- "percent": 1.86,
277
+ "percent": 1.87,
277
278
  "reduction": 19.47
278
279
  },
279
280
  {
@@ -287,7 +288,7 @@
287
288
  "dependents": [
288
289
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts"
289
290
  ],
290
- "percent": 1.76,
291
+ "percent": 1.77,
291
292
  "reduction": 34.79
292
293
  },
293
294
  {
@@ -299,7 +300,7 @@
299
300
  ],
300
301
  "removedExports": [],
301
302
  "dependents": [],
302
- "percent": 1.72,
303
+ "percent": 1.73,
303
304
  "reduction": 29.12
304
305
  },
305
306
  {
@@ -313,7 +314,7 @@
313
314
  "dependents": [
314
315
  "/src/adapters/node-http/content-type/json/index.ts"
315
316
  ],
316
- "percent": 1.71,
317
+ "percent": 1.72,
317
318
  "reduction": 0.19
318
319
  },
319
320
  {
@@ -325,7 +326,7 @@
325
326
  ],
326
327
  "removedExports": [],
327
328
  "dependents": [],
328
- "percent": 1.7,
329
+ "percent": 1.71,
329
330
  "reduction": 21.04
330
331
  },
331
332
  {
@@ -355,7 +356,7 @@
355
356
  "/src/unstable-core-do-not-import/router.ts",
356
357
  "/src/unstable-core-do-not-import/initTRPC.ts"
357
358
  ],
358
- "percent": 1.62,
359
+ "percent": 1.63,
359
360
  "reduction": 5.58
360
361
  },
361
362
  {
@@ -369,7 +370,7 @@
369
370
  "dependents": [
370
371
  "/src/adapters/fastify/index.ts"
371
372
  ],
372
- "percent": 1.59,
373
+ "percent": 1.6,
373
374
  "reduction": 34.33
374
375
  },
375
376
  {
@@ -383,7 +384,7 @@
383
384
  "dependents": [
384
385
  "/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts"
385
386
  ],
386
- "percent": 1.49,
387
+ "percent": 1.5,
387
388
  "reduction": 0
388
389
  },
389
390
  {
@@ -399,7 +400,7 @@
399
400
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts",
400
401
  "/src/unstable-core-do-not-import/error/getErrorShape.ts"
401
402
  ],
402
- "percent": 1.36,
403
+ "percent": 1.37,
403
404
  "reduction": 22.76
404
405
  },
405
406
  {
@@ -414,7 +415,7 @@
414
415
  "/src/unstable-core-do-not-import.ts",
415
416
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
416
417
  ],
417
- "percent": 1.06,
418
+ "percent": 1.07,
418
419
  "reduction": 56.22
419
420
  },
420
421
  {
@@ -436,7 +437,7 @@
436
437
  "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
437
438
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
438
439
  ],
439
- "percent": 0.87,
440
+ "percent": 0.88,
440
441
  "reduction": 19.78
441
442
  },
442
443
  {
@@ -537,7 +538,7 @@
537
538
  ],
538
539
  "removedExports": [],
539
540
  "dependents": [],
540
- "percent": 0.36,
541
+ "percent": 0.37,
541
542
  "reduction": 71.37
542
543
  },
543
544
  {
@@ -551,7 +552,7 @@
551
552
  "dependents": [
552
553
  "/src/adapters/node-http/nodeHTTPRequestHandler.ts"
553
554
  ],
554
- "percent": 0.31,
555
+ "percent": 0.32,
555
556
  "reduction": 35.11
556
557
  },
557
558
  {
@@ -589,10 +590,10 @@
589
590
  ],
590
591
  "removedExports": [],
591
592
  "dependents": [
592
- "/src/adapters/node-http/content-type/form-data/index.ts",
593
- "/src/adapters/node-http/content-type/json/index.ts"
593
+ "/src/adapters/node-http/content-type/json/index.ts",
594
+ "/src/adapters/node-http/content-type/form-data/index.ts"
594
595
  ],
595
- "percent": 0.12,
596
+ "percent": 0.13,
596
597
  "reduction": 86.68
597
598
  },
598
599
  {
@@ -657,9 +658,9 @@
657
658
  "reduction": 100
658
659
  },
659
660
  {
660
- "id": "/src/unstable-core-do-not-import.ts",
661
+ "id": "/src/shared.ts",
661
662
  "size": 0,
662
- "origSize": 1552,
663
+ "origSize": 653,
663
664
  "renderedExports": [],
664
665
  "removedExports": [],
665
666
  "dependents": [],
@@ -667,9 +668,9 @@
667
668
  "reduction": 100
668
669
  },
669
670
  {
670
- "id": "/src/shared.ts",
671
+ "id": "/src/unstable-core-do-not-import.ts",
671
672
  "size": 0,
672
- "origSize": 653,
673
+ "origSize": 1552,
673
674
  "renderedExports": [],
674
675
  "removedExports": [],
675
676
  "dependents": [],
@@ -715,8 +716,8 @@
715
716
  "renderedExports": [],
716
717
  "removedExports": [],
717
718
  "dependents": [
718
- "/src/adapters/next.ts",
719
719
  "/src/adapters/express.ts",
720
+ "/src/adapters/next.ts",
720
721
  "/src/adapters/standalone.ts"
721
722
  ],
722
723
  "percent": 0,
@@ -1 +1 @@
1
- {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../src/observable/observable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EAER,aAAa,EAEd,MAAM,SAAS,CAAC;AAMjB,cAAc;AACd,MAAM,MAAM,oBAAoB,CAAC,WAAW,IAAI,WAAW,SAAS,UAAU,CAC5E,MAAM,MAAM,EACZ,OAAO,CACR,GACG,MAAM,GACN,KAAK,CAAC;AAEV,cAAc;AACd,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAE1E;AAED,cAAc;AACd,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,EACjD,SAAS,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,aAAa,GAC/D,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CA6D5B;AA8BD,gBAAgB;AAChB,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;;iBAEtB,IAAI;EAkCtB"}
1
+ {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../src/observable/observable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EAER,aAAa,EAEd,MAAM,SAAS,CAAC;AAEjB,cAAc;AACd,MAAM,MAAM,oBAAoB,CAAC,WAAW,IAAI,WAAW,SAAS,UAAU,CAC5E,MAAM,MAAM,EACZ,OAAO,CACR,GACG,MAAM,GACN,KAAK,CAAC;AAEV,cAAc;AACd,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAE1E;AAED,cAAc;AACd,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,EACjD,SAAS,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,aAAa,GAC/D,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CA6D5B;AAcD,gBAAgB;AAChB,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;;iBAEtB,IAAI;EAkCtB"}
@@ -1,8 +1,5 @@
1
1
  'use strict';
2
2
 
3
- function identity(x) {
4
- return x;
5
- }
6
3
  /** @public */ function isObservable(x) {
7
4
  return typeof x === 'object' && x !== null && 'subscribe' in x;
8
5
  }
@@ -60,22 +57,13 @@ function identity(x) {
60
57
  };
61
58
  },
62
59
  pipe (...operations) {
63
- return pipeFromArray(operations)(self);
60
+ return operations.reduce(pipeReducer, self);
64
61
  }
65
62
  };
66
63
  return self;
67
64
  }
68
- function pipeFromArray(fns) {
69
- if (fns.length === 0) {
70
- return identity;
71
- }
72
- if (fns.length === 1) {
73
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74
- return fns[0];
75
- }
76
- return function piped(input) {
77
- return fns.reduce((prev, fn)=>fn(prev), input);
78
- };
65
+ function pipeReducer(prev, fn) {
66
+ return fn(prev);
79
67
  }
80
68
  class ObservableAbortError extends Error {
81
69
  constructor(message){
@@ -1,6 +1,3 @@
1
- function identity(x) {
2
- return x;
3
- }
4
1
  /** @public */ function isObservable(x) {
5
2
  return typeof x === 'object' && x !== null && 'subscribe' in x;
6
3
  }
@@ -58,22 +55,13 @@ function identity(x) {
58
55
  };
59
56
  },
60
57
  pipe (...operations) {
61
- return pipeFromArray(operations)(self);
58
+ return operations.reduce(pipeReducer, self);
62
59
  }
63
60
  };
64
61
  return self;
65
62
  }
66
- function pipeFromArray(fns) {
67
- if (fns.length === 0) {
68
- return identity;
69
- }
70
- if (fns.length === 1) {
71
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
72
- return fns[0];
73
- }
74
- return function piped(input) {
75
- return fns.reduce((prev, fn)=>fn(prev), input);
76
- };
63
+ function pipeReducer(prev, fn) {
64
+ return fn(prev);
77
65
  }
78
66
  class ObservableAbortError extends Error {
79
67
  constructor(message){
@@ -1 +1 @@
1
- {"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../../src/observable/operators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,QAAQ,EACR,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EACnD,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,WAAW,GAC3D,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAoB7D;AAED,UAAU,WAAW;CAAG;AACxB,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAClC,KAAK,CAAC,EAAE,WAAW,GAClB,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CA2D1C;AAED,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC1C,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAqB1C"}
1
+ {"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../../src/observable/operators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,QAAQ,EACR,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EACnD,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,WAAW,GAC3D,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAkB7D;AAED,UAAU,WAAW;CAAG;AACxB,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAClC,KAAK,CAAC,EAAE,WAAW,GAClB,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAyD1C;AAED,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC1C,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAmB1C"}
@@ -1,28 +1,28 @@
1
1
  'use strict';
2
2
 
3
+ var observable = require('./observable.js');
4
+
3
5
  function map(project) {
4
- return (originalObserver)=>{
5
- return {
6
- subscribe (observer) {
7
- let index = 0;
8
- const subscription = originalObserver.subscribe({
9
- next (value) {
10
- observer.next?.(project(value, index++));
11
- },
12
- error (error) {
13
- observer.error?.(error);
14
- },
15
- complete () {
16
- observer.complete?.();
17
- }
18
- });
19
- return subscription;
20
- }
21
- };
6
+ return (source)=>{
7
+ return observable.observable((destination)=>{
8
+ let index = 0;
9
+ const subscription = source.subscribe({
10
+ next (value) {
11
+ destination.next(project(value, index++));
12
+ },
13
+ error (error) {
14
+ destination.error(error);
15
+ },
16
+ complete () {
17
+ destination.complete();
18
+ }
19
+ });
20
+ return subscription;
21
+ });
22
22
  };
23
23
  }
24
24
  function share(_opts) {
25
- return (originalObserver)=>{
25
+ return (source)=>{
26
26
  let refCount = 0;
27
27
  let subscription = null;
28
28
  const observers = [];
@@ -30,7 +30,7 @@ function share(_opts) {
30
30
  if (subscription) {
31
31
  return;
32
32
  }
33
- subscription = originalObserver.subscribe({
33
+ subscription = source.subscribe({
34
34
  next (value) {
35
35
  for (const observer of observers){
36
36
  observer.next?.(value);
@@ -56,45 +56,41 @@ function share(_opts) {
56
56
  _sub.unsubscribe();
57
57
  }
58
58
  }
59
- return {
60
- subscribe (observer) {
61
- refCount++;
62
- observers.push(observer);
63
- startIfNeeded();
64
- return {
65
- unsubscribe () {
66
- refCount--;
67
- resetIfNeeded();
68
- const index = observers.findIndex((v)=>v === observer);
69
- if (index > -1) {
70
- observers.splice(index, 1);
71
- }
59
+ return observable.observable((subscriber)=>{
60
+ refCount++;
61
+ observers.push(subscriber);
62
+ startIfNeeded();
63
+ return {
64
+ unsubscribe () {
65
+ refCount--;
66
+ resetIfNeeded();
67
+ const index = observers.findIndex((v)=>v === subscriber);
68
+ if (index > -1) {
69
+ observers.splice(index, 1);
72
70
  }
73
- };
74
- }
75
- };
71
+ }
72
+ };
73
+ });
76
74
  };
77
75
  }
78
76
  function tap(observer) {
79
- return (originalObserver)=>{
80
- return {
81
- subscribe (observer2) {
82
- return originalObserver.subscribe({
83
- next (v) {
84
- observer.next?.(v);
85
- observer2.next?.(v);
86
- },
87
- error (v) {
88
- observer.error?.(v);
89
- observer2.error?.(v);
90
- },
91
- complete () {
92
- observer.complete?.();
93
- observer2.complete?.();
94
- }
95
- });
96
- }
97
- };
77
+ return (source)=>{
78
+ return observable.observable((destination)=>{
79
+ return source.subscribe({
80
+ next (value) {
81
+ observer.next?.(value);
82
+ destination.next(value);
83
+ },
84
+ error (error) {
85
+ observer.error?.(error);
86
+ destination.error(error);
87
+ },
88
+ complete () {
89
+ observer.complete?.();
90
+ destination.complete();
91
+ }
92
+ });
93
+ });
98
94
  };
99
95
  }
100
96
 
@@ -1,26 +1,26 @@
1
+ import { observable } from './observable.mjs';
2
+
1
3
  function map(project) {
2
- return (originalObserver)=>{
3
- return {
4
- subscribe (observer) {
5
- let index = 0;
6
- const subscription = originalObserver.subscribe({
7
- next (value) {
8
- observer.next?.(project(value, index++));
9
- },
10
- error (error) {
11
- observer.error?.(error);
12
- },
13
- complete () {
14
- observer.complete?.();
15
- }
16
- });
17
- return subscription;
18
- }
19
- };
4
+ return (source)=>{
5
+ return observable((destination)=>{
6
+ let index = 0;
7
+ const subscription = source.subscribe({
8
+ next (value) {
9
+ destination.next(project(value, index++));
10
+ },
11
+ error (error) {
12
+ destination.error(error);
13
+ },
14
+ complete () {
15
+ destination.complete();
16
+ }
17
+ });
18
+ return subscription;
19
+ });
20
20
  };
21
21
  }
22
22
  function share(_opts) {
23
- return (originalObserver)=>{
23
+ return (source)=>{
24
24
  let refCount = 0;
25
25
  let subscription = null;
26
26
  const observers = [];
@@ -28,7 +28,7 @@ function share(_opts) {
28
28
  if (subscription) {
29
29
  return;
30
30
  }
31
- subscription = originalObserver.subscribe({
31
+ subscription = source.subscribe({
32
32
  next (value) {
33
33
  for (const observer of observers){
34
34
  observer.next?.(value);
@@ -54,45 +54,41 @@ function share(_opts) {
54
54
  _sub.unsubscribe();
55
55
  }
56
56
  }
57
- return {
58
- subscribe (observer) {
59
- refCount++;
60
- observers.push(observer);
61
- startIfNeeded();
62
- return {
63
- unsubscribe () {
64
- refCount--;
65
- resetIfNeeded();
66
- const index = observers.findIndex((v)=>v === observer);
67
- if (index > -1) {
68
- observers.splice(index, 1);
69
- }
57
+ return observable((subscriber)=>{
58
+ refCount++;
59
+ observers.push(subscriber);
60
+ startIfNeeded();
61
+ return {
62
+ unsubscribe () {
63
+ refCount--;
64
+ resetIfNeeded();
65
+ const index = observers.findIndex((v)=>v === subscriber);
66
+ if (index > -1) {
67
+ observers.splice(index, 1);
70
68
  }
71
- };
72
- }
73
- };
69
+ }
70
+ };
71
+ });
74
72
  };
75
73
  }
76
74
  function tap(observer) {
77
- return (originalObserver)=>{
78
- return {
79
- subscribe (observer2) {
80
- return originalObserver.subscribe({
81
- next (v) {
82
- observer.next?.(v);
83
- observer2.next?.(v);
84
- },
85
- error (v) {
86
- observer.error?.(v);
87
- observer2.error?.(v);
88
- },
89
- complete () {
90
- observer.complete?.();
91
- observer2.complete?.();
92
- }
93
- });
94
- }
95
- };
75
+ return (source)=>{
76
+ return observable((destination)=>{
77
+ return source.subscribe({
78
+ next (value) {
79
+ observer.next?.(value);
80
+ destination.next(value);
81
+ },
82
+ error (error) {
83
+ observer.error?.(error);
84
+ destination.error(error);
85
+ },
86
+ complete () {
87
+ observer.complete?.();
88
+ destination.complete();
89
+ }
90
+ });
91
+ });
96
92
  };
97
93
  }
98
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-next-beta.304+1724978f1",
3
+ "version": "11.0.0-next-beta.305+0a3c261bd",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -157,5 +157,5 @@
157
157
  "funding": [
158
158
  "https://trpc.io/sponsor"
159
159
  ],
160
- "gitHead": "1724978f1aa05be40413cd7ca0859b74d6971b68"
160
+ "gitHead": "0a3c261bd712dd84bf19c6d378a0ea92e1674e1a"
161
161
  }
@@ -6,10 +6,6 @@ import type {
6
6
  UnaryFunction,
7
7
  } from './types';
8
8
 
9
- function identity<TType>(x: TType): TType {
10
- return x;
11
- }
12
-
13
9
  /** @public */
14
10
  export type inferObservableValue<TObservable> = TObservable extends Observable<
15
11
  infer TValue,
@@ -83,30 +79,14 @@ export function observable<TValue, TError = unknown>(
83
79
  pipe(
84
80
  ...operations: OperatorFunction<any, any, any, any>[]
85
81
  ): Observable<any, any> {
86
- return pipeFromArray(operations)(self) as any;
82
+ return operations.reduce(pipeReducer, self);
87
83
  },
88
84
  };
89
85
  return self;
90
86
  }
91
87
 
92
- function pipeFromArray<TSource, TReturn>(
93
- fns: UnaryFunction<TSource, TReturn>[],
94
- ): UnaryFunction<TSource, TReturn> {
95
- if (fns.length === 0) {
96
- return identity as UnaryFunction<any, any>;
97
- }
98
-
99
- if (fns.length === 1) {
100
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
101
- return fns[0]!;
102
- }
103
-
104
- return function piped(input: TSource): TReturn {
105
- return fns.reduce(
106
- (prev: any, fn: UnaryFunction<TSource, TReturn>) => fn(prev),
107
- input as any,
108
- );
109
- };
88
+ function pipeReducer(prev: any, fn: UnaryFunction<any, any>) {
89
+ return fn(prev);
110
90
  }
111
91
 
112
92
  class ObservableAbortError extends Error {
@@ -1,3 +1,4 @@
1
+ import { observable } from './observable';
1
2
  import type {
2
3
  MonoTypeOperatorFunction,
3
4
  Observer,
@@ -8,24 +9,22 @@ import type {
8
9
  export function map<TValueBefore, TError, TValueAfter>(
9
10
  project: (value: TValueBefore, index: number) => TValueAfter,
10
11
  ): 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
- };
12
+ return (source) => {
13
+ return observable((destination) => {
14
+ let index = 0;
15
+ const subscription = source.subscribe({
16
+ next(value) {
17
+ destination.next(project(value, index++));
18
+ },
19
+ error(error) {
20
+ destination.error(error);
21
+ },
22
+ complete() {
23
+ destination.complete();
24
+ },
25
+ });
26
+ return subscription;
27
+ });
29
28
  };
30
29
  }
31
30
 
@@ -33,7 +32,7 @@ interface ShareConfig {}
33
32
  export function share<TValue, TError>(
34
33
  _opts?: ShareConfig,
35
34
  ): MonoTypeOperatorFunction<TValue, TError> {
36
- return (originalObserver) => {
35
+ return (source) => {
37
36
  let refCount = 0;
38
37
 
39
38
  let subscription: Unsubscribable | null = null;
@@ -43,7 +42,7 @@ export function share<TValue, TError>(
43
42
  if (subscription) {
44
43
  return;
45
44
  }
46
- subscription = originalObserver.subscribe({
45
+ subscription = source.subscribe({
47
46
  next(value) {
48
47
  for (const observer of observers) {
49
48
  observer.next?.(value);
@@ -70,50 +69,46 @@ export function share<TValue, TError>(
70
69
  }
71
70
  }
72
71
 
73
- return {
74
- subscribe(observer) {
75
- refCount++;
72
+ return observable((subscriber) => {
73
+ refCount++;
76
74
 
77
- observers.push(observer);
78
- startIfNeeded();
79
- return {
80
- unsubscribe() {
81
- refCount--;
82
- resetIfNeeded();
75
+ observers.push(subscriber);
76
+ startIfNeeded();
77
+ return {
78
+ unsubscribe() {
79
+ refCount--;
80
+ resetIfNeeded();
83
81
 
84
- const index = observers.findIndex((v) => v === observer);
82
+ const index = observers.findIndex((v) => v === subscriber);
85
83
 
86
- if (index > -1) {
87
- observers.splice(index, 1);
88
- }
89
- },
90
- };
91
- },
92
- };
84
+ if (index > -1) {
85
+ observers.splice(index, 1);
86
+ }
87
+ },
88
+ };
89
+ });
93
90
  };
94
91
  }
95
92
 
96
93
  export function tap<TValue, TError>(
97
94
  observer: Partial<Observer<TValue, TError>>,
98
95
  ): 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
- };
96
+ return (source) => {
97
+ return observable((destination) => {
98
+ return source.subscribe({
99
+ next(value) {
100
+ observer.next?.(value);
101
+ destination.next(value);
102
+ },
103
+ error(error) {
104
+ observer.error?.(error);
105
+ destination.error(error);
106
+ },
107
+ complete() {
108
+ observer.complete?.();
109
+ destination.complete();
110
+ },
111
+ });
112
+ });
118
113
  };
119
114
  }