/** * Graph DSL Function * * Provides the main Graph() function for defining entity graphs with * type mappings, relationships, and MDXLD conventions. * * @packageDocumentation */ import type { GraphInput, ParsedGraph, ParsedEntity, ParsedField } from './types.js'; /** * Type aliases that resolve to canonical primitive type names. * * These allow shorthand or alternate spellings to be used in schema * definitions while normalizing to a single canonical type internally. * * | Alias | Resolves To | * |--------|-------------| * | `bool` | `boolean` | */ export declare const TYPE_ALIASES: Record; /** * Parametric types that accept parameters in parentheses. * * | Type | Parameters | Example | * |------|------------|---------| * | `decimal` | precision, scale | `decimal(10,2)` | * | `varchar` | length | `varchar(255)` | * | `char` | length | `char(10)` | * | `fixed` | length | `fixed(256)` | */ export declare const PARAMETRIC_TYPES: Set; /** * Generic types that accept type parameters in angle brackets. * * | Type | Parameters | Example | * |------|------------|---------| * | `map` | key type, value type | `map` | * | `struct` | struct name | `struct
` | * | `enum` | enum name | `enum` | * | `ref` | reference target | `ref` | * | `list` | element type | `list` | */ export declare const GENERIC_TYPES: Set; /** * Split generic type parameters respecting nested angle brackets. * * For example, `"string, list"` splits to `["string", "list"]` * rather than splitting inside the nested `<>`. * * @param content - The content inside the top-level angle brackets * @returns Array of parameter strings, trimmed */ export declare function splitGenericParams(content: string): string[]; /** * Parse a default value string into its typed representation. * * Handles: * - Quoted strings: `"active"` or `'active'` -> `"active"` * - Numbers: `42`, `3.14`, `-1` -> number * - Booleans: `true`, `false` -> boolean * - Null: `null` -> null * - Empty object: `{}` -> {} * - Empty array: `[]` -> [] * - Function calls: `now()`, `gen_random_uuid()` -> { function: "name" } * * @param value - The raw default value string * @returns The parsed default value */ export declare function parseDefaultValue(value: string): unknown; /** * Create a parsed graph schema from entity definitions * * The Graph() function is the main DSL for defining entity graphs. It accepts * a record of entity definitions and returns a fully parsed graph with * resolved type URIs and field relationships. * * ## Entity Definition Formats * * ### Simple Type Mapping * ```ts * const schema = Graph({ * User: 'https://schema.org.ai/Person', * Org: 'https://schema.org.ai/Organization', * }) * ``` * * ### With Properties and Relationships * ```ts * const schema = Graph({ * User: 'https://schema.org.ai/Person', * Post: { * $type: 'https://schema.org.ai/BlogPosting', * title: 'string', * content: 'markdown', * author: '->User.posts', // forward exact with backref * categories: ['~>Category'], // forward fuzzy array * }, * Category: { * $type: 'https://schema.org.ai/Category', * name: 'string', * }, * }) * ``` * * ### With Passthrough Directives * ```ts * const schema = Graph({ * User: { * $type: 'https://schema.org.ai/Person', * $partitionBy: ['tenantId'], // IceType partition key * $index: [['email'], ['createdAt']], // Secondary indexes * $fts: ['bio'], // Full-text search fields * id: 'uuid!', * email: 'string!#', * tenantId: 'string', * }, * }) * * // Access directives * schema.entities.get('User')?.directives * // => { $partitionBy: ['tenantId'], $index: [['email'], ['createdAt']], $fts: ['bio'] } * ``` * * @param input - Entity definitions * @returns Parsed graph with entities and type URIs * * @example Basic usage * ```ts * const schema = Graph({ * User: 'https://schema.org.ai/Person', * Post: { * $type: 'https://schema.org.ai/BlogPosting', * title: 'string', * author: '->User', * }, * }) * * // Access entities * schema.entities.get('Post') * // => { name: 'Post', $type: '...', fields: Map { 'title' => ..., 'author' => ... } } * * // Access type URIs * schema.typeUris.get('User') * // => 'https://schema.org.ai/Person' * ``` */ export declare function Graph(input: GraphInput): ParsedGraph; /** * Get all entity names from a parsed graph */ export declare function getEntityNames(graph: ParsedGraph): string[]; /** * Get all type URIs from a parsed graph */ export declare function getTypeUris(graph: ParsedGraph): Map; /** * Get an entity by name from a parsed graph */ export declare function getEntity(graph: ParsedGraph, name: string): ParsedEntity | undefined; /** * Check if an entity exists in the graph */ export declare function hasEntity(graph: ParsedGraph, name: string): boolean; /** * Get all relationship fields for an entity */ export declare function getRelationshipFields(graph: ParsedGraph, entityName: string): ParsedField[]; /** * Get all entities that reference a given entity */ export declare function getReferencingEntities(graph: ParsedGraph, entityName: string): Array<{ entity: string; field: string; }>; //# sourceMappingURL=graph.d.ts.map