Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add limit to all getAll*() methods (fixes #233) #234

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const typePredicate = (documentType: string): string =>
* Creates a predicate to filter content by document tags. All tags are required
* on the document.
*
* @param documentType - Document tags to filter queried content.
* @param tags - Document tags to filter queried content.
*
* @returns A predicate that can be used in a Prismic REST API V2 request.
*/
Expand All @@ -229,7 +229,7 @@ const everyTagPredicate = (tags: string | string[]): string =>
* Creates a predicate to filter content by document tags. At least one matching
* tag is required on the document.
*
* @param documentType - Document tags to filter queried content.
* @param tags - Document tags to filter queried content.
*
* @returns A predicate that can be used in a Prismic REST API V2 request.
*/
Expand Down Expand Up @@ -257,8 +257,9 @@ const someTagsPredicate = (tags: string | string[]): string =>
* @returns A client that can query content from the repository.
*/
export const createClient = (
...args: ConstructorParameters<typeof Client>
): Client => new Client(...args);
repositoryNameOrEndpoint: ConstructorParameters<typeof Client>[0],
options: ConstructorParameters<typeof Client>[1] = {},
): Client => new Client(repositoryNameOrEndpoint, options);

/**
* A client that allows querying content from a Prismic repository.
Expand Down Expand Up @@ -658,7 +659,7 @@ export class Client {
*/
async getAllByIDs<TDocument extends prismicT.PrismicDocument>(
ids: string[],
params?: Partial<BuildQueryURLArgs> & FetchParams,
params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams,
): Promise<TDocument[]> {
return await this.dangerouslyGetAll<TDocument>(
appendPredicates(params, predicate.in("document.id", ids)),
Expand Down Expand Up @@ -764,7 +765,7 @@ export class Client {
async getAllByUIDs<TDocument extends prismicT.PrismicDocument>(
documentType: string,
uids: string[],
params?: Partial<BuildQueryURLArgs> & FetchParams,
params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams,
): Promise<TDocument[]> {
return await this.dangerouslyGetAll<TDocument>(
appendPredicates(params, [
Expand Down Expand Up @@ -849,7 +850,9 @@ export class Client {
*/
async getAllByType<TDocument extends prismicT.PrismicDocument>(
documentType: string,
params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams,
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
GetAllParams &
FetchParams,
): Promise<TDocument[]> {
return await this.dangerouslyGetAll<TDocument>(
appendPredicates(params, typePredicate(documentType)),
Expand Down Expand Up @@ -901,7 +904,9 @@ export class Client {
*/
async getAllByTag<TDocument extends prismicT.PrismicDocument>(
tag: string,
params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams,
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
GetAllParams &
FetchParams,
): Promise<TDocument[]> {
return await this.dangerouslyGetAll<TDocument>(
appendPredicates(params, someTagsPredicate(tag)),
Expand Down Expand Up @@ -953,7 +958,9 @@ export class Client {
*/
async getAllByEveryTag<TDocument extends prismicT.PrismicDocument>(
tags: string[],
params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams,
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
GetAllParams &
FetchParams,
): Promise<TDocument[]> {
return await this.dangerouslyGetAll<TDocument>(
appendPredicates(params, everyTagPredicate(tags)),
Expand Down Expand Up @@ -1005,7 +1012,9 @@ export class Client {
*/
async getAllBySomeTags<TDocument extends prismicT.PrismicDocument>(
tags: string[],
params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams,
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
GetAllParams &
FetchParams,
): Promise<TDocument[]> {
return await this.dangerouslyGetAll<TDocument>(
appendPredicates(params, someTagsPredicate(tags)),
Expand Down Expand Up @@ -1258,7 +1267,7 @@ export class Client {
* const document = await client.getByID("WW4bKScAAMAqmluX");
* ```
*
* @param id - The ID of the Release.
* @param releaseID - The ID of the Release.
*/
queryContentFromReleaseByID(releaseID: string): void {
this.refState = {
Expand All @@ -1281,7 +1290,7 @@ export class Client {
* const document = await client.getByID("WW4bKScAAMAqmluX");
* ```
*
* @param label - The label of the Release.
* @param releaseLabel - The label of the Release.
*/
queryContentFromReleaseByLabel(releaseLabel: string): void {
this.refState = {
Expand Down