@@ -3,7 +3,7 @@ import { z } from 'zod';
3
3
import * as trpc from '@trpc/server' ;
4
4
import { observable } from '@trpc/server/observable' ;
5
5
import { EventEmitter } from 'events' ;
6
- import { handleIPCOperation } from '../handleIPCOperation ' ;
6
+ import { handleIPCMessage } from '../handleIPCMessage ' ;
7
7
import { IpcMainInvokeEvent } from 'electron' ;
8
8
9
9
interface MockEvent {
@@ -51,11 +51,22 @@ describe('api', () => {
51
51
} ,
52
52
} ) ;
53
53
54
- await handleIPCOperation ( {
54
+ await handleIPCMessage ( {
55
55
createContext : async ( ) => ( { } ) ,
56
- operation : { context : { } , id : 1 , input : { id : 'test-id' } , path : 'testQuery' , type : 'query' } ,
57
- router : testRouter ,
58
56
event,
57
+ internalId : '1-1:1' ,
58
+ message : {
59
+ method : 'request' ,
60
+ operation : {
61
+ context : { } ,
62
+ id : 1 ,
63
+ input : { id : 'test-id' } ,
64
+ path : 'testQuery' ,
65
+ type : 'query' ,
66
+ } ,
67
+ } ,
68
+ router : testRouter ,
69
+ subscriptions : new Map ( ) ,
59
70
} ) ;
60
71
61
72
expect ( event . sender . send ) . toHaveBeenCalledOnce ( ) ;
@@ -79,11 +90,22 @@ describe('api', () => {
79
90
} ,
80
91
} ) ;
81
92
82
- await handleIPCOperation ( {
93
+ await handleIPCMessage ( {
83
94
createContext : async ( ) => ( { } ) ,
84
- operation : { context : { } , id : 1 , input : { id : 'test-id' } , path : 'testQuery' , type : 'query' } ,
85
- router : testRouter ,
86
95
event,
96
+ internalId : '1-1:1' ,
97
+ message : {
98
+ method : 'request' ,
99
+ operation : {
100
+ context : { } ,
101
+ id : 1 ,
102
+ input : { id : 'test-id' } ,
103
+ path : 'testQuery' ,
104
+ type : 'query' ,
105
+ } ,
106
+ } ,
107
+ router : testRouter ,
108
+ subscriptions : new Map ( ) ,
87
109
} ) ;
88
110
89
111
expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
@@ -98,15 +120,20 @@ describe('api', () => {
98
120
} ,
99
121
} ) ;
100
122
101
- await handleIPCOperation ( {
123
+ await handleIPCMessage ( {
102
124
createContext : async ( ) => ( { } ) ,
103
- operation : {
104
- context : { } ,
105
- id : 1 ,
106
- input : undefined ,
107
- path : 'testSubscription' ,
108
- type : 'subscription' ,
125
+ message : {
126
+ method : 'request' ,
127
+ operation : {
128
+ context : { } ,
129
+ id : 1 ,
130
+ input : undefined ,
131
+ path : 'testSubscription' ,
132
+ type : 'subscription' ,
133
+ } ,
109
134
} ,
135
+ internalId : '1-1:1' ,
136
+ subscriptions : new Map ( ) ,
110
137
router : testRouter ,
111
138
event,
112
139
} ) ;
@@ -124,41 +151,6 @@ describe('api', () => {
124
151
} ) ;
125
152
} ) ;
126
153
127
- test ( 'cancels subscriptions when webcontents are closed' , async ( ) => {
128
- let isDestroyed = false ;
129
- let onDestroyed : ( ) => void ;
130
- const event = makeEvent ( {
131
- sender : {
132
- isDestroyed : ( ) => isDestroyed ,
133
- send : vi . fn ( ) ,
134
- on : ( _event : string , cb : ( ) => void ) => {
135
- onDestroyed = cb ;
136
- } ,
137
- } ,
138
- } ) ;
139
-
140
- await handleIPCOperation ( {
141
- createContext : async ( ) => ( { } ) ,
142
- operation : {
143
- context : { } ,
144
- id : 1 ,
145
- input : undefined ,
146
- path : 'testSubscription' ,
147
- type : 'subscription' ,
148
- } ,
149
- router : testRouter ,
150
- event,
151
- } ) ;
152
-
153
- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
154
-
155
- onDestroyed ( ) ;
156
-
157
- ee . emit ( 'test' ) ;
158
-
159
- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
160
- } ) ;
161
-
162
154
test ( 'subscription responds using custom serializer' , async ( ) => {
163
155
const event = makeEvent ( {
164
156
sender : {
@@ -193,15 +185,20 @@ describe('api', () => {
193
185
} ) ,
194
186
} ) ;
195
187
196
- await handleIPCOperation ( {
188
+ await handleIPCMessage ( {
197
189
createContext : async ( ) => ( { } ) ,
198
- operation : {
199
- context : { } ,
200
- id : 1 ,
201
- input : undefined ,
202
- path : 'testSubscription' ,
203
- type : 'subscription' ,
190
+ message : {
191
+ method : 'request' ,
192
+ operation : {
193
+ context : { } ,
194
+ id : 1 ,
195
+ input : undefined ,
196
+ path : 'testSubscription' ,
197
+ type : 'subscription' ,
198
+ } ,
204
199
} ,
200
+ internalId : '1-1:1' ,
201
+ subscriptions : new Map ( ) ,
205
202
router : testRouter ,
206
203
event,
207
204
} ) ;
@@ -219,64 +216,4 @@ describe('api', () => {
219
216
} ,
220
217
} ) ;
221
218
} ) ;
222
-
223
- test ( "doesn't crash when canceling subscriptions when custom deserializer doesn't allow undefined" , async ( ) => {
224
- const t = trpc . initTRPC . create ( {
225
- transformer : {
226
- deserialize : ( input : unknown ) => {
227
- if ( ! input ) throw new Error ( "Can't parse empty input" ) ;
228
- return JSON . parse ( input as string ) ;
229
- } ,
230
- serialize : ( input ) => {
231
- return JSON . stringify ( input ) ;
232
- } ,
233
- } ,
234
- } ) ;
235
-
236
- const testRouter = t . router ( {
237
- testSubscription : t . procedure . subscription ( ( ) => {
238
- return observable ( ( emit ) => {
239
- function testResponse ( ) {
240
- emit . next ( 'test response' ) ;
241
- }
242
-
243
- ee . on ( 'test' , testResponse ) ;
244
- return ( ) => ee . off ( 'test' , testResponse ) ;
245
- } ) ;
246
- } ) ,
247
- } ) ;
248
-
249
- let isDestroyed = false ;
250
- let onDestroyed : ( ) => void ;
251
- const event = makeEvent ( {
252
- sender : {
253
- isDestroyed : ( ) => isDestroyed ,
254
- send : vi . fn ( ) ,
255
- on : ( _event : string , cb : ( ) => void ) => {
256
- onDestroyed = cb ;
257
- } ,
258
- } ,
259
- } ) ;
260
-
261
- await handleIPCOperation ( {
262
- createContext : async ( ) => ( { } ) ,
263
- operation : {
264
- context : { } ,
265
- id : 1 ,
266
- input : undefined ,
267
- path : 'testSubscription' ,
268
- type : 'subscription' ,
269
- } ,
270
- router : testRouter ,
271
- event,
272
- } ) ;
273
-
274
- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
275
-
276
- onDestroyed ( ) ;
277
-
278
- ee . emit ( 'test' ) ;
279
-
280
- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
281
- } ) ;
282
219
} ) ;
0 commit comments