@nicia-ai/typegraph 0.59.0 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +3 -0
  3. package/dist/backend/postgres/pglite-store.cjs +1 -1
  4. package/dist/backend/postgres/pglite-store.d.cts +2 -2
  5. package/dist/backend/postgres/pglite-store.d.ts +2 -2
  6. package/dist/backend/postgres/pglite-store.js +1 -1
  7. package/dist/backend/sqlite/local-store.cjs +1 -1
  8. package/dist/backend/sqlite/local-store.d.cts +2 -2
  9. package/dist/backend/sqlite/local-store.d.ts +2 -2
  10. package/dist/backend/sqlite/local-store.js +1 -1
  11. package/dist/{chunk-MKQY4ZLZ.js → chunk-2DKIJP2R.js} +73 -41
  12. package/dist/chunk-2DKIJP2R.js.map +1 -0
  13. package/dist/{chunk-6BVZHDAZ.js → chunk-43DOTETB.js} +3 -3
  14. package/dist/{chunk-6BVZHDAZ.js.map → chunk-43DOTETB.js.map} +1 -1
  15. package/dist/{chunk-IV5W7LKW.cjs → chunk-A22XPVBQ.cjs} +2 -2
  16. package/dist/chunk-A22XPVBQ.cjs.map +1 -0
  17. package/dist/{chunk-W4NT4IMI.js → chunk-B4P4DAW3.js} +3 -3
  18. package/dist/{chunk-W4NT4IMI.js.map → chunk-B4P4DAW3.js.map} +1 -1
  19. package/dist/{chunk-CA76FVJB.cjs → chunk-CNFKFE5L.cjs} +399 -367
  20. package/dist/chunk-CNFKFE5L.cjs.map +1 -0
  21. package/dist/{chunk-EN67I47R.cjs → chunk-EHDLHPMK.cjs} +9 -9
  22. package/dist/{chunk-EN67I47R.cjs.map → chunk-EHDLHPMK.cjs.map} +1 -1
  23. package/dist/{chunk-V3JKR2CN.js → chunk-FTDRMXIJ.js} +5 -5
  24. package/dist/{chunk-V3JKR2CN.js.map → chunk-FTDRMXIJ.js.map} +1 -1
  25. package/dist/{chunk-3GX5HTPP.js → chunk-ILVXUOQY.js} +3 -3
  26. package/dist/{chunk-3GX5HTPP.js.map → chunk-ILVXUOQY.js.map} +1 -1
  27. package/dist/{chunk-XGYUUUHY.cjs → chunk-KGQVK2II.cjs} +40 -40
  28. package/dist/{chunk-XGYUUUHY.cjs.map → chunk-KGQVK2II.cjs.map} +1 -1
  29. package/dist/{chunk-BPYZUJX5.cjs → chunk-MTJAT6UO.cjs} +5 -5
  30. package/dist/{chunk-BPYZUJX5.cjs.map → chunk-MTJAT6UO.cjs.map} +1 -1
  31. package/dist/{chunk-2GZL5ED3.cjs → chunk-OKA6H3B3.cjs} +19 -19
  32. package/dist/{chunk-2GZL5ED3.cjs.map → chunk-OKA6H3B3.cjs.map} +1 -1
  33. package/dist/{chunk-26CL47SW.cjs → chunk-PTFO3JI5.cjs} +110 -110
  34. package/dist/{chunk-26CL47SW.cjs.map → chunk-PTFO3JI5.cjs.map} +1 -1
  35. package/dist/{chunk-UOHFBYYH.cjs → chunk-Q6ZVQWH7.cjs} +36 -36
  36. package/dist/{chunk-UOHFBYYH.cjs.map → chunk-Q6ZVQWH7.cjs.map} +1 -1
  37. package/dist/{chunk-HWWPL2YL.js → chunk-QWIR5533.js} +2 -2
  38. package/dist/chunk-QWIR5533.js.map +1 -0
  39. package/dist/{chunk-DZ3ETMXF.js → chunk-UVQMUBZ6.js} +6 -6
  40. package/dist/{chunk-DZ3ETMXF.js.map → chunk-UVQMUBZ6.js.map} +1 -1
  41. package/dist/{chunk-E6PU35DE.js → chunk-W6K6NSRT.js} +4 -4
  42. package/dist/{chunk-E6PU35DE.js.map → chunk-W6K6NSRT.js.map} +1 -1
  43. package/dist/graph-merge/index.cjs +119 -119
  44. package/dist/graph-merge/index.d.cts +2 -2
  45. package/dist/graph-merge/index.d.ts +2 -2
  46. package/dist/graph-merge/index.js +7 -7
  47. package/dist/{graph-templates-DQnmCPkd.d.ts → graph-templates-ClBhrXiA.d.ts} +1 -1
  48. package/dist/{graph-templates-Buh-RlmQ.d.cts → graph-templates-DfmKDARd.d.cts} +1 -1
  49. package/dist/index.cjs +68 -68
  50. package/dist/index.d.cts +3 -3
  51. package/dist/index.d.ts +3 -3
  52. package/dist/index.js +8 -8
  53. package/dist/interchange/index.cjs +28 -28
  54. package/dist/interchange/index.d.cts +2 -2
  55. package/dist/interchange/index.d.ts +2 -2
  56. package/dist/interchange/index.js +5 -5
  57. package/dist/{local-store-impl-GFBZBCTN.cjs → local-store-impl-QGSRYFZF.cjs} +9 -9
  58. package/dist/{local-store-impl-GFBZBCTN.cjs.map → local-store-impl-QGSRYFZF.cjs.map} +1 -1
  59. package/dist/{local-store-impl-EPUMDNQJ.js → local-store-impl-VEVK2VGA.js} +8 -8
  60. package/dist/{local-store-impl-EPUMDNQJ.js.map → local-store-impl-VEVK2VGA.js.map} +1 -1
  61. package/dist/{pglite-store-impl-DB4RRLB7.cjs → pglite-store-impl-33CI3P3M.cjs} +9 -9
  62. package/dist/{pglite-store-impl-DB4RRLB7.cjs.map → pglite-store-impl-33CI3P3M.cjs.map} +1 -1
  63. package/dist/{pglite-store-impl-M5PWKN7Z.js → pglite-store-impl-RDPTOOP3.js} +8 -8
  64. package/dist/{pglite-store-impl-M5PWKN7Z.js.map → pglite-store-impl-RDPTOOP3.js.map} +1 -1
  65. package/dist/profiler/index.d.cts +2 -2
  66. package/dist/profiler/index.d.ts +2 -2
  67. package/dist/provenance/index.cjs +15 -15
  68. package/dist/provenance/index.d.cts +2 -2
  69. package/dist/provenance/index.d.ts +2 -2
  70. package/dist/provenance/index.js +2 -2
  71. package/dist/schema/index.cjs +34 -34
  72. package/dist/schema/index.d.cts +3 -3
  73. package/dist/schema/index.d.ts +3 -3
  74. package/dist/schema/index.js +4 -4
  75. package/dist/{store-sLu0hcRm.d.ts → store-B5WZ8E5m.d.ts} +225 -215
  76. package/dist/{store-CvtRQ8Nb.d.cts → store-DdhFpX53.d.cts} +225 -215
  77. package/package.json +1 -1
  78. package/dist/chunk-CA76FVJB.cjs.map +0 -1
  79. package/dist/chunk-HWWPL2YL.js.map +0 -1
  80. package/dist/chunk-IV5W7LKW.cjs.map +0 -1
  81. package/dist/chunk-MKQY4ZLZ.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { $ as NodeType, fp as EdgeType, _ as AnyEdgeType, G as GraphIdentityConfig, e9 as ValueType, hs as PredicateExpression, cm as FulltextQueryMode, ht as VectorMetricType, Q as QueryAst, J as JsonPointer, eP as FieldRef, go as ParameterRef, gQ as TraversalExpansion, f as GraphBackend, q as SqlDialect, gH as SqlSchema, hu as Traversal, hv as NodePredicate, hw as ProjectedField, gn as OrderSpec, hx as AggregateOrderSpec, dS as TemporalMode, R as RecordedInstant, hy as GroupBySpec, fI as HybridFusionOptions, fX as JsonPointerInput, hz as RecursiveCyclePolicy, e as GraphDef, eS as TraversalDirection$1, fm as EdgeRegistration, gf as NodeId, T as TransactionBackend, b2 as CompiledSelectSql, eO as AggregateExpr, gG as SortDirection, d as FulltextStrategy, V as VectorStrategy, hA as VectorSlotMap, hB as RecordedReadBinding, dr as RecursiveTraversalVerdict, hC as SelectiveField, hD as ComposableQuery, hE as SetOperationType, hF as SetOperation, gi as NodeKinds, n as NodeRow, K as KindEntity, fC as ExternalRecordedReadSource, ff as EdgeId, l as EdgeRow, hG as BackendValidityEndMutation, cQ as JsonScalar, gm as NodeRegistration, fg as EdgeKinds, dV as TransactionReadBackend, eV as AllNodeTypes, am as SchemaDiff, S as SchemaVersionRow, a5 as SerializedSchema, fG as GraphAnnotations, cS as KindAnnotations, ai as JsonSchema, d_ as UniquenessScope, aY as Collation, aR as Cardinality, bN as EndpointExistence, cs as GraphExtension, hH as ReadCoordinate, aN as BackendIdentity, cq as GraphEntityReadBackend, dD as SchemaReadBackend, dd as QueryExecutionBackend, dH as SqlCompilationBackend, de as RawQueryExecutionBackend, ec as VectorMetric, aG as TypeGraphError, Y as BackendCapabilities, b$ as ExtensionNodeDef, hI as ExtensionObjectSchema, bV as ExtensionEdgeDef, hJ as ExtensionEdgeProperties, g5 as MaterializeIndexesOptions, g6 as MaterializeIndexesResult, g7 as MaterializeSystemIndexesOptions, C as ContributionDiagnostic, c as ContributionRepairResult, be as ContributionProbeResult, bh as ContributionRebuildScope, bg as ContributionRebuildResult, dU as TransactionOptions, A as AdapterBackend } from './types-Dky3sCFz.js';
