Skip to content

Commit

Permalink
improve collection and collectionGroup JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
tylim88 committed Jul 31, 2023
1 parent 5d9e016 commit b42b8b5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
7 changes: 6 additions & 1 deletion codeForDoc/src/quick_start/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getDocs, query, where, orderBy, limit } from 'firelordjs'
// filter documents
getDocs(
query(
example.collection(),
example.collection(), // or example.collectionGroup()
where('f.h', '>', 1010),
orderBy('f.h'),
limit(10)
Expand All @@ -25,3 +25,8 @@ getDocs(
// similar to docSnapshot of getDoc
})
})

// get all collection documents
getDocs(
example.collection() // or example.collectionGroup()
)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firelordjs",
"version": "2.6.4",
"version": "2.6.5",
"description": "🔥 High Precision Typescript Wrapper for Firestore Web, Providing Unparalleled Type Safe and Dev Experience",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
12 changes: 4 additions & 8 deletions src/types/firelord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ type Doc_<T extends MetaType> = {
}

type Collection_<T extends MetaType> = {
/**
* Gets a `CollectionReference` instance that refers to the collection at
* the specified absolute path.
*
* @param documentIds - all the docID(s) needed to build this collection path.
* @returns The `CollectionReference` instance.
*/
collection: Collection<T>
}

type CollectionGroup_<T extends MetaType> = {
/**
* @returns — The created Query.
* related documentations:
* - {@link https://firelordjs.com/quick_start/#query query}
* - {@link https://firelordjs.com/quick_start/#onsnapshot onSnapshot}
* @returns — The created {@link Query}.
*/
collectionGroup: () => Query<T>
}
Expand Down
42 changes: 24 additions & 18 deletions src/types/refs/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { DocumentReference } from './doc'
import { Query } from './query'

/**
* A `CollectionReference` object can be used for adding documents, getting
* document references, and querying for documents (using {@link query}).
* A {@link CollectionReference} object can be used for adding documents, getting
* {@link DocumentReference}, and querying for documents (using {@link Query}).
*/
export interface CollectionReference<T extends MetaType> extends Query<T> {
/** The type of this Firestore reference. */
Expand All @@ -20,32 +20,38 @@ export interface CollectionReference<T extends MetaType> extends Query<T> {
*/
get path(): T['collectionPath']
/**
* A reference to the containing `DocumentReference` if this is a
* subcollection. If this isn't a subcollection, the reference is null.
* A reference to the containing parent {@link DocumentReference} if this is a
* sub-collection. If this isn't a sub-collection, the reference is null.
*/
get parent(): T['parent'] extends MetaType
? DocumentReference<T['parent']>
: null
}

export type CollectionCreator =
export type CollectionCreator = <T extends MetaType>(
fStore: Firestore,
...collectionIDs: GetOddOrEvenSegments<T['collectionPath'], 'Odd'>
) => Collection<T>

export type Collection<T extends MetaType> = {
/**
* Gets a `CollectionReference` instance that refers to the collection at
* Gets a {@link CollectionReference} instance that refers to the collection at
* the specified absolute path.
*
* @param documentIds - all the docID(s) needed to build this collection path.
* @returns The `CollectionReference` instance.
* related documentations:
* - {@link https://firelordjs.com/guides/metatype child meta type}
* - {@link https://firelordjs.com/quick_start#operations operation}
* @param documentIds
* All the docID(s) needed to build this document path, eg
* - for top-collection: example.collection()
* - for sub-collection: example.collection(GrandParentDocId, ParentsDocId)
*
* @returns The {@link CollectionReference} instance.
*/
<T extends MetaType>(
fStore: Firestore,
...collectionIDs: GetOddOrEvenSegments<T['collectionPath'], 'Odd'>
) => Collection<T>

export type Collection<T extends MetaType> = <
D extends GetOddOrEvenSegments<T['collectionPath'], 'Even'>
>(
...documentIDs: D extends never ? D : IsValidDocIDLoop<D>
) => CollectionReference<T>
<D extends GetOddOrEvenSegments<T['collectionPath'], 'Even'>>(
...documentIDs: D extends never ? D : IsValidDocIDLoop<D>
): CollectionReference<T>
}

export type GetCollectionIds<T extends MetaType> = GetOddOrEvenSegments<
T['collectionPath'],
Expand Down
13 changes: 6 additions & 7 deletions src/types/refs/collectionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import { Firestore } from '../alias'
import { Query } from './query'

/**
* A `CollectionGroup` refers to all documents that are contained in a
* collection or subcollection with a specific collection ID.
* A {@link CollectionGroup} refers to all documents that are contained in a
* collection or sub-collection with a specific collection ID.
*/
export interface CollectionGroupReference<T extends MetaType> extends Query<T> {
export interface CollectionGroup<T extends MetaType> extends Query<T> {
/** The type of this Firestore reference. */
readonly type: 'query'
}

export type CollectionGroupCreator = <T extends MetaType>(
fStore: Firestore,
collectionID: T['collectionID']
) => /**
* @returns — The created Query.
*/
() => CollectionGroupReference<T>
) => {
(): CollectionGroup<T>
}

0 comments on commit b42b8b5

Please sign in to comment.