Skip to content

Remove Cyclic Dependencies #4160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5599705
Move FieldMask
schmidt-sebastian Dec 3, 2020
b8efc13
Move normalizeTimestamp
schmidt-sebastian Dec 3, 2020
6af13ee
Move TypeOrder
schmidt-sebastian Dec 3, 2020
f315c89
Move query
schmidt-sebastian Dec 3, 2020
bf8f746
Move toDouble, toInteger
schmidt-sebastian Dec 3, 2020
fb16170
Move Serializer
schmidt-sebastian Dec 3, 2020
b682857
Move PersistenceTransaction
schmidt-sebastian Dec 3, 2020
6e32f92
Move ExponentialBackoff
schmidt-sebastian Dec 3, 2020
e2846a9
Move LocalStoreImpl
schmidt-sebastian Dec 3, 2020
8fcc47b
LruGarbageCollector
schmidt-sebastian Dec 3, 2020
3456d83
Move PRIMARY_LEASE_LOST_ERROR_MSG
schmidt-sebastian Dec 3, 2020
0fba935
BundleReader
schmidt-sebastian Dec 3, 2020
3e69755
Move BundleLoader
schmidt-sebastian Dec 3, 2020
a4758a0
IndexedDbBundleCache
schmidt-sebastian Dec 3, 2020
1b1a67d
IndexedDbIndexManager
schmidt-sebastian Dec 3, 2020
11df697
Clean up IndexedDbPersistence
schmidt-sebastian Dec 3, 2020
1159302
Remove unused imports
schmidt-sebastian Dec 3, 2020
e5b9a81
removeMutationBatch/DocumentKey
schmidt-sebastian Dec 3, 2020
b639a29
IndexedDbSchemaConverter
schmidt-sebastian Dec 3, 2020
a503100
IndexedDbBundleCache
schmidt-sebastian Dec 3, 2020
cccabf2
MemoryTargetCache
schmidt-sebastian Dec 3, 2020
0b518f0
Move FieldValue
schmidt-sebastian Dec 3, 2020
cb07140
Move FieldValue implementations
schmidt-sebastian Dec 3, 2020
d9c66ec
Fix Components
schmidt-sebastian Dec 3, 2020
c06dd59
Make Reference unique
schmidt-sebastian Dec 3, 2020
d03efd3
Move ensureClientConfigured/configureClient
schmidt-sebastian Dec 3, 2020
c2f951e
Move SnapshotMetadata
schmidt-sebastian Dec 3, 2020
2c0faa2
Fix lite/.../query.ts
schmidt-sebastian Dec 3, 2020
97b2189
Move UserDataWriter
schmidt-sebastian Dec 3, 2020
ec5ac56
Add onwarn
schmidt-sebastian Dec 3, 2020
fef7824
Cleanup
schmidt-sebastian Dec 3, 2020
7fb2de0
Fix unit tests
schmidt-sebastian Dec 3, 2020
2e666fe
Cleanup imports/exports
schmidt-sebastian Dec 3, 2020
fde4f7f
FieldValue exports
schmidt-sebastian Dec 3, 2020
f324093
Manual cleanup
schmidt-sebastian Dec 4, 2020
a1f8f77
Merge
schmidt-sebastian Dec 4, 2020
e66d39d
Add separate FieldMask
schmidt-sebastian Dec 4, 2020
57ff562
Add TypeOrder comment
schmidt-sebastian Dec 4, 2020
a4001fc
s/numberSerializer/valueSerializer
schmidt-sebastian Dec 4, 2020
618017d
AsyncQueue/AsyncQueueImpl
schmidt-sebastian Dec 5, 2020
a35b1d6
s/_methods/_impl
schmidt-sebastian Dec 5, 2020
a8e3409
getStore
schmidt-sebastian Dec 5, 2020
0294aa3
BATCHID_UNKNOWN
schmidt-sebastian Dec 5, 2020
6482dae
removeMutationBatch
schmidt-sebastian Dec 5, 2020
b15d996
DocumentKey
schmidt-sebastian Dec 5, 2020
045f33f
FirestoreService
schmidt-sebastian Dec 5, 2020
55fb014
Fix bad merge
schmidt-sebastian Dec 5, 2020
d41071c
Feedback
schmidt-sebastian Dec 8, 2020
9f9cfaf
Merge
schmidt-sebastian Dec 8, 2020
25d414c
Fix bundles
schmidt-sebastian Dec 8, 2020
d180871
Undo API Extractor
schmidt-sebastian Dec 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/firestore/lite/src/api/field_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* limitations under the License.
*/

import { FieldValue } from '../../../src/api/field_value';
import {
ArrayRemoveFieldValueImpl,
ArrayUnionFieldValueImpl,
DeleteFieldValueImpl,
FieldValue,
NumericIncrementFieldValueImpl,
ServerTimestampFieldValueImpl
} from '../../../src/api/field_value';
} from '../../../src/api/user_data_reader';

