Skip to content

Commit 90a5e3c

Browse files
committed
experimentation with augmentation for ppl
1 parent fd20eff commit 90a5e3c

File tree

10 files changed

+155
-72
lines changed

10 files changed

+155
-72
lines changed

common/api-review/firestore-lite.api.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,10 +1029,6 @@ export interface FindNearestOptions {
10291029
// @public
10301030
export class Firestore {
10311031
get app(): FirebaseApp;
1032-
// Warning: (ae-incompatible-release-tags) The symbol "pipeline" is marked as @public, but its signature references "PipelineSource" which is marked as @beta
1033-
//
1034-
// (undocumented)
1035-
pipeline(): PipelineSource;
10361032
toJSON(): object;
10371033
type: 'firestore-lite' | 'firestore';
10381034
}
@@ -2111,6 +2107,9 @@ export function updateDoc<AppModelType, DbModelType extends DocumentData>(refere
21112107
// @public
21122108
export function updateDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void>;
21132109

2110+
// @public (undocumented)
2111+
export function useFirestorePipelines(): void;
2112+
21142113
// @public
21152114
export function vector(values?: number[]): VectorValue;
21162115

@@ -2176,8 +2175,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;
21762175

21772176
// Warnings were encountered during analysis:
21782177
//
2179-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9258:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
2180-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9259:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
2181-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9288:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
2178+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9257:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
2179+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9258:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
2180+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9287:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
21822181

21832182
```

common/api-review/firestore.api.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,10 +1073,6 @@ export interface FindNearestOptions {
10731073
// @public
10741074
export class Firestore {
10751075
get app(): FirebaseApp;
1076-
// Warning: (ae-incompatible-release-tags) The symbol "pipeline" is marked as @public, but its signature references "PipelineSource" which is marked as @beta
1077-
//
1078-
// (undocumented)
1079-
pipeline: () => PipelineSource;
10801076
toJSON(): object;
10811077
type: 'firestore-lite' | 'firestore';
10821078
}
@@ -2396,6 +2392,9 @@ export function updateDoc<AppModelType, DbModelType extends DocumentData>(refere
23962392
// @public
23972393
export function updateDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void>;
23982394

2395+
// @public (undocumented)
2396+
export function useFirestorePipelines(): void;
2397+
23992398
// @public
24002399
export function vector(values?: number[]): VectorValue;
24012400

@@ -2464,8 +2463,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;
24642463

24652464
// Warnings were encountered during analysis:
24662465
//
2467-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10108:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
2468-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10109:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
2469-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10138:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
2466+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10107:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
2467+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10108:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
2468+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10137:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
24702469

24712470
```

packages/firestore/lite/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export { PipelineResult } from '../src/lite-api/pipeline-result';
3333

3434
export { Pipeline } from '../src/lite-api/pipeline';
3535

36+
export { useFirestorePipelines } from '../src/lite-api/database-augmentation';
37+
3638
export {
3739
Stage,
3840
FindNearestOptions,

packages/firestore/src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export { PipelineResult } from './lite-api/pipeline-result';
2121

2222
export { Pipeline } from './lite-api/pipeline';
2323

24+
export { useFirestorePipelines } from './api/database-augmentation';
25+
2426
export {
2527
Stage,
2628
FindNearestOptions,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Pipeline } from '../lite-api/pipeline';
2+
import { PipelineSource } from '../lite-api/pipeline-source';
3+
import { newUserDataReader } from '../lite-api/user_data_reader';
4+
import { DocumentKey } from '../model/document_key';
5+
6+
import { Firestore } from './database';
7+
import { DocumentReference, Query } from './reference';
8+
import { ExpUserDataWriter } from './user_data_writer';
9+
10+
declare module './database' {
11+
interface Firestore {
12+
pipeline(): PipelineSource;
13+
}
14+
}
15+
16+
declare module './reference' {
17+
interface Query {
18+
pipeline(): Pipeline;
19+
}
20+
}
21+
22+
export function useFirestorePipelines(): void {
23+
Firestore.prototype.pipeline = function (): PipelineSource {
24+
const firestore = this;
25+
return new PipelineSource(
26+
this,
27+
newUserDataReader(firestore),
28+
new ExpUserDataWriter(firestore),
29+
(key: DocumentKey) => {
30+
return new DocumentReference(firestore, null, key);
31+
}
32+
);
33+
};
34+
35+
Query.prototype.pipeline = function (): Pipeline {
36+
let pipeline;
37+
if (this._query.collectionGroup) {
38+
pipeline = this.firestore
39+
.pipeline()
40+
.collectionGroup(this._query.collectionGroup);
41+
} else {
42+
pipeline = this.firestore
43+
.pipeline()
44+
.collection(this._query.path.canonicalString());
45+
}
46+
47+
// TODO(pipeline) convert existing query filters, limits, etc into
48+
// pipeline stages
49+
50+
return pipeline;
51+
};
52+
}

packages/firestore/src/api/database.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ import {
4646
connectFirestoreEmulator,
4747
Firestore as LiteFirestore
4848
} from '../lite-api/database';
49-
import { PipelineSource } from '../lite-api/pipeline-source';
50-
import { DocumentReference, Query } from '../lite-api/reference';
51-
import { newUserDataReader } from '../lite-api/user_data_reader';
49+
import { Query } from '../lite-api/reference';
5250
import {
5351
indexedDbClearPersistence,
5452
indexedDbStoragePrefix
5553
} from '../local/indexeddb_persistence';
5654
import { LRU_COLLECTION_DISABLED } from '../local/lru_garbage_collector';
5755
import { LRU_MINIMUM_CACHE_SIZE_BYTES } from '../local/lru_garbage_collector_impl';
58-
import { DocumentKey } from '../model/document_key';
5956
import { debugAssert } from '../util/assert';
6057
import { AsyncQueue } from '../util/async_queue';
6158
import { AsyncQueueImpl } from '../util/async_queue_impl';
@@ -67,7 +64,6 @@ import { Deferred } from '../util/promise';
6764
import { LoadBundleTask } from './bundle';
6865
import { CredentialsProvider } from './credentials';
6966
import { FirestoreSettings, PersistenceSettings } from './settings';
70-
import { ExpUserDataWriter } from './user_data_writer';
7167

7268
export {
7369
connectFirestoreEmulator,
@@ -108,18 +104,6 @@ export class Firestore extends LiteFirestore {
108104
_online: OnlineComponentProviderFactory;
109105
};
110106

111-
pipeline = (): PipelineSource => {
112-
const firestore = this;
113-
return new PipelineSource(
114-
this,
115-
newUserDataReader(firestore),
116-
new ExpUserDataWriter(firestore),
117-
(key: DocumentKey) => {
118-
return new DocumentReference(firestore, null, key);
119-
}
120-
);
121-
};
122-
123107
/** @hideconstructor */
124108
constructor(
125109
authCredentialsProvider: CredentialsProvider<User>,
@@ -146,6 +130,16 @@ export class Firestore extends LiteFirestore {
146130
}
147131
}
148132

133+
// Undocumented method of Firestore. This is only
134+
// in place to give developers a runtime error suggesting
135+
// how to correctly initialize Firestore for use with Pipelines.
136+
// @ts-ignore
137+
Firestore.prototype.pipeline = function (): unknown {
138+
throw new Error(
139+
'Pipelines not initialized. Your application must call `useFirestorePipelines()` before using Firestore Pipeline features.'
140+
);
141+
};
142+
149143
/**
150144
* Initializes a new instance of {@link Firestore} with the provided settings.
151145
* Can only be called before any other function, including
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { DocumentKey } from '../model/document_key';
2+
3+
import { Firestore } from './database';
4+
import { Pipeline } from './pipeline';
5+
import { PipelineSource } from './pipeline-source';
6+
import { DocumentReference, Query } from './reference';
7+
import { LiteUserDataWriter } from './reference_impl';
8+
import { newUserDataReader } from './user_data_reader';
9+
10+
declare module './database' {
11+
interface Firestore {
12+
pipeline(): PipelineSource;
13+
}
14+
}
15+
16+
declare module './reference' {
17+
interface Query {
18+
pipeline(): Pipeline;
19+
}
20+
}
21+
22+
export function useFirestorePipelines(): void {
23+
Firestore.prototype.pipeline = function (): PipelineSource {
24+
const userDataWriter = new LiteUserDataWriter(this);
25+
const userDataReader = newUserDataReader(this);
26+
return new PipelineSource(
27+
this,
28+
userDataReader,
29+
userDataWriter,
30+
(key: DocumentKey) => {
31+
return new DocumentReference(this, null, key);
32+
}
33+
);
34+
};
35+
36+
Query.prototype.pipeline = function (): Pipeline {
37+
let pipeline;
38+
if (this._query.collectionGroup) {
39+
pipeline = this.firestore
40+
.pipeline()
41+
.collectionGroup(this._query.collectionGroup);
42+
} else {
43+
pipeline = this.firestore
44+
.pipeline()
45+
.collection(this._query.path.canonicalString());
46+
}
47+
48+
// TODO(pipeline) convert existing query filters, limits, etc into
49+
// pipeline stages
50+
51+
return pipeline;
52+
};
53+
}

packages/firestore/src/lite-api/database.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
getDefaultEmulatorHostnameAndPort
2929
} from '@firebase/util';
3030

31-
import { PipelineSource, DocumentReference } from '../api';
3231
import {
3332
CredentialsProvider,
3433
EmulatorAuthCredentialsProvider,
@@ -37,20 +36,17 @@ import {
3736
} from '../api/credentials';
3837
import { User } from '../auth/user';
3938
import { DatabaseId, DEFAULT_DATABASE_NAME } from '../core/database_info';
40-
import { DocumentKey } from '../model/document_key';
4139
import { Code, FirestoreError } from '../util/error';
4240
import { cast } from '../util/input_validation';
4341
import { logWarn } from '../util/log';
4442

4543
import { FirestoreService, removeComponents } from './components';
46-
import { LiteUserDataWriter } from './reference_impl';
4744
import {
4845
DEFAULT_HOST,
4946
FirestoreSettingsImpl,
5047
PrivateSettings,
5148
FirestoreSettings
5249
} from './settings';
53-
import { newUserDataReader } from './user_data_reader';
5450

5551
export { EmulatorMockTokenOptions } from '@firebase/util';
5652

@@ -177,21 +173,18 @@ export class Firestore implements FirestoreService {
177173
removeComponents(this);
178174
return Promise.resolve();
179175
}
180-
181-
pipeline(): PipelineSource {
182-
const userDataWriter = new LiteUserDataWriter(this);
183-
const userDataReader = newUserDataReader(this);
184-
return new PipelineSource(
185-
this,
186-
userDataReader,
187-
userDataWriter,
188-
(key: DocumentKey) => {
189-
return new DocumentReference(this, null, key);
190-
}
191-
);
192-
}
193176
}
194177

178+
// Undocumented method of Firestore. This is only
179+
// in place to give developers a runtime error suggesting
180+
// how to correctly initialize Firestore for use with Pipelines.
181+
// @ts-ignore
182+
Firestore.prototype.pipeline = function (): unknown {
183+
throw new Error(
184+
'Pipelines not initialized. Your application must call `useFirestorePipelines()` before using Firestore Pipeline features.'
185+
);
186+
};
187+
195188
/**
196189
* Initializes a new instance of Cloud Firestore with the provided settings.
197190
* Can only be called before any other functions, including

packages/firestore/src/lite-api/reference.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import { AutoId } from '../util/misc';
3737
import { Firestore } from './database';
3838
import { FieldPath } from './field_path';
3939
import { FieldValue } from './field_value';
40-
import { Pipeline } from './pipeline';
4140
import { FirestoreDataConverter } from './snapshot';
4241
import { NestedUpdateFields, Primitive } from './types';
4342

@@ -178,30 +177,18 @@ export class Query<
178177
this._query
179178
);
180179
}
181-
182-
/**
183-
* @private
184-
* @internal
185-
*/
186-
pipeline(): Pipeline {
187-
let pipeline;
188-
if (this._query.collectionGroup) {
189-
pipeline = this.firestore
190-
.pipeline()
191-
.collectionGroup(this._query.collectionGroup);
192-
} else {
193-
pipeline = this.firestore
194-
.pipeline()
195-
.collection(this._query.path.canonicalString());
196-
}
197-
198-
// TODO(pipeline) convert existing query filters, limits, etc into
199-
// pipeline stages
200-
201-
return pipeline;
202-
}
203180
}
204181

182+
// Undocumented method of Query. This is only
183+
// in place to give developers a runtime error suggesting
184+
// how to correctly initialize Firestore for use with Pipelines.
185+
// @ts-ignore
186+
Query.prototype.pipeline = function () {
187+
throw new Error(
188+
'Pipelines not initialized. Your application must call `useFirestorePipelines()` before using Firestore Pipeline features.'
189+
);
190+
};
191+
205192
/**
206193
* A `DocumentReference` refers to a document location in a Firestore database
207194
* and can be used to write, read, or listen to the location. The document at

packages/firestore/test/integration/api/pipeline.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ import {
4848
regexMatch,
4949
setDoc,
5050
startsWith,
51-
subtract
51+
subtract,
52+
useFirestorePipelines
5253
} from '../util/firebase_export';
5354
import { apiDescribe, withTestCollection } from '../util/helpers';
5455

5556
use(chaiAsPromised);
57+
useFirestorePipelines();
5658

5759
apiDescribe.only('Pipelines', persistence => {
5860
addEqualityMatcher();

0 commit comments

Comments
 (0)