import { a as SchemaValidationResult, i as ProblemPathTypeSegment, l as Schema$1, n as ProblemPathPropertySegment, o as TypeWithProblems, r as ProblemPathSegment, s as _FIXME_, t as ProblemPath } from "./typedefs-LNWlFyVi.js";
import { SetSynchronization, SynchronizationRequest, SynchronizationResult } from "@sanity/descriptors";
import { SanityDocumentLike, Schema, SchemaType, SchemaTypeDefinition, SchemaValidationProblem, SchemaValidationProblemGroup } from "@sanity/types";
import { RequestOptions } from "get-it";
import { SchemaType as SchemaType$1 } from "groq-js";
import { ComponentType, ReactNode } from "react";
/** The scheduler is capable of executing work in different ways. */
type Scheduler = {
  map<T, U>(arr: T[], fn: (val: T) => U): Promise<U[]>;
  forEach<T>(arr: T[], fn: (val: T) => void): Promise<void>;
  forEachIter<T>(iter: Iterable<T>, fn: (val: T) => void): Promise<void>;
};
type RegistryType = 'sanity.schema.registry';
export declare class DescriptorConverter {
  cache: WeakMap<Schema, SetSynchronization<RegistryType>>;
  /**
   * Returns a synchronization object for a schema.
   *
   * This is automatically cached in a weak map.
   */
  get(schema: Schema, opts?: {
    /**
     * If present, this will use an idle scheduler which records duration into this array.
     * This option will be ignored if the `scheduler` option is passed in.
     **/
    pauseDurations?: number[];
    /** An explicit scheduler to do the work. */
    scheduler?: Scheduler;
  }): Promise<SetSynchronization<RegistryType>>;
}
type SchemaSynchronizationRequest = SynchronizationRequest;
type SchemaSynchronizationResult = SynchronizationResult;
/**
 * Returns the next request that should be generated for synchronizing the
 * schema, based on the previous response from the /synchronize endpoint.
 *
 * @param response - The previous response, or `null` if it's the first request.
 * @returns The next request, or `null` if it's been fully synchronized.
 */
export declare function processSchemaSynchronization(sync: SetSynchronization<RegistryType>, response: SchemaSynchronizationResult | null): SchemaSynchronizationRequest | null;
/**
 * Headers applied to each request.
 *
 * @internal
 */
type RequestHeaders = Record<string, string>;
/**
 * Request shape the client passes to the transport. Aliases get-it's
 * `RequestOptions` so the bundled requester and any caller-injected one share a
 * single contract; the client itself only ever sets `url`, `method`, `body`,
 * and `headers`.
 *
 * @internal
 */
type DescriptorRequestOptions = RequestOptions;
/**
 * The transport seam. The client calls this for every request; the return value
 * is the parsed response body. Any requester with the shape
 * `<B>(options): Promise<B>` is structurally assignable, so callers can bring
 * their own transport. Note that a configured get-it v9 instance does NOT
 * qualify on its own — it resolves with the full response object, not the
 * parsed body — so it must be wrapped the way {@link createGetItRequester}
 * wraps it.
 *
 * @internal
 */
type DescriptorRequester = <T>(options: DescriptorRequestOptions) => Promise<T>;
/**
 * A completed phase of an upload, passed to `onPhaseComplete`.
 *
 * @internal
 */
interface UploadSchemaPhase {
  /**
   * - `convert`     — schema → descriptor set. Awaited but CPU-bound; the shared
   *   converter's `WeakMap` cache makes this ~0s on a repeat upload of the same
   *   compiled `Schema` instance.
   * - `claim`       — the claim request (permanent or temporary).
   * - `synchronize` — one synchronize iteration (see `iteration`).
   * - `commit`      — the commit request that pins a permanent claim. Emitted by
   *   the `commit()` thunk returned from `prepareSchemaUpload`, or inline by
   *   `uploadSchema`. Never emitted for a temporary claim.
   * - `total`       — the whole `uploadSchema` call; emitted last, on success
   *   only. `prepareSchemaUpload` does not emit `total` (a standalone caller can
   *   time the awaited promise itself).
   */
  phase: 'convert' | 'claim' | 'synchronize' | 'commit' | 'total';
  /** Elapsed wall-clock time for this phase, in seconds. */
  durationSeconds: number;
  /** Zero-based iteration index. Present only for `phase: 'synchronize'`. */
  iteration?: number;
}
interface BaseUploadSchemaOptions {
  /** Context key the server uses to scope/optimize synchronization, e.g. `studio:<appId>`. */
  contextKey: string;
  /** Headers applied to every request. */
  headers?: RequestHeaders;
  /** Convenience auth applied as `Authorization: Bearer <token>` on every request. */
  token?: string;
  /** Descriptor API version path segment. Default 'v2025-06-01'. */
  apiVersion?: string;
  /** Max synchronize iterations before throwing. Default 5. */
  maxSyncIterations?: number;
  /**
   * Optional observability hook. Invoked once per phase as it completes, with
   * the elapsed wall-clock time for that phase.
   *
   * Fire-and-forget: the return value is ignored and any error it throws is
   * swallowed, so instrumentation can never break or slow an upload.
   */
  onPhaseComplete?: (event: UploadSchemaPhase) => void;
}
/**
 * Transport — provide exactly one of `baseUrl` or `requester`. The mutually
 * exclusive shape makes "both" and "neither" a compile-time error.
 */