/**
* Returns a sentinel for use with {@link updateDoc} or
Expand Down
152 changes: 1 addition & 151 deletions packages/firestore/src/api/field_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@
*/

import { FieldTransform } from '../model/mutation';
import {
ArrayRemoveTransformOperation,
ArrayUnionTransformOperation,
NumericIncrementTransformOperation,
ServerTimestampTransform
} from '../model/transform_operation';
import { ParseContext, parseData, UserDataSource } from './user_data_reader';
import { debugAssert } from '../util/assert';
import { toNumber } from '../remote/value_serializer';
import { ParseContext } from './parse_context';

/**
* Sentinel values that can be used when writing document fields with `set()`
Expand All @@ -40,145 +32,3 @@ export abstract class FieldValue {

abstract _toFieldTransform(context: ParseContext): FieldTransform | null;
}

export class DeleteFieldValueImpl extends FieldValue {
_toFieldTransform(context: ParseContext): null {
if (context.dataSource === UserDataSource.MergeSet) {
// No transform to add for a delete, but we need to add it to our
// fieldMask so it gets deleted.
context.fieldMask.push(context.path!);
} else if (context.dataSource === UserDataSource.Update) {
debugAssert(
context.path!.length > 0,
`${this._methodName}() at the top level should have already ` +
'been handled.'
);
throw context.createError(
`${this._methodName}() can only appear at the top level ` +
'of your update data'
);
} else {
// We shouldn't encounter delete sentinels for queries or non-merge set() calls.
throw context.createError(
`${this._methodName}() cannot be used with set() unless you pass ` +
'{merge:true}'
);
}
return null;
}

isEqual(other: FieldValue): boolean {
return other instanceof DeleteFieldValueImpl;
}
}

/**
* Creates a child context for parsing SerializableFieldValues.
*
* This is different than calling `ParseContext.contextWith` because it keeps
* the fieldTransforms and fieldMask separate.
*
* The created context has its `dataSource` set to `UserDataSource.Argument`.
* Although these values are used with writes, any elements in these FieldValues
* are not considered writes since they cannot contain any FieldValue sentinels,
* etc.
*
* @param fieldValue - The sentinel FieldValue for which to create a child
* context.
* @param context - The parent context.
* @param arrayElement - Whether or not the FieldValue has an array.
*/
function createSentinelChildContext(
fieldValue: FieldValue,
context: ParseContext,
arrayElement: boolean
): ParseContext {
return new ParseContext(
{
dataSource: UserDataSource.Argument,
targetDoc: context.settings.targetDoc,
methodName: fieldValue._methodName,
arrayElement
},
context.databaseId,
context.serializer,
context.ignoreUndefinedProperties
);
}

export class ServerTimestampFieldValueImpl extends FieldValue {
_toFieldTransform(context: ParseContext): FieldTransform {
return new FieldTransform(context.path!, new ServerTimestampTransform());
}

isEqual(other: FieldValue): boolean {
return other instanceof ServerTimestampFieldValueImpl;
}
}

export class ArrayUnionFieldValueImpl extends FieldValue {
constructor(methodName: string, private readonly _elements: unknown[]) {
super(methodName);
}

_toFieldTransform(context: ParseContext): FieldTransform {
const parseContext = createSentinelChildContext(
this,
context,
/*array=*/ true
);
const parsedElements = this._elements.map(
element => parseData(element, parseContext)!
);
const arrayUnion = new ArrayUnionTransformOperation(parsedElements);
return new FieldTransform(context.path!, arrayUnion);
}

isEqual(other: FieldValue): boolean {
// TODO(mrschmidt): Implement isEquals
return this === other;
}
}

export class ArrayRemoveFieldValueImpl extends FieldValue {
constructor(methodName: string, readonly _elements: unknown[]) {
super(methodName);
}

_toFieldTransform(context: ParseContext): FieldTransform {
const parseContext = createSentinelChildContext(
this,
context,
/*array=*/ true
);
const parsedElements = this._elements.map(
element => parseData(element, parseContext)!
);
const arrayUnion = new ArrayRemoveTransformOperation(parsedElements);
return new FieldTransform(context.path!, arrayUnion);
}

isEqual(other: FieldValue): boolean {
// TODO(mrschmidt): Implement isEquals
return this === other;
}
}

export class NumericIncrementFieldValueImpl extends FieldValue {
constructor(methodName: string, private readonly _operand: number) {
super(methodName);
}

_toFieldTransform(context: ParseContext): FieldTransform {
const numericIncrement = new NumericIncrementTransformOperation(
context.serializer,
toNumber(context.serializer, this._operand)
);
return new FieldTransform(context.path!, numericIncrement);
}

isEqual(other: FieldValue): boolean {
// TODO(mrschmidt): Implement isEquals
return this === other;
}
}
23 changes: 23 additions & 0 deletions packages/firestore/src/api/parse_context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { DatabaseId } from '../core/database_info';

export interface ParseContext {
readonly databaseId: DatabaseId;
readonly ignoreUndefinedProperties: boolean;
}
Loading