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;AAC5B,EAAA,OACE,OAAO,KAAA,KAAU,QAAA,IACjB,KAAA,KAAU,IAAA,IACV,0BAA0B,KAAA,IAC1B,OAAQ,KAAA,CAAkC,sBAAsB,CAAA,KAC9D,QAAA;AAEN;AAMO,SAAS,oBAAoB,MAAA,EAAuC;AACzE,EAAA,IAAI,mBAAA,CAAoB,MAAM,CAAA,EAAG;AAC/B,IAAA,OAAO,OAAO,sBAAsB,CAAA;AAAA,EACtC;AACA,EAAA,OAAO,MAAA;AACT;AAoBO,SAAS,kBACd,KAAA,EACqC;AACrC,EAAA,OAAO,CAAC,EAAA,MAAgB,EAAE,KAAA,EAAO,EAAA,EAAG,CAAA;AACtC","file":"chunk-VPPDQOET.cjs","sourcesContent":["import {\n  type InferenceType,\n  META_EDGE_BRAND,\n  type MetaEdge,\n  type MetaEdgeProperties,\n} from \"../ontology/types\";\n\n// ============================================================\n// Meta-Edge Factory Options\n// ============================================================\n\n/**\n * Options for creating a meta-edge.\n */\nexport type MetaEdgeOptions = Readonly<{\n  /** Whether the relationship is transitive (A→B, B→C implies A→C) */\n  transitive?: boolean;\n  /** Whether the relationship is symmetric (A→B implies B→A) */\n  symmetric?: boolean;\n  /** Whether the relationship is reflexive (A→A is always true) */\n  reflexive?: boolean;\n  /** Name of the inverse meta-edge */\n  inverse?: string;\n  /** How this meta-edge affects queries and validation */\n  inference?: InferenceType;\n  /** Optional description */\n  description?: string;\n}>;\n\n// ============================================================\n// Meta-Edge Factory\n// ============================================================\n\n/**\n * Creates a custom meta-edge definition.\n *\n * @example\n * ```typescript\n * // Custom meta-edge for regulatory relationships\n * const regulatedBy = metaEdge(\"regulatedBy\", {\n *   description: \"Type X is regulated by authority type Y\",\n *   transitive: false,\n *   symmetric: false,\n * });\n * ```\n */\nexport function metaEdge<K extends string>(\n  name: K,\n  options: MetaEdgeOptions = {},\n): MetaEdge<K> {\n  const properties: MetaEdgeProperties = {\n    transitive: options.transitive ?? false,\n    symmetric: options.symmetric ?? false,\n    reflexive: options.reflexive ?? false,\n    inverse: options.inverse,\n    inference: options.inference ?? \"none\",\n    description: options.description,\n  };\n\n  return Object.freeze({\n    [META_EDGE_BRAND]: true as const,\n    name,\n    properties,\n  });\n}\n","/**\n * External reference type for hybrid overlay patterns.\n *\n * Creates a Zod-compatible schema for referencing entities in external\n * data sources (e.g., existing application tables) from TypeGraph nodes.\n */\nimport { z } from \"zod\";\n\n// ============================================================\n// External Reference Metadata Symbol\n// ============================================================\n\n/**\n * Symbol key for storing external table name on the schema.\n * This allows the schema introspector to detect external reference types\n * and extract source information.\n */\nexport const EXTERNAL_REF_TABLE_KEY = \"_externalRefTable\" as const;\n\n// ============================================================\n// External Reference Value Type\n// ============================================================\n\n/**\n * The shape of an external reference value.\n * Contains the source table identifier and the ID of the referenced record.\n */\nexport type ExternalRefValue<T extends string = string> = Readonly<{\n  table: T;\n  id: string;\n}>;\n\n// ============================================================\n// External Reference Schema Type\n// ============================================================\n\n/**\n * A Zod schema for external references with attached table metadata.\n */\nexport type ExternalRefSchema<T extends string = string> = z.ZodType<\n  ExternalRefValue<T>\n> &\n  Readonly<{\n    [EXTERNAL_REF_TABLE_KEY]: T;\n  }>;\n\n// ============================================================\n// External Reference Factory\n// ============================================================\n\n/**\n * Creates a Zod schema for referencing external data sources.\n *\n * Use this when building a hybrid overlay where TypeGraph stores\n * graph relationships and metadata while your existing tables\n * remain the source of truth for entity data.\n *\n * @param table - The identifier for the external table/source (e.g., \"users\", \"documents\")\n * @returns A Zod schema that validates external reference objects\n *\n * @example\n * ```typescript\n * import { defineNode, externalRef, embedding } from \"@nicia-ai/typegraph\";\n *\n * // Reference documents from your existing application database\n * const Document = defineNode(\"Document\", {\n *   schema: z.object({\n *     source: externalRef(\"documents\"),\n *     embedding: embedding(1536).optional(),\n *     extractedTopics: z.array(z.string()).optional(),\n *   }),\n * });\n *\n * // Create a node referencing an external document\n * await store.nodes.Document.create({\n *   source: { table: \"documents\", id: \"doc_abc123\" },\n *   embedding: await generateEmbedding(docContent),\n * });\n *\n * // Query and hydrate with external data\n * const results = await store\n *   .query()\n *   .from(\"Document\", \"d\")\n *   .whereNode(\"d\", (d) => d.embedding.similarTo(query, 10))\n *   .select((ctx) => ctx.d.source)\n *   .execute();\n *\n * // Fetch full data from your app database\n * const externalIds = results.map((r) => r.id);\n * const fullDocs = await appDb.query.documents.findMany({\n *   where: inArray(documents.id, externalIds),\n * });\n * ```\n */\nexport function externalRef<T extends string>(table: T): ExternalRefSchema<T> {\n  if (typeof table !== \"string\" || table.length === 0) {\n    throw new Error(\n      `External reference table must be a non-empty string, got: ${typeof table === \"string\" ? `\"${table}\"` : typeof table}`,\n    );\n  }\n\n  const schema = z.object({\n    table: z.literal(table),\n    id: z.string().min(1, \"External reference ID must be non-empty\"),\n  });\n\n  // Attach table metadata for introspection\n  return Object.assign(schema, {\n    [EXTERNAL_REF_TABLE_KEY]: table,\n  });\n}\n\n// ============================================================\n// Type Guards\n// ============================================================\n\n/**\n * Checks if a value is an external reference schema.\n */\nexport function isExternalRefSchema(\n  value: unknown,\n): value is ExternalRefSchema {\n  return (\n    typeof value === \"object\" &&\n    value !== null &&\n    EXTERNAL_REF_TABLE_KEY in value &&\n    typeof (value as Record<string, unknown>)[EXTERNAL_REF_TABLE_KEY] ===\n      \"string\"\n  );\n}\n\n/**\n * Gets the table name from an external reference schema.\n * Returns undefined if the schema is not an external reference schema.\n */\nexport function getExternalRefTable(schema: z.ZodType): string | undefined {\n  if (isExternalRefSchema(schema)) {\n    return schema[EXTERNAL_REF_TABLE_KEY];\n  }\n  return undefined;\n}\n\n// ============================================================\n// Helper for creating reference values\n// ============================================================\n\n/**\n * Helper function to create a typed external reference value.\n * Useful when you want to avoid repeating the table name.\n *\n * @example\n * ```typescript\n * const docRef = createExternalRef(\"documents\");\n *\n * await store.nodes.Document.create({\n *   source: docRef(\"doc_123\"),\n *   embedding: [...],\n * });\n * ```\n */\nexport function createExternalRef<T extends string>(\n  table: T,\n): (id: string) => ExternalRefValue<T> {\n  return (id: string) => ({ table, id });\n}\n"]}