@@ -307,48 +307,47 @@ export class Collection<TData extends object = object, TNested extends object =
307307 toJSON ( ) : Collection . Serialized {
308308 return {
309309 name : this . name ,
310- unindexedSortComparator : this . _unindexedSortComparator ,
311- defaultLokiOperatorPackage : this . _defaultLokiOperatorPackage ,
310+ _unindexedSortComparator : this . _unindexedSortComparator ,
311+ _defaultLokiOperatorPackage : this . _defaultLokiOperatorPackage ,
312312 _dynamicViews : this . _dynamicViews ,
313- uniqueNames : Object . keys ( this . _constraints . unique ) ,
314- transforms : this . _transforms as any ,
315- rangedIndexes : this . _rangedIndexes as any ,
313+ _uniqueNames : Object . keys ( this . _constraints . unique ) ,
314+ _transforms : this . _transforms as any ,
315+ _rangedIndexes : this . _rangedIndexes as any ,
316316 _data : this . _data ,
317- idIndex : this . _idIndex ,
318- maxId : this . _maxId ,
317+ _idIndex : this . _idIndex ,
318+ _maxId : this . _maxId ,
319319 _dirty : this . _dirty ,
320320 _nestedProperties : this . _nestedProperties ,
321- transactional : this . _transactional ,
322- asyncListeners : this . _asyncListeners ,
323- disableMeta : this . _disableMeta ,
324- disableChangesApi : this . _disableChangesApi ,
325- disableDeltaChangesApi : this . _disableDeltaChangesApi ,
326- cloneObjects : this . _cloneObjects ,
327- cloneMethod : this . _cloneMethod ,
328- changes : this . _changes ,
321+ _transactional : this . _transactional ,
322+ _asyncListeners : this . _asyncListeners ,
323+ _disableMeta : this . _disableMeta ,
324+ _disableChangesApi : this . _disableChangesApi ,
325+ _disableDeltaChangesApi : this . _disableDeltaChangesApi ,
326+ _cloneObjects : this . _cloneObjects ,
327+ _cloneMethod : this . _cloneMethod ,
328+ _changes : this . _changes ,
329329 _fullTextSearch : this . _fullTextSearch
330330 } ;
331331 }
332332
333- static fromJSONObject ( obj : Collection . Serialized , options ?: Collection . DeserializeOptions ) {
333+ static fromJSONObject ( obj : Collection . Serialized /*| Collection */ , options ?: Collection . DeserializeOptions ) {
334334 // instantiate collection with options needed by constructor
335335 let coll = new Collection < any > ( obj . name , {
336- disableChangesApi : obj . disableChangesApi ,
337- disableDeltaChangesApi : obj . disableDeltaChangesApi ,
338- unindexedSortComparator : obj . unindexedSortComparator ,
339- defaultLokiOperatorPackage : obj . defaultLokiOperatorPackage
336+ disableChangesApi : obj . _disableChangesApi ,
337+ disableDeltaChangesApi : obj . _disableDeltaChangesApi ,
338+ unindexedSortComparator : obj . _unindexedSortComparator ,
339+ defaultLokiOperatorPackage : obj . _defaultLokiOperatorPackage
340340 } ) ;
341341
342- coll . _transactional = obj . transactional ;
343- coll . _asyncListeners = obj . asyncListeners ;
344- coll . _disableMeta = obj . disableMeta ;
345- coll . _disableChangesApi = obj . disableChangesApi ;
346- coll . _cloneObjects = obj . cloneObjects ;
347- coll . _cloneMethod = obj . cloneMethod || "deep" ;
348- coll . _changes = obj . changes ;
342+ coll . _transactional = obj . _transactional ;
343+ coll . _asyncListeners = obj . _asyncListeners ;
344+ coll . _disableMeta = obj . _disableMeta ;
345+ coll . _disableChangesApi = obj . _disableChangesApi ;
346+ coll . _cloneObjects = obj . _cloneObjects ;
347+ coll . _cloneMethod = obj . _cloneMethod || "deep" ;
348+ coll . _changes = obj . _changes ;
349349 coll . _nestedProperties = obj . _nestedProperties as any [ ] ;
350- coll . _rangedIndexes = obj . rangedIndexes || { } ;
351-
350+ coll . _rangedIndexes = obj . _rangedIndexes || { } ;
352351 coll . _dirty = ( options && options . retainDirtyFlags === true ) ? obj . _dirty : false ;
353352
354353 function makeLoader ( coll : Collection . Serialized ) {
@@ -388,16 +387,16 @@ export class Collection<TData extends object = object, TNested extends object =
388387 }
389388 }
390389
391- coll . _maxId = ( obj . maxId === undefined ) ? 0 : obj . maxId ;
392- coll . _idIndex = obj . idIndex ;
393- if ( obj . transforms !== undefined ) {
394- coll . _transforms = obj . transforms ;
390+ coll . _maxId = ( obj . _maxId === undefined ) ? 0 : obj . _maxId ;
391+ coll . _idIndex = obj . _idIndex ;
392+ if ( obj . _transforms !== undefined ) {
393+ coll . _transforms = obj . _transforms ;
395394 }
396395
397396 // inflate rangedindexes
398- for ( let ri in obj . rangedIndexes ) {
397+ for ( let ri in obj . _rangedIndexes ) {
399398 // shortcut reference to serialized meta
400- let sri = obj . rangedIndexes [ ri ] ;
399+ let sri = obj . _rangedIndexes [ ri ] ;
401400 // lookup index factory function in map based on index type name
402401 let rif = RangedIndexFactoryMap [ sri . indexTypeName ] ;
403402 // lookup comparator function in map based on comparator name
@@ -413,9 +412,15 @@ export class Collection<TData extends object = object, TNested extends object =
413412 coll . _ensureId ( ) ;
414413
415414 // regenerate unique indexes
416- if ( obj . uniqueNames !== undefined ) {
417- for ( let j = 0 ; j < obj . uniqueNames . length ; j ++ ) {
418- coll . ensureUniqueIndex ( obj . uniqueNames [ j ] ) ;
415+ let uniqueNames = obj . _uniqueNames ;
416+ // Check if type is collection.
417+ let maybeColl = obj as any as Collection < any > ;
418+ if ( maybeColl . _constraints && maybeColl . _constraints . unique !== undefined ) {
419+ uniqueNames = Object . keys ( maybeColl . _constraints . unique ) ;
420+ }
421+ if ( uniqueNames ) {
422+ for ( let j = 0 ; j < uniqueNames . length ; j ++ ) {
423+ coll . ensureUniqueIndex ( uniqueNames [ j ] ) ;
419424 }
420425 }
421426
@@ -1710,25 +1715,25 @@ export namespace Collection {
17101715
17111716 export interface Serialized {
17121717 name : string ;
1713- unindexedSortComparator : string ;
1714- defaultLokiOperatorPackage : string ;
1718+ _unindexedSortComparator : string ;
1719+ _defaultLokiOperatorPackage : string ;
17151720 _dynamicViews : DynamicView [ ] ;
17161721 _nestedProperties : { name : string , path : string [ ] } [ ] ;
1717- uniqueNames : string [ ] ;
1718- transforms : Dict < Transform [ ] > ;
1719- rangedIndexes : RangedIndexOptions ;
1722+ _uniqueNames : string [ ] ;
1723+ _transforms : Dict < Transform [ ] > ;
1724+ _rangedIndexes : RangedIndexOptions ;
17201725 _data : Doc < any > [ ] ;
1721- idIndex : number [ ] ;
1722- maxId : number ;
1726+ _idIndex : number [ ] ;
1727+ _maxId : number ;
17231728 _dirty : boolean ;
1724- transactional : boolean ;
1725- asyncListeners : boolean ;
1726- disableMeta : boolean ;
1727- disableChangesApi : boolean ;
1728- disableDeltaChangesApi : boolean ;
1729- cloneObjects : boolean ;
1730- cloneMethod : CloneMethod ;
1731- changes : any ;
1729+ _transactional : boolean ;
1730+ _asyncListeners : boolean ;
1731+ _disableMeta : boolean ;
1732+ _disableChangesApi : boolean ;
1733+ _disableDeltaChangesApi : boolean ;
1734+ _cloneObjects : boolean ;
1735+ _cloneMethod : CloneMethod ;
1736+ _changes : any ;
17321737 _fullTextSearch : FullTextSearch ;
17331738 }
17341739
0 commit comments