2
+ import { $ as NodeType, fp as EdgeType, _ as AnyEdgeType, G as GraphIdentityConfig, e9 as ValueType, hs as PredicateExpression, cm as FulltextQueryMode, ht as VectorMetricType, Q as QueryAst, J as JsonPointer, eP as FieldRef, go as ParameterRef, gQ as TraversalExpansion, f as GraphBackend, q as SqlDialect, gH as SqlSchema, hu as Traversal, hv as NodePredicate, hw as ProjectedField, gn as OrderSpec, hx as AggregateOrderSpec, dS as TemporalMode, R as RecordedInstant, hy as GroupBySpec, fI as HybridFusionOptions, fX as JsonPointerInput, hz as RecursiveCyclePolicy, e as GraphDef, eS as TraversalDirection$1, fm as EdgeRegistration, gf as NodeId, T as TransactionBackend, b2 as CompiledSelectSql, eO as AggregateExpr, gG as SortDirection, d as FulltextStrategy, V as VectorStrategy, hA as VectorSlotMap, hB as RecordedReadBinding, dr as RecursiveTraversalVerdict, hC as SelectiveField, hD as ComposableQuery, hE as SetOperationType, hF as SetOperation, fg as EdgeKinds, eV as AllNodeTypes, gi as NodeKinds, n as NodeRow, K as KindEntity, fC as ExternalRecordedReadSource, ff as EdgeId, l as EdgeRow, hG as BackendValidityEndMutation, cQ as JsonScalar, gm as NodeRegistration, dV as TransactionReadBackend, am as SchemaDiff, S as SchemaVersionRow, a5 as SerializedSchema, fG as GraphAnnotations, cS as KindAnnotations, ai as JsonSchema, d_ as UniquenessScope, aY as Collation, aR as Cardinality, bN as EndpointExistence, cs as GraphExtension, hH as ReadCoordinate, aN as BackendIdentity, cq as GraphEntityReadBackend, dD as SchemaReadBackend, dd as QueryExecutionBackend, dH as SqlCompilationBackend, de as RawQueryExecutionBackend, ec as VectorMetric, aG as TypeGraphError, Y as BackendCapabilities, b$ as ExtensionNodeDef, hI as ExtensionObjectSchema, bV as ExtensionEdgeDef, hJ as ExtensionEdgeProperties, g5 as MaterializeIndexesOptions, g6 as MaterializeIndexesResult, g7 as MaterializeSystemIndexesOptions, C as ContributionDiagnostic, c as ContributionRepairResult, be as ContributionProbeResult, bh as ContributionRebuildScope, bg as ContributionRebuildResult, dU as TransactionOptions, A as AdapterBackend } from './types-Dky3sCFz.js';
3
3
  import { S as SearchableMetadata, c as EmbeddingValue } from './searchable-Bg2lMPRm.js';