type TransportOptions = {
  /** Base URL for the bundled get-it transport. */
  baseUrl: string;
  requester?: never;
} | {
  /** Bring-your-own transport. Use instead of `baseUrl` to control auth, retries, etc. */
  requester: DescriptorRequester;
  baseUrl?: never;
};
/**
 * Options for {@link prepareSchemaUpload}.
 *
 * @internal
 */
type PrepareSchemaUploadOptions = BaseUploadSchemaOptions & TransportOptions & {
  /**
   * Claim lifecycle for the uploaded descriptor — chosen here because the kind
   * of claim is fixed in the `/claim` request and cannot be changed later:
   *
   * - `'permanent'` — claim with `permanent: true`. The response carries a
   *   `commitId` and the descriptor is **not** retained until committed. The
   *   returned `PreparedSchemaUpload` includes a `commit()` thunk to finalize
   *   it (e.g. after a dependent write succeeds). Never calling `commit()`
   *   leaves the claim to expire — nothing is pinned.
   * - `'temporary'` — claim with `permanent: false`. The response carries
   *   `expiresAt`; there is nothing to commit, so no `commit()` thunk is
   *   returned. The descriptor is retained only until the claim expires (or
   *   until pinned by a referencing permanent descriptor — e.g. a manifest
   *   that lists it).
   */
  claim: 'temporary' | 'permanent';
};
/**
 * Options for {@link uploadSchema}.
 *
 * @internal
 */
type UploadSchemaOptions = BaseUploadSchemaOptions & TransportOptions;
/**
 * Result of {@link prepareSchemaUpload}: the synchronized descriptor id and,
 * for a permanent claim, a `commit()` thunk to pin it later.
 *
 * @internal
 */
interface PreparedSchemaUpload {
  /** Content-addressed descriptor id of the synchronized schema. */
  descriptorId: string;
  /**
   * Present only for `claim: 'permanent'`. Finalizes the permanent claim by
   * committing it. Safe to skip: not calling it leaves the claim to expire.
   */
  commit?: () => Promise<void>;
}
/**
 * Convert a Sanity schema to a descriptor set, claim its id, and synchronize
 * until complete — but do **not** commit. For a permanent claim, the returned
 * `commit()` thunk finalizes the claim when the caller is ready (e.g. after a
 * dependent write succeeds); for a temporary claim no thunk is returned. This is
 * the building block `uploadSchema` is built on, exposed for callers that need
 * to control the claim/commit lifecycle.
 *
 * @internal
 */
export declare function prepareSchemaUpload(schema: Schema, options: PrepareSchemaUploadOptions): Promise<PreparedSchemaUpload>;
/**
 * Convert a Sanity schema to a descriptor set and upload it permanently:
 * permanently claim the id, run the synchronization loop until complete, then
 * commit the claim to pin the descriptor. Returns the content-addressed
 * descriptor id.
 *
 * A convenience over {@link prepareSchemaUpload} — it prepares a permanent claim
 * and commits it inline. Callers that need a temporary claim, or that need to
 * commit in a later step, should use `prepareSchemaUpload` directly.
 *
 * @internal
 */
export declare function uploadSchema(schema: Schema, options: UploadSchemaOptions): Promise<string>;
export declare const isActionEnabled: (schemaType: SchemaType, action: string) => boolean;
export declare const DEFAULT_MAX_FIELD_DEPTH = 5;
export declare function resolveSearchConfigForBaseFieldPaths(type: any, maxDepth?: number): any;
/**
 * @internal
 */
