import {z} from 'zod' export type ListSnapshotsRequest = {skip?: number | undefined, limit?: number | undefined}; export type CreateApiV1NamespacesNamespaceIdentifierSnapshotsListArgs = {namespace_identifier: string, body: ListSnapshotsRequest}; export type CreateApiV1NamespacesNamespaceIdentifierSnapshotsListOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const snapshotType = z.enum(["daily", "pre_delete", "manual"]); export const snapshotStatus = z.enum(["pending", "in_progress", "completed", "partial", "failed", "expired"]); export const clusterTime = z.object({t: z.number().int(), i: z.number().int()}); export const mongoFrontier = z.object({read_concern: z.string().optional(), cluster_time_start: clusterTime.nullable().optional(), cluster_time_end: clusterTime.nullable().optional(), error: z.string().nullable().optional()}); export const shardFrontier = z.object({history_id: z.string().optional(), durable_confirmed_seq: z.number().int().optional(), shipped_wal_highwater: z.number().int().optional(), frontier_seq: z.number().int().optional(), note: z.string().nullable().optional()}); export const vectorFrontier = z.object({capture_mode: z.string().optional(), shards_start: z.record(z.string(), shardFrontier).optional(), shards_end: z.record(z.string(), shardFrontier).optional(), error: z.string().nullable().optional()}); export const objectFrontier = z.object({generation_cutoff: z.number().int().nullable().optional(), last_modified_cutoff: z.string().nullable().optional(), objects_listed: z.number().int().optional()}); export const artifactDigest = z.object({sha256: z.string(), size: z.number().int()}); export const secretVersion = z.object({name: z.string(), version: z.string()}); export const snapshotFrontier = z.object({consistency: z.string().optional(), mongo: mongoFrontier.optional(), vectors: vectorFrontier.optional(), objects: objectFrontier.optional(), config_yaml: z.string().nullable().optional(), config_yaml_error: z.string().nullable().optional(), digests: z.record(z.string(), artifactDigest).optional(), schema_versions: z.record(z.string(), z.union([z.number().int(), z.string()])).optional(), secrets: z.array(secretVersion).optional()}); export const snapshotManifest = z.object({snapshot_id: z.string(), namespace_id: z.string(), namespace_name: z.string(), schema_version: z.number().int().optional(), created_at: z.string(), snapshot_type: z.string(), mongo_collections: z.record(z.string(), z.number().int()).optional(), vector_point_count: z.number().int().optional(), s3_object_count: z.number().int().optional(), s3_total_bytes: z.number().int().optional(), s3_objects_copied: z.boolean().optional(), include_vectors: z.boolean().optional(), vector_shard_key: z.string().nullable().optional(), frontier: snapshotFrontier.nullable().optional()}); export const snapshotCopyOut = z.object({status: z.string(), bucket: z.string().nullable().optional(), objects: z.number().int().optional(), bytes: z.number().int().optional(), mismatched: z.array(z.string()).optional(), error: z.string().nullable().optional()}); export const restoreCollectionOutcome = z.object({collection: z.string(), expected: z.number().int(), restored: z.number().int(), status: z.string(), reason: z.string().nullable().optional()}); export const retrieverParityResult = z.object({retriever_name: z.string(), status: z.string(), reason: z.string().nullable().optional(), probe_inputs: z.record(z.string(), z.unknown()).nullable().optional(), source_top_k: z.array(z.string()).optional(), target_top_k: z.array(z.string()).optional(), overlap: z.number().int().nullable().optional()}); export const restoreReport = z.object({snapshot_id: z.string(), target_namespace_id: z.string(), complete: z.boolean(), collections: z.array(restoreCollectionOutcome).optional(), vector_expected: z.number().int().optional(), vector_restored: z.number().int().optional(), vector_source: z.string().nullable().optional(), vector_status: z.string().optional(), skipped_summary: z.array(z.string()).optional(), retriever_parity: z.array(retrieverParityResult).optional(), restore_point: z.string().nullable().optional(), resolved_seq: z.number().int().nullable().optional(), fork_id: z.string().nullable().optional(), write_gap: z.record(z.string(), z.unknown()).nullable().optional()}); export const snapshotModel = z.object({snapshot_id: z.string().optional(), namespace_id: z.string(), namespace_name: z.string(), internal_id: z.string(), snapshot_type: snapshotType, status: snapshotStatus.optional(), created_at: z.string().nullable().optional(), dispatch_at: z.string().nullable().optional(), completed_at: z.string().nullable().optional(), expires_at: z.string().nullable().optional(), schema_version: z.number().int().optional(), s3_prefix: z.string().optional(), s3_objects_copied: z.boolean().optional(), manifest: snapshotManifest.nullable().optional(), error: z.string().nullable().optional(), task_id: z.string().nullable().optional(), include_vectors: z.boolean().optional(), vector_shard_key: z.string().nullable().optional(), copy_out: snapshotCopyOut.nullable().optional(), imported_from: z.record(z.string(), z.unknown()).nullable().optional(), last_restore: restoreReport.nullable().optional()}); export const listSnapshotsResponse = z.object({results: z.array(snapshotModel), total_count: z.number().int()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List Namespace Snapshots * * POST /v1/namespaces/{namespace_identifier}/snapshots/list */ export const createApiV1NamespacesNamespaceIdentifierSnapshotsList = async (args: CreateApiV1NamespacesNamespaceIdentifierSnapshotsListArgs, options?: CreateApiV1NamespacesNamespaceIdentifierSnapshotsListOptions) => { const {baseUrl = "https://api.mixpeek.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/namespaces/${encodeURIComponent(String(args.namespace_identifier))}/snapshots/list${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(listSnapshotsResponse, await res.json()) };