Skip to content

Commit 180751f

Browse files
Almost
1 parent 10d1d7e commit 180751f

File tree

4 files changed

+83
-72
lines changed

4 files changed

+83
-72
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,10 @@ export function documentId(): FieldPath;
133133
//
134134
// @public
135135
export class DocumentReference<T = DocumentData> extends _DocumentKeyReference<T> {
136-
constructor(firestore: FirebaseFirestore_2, converter: FirestoreDataConverter_2<T> | null, _path: ResourcePath);
136+
constructor(firestore: FirebaseFirestore_2, _converter: FirestoreDataConverter_2<T> | null, _path: ResourcePath);
137137
// (undocumented)
138138
collection(path: string): CollectionReference<DocumentData>;
139139
// (undocumented)
140-
readonly converter: FirestoreDataConverter_2<T> | null;
141-
// (undocumented)
142140
readonly firestore: FirebaseFirestore_2;
143141
// (undocumented)
144142
get id(): string;
@@ -378,9 +376,9 @@ export interface PersistenceSettings {
378376

379377
// @public (undocumented)
380378
export class Query<T = DocumentData> {
381-
constructor(firestore: FirebaseFirestore_2, converter: FirestoreDataConverter_2<T> | null, _query: Query_2);
379+
constructor(firestore: FirebaseFirestore_2, _converter: FirestoreDataConverter_2<T> | null, _query: Query_2);
382380
// (undocumented)
383-
readonly converter: FirestoreDataConverter_2<T> | null;
381+
readonly _converter: FirestoreDataConverter_2<T> | null;
384382
// (undocumented)
385383
readonly firestore: FirebaseFirestore_2;
386384
// Warning: (ae-forgotten-export) The symbol "Query" needs to be exported by the entry point index.d.ts
@@ -583,7 +581,7 @@ export function waitForPendingWrites(firestore: FirebaseFirestore): Promise<void
583581
export function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryConstraint;
584582

585583
// @public (undocumented)
586-
export type WhereFilterOp = '<' | '<=' | '==' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any';
584+
export type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';
587585

588586
// @public (undocumented)
589587
export class WriteBatch {

packages/firestore/exp-types/index.d.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export declare function documentId(): FieldPath;
9494
*/
9595
export declare class DocumentReference<T = DocumentData> {
9696
readonly firestore: FirebaseFirestore;
97-
readonly converter: FirestoreDataConverter<T> | null;
9897
readonly type = 'document';
9998
private constructor();
10099
get id(): string;
@@ -109,8 +108,6 @@ export declare class DocumentSnapshot<T = DocumentData> {
109108
exists(): this is QueryDocumentSnapshot<T>;
110109
data(options?: SnapshotOptions): T | undefined;
111110
get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
112-
get id(): string;
113-
get ref(): DocumentReference<T>;
114111
}
115112
export declare function enableIndexedDbPersistence(
116113
firestore: FirebaseFirestore,
@@ -146,16 +143,13 @@ export declare class FieldPath {
146143
isEqual(other: FieldPath): boolean;
147144
}
148145
/** The public FieldValue class of the lite API. */
149-
export declare abstract class FieldValue {
150-
abstract isEqual(other: FieldValue): boolean;
151-
}
146+
export declare abstract class FieldValue {}
152147
/**
153148
* The root reference to the Firestore database and the entry point for the
154149
* tree-shakeable SDK.
155150
*/
156151
export declare class FirebaseFirestore {
157152
private constructor();
158-
readonly app: FirebaseApp;
159153
}
160154
export declare interface FirestoreDataConverter<T> {
161155
toFirestore(modelObject: T): DocumentData;
@@ -354,7 +348,6 @@ export declare interface PersistenceSettings {
354348
}
355349
export declare class Query<T = DocumentData> {
356350
readonly firestore: FirebaseFirestore;
357-
readonly converter: FirestoreDataConverter<T> | null;
358351
readonly type: 'query' | 'collection';
359352
protected constructor();
360353
withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
@@ -422,9 +415,6 @@ export declare type SetOptions =
422415
};
423416
export declare interface Settings {
424417
cacheSizeBytes?: number;
425-
host?: string;
426-
ssl?: boolean;
427-
ignoreUndefinedProperties?: boolean;
428418
}
429419
export declare function snapshotEqual<T>(
430420
left: DocumentSnapshot<T> | QuerySnapshot<T>,
@@ -487,20 +477,6 @@ export declare class Timestamp {
487477
export declare class Transaction {
488478
private constructor();
489479
get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
490-
set<T>(documentRef: DocumentReference<T>, data: T): this;
491-
set<T>(
492-
documentRef: DocumentReference<T>,
493-
data: Partial<T>,
494-
options: SetOptions
495-
): this;
496-
update(documentRef: DocumentReference<unknown>, data: UpdateData): this;
497-
update(
498-
documentRef: DocumentReference<unknown>,
499-
field: string | FieldPath,
500-
data: unknown,
501-
...moreFieldsAndValues: unknown[]
502-
): this;
503-
delete(documentRef: DocumentReference<unknown>): this;
504480
}
505481
export declare interface Unsubscribe {
506482
(): void;
@@ -530,11 +506,13 @@ export declare type WhereFilterOp =
530506
| '<'
531507
| '<='
532508
| '=='
509+
| '!='
533510
| '>='
534511
| '>'
535512
| 'array-contains'
536513
| 'in'
537-
| 'array-contains-any';
514+
| 'array-contains-any'
515+
| 'not-in';
538516
export declare class WriteBatch {
539517
private constructor();
540518
set<T>(documentRef: DocumentReference<T>, data: T): WriteBatch;
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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+
118
export declare class B1 {
2-
data: ()
3-
foo: ()
19+
data?: string;
20+
foo(data: string): string;
21+
foo(data: string): string | void;
422
}
523
export {};

packages/firestore/scripts/prune-dts.ts

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ function visit<T extends ts.Node>(
103103
]).transformed[0] as T;
104104
}
105105

106+
function convertParams(params?: ts.ParameterDeclaration[]):ts.ParameterDeclaration[]|undefined {
107+
return params?.map(t => {
108+
return ts.createParameter(t.decorators, t.modifiers, t.dotDotDotToken, t.name, t.questionToken, t.type, t.initializer)
109+
});
110+
}
111+
106112
/**
107113
* Examines `extends` and `implements` clauses and removes or replaces them if
108114
* they refer to a non-exported type. When an export is removed, all members
@@ -159,48 +165,13 @@ function prunePrivateImports<
159165
// Iterate all members of the private type and add them to the
160166
// public type if they are not already part of the public type.
161167
const privateType = typeChecker.getTypeAtLocation(type);
162-
for (const property of privateType.getProperties()) {
163-
const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, type);
164-
console.log("Name:", property.name, "Type:", typeChecker.typeToString(propertyType));
165-
let newType = typeChecker.typeToTypeNode(propertyType, undefined, undefined)!;
166-
additionalMembers.push(ts.createPropertyAssignment( property.name,
167-
168-
ts.createExpression newType));
169-
170-
//if (!currentMembers || !currentMembers.has(memberName)) {
171-
// additionalMembers.push(
172-
// ...property.declarations.map(d =>
173-
// visit(typeChecker, type, d)
174-
// )
175-
// );
176-
// }
177-
// if (privateType?.symbol?.members) {
178-
//
179-
// privateType.symbol.members!.forEach((definition, memberName) => {
180-
// if (!currentMembers || !currentMembers.has(memberName)) {
181-
// additionalMembers.push(
182-
// ...definition.declarations.slice(0,1).map(d =>
183-
// visit(typeChecker, type, d)
184-
// )
185-
// );
186-
// }
187-
// });
168+
for (const privateProperty of privateType.getProperties()) {
169+
additionalMembers.push(...getPublicPropertyDeclarations(typeChecker, privateProperty, type));
188170
}
189171
}
190172
}
191173
}
192-
193-
// for (const property of privateType.getProperties()) {
194-
// for (const declaration of property.declarations) {
195-
// if (ts.isPropertyDeclaration(declaration)) {
196-
//
197-
// const localType = typeChecker.typeToTypeNode(typeChecker.getTypeOfSymbolAtLocation(property, type), node, undefined);
198-
//
199-
// const updatedElement = ts.updateProperty(declaration, declaration.decorators, declaration.modifiers, declaration.name, declaration.questionToken || declaration.exclamationToken, localType, declaration.initializer);
200-
// additionalMembers.push(updatedElement);
201-
// }
202-
// }
203-
// }
174+
204175
if (exportedTypes.length > 0) {
205176
prunedHeritageClauses.push(
206177
ts.updateHeritageClause(heritageClause, exportedTypes)
@@ -233,6 +204,52 @@ function prunePrivateImports<
233204
}
234205
}
235206

207+
208+
function getPublicPropertyDeclarations(typeChecker: ts.TypeChecker, property: ts.Symbol, location: ts.Node) : Array<ts.NamedDeclaration> {
209+
const declaredType = typeChecker.getTypeOfSymbolAtLocation(property, location);
210+
const resolvedType = typeChecker.typeToTypeNode(declaredType, location, undefined)!;
211+
212+
const declaration = property.declarations[0];
213+
const optional = !!(property.flags & ts.SymbolFlags.Optional) ? ts.createToken(ts.SyntaxKind.QuestionToken) : undefined;
214+
215+
// Based on https://github.com/microsoft/TypeScript/blob/8e9de9bed2e0170f7c43ef17b292cea29b46befb/src/services/codefixes/helpers.ts#L34
216+
217+
switch (declaration.kind) {
218+
case ts.SyntaxKind.PropertySignature:
219+
case ts.SyntaxKind.PropertyDeclaration:
220+
const modifiers =declaration.modifiers;
221+
return [ts.createProperty(
222+
/*decorators*/ undefined,
223+
modifiers,
224+
property.name,
225+
optional,
226+
resolvedType,
227+
/*initializer*/ undefined)];
228+
case ts.SyntaxKind.MethodSignature:
229+
case ts.SyntaxKind.MethodDeclaration:
230+
return declaredType.getCallSignatures().map(callSignature => {
231+
const methodDeclaration = typeChecker.signatureToSignatureDeclaration(callSignature, ts.SyntaxKind.MethodDeclaration, location, undefined)! as ts.MethodDeclaration;
232+
return ts.createMethod(
233+
methodDeclaration.decorators,
234+
methodDeclaration.modifiers,
235+
methodDeclaration.asteriskToken,
236+
property.name,
237+
optional,
238+
methodDeclaration.typeParameters?.map(t => {
239+
return ts.createTypeParameterDeclaration(t.name, t.constraint, t.default) // Fix
240+
}), // this should be newType
241+
methodDeclaration.parameters,
242+
typeChecker.typeToTypeNode(callSignature.getReturnType(), undefined, undefined),
243+
/*block*/ undefined);
244+
});
245+
case ts.SyntaxKind.GetAccessor:
246+
case ts.SyntaxKind.SetAccessor:
247+
// TODO: Port set and get accessor support from https://github.com/microsoft/TypeScript/blob/8e9de9bed2e0170f7c43ef17b292cea29b46befb/src/services/codefixes/helpers.ts#L34
248+
throw new Error("get() and set() accessors are not supported yet by the Prune API script.");
249+
}
250+
251+
return [];
252+
}
236253
/**
237254
* Replaces input types of public APIs that consume non-exported types, which
238255
* allows us to exclude private types from the pruned definitions. Returns the

0 commit comments

Comments
 (0)