import { type Maybe } from '@takeshape/util';
import { type SchemaDefaultsOptions } from './builtin-schema.ts';
import type { FieldMapping, ProjectSchemaJSON, PropertySchema, QueryJSON, ServiceConfig, ShapeJSON, ShapeMap, ShapeSchema } from './project-schema/index.ts';
import { type RefItem, type RefItemWithPath, type ServicesContext, type ServicesShapesContext } from './refs.ts';
import { type LatestProjectSchemaWithServices, type LayerSchema, type SchemaPath, type SchemaPropertyName, type SchemaPropertyNode, type SchemaWithArgs, type ServiceMap } from './types/index.ts';
export declare function isBuiltinShape(ref: string): boolean;
export declare function isBuiltinQuery(name: string): boolean;
export declare function isBuiltinMutation(name: string): boolean;
export declare function isBuiltinType(projectSchema: ProjectSchemaJSON, refSchema: PropertySchema): boolean;
export declare const schemaMetadataKeys: readonly ["$comment", "title", "description", "@l10n", "@deprecationReason", "@tag", "@tags", "@syncLocaleStructure", "@sensitive"];
export declare const commonSchemaKeys: readonly ["type", "default", "readOnly", "$comment", "title", "description", "@l10n", "@deprecationReason", "@tag", "@tags", "@syncLocaleStructure", "@sensitive"];
export declare const scalarSchemaKeys: readonly ["type", "default", "readOnly", "$comment", "title", "description", "@l10n", "@deprecationReason", "@tag", "@tags", "@syncLocaleStructure", "@sensitive", "format", "oneOf", "multipleOf", "maximum", "exclusiveMaximum", "minimum", "exclusiveMinimum", "maxLength", "minLength", "pattern"];
export declare const objectSchemaKeys: readonly ["type", "default", "readOnly", "$comment", "title", "description", "@l10n", "@deprecationReason", "@tag", "@tags", "@syncLocaleStructure", "@sensitive", "properties", "required"];
export declare const arraySchemaKeys: readonly ["type", "default", "readOnly", "$comment", "title", "description", "@l10n", "@deprecationReason", "@tag", "@tags", "@syncLocaleStructure", "@sensitive", "items", "additionalItems", "maxItems", "minItems", "uniqueItems"];
export declare const multipleRelationshipSchemaKeys: string[];
export declare const nonStructuralSchemaKeys: string[];
export declare function getServiceIdFieldName(serviceFieldName: string): string;
export declare function getGeneratorVersion(generator: string): string;
export declare function pathBetween(fromShape: ShapeJSON, toShape: ShapeJSON, projectSchema: ProjectSchemaJSON, depthLimit?: number): string[];
type ShapeModelInfo = Pick<ShapeJSON, 'name' | 'model'>;
export declare function getShapeQueriesAndMutations(shapes: ShapeModelInfo | ShapeModelInfo[]): Pick<ProjectSchemaJSON, 'queries' | 'mutations'>;
export declare function getCommonBuiltInProperties(shape: Pick<ShapeJSON, 'id'>): Record<string, PropertySchema>;
export declare const DEFAULT_ID_FIELD = "id";
export declare function getIdField(obj?: {
    idField?: string;
}): string;
export declare function getModelBuiltInProperties(projectSchema: Partial<Pick<ProjectSchemaJSON, 'apiVersion' | 'workflows'>>, shape: Pick<ShapeJSON, 'id' | 'workflow'>): Record<string, PropertySchema>;
/**
 * Return all the built in property names,
 */
export declare function getBuiltInPropertyNames(profile?: BuiltInPropertiesProfile): Set<string>;
export declare enum BuiltInPropertiesProfile {
    Model = 0,
    Cached = 1,
    None = 2
}
export declare const isBuiltInPropertyName: (name: string, profile?: BuiltInPropertiesProfile) => boolean;
export declare function applyBuiltinPropertiesToShape(projectSchema: ProjectSchemaJSON, shape: ShapeJSON): ShapeJSON;
/**
 * Get all built-in shapes that are depended on by the given project schema.
 * Required built-in shapes are always included.
 */
