import type { Maybe } from '@takeshape/util';
import type { PropertySchemaV4_0_0, QueryJSONV4_0_0, ReturnShapeV4_0_0, ShapeJSONV4_0_0, ShapeMapV4_0_0 } from '../project-schema/index.ts';
import type { SchemaPath } from '../types/index.ts';
/**
 * This interface describes a parsed `@ref` or `$ref`.
 * The intended usage is to convert a schema with a ref to a RefItem which can then
 * be passed to the various rich utilities in this file.
 */
export type RefItem = {
    typeName: string;
    layerId: string;
    template?: string;
};
/**
 * Adds a schema path, needed when visiting a whole schema to report errors.
 */
export type RefItemWithPath = {
    path: SchemaPath;
} & RefItem;
/**
 * Safely turn a "template" shape reference (`@args`, `args`, `shape`) into a `RefItem`
 *
 * @param context A partial project schema
 * @param refExpression
 * A ref expression might include "template" name and refer to a local or remote
 * shape, `Foo` or `CreateArgs<Foo>` or `CreateArgs<remote:Foo>`.*
 */
export declare function refExpressionToRefItem(refExpression: string): RefItem;
/**
 * Sugar for converting a `refExpression` directly into a shape, without the
 * intermediate `refItem`.
 *
 * @param context A partial project schema
 * @param refExpression
 * A ref expression might include "template" name and refer to a local or remote
 * shape, `Foo` or `CreateArgs<Foo>` or `CreateArgs<remote:Foo>`.
 */
export declare function refExpressionToShape(shapes: ShapeMapV4_0_0, refExpression: string): Maybe<ShapeJSONV4_0_0>;
/**
 * Provided a service name and a referenced type. Supports 2 or 3 part
 * references, e.g., `shopify:my-store:ProductInput` or `my-store:ProductInput`.
 *
 * @returns
 * A 2 member array, where 0 is the service name, 1 is the referenced type.
 */
export declare function splitAtRef(atRef: string): [string, string];
/**
 * Parses and returns a typeName, serviceKey, and potentially a namespace for
 * the type.
 */
export declare function atRefToRefItem(atRef: string, template?: string): RefItem;
/**
 * Given a content schema and project schema, finds a `@ref` or `$ref` and
 * returns a `RefItem` suitable for loading a referenced schema...
 */
export declare function getRef(refSchema: PropertySchemaV4_0_0): Maybe<RefItem>;
export declare function getRefWithPath(refSchema: PropertySchemaV4_0_0, schemaPath?: SchemaPath): Maybe<RefItemWithPath>;
/**
 * Tests for a `@ref` or `$ref` property directly on the passed schema.
 *
 * @param schema Any schema that might could have a ref property.
 */
export declare function hasRefProperty(schema: PropertySchemaV4_0_0): boolean;
/**
 * From a schema with a ref, will return the top-level ref, and potentially
 * a ref item from a nested `items` property.
 */
export declare function getRefOrItemsRef(refSchema: PropertySchemaV4_0_0, schemaPath?: SchemaPath): Maybe<RefItemWithPath>;
/**
 * Turns a `RefItem` into an `@ref`.
 */
export declare function refItemToString(refItem: RefItem): string;
/**
 * Get a Shape referenced by a `RefItem`.
 */
export declare function refItemToShape(shapes: ShapeMapV4_0_0, refItem: RefItem): Maybe<ShapeJSONV4_0_0>;
/**
 * Helper fn to omit `ref` props from the target schema, and then extend it with the source schema.
 */
export declare const omitRefAndExtend: (targetSchema: PropertySchemaV4_0_0, sourceSchema: PropertySchemaV4_0_0) => import("lodash").Omit<PropertySchemaV4_0_0, "@ref" | "$ref"> & PropertySchemaV4_0_0;
/**
 * If there is a $ref, this will insert a content schema from the top level
 * in place of the reference.
 */
export declare function followRef(shapes: ShapeMapV4_0_0, contentSchema: PropertySchemaV4_0_0): PropertySchemaV4_0_0;
/**
 * Returns whether a schema has refs.
 */
export declare function hasRef(contentSchema: PropertySchemaV4_0_0): boolean;
/**
 * Returns whether a schema has refs which can be followed.
 */
export declare function hasResolvableRef(shapes: ShapeMapV4_0_0, contentSchema: PropertySchemaV4_0_0): boolean;
export declare function getArgsReferenceWithPath(argsSchema: PropertySchemaV4_0_0 | QueryJSONV4_0_0, schemaPath?: SchemaPath): Maybe<RefItemWithPath>;
export declare function dereferenceSchema(shapes: ShapeMapV4_0_0, shapeOrFieldSchema: PropertySchemaV4_0_0, schemaPath?: SchemaPath): PropertySchemaV4_0_0;
export type ParsedReturnShape = {
    isArray: boolean;
    template?: string;
    shapeName: string;
    ref?: RefItem;
};
export declare function parseReturnShape(shape: ReturnShapeV4_0_0): ParsedReturnShape;
