-
Notifications
You must be signed in to change notification settings - Fork 1k
DML prototype #9490
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
base: main
Are you sure you want to change the base?
DML prototype #9490
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,11 +38,13 @@ | |
| Expression, | ||
| Field, | ||
| field, | ||
| Ordering | ||
| Ordering, | ||
| Selectable | ||
|
Check failure on line 42 in packages/firestore/src/lite-api/stage.ts
|
||
| } from './expressions'; | ||
| import { Pipeline } from './pipeline'; | ||
| import { StageOptions } from './stage_options'; | ||
| import { isUserData, UserData } from './user_data_reader'; | ||
| import { selectablesToMap } from '../util/pipeline_util'; | ||
|
Check failure on line 47 in packages/firestore/src/lite-api/stage.ts
|
||
|
|
||
| /** | ||
| * @beta | ||
|
|
@@ -762,3 +764,127 @@ | |
| } | ||
| return expressionMap; | ||
| } | ||
|
|
||
| /** | ||
| * @beta | ||
| */ | ||
| export class Delete extends Stage { | ||
| get _name(): string { | ||
| return 'delete'; | ||
| } | ||
|
|
||
| get _optionsUtil(): OptionsUtil { | ||
| return new OptionsUtil({ | ||
| transactional: { serverName: 'transactional' }, | ||
| returns: { serverName: 'returns' } | ||
| }); | ||
| } | ||
|
|
||
| constructor(options: StageOptions) { | ||
| super(options); | ||
| } | ||
|
|
||
| /** | ||
| * @internal | ||
| * @private | ||
| */ | ||
| _toProto(serializer: JsonProtoSerializer): ProtoStage { | ||
| return { | ||
| ...super._toProto(serializer), | ||
| args: [] | ||
| }; | ||
| } | ||
|
|
||
| _readUserData(context: ParseContext): void { | ||
| super._readUserData(context); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @beta | ||
| */ | ||
| export class Upsert extends Stage { | ||
| get _name(): string { | ||
| return 'upsert'; | ||
| } | ||
|
|
||
| get _optionsUtil(): OptionsUtil { | ||
| return new OptionsUtil({ | ||
| transactional: { serverName: 'transactional' }, | ||
| returns: { serverName: 'returns' }, | ||
| conflictResolution: { serverName: 'conflict_resolution' } | ||
| }); | ||
| } | ||
|
|
||
| constructor(options: StageOptions) { | ||
| super(options); | ||
|
|
||
| if ('collection' in this.knownOptions && typeof this.knownOptions.collection === 'string') { | ||
| const collection = this.knownOptions.collection; | ||
| this.knownOptions.collection = collection.startsWith('/') ? collection : '/' + collection; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @internal | ||
| * @private | ||
| */ | ||
| _toProto(serializer: JsonProtoSerializer): ProtoStage { | ||
| let args: any[] = []; | ||
|
Check failure on line 833 in packages/firestore/src/lite-api/stage.ts
|
||
| if (this.knownOptions.collection) { | ||
| args.push({ referenceValue: this.knownOptions.collection }); | ||
| } | ||
| return { | ||
| ...super._toProto(serializer), | ||
| args | ||
| }; | ||
| } | ||
|
|
||
| _readUserData(context: ParseContext): void { | ||
| super._readUserData(context); | ||
| } | ||
| } | ||
|
Comment on lines
+806
to
+846
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| /** | ||
| * @beta | ||
| */ | ||
| export class Insert extends Stage { | ||
| get _name(): string { | ||
| return 'insert'; | ||
| } | ||
|
|
||
| get _optionsUtil(): OptionsUtil { | ||
| return new OptionsUtil({ | ||
| transactional: { serverName: 'transactional' }, | ||
| returns: { serverName: 'returns' } | ||
| }); | ||
| } | ||
|
|
||
| constructor(options: StageOptions) { | ||
| super(options); | ||
|
|
||
| if ('collection' in this.knownOptions && typeof this.knownOptions.collection === 'string') { | ||
| const collection = this.knownOptions.collection; | ||
| this.knownOptions.collection = collection.startsWith('/') ? collection : '/' + collection; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @internal | ||
| * @private | ||
| */ | ||
| _toProto(serializer: JsonProtoSerializer): ProtoStage { | ||
| let args: any[] = []; | ||
| if (this.knownOptions.collection) { | ||
| args.push({ referenceValue: this.knownOptions.collection }); | ||
| } | ||
| return { | ||
| ...super._toProto(serializer), | ||
| args | ||
| }; | ||
| } | ||
|
|
||
| _readUserData(context: ParseContext): void { | ||
| super._readUserData(context); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type check for
CollectionReferenceis a bit brittle and is duplicated in theinsertmethod below. It can be simplified and made more robust by using theisCollectionReferencetype guard, which is exported from./reference.For example, if
collectionOrOptionsisnull,typeof collectionOrOptionsis'object', which would cause aTypeErroron the'type' in collectionOrOptionscheck.You'll need to import
isCollectionReferencefrom./referenceto use it.