import { z } from "zod"; /** * Symbol for storing fieldFrom metadata on Zod schemas */ export declare const FIELD_FROM_METADATA: unique symbol; /** * Symbol for storing userContext metadata on Zod schemas */ export declare const USER_CONTEXT_METADATA: unique symbol; /** * Symbol for storing organizationContext metadata on Zod schemas */ export declare const ORGANIZATION_CONTEXT_METADATA: unique symbol; /** * Metadata stored on fieldFrom Zod schemas */ export interface FieldFromMetadata { /** Name of the function that provides options for this field */ functionName: string; } /** * Type for a Zod string with fieldFrom metadata */ export type FieldFromString = z.ZodString & { [FIELD_FROM_METADATA]: FieldFromMetadata; }; /** * Create a string field that gets its options from another function. * * The referenced function should return `{ value: string, label: string }[]`. * - If the function has empty inputs `z.object({})`, it's treated as **bulk** (all options fetched at once) * - If the function has a `query` input, it's treated as **autocomplete** (options searched) * * @param functionName - Name of the function that provides options * * @example * ```ts * defineOntology({ * functions: { * // Bulk options source (empty inputs) * getUserStatuses: { * description: 'Get available user statuses', * access: ['admin'], * entities: [], * inputs: z.object({}), * outputs: z.array(z.object({ value: z.string(), label: z.string() })), * resolver: './resolvers/options/userStatuses.ts', * }, * * // Autocomplete source (has query input) * searchTeams: { * description: 'Search for teams', * access: ['admin'], * entities: [], * inputs: z.object({ query: z.string() }), * outputs: z.array(z.object({ value: z.string(), label: z.string() })), * resolver: './resolvers/options/searchTeams.ts', * }, * * // Function using fieldFrom * createUser: { * description: 'Create a user', * access: ['admin'], * entities: ['User'], * inputs: z.object({ * name: z.string(), * status: fieldFrom('getUserStatuses'), * team: fieldFrom('searchTeams'), * }), * resolver: './resolvers/createUser.ts', * }, * }, * }) * ``` */ export declare function fieldFrom(functionName: string): FieldFromString; /** * Check if a Zod schema has fieldFrom metadata */ export declare function hasFieldFromMetadata(schema: unknown): schema is FieldFromString; /** * Extract fieldFrom metadata from a Zod schema */ export declare function getFieldFromMetadata(schema: unknown): FieldFromMetadata | null; /** * Type for a Zod schema with userContext metadata */ export type UserContextSchema = T & { [USER_CONTEXT_METADATA]: true; }; /** * Mark a schema as user context that will be injected at runtime. * * Fields marked with `userContext()` are: * - **Injected**: Populated from `auth()` result's `user` field * - **Hidden**: Not exposed in public API/MCP schemas * - **Type-safe**: Resolver receives typed user object * * @param schema - Zod schema for the user context shape * * @example * ```ts * defineOntology({ * auth: async (req) => { * const user = await verifyToken(req); * return { * groups: user.isAdmin ? ['admin'] : ['user'], * user: { id: user.id, email: user.email } * }; * }, * * functions: { * editPost: { * description: 'Edit a post', * access: ['user', 'admin'], * entities: ['Post'], * inputs: z.object({ * postId: z.string(), * title: z.string(), * currentUser: userContext(z.object({ * id: z.string(), * email: z.string(), * })), * }), * resolver: './resolvers/editPost.ts', * }, * }, * }) * ``` */ export declare function userContext(schema: T): UserContextSchema; /** * Check if a Zod schema has userContext metadata */ export declare function hasUserContextMetadata(schema: unknown): schema is UserContextSchema; /** * Get all userContext field names from a Zod object schema * * Note: Uses zod-utils for bundler compatibility (instanceof fails across module boundaries) */ export declare function getUserContextFields(schema: z.ZodType): string[]; /** * Type for a Zod schema with organizationContext metadata */ export type OrganizationContextSchema = T & { [ORGANIZATION_CONTEXT_METADATA]: true; }; /** * Mark a schema as organization context that will be injected at runtime. * * Fields marked with `organizationContext()` are: * - **Injected**: Populated from `auth()` result's `organization` field * - **Hidden**: Not exposed in public API/MCP schemas * - **Type-safe**: Resolver receives typed organization object * * @param schema - Zod schema for the organization context shape * * @example * ```ts * defineOntology({ * auth: async (req) => { * const orgId = new URL(req.url).searchParams.get('org_id'); * if (!orgId) return { groups: ['public'] }; * * const user = await verifyToken(req); * const org = await db.organizations.findById(orgId); * * // Verify user membership in organization * const isMember = await db.organizationMembers.exists({ userId: user.id, orgId }); * if (!isMember) throw new Error('Not a member of this organization'); * * return { * groups: ['member'], * organization: { id: org.id, name: org.name } * }; * }, * * functions: { * createProject: { * description: 'Create a project in the organization', * access: ['member'], * entities: ['Project'], * inputs: z.object({ * name: z.string(), * description: z.string(), * currentOrg: organizationContext(z.object({ * id: z.string(), * name: z.string(), * })), * }), * resolver: './resolvers/createProject.ts', * }, * }, * }) * ``` */ export declare function organizationContext(schema: T): OrganizationContextSchema; /** * Check if a Zod schema has organizationContext metadata */ export declare function hasOrganizationContextMetadata(schema: unknown): schema is OrganizationContextSchema; /** * Get all organizationContext field names from a Zod object schema * * Note: Uses zod-utils for bundler compatibility (instanceof fails across module boundaries) */ export declare function getOrganizationContextFields(schema: z.ZodType): string[];