export declare function resolveSearchConfig(type: any, maxDepth?: number): any;
export declare const ALL_FIELDS_GROUP_NAME = "all-fields";
export declare function createSchemaFromManifestTypes(schemaDef: {
  name: string;
  types: unknown[];
}): Schema$1;
interface MediaLibraryConfig {
  enabled?: boolean;
  libraryId?: string;
  __internal?: {
    frontendHost?: string;
  };
}
declare const SANITY_WORKSPACE_SCHEMA_ID_PREFIX = "_.schemas";
declare const SANITY_WORKSPACE_SCHEMA_TYPE = "system.schema";
declare const CURRENT_WORKSPACE_SCHEMA_VERSION = "2025-05-01";
type ManifestSerializable = string | number | boolean | {
  [k: string]: ManifestSerializable;
} | ManifestSerializable[];
interface CreateManifest {
  version: number;
  createdAt: string;
  workspaces: ManifestWorkspaceFile[];
  studioVersion: string | null;
}
interface ManifestWorkspaceFile extends Omit<CreateWorkspaceManifest, 'schema' | 'tools'> {
  schema: string;
  tools: string;
}
interface CreateWorkspaceManifest {
  name: string;
  title?: string;
  subtitle?: string;
  basePath: string;
  dataset: string;
  projectId: string;
  mediaLibrary?: MediaLibraryConfig;
  schema: ManifestSchemaType[];
  tools: ManifestTool[];
  /**
   * returns undefined in the case of the icon not being able to be stringified
   */
  icon: string | undefined;
}
interface ManifestSchemaType {
  type: string;
  name: string;
  title?: string;
  deprecated?: {
    reason: string;
  };
  readOnly?: boolean | 'conditional';
  hidden?: boolean | 'conditional';
  validation?: ManifestValidationGroup[];
  fields?: ManifestField[];
  to?: ManifestReferenceMember[];
  of?: ManifestArrayMember[];
  preview?: {
    select: Record<string, string>;
  };
  fieldsets?: ManifestFieldset[];
  options?: Record<string, ManifestSerializable>;
  marks?: {
    annotations?: ManifestArrayMember[];
    decorators?: ManifestTitledValue[];
  };
  lists?: ManifestTitledValue[];
  styles?: ManifestTitledValue[];
}
interface ManifestFieldset {
  name: string;
  title?: string;
  [index: string]: ManifestSerializable | undefined;
}
interface ManifestTitledValue {
  value: string;
  title?: string;
}
type ManifestField = ManifestSchemaType & {
  fieldset?: string;
};
type ManifestArrayMember = Omit<ManifestSchemaType, 'name'> & {
  name?: string;
};
type ManifestReferenceMember = Omit<ManifestSchemaType, 'name'> & {
  name?: string;
};
interface ManifestValidationGroup {
  rules: ManifestValidationRule[];
  message?: string;
  level?: 'error' | 'warning' | 'info';
}
type ManifestValidationRule = {
  flag: string;
  constraint?: ManifestSerializable;
  [index: string]: ManifestSerializable | undefined;
};
interface ManifestTool {
  name: string;
  title: string;
  /**
   * returns undefined in the case of the icon not being able to be stringified
   */
  icon: string | undefined;
  type: string | null;
}
type DefaultWorkspaceSchemaId = `${typeof SANITY_WORKSPACE_SCHEMA_ID_PREFIX}.${string}`;
type PrefixedWorkspaceSchemaId = `${DefaultWorkspaceSchemaId}.${string}`;
type WorkspaceSchemaId = DefaultWorkspaceSchemaId | PrefixedWorkspaceSchemaId;
interface StoredWorkspaceSchema extends SanityDocumentLike {
  _type: typeof SANITY_WORKSPACE_SCHEMA_TYPE;
  _id: WorkspaceSchemaId;
  version: typeof CURRENT_WORKSPACE_SCHEMA_VERSION | undefined;
  tag?: string;
  workspace: {
    name: string;
    title?: string;
  };
  /**
   * The API expects JSON coming in, but will store a string to save on attribute paths.
   * Consumers must use JSON.parse on the value, put we deploy to the API using ManifestSchemaType[]
   */
  schema: string | ManifestSchemaType[];
}
interface ManifestWorkspaceInput {
  name: string;
  title?: string;
  subtitle?: string;
  basePath: string;
  projectId: string;
  dataset: string;
  icon?: ComponentType | ReactNode;
  mediaLibrary?: MediaLibraryConfig;
  schema: Schema;
  tools: ManifestToolInput[];
}
interface ManifestToolInput {
  title: string;
  name: string;
  icon?: ComponentType | ReactNode;
  __internalApplicationType?: string;
}
type IconResolver = (props: {
  icon?: ComponentType | ReactNode;
  title: string;
  subtitle?: string;
}) => string | undefined | Promise<string | undefined>;
export declare function extractCreateWorkspaceManifest(workspace: ManifestWorkspaceInput, iconResolver?: IconResolver): Promise<CreateWorkspaceManifest>;
/**
 * Extracts all serializable properties from userland schema types,
 * so they best-effort can be used as definitions for Schema.compile
 . */