export declare function getBuiltinsUsed(builtInShapes: ShapeMap, projectSchema: ProjectSchemaJSON): ShapeMap;
export declare function applyDefaultsToSchema<T extends ProjectSchemaJSON>(projectSchema: T, options?: SchemaDefaultsOptions): T;
export declare function getArgsReference(projectSchema: ServicesContext, argsSchema: SchemaWithArgs): Maybe<RefItem>;
export declare function getArgsReferenceWithPath(context: ServicesContext, argsSchema: SchemaWithArgs, schemaPath?: SchemaPath): Maybe<RefItemWithPath>;
export declare function getArgsShapeSchema(context: ServicesShapesContext, argsSchema: SchemaWithArgs): Maybe<ShapeSchema>;
export declare function shapeToPropertySchema(projectSchema: ProjectSchemaJSON, shape: ShapeJSON): PropertySchema;
/**
 * Currently this is not 100% valid JSON schema, but its output can be used with createSchemaValidator
 */
export declare function shapeToJsonSchema(projectSchema: ProjectSchemaJSON, shape: ShapeJSON): {
    definitions: Record<string, PropertySchema>;
    $ref?: string;
    title?: string;
    description?: string;
    default?: any;
    readOnly?: boolean;
    multipleOf?: number;
    maximum?: number;
    exclusiveMaximum?: number;
    minimum?: number;
    exclusiveMinimum?: number;
    maxLength?: import("./project-schema/latest.ts").NonNegativeInteger;
    minLength?: import("./project-schema/latest.ts").NonNegativeIntegerDefault0;
    pattern?: string;
    additionalItems?: PropertySchema;
    items?: PropertySchema;
    maxItems?: import("./project-schema/latest.ts").NonNegativeInteger;
    minItems?: import("./project-schema/latest.ts").NonNegativeIntegerDefault0;
    uniqueItems?: boolean;
    contains?: PropertySchema;
    maxProperties?: import("./project-schema/latest.ts").NonNegativeInteger;
    minProperties?: import("./project-schema/latest.ts").NonNegativeIntegerDefault0;
    required?: import("./project-schema/latest.ts").StringArray;
    additionalProperties?: PropertySchema | false;
    properties?: {
        [k: string]: PropertySchema;
    };
    const?: any;
    enum?: any[];
    type?: import("./project-schema/latest.ts").SimpleTypes | import("./project-schema/latest.ts").SimpleTypes[];
    format?: string;
    contentMediaType?: string;
    contentEncoding?: string;
    allOf?: import("./project-schema/latest.ts").SchemaArray;
    discriminator?: {
        propertyName?: string;
        [k: string]: any;
    };
    oneOf?: import("./project-schema/latest.ts").SchemaArray;
    extends?: import("./project-schema/latest.ts").ObjectOrRefArray;
    '@backreference'?: import("./project-schema/latest.ts").BackReference;
    '@input'?: PropertySchema;
    '@output'?: PropertySchema;
    '@syncLocaleStructure'?: boolean;
    '@sensitive'?: boolean;
    '@draftjs'?: boolean;
    '@l10n'?: boolean;
    '@key'?: string;
    '@workflow'?: string;
    '@mapping'?: FieldMapping;
    '@tag'?: string;
    '@tags'?: string[];
    '@deprecationReason'?: string;
    '@args'?: import("./project-schema/latest.ts").Args;
    '@resolver'?: import("./project-schema/latest.ts").Resolver;
    '@dependencies'?: import("./project-schema/latest.ts").Dependencies;
    '@ref'?: import("./project-schema/latest.ts").Ref;
    '@derivedFrom'?: string;
    '@indexed'?: import("./project-schema/latest.ts").Indexed;
    '@graphql'?: import("./project-schema/latest.ts").GraphQLConfig;
    $id: string;
};
export declare function projectSchemaToJSONSchema(projectSchema: ProjectSchemaJSON): {
    definitions: Record<string, PropertySchema>;
};
export declare function getShapeDependencies(projectSchema: ProjectSchemaJSON, shape: ShapeJSON, predicate?: (propSchema: PropertySchema) => boolean): string[];
type GetRelevantShapesParams = {
    shapeNames?: string[];
    shapeIds?: string[];
    byId?: boolean;
    includeDependencies?: boolean;
};
export declare function getRelevantShapes(projectSchema: ProjectSchemaJSON, params: GetRelevantShapesParams): ShapeMap;
/**
 * Visitor callback return false to stop iterating
 */