4
4
  import { b as BundleVerdictOf, U as UNIQUE_SIDECAR_BATCH, B as BATCH_POINT_READ } from './resolve-BbjZDYTw.js';
5
5
 
@@ -1930,6 +1930,215 @@ declare const IDENTITY_READ_NAMES: readonly ["representativeOf", "membersOf", "n
1930
1930
  /** Recorded-time collection point reads that reconstruct safely by id. */
1931
1931
  declare const RECORDED_POINT_READ_NAMES: readonly ["getById", "getByIds"];
1932
1932
 
1933
+ /** Edge metadata fields accepted by bounded neighbor and subgraph reads. */
1934
+ type NeighborOrderField = "createdAt" | "id" | "updatedAt" | "validFrom" | "validTo";
1935
+ /** Node property names accepted by adjacent-node ordering. */
1936
+ type NeighborNodeOrderField<G extends GraphDef> = {
1937
+ [K in keyof G["nodes"] & string]: Exclude<keyof Node<G["nodes"][K]["type"]>, "id" | "kind" | "meta"> & string;
1938
+ }[keyof G["nodes"] & string];
1939
+ type NeighborOrder<G extends GraphDef> = Readonly<{
1940
+ by?: "edge";
1941
+ field: NeighborOrderField;
1942
+ direction?: "asc" | "desc";
1943
+ }> | Readonly<{
1944
+ by: "node";
1945
+ field: NeighborNodeOrderField<G>;
1946
+ direction?: "asc" | "desc";
1947
+ }>;
1948
+ /** Per-edge-kind ordering and bound applied before traversal expands an edge. */
1949
+ type EdgeReadWindow = Readonly<{
1950
+ limit: number;
1951
+ /** Direction for this edge kind; defaults to the traversal direction. */
1952
+ direction?: "both" | "in" | "out";
1953
+ orderBy?: Readonly<{
1954
+ field: NeighborOrderField;
1955
+ direction?: "asc" | "desc";
1956
+ }>;
1957
+ }>;
1958
+ /** Options for reading adjacent edge-node pairs without hydrating all targets. */
1959
+ type NeighborReadOptionsBoundary<G extends GraphDef, K extends EdgeKinds<G>> = Readonly<{
1960
+ edges?: readonly K[];
1961
+ direction?: "both" | "in" | "out";
1962
+ orderBy?: NeighborOrder<G>;
1963
+ limit?: number;
1964
+ temporalMode?: TemporalMode;
1965
+ asOf?: string;
1966
+ }>;
1967
+ type NeighborReadOptions<G extends GraphDef, K extends EdgeKinds<G>> = NeighborReadOptionsBoundary<G, K> & Required<Pick<NeighborReadOptionsBoundary<G, K>, "edges">>;
1968
+ /** One edge and the node it reaches from the requested source and direction. */
1969
+ type NeighborResult<G extends GraphDef, K extends EdgeKinds<G>> = Readonly<{
1970
+ edge: GraphEdgeForKinds<G, K>;
1971
+ node: Node<AllNodeTypes<G>>;
1972
+ }>;
1973
+
1974
+ /**
1975
+ * Discriminated union of all Node runtime types in a graph.
1976
+ *
1977
+ * Unlike `AllNodeTypes<G>` which gives the union of *type definitions*,
1978
+ * `AnyNode<G>` gives the union of *runtime node instances*.
1979
+ */
1980
+ type AnyNode<G extends GraphDef> = {
1981
+ [K in NodeKinds<G>]: Node<G["nodes"][K]["type"]>;
1982
+ }[NodeKinds<G>];
1983
+ /**
1984
+ * Discriminated union of all Edge runtime types in a graph.
1985
+ */
1986
+ type AnyEdge<G extends GraphDef> = {
1987
+ [K in EdgeKinds<G>]: Edge<G["edges"][K]["type"]>;
1988
+ }[EdgeKinds<G>];
1989
+ /**
1990
+ * Discriminated union of Node runtime types narrowed to a subset of kinds.
1991
+ */
1992
+ type SubsetNode<G extends GraphDef, K extends NodeKinds<G>> = {
1993
+ [Kind in K]: Node<G["nodes"][Kind]["type"]>;
1994
+ }[K];
1995
+ /**
1996
+ * Discriminated union of Edge runtime types narrowed to a subset of kinds.
1997
+ */
1998
+ type SubsetEdge<G extends GraphDef, K extends EdgeKinds<G>> = {
1999
+ [Kind in K]: Edge<G["edges"][Kind]["type"]>;
2000
+ }[K];
2001
+ type EmptyShape = Readonly<Record<never, never>>;
2002
+ type NodeProjectionPropertyKey<N extends NodeType> = Exclude<keyof Node<N>, "id" | "kind" | "meta"> & string;
2003
+ type EdgeProjectionPropertyKey<E extends AnyEdgeType> = Exclude<keyof Edge<E>, "id" | "kind" | "fromKind" | "fromId" | "toKind" | "toId" | "meta"> & string;
2004
+ type SubgraphNodeProjectionField<N extends NodeType = NodeType> = NodeProjectionPropertyKey<N> | "meta";
2005
+ type SubgraphEdgeProjectionField<E extends AnyEdgeType = AnyEdgeType> = EdgeProjectionPropertyKey<E> | "meta";
2006
+ type SubgraphNodeProjectionMap<G extends GraphDef, NK extends NodeKinds<G> = NodeKinds<G>> = Readonly<{
2007
+ [K in NodeKinds<G>]?: K extends NK ? readonly SubgraphNodeProjectionField<G["nodes"][K]["type"]>[] : never;
2008
+ }>;
2009
+ type SubgraphEdgeProjectionMap<G extends GraphDef, EK extends EdgeKinds<G> = EdgeKinds<G>> = Readonly<{
2010
+ [K in EdgeKinds<G>]?: K extends EK ? readonly SubgraphEdgeProjectionField<G["edges"][K]["type"]>[] : never;
2011
+ }>;
2012
+ type SubgraphProject<G extends GraphDef, NK extends NodeKinds<G> = NodeKinds<G>, EK extends EdgeKinds<G> = EdgeKinds<G>> = Readonly<{
2013
+ /**
2014
+ * Node fields to keep per kind.
2015
+ *
2016
+ * Projected nodes always retain `kind` and `id`.
2017
+ * Use `"meta"` to include the full metadata object; omit it to exclude metadata entirely.
2018
+ * Only kinds present in `includeKinds` (or all node kinds when omitted) are valid keys.
2019
+ */
2020
+ nodes?: SubgraphNodeProjectionMap<G, NK>;
2021
+ /**
2022
+ * Edge fields to keep per kind.
2023
+ *
2024
+ * Projected edges always retain `id`, `kind`, `fromKind`, `fromId`,
2025
+ * `toKind`, and `toId`.
2026
+ * Use `"meta"` to include the full metadata object; omit it to exclude metadata entirely.
2027
+ * Only edge kinds listed in `edges` are valid keys.
2028
+ */
2029
+ edges?: SubgraphEdgeProjectionMap<G, EK>;
2030
+ }>;
2031
+ /**
2032
+ * Identity function that preserves literal types for reusable projection configs.
2033
+ *
2034
+ * Without this helper, storing a projection in a typed variable widens the
2035
+ * field arrays to `string[]`, defeating compile-time narrowing on results.
2036
+ *
2037
+ * @example
2038
+ * ```ts
2039
+ * const project = defineSubgraphProject(graph)({
2040
+ * nodes: { Task: ["title", "meta"] },
2041
+ * edges: { uses_skill: [] },
2042
+ * });
2043
+ * const result = await store.subgraph(rootId, { edges: ["uses_skill"], project });
2044
+ * // result.nodes narrowed correctly — task.status is a type error
2045
+ * ```
2046
+ */
2047
+ declare function defineSubgraphProject<G extends GraphDef>(_graph: G): <const P extends SubgraphProject<G>>(project: P) => P;
2048
+ type HasMeta<Selection extends readonly string[] | undefined> = Selection extends readonly string[] ? "meta" extends Selection[number] ? true : false : false;
2049
+ type SelectedNodeProps<N extends NodeType, Selection extends readonly string[] | undefined> = Selection extends readonly string[] ? Pick<Node<N>, Extract<Selection[number], NodeProjectionPropertyKey<N>>> : EmptyShape;
2050
+ type SelectedEdgeProps<E extends AnyEdgeType, Selection extends readonly string[] | undefined> = Selection extends readonly string[] ? Pick<Edge<E>, Extract<Selection[number], EdgeProjectionPropertyKey<E>>> : EmptyShape;
2051
+ type ProjectedNodeResult<N extends NodeType, Selection extends readonly string[] | undefined> = Readonly<Pick<Node<N>, "id" | "kind">> & Readonly<SelectedNodeProps<N, Selection>> & (HasMeta<Selection> extends true ? Readonly<{
2052
+ meta: NodeMeta;
2053
+ }> : EmptyShape);
2054
+ type ProjectedEdgeResult<E extends AnyEdgeType, Selection extends readonly string[] | undefined> = Readonly<Pick<Edge<E>, "id" | "kind" | "fromKind" | "fromId" | "toKind" | "toId">> & Readonly<SelectedEdgeProps<E, Selection>> & (HasMeta<Selection> extends true ? Readonly<{
2055
+ meta: EdgeMeta;
2056
+ }> : EmptyShape);
2057
+ type ProjectionSelection<P, Key extends "nodes" | "edges", Kind extends string> = P extends Readonly<{
2058
+ [K in Key]?: infer Map;
2059
+ }> ? Map extends Readonly<Record<string, readonly string[] | undefined>> ? Kind extends keyof Map ? Map[Kind] : undefined : undefined : undefined;
2060
+ type SubgraphNodeResultForKind<G extends GraphDef, Kind extends NodeKinds<G>, P> = ProjectionSelection<P, "nodes", Kind> extends readonly string[] ? ProjectedNodeResult<G["nodes"][Kind]["type"], ProjectionSelection<P, "nodes", Kind>> : Node<G["nodes"][Kind]["type"]>;
2061
+ type SubgraphEdgeResultForKind<G extends GraphDef, Kind extends EdgeKinds<G>, P> = ProjectionSelection<P, "edges", Kind> extends readonly string[] ? ProjectedEdgeResult<G["edges"][Kind]["type"], ProjectionSelection<P, "edges", Kind>> : Edge<G["edges"][Kind]["type"]>;
2062
+ type SubgraphOptions<G extends GraphDef, EK extends EdgeKinds<G>, NK extends NodeKinds<G>, P extends SubgraphProject<G, NK, EK> | undefined = undefined> = Readonly<{
2063
+ /** Edge kinds to follow during traversal. Edges not listed are not traversed. */
2064
+ edges: readonly EK[];
2065
+ /** Maximum traversal depth from root (default: 10). */
2066
+ maxDepth?: number;
2067
+ /**
2068
+ * Node kinds to include in the result. Nodes of other kinds are still
2069
+ * traversed through but omitted from the output. When omitted, all
2070
+ * reachable node kinds are included.
2071
+ */
2072
+ includeKinds?: readonly NK[];
2073
+ /** Exclude the root node from the result (default: false). */
2074
+ excludeRoot?: boolean;
2075
+ /**
2076
+ * Edge direction policy (default: "out").
2077
+ * - "out": follow edges in their defined direction only
2078
+ * - "both": follow edges in both directions (undirected traversal)
2079
+ */
2080
+ direction?: "out" | "both";
2081
+ /** Cycle policy — reuse RecursiveCyclePolicy (default: "prevent"). */
2082
+ cyclePolicy?: RecursiveCyclePolicy;
2083
+ /**
2084
+ * Temporal mode applied to both nodes and edges along the traversal and in
2085
+ * the hydrated result. Defaults to `graph.defaults.temporalMode`.
2086
+ */
2087
+ temporalMode?: TemporalMode;
2088
+ /** ISO-8601 timestamp used when `temporalMode === "asOf"`. */
2089
+ asOf?: string;
2090
+ /** @internal Recorded coordinates are supplied by StoreView only. */
2091
+ recordedAsOf?: never;
2092
+ /**
2093
+ * Optional field-level projection per node/edge kind.
2094
+ *
2095
+ * Projected nodes keep `kind` and `id`; projected edges keep their structural
2096
+ * endpoint fields. Kinds omitted from `project` remain fully hydrated.
2097
+ * Projection applies to every returned entity, including the root node.
2098
+ *
2099
+ * Only kinds present in `includeKinds` (nodes) or `edges` (edges) are valid
2100
+ * projection keys. Specifying a kind outside those sets is a compile-time error.
2101
+ */
2102
+ project?: P;
2103
+ /**
2104
+ * Per-edge-kind windows applied while traversing and hydrating. Each limit
2105
+ * is partitioned by the current endpoint, so append-only edge histories can
2106
+ * contribute only their newest N targets at every hop.
2107
+ */
2108
+ edgeWindows?: Readonly<Partial<Record<EK, EdgeReadWindow>>>;
2109
+ }>;
2110
+ /**
2111
+ * Subgraph options as seen by the internal executor: identical to the public
2112
+ * {@link SubgraphOptions} except the recorded/system-time pin is a branded
2113
+ * instant the StoreView seam supplies. The public surface keeps
2114
+ * `recordedAsOf?: never`;
2115
+ * recorded reads reach the executor only through `store.subgraphAtCoordinate`.
2116
+ */
2117
+ type InternalSubgraphOptions<G extends GraphDef, EK extends EdgeKinds<G>, NK extends NodeKinds<G>, P extends SubgraphProject<G, NK, EK> | undefined = undefined> = Omit<SubgraphOptions<G, EK, NK, P>, "recordedAsOf"> & Readonly<{
2118
+ recordedAsOf?: RecordedInstant;
2119
+ }>;
2120
+ /**
2121
+ * Union of all node result types in a subgraph, respecting projection.
2122
+ */
2123
+ type SubgraphNodeResult<G extends GraphDef, NK extends NodeKinds<G> = NodeKinds<G>, P = undefined> = {
2124
+ [Kind in NK]: SubgraphNodeResultForKind<G, Kind, P>;
2125
+ }[NK];
2126
+ /**
2127
+ * Union of all edge result types in a subgraph, respecting projection.
2128
+ */
2129
+ type SubgraphEdgeResult<G extends GraphDef, EK extends EdgeKinds<G> = EdgeKinds<G>, P = undefined> = {
2130
+ [Kind in EK]: SubgraphEdgeResultForKind<G, Kind, P>;
2131
+ }[EK];
2132
+ type SubgraphResult<G extends GraphDef, NK extends NodeKinds<G> = NodeKinds<G>, EK extends EdgeKinds<G> = EdgeKinds<G>, P extends SubgraphProject<G, NK, EK> | undefined = undefined> = Readonly<{
2133
+ /** The root node, or undefined if the root was not found or excluded. */
2134
+ root: SubgraphNodeResult<G, NK, P> | undefined;
2135
+ nodes: ReadonlyMap<string, SubgraphNodeResult<G, NK, P>>;
2136
+ /** Forward adjacency: fromId → edgeKind → edges to targets. */
2137
+ adjacency: ReadonlyMap<string, ReadonlyMap<EK, readonly SubgraphEdgeResult<G, EK, P>[]>>;
2138
+ /** Reverse adjacency: toId → edgeKind → edges from sources. */
2139
+ reverseAdjacency: ReadonlyMap<string, ReadonlyMap<EK, readonly SubgraphEdgeResult<G, EK, P>[]>>;
2140
+ }>;
2141
+
1933
2142
  /**
1934
2143
  * Store types for TypeGraph operations.
1935
2144
  */
@@ -3553,11 +3762,21 @@ type TransactionCollections<G extends GraphDef> = Readonly<{
3553
3762
  identity: IdentityFacade<G>;
3554
3763
  }> : Readonly<Record<never, never>>);
