@@ -108,20 +108,20 @@ export type FormattedIncrementalResult<
108
108
* @internal
109
109
*/
110
110
export class IncrementalPublisher {
111
- initialResult : {
111
+ private _initialResult : {
112
112
children : Set < IncrementalDataRecord > ;
113
113
isCompleted : boolean ;
114
114
} ;
115
115
116
- _released : Set < IncrementalDataRecord > ;
117
- _pending : Set < IncrementalDataRecord > ;
116
+ private _released : Set < IncrementalDataRecord > ;
117
+ private _pending : Set < IncrementalDataRecord > ;
118
118
119
119
// these are assigned within the Promise executor called synchronously within the constructor
120
- _signalled ! : Promise < unknown > ;
121
- _resolve ! : ( ) => void ;
120
+ private _signalled ! : Promise < unknown > ;
121
+ private _resolve ! : ( ) => void ;
122
122
123
123
constructor ( ) {
124
- this . initialResult = {
124
+ this . _initialResult = {
125
125
children : new Set ( ) ,
126
126
isCompleted : false ,
127
127
} ;
@@ -130,47 +130,10 @@ export class IncrementalPublisher {
130
130
this . _reset ( ) ;
131
131
}
132
132
133
- _trigger ( ) {
134
- this . _resolve ( ) ;
135
- this . _reset ( ) ;
136
- }
137
-
138
- _reset ( ) {
139
- // promiseWithResolvers uses void only as a generic type parameter
140
- // see: https://typescript-eslint.io/rules/no-invalid-void-type/
141
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
142
- const { promise : signalled , resolve } = promiseWithResolvers < void > ( ) ;
143
- this . _resolve = resolve ;
144
- this . _signalled = signalled ;
145
- }
146
-
147
133
hasNext ( ) : boolean {
148
134
return this . _pending . size > 0 ;
149
135
}
150
136
151
- _introduce ( item : IncrementalDataRecord ) {
152
- this . _pending . add ( item ) ;
153
- }
154
-
155
- _release ( item : IncrementalDataRecord ) : void {
156
- if ( this . _pending . has ( item ) ) {
157
- this . _released . add ( item ) ;
158
- this . _trigger ( ) ;
159
- }
160
- }
161
-
162
- _push ( item : IncrementalDataRecord ) : void {
163
- this . _released . add ( item ) ;
164
- this . _pending . add ( item ) ;
165
- this . _trigger ( ) ;
166
- }
167
-
168
- _delete ( item : IncrementalDataRecord ) {
169
- this . _released . delete ( item ) ;
170
- this . _pending . delete ( item ) ;
171
- this . _trigger ( ) ;
172
- }
173
-
174
137
subscribe ( ) : AsyncGenerator <
175
138
SubsequentIncrementalExecutionResult ,
176
139
void ,
@@ -247,46 +210,6 @@ export class IncrementalPublisher {
247
210
} ;
248
211
}
249
212
250
- _getIncrementalResult (
251
- completedRecords : ReadonlySet < IncrementalDataRecord > ,
252
- ) : SubsequentIncrementalExecutionResult | undefined {
253
- const incrementalResults : Array < IncrementalResult > = [ ] ;
254
- let encounteredCompletedAsyncIterator = false ;
255
- for ( const incrementalDataRecord of completedRecords ) {
256
- const incrementalResult : IncrementalResult = { } ;
257
- for ( const child of incrementalDataRecord . children ) {
258
- this . _publish ( child ) ;
259
- }
260
- if ( isStreamItemsRecord ( incrementalDataRecord ) ) {
261
- const items = incrementalDataRecord . items ;
262
- if ( incrementalDataRecord . isCompletedAsyncIterator ) {
263
- // async iterable resolver just finished but there may be pending payloads
264
- encounteredCompletedAsyncIterator = true ;
265
- continue ;
266
- }
267
- ( incrementalResult as IncrementalStreamResult ) . items = items ;
268
- } else {
269
- const data = incrementalDataRecord . data ;
270
- ( incrementalResult as IncrementalDeferResult ) . data = data ?? null ;
271
- }
272
-
273
- incrementalResult . path = incrementalDataRecord . path ;
274
- if ( incrementalDataRecord . label != null ) {
275
- incrementalResult . label = incrementalDataRecord . label ;
276
- }
277
- if ( incrementalDataRecord . errors . length > 0 ) {
278
- incrementalResult . errors = incrementalDataRecord . errors ;
279
- }
280
- incrementalResults . push ( incrementalResult ) ;
281
- }
282
-
283
- return incrementalResults . length
284
- ? { incremental : incrementalResults , hasNext : this . hasNext ( ) }
285
- : encounteredCompletedAsyncIterator && ! this . hasNext ( )
286
- ? { hasNext : false }
287
- : undefined ;
288
- }
289
-
290
213
prepareNewDeferredFragmentRecord ( opts : {
291
214
label : string | undefined ;
292
215
path : Path | undefined ;
@@ -298,7 +221,7 @@ export class IncrementalPublisher {
298
221
if ( parentContext ) {
299
222
parentContext . children . add ( deferredFragmentRecord ) ;
300
223
} else {
301
- this . initialResult . children . add ( deferredFragmentRecord ) ;
224
+ this . _initialResult . children . add ( deferredFragmentRecord ) ;
302
225
}
303
226
304
227
return deferredFragmentRecord ;
@@ -316,7 +239,7 @@ export class IncrementalPublisher {
316
239
if ( parentContext ) {
317
240
parentContext . children . add ( streamItemsRecord ) ;
318
241
} else {
319
- this . initialResult . children . add ( streamItemsRecord ) ;
242
+ this . _initialResult . children . add ( streamItemsRecord ) ;
320
243
}
321
244
322
245
return streamItemsRecord ;
@@ -352,19 +275,11 @@ export class IncrementalPublisher {
352
275
}
353
276
354
277
publishInitial ( ) {
355
- for ( const child of this . initialResult . children ) {
278
+ for ( const child of this . _initialResult . children ) {
356
279
this . _publish ( child ) ;
357
280
}
358
281
}
359
282
360
- _publish ( incrementalDataRecord : IncrementalDataRecord ) {
361
- if ( incrementalDataRecord . isCompleted ) {
362
- this . _push ( incrementalDataRecord ) ;
363
- } else {
364
- this . _introduce ( incrementalDataRecord ) ;
365
- }
366
- }
367
-
368
283
filter (
369
284
nullPath : Path ,
370
285
erroringIncrementalDataRecord : IncrementalDataRecord | undefined ,
@@ -375,7 +290,7 @@ export class IncrementalPublisher {
375
290
376
291
const children =
377
292
erroringIncrementalDataRecord === undefined
378
- ? this . initialResult . children
293
+ ? this . _initialResult . children
379
294
: erroringIncrementalDataRecord . children ;
380
295
381
296
for ( const child of this . _getDescendants ( children ) ) {
@@ -386,7 +301,7 @@ export class IncrementalPublisher {
386
301
this . _delete ( child ) ;
387
302
const parent =
388
303
child . parentContext === undefined
389
- ? this . initialResult
304
+ ? this . _initialResult
390
305
: child . parentContext ;
391
306
parent . children . delete ( child ) ;
392
307
@@ -404,7 +319,92 @@ export class IncrementalPublisher {
404
319
} ) ;
405
320
}
406
321
407
- _getDescendants (
322
+ private _trigger ( ) {
323
+ this . _resolve ( ) ;
324
+ this . _reset ( ) ;
325
+ }
326
+
327
+ private _reset ( ) {
328
+ // promiseWithResolvers uses void only as a generic type parameter
329
+ // see: https://typescript-eslint.io/rules/no-invalid-void-type/
330
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
331
+ const { promise : signalled , resolve } = promiseWithResolvers < void > ( ) ;
332
+ this . _resolve = resolve ;
333
+ this . _signalled = signalled ;
334
+ }
335
+
336
+ private _introduce ( item : IncrementalDataRecord ) {
337
+ this . _pending . add ( item ) ;
338
+ }
339
+
340
+ private _release ( item : IncrementalDataRecord ) : void {
341
+ if ( this . _pending . has ( item ) ) {
342
+ this . _released . add ( item ) ;
343
+ this . _trigger ( ) ;
344
+ }
345
+ }
346
+
347
+ private _push ( item : IncrementalDataRecord ) : void {
348
+ this . _released . add ( item ) ;
349
+ this . _pending . add ( item ) ;
350
+ this . _trigger ( ) ;
351
+ }
352
+
353
+ private _delete ( item : IncrementalDataRecord ) {
354
+ this . _released . delete ( item ) ;
355
+ this . _pending . delete ( item ) ;
356
+ this . _trigger ( ) ;
357
+ }
358
+
359
+ private _getIncrementalResult (
360
+ completedRecords : ReadonlySet < IncrementalDataRecord > ,
361
+ ) : SubsequentIncrementalExecutionResult | undefined {
362
+ const incrementalResults : Array < IncrementalResult > = [ ] ;
363
+ let encounteredCompletedAsyncIterator = false ;
364
+ for ( const incrementalDataRecord of completedRecords ) {
365
+ const incrementalResult : IncrementalResult = { } ;
366
+ for ( const child of incrementalDataRecord . children ) {
367
+ this . _publish ( child ) ;
368
+ }
369
+ if ( isStreamItemsRecord ( incrementalDataRecord ) ) {
370
+ const items = incrementalDataRecord . items ;
371
+ if ( incrementalDataRecord . isCompletedAsyncIterator ) {
372
+ // async iterable resolver just finished but there may be pending payloads
373
+ encounteredCompletedAsyncIterator = true ;
374
+ continue ;
375
+ }
376
+ ( incrementalResult as IncrementalStreamResult ) . items = items ;
377
+ } else {
378
+ const data = incrementalDataRecord . data ;
379
+ ( incrementalResult as IncrementalDeferResult ) . data = data ?? null ;
380
+ }
381
+
382
+ incrementalResult . path = incrementalDataRecord . path ;
383
+ if ( incrementalDataRecord . label != null ) {
384
+ incrementalResult . label = incrementalDataRecord . label ;
385
+ }
386
+ if ( incrementalDataRecord . errors . length > 0 ) {
387
+ incrementalResult . errors = incrementalDataRecord . errors ;
388
+ }
389
+ incrementalResults . push ( incrementalResult ) ;
390
+ }
391
+
392
+ return incrementalResults . length
393
+ ? { incremental : incrementalResults , hasNext : this . hasNext ( ) }
394
+ : encounteredCompletedAsyncIterator && ! this . hasNext ( )
395
+ ? { hasNext : false }
396
+ : undefined ;
397
+ }
398
+
399
+ private _publish ( incrementalDataRecord : IncrementalDataRecord ) {
400
+ if ( incrementalDataRecord . isCompleted ) {
401
+ this . _push ( incrementalDataRecord ) ;
402
+ } else {
403
+ this . _introduce ( incrementalDataRecord ) ;
404
+ }
405
+ }
406
+
407
+ private _getDescendants (
408
408
children : ReadonlySet < IncrementalDataRecord > ,
409
409
descendants = new Set < IncrementalDataRecord > ( ) ,
410
410
) : ReadonlySet < IncrementalDataRecord > {
@@ -415,7 +415,7 @@ export class IncrementalPublisher {
415
415
return descendants ;
416
416
}
417
417
418
- _matchesPath (
418
+ private _matchesPath (
419
419
testPath : Array < string | number > ,
420
420
basePath : Array < string | number > ,
421
421
) : boolean {
0 commit comments