Laravel AT Protocol Client (alpha & unstable)

Return typed response objects from record client methods

+9 -9
src/Client/Records/FollowRecordClient.php
··· 5 5 use DateTimeInterface; 6 6 use SocialDept\AtpClient\Attributes\ScopedEndpoint; 7 7 use SocialDept\AtpClient\Client\Requests\Request; 8 - use SocialDept\AtpClient\Data\StrongRef; 8 + use SocialDept\AtpClient\Data\Record; 9 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\CreateRecordResponse; 10 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DeleteRecordResponse; 9 11 use SocialDept\AtpClient\Enums\Nsid\BskyGraph; 10 12 use SocialDept\AtpClient\Enums\Scope; 11 13 ··· 21 23 public function create( 22 24 string $subject, 23 25 ?DateTimeInterface $createdAt = null 24 - ): StrongRef { 26 + ): CreateRecordResponse { 25 27 $record = [ 26 28 '$type' => BskyGraph::Follow->value, 27 29 'subject' => $subject, // DID 28 30 'createdAt' => ($createdAt ?? now())->format('c'), 29 31 ]; 30 32 31 - $response = $this->atp->atproto->repo->createRecord( 33 + return $this->atp->atproto->repo->createRecord( 32 34 repo: $this->atp->client->session()->did(), 33 35 collection: BskyGraph::Follow, 34 36 record: $record 35 37 ); 36 - 37 - return StrongRef::fromResponse($response->json()); 38 38 } 39 39 40 40 /** ··· 44 44 */ 45 45 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')] 46 46 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.graph.follow?action=delete')] 47 - public function delete(string $rkey): void 47 + public function delete(string $rkey): DeleteRecordResponse 48 48 { 49 - $this->atp->atproto->repo->deleteRecord( 49 + return $this->atp->atproto->repo->deleteRecord( 50 50 repo: $this->atp->client->session()->did(), 51 51 collection: BskyGraph::Follow, 52 52 rkey: $rkey ··· 59 59 * @requires transition:generic (rpc:com.atproto.repo.getRecord) 60 60 */ 61 61 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')] 62 - public function get(string $rkey, ?string $cid = null): array 62 + public function get(string $rkey, ?string $cid = null): Record 63 63 { 64 64 $response = $this->atp->atproto->repo->getRecord( 65 65 repo: $this->atp->client->session()->did(), ··· 68 68 cid: $cid 69 69 ); 70 70 71 - return $response->json('value'); 71 + return Record::fromArrayRaw($response->toArray()); 72 72 } 73 73 }
+9 -8
src/Client/Records/LikeRecordClient.php
··· 5 5 use DateTimeInterface; 6 6 use SocialDept\AtpClient\Attributes\ScopedEndpoint; 7 7 use SocialDept\AtpClient\Client\Requests\Request; 8 + use SocialDept\AtpClient\Data\Record; 9 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\CreateRecordResponse; 10 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DeleteRecordResponse; 8 11 use SocialDept\AtpClient\Data\StrongRef; 9 12 use SocialDept\AtpClient\Enums\Nsid\BskyFeed; 10 13 use SocialDept\AtpClient\Enums\Scope; ··· 21 24 public function create( 22 25 StrongRef $subject, 23 26 ?DateTimeInterface $createdAt = null 24 - ): StrongRef { 27 + ): CreateRecordResponse { 25 28 $record = [ 26 29 '$type' => BskyFeed::Like->value, 27 30 'subject' => $subject->toArray(), 28 31 'createdAt' => ($createdAt ?? now())->format('c'), 29 32 ]; 30 33 31 - $response = $this->atp->atproto->repo->createRecord( 34 + return $this->atp->atproto->repo->createRecord( 32 35 repo: $this->atp->client->session()->did(), 33 36 collection: BskyFeed::Like, 34 37 record: $record 35 38 ); 36 - 37 - return StrongRef::fromResponse($response->json()); 38 39 } 39 40 40 41 /** ··· 44 45 */ 45 46 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')] 46 47 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.like?action=delete')] 47 - public function delete(string $rkey): void 48 + public function delete(string $rkey): DeleteRecordResponse 48 49 { 49 - $this->atp->atproto->repo->deleteRecord( 50 + return $this->atp->atproto->repo->deleteRecord( 50 51 repo: $this->atp->client->session()->did(), 51 52 collection: BskyFeed::Like, 52 53 rkey: $rkey ··· 59 60 * @requires transition:generic (rpc:com.atproto.repo.getRecord) 60 61 */ 61 62 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')] 62 - public function get(string $rkey, ?string $cid = null): array 63 + public function get(string $rkey, ?string $cid = null): Record 63 64 { 64 65 $response = $this->atp->atproto->repo->getRecord( 65 66 repo: $this->atp->client->session()->did(), ··· 68 69 cid: $cid 69 70 ); 70 71 71 - return $response->json('value'); 72 + return Record::fromArrayRaw($response->toArray()); 72 73 } 73 74 }
+11 -12
src/Client/Records/ProfileRecordClient.php
··· 4 4 5 5 use SocialDept\AtpClient\Attributes\ScopedEndpoint; 6 6 use SocialDept\AtpClient\Client\Requests\Request; 7 - use SocialDept\AtpClient\Data\StrongRef; 7 + use SocialDept\AtpClient\Data\Record; 8 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\PutRecordResponse; 8 9 use SocialDept\AtpClient\Enums\Nsid\BskyActor; 9 10 use SocialDept\AtpClient\Enums\Scope; 10 11 ··· 17 18 */ 18 19 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')] 19 20 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')] 20 - public function update(array $profile): StrongRef 21 + public function update(array $profile): PutRecordResponse 21 22 { 22 23 // Ensure $type is set 23 24 if (! isset($profile['$type'])) { 24 25 $profile['$type'] = BskyActor::Profile->value; 25 26 } 26 27 27 - $response = $this->atp->atproto->repo->putRecord( 28 + return $this->atp->atproto->repo->putRecord( 28 29 repo: $this->atp->client->session()->did(), 29 30 collection: BskyActor::Profile, 30 31 rkey: 'self', // Profile records always use 'self' as rkey 31 32 record: $profile 32 33 ); 33 - 34 - return StrongRef::fromResponse($response->json()); 35 34 } 36 35 37 36 /** ··· 40 39 * @requires transition:generic (rpc:com.atproto.repo.getRecord) 41 40 */ 42 41 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')] 43 - public function get(): array 42 + public function get(): Record 44 43 { 45 44 $response = $this->atp->atproto->repo->getRecord( 46 45 repo: $this->atp->client->session()->did(), ··· 48 47 rkey: 'self' 49 48 ); 50 49 51 - return $response->json('value'); 50 + return Record::fromArrayRaw($response->toArray()); 52 51 } 53 52 54 53 /** ··· 58 57 */ 59 58 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')] 60 59 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')] 61 - public function updateDisplayName(string $displayName): StrongRef 60 + public function updateDisplayName(string $displayName): PutRecordResponse 62 61 { 63 62 $profile = $this->getOrCreateProfile(); 64 63 $profile['displayName'] = $displayName; ··· 73 72 */ 74 73 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')] 75 74 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')] 76 - public function updateDescription(string $description): StrongRef 75 + public function updateDescription(string $description): PutRecordResponse 77 76 { 78 77 $profile = $this->getOrCreateProfile(); 79 78 $profile['description'] = $description; ··· 88 87 */ 89 88 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')] 90 89 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')] 91 - public function updateAvatar(array $avatarBlob): StrongRef 90 + public function updateAvatar(array $avatarBlob): PutRecordResponse 92 91 { 93 92 $profile = $this->getOrCreateProfile(); 94 93 $profile['avatar'] = $avatarBlob; ··· 103 102 */ 104 103 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')] 105 104 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')] 106 - public function updateBanner(array $bannerBlob): StrongRef 105 + public function updateBanner(array $bannerBlob): PutRecordResponse 107 106 { 108 107 $profile = $this->getOrCreateProfile(); 109 108 $profile['banner'] = $bannerBlob; ··· 117 116 protected function getOrCreateProfile(): array 118 117 { 119 118 try { 120 - return $this->get(); 119 + return $this->get()->value; 121 120 } catch (\Exception $e) { 122 121 // Profile doesn't exist, return empty structure 123 122 return [