1010// the file licenses/APL2.txt.
1111//
1212
13- import { HTTPError } from "./httpError " ;
13+ import { HTTPError , normalizeCollectionID } from "./utils " ;
1414import { KeyPath , KeyPathCache } from "./keyPath" ;
1515import type * as tdk from "./tdkSchema" ;
1616import type * as cbl from "@couchbase/lite-js" ;
@@ -22,7 +22,7 @@ export class Snapshot {
2222
2323 /** Adds a (possibly nonexistent) document to the snapshot. */
2424 async record ( collection : string , id : cbl . DocID ) {
25- const doc = await this . db . getCollection ( collection ) . getDocument ( id ) ;
25+ const doc = await this . # getCollection( collection ) . getDocument ( id ) ;
2626 this . #documents. set ( collection , id , doc ?? null ) ;
2727 }
2828
@@ -42,14 +42,14 @@ export class Snapshot {
4242 let expected : cbl . CBLDocument | undefined ;
4343 // Update the old document with the changes listed in the DatabaseUpdateItem:
4444 if ( oldDoc ) {
45- expected = update ? this . applyUpdate ( oldDoc , update ) : oldDoc ;
45+ expected = update ? this . # applyUpdate( oldDoc , update ) : oldDoc ;
4646 } else {
47- oldDoc = this . db . getCollection ( collection ) . createDocument ( id ) ;
48- expected = this . applyUpdate ( oldDoc , update ! ! ) ;
47+ oldDoc = this . # getCollection( collection ) . createDocument ( id ) ;
48+ expected = this . # applyUpdate( oldDoc , update ! ! ) ;
4949 }
5050 // Compare the updated oldDoc against the database's current document:
51- const newDoc = await this . db . getCollection ( collection ) . getDocument ( id ) ;
52- const result = this . compareDocs ( expected , newDoc , update ?. type ) ;
51+ const newDoc = await this . # getCollection( collection ) . getDocument ( id ) ;
52+ const result = this . # compareDocs( expected , newDoc , update ?. type ) ;
5353 if ( result !== undefined ) {
5454 // On failure, return the result:
5555 result . result = false ;
@@ -63,9 +63,8 @@ export class Snapshot {
6363 }
6464
6565
66- /** Applies the changes described in a `DatabaseUpdateItem` to a `CBLDocument`.
67- * @internal (exposed for testing) */
68- applyUpdate ( doc : cbl . CBLDocument , update : tdk . DatabaseUpdateItem )
66+ /** Applies the changes described in a `DatabaseUpdateItem` to a `CBLDocument`. */
67+ #applyUpdate( doc : cbl . CBLDocument , update : tdk . DatabaseUpdateItem )
6968 : cbl . CBLDocument | undefined
7069 {
7170 if ( update . type !== 'UPDATE' )
@@ -96,11 +95,10 @@ export class Snapshot {
9695
9796
9897 /** Compares the expected and actual bodies of a document.
99- * @returns `undefined` if they're equal, or a response describing the mismatch.
100- * @internal (exposed for testing) */
101- compareDocs ( expected : cbl . CBLDocument | undefined ,
102- actual : cbl . CBLDocument | undefined ,
103- updateType : string | undefined ) : tdk . VerifyDocumentsResponse | undefined {
98+ * @returns `undefined` if they're equal, or a response describing the mismatch. */
99+ #compareDocs( expected : cbl . CBLDocument | undefined ,
100+ actual : cbl . CBLDocument | undefined ,
101+ updateType : string | undefined ) : tdk . VerifyDocumentsResponse | undefined {
104102 let response : tdk . VerifyDocumentsResponse | undefined = undefined ;
105103 let path = new Array < string | number > ( ) ;
106104
@@ -185,6 +183,11 @@ export class Snapshot {
185183 }
186184
187185
186+ #getCollection( name : string ) : cbl . Collection {
187+ return this . db . getCollection ( normalizeCollectionID ( name ) ) ;
188+ }
189+
190+
188191 readonly #documents = new DocumentMap < cbl . CBLDocument | null > ( ) ;
189192}
190193
0 commit comments