export type PropertyVisitorCallback = ((schema: PropertySchema, path: SchemaPath) => boolean) | ((schema: PropertySchema, path: SchemaPath) => void);
export declare function visitSchemaProperties(root: PropertySchema, path: SchemaPath, callback: PropertyVisitorCallback): void;
export declare function visitShapeProperties(shapes: ShapeMap, callback: PropertyVisitorCallback): void;
export type RefPredicate = (ref: RefItemWithPath) => boolean;
/**
 * Walk through a `ProjectSchemaJSON` and collect all the `ref`s.
 */
export declare function getAllRefsInShapes(projectSchema: ServicesShapesContext, predicate?: RefPredicate): RefItemWithPath[];
export declare function getRefsInAgents(context: Pick<ProjectSchemaJSON, 'services' | 'agents'>, predicate?: RefPredicate): RefItemWithPath[];
/**
 * Get all refs
 */
export declare function getAllRefsInQuery(projectSchema: ServicesShapesContext, queryPath: string[], query: QueryJSON, predicate?: (ref: RefItemWithPath) => boolean): RefItemWithPath[];
/**
 * Collect refs from `queries` or `mutations`.
 */
export declare function getAllRefsInQueries(projectSchema: Pick<ProjectSchemaJSON, 'queries' | 'mutations' | 'shapes' | 'services'>, rootPropertyName: 'queries' | 'mutations', predicate?: RefPredicate): RefItemWithPath[];
/**
 * Get all refs in a ProjectSchemaJSON
 * @param predicate return true to include the ref in
 */
export declare function getAllRefs(projectSchema: Pick<ProjectSchemaJSON, 'queries' | 'mutations' | 'shapes' | 'services' | 'agents'>, predicate?: RefPredicate): RefItemWithPath[];
/**
 * Get all valid refs in a ProjectSchemaJSON
 * @param predicate return true to include the ref in
 */
export declare function getAllValidRefs(projectSchema: Pick<ProjectSchemaJSON, 'queries' | 'mutations' | 'shapes' | 'services'>, predicate?: RefPredicate): RefItemWithPath[];
export declare function splitMapping(mapping: string): string[];
export declare function findMapping(schema: PropertySchema, predicate: (mappingStr: string) => boolean): string | undefined;
export declare function getFirstMapping(schema: PropertySchema): string | undefined;
/**
 * Find key for use storing data in ShapeDB or API Indexing this allows renaming of properties without db migration
 * Mapping must be using the shapedb service id
 * @param schema
 */
export declare function getStorageKey(schema: PropertySchema): string | undefined;
export declare function emptySchema(projectId: string): ProjectSchemaJSON;
export declare function createLayerSchema(partialSchema?: Partial<LayerSchema>): LayerSchema;
export declare function getShapesById(projectSchema: ProjectSchemaJSON): ShapeMap;
/**
 * Walk through the project schema and return an array of all
 * referenced shape names that are in a service namespace.
 *
 * @param projectSchema A V3 project schema.
 *
 * @returns A `string` array with all the shapes that are in namespaces.
 */
export declare function getAllNamespaceShapes(projectSchema: ProjectSchemaJSON): string[];
/**
 * Returns a list of all shape names in a service namespace, excluding any
 * that have been set directly in the project schema
 *
 * @todo It's unsound to discard dependencies in this way, should avoid
 *       collisions with aliases or similar any remote shape that collides,
 *       e.g., Shopify_Product -> Shopify_Product_2
 *
 * @param projectSchema A V3 project schema with remote service configs.
 *
 * @returns A `Set` of shape names.
 */
export declare function getNamespacedShapeNameList(projectSchema: LatestProjectSchemaWithServices): Set<string>;
/**
 * Filter the service map to return only services passing the GraphQL Service
 * typeguard.
 *
 * @param serviceMap A service map.
 *
 * @returns A new map with the filtered list of services
 */
export declare function filterGraphQLServiceMap(serviceMap: ServiceMap): Map<string, ServiceConfig>;
/**
 * Creates a schema property list chainable fn, allowing you to manipulate and
 * iterate the properties in a schema.
 */
