16
16
*/
17
17
18
18
import { BatchId , ListenSequenceNumber , TargetId } from '../core/types' ;
19
+ import { IndexKind } from '../model/field_index' ;
19
20
import { ResourcePath } from '../model/path' ;
20
21
import { BundledQuery } from '../protos/firestore_bundle_proto' ;
21
22
import {
@@ -31,6 +32,11 @@ import {
31
32
encodeResourcePath
32
33
} from './encoded_resource_path' ;
33
34
35
+ // TODO(indexing): Remove this constant
36
+ const INDEXING_ENABLED = false ;
37
+
38
+ export const INDEXING_SCHEMA_VERSION = 12 ;
39
+
34
40
/**
35
41
* Schema Version for the Web client:
36
42
* 1. Initial version including Mutation Queue, Query Cache, and Remote
@@ -49,8 +55,9 @@ import {
49
55
* an auto-incrementing ID. This is required for Index-Free queries.
50
56
* 10. Rewrite the canonical IDs to the explicit Protobuf-based format.
51
57
* 11. Add bundles and named_queries for bundle support.
58
+ * 12. Add indexing support.
52
59
*/
53
- export const SCHEMA_VERSION = 11 ;
60
+ export const SCHEMA_VERSION = INDEXING_ENABLED ? INDEXING_SCHEMA_VERSION : 11 ;
54
61
55
62
/**
56
63
* Wrapper class to store timestamps (seconds and nanos) in IndexedDb objects.
@@ -655,9 +662,7 @@ export type DbClientMetadataKey = string;
655
662
656
663
export type DbBundlesKey = string ;
657
664
658
- /**
659
- * A object representing a bundle loaded by the SDK.
660
- */
665
+ /** An object representing a bundle loaded by the SDK. */
661
666
export class DbBundle {
662
667
/** Name of the IndexedDb object store. */
663
668
static store = 'bundles' ;
@@ -676,9 +681,7 @@ export class DbBundle {
676
681
677
682
export type DbNamedQueriesKey = string ;
678
683
679
- /**
680
- * A object representing a named query loaded by the SDK via a bundle.
681
- */
684
+ /** An object representing a named query loaded by the SDK via a bundle. */
682
685
export class DbNamedQuery {
683
686
/** Name of the IndexedDb object store. */
684
687
static store = 'namedQueries' ;
@@ -695,6 +698,101 @@ export class DbNamedQuery {
695
698
) { }
696
699
}
697
700
701
+ /** The key for each index consisting of just the index id. */
702
+ export type DbIndexConfigurationKey = number ;
703
+
704
+ /** An object representing the global configuration for a field index. */
705
+ export class DbIndexConfiguration {
706
+ /** Name of the IndexedDb object store. */
707
+ static store = 'indexConfiguration' ;
708
+
709
+ static keyPath = 'indexId' ;
710
+
711
+ constructor (
712
+ /** The index id for this entry. */
713
+ public indexId : number ,
714
+ /** The collection group this index belongs to. */
715
+ public collectionGroup : string ,
716
+ /** The fields to index for this index. */
717
+ public fields : [ [ name : string , kind : IndexKind ] ]
718
+ ) { }
719
+ }
720
+
721
+ /** The key for each index state consisting of the index id and its user id. */
722
+ export type DbIndexStateKey = [ number , string ] ;
723
+
724
+ /**
725
+ * An object describing how up-to-date the index backfill is for each user and
726
+ * index.
727
+ */
728
+ export class DbIndexState {
729
+ /** Name of the IndexedDb object store. */
730
+ static store = 'indexState' ;
731
+
732
+ static keyPath = [ 'indexId' , 'uid' ] ;
733
+
734
+ constructor (
735
+ /** The index id for this entry. */
736
+ public indexId : number ,
737
+ /** The user id for this entry. */
738
+ public uid : string ,
739
+ /**
740
+ * A number that indicates when the index was last updated (relative to
741
+ * other indexes).
742
+ */
743
+ public sequenceNumber : number ,
744
+ /**
745
+ * The latest read time that has been indexed by Firestore for this field
746
+ * index. Set to `{seconds: 0, nanos: 0}` if no documents have been indexed.
747
+ */
748
+ public readTime : DbTimestamp ,
749
+ /**
750
+ * The last document that has been indexed for this field index. Empty if
751
+ * no documents have been indexed.
752
+ */
753
+ public documentKey : EncodedResourcePath ,
754
+ /**
755
+ * The largest mutation batch id that has been processed for this index. -1
756
+ * if no mutations have been indexed.
757
+ */
758
+ public largestBatchId : number
759
+ ) { }
760
+ }
761
+
762
+ /**
763
+ * The key for each index entry consists of the index id and its user id,
764
+ * the encoded array and directional value for the indexed fields as well as
765
+ * the encoded document path for the indexed document.
766
+ */
767
+ export type DbIndexEntryKey = [ number , string , Uint8Array , Uint8Array , string ] ;
768
+
769
+ /** An object that stores the encoded entries for all documents and fields. */
770
+ export class DbIndexEntries {
771
+ /** Name of the IndexedDb object store. */
772
+ static store = 'indexEntries' ;
773
+
774
+ static keyPath = [
775
+ 'indexId' ,
776
+ 'uid' ,
777
+ 'arrayValue' ,
778
+ 'directionalValue' ,
779
+ 'documentKey'
780
+ ] ;
781
+
782
+ constructor (
783
+ /** The index id for this entry. */
784
+ public indexId : number ,
785
+ /** The user id for this entry. */
786
+ public uid : string ,
787
+ /** The encoded array index value for this entry. */
788
+ public arrayValue : Uint8Array ,
789
+ /** The encoded directional value for equality and inequality filters. */
790
+ public directionalValue : Uint8Array ,
791
+ /** The document key this entry points to. */
792
+ public documentKey : EncodedResourcePath
793
+ ) { }
794
+ }
795
+
698
796
// Visible for testing
699
797
export const V1_STORES = [
700
798
DbMutationQueue . store ,
@@ -712,7 +810,6 @@ export const V1_STORES = [
712
810
// Visible for testing
713
811
export const V3_STORES = V1_STORES ;
714
812
715
- // Visible for testing
716
813
// Note: DbRemoteDocumentChanges is no longer used and dropped with v9.
717
814
export const V4_STORES = [ ...V3_STORES , DbClientMetadata . store ] ;
718
815
@@ -730,6 +827,13 @@ export const V8_STORES = [...V6_STORES, DbCollectionParent.store];
730
827
731
828
export const V11_STORES = [ ...V8_STORES , DbBundle . store , DbNamedQuery . store ] ;
732
829
830
+ export const V12_STORES = [
831
+ ...V11_STORES ,
832
+ DbIndexConfiguration . store ,
833
+ DbIndexState . store ,
834
+ DbIndexEntries . store
835
+ ] ;
836
+
733
837
/**
734
838
* The list of all default IndexedDB stores used throughout the SDK. This is
735
839
* used when creating transactions so that access across all stores is done
0 commit comments