import type { PeeringDbClient } from './peeringdb.classes.client.js'; import type { INetwork } from './interfaces/peeringdb.api.network.js'; import type { IQueryOptions } from './peeringdb.types.js'; /** * Manager for Network resources */ export class NetworkManager { constructor(private client: PeeringDbClient) {} /** * List networks with optional filtering */ async list(options: IQueryOptions = {}): Promise { return this.client.request('net', 'GET', options); } /** * Get a single network by ID */ async getById(id: number, depth?: 0 | 1 | 2): Promise { const options: IQueryOptions = { id }; if (depth !== undefined) { options.depth = depth; } const results = await this.client.request('net', 'GET', options); return results[0] || null; } /** * Get a network by ASN */ async getByAsn(asn: number, depth?: 0 | 1 | 2): Promise { const options: IQueryOptions = { asn }; if (depth !== undefined) { options.depth = depth; } const results = await this.client.request('net', 'GET', options); return results[0] || null; } /** * Search networks by name */ async searchByName(name: string, options: IQueryOptions = {}): Promise { return this.client.request('net', 'GET', { ...options, name__contains: name, }); } /** * Get networks by organization ID */ async getByOrgId(orgId: number, options: IQueryOptions = {}): Promise { return this.client.request('net', 'GET', { ...options, org_id: orgId, }); } /** * Search networks by IRR as-set */ async searchByIrrAsSet(irrAsSet: string, options: IQueryOptions = {}): Promise { return this.client.request('net', 'GET', { ...options, irr_as_set__contains: irrAsSet, }); } /** * Get networks by peering policy */ async getByPolicy(policy: string, options: IQueryOptions = {}): Promise { return this.client.request('net', 'GET', { ...options, policy_general: policy, }); } /** * Create a new network (requires authentication) */ async create(data: Partial): Promise { const results = await this.client.request('net', 'POST', {}, data); return results[0]; } /** * Update a network (requires authentication) */ async update(id: number, data: Partial): Promise { const results = await this.client.request(`net/${id}`, 'PUT', {}, data); return results[0]; } /** * Delete a network (requires authentication) */ async delete(id: number): Promise { await this.client.request('net', 'DELETE', { id }); } }