export declare function extractManifestSchemaTypes(schema: Schema): ManifestSchemaType[];
export declare const validForNamesChars = "a-zA-Z0-9_-";
export declare const validForNamesPattern: RegExp;
export declare function getWorkspaceSchemaId(args: {
  workspaceName: string;
  tag?: string;
}): {
  safeBaseId: DefaultWorkspaceSchemaId;
  safeTaggedId: WorkspaceSchemaId;
  idWarning: string | undefined;
};
interface ParsedWorkspaceSchemaId {
  schemaId: string;
  workspace: string;
}
export declare function parseWorkspaceSchemaId(id: string, errors: string[]): ParsedWorkspaceSchemaId | undefined;
export declare function createStoredWorkspaceSchemaPayload(args: {
  workspace: {
    name: string;
    title?: string;
  };
  schema: ManifestSchemaType[];
  tag?: string;
}): Omit<StoredWorkspaceSchema, '_id' | '_type'>;
export declare const builtinTypes: ({
  name: string;
  title: string;
  type: string;
  fieldsets: {
    name: string;
    title: string;
    description: string;
  }[];
  fields: ({
    name: string;
    type: string;
    title: string;
    readOnly: boolean;
    fieldset?: undefined;
    validation?: undefined;
    hidden?: undefined;
  } | {
    name: string;
    type: string;
    title: string;
    fieldset?: undefined;
    readOnly?: undefined;
    validation?: undefined;
    hidden?: undefined;
  } | {
    name: string;
    type: string;
    title: string;
    readOnly: boolean;
    fieldset: string;
    validation: (Rule: import("@sanity/types").Rule) => import("@sanity/types").Rule;
    hidden?: undefined;
  } | {
    name: string;
    type: string;
    readOnly: boolean;
    hidden: boolean;
    fieldset: string;
    title?: undefined;
    validation?: undefined;
  } | {
    name: string;
    type: string;
    title: string;
    readOnly: boolean;
    fieldset: string;
    validation?: undefined;
    hidden?: undefined;
  })[];
  preview: {
    select: {
      title: string;
      path: string;
      mimeType: string;
      size: string;
    };
    prepare(doc: Record<string, any>): {
      title: any;
      subtitle: string;
    };
  };
  orderings: {
    title: string;
    name: string;
    by: {
      field: string;
      direction: string;
    }[];
  }[];
} | {
  title: string;
  name: string;
  type: string;
  fields: {
    name: string;
    type: string;
    title: string;
  }[];
} | {
  name: string;
  title: string;
  type: string;
  fieldsets: {
    name: string;
    title: string;
    description: string;
  }[];
  fields: ({
    name: string;
    type: string;
    title: string;
    readOnly: boolean;
    fieldset?: undefined;
    validation?: undefined;
    hidden?: undefined;
  } | {
    name: string;
    type: string;
    title: string;
    fieldset?: undefined;
    readOnly?: undefined;
    validation?: undefined;
    hidden?: undefined;
  } | {
    name: string;
    type: string;
    title: string;
    readOnly: boolean;
    fieldset: string;
    validation: (Rule: import("@sanity/types").Rule) => import("@sanity/types").Rule;
    hidden?: undefined;
  } | {
    name: string;
    type: string;
    readOnly: boolean;
    hidden: boolean;
    fieldset: string;
    title?: undefined;
    validation?: undefined;
  } | {
    name: string;
    type: string;
    title: string;
    readOnly: boolean;
    fieldset: string;
    validation?: undefined;
    hidden?: undefined;
  })[];
  preview: {
    select: {
      id: string;
      title: string;
      mimeType: string;
      size: string;
      media: string;
    };
    prepare(doc: Partial<import("@sanity/types").SanityDocument>): {
      title: {};
      media: {
        asset: {
          _ref: unknown;
        };
        media?: {} | undefined;
      };
      subtitle: string;
    };
  };
  orderings: {
    title: string;
    name: string;
    by: {
      field: string;
      direction: string;
    }[];
  }[];
} | {
  name: string;
  title: string;
  type: string;
  fields: {
    name: string;
    type: string;
    validation: (Rule: import("@sanity/types").Rule) => import("@sanity/types").Rule;
  }[];
} | {
  name: string;
  title: string;
  type: string;
  fieldsets: {
    name: string;
    title: string;
    options: {
      collapsable: boolean;
    };
  }[];
  fields: ({
    name: string;
    type: string;
    fieldset?: undefined;
    title?: undefined;
    readOnly?: undefined;
  } | {
    name: string;
    title: string;
    type: string;
    fieldset: string;
    readOnly?: undefined;
  } | {
    fieldset?: undefined;
    name: string;
    title: string;
    type: string;
    readOnly: boolean;
  })[];
})[];
interface ExtractSchemaOptions {
  enforceRequiredFields?: boolean;
}
/**
 * Extracts a GROQ-compatible schema from a Sanity schema definition. The extraction happens in three passes:
 *
 * 1. **Dependency analysis & hoisting detection** (`sortByDependencies`): Walks the entire schema to sort
 *    types topologically and identifies inline object fields that are used multiple times (candidates
 *    for "hoisting").
 *
 * 2. **Hoisted type creation**: For any repeated inline fields, we create top-level named type definitions
 *    first, so they exist before being referenced.
 *
 * 3. **Main type conversion**: Processes each schema type in dependency order. When a field was marked for
 *    hoisting, we emit an `inline` reference to the hoisted type instead of duplicating the structure.
 */
