@@ -2,6 +2,26 @@ import { interfaces, LDLogger } from '@launchdarkly/node-server-sdk';
22
33import MongoDBClientState from './MongoDBClientState' ;
44
5+ /**
6+ * @internal
7+ */
8+ interface FeatureDocument {
9+ _id : string ;
10+ namespace : string ;
11+ version : number ;
12+ item ?: string ;
13+ deleted ?: boolean ;
14+ }
15+
16+ /**
17+ * @internal
18+ */
19+ interface InitializedDocument {
20+ _id : string ;
21+ initialized : boolean ;
22+ timestamp : Date ;
23+ }
24+
525/**
626 * @internal
727 */
@@ -66,7 +86,7 @@ export default class MongoDBCore implements interfaces.PersistentDataStore {
6686
6787 for ( const collection of allData ) {
6888 const { namespace } = collection . key ;
69- const mongoCollection = await this . _state . getCollection ( namespace ) ;
89+ const mongoCollection = await this . _state . getCollection < FeatureDocument > ( namespace ) ;
7090 const existingDocs = await mongoCollection . find ( { } , { projection : { _id : 1 } } ) . toArray ( ) ;
7191
7292 for ( const doc of existingDocs ) {
@@ -80,7 +100,7 @@ export default class MongoDBCore implements interfaces.PersistentDataStore {
80100 for ( const collection of allData ) {
81101 const { namespace } = collection . key ;
82102 const items = collection . item ;
83- const mongoCollection = await this . _state . getCollection ( namespace ) ;
103+ const mongoCollection = await this . _state . getCollection < FeatureDocument > ( namespace ) ;
84104
85105 // Prepare bulk operations for this namespace
86106 const bulkOps : any [ ] = [ ] ;
@@ -89,11 +109,11 @@ export default class MongoDBCore implements interfaces.PersistentDataStore {
89109 const itemKey = `${ namespace } :${ keyedItem . key } ` ;
90110 itemsToKeep . add ( itemKey ) ;
91111
92- const doc : any = {
93- _id : keyedItem . key ,
94- namespace,
95- version : keyedItem . item . version ,
96- } ;
112+ const doc : FeatureDocument = {
113+ _id : keyedItem . key ,
114+ namespace,
115+ version : keyedItem . item . version ,
116+ } ;
97117
98118 if ( keyedItem . item . deleted ) {
99119 doc . deleted = true ;
@@ -119,7 +139,7 @@ export default class MongoDBCore implements interfaces.PersistentDataStore {
119139 // Delete items that are no longer present in the new data
120140 for ( const collection of allData ) {
121141 const { namespace } = collection . key ;
122- const mongoCollection = await this . _state . getCollection ( namespace ) ;
142+ const mongoCollection = await this . _state . getCollection < FeatureDocument > ( namespace ) ;
123143
124144 const itemsToDelete : string [ ] = [ ] ;
125145 for ( const existingItem of existingItems ) {
@@ -134,10 +154,10 @@ export default class MongoDBCore implements interfaces.PersistentDataStore {
134154 }
135155
136156 // Set the initialized flag
137- const initCollection = await this . _state . getCollection ( COLLECTION_INITIALIZED ) ;
157+ const initCollection = await this . _state . getCollection < InitializedDocument > ( COLLECTION_INITIALIZED ) ;
138158 await initCollection . replaceOne (
139159 { _id : this . _initedKey } ,
140- { _id : this . _initedKey , initialized : true , timestamp : new Date ( ) } ,
160+ { initialized : true , timestamp : new Date ( ) } as any ,
141161 { upsert : true }
142162 ) ;
143163
@@ -154,7 +174,7 @@ export default class MongoDBCore implements interfaces.PersistentDataStore {
154174 callback : ( descriptor : interfaces . SerializedItemDescriptor | undefined ) => void ,
155175 ) : Promise < void > {
156176 try {
157- const collection = await this . _state . getCollection ( kind . namespace ) ;
177+ const collection = await this . _state . getCollection < FeatureDocument > ( kind . namespace ) ;
158178 const doc = await collection . findOne ( { _id : key } ) ;
159179
160180 if ( doc ) {
@@ -180,7 +200,7 @@ export default class MongoDBCore implements interfaces.PersistentDataStore {
180200 ) => void ,
181201 ) : Promise < void > {
182202 try {
183- const collection = await this . _state . getCollection ( kind . namespace ) ;
203+ const collection = await this . _state . getCollection < FeatureDocument > ( kind . namespace ) ;
184204 const docs = await collection . find ( { deleted : { $ne : true } } ) . toArray ( ) ;
185205
186206 const results : interfaces . KeyedItem < string , interfaces . SerializedItemDescriptor > [ ] = [ ] ;
@@ -213,9 +233,9 @@ export default class MongoDBCore implements interfaces.PersistentDataStore {
213233 ) => void ,
214234 ) : Promise < void > {
215235 try {
216- const collection = await this . _state . getCollection ( kind . namespace ) ;
236+ const collection = await this . _state . getCollection < FeatureDocument > ( kind . namespace ) ;
217237
218- const doc : any = {
238+ const doc : FeatureDocument = {
219239 _id : key ,
220240 namespace : kind . namespace ,
221241 version : descriptor . version ,
@@ -256,7 +276,7 @@ export default class MongoDBCore implements interfaces.PersistentDataStore {
256276
257277 async initialized ( callback : ( isInitialized : boolean ) => void ) : Promise < void > {
258278 try {
259- const collection = await this . _state . getCollection ( COLLECTION_INITIALIZED ) ;
279+ const collection = await this . _state . getCollection < InitializedDocument > ( COLLECTION_INITIALIZED ) ;
260280 const doc = await collection . findOne ( { _id : this . _initedKey } ) ;
261281 callback ( ! ! doc ?. initialized ) ;
262282 } catch ( error ) {
0 commit comments