Laravel AT Protocol Client (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpClient\Client\Requests\Atproto;
4
5use BackedEnum;
6use SocialDept\AtpClient\Attributes\PublicEndpoint;
7use SocialDept\AtpClient\Client\Requests\Request;
8use SocialDept\AtpClient\Data\Responses\Atproto\Sync\GetRepoStatusResponse;
9use SocialDept\AtpClient\Data\Responses\Atproto\Sync\ListBlobsResponse;
10use SocialDept\AtpClient\Data\Responses\Atproto\Sync\ListReposByCollectionResponse;
11use SocialDept\AtpClient\Data\Responses\Atproto\Sync\ListReposResponse;
12use SocialDept\AtpClient\Enums\Nsid\AtprotoSync;
13use SocialDept\AtpClient\Http\Response;
14use SocialDept\AtpSchema\Generated\Com\Atproto\Repo\Defs\CommitMeta;
15
16class SyncRequestClient extends Request
17{
18 /**
19 * Get a blob associated with a given account
20 *
21 * @see https://docs.bsky.app/docs/api/com-atproto-sync-get-blob
22 */
23 #[PublicEndpoint]
24 public function getBlob(string $did, string $cid): Response
25 {
26 return $this->atp->client->get(
27 endpoint: AtprotoSync::GetBlob,
28 params: compact('did', 'cid')
29 );
30 }
31
32 /**
33 * Download a repository export as CAR file
34 *
35 * @see https://docs.bsky.app/docs/api/com-atproto-sync-get-repo
36 */
37 #[PublicEndpoint]
38 public function getRepo(string $did, ?string $since = null): Response
39 {
40 return $this->atp->client->get(
41 endpoint: AtprotoSync::GetRepo,
42 params: compact('did', 'since')
43 );
44 }
45
46 /**
47 * Enumerates all the DID, rev, and commit CID for all repos hosted by this service
48 *
49 * @see https://docs.bsky.app/docs/api/com-atproto-sync-list-repos
50 */
51 #[PublicEndpoint]
52 public function listRepos(int $limit = 500, ?string $cursor = null): ListReposResponse
53 {
54 $response = $this->atp->client->get(
55 endpoint: AtprotoSync::ListRepos,
56 params: compact('limit', 'cursor')
57 );
58
59 return ListReposResponse::fromArray($response->json());
60 }
61
62 /**
63 * Enumerates all the DIDs with records in a specific collection
64 *
65 * @see https://docs.bsky.app/docs/api/com-atproto-sync-list-repos-by-collection
66 */
67 #[PublicEndpoint]
68 public function listReposByCollection(
69 string|BackedEnum $collection,
70 int $limit = 500,
71 ?string $cursor = null
72 ): ListReposByCollectionResponse {
73 $collection = $collection instanceof BackedEnum ? $collection->value : $collection;
74
75 $response = $this->atp->client->get(
76 endpoint: AtprotoSync::ListReposByCollection,
77 params: compact('collection', 'limit', 'cursor')
78 );
79
80 return ListReposByCollectionResponse::fromArray($response->json());
81 }
82
83 /**
84 * Get the current commit CID & revision of the specified repo
85 *
86 * @see https://docs.bsky.app/docs/api/com-atproto-sync-get-latest-commit
87 */
88 #[PublicEndpoint]
89 public function getLatestCommit(string $did): CommitMeta
90 {
91 $response = $this->atp->client->get(
92 endpoint: AtprotoSync::GetLatestCommit,
93 params: compact('did')
94 );
95
96 return CommitMeta::fromArray($response->json());
97 }
98
99 /**
100 * Get data blocks needed to prove the existence or non-existence of record
101 *
102 * @see https://docs.bsky.app/docs/api/com-atproto-sync-get-record
103 */
104 #[PublicEndpoint]
105 public function getRecord(string $did, string|BackedEnum $collection, string $rkey): Response
106 {
107 $collection = $collection instanceof BackedEnum ? $collection->value : $collection;
108
109 return $this->atp->client->get(
110 endpoint: AtprotoSync::GetRecord,
111 params: compact('did', 'collection', 'rkey')
112 );
113 }
114
115 /**
116 * List blob CIDs for an account, since some repo revision
117 *
118 * @see https://docs.bsky.app/docs/api/com-atproto-sync-list-blobs
119 */
120 #[PublicEndpoint]
121 public function listBlobs(
122 string $did,
123 ?string $since = null,
124 int $limit = 500,
125 ?string $cursor = null
126 ): ListBlobsResponse {
127 $response = $this->atp->client->get(
128 endpoint: AtprotoSync::ListBlobs,
129 params: compact('did', 'since', 'limit', 'cursor')
130 );
131
132 return ListBlobsResponse::fromArray($response->json());
133 }
134
135 /**
136 * Get data blocks from a given repo, by CID
137 *
138 * @see https://docs.bsky.app/docs/api/com-atproto-sync-get-blocks
139 */
140 #[PublicEndpoint]
141 public function getBlocks(string $did, array $cids): Response
142 {
143 return $this->atp->client->get(
144 endpoint: AtprotoSync::GetBlocks,
145 params: compact('did', 'cids')
146 );
147 }
148
149 /**
150 * Get the hosting status for a repository, on this server
151 *
152 * @see https://docs.bsky.app/docs/api/com-atproto-sync-get-repo-status
153 */
154 #[PublicEndpoint]
155 public function getRepoStatus(string $did): GetRepoStatusResponse
156 {
157 $response = $this->atp->client->get(
158 endpoint: AtprotoSync::GetRepoStatus,
159 params: compact('did')
160 );
161
162 return GetRepoStatusResponse::fromArray($response->json());
163 }
164}