1818import { ObjectValue } from '../model/object_value' ;
1919import { isOptionalEqual } from '../util/misc' ;
2020
21+ import { Field } from './expressions' ;
2122import { FieldPath } from './field_path' ;
23+ import { Pipeline } from './pipeline' ;
2224import { DocumentData , DocumentReference , refEqual } from './reference' ;
2325import { fieldPathFromArgument } from './snapshot' ;
2426import { Timestamp } from './timestamp' ;
2527import { AbstractUserDataWriter } from './user_data_writer' ;
2628
29+ export class PipelineSnapshot {
30+ private readonly _pipeline : Pipeline ;
31+ private readonly _executionTime : Timestamp | undefined ;
32+ private readonly _results : PipelineResult [ ] ;
33+ constructor (
34+ pipeline : Pipeline ,
35+ results : PipelineResult [ ] ,
36+ executionTime ?: Timestamp
37+ ) {
38+ this . _pipeline = pipeline ;
39+ this . _executionTime = executionTime ;
40+ this . _results = results ;
41+ }
42+
43+ /**
44+ * The Pipeline on which you called `execute()` in order to get this
45+ * `PipelineSnapshot`.
46+ */
47+ get pipeline ( ) : Pipeline {
48+ return this . _pipeline ;
49+ }
50+
51+ /** An array of all the results in the `PipelineSnapshot`. */
52+ get results ( ) : PipelineResult [ ] {
53+ return this . _results ;
54+ }
55+
56+ /**
57+ * The time at which the pipeline producing this result is executed.
58+ *
59+ * @type {Timestamp }
60+ * @readonly
61+ *
62+ */
63+ get executionTime ( ) : Timestamp {
64+ if ( this . _executionTime === undefined ) {
65+ throw new Error (
66+ "'executionTime' is expected to exist, but it is undefined"
67+ ) ;
68+ }
69+ return this . _executionTime ;
70+ }
71+ }
72+
2773/**
2874 * @beta
2975 *
@@ -36,7 +82,6 @@ import { AbstractUserDataWriter } from './user_data_writer';
3682export class PipelineResult < AppModelType = DocumentData > {
3783 private readonly _userDataWriter : AbstractUserDataWriter ;
3884
39- private readonly _executionTime : Timestamp | undefined ;
4085 private readonly _createTime : Timestamp | undefined ;
4186 private readonly _updateTime : Timestamp | undefined ;
4287
@@ -69,13 +114,11 @@ export class PipelineResult<AppModelType = DocumentData> {
69114 userDataWriter : AbstractUserDataWriter ,
70115 ref ?: DocumentReference ,
71116 fields ?: ObjectValue ,
72- executionTime ?: Timestamp ,
73117 createTime ?: Timestamp ,
74118 updateTime ?: Timestamp
75119 ) {
76120 this . _ref = ref ;
77121 this . _userDataWriter = userDataWriter ;
78- this . _executionTime = executionTime ;
79122 this . _createTime = createTime ;
80123 this . _updateTime = updateTime ;
81124 this . _fields = fields ;
@@ -120,22 +163,6 @@ export class PipelineResult<AppModelType = DocumentData> {
120163 return this . _updateTime ;
121164 }
122165
123- /**
124- * The time at which the pipeline producing this result is executed.
125- *
126- * @type {Timestamp }
127- * @readonly
128- *
129- */
130- get executionTime ( ) : Timestamp {
131- if ( this . _executionTime === undefined ) {
132- throw new Error (
133- "'executionTime' is expected to exist, but it is undefined"
134- ) ;
135- }
136- return this . _executionTime ;
137- }
138-
139166 /**
140167 * Retrieves all fields in the result as an object. Returns 'undefined' if
141168 * the document doesn't exist.
@@ -166,7 +193,7 @@ export class PipelineResult<AppModelType = DocumentData> {
166193 /**
167194 * Retrieves the field specified by `field`.
168195 *
169- * @param {string|FieldPath } field The field path
196+ * @param {string|FieldPath|Field } field The field path
170197 * (e.g. 'foo' or 'foo.bar') to a specific field.
171198 * @returns {* } The data at the specified field location or undefined if no
172199 * such field exists.
@@ -184,7 +211,7 @@ export class PipelineResult<AppModelType = DocumentData> {
184211 // We deliberately use `any` in the external API to not impose type-checking
185212 // on end users.
186213 // eslint-disable-next-line @typescript-eslint/no-explicit-any
187- get ( fieldPath : string | FieldPath ) : any {
214+ get ( fieldPath : string | FieldPath | Field ) : any {
188215 if ( this . _fields === undefined ) {
189216 return undefined ;
190217 }
0 commit comments