export declare const createSchemaPropertyList: import("lodash").CurriedFunction2<ServicesShapesContext, PropertySchema | ShapeJSON, {
    _propertyIterator: Map<string, PropertySchema>;
    orderBy: (iteratees?: ((n: SchemaPropertyNode) => string)[], orders?: ("asc" | "desc")[]) => /*elided*/ any;
    sortWith: (comparator?: (a: SchemaPropertyNode, b: SchemaPropertyNode) => number) => /*elided*/ any;
    sortByNamesWithList: (comparatorArray?: string[]) => /*elided*/ any;
    filterBy: (predicate: (n: SchemaPropertyNode) => boolean) => /*elided*/ any;
    forEach: (iteratee: (n: SchemaPropertyNode) => void) => /*elided*/ any;
    getNodes: () => SchemaPropertyNode[];
    getObject: () => Record<string, PropertySchema>;
    getNames: () => SchemaPropertyName[];
    getValues: () => PropertySchema[];
}>;
declare class SchemaPropertyAccessor {
    private readonly schema;
    private readonly properties;
    private readonly entries;
    constructor(context: ServicesShapesContext, shapeOrSchema: PropertySchema | ShapeJSON);
    getValue(propertyName: SchemaPropertyName): Maybe<PropertySchema>;
    findValue(predicate: (n: SchemaPropertyNode) => boolean): Maybe<PropertySchema>;
    findName(predicate: (n: SchemaPropertyNode) => boolean): Maybe<SchemaPropertyName>;
    getKey(propertyName: SchemaPropertyName): Maybe<string>;
}
export type { SchemaPropertyAccessor };
/**
 * Creates a schema property accessor, allowing you to safely access schema
 * properties.
 */
export declare const createSchemaPropertyAccessor: import("lodash").CurriedFunction2<ServicesShapesContext, PropertySchema | ShapeJSON, SchemaPropertyAccessor>;
export type QueryMutationSlice = Pick<ProjectSchemaJSON, 'queries' | 'mutations'>;
/**
 * Find the query in the schema that corresponds to the given shape and resolver.
 */
export declare const findQueryByShape: (projectSchema: QueryMutationSlice, shapeName: string, resolver: string) => string | undefined;
/**
 * Find the query in the schema that corresponds to the given shape and resolver.
 */
export declare const findMutationByShape: (projectSchema: QueryMutationSlice, shapeName: string, resolver: string) => string | undefined;
/**
 * Find the query in the schema that corresponds to the given shape and resolver.
 * Throw an error if that query does not exist
 */
export declare const ensureQueryByShape: (projectSchema: QueryMutationSlice, shapeName: string, resolver: string) => string;
/**
 * Find the mutation in the schema that corresponds to the given shape and resolver.
 * Throw an error if that mutation does not exist
 */
export declare const ensureMutationByShape: (projectSchema: QueryMutationSlice, shapeName: string, resolver: string) => string;
export type ResolverWithDefaultMutation = 'shapedb:create' | 'shapedb:update' | 'shapedb:delete' | 'shapedb:duplicate';
/**
 * Find the query in the schema that corresponds to the given shape and resolver.
 */
export declare const getDefaultMutationName: (shapeName: string, resolver: ResolverWithDefaultMutation) => string;
export declare function createShape(name: string, schema: ShapeSchema, rest?: Partial<ShapeJSON>): ShapeJSON;
export declare function queryToPropertySchema(projectSchema: ProjectSchemaJSON, query: QueryJSON): PropertySchema;
export declare function getQueriesShape(projectSchema: ProjectSchemaJSON, operation: 'query' | 'mutation'): ShapeJSON;
/**
 * Return true if `schemaWithRef` is a ref to a shape named `shapeName`
 */
export declare function schemaMatchesShapeName(workingCopy: ProjectSchemaJSON, propertySchema: PropertySchema, shapeName: string): boolean;
/**
 * Return true if `shape` has a property that is an array of refs to `shapeName`
 */
export declare const shapeHasArrayPropOfShape: (projectSchema: ProjectSchemaJSON, shape: ShapeJSON, shapeName: string) => boolean;
export declare const getQueryMapName: (type: "query" | "mutation") => "queries" | "mutations";
