import { cB as GraphExtension, aN as TypeGraphError, fS as ErrorCategory, K as KindEntity } from '../types-BynPp5kU.cjs'; export { fa as CURRENT_GRAPH_EXTENSION_VERSION, c0 as ExtensionArrayItemType, c1 as ExtensionArrayProperty, c2 as ExtensionBooleanProperty, c3 as ExtensionEdgeDef, c4 as ExtensionEdgeIndex, i4 as ExtensionEdgeProperties, c5 as ExtensionEmbeddingModifier, c6 as ExtensionEnumProperty, c7 as ExtensionIndex, c8 as ExtensionIndexWhere, c9 as ExtensionNodeDef, ca as ExtensionNodeIndex, cb as ExtensionNumberProperty, cc as ExtensionObjectFieldProperty, i6 as ExtensionObjectOutput, cd as ExtensionObjectProperty, i3 as ExtensionObjectSchema, ce as ExtensionOntologyRelation, i7 as ExtensionPropertyOutput, cg as ExtensionPropertyType, ch as ExtensionSearchableModifier, ci as ExtensionStringProperty, cj as ExtensionUniqueConstraint, ck as ExtensionUniqueWhere, i8 as GRAPH_EXTENSION_TOP_LEVEL_KEYS, i9 as GraphExtensionTopLevelKey, cC as GraphExtensionVersion, gk as LEGACY_GRAPH_EXTENSION_VERSION } from '../types-BynPp5kU.cjs'; import { R as Result } from '../result-DWo6mUVz.cjs'; import 'zod'; /** * Validates and freezes a graph-extension document. * * Authoring entry point — runs validation in **strict** mode: unknown * top-level keys (e.g. `node` instead of `nodes`) and unsupported * string formats (e.g. `"date-time"` with a hyphen instead of * `"datetime"`) fail loudly with `UNKNOWN_DOCUMENT_KEY` / * `UNSUPPORTED_STRING_FORMAT`. The persistence-load path leaves both * checks off so a document committed by a future v1.x writer with * additive fields still parses on an older v1 reader. Callers * accepting raw JSON from an untyped source (e.g. an LLM proposal) * should validate first via `validateGraphExtension` and surface * the structured issues, then pass the validated document here. * * @param input - Document describing additional node kinds, edge * kinds, and ontology relations. Must satisfy the v1 property-type * subset documented in `ExtensionPropertyType`. * * @returns The same document, deeply frozen and shape-checked. * * @throws {GraphExtensionValidationError} when the document violates * the v1 property-type subset, references undeclared kinds, contains * ontology cycles, etc. The thrown error's `details.issues` array * carries every failure with a JSON-pointer path. * @throws {GraphExtensionVersionUnsupportedError} when the document * declares a future major version this library cannot safely decode. * * @example * ```typescript * const extension = defineGraphExtension({ * nodes: { * Paper: { * properties: { * doi: { type: "string" }, * title: { type: "string", searchable: { language: "english" } }, * }, * unique: [{ name: "paper_doi", fields: ["doi"] }], * }, * }, * }); * * const evolved = await store.evolve(extension); * const papers = evolved.getNodeCollectionOrThrow("Paper"); * ``` */ declare function defineGraphExtension(input: T): T & GraphExtension; /** * Errors raised across the graph-extension surface. * * Two flavours: * * - **Validation issues** (`GraphExtensionValidationError` + * `GraphExtensionIssue` / `GraphExtensionIssueCode`) — produced by * `validateGraphExtension`. The issue list batches every failure * with a JSON-pointer `path` so a UI can highlight every offending * field at once. * - **Operation errors** (every other class in this file, all extending * `GraphExtensionError`) — thrown one at a time from `evolve`, * `removeKinds`, `materializeIndexes`, search, etc. Each carries a * stable string `code` for logging / serialization PLUS a typed * shape so consumers can `instanceof` for control flow. */ /** * One specific issue raised during graph-extension validation. */ type GraphExtensionIssue = Readonly<{ /** * JSON-pointer path to the offending value, rooted at the document * (e.g. `/nodes/Paper/properties/title/pattern`). The empty string * `""` means "the document itself". */ path: string; /** Human-readable explanation of the failure. */ message: string; /** * Stable machine-readable code so callers (and tests) can branch on * specific failure modes without parsing messages. New codes are * additive. */ code: GraphExtensionIssueCode; }>; /** * Stable machine codes for every validation failure produced by the * document validator. New codes are additive — existing codes never * change meaning. * * Note: codes here describe per-field validation problems. Operation- * level errors (kind not found, version mismatch on persisted doc, * compile-time-kind removal, etc.) surface as typed Error subclasses * exported below — not as issue codes. */ /** * Every issue code emitted by `validateGraphExtension`. Const-array form * so tests, codegen, and runtime introspection can iterate the full set * without restating it. */ declare const GRAPH_EXTENSION_ISSUE_CODES: readonly ["UNSUPPORTED_PROPERTY_TYPE", "INVALID_PROPERTY_REFINEMENT", "NESTED_ARRAY", "NESTED_OBJECT_TOO_DEEP", "INVALID_MODIFIER_TARGET", "INVALID_ENUM_VALUES", "INVALID_NUMBER_BOUNDS", "INVALID_LENGTH_BOUNDS", "INVALID_PATTERN", "INVALID_EMBEDDING_DIMENSIONS", "INVALID_SEARCHABLE_LANGUAGE", "RESERVED_PROPERTY_NAME", "INVALID_KIND_NAME", "DUPLICATE_KIND_NAME", "EMPTY_PROPERTIES", "EMPTY_FROM_OR_TO", "DUPLICATE_UNIQUE_CONSTRAINT", "EMPTY_UNIQUE_FIELDS", "DUPLICATE_UNIQUE_FIELD", "UNKNOWN_UNIQUE_FIELD", "INVALID_UNIQUE_WHERE_OP", "UNKNOWN_UNIQUE_WHERE_FIELD", "INVALID_ANNOTATION", "UNKNOWN_META_EDGE", "ONTOLOGY_CYCLE", "ONTOLOGY_SELF_LOOP", "ONTOLOGY_DISJOINT_CONFLICT", "ONTOLOGY_INVERSE_MULTIPLE_PARTNERS", "DUPLICATE_ONTOLOGY_RELATION", "INVALID_DOCUMENT_SHAPE", "UNKNOWN_DOCUMENT_KEY", "UNSUPPORTED_STRING_FORMAT", "INVALID_INDEX_DECLARATION", "DUPLICATE_INDEX_NAME", "EMPTY_INDEX_FIELDS", "UNKNOWN_PROPERTY_KEY"]; type GraphExtensionIssueCode = (typeof GRAPH_EXTENSION_ISSUE_CODES)[number]; /** * Base class for every graph-extension error. Consumers can catch * the family with one `instanceof GraphExtensionError` check and * branch on the concrete subclass beneath. Carries the same * `code` / `category` / `details` slots as `TypeGraphError` so existing * `isTypeGraphError` / `isUserRecoverable` helpers continue to apply. */ declare abstract class GraphExtensionError extends TypeGraphError { readonly code: string; protected constructor(spec: { message: string; code: string; details: Readonly>; suggestion: string; category?: ErrorCategory; cause?: unknown; }); } /** * Thrown when `validateGraphExtension` (or `defineGraphExtension`) * rejects an input document for one or more shape/content reasons. * * The `issues` array carries every failure with a JSON-pointer * `path`, so callers presenting the document to a human reviewer can * highlight every offending field at once. */ declare class GraphExtensionValidationError extends GraphExtensionError { readonly code: "GRAPH_EXTENSION_INVALID"; readonly issues: readonly GraphExtensionIssue[]; readonly details: Readonly<{ issues: readonly GraphExtensionIssue[]; }>; constructor(issues: readonly GraphExtensionIssue[], cause?: unknown); } /** * Thrown when an extension declares a kind whose name collides with an * existing compile-time kind. The graph-extension contract is * additive: graph-extension-declared kinds cannot shadow compile-time kinds. */ declare class KindCollisionError extends GraphExtensionError { readonly code: "KIND_COLLISION"; readonly kindName: string; readonly entity: KindEntity; constructor(kindName: string, entity: KindEntity, graphId: string); } /** * One classified delta in a `IncompatibleChangeError`. * * `field` is `undefined` for kind-level changes (e.g. tightening edge * endpoints, adding a unique constraint to a populated kind). `detail` * is human-readable and intended for surfaces showing the change to a * reviewer (e.g. `"minLength: 5 → 10"`). */ /** * Every incompatible-change classification produced by `evolve`'s * delta classifier. Const-array form so tests and reviewer UIs can * enumerate the set without restating it. */ declare const INCOMPATIBLE_CHANGE_TYPES: readonly ["REMOVE_PROPERTY", "ADD_REQUIRED_PROPERTY", "TIGHTEN_OPTIONALITY", "TIGHTEN_CONSTRAINT", "ADD_PATTERN", "CHANGE_PATTERN", "ADD_FORMAT", "CHANGE_FORMAT", "TIGHTEN_INT", "TIGHTEN_ENUM", "TYPE_CHANGE", "ADD_UNIQUE_ON_POPULATED", "TIGHTEN_EDGE_ENDPOINTS"]; type IncompatibleChangeType = (typeof INCOMPATIBLE_CHANGE_TYPES)[number]; type IncompatibleChange = Readonly<{ kind: string; field?: string; type: IncompatibleChangeType; detail?: string; }>; /** * Thrown when `evolve` rejects one or more deltas against an existing * extension kind. Carries a structured `changes` list so a reviewer * UI can show the incompatible deltas across every affected kind in * one shot. */ declare class IncompatibleChangeError extends GraphExtensionError { readonly code: "INCOMPATIBLE_CHANGE"; readonly changes: readonly IncompatibleChange[]; constructor(changes: readonly IncompatibleChange[], graphId: string); } /** * Thrown when an extension's edge or ontology endpoint references a * kind that exists in neither the extension nor the host graph. * Distinct from `KindNotFoundError` because the cause is a * stale persisted extension (a compile-time kind was removed from * source after the extension was committed) rather than a * call-site typo. */ declare class GraphExtensionUnresolvedEndpointError extends GraphExtensionError { readonly code: "GRAPH_EXTENSION_UNRESOLVED_ENDPOINT"; readonly edgeKind: string; readonly side: "from" | "to"; readonly endpoint: string; constructor(edgeKind: string, side: "from" | "to", endpoint: string, graphId: string); } /** * Thrown when `inverseOf` or `implies` uses an unresolved bare edge-kind * name. Absolute HTTP(S) IRIs remain deliberate inert external references. */ declare class GraphExtensionUnresolvedOntologyEndpointError extends GraphExtensionError { readonly code: "GRAPH_EXTENSION_UNRESOLVED_ONTOLOGY_ENDPOINT"; readonly metaEdge: "inverseOf" | "implies"; readonly endpoint: string; constructor(metaEdge: "inverseOf" | "implies", endpoint: string, graphId: string); } /** * Thrown by `removeKinds` when the removal list contains a compile- * time kind. Compile-time kinds are removed by recompiling and * redeploying — persisting "removed-compile-time-kind" state in * `schema_doc` is incoherent because the kind would resurrect on the * next deploy. */ declare class RemoveCompileTimeKindError extends GraphExtensionError { readonly code: "REMOVE_COMPILE_TIME_KIND"; readonly kindName: string; readonly entity: KindEntity; constructor(kindName: string, entity: KindEntity, graphId: string); } /** * Thrown by `removeKinds` when a compile-time edge or ontology * relation references the graph-extension kind being removed. Removing the * kind would orphan compile-time references — incoherent at the next * deploy. */ declare class KindHasReferentsError extends GraphExtensionError { readonly code: "KIND_HAS_REFERENTS"; readonly kindName: string; readonly referents: readonly KindReferent[]; constructor(kindName: string, referents: readonly KindReferent[], graphId: string); } type KindReferent = Readonly<{ type: "compile-time-edge" | "compile-time-ontology"; name: string; }>; /** * Thrown when a persisted graph extension was authored against a * higher major version of the graph-extension format than the * current library supports. The library refuses to load it rather * than risk silently misreading newer fields. */ declare class GraphExtensionVersionUnsupportedError extends GraphExtensionError { readonly code: "GRAPH_EXTENSION_VERSION_UNSUPPORTED"; readonly persistedVersion: number; readonly currentVersion: number; constructor(persistedVersion: number, currentVersion: number); } type ValidateGraphExtensionOptions = Readonly<{ /** * Reject unknown top-level keys and unsupported string formats. * Used by `defineGraphExtension`, where the document is being * authored fresh against the current library version — typos in * `nodes` / `format: "date-time"` etc. should fail loudly. The * persistence-load path leaves this off so a document committed by * a future v1.x writer with additive fields still parses on an * older v1 reader. */ strict?: boolean; }>; /** * Validates a graph extension. * * Returns the (frozen, deeply normalized) extension on success, or a * `GraphExtensionValidationError` carrying every issue on authoring * failure. Unsupported future major versions throw * `GraphExtensionVersionUnsupportedError` immediately because the * current library cannot safely decode the rest of the document. * Callers that prefer exceptions for validation failures wrap the * returned `Result` with `unwrap()`. */ declare function validateGraphExtension(input: unknown, options?: ValidateGraphExtensionOptions): Result; export { GRAPH_EXTENSION_ISSUE_CODES, GraphExtension, GraphExtensionError, type GraphExtensionIssue, type GraphExtensionIssueCode, GraphExtensionUnresolvedEndpointError, GraphExtensionUnresolvedOntologyEndpointError, GraphExtensionValidationError, GraphExtensionVersionUnsupportedError, INCOMPATIBLE_CHANGE_TYPES, type IncompatibleChange, IncompatibleChangeError, type IncompatibleChangeType, KindCollisionError, KindHasReferentsError, type KindReferent, RemoveCompileTimeKindError, defineGraphExtension, validateGraphExtension };