3555
3764
  /**
3556
- * A portable transaction context containing only TypeGraph-owned graph
3557
- * operations. Managed Stores use this surface so adapter-native handles never
3558
- * enter their public contract.
3765
+ * A portable transaction context containing TypeGraph-owned collections and
3766
+ * transaction-bound graph reads. Managed Stores use this surface so
3767
+ * adapter-native handles never enter their public contract.
3559
3768
  */
3560
- type TransactionContext<G extends GraphDef> = TransactionCollections<G>;
3769
+ type TransactionContext<G extends GraphDef> = TransactionCollections<G> & Readonly<{
3770
+ query: () => InitialQueryBuilder<G, "open">;
3771
+ batchOnce: <const Queries extends readonly [
3772
+ EmbeddableOneStatementRead<unknown>,
3773
+ EmbeddableOneStatementRead<unknown>,
3774
+ ...EmbeddableOneStatementRead<unknown>[]
3775
+ ]>(build: (read: BatchReadBuilder<G>) => Queries) => Promise<OneStatementBatchResults<Queries>>;
3776
+ neighbors: <const K extends EdgeKinds<G>>(source: GraphNodeReference<G>, options: NeighborReadOptions<G, K>) => Promise<readonly NeighborResult<G, K>[]>;
3777
+ countNeighbors: <const K extends EdgeKinds<G>>(source: GraphNodeReference<G>, options: Omit<NeighborReadOptions<G, K>, "limit" | "orderBy">) => Promise<number>;
3778
+ subgraph: <const EK extends EdgeKinds<G>, const NK extends NodeKinds<G> = NodeKinds<G>, const P extends SubgraphProject<G, NK, EK> | undefined = undefined>(rootId: NodeId<AllNodeTypes<G>>, options: SubgraphOptions<G, EK, NK, P>) => Promise<SubgraphResult<G, NK, EK, P>>;
3779
+ }>;
3561
3780
  /**
3562
3781
  * A transaction context exposed by an {@link AdapterStore}. In addition to the
3563
3782
  * portable graph collections, it carries the adapter-native handle when that
@@ -3565,7 +3784,7 @@ type TransactionContext<G extends GraphDef> = TransactionCollections<G>;
3565
3784
  * read projection as the portable context; adapter-native writes intentionally
3566
3785
  * go through `sql`, making that escape hatch explicit.
3567
3786
  */
