1
- import { Orbit } from '@orbit/core' ;
1
+ import { Assertion , Orbit } from '@orbit/core' ;
2
2
import {
3
3
buildQuery ,
4
4
buildTransform ,
@@ -60,12 +60,8 @@ import {
60
60
RecordCacheSettings ,
61
61
RecordCacheTransformOptions
62
62
} from './record-cache' ;
63
- import {
64
- RecordTransformBuffer ,
65
- RecordTransformBufferClass
66
- } from './record-transform-buffer' ;
63
+ import { RecordTransformBuffer } from './record-transform-buffer' ;
67
64
import { PatchResult , RecordCacheUpdateDetails } from './response' ;
68
- import { SyncRecordCacheSettings } from './sync-record-cache' ;
69
65
70
66
const { assert, deprecate } = Orbit ;
71
67
@@ -80,8 +76,7 @@ export interface AsyncRecordCacheSettings<
80
76
transformOperators ?: Dict < AsyncTransformOperator > ;
81
77
inverseTransformOperators ?: Dict < AsyncInverseTransformOperator > ;
82
78
debounceLiveQueries ?: boolean ;
83
- transformBufferClass ?: RecordTransformBufferClass ;
84
- transformBufferSettings ?: SyncRecordCacheSettings < QO , TO > ;
79
+ transformBuffer ?: RecordTransformBuffer ;
85
80
}
86
81
87
82
export abstract class AsyncRecordCache <
@@ -103,8 +98,6 @@ export abstract class AsyncRecordCache<
103
98
protected _inverseTransformOperators : Dict < AsyncInverseTransformOperator > ;
104
99
protected _debounceLiveQueries : boolean ;
105
100
protected _transformBuffer ?: RecordTransformBuffer ;
106
- protected _transformBufferClass ?: RecordTransformBufferClass ;
107
- protected _transformBufferSettings ?: SyncRecordCacheSettings < QO , TO > ;
108
101
109
102
constructor ( settings : AsyncRecordCacheSettings < QO , TO , QB , TB > ) {
110
103
super ( settings ) ;
@@ -115,6 +108,7 @@ export abstract class AsyncRecordCache<
115
108
this . _inverseTransformOperators =
116
109
settings . inverseTransformOperators ?? AsyncInverseTransformOperators ;
117
110
this . _debounceLiveQueries = settings . debounceLiveQueries !== false ;
111
+ this . _transformBuffer = settings . transformBuffer ;
118
112
119
113
const processors : AsyncOperationProcessorClass [ ] = settings . processors
120
114
? settings . processors
@@ -494,14 +488,9 @@ export abstract class AsyncRecordCache<
494
488
495
489
protected _getTransformBuffer ( ) : RecordTransformBuffer {
496
490
if ( this . _transformBuffer === undefined ) {
497
- let transformBufferClass =
498
- this . _transformBufferClass ?? RecordTransformBuffer ;
499
- let settings = this . _transformBufferSettings ?? { schema : this . schema } ;
500
- settings . schema = settings . schema ?? this . schema ;
501
- settings . keyMap = settings . keyMap ?? this . keyMap ;
502
- this . _transformBuffer = new transformBufferClass ( settings ) ;
503
- } else {
504
- this . _transformBuffer . reset ( ) ;
491
+ throw new Assertion (
492
+ 'transformBuffer must be provided to cache via constructor settings'
493
+ ) ;
505
494
}
506
495
return this . _transformBuffer ;
507
496
}
@@ -520,6 +509,7 @@ export abstract class AsyncRecordCache<
520
509
const relatedRecords = inverseRelationships . map ( ( ir ) => ir . record ) ;
521
510
Array . prototype . push . apply ( records , relatedRecords ) ;
522
511
512
+ buffer . resetState ( ) ;
523
513
buffer . setRecordsSync ( await this . getRecordsAsync ( records ) ) ;
524
514
buffer . addInverseRelationshipsSync ( inverseRelationships ) ;
525
515
0 commit comments