1 | /**
|
2 | * @license
|
3 | * Copyright 2017 Google LLC
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | import { ReferenceConstructor } from '../exp/Reference';
|
18 | import { Operation } from './operation/Operation';
|
19 | import { Node } from './snap/Node';
|
20 | import { Path } from './util/Path';
|
21 | import { Event } from './view/Event';
|
22 | import { EventRegistration, QueryContext } from './view/EventRegistration';
|
23 | import { View } from './view/View';
|
24 | import { WriteTreeRef } from './WriteTree';
|
25 | /**
|
26 | * SyncPoint represents a single location in a SyncTree with 1 or more event registrations, meaning we need to
|
27 | * maintain 1 or more Views at this location to cache server data and raise appropriate events for server changes
|
28 | * and user writes (set, transaction, update).
|
29 | *
|
30 | * It's responsible for:
|
31 | * - Maintaining the set of 1 or more views necessary at this location (a SyncPoint with 0 views should be removed).
|
32 | * - Proxying user / server operations to the views as appropriate (i.e. applyServerOverwrite,
|
33 | * applyUserOverwrite, etc.)
|
34 | */
|
35 | export declare class SyncPoint {
|
36 | /**
|
37 | * The Views being tracked at this location in the tree, stored as a map where the key is a
|
38 | * queryId and the value is the View for that query.
|
39 | *
|
40 | * NOTE: This list will be quite small (usually 1, but perhaps 2 or 3; any more is an odd use case).
|
41 | */
|
42 | readonly views: Map<string, View>;
|
43 | }
|
44 | export declare function syncPointSetReferenceConstructor(val: ReferenceConstructor): void;
|
45 | export declare function syncPointIsEmpty(syncPoint: SyncPoint): boolean;
|
46 | export declare function syncPointApplyOperation(syncPoint: SyncPoint, operation: Operation, writesCache: WriteTreeRef, optCompleteServerCache: Node | null): Event[];
|
47 | /**
|
48 | * Get a view for the specified query.
|
49 | *
|
50 | * @param query - The query to return a view for
|
51 | * @param writesCache
|
52 | * @param serverCache
|
53 | * @param serverCacheComplete
|
54 | * @returns Events to raise.
|
55 | */
|
56 | export declare function syncPointGetView(syncPoint: SyncPoint, query: QueryContext, writesCache: WriteTreeRef, serverCache: Node | null, serverCacheComplete: boolean): View;
|
57 | /**
|
58 | * Add an event callback for the specified query.
|
59 | *
|
60 | * @param query
|
61 | * @param eventRegistration
|
62 | * @param writesCache
|
63 | * @param serverCache - Complete server cache, if we have it.
|
64 | * @param serverCacheComplete
|
65 | * @returns Events to raise.
|
66 | */
|
67 | export declare function syncPointAddEventRegistration(syncPoint: SyncPoint, query: QueryContext, eventRegistration: EventRegistration, writesCache: WriteTreeRef, serverCache: Node | null, serverCacheComplete: boolean): Event[];
|
68 | /**
|
69 | * Remove event callback(s). Return cancelEvents if a cancelError is specified.
|
70 | *
|
71 | * If query is the default query, we'll check all views for the specified eventRegistration.
|
72 | * If eventRegistration is null, we'll remove all callbacks for the specified view(s).
|
73 | *
|
74 | * @param eventRegistration - If null, remove all callbacks.
|
75 | * @param cancelError - If a cancelError is provided, appropriate cancel events will be returned.
|
76 | * @returns removed queries and any cancel events
|
77 | */
|
78 | export declare function syncPointRemoveEventRegistration(syncPoint: SyncPoint, query: QueryContext, eventRegistration: EventRegistration | null, cancelError?: Error): {
|
79 | removed: QueryContext[];
|
80 | events: Event[];
|
81 | };
|
82 | export declare function syncPointGetQueryViews(syncPoint: SyncPoint): View[];
|
83 | /**
|
84 | * @param path - The path to the desired complete snapshot
|
85 | * @returns A complete cache, if it exists
|
86 | */
|
87 | export declare function syncPointGetCompleteServerCache(syncPoint: SyncPoint, path: Path): Node | null;
|
88 | export declare function syncPointViewForQuery(syncPoint: SyncPoint, query: QueryContext): View | null;
|
89 | export declare function syncPointViewExistsForQuery(syncPoint: SyncPoint, query: QueryContext): boolean;
|
90 | export declare function syncPointHasCompleteView(syncPoint: SyncPoint): boolean;
|
91 | export declare function syncPointGetCompleteView(syncPoint: SyncPoint): View | null;
|