client.ts (1048B)
1 import { ClientRepository } from "../../core/application/oauth2/client_repository.ts"; 2 import { EntityNotFound } from "../../core/application/repository_error.ts"; 3 import { Client } from "#core/domain/client.ts"; 4 import { Scope } from "#core/domain/scope.ts"; 5 import { Token } from "#core/domain/token.ts"; 6 import { UUID } from "#core/domain/uuid.ts"; 7 8 export class ConfigClientRepositoryAdapter implements ClientRepository { 9 constructor(private readonly path: string) { 10 } 11 12 async find(id: string): Promise<Client> { 13 const client = (JSON.parse(await Deno.readTextFile(this.path)) as { 14 id: string; 15 secret: string; 16 redirectUri: string; 17 scope: string; 18 description: string; 19 }[]) 20 .map((item) => 21 new Client( 22 new UUID(item.id), 23 new Token(item.secret), 24 new URL(item.redirectUri), 25 Scope.of(item.scope), 26 item.description, 27 ) 28 ) 29 .find((i) => i.id); 30 if (client) { 31 return client; 32 } 33 throw new EntityNotFound(id); 34 } 35 }