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

feat(entrypoints): filter entrypoints by connectivity and status #588

Merged
merged 8 commits into from
Aug 21, 2024
14 changes: 8 additions & 6 deletions src/EntryPoint/EntryPoints.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export interface EntryPointFilter {
maksadbek marked this conversation as resolved.
Show resolved Hide resolved
projectId: string;
limit?: number;
connectivity?: string[];
status?: string[];
}

export interface EntryPoints {
entrypoints(
projectId: string,
limit?: number,
connectivity?: string[],
status?: string[]
): Promise<EntryPoint[]>;
entrypoints(filter: EntryPointFilter): Promise<EntryPoint[]>;
}

export const EntryPoints: unique symbol = Symbol('EntryPoints');
Expand Down
10 changes: 8 additions & 2 deletions src/EntryPoint/RestEntryPoints.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ describe('RestEntryPoints', () => {
.get('/api/v2/projects/1/entry-points?limit=10')
.reply(200, { items: [{ id: 1, name: 'entrypoint1' }] });

const result = await restEntryPoints.entrypoints('1', 10);
const result = await restEntryPoints.entrypoints({
projectId: '1',
limit: 10
});

expect(result).toEqual([{ id: 1, name: 'entrypoint1' }]);
});
Expand Down Expand Up @@ -94,7 +97,10 @@ describe('RestEntryPoints', () => {
]
});

const result = await restEntryPoints.entrypoints('1', 111);
const result = await restEntryPoints.entrypoints({
projectId: '1',
limit: 111
});

expect(result).toEqual([
{ id: 1, name: 'entrypoint1', createdAt: '2024-08-06T09:40:50.226Z' },
Expand Down
30 changes: 14 additions & 16 deletions src/EntryPoint/RestEntryPoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntryPoints, EntryPoint } from './EntryPoints';
import { EntryPoints, EntryPoint, EntryPointFilter } from './EntryPoints';
import { ProxyFactory } from '../Utils';
import axios, { Axios } from 'axios';
import { inject, injectable } from 'tsyringe';
Expand Down Expand Up @@ -52,29 +52,27 @@ export class RestEntryPoints implements EntryPoints {
});
}

public async entrypoints(
projectId: string,
limit: number = 10,
connectivity?: string[],
status?: string[]
): Promise<EntryPoint[]> {
let remaining = limit;
public async entrypoints(filter: EntryPointFilter): Promise<EntryPoint[]> {
let remaining = filter.limit ?? 10;
const data: EntryPoint[] = [];
maksadbek marked this conversation as resolved.
Show resolved Hide resolved
let nextId: string;
let nextCreatedAt: string;

while (remaining > 0) {
const {
data: { items = [] }
} = await this.client.get(`/api/v2/projects/${projectId}/entry-points`, {
params: {
nextId,
nextCreatedAt,
limit: Math.min(remaining, this.entrypointsPaginationBatchSize),
connectivity,
status
} = await this.client.get(
`/api/v2/projects/${filter.projectId}/entry-points`,
{
params: {
nextId,
nextCreatedAt,
connectivity: filter.connectivity,
status: filter.status,
limit: Math.min(remaining, this.entrypointsPaginationBatchSize)
}
}
maksadbek marked this conversation as resolved.
Show resolved Hide resolved
});
);

if (!items.length) {
break;
Expand Down
Loading