export declare function extractSchema(schemaDef: Schema, extractOptions?: ExtractSchemaOptions): SchemaType$1;
/**
 * @internal
 */
export declare function groupProblems(types: SchemaTypeDefinition[]): SchemaValidationProblemGroup[];
/**
 * Ensure that the provided value is a valid Media Library asset aspect that can be safely deployed.
 *
 * @internal
 */
export declare function validateMediaLibraryAssetAspect(maybeAspect: unknown): [isValidMediaLibraryAspect: boolean, validationErrors: SchemaValidationProblem[][]];
declare function validateBlockType(typeDef: any, visitorContext: any): {
  marks: any;
  styles: any;
  name: any;
  of: any;
  _problems: SchemaValidationResult[];
};
declare const typeVisitors: {
  array: (typeDef: any, visitorContext: any) => any;
  object: (typeDef: any, visitorContext: any) => any;
  slug: (typeDef: any, visitorContext: any) => any;
  file: (typeDef: any, visitorContext: any) => any;
  image: (typeDef: any, visitorContext: any) => any;
  block: typeof validateBlockType;
  document: (typeDefinition: any, visitorContext: any) => any;
  reference: (typeDef: any, visitorContext: any) => any;
  crossDatasetReference: (typeDef: any, visitorContext: any) => any;
  globalDocumentReference: (typeDef: any, visitorContext: any) => any;
};
interface Options {
  parentTypes?: _FIXME_[];
  transformTypeVisitors?: (visitors: typeof typeVisitors) => Partial<typeof typeVisitors>;
  transformCommonVisitors?: (visitors: any[]) => any[];
}
/**
 * @internal
 */
export declare function validateSchema(schemaTypes: _FIXME_, { parentTypes, transformTypeVisitors, transformCommonVisitors }?: Options): {
  get(typeName: string): any;
  has(typeName: string): boolean;
  getTypeNames(): string[];
  getTypes(): any[];
  toJSON(): any[];
};
export declare class ValidationError extends Error {
  problems: SchemaValidationProblemGroup[];
  constructor(problems: SchemaValidationProblemGroup[]);
}
export type { CreateManifest, CreateWorkspaceManifest, DefaultWorkspaceSchemaId, DescriptorRequester, _FIXME_ as FIXME, IconResolver, ManifestSchemaType, ManifestWorkspaceFile, ParsedWorkspaceSchemaId, PrepareSchemaUploadOptions, PreparedSchemaUpload, SchemaValidationResult as Problem, SchemaValidationResult as ValidationResult, ProblemPath, ProblemPathPropertySegment, ProblemPathSegment, ProblemPathTypeSegment, SchemaSynchronizationRequest, SchemaSynchronizationResult, StoredWorkspaceSchema, TypeWithProblems, UploadSchemaOptions, UploadSchemaPhase, WorkspaceSchemaId };
//# sourceMappingURL=_internal.d.ts.map