this repo has no description
at main 7.3 kB view raw
1// Generated TypeScript client for AT Protocol records 2// Generated at: 2025-10-03 14:17:15 UTC 3// Lexicons: 2 4 5/** 6 * @example Usage 7 * ```ts 8 * import { AtProtoClient } from "./generated_client.ts"; 9 * 10 * const client = new AtProtoClient( 11 * 'https://api.slices.network', 12 * 'at://did:plc:ovreo3dlfroo4ztkep3kjlle/network.slices.slice/3m25liqjjnh2o' 13 * ); 14 * 15 * // Get records from the run.smallweb.server collection 16 * const records = await client.run.smallweb.server.getRecords(); 17 * 18 * // Get a specific record 19 * const record = await client.run.smallweb.server.getRecord({ 20 * uri: 'at://did:plc:example/run.smallweb.server/3abc123' 21 * }); 22 * 23 * // Get records with filtering and search 24 * const filteredRecords = await client.run.smallweb.server.getRecords({ 25 * where: { 26 * text: { contains: "example search term" } 27 * } 28 * }); 29 * 30 * // Use slice-level methods for cross-collection queries with type safety 31 * const sliceRecords = await client.network.slices.slice.getSliceRecords<RunSmallwebServer>({ 32 * where: { 33 * collection: { eq: 'run.smallweb.server' } 34 * } 35 * }); 36 * 37 * // Search across multiple collections using union types 38 * const multiCollectionRecords = await client.network.slices.slice.getSliceRecords<RunSmallwebServer | AppBskyActorProfile>({ 39 * where: { 40 * collection: { in: ['run.smallweb.server', 'app.bsky.actor.profile'] }, 41 * text: { contains: 'example search term' }, 42 * did: { in: ['did:plc:user1', 'did:plc:user2'] } 43 * }, 44 * limit: 20 45 * }); 46 * 47 * // Serve the records as JSON 48 * Deno.serve(async () => new Response(JSON.stringify(records.records.map(r => r.value)))); 49 * ``` 50 */ 51 52import { 53 type AuthProvider, 54 type BlobRef, 55 type CountRecordsResponse, 56 type GetRecordParams, 57 type GetRecordsResponse, 58 type IndexedRecordFields, 59 type RecordResponse, 60 SlicesClient, 61 type SortField, 62 type WhereCondition, 63} from "@slices/client"; 64import type { OAuthClient } from "@slices/oauth"; 65 66export interface RunSmallwebServer { 67 /** The DID of the server owner */ 68 owner: string; 69 /** The domain name of the server */ 70 domain: string; 71 /** The timestamp when the server was created */ 72 createdAt: string; 73} 74 75export type RunSmallwebServerSortFields = "owner" | "domain" | "createdAt"; 76 77export interface RunSmallwebApp { 78 /** Name of the app */ 79 name: string; 80 /** The server where the app is hosted */ 81 server: string; 82 /** The URL of the app */ 83 url: string; 84 /** The DID of the app owner */ 85 owner: string; 86 /** The timestamp when the app was created */ 87 createdAt: string; 88} 89 90export type RunSmallwebAppSortFields = 91 | "name" 92 | "server" 93 | "url" 94 | "owner" 95 | "createdAt"; 96 97class ServerSmallwebRunClient { 98 private readonly client: SlicesClient; 99 100 constructor(client: SlicesClient) { 101 this.client = client; 102 } 103 104 async getRecords( 105 params?: { 106 limit?: number; 107 cursor?: string; 108 where?: { 109 [K in RunSmallwebServerSortFields | IndexedRecordFields]?: 110 WhereCondition; 111 }; 112 orWhere?: { 113 [K in RunSmallwebServerSortFields | IndexedRecordFields]?: 114 WhereCondition; 115 }; 116 sortBy?: SortField<RunSmallwebServerSortFields>[]; 117 }, 118 ): Promise<GetRecordsResponse<RunSmallwebServer>> { 119 return await this.client.getRecords("run.smallweb.server", params); 120 } 121 122 async getRecord( 123 params: GetRecordParams, 124 ): Promise<RecordResponse<RunSmallwebServer>> { 125 return await this.client.getRecord("run.smallweb.server", params); 126 } 127 128 async countRecords( 129 params?: { 130 limit?: number; 131 cursor?: string; 132 where?: { 133 [K in RunSmallwebServerSortFields | IndexedRecordFields]?: 134 WhereCondition; 135 }; 136 orWhere?: { 137 [K in RunSmallwebServerSortFields | IndexedRecordFields]?: 138 WhereCondition; 139 }; 140 sortBy?: SortField<RunSmallwebServerSortFields>[]; 141 }, 142 ): Promise<CountRecordsResponse> { 143 return await this.client.countRecords("run.smallweb.server", params); 144 } 145 146 async createRecord( 147 record: RunSmallwebServer, 148 useSelfRkey?: boolean, 149 ): Promise<{ uri: string; cid: string }> { 150 return await this.client.createRecord( 151 "run.smallweb.server", 152 record, 153 useSelfRkey, 154 ); 155 } 156 157 async updateRecord( 158 rkey: string, 159 record: RunSmallwebServer, 160 ): Promise<{ uri: string; cid: string }> { 161 return await this.client.updateRecord("run.smallweb.server", rkey, record); 162 } 163 164 async deleteRecord(rkey: string): Promise<void> { 165 return await this.client.deleteRecord("run.smallweb.server", rkey); 166 } 167} 168 169class AppSmallwebRunClient { 170 private readonly client: SlicesClient; 171 172 constructor(client: SlicesClient) { 173 this.client = client; 174 } 175 176 async getRecords( 177 params?: { 178 limit?: number; 179 cursor?: string; 180 where?: { 181 [K in RunSmallwebAppSortFields | IndexedRecordFields]?: WhereCondition; 182 }; 183 orWhere?: { 184 [K in RunSmallwebAppSortFields | IndexedRecordFields]?: WhereCondition; 185 }; 186 sortBy?: SortField<RunSmallwebAppSortFields>[]; 187 }, 188 ): Promise<GetRecordsResponse<RunSmallwebApp>> { 189 return await this.client.getRecords("run.smallweb.app", params); 190 } 191 192 async getRecord( 193 params: GetRecordParams, 194 ): Promise<RecordResponse<RunSmallwebApp>> { 195 return await this.client.getRecord("run.smallweb.app", params); 196 } 197 198 async countRecords( 199 params?: { 200 limit?: number; 201 cursor?: string; 202 where?: { 203 [K in RunSmallwebAppSortFields | IndexedRecordFields]?: WhereCondition; 204 }; 205 orWhere?: { 206 [K in RunSmallwebAppSortFields | IndexedRecordFields]?: WhereCondition; 207 }; 208 sortBy?: SortField<RunSmallwebAppSortFields>[]; 209 }, 210 ): Promise<CountRecordsResponse> { 211 return await this.client.countRecords("run.smallweb.app", params); 212 } 213 214 async createRecord( 215 record: RunSmallwebApp, 216 useSelfRkey?: boolean, 217 ): Promise<{ uri: string; cid: string }> { 218 return await this.client.createRecord( 219 "run.smallweb.app", 220 record, 221 useSelfRkey, 222 ); 223 } 224 225 async updateRecord( 226 rkey: string, 227 record: RunSmallwebApp, 228 ): Promise<{ uri: string; cid: string }> { 229 return await this.client.updateRecord("run.smallweb.app", rkey, record); 230 } 231 232 async deleteRecord(rkey: string): Promise<void> { 233 return await this.client.deleteRecord("run.smallweb.app", rkey); 234 } 235} 236 237class SmallwebRunClient { 238 readonly server: ServerSmallwebRunClient; 239 readonly app: AppSmallwebRunClient; 240 private readonly client: SlicesClient; 241 242 constructor(client: SlicesClient) { 243 this.client = client; 244 this.server = new ServerSmallwebRunClient(client); 245 this.app = new AppSmallwebRunClient(client); 246 } 247} 248 249class RunClient { 250 readonly smallweb: SmallwebRunClient; 251 private readonly client: SlicesClient; 252 253 constructor(client: SlicesClient) { 254 this.client = client; 255 this.smallweb = new SmallwebRunClient(client); 256 } 257} 258 259export class AtProtoClient extends SlicesClient { 260 readonly run: RunClient; 261 readonly oauth?: OAuthClient | AuthProvider; 262 263 constructor( 264 baseUrl: string, 265 sliceUri: string, 266 oauthClient?: OAuthClient | AuthProvider, 267 ) { 268 super(baseUrl, sliceUri, oauthClient); 269 this.run = new RunClient(this); 270 this.oauth = oauthClient; 271 } 272}