3568
- type AdapterTransactionContext<G extends GraphDef, TNativeTransaction> = TransactionCollections<G> & AdapterTransactionSqlAccess<TNativeTransaction>;
3787
+ type AdapterTransactionContext<G extends GraphDef, TNativeTransaction> = TransactionContext<G> & AdapterTransactionSqlAccess<TNativeTransaction>;
3569
3788
  /**
3570
3789
  * Scoped write measurement, available only on the receipt-enabled transaction
3571
3790
  * contexts (`transactionWithReceipt`, `withRecordedTransaction`). Runs `fn`,
@@ -4864,215 +5083,6 @@ type MaterializeRemovalsResult = Readonly<{
4864
5083
  reclaimedVectorFields: readonly ReclaimedVectorFieldEntry[];
4865
5084
  }>;
4866
5085
 
4867
- /** Edge metadata fields accepted by bounded neighbor and subgraph reads. */
4868
- type NeighborOrderField = "createdAt" | "id" | "updatedAt" | "validFrom" | "validTo";
4869
- /** Node property names accepted by adjacent-node ordering. */
4870
- type NeighborNodeOrderField<G extends GraphDef> = {
4871
- [K in keyof G["nodes"] & string]: Exclude<keyof Node<G["nodes"][K]["type"]>, "id" | "kind" | "meta"> & string;
4872
- }[keyof G["nodes"] & string];
4873
- type NeighborOrder<G extends GraphDef> = Readonly<{
4874
- by?: "edge";
4875
- field: NeighborOrderField;
4876
- direction?: "asc" | "desc";
4877
- }> | Readonly<{
4878
- by: "node";
4879
- field: NeighborNodeOrderField<G>;
4880
- direction?: "asc" | "desc";
4881
- }>;
4882
- /** Per-edge-kind ordering and bound applied before traversal expands an edge. */
4883
- type EdgeReadWindow = Readonly<{
4884
- limit: number;
4885
- /** Direction for this edge kind; defaults to the traversal direction. */
4886
- direction?: "both" | "in" | "out";
4887
- orderBy?: Readonly<{
4888
- field: NeighborOrderField;
4889
- direction?: "asc" | "desc";
4890
- }>;
4891
- }>;
4892
- /** Options for reading adjacent edge-node pairs without hydrating all targets. */
4893
- type NeighborReadOptionsBoundary<G extends GraphDef, K extends EdgeKinds<G>> = Readonly<{
4894
- edges?: readonly K[];
4895
- direction?: "both" | "in" | "out";
4896
- orderBy?: NeighborOrder<G>;
4897
- limit?: number;
4898
- temporalMode?: TemporalMode;
4899
- asOf?: string;
4900
- }>;
4901
- type NeighborReadOptions<G extends GraphDef, K extends EdgeKinds<G>> = NeighborReadOptionsBoundary<G, K> & Required<Pick<NeighborReadOptionsBoundary<G, K>, "edges">>;
4902
- /** One edge and the node it reaches from the requested source and direction. */
4903
- type NeighborResult<G extends GraphDef, K extends EdgeKinds<G>> = Readonly<{
4904
- edge: GraphEdgeForKinds<G, K>;
4905
- node: Node<AllNodeTypes<G>>;
4906
- }>;
4907
-
4908
- /**
4909
- * Discriminated union of all Node runtime types in a graph.
4910
- *
4911
- * Unlike `AllNodeTypes<G>` which gives the union of *type definitions*,
4912
- * `AnyNode<G>` gives the union of *runtime node instances*.
4913
- */
4914
- type AnyNode<G extends GraphDef> = {
4915
- [K in NodeKinds<G>]: Node<G["nodes"][K]["type"]>;
4916
- }[NodeKinds<G>];
4917
- /**
4918
- * Discriminated union of all Edge runtime types in a graph.
4919
- */
4920
- type AnyEdge<G extends GraphDef> = {
4921
- [K in EdgeKinds<G>]: Edge<G["edges"][K]["type"]>;
4922
- }[EdgeKinds<G>];
4923
- /**
4924
- * Discriminated union of Node runtime types narrowed to a subset of kinds.
4925
- */
4926
- type SubsetNode<G extends GraphDef, K extends NodeKinds<G>> = {
4927
- [Kind in K]: Node<G["nodes"][Kind]["type"]>;
4928
- }[K];
4929
- /**
4930
- * Discriminated union of Edge runtime types narrowed to a subset of kinds.
4931
- */
4932
- type SubsetEdge<G extends GraphDef, K extends EdgeKinds<G>> = {
4933
- [Kind in K]: Edge<G["edges"][Kind]["type"]>;
4934
- }[K];
4935
- type EmptyShape = Readonly<Record<never, never>>;
4936
- type NodeProjectionPropertyKey<N extends NodeType> = Exclude<keyof Node<N>, "id" | "kind" | "meta"> & string;
4937
- type EdgeProjectionPropertyKey<E extends AnyEdgeType> = Exclude<keyof Edge<E>, "id" | "kind" | "fromKind" | "fromId" | "toKind" | "toId" | "meta"> & string;
4938
- type SubgraphNodeProjectionField<N extends NodeType = NodeType> = NodeProjectionPropertyKey<N> | "meta";
4939
- type SubgraphEdgeProjectionField<E extends AnyEdgeType = AnyEdgeType> = EdgeProjectionPropertyKey<E> | "meta";
4940
- type SubgraphNodeProjectionMap<G extends GraphDef, NK extends NodeKinds<G> = NodeKinds<G>> = Readonly<{
4941
- [K in NodeKinds<G>]?: K extends NK ? readonly SubgraphNodeProjectionField<G["nodes"][K]["type"]>[] : never;
4942
- }>;
4943
- type SubgraphEdgeProjectionMap<G extends GraphDef, EK extends EdgeKinds<G> = EdgeKinds<G>> = Readonly<{
4944
- [K in EdgeKinds<G>]?: K extends EK ? readonly SubgraphEdgeProjectionField<G["edges"][K]["type"]>[] : never;
4945
- }>;
4946
- type SubgraphProject<G extends GraphDef, NK extends NodeKinds<G> = NodeKinds<G>, EK extends EdgeKinds<G> = EdgeKinds<G>> = Readonly<{
4947
- /**
4948
- * Node fields to keep per kind.
4949
- *
4950
- * Projected nodes always retain `kind` and `id`.
4951
- * Use `"meta"` to include the full metadata object; omit it to exclude metadata entirely.
4952
- * Only kinds present in `includeKinds` (or all node kinds when omitted) are valid keys.
4953
- */
4954
- nodes?: SubgraphNodeProjectionMap<G, NK>;
4955
- /**
4956
- * Edge fields to keep per kind.
4957
- *
4958
- * Projected edges always retain `id`, `kind`, `fromKind`, `fromId`,
4959
- * `toKind`, and `toId`.
4960
- * Use `"meta"` to include the full metadata object; omit it to exclude metadata entirely.
4961
- * Only edge kinds listed in `edges` are valid keys.
4962
- */
4963
- edges?: SubgraphEdgeProjectionMap<G, EK>;
4964
- }>;
4965
- /**
4966
- * Identity function that preserves literal types for reusable projection configs.
4967
- *
4968
- * Without this helper, storing a projection in a typed variable widens the
4969
- * field arrays to `string[]`, defeating compile-time narrowing on results.
4970
- *
4971
- * @example
4972
- * ```ts
4973
- * const project = defineSubgraphProject(graph)({
4974
- * nodes: { Task: ["title", "meta"] },
4975
- * edges: { uses_skill: [] },
4976
- * });
4977
- * const result = await store.subgraph(rootId, { edges: ["uses_skill"], project });
4978
- * // result.nodes narrowed correctly — task.status is a type error
4979
- * ```
4980
- */
4981
- declare function defineSubgraphProject<G extends GraphDef>(_graph: G): <const P extends SubgraphProject<G>>(project: P) => P;
4982
- type HasMeta<Selection extends readonly string[] | undefined> = Selection extends readonly string[] ? "meta" extends Selection[number] ? true : false : false;
4983
- type SelectedNodeProps<N extends NodeType, Selection extends readonly string[] | undefined> = Selection extends readonly string[] ? Pick<Node<N>, Extract<Selection[number], NodeProjectionPropertyKey<N>>> : EmptyShape;
4984
- type SelectedEdgeProps<E extends AnyEdgeType, Selection extends readonly string[] | undefined> = Selection extends readonly string[] ? Pick<Edge<E>, Extract<Selection[number], EdgeProjectionPropertyKey<E>>> : EmptyShape;
4985
- type ProjectedNodeResult<N extends NodeType, Selection extends readonly string[] | undefined> = Readonly<Pick<Node<N>, "id" | "kind">> & Readonly<SelectedNodeProps<N, Selection>> & (HasMeta<Selection> extends true ? Readonly<{
4986
- meta: NodeMeta;
4987
- }> : EmptyShape);
4988
- type ProjectedEdgeResult<E extends AnyEdgeType, Selection extends readonly string[] | undefined> = Readonly<Pick<Edge<E>, "id" | "kind" | "fromKind" | "fromId" | "toKind" | "toId">> & Readonly<SelectedEdgeProps<E, Selection>> & (HasMeta<Selection> extends true ? Readonly<{
4989
- meta: EdgeMeta;
4990
- }> : EmptyShape);
4991
- type ProjectionSelection<P, Key extends "nodes" | "edges", Kind extends string> = P extends Readonly<{
4992
- [K in Key]?: infer Map;
4993
- }> ? Map extends Readonly<Record<string, readonly string[] | undefined>> ? Kind extends keyof Map ? Map[Kind] : undefined : undefined : undefined;
4994
- type SubgraphNodeResultForKind<G extends GraphDef, Kind extends NodeKinds<G>, P> = ProjectionSelection<P, "nodes", Kind> extends readonly string[] ? ProjectedNodeResult<G["nodes"][Kind]["type"], ProjectionSelection<P, "nodes", Kind>> : Node<G["nodes"][Kind]["type"]>;
4995
- type SubgraphEdgeResultForKind<G extends GraphDef, Kind extends EdgeKinds<G>, P> = ProjectionSelection<P, "edges", Kind> extends readonly string[] ? ProjectedEdgeResult<G["edges"][Kind]["type"], ProjectionSelection<P, "edges", Kind>> : Edge<G["edges"][Kind]["type"]>;
4996
- type SubgraphOptions<G extends GraphDef, EK extends EdgeKinds<G>, NK extends NodeKinds<G>, P extends SubgraphProject<G, NK, EK> | undefined = undefined> = Readonly<{
4997
- /** Edge kinds to follow during traversal. Edges not listed are not traversed. */
4998
- edges: readonly EK[];
4999
- /** Maximum traversal depth from root (default: 10). */
5000
- maxDepth?: number;
5001
- /**
5002
- * Node kinds to include in the result. Nodes of other kinds are still
5003
- * traversed through but omitted from the output. When omitted, all
5004
- * reachable node kinds are included.
5005
- */
5006
- includeKinds?: readonly NK[];
5007
- /** Exclude the root node from the result (default: false). */
5008
- excludeRoot?: boolean;
5009
- /**
5010
- * Edge direction policy (default: "out").
5011
- * - "out": follow edges in their defined direction only
5012
- * - "both": follow edges in both directions (undirected traversal)
5013
- */
5014
- direction?: "out" | "both";
5015
- /** Cycle policy — reuse RecursiveCyclePolicy (default: "prevent"). */
5016
- cyclePolicy?: RecursiveCyclePolicy;
5017
- /**
5018
- * Temporal mode applied to both nodes and edges along the traversal and in
5019
- * the hydrated result. Defaults to `graph.defaults.temporalMode`.
5020
- */
5021
- temporalMode?: TemporalMode;
5022
- /** ISO-8601 timestamp used when `temporalMode === "asOf"`. */
5023
- asOf?: string;
5024
- /** @internal Recorded coordinates are supplied by StoreView only. */
5025
- recordedAsOf?: never;
5026
- /**
5027
- * Optional field-level projection per node/edge kind.
5028
- *
5029
- * Projected nodes keep `kind` and `id`; projected edges keep their structural
5030
- * endpoint fields. Kinds omitted from `project` remain fully hydrated.
5031
- * Projection applies to every returned entity, including the root node.
5032
- *
5033
- * Only kinds present in `includeKinds` (nodes) or `edges` (edges) are valid
5034
- * projection keys. Specifying a kind outside those sets is a compile-time error.
5035
- */
5036
- project?: P;
5037
- /**
5038
- * Per-edge-kind windows applied while traversing and hydrating. Each limit
5039
- * is partitioned by the current endpoint, so append-only edge histories can
5040
- * contribute only their newest N targets at every hop.
5041
- */
5042
- edgeWindows?: Readonly<Partial<Record<EK, EdgeReadWindow>>>;
5043
- }>;
5044
- /**
5045
- * Subgraph options as seen by the internal executor: identical to the public
5046
- * {@link SubgraphOptions} except the recorded/system-time pin is a branded
5047
- * instant the StoreView seam supplies. The public surface keeps
5048
- * `recordedAsOf?: never`;
5049
- * recorded reads reach the executor only through `store.subgraphAtCoordinate`.
5050
- */
5051
- type InternalSubgraphOptions<G extends GraphDef, EK extends EdgeKinds<G>, NK extends NodeKinds<G>, P extends SubgraphProject<G, NK, EK> | undefined = undefined> = Omit<SubgraphOptions<G, EK, NK, P>, "recordedAsOf"> & Readonly<{
5052
- recordedAsOf?: RecordedInstant;
5053
- }>;
5054
- /**
5055
- * Union of all node result types in a subgraph, respecting projection.
5056
- */
5057
- type SubgraphNodeResult<G extends GraphDef, NK extends NodeKinds<G> = NodeKinds<G>, P = undefined> = {
5058
- [Kind in NK]: SubgraphNodeResultForKind<G, Kind, P>;
5059
- }[NK];
5060
- /**
5061
- * Union of all edge result types in a subgraph, respecting projection.
5062
- */
5063
- type SubgraphEdgeResult<G extends GraphDef, EK extends EdgeKinds<G> = EdgeKinds<G>, P = undefined> = {
5064
- [Kind in EK]: SubgraphEdgeResultForKind<G, Kind, P>;
5065
- }[EK];
5066
- type SubgraphResult<G extends GraphDef, NK extends NodeKinds<G> = NodeKinds<G>, EK extends EdgeKinds<G> = EdgeKinds<G>, P extends SubgraphProject<G, NK, EK> | undefined = undefined> = Readonly<{
5067
- /** The root node, or undefined if the root was not found or excluded. */
5068
- root: SubgraphNodeResult<G, NK, P> | undefined;
5069
- nodes: ReadonlyMap<string, SubgraphNodeResult<G, NK, P>>;
5070
- /** Forward adjacency: fromId → edgeKind → edges to targets. */
5071
- adjacency: ReadonlyMap<string, ReadonlyMap<EK, readonly SubgraphEdgeResult<G, EK, P>[]>>;
5072
- /** Reverse adjacency: toId → edgeKind → edges from sources. */
5073
- reverseAdjacency: ReadonlyMap<string, ReadonlyMap<EK, readonly SubgraphEdgeResult<G, EK, P>[]>>;
5074
- }>;
5075
-
5076
5086
  declare const STORE_RUNTIME: unique symbol;
5077
5087
  /**
5078
5088
  * @internal Operations used by Store-owned views. The port is absent from the