{"version":3,"sources":["../src/core/node.ts","../src/core/edge.ts","../src/ontology/types.ts"],"names":["assertSchemaKeysAreFree","RESERVED_NODE_KEYS","assertClaimAxisSafe","assertJsonValue","NODE_TYPE_BRAND","z","validateSchemaKeys","RESERVED_EDGE_KEYS","validateTargetMapEntries","normalizeTargetMap","EDGE_TYPE_BRAND"],"mappings":";;;;;;;AAoCA,SAAS,kBAAA,CACP,QACA,IAAA,EACM;AACN,EAAAA,yCAAA,CAAwB,MAAA,EAAQ,IAAA,EAAM,MAAA,EAAQC,oCAAkB,CAAA;AAClE;AAgBO,SAAS,UAAA,CAGd,MAAS,OAAA,EAA+C;AAGxD,EAAAC,qCAAA,CAAoB,MAAM,WAAW,CAAA;AACrC,EAAA,kBAAA,CAAmB,OAAA,CAAQ,QAAQ,IAAI,CAAA;AACvC,EAAA,IAAI,OAAA,CAAQ,gBAAgB,MAAA,EAAW;AACrC,IAAAC,iCAAA,CAAgB,OAAA,CAAQ,WAAA,EAAa,aAAA,EAAe,CAAA,MAAA,EAAS,IAAI,CAAA,CAAA,CAAG,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,OAAO,MAAA,CAAO;AAAA,IACnB,CAACC,iCAAe,GAAG,IAAA;AAAA,IACnB,IAAA,EAAM,IAAA;AAAA,IACN,QAAQ,OAAA,CAAQ,MAAA;AAAA,IAChB,aAAa,OAAA,CAAQ,WAAA;AAAA,IACrB,aAAa,OAAA,CAAQ;AAAA,GACtB,CAAA;AACH;AC1BA,IAAM,YAAA,GAAeC,KAAA,CAAE,MAAA,CAAO,EAAE,CAAA;AAOhC,SAASC,mBAAAA,CACP,QACA,IAAA,EACM;AACN,EAAAN,yCAAA,CAAwB,MAAA,EAAQ,IAAA,EAAM,MAAA,EAAQO,oCAAkB,CAAA;AAClE;AAoEO,SAAS,UAAA,CAMd,MACA,OAAA,EACqD;AACrD,EAAA,MAAM,MAAA,GAAS,SAAS,MAAA,IAAU,YAAA;AAClC,EAAAD,mBAAAA,CAAmB,QAAQ,IAAI,CAAA;AAC/B,EAAA,IAAI,OAAA,EAAS,gBAAgB,MAAA,EAAW;AACtC,IAAAH,iCAAA,CAAgB,OAAA,CAAQ,WAAA,EAAa,aAAA,EAAe,CAAA,MAAA,EAAS,IAAI,CAAA,CAAA,CAAG,CAAA;AAAA,EACtE;AAEA,EAAA,IAAI,aAA6B,OAAA,EAAS,EAAA;AAC1C,EAAA,IAAI,OAAA,EAAS,OAAO,MAAA,IAAa,CAAC,MAAM,OAAA,CAAQ,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC3D,IAAAK,0CAAA,CAAyB,IAAA,EAAM,OAAA,CAAQ,IAAA,EAAM,OAAA,CAAQ,EAAE,CAAA;AACvD,IAAA,UAAA,GAAaC,oCAAA,CAAmB,QAAQ,EAAE,CAAA;AAAA,EAC5C;AAEA,EAAA,OAAO,OAAO,MAAA,CAAO;AAAA,IACnB,CAACC,iCAAe,GAAG,IAAA;AAAA,IACnB,IAAA,EAAM,IAAA;AAAA,IACN,MAAA;AAAA,IACA,aAAa,OAAA,EAAS,WAAA;AAAA,IACtB,aAAa,OAAA,EAAS,WAAA;AAAA,IACtB,MAAM,OAAA,EAAS,IAAA;AAAA,IACf,EAAA,EAAI;AAAA,GACL,CAAA;AACH;;;ACzJO,IAAM,eAAA,GAAkB;AA+ExB,SAAS,WAAW,KAAA,EAAmC;AAC5D,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,eAAA,IAAmB,KAAA,IAClB,KAAA,CAAkC,eAAe,CAAA,KAAM,IAAA;AAE5D;AAKO,SAAS,YACd,SAAA,EACQ;AACR,EAAA,IAAI,OAAO,cAAc,QAAA,EAAU;AACjC,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,SAAA,CAAU,IAAA;AACnB","file":"chunk-ICOTLZBV.cjs","sourcesContent":["import { type z } from \"zod\";\n\nimport { assertClaimAxisSafe } from \"../store/claims/axis\";\nimport {\n  assertSchemaKeysAreFree,\n  RESERVED_NODE_KEYS,\n} from \"../store/reserved-keys\";\nimport { assertJsonValue } from \"./json-value\";\nimport { type KindAnnotations, NODE_TYPE_BRAND, type NodeType } from \"./types\";\n\n// ============================================================\n// Node Factory Options\n// ============================================================\n\n/**\n * Options for defining a node type.\n */\nexport type DefineNodeOptions<S extends z.ZodObject<z.ZodRawShape>> = Readonly<{\n  /** Zod schema for node properties */\n  schema: S;\n  /** Optional description for documentation */\n  description?: string;\n  /**\n   * Consumer-owned structured annotations for the kind.\n   *\n   * Stored in the canonical schema and **participates in schema hashing** —\n   * any change bumps the schema version and shows up as a `safe`-severity\n   * diff in `getSchemaChanges`. See `KindAnnotations` for the contract.\n   */\n  annotations?: KindAnnotations;\n}>;\n\n// ============================================================\n// Node Factory\n// ============================================================\n\nfunction validateSchemaKeys(\n  schema: z.ZodObject<z.ZodRawShape>,\n  name: string,\n): void {\n  assertSchemaKeysAreFree(\"Node\", name, schema, RESERVED_NODE_KEYS);\n}\n\n/**\n * Creates a node type definition.\n *\n * @example\n * ```typescript\n * const Person = defineNode(\"Person\", {\n *   schema: z.object({\n *     fullName: z.string().min(1),\n *     email: z.string().email().optional(),\n *   }),\n *   description: \"A person in the system\",\n * });\n * ```\n */\nexport function defineNode<\n  K extends string,\n  S extends z.ZodObject<z.ZodRawShape>,\n>(name: K, options: DefineNodeOptions<S>): NodeType<K, S> {\n  // A kind name is a claim axis, so it may not contain the code point reserved\n  // for building the axes that are not kinds.\n  assertClaimAxisSafe(name, \"Node kind\");\n  validateSchemaKeys(options.schema, name);\n  if (options.annotations !== undefined) {\n    assertJsonValue(options.annotations, \"annotations\", `Node \"${name}\"`);\n  }\n\n  return Object.freeze({\n    [NODE_TYPE_BRAND]: true as const,\n    kind: name,\n    schema: options.schema,\n    description: options.description,\n    annotations: options.annotations,\n  });\n}\n","import { z } from \"zod\";\n\nimport {\n  assertSchemaKeysAreFree,\n  RESERVED_EDGE_KEYS,\n} from \"../store/reserved-keys\";\nimport { normalizeTargetMap, validateTargetMapEntries } from \"./edge-endpoints\";\nimport { assertJsonValue } from \"./json-value\";\nimport {\n  EDGE_TYPE_BRAND,\n  type EdgeTargets,\n  type EdgeType,\n  type KindAnnotations,\n  type NodeType,\n} from \"./types\";\n\n// ============================================================\n// Edge Factory Options\n// ============================================================\n\n/**\n * Options for defining an edge type.\n */\nexport type DefineEdgeOptions<\n  S extends z.ZodObject<z.ZodRawShape>,\n  From extends readonly NodeType[] | undefined = undefined,\n  To extends EdgeTargets | undefined = undefined,\n> = Readonly<{\n  /** Zod schema for edge properties (defaults to empty object) */\n  schema?: S;\n  /** Optional description for documentation */\n  description?: string;\n  /**\n   * Consumer-owned structured annotations for the kind.\n   *\n   * Stored in the canonical schema and **participates in schema hashing** —\n   * any change bumps the schema version and shows up as a `safe`-severity\n   * diff in `getSchemaChanges`. See `KindAnnotations` for the contract.\n   */\n  annotations?: KindAnnotations;\n  /** Node types that can be the source of this edge (domain constraint) */\n  from?: From;\n  /** Node types or source-to-target mapping for this edge (range constraint) */\n  to?: To;\n}>;\n\n// ============================================================\n// Empty Schema\n// ============================================================\n\nconst EMPTY_SCHEMA = z.object({});\ntype EmptySchema = typeof EMPTY_SCHEMA;\n\n// ============================================================\n// Edge Factory\n// ============================================================\n\nfunction validateSchemaKeys(\n  schema: z.ZodObject<z.ZodRawShape>,\n  name: string,\n): void {\n  assertSchemaKeysAreFree(\"Edge\", name, schema, RESERVED_EDGE_KEYS);\n}\n\n/**\n * Creates an edge type definition.\n *\n * @example\n * ```typescript\n * // Edge with no properties\n * const hasEpisode = defineEdge(\"hasEpisode\");\n *\n * // Edge with properties\n * const employedAt = defineEdge(\"employedAt\", {\n *   schema: z.object({\n *     isPrimary: z.boolean().default(true),\n *     startedAt: z.date(),\n *   }),\n *   description: \"Employment relationship\",\n * });\n *\n * // Edge with domain/range constraints (can be used directly in defineGraph)\n * const worksAt = defineEdge(\"worksAt\", {\n *   schema: z.object({ role: z.string() }),\n *   from: [Person],\n *   to: [Company],\n * });\n *\n * // Edge with source-dependent target constraints\n * const dependsOn = defineEdge(\"dependsOn\", {\n *   from: [Task, Course],\n *   to: {\n *     Task: [Task],\n *     Course: [Course],\n *   },\n * });\n * ```\n */\n// Overload: no options - returns edge without domain/range\nexport function defineEdge<K extends string>(name: K): EdgeType<K, EmptySchema>;\n\n// Overload: options with Cartesian from/to arrays\nexport function defineEdge<\n  K extends string,\n  S extends z.ZodObject<z.ZodRawShape>,\n  From extends readonly NodeType[],\n  To extends readonly NodeType[],\n>(\n  name: K,\n  options: DefineEdgeOptions<S, From, To> & { from: From; to: To },\n): EdgeType<K, S, From, To>;\n\n// Overload: options with source-dependent target mapping\nexport function defineEdge<\n  K extends string,\n  S extends z.ZodObject<z.ZodRawShape>,\n  From extends readonly NodeType[],\n  To extends Record<From[number][\"kind\"], readonly [NodeType, ...NodeType[]]>,\n>(\n  name: K,\n  options: DefineEdgeOptions<S, From, To> & { from: From; to: To },\n): EdgeType<K, S, From, To>;\n\n// Overload: options without from/to - returns edge without domain/range\nexport function defineEdge<\n  K extends string,\n  S extends z.ZodObject<z.ZodRawShape>,\n>(name: K, options: DefineEdgeOptions<S, undefined, undefined>): EdgeType<K, S>;\n\n// Implementation\nexport function defineEdge<\n  K extends string,\n  S extends z.ZodObject<z.ZodRawShape>,\n  From extends readonly NodeType[] | undefined,\n  To extends EdgeTargets | undefined,\n>(\n  name: K,\n  options?: DefineEdgeOptions<S, From, To>,\n): EdgeType<K, S, From, To> | EdgeType<K, EmptySchema> {\n  const schema = options?.schema ?? EMPTY_SCHEMA;\n  validateSchemaKeys(schema, name);\n  if (options?.annotations !== undefined) {\n    assertJsonValue(options.annotations, \"annotations\", `Edge \"${name}\"`);\n  }\n\n  let resolvedTo: To | undefined = options?.to;\n  if (options?.to !== undefined && !Array.isArray(options.to)) {\n    validateTargetMapEntries(name, options.from, options.to);\n    resolvedTo = normalizeTargetMap(options.to) as To;\n  }\n\n  return Object.freeze({\n    [EDGE_TYPE_BRAND]: true as const,\n    kind: name,\n    schema,\n    description: options?.description,\n    annotations: options?.annotations,\n    from: options?.from,\n    to: resolvedTo,\n  }) as EdgeType<K, S, From, To> | EdgeType<K, EmptySchema>;\n}\n","import { type AnyEdgeType, type NodeType } from \"../core/types\";\n\n// ============================================================\n// Brand Key\n// ============================================================\n\n/** Brand key for MetaEdge */\nexport const META_EDGE_BRAND = \"__metaEdge\" as const;\n\n// ============================================================\n// Inference Types\n// ============================================================\n\n/**\n * How a meta-edge affects queries and validation.\n */\nexport type InferenceType =\n  | \"subsumption\" // Query for X includes instances of subclasses\n  | \"hierarchy\" // Enables broader/narrower traversal\n  | \"substitution\" // Can substitute equivalent types\n  | \"constraint\" // Validation rules\n  | \"composition\" // Part-whole navigation\n  | \"association\" // Discovery/recommendation\n  | \"none\"; // No automatic inference\n\n// ============================================================\n// Meta-Edge Properties\n// ============================================================\n\n/**\n * Properties of a meta-edge.\n */\nexport type MetaEdgeProperties = Readonly<{\n  transitive: boolean; // A→B, B→C implies A→C\n  symmetric: boolean; // A→B implies B→A\n  reflexive: boolean; // A→A is always true\n  inverse: string | undefined; // Name of inverse meta-edge\n  inference: InferenceType; // How this affects queries\n  description: string | undefined;\n}>;\n\n// ============================================================\n// Meta-Edge Type\n// ============================================================\n\n/**\n * A meta-edge definition.\n *\n * Meta-edges represent type-level relationships (between kinds),\n * not instance-level relationships (between nodes).\n */\nexport type MetaEdge<K extends string = string> = Readonly<{\n  [META_EDGE_BRAND]: true;\n  name: K;\n  properties: MetaEdgeProperties;\n}>;\n\n// ============================================================\n// Ontology Relation\n// ============================================================\n\n/**\n * A relation in the ontology (instance of meta-edge between types).\n *\n * @example\n * ```typescript\n * // Podcast subClassOf Media\n * subClassOf(Podcast, Media)\n *\n * // Person equivalentTo schema:Person\n * equivalentTo(Person, \"https://schema.org/Person\")\n * ```\n */\nexport type OntologyRelation = Readonly<{\n  metaEdge: MetaEdge;\n  from: NodeType | AnyEdgeType | string; // string for external IRIs\n  to: NodeType | AnyEdgeType | string;\n}>;\n\n// ============================================================\n// Type Guards\n// ============================================================\n\n/**\n * Checks if a value is a MetaEdge.\n */\nexport function isMetaEdge(value: unknown): value is MetaEdge {\n  return (\n    typeof value === \"object\" &&\n    value !== null &&\n    META_EDGE_BRAND in value &&\n    (value as Record<string, unknown>)[META_EDGE_BRAND] === true\n  );\n}\n\n/**\n * Gets the type name from a NodeType, EdgeType, or IRI string.\n */\nexport function getTypeName(\n  typeOrIri: NodeType | AnyEdgeType | string,\n): string {\n  if (typeof typeOrIri === \"string\") {\n    return typeOrIri;\n  }\n  return typeOrIri.kind;\n}\n"]}