Skip to content

Commit

Permalink
Strass/typescript defs expansion (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakTax authored and mickeyreiss committed Sep 25, 2018
1 parent be24a49 commit 865244f
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 32 deletions.
101 changes: 85 additions & 16 deletions langs/ts/ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,28 @@ const (
import { firestore } from 'firebase';
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export interface DocumentSnapshot<DataType = firestore.DocumentData>
extends firestore.DocumentSnapshot {
data(options?: firestore.SnapshotOptions): DataType | undefined;
}
export interface QueryDocumentSnapshot<
DataType = firestore.DocumentData
> extends firestore.QueryDocumentSnapshot {
export interface QueryDocumentSnapshot<DataType = firestore.DocumentData>
extends firestore.QueryDocumentSnapshot {
data(options?: firestore.SnapshotOptions): DataType | undefined;
}
export interface QuerySnapshot<DataType = firestore.DocumentData>
extends firestore.QuerySnapshot {
readonly docs: QueryDocumentSnapshot<DataType>[];
}
export interface DocumentSnapshotExpanded<
DataType = firestore.DocumentData
> {
export interface DocumentSnapshotExpanded<DataType = firestore.DocumentData> {
exists: firestore.DocumentSnapshot['exists'];
ref: firestore.DocumentSnapshot['ref'];
id: firestore.DocumentSnapshot['id'];
metadata: firestore.DocumentSnapshot['metadata'];
data: DataType;
}
export interface QuerySnapshotExpanded<
DataType = firestore.DocumentData
> {
export interface QuerySnapshotExpanded<DataType = firestore.DocumentData> {
metadata: {
hasPendingWrites: firestore.QuerySnapshot['metadata']['hasPendingWrites'];
fromCache: firestore.QuerySnapshot['metadata']['fromCache'];
Expand All @@ -172,19 +169,91 @@ export interface QuerySnapshotExpanded<
[docId: string]: DocumentSnapshotExpanded<DataType>;
};
}
export interface DocumentReference<DataType> extends firestore.DocumentReference {
data(options?: firestore.SnapshotOptions): DataType | undefined;
export interface DocumentReference<DataType = firestore.DocumentData>
extends firestore.DocumentReference {
set(data: DataType, options?: firestore.SetOptions): Promise<void>;
get(options?: firestore.GetOptions): Promise<DocumentSnapshot<DataType>>;
onSnapshot(observer: {
next?: (snapshot: DocumentSnapshot<DataType>) => void;
error?: (error: firestore.FirestoreError) => void;
complete?: () => void;
}): () => void;
onSnapshot(
options: firestore.SnapshotListenOptions,
observer: {
next?: (snapshot: DocumentSnapshot<DataType>) => void;
error?: (error: Error) => void;
complete?: () => void;
},
): () => void;
onSnapshot(
onNext: (snapshot: DocumentSnapshot<DataType>) => void,
onError?: (error: Error) => void,
onCompletion?: () => void,
): () => void;
onSnapshot(
options: firestore.SnapshotListenOptions,
onNext: (snapshot: DocumentSnapshot<DataType>) => void,
onError?: (error: Error) => void,
onCompletion?: () => void,
): () => void;
}
export interface CollectionReference<
DataType = firestore.DocumentData
> extends firestore.CollectionReference {
get(options?: firestore.GetOptions): Promise<QuerySnapshot<DataType>>;
export interface CollectionReference<DataType = firestore.DocumentData>
extends Query<DataType>,
Omit<firestore.CollectionReference, keyof Query> {
add(data: DataType): Promise<DocumentReference>;
}
export interface Collection<DataType = firestore.DocumentData> {
[id: string]: DocumentSnapshotExpanded<DataType>;
}
export interface Query<DataType = firestore.DocumentData>
extends firestore.Query {
where(
fieldPath: string | firestore.FieldPath,
opStr: firestore.WhereFilterOp,
value: any,
): Query<DataType>;
orderBy(
fieldPath: string | firestore.FieldPath,
directionStr?: firestore.OrderByDirection,
): Query<DataType>;
limit(limit: number): Query<DataType>;
startAt(snapshot: DocumentSnapshot): Query<DataType>;
startAt(...fieldValues: any[]): Query<DataType>;
startAfter(snapshot: DocumentSnapshot): Query<DataType>;
startAfter(...fieldValues: any[]): Query<DataType>;
endBefore(snapshot: DocumentSnapshot): Query<DataType>;
endBefore(...fieldValues: any[]): Query<DataType>;
endAt(snapshot: DocumentSnapshot): Query<DataType>;
endAt(...fieldValues: any[]): Query<DataType>;
get(options?: firestore.GetOptions): Promise<QuerySnapshot<DataType>>;
onSnapshot(observer: {
next?: (snapshot: QuerySnapshot<DataType>) => void;
error?: (error: Error) => void;
complete?: () => void;
}): () => void;
onSnapshot(
options: firestore.SnapshotListenOptions,
observer: {
next?: (snapshot: QuerySnapshot<DataType>) => void;
error?: (error: Error) => void;
complete?: () => void;
},
): () => void;
onSnapshot(
onNext: (snapshot: QuerySnapshot<DataType>) => void,
onError?: (error: Error) => void,
onCompletion?: () => void,
): () => void;
onSnapshot(
options: firestore.SnapshotListenOptions,
onNext: (snapshot: QuerySnapshot<DataType>) => void,
onError?: (error: Error) => void,
onCompletion?: () => void,
): () => void;
}
// tslint:disable-next-line:no-namespace
export namespace {{.Options | getSchemaOption "ts" "namespace" "firemodel"}} {
type URL = string;
Expand All @@ -193,7 +262,7 @@ export namespace {{.Options | getSchemaOption "ts" "namespace" "firemodel"}} {
url: URL;
mimeType: string;
name: string;
}
}
{{- range .Enums -}}
{{- template "enum" .}}
Expand Down
101 changes: 85 additions & 16 deletions testfixtures/firemodel/TestFiremodelFromSchema/ts/firemodel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,28 @@

import { firestore } from 'firebase';

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

export interface DocumentSnapshot<DataType = firestore.DocumentData>
extends firestore.DocumentSnapshot {
data(options?: firestore.SnapshotOptions): DataType | undefined;
}
export interface QueryDocumentSnapshot<
DataType = firestore.DocumentData
> extends firestore.QueryDocumentSnapshot {
export interface QueryDocumentSnapshot<DataType = firestore.DocumentData>
extends firestore.QueryDocumentSnapshot {
data(options?: firestore.SnapshotOptions): DataType | undefined;
}
export interface QuerySnapshot<DataType = firestore.DocumentData>
extends firestore.QuerySnapshot {
readonly docs: QueryDocumentSnapshot<DataType>[];
}
export interface DocumentSnapshotExpanded<
DataType = firestore.DocumentData
> {
export interface DocumentSnapshotExpanded<DataType = firestore.DocumentData> {
exists: firestore.DocumentSnapshot['exists'];
ref: firestore.DocumentSnapshot['ref'];
id: firestore.DocumentSnapshot['id'];
metadata: firestore.DocumentSnapshot['metadata'];
data: DataType;
}
export interface QuerySnapshotExpanded<
DataType = firestore.DocumentData
> {
export interface QuerySnapshotExpanded<DataType = firestore.DocumentData> {
metadata: {
hasPendingWrites: firestore.QuerySnapshot['metadata']['hasPendingWrites'];
fromCache: firestore.QuerySnapshot['metadata']['fromCache'];
Expand All @@ -37,19 +34,91 @@ export interface QuerySnapshotExpanded<
[docId: string]: DocumentSnapshotExpanded<DataType>;
};
}
export interface DocumentReference<DataType> extends firestore.DocumentReference {
data(options?: firestore.SnapshotOptions): DataType | undefined;
export interface DocumentReference<DataType = firestore.DocumentData>
extends firestore.DocumentReference {
set(data: DataType, options?: firestore.SetOptions): Promise<void>;
get(options?: firestore.GetOptions): Promise<DocumentSnapshot<DataType>>;
onSnapshot(observer: {
next?: (snapshot: DocumentSnapshot<DataType>) => void;
error?: (error: firestore.FirestoreError) => void;
complete?: () => void;
}): () => void;
onSnapshot(
options: firestore.SnapshotListenOptions,
observer: {
next?: (snapshot: DocumentSnapshot<DataType>) => void;
error?: (error: Error) => void;
complete?: () => void;
},
): () => void;
onSnapshot(
onNext: (snapshot: DocumentSnapshot<DataType>) => void,
onError?: (error: Error) => void,
onCompletion?: () => void,
): () => void;
onSnapshot(
options: firestore.SnapshotListenOptions,
onNext: (snapshot: DocumentSnapshot<DataType>) => void,
onError?: (error: Error) => void,
onCompletion?: () => void,
): () => void;
}
export interface CollectionReference<
DataType = firestore.DocumentData
> extends firestore.CollectionReference {
get(options?: firestore.GetOptions): Promise<QuerySnapshot<DataType>>;
export interface CollectionReference<DataType = firestore.DocumentData>
extends Query<DataType>,
Omit<firestore.CollectionReference, keyof Query> {
add(data: DataType): Promise<DocumentReference>;
}
export interface Collection<DataType = firestore.DocumentData> {
[id: string]: DocumentSnapshotExpanded<DataType>;
}

export interface Query<DataType = firestore.DocumentData>
extends firestore.Query {
where(
fieldPath: string | firestore.FieldPath,
opStr: firestore.WhereFilterOp,
value: any,
): Query<DataType>;
orderBy(
fieldPath: string | firestore.FieldPath,
directionStr?: firestore.OrderByDirection,
): Query<DataType>;
limit(limit: number): Query<DataType>;
startAt(snapshot: DocumentSnapshot): Query<DataType>;
startAt(...fieldValues: any[]): Query<DataType>;
startAfter(snapshot: DocumentSnapshot): Query<DataType>;
startAfter(...fieldValues: any[]): Query<DataType>;
endBefore(snapshot: DocumentSnapshot): Query<DataType>;
endBefore(...fieldValues: any[]): Query<DataType>;
endAt(snapshot: DocumentSnapshot): Query<DataType>;
endAt(...fieldValues: any[]): Query<DataType>;
get(options?: firestore.GetOptions): Promise<QuerySnapshot<DataType>>;
onSnapshot(observer: {
next?: (snapshot: QuerySnapshot<DataType>) => void;
error?: (error: Error) => void;
complete?: () => void;
}): () => void;
onSnapshot(
options: firestore.SnapshotListenOptions,
observer: {
next?: (snapshot: QuerySnapshot<DataType>) => void;
error?: (error: Error) => void;
complete?: () => void;
},
): () => void;
onSnapshot(
onNext: (snapshot: QuerySnapshot<DataType>) => void,
onError?: (error: Error) => void,
onCompletion?: () => void,
): () => void;
onSnapshot(
options: firestore.SnapshotListenOptions,
onNext: (snapshot: QuerySnapshot<DataType>) => void,
onError?: (error: Error) => void,
onCompletion?: () => void,
): () => void;
}

// tslint:disable-next-line:no-namespace
export namespace example {
type URL = string;
Expand All @@ -58,7 +127,7 @@ export namespace example {
url: URL;
mimeType: string;
name: string;
}
}

/** TODO: Add documentation to TestDirection. */
export enum TestDirection {
Expand Down

0 comments on commit 865244f

Please sign in to comment.