| 148 | * Mixedbread implementation of the Store interface |
| 149 | */ |
| 150 | export class MixedbreadStore implements Store { |
| 151 | private client: Mixedbread; |
| 152 | private clientFactory: () => Promise<Mixedbread>; |
| 153 | |
| 154 | constructor(client: Mixedbread, clientFactory: () => Promise<Mixedbread>) { |
| 155 | this.client = client; |
| 156 | this.clientFactory = clientFactory; |
| 157 | } |
| 158 | |
| 159 | async refreshClient(): Promise<void> { |
| 160 | this.client = await this.clientFactory(); |
| 161 | } |
| 162 | |
| 163 | async *listFiles( |
| 164 | storeId: string, |
| 165 | options?: ListFilesOptions, |
| 166 | ): AsyncGenerator<StoreFile> { |
| 167 | let after: string | undefined; |
| 168 | do { |
| 169 | const response = await this.client.stores.files.list(storeId, { |
| 170 | limit: 100, |
| 171 | after, |
| 172 | metadata_filter: options?.pathPrefix |
| 173 | ? { key: "path", operator: "starts_with", value: options.pathPrefix } |
| 174 | : null, |
| 175 | }); |
| 176 | |
| 177 | for (const f of response.data) { |
| 178 | yield { |
| 179 | external_id: f.external_id ?? null, |
| 180 | metadata: (f.metadata || null) as FileMetadata | null, |
| 181 | }; |
| 182 | } |
| 183 | |
| 184 | after = response.pagination?.has_more |
| 185 | ? (response.pagination?.last_cursor ?? undefined) |
| 186 | : undefined; |
| 187 | } while (after); |
| 188 | } |
| 189 | |
| 190 | async uploadFile( |
| 191 | storeId: string, |
| 192 | file: File | ReadableStream, |
| 193 | options: UploadFileOptions, |
| 194 | ): Promise<void> { |
| 195 | await ( |
| 196 | this.client.stores.files.upload as ( |
| 197 | storeIdentifier: string, |
| 198 | file: Uploadable, |
| 199 | body?: { |
| 200 | external_id?: string | null; |
| 201 | overwrite?: boolean; |
| 202 | metadata?: unknown; |
| 203 | }, |
| 204 | ) => Promise<unknown> |
| 205 | )(storeId, file as Uploadable, { |
| 206 | external_id: options.external_id, |
| 207 | overwrite: options.overwrite ?? true, |
nothing calls this directly
no outgoing calls
no test coverage detected