@nicia-ai/typegraph 0.3.1 → 0.5.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 (73) hide show
  1. package/dist/backend/drizzle/index.cjs +6 -6
  2. package/dist/backend/drizzle/index.d.cts +1 -1
  3. package/dist/backend/drizzle/index.d.ts +1 -1
  4. package/dist/backend/drizzle/index.js +4 -4
  5. package/dist/backend/drizzle/postgres.cjs +4 -4
  6. package/dist/backend/drizzle/postgres.d.cts +1 -1
  7. package/dist/backend/drizzle/postgres.d.ts +1 -1
  8. package/dist/backend/drizzle/postgres.js +3 -3
  9. package/dist/backend/drizzle/sqlite.cjs +4 -4
  10. package/dist/backend/drizzle/sqlite.d.cts +1 -1
  11. package/dist/backend/drizzle/sqlite.d.ts +1 -1
  12. package/dist/backend/drizzle/sqlite.js +3 -3
  13. package/dist/backend/postgres/index.cjs +4 -4
  14. package/dist/backend/postgres/index.d.cts +1 -1
  15. package/dist/backend/postgres/index.d.ts +1 -1
  16. package/dist/backend/postgres/index.js +3 -3
  17. package/dist/backend/sqlite/index.cjs +6 -6
  18. package/dist/backend/sqlite/index.d.cts +1 -1
  19. package/dist/backend/sqlite/index.d.ts +1 -1
  20. package/dist/backend/sqlite/index.js +4 -4
  21. package/dist/{chunk-OYL2SGBD.cjs → chunk-44SXEVF4.cjs} +18 -2
  22. package/dist/chunk-44SXEVF4.cjs.map +1 -0
  23. package/dist/{chunk-F2BZSEFE.js → chunk-4MTYE6CF.js} +4 -4
  24. package/dist/{chunk-F2BZSEFE.js.map → chunk-4MTYE6CF.js.map} +1 -1
  25. package/dist/{chunk-4HARSV2G.js → chunk-6HFWKZU5.js} +61 -3
  26. package/dist/chunk-6HFWKZU5.js.map +1 -0
  27. package/dist/{chunk-F23W4W3A.cjs → chunk-ENXM4W4M.cjs} +18 -18
  28. package/dist/{chunk-F23W4W3A.cjs.map → chunk-ENXM4W4M.cjs.map} +1 -1
  29. package/dist/{chunk-ZJHQZZT2.cjs → chunk-K2ROKOK3.cjs} +6 -6
  30. package/dist/{chunk-ZJHQZZT2.cjs.map → chunk-K2ROKOK3.cjs.map} +1 -1
  31. package/dist/{chunk-46YY2FRV.js → chunk-KKFJJYCP.js} +3 -3
  32. package/dist/{chunk-46YY2FRV.js.map → chunk-KKFJJYCP.js.map} +1 -1
  33. package/dist/{chunk-CMHFS34N.cjs → chunk-KPU6TLUV.cjs} +16 -16
  34. package/dist/{chunk-CMHFS34N.cjs.map → chunk-KPU6TLUV.cjs.map} +1 -1
  35. package/dist/{chunk-DD6ONEBN.cjs → chunk-LDM2AFKZ.cjs} +12 -12
  36. package/dist/{chunk-DD6ONEBN.cjs.map → chunk-LDM2AFKZ.cjs.map} +1 -1
  37. package/dist/{chunk-NP4G4ZKM.js → chunk-M5SOQ7UV.js} +4 -4
  38. package/dist/{chunk-NP4G4ZKM.js.map → chunk-M5SOQ7UV.js.map} +1 -1
  39. package/dist/{chunk-SFY2PPOY.cjs → chunk-PW5BSBZV.cjs} +68 -10
  40. package/dist/chunk-PW5BSBZV.cjs.map +1 -0
  41. package/dist/{chunk-O5XPCJLF.js → chunk-SJ2QMDXY.js} +18 -3
  42. package/dist/chunk-SJ2QMDXY.js.map +1 -0
  43. package/dist/{chunk-XDTYTNYL.js → chunk-TGDFBLGS.js} +3 -3
  44. package/dist/{chunk-XDTYTNYL.js.map → chunk-TGDFBLGS.js.map} +1 -1
  45. package/dist/{index-Dkicw49A.d.ts → index-DyrR_d-H.d.cts} +9 -1
  46. package/dist/{index-Dkicw49A.d.cts → index-DyrR_d-H.d.ts} +9 -1
  47. package/dist/index.cjs +1130 -218
  48. package/dist/index.cjs.map +1 -1
  49. package/dist/index.d.cts +7 -7
  50. package/dist/index.d.ts +7 -7
  51. package/dist/index.js +924 -16
  52. package/dist/index.js.map +1 -1
  53. package/dist/interchange/index.cjs +7 -7
  54. package/dist/interchange/index.d.cts +3 -3
  55. package/dist/interchange/index.d.ts +3 -3
  56. package/dist/interchange/index.js +2 -2
  57. package/dist/{manager-e9LXthrx.d.ts → manager-DXC7CqKG.d.ts} +1 -1
  58. package/dist/{manager-Jc5Btay9.d.cts → manager-DiPf-0GG.d.cts} +1 -1
  59. package/dist/profiler/index.d.cts +3 -3
  60. package/dist/profiler/index.d.ts +3 -3
  61. package/dist/schema/index.cjs +22 -22
  62. package/dist/schema/index.d.cts +5 -5
  63. package/dist/schema/index.d.ts +5 -5
  64. package/dist/schema/index.js +4 -4
  65. package/dist/{store-DM3Tk3Pw.d.ts → store-DODIWZxC.d.ts} +145 -7
  66. package/dist/{store-nbBybLWP.d.cts → store-nDW3GOFb.d.cts} +145 -7
  67. package/dist/{types-Cdbi4hcx.d.ts → types-DpIoePMI.d.ts} +19 -0
  68. package/dist/{types-DDP0MGBF.d.cts → types-WX8V9dqn.d.cts} +19 -0
  69. package/package.json +2 -2
  70. package/dist/chunk-4HARSV2G.js.map +0 -1
  71. package/dist/chunk-O5XPCJLF.js.map +0 -1
  72. package/dist/chunk-OYL2SGBD.cjs.map +0 -1
  73. package/dist/chunk-SFY2PPOY.cjs.map +0 -1
@@ -1,5 +1,5 @@
1
- import { k as SqlSchema, G as GraphBackend } from './types-DDP0MGBF.cjs';
2
- import { K as KindRegistry, G as GraphDef, b as SchemaManagerOptions, c as SchemaValidationResult } from './manager-Jc5Btay9.cjs';
1
+ import { k as SqlSchema, G as GraphBackend } from './types-WX8V9dqn.cjs';
2
+ import { K as KindRegistry, G as GraphDef, b as SchemaManagerOptions, c as SchemaValidationResult } from './manager-DiPf-0GG.cjs';
3
3
  import { N as NodeType, A as AnyEdgeType, T as TemporalMode, E as EdgeType, b as EdgeRegistration, g as NodeId } from './types-DTJEu_-h.cjs';
4
4
  import { V as ValueType, i as PredicateExpression, k as VectorMetricType, Q as QueryAst, J as JsonPointer, F as FieldRef, P as ParameterRef, d as JsonPointerInput, T as TraversalExpansion, l as Traversal, N as NodePredicate, m as ProjectedField, O as OrderSpec, G as GroupBySpec, o as RecursiveCyclePolicy, q as TraversalDirection, A as AggregateExpr, r as SelectiveField, s as ComposableQuery, t as SetOperationType, u as SetOperation, S as SortDirection } from './ast-D-3bOanX.cjs';
5
5
  import { SQL } from 'drizzle-orm';
@@ -724,7 +724,7 @@ type OperationHookContext = HookContext & Readonly<{
724
724
  /**
725
725
  * Observability hooks for monitoring store operations.
726
726
  *
727
- * Note: Batch operations (`bulkCreate`, `bulkInsert`, `bulkUpsert`) skip
727
+ * Note: Batch operations (`bulkCreate`, `bulkInsert`, `bulkUpsertById`) skip
728
728
  * per-item operation hooks for throughput. Query hooks still fire normally.
729
729
  *
730
730
  * @example
@@ -776,6 +776,59 @@ type StoreOptions = Readonly<{
776
776
  traversalExpansion?: TraversalExpansion;
777
777
  }>;
778
778
  }>;
779
+ /**
780
+ * Behavior when a get-or-create operation matches an existing record.
781
+ */
782
+ type IfExistsMode = "return" | "update";
783
+ /**
784
+ * Action taken by a get-or-create operation.
785
+ */
786
+ type GetOrCreateAction = "created" | "found" | "updated" | "resurrected";
787
+ /**
788
+ * Result of a node getOrCreateByConstraint operation.
789
+ */
790
+ type NodeGetOrCreateByConstraintResult<N extends NodeType> = Readonly<{
791
+ node: Node<N>;
792
+ action: GetOrCreateAction;
793
+ }>;
794
+ /**
795
+ * Options for node getOrCreateByConstraint operations.
796
+ */
797
+ type NodeGetOrCreateByConstraintOptions = Readonly<{
798
+ /** Existing record behavior. Default: "return" */
799
+ ifExists?: IfExistsMode;
800
+ }>;
801
+ /**
802
+ * Result of an edge getOrCreateByEndpoints operation.
803
+ */
804
+ type EdgeGetOrCreateByEndpointsResult<E extends AnyEdgeType> = Readonly<{
805
+ edge: Edge<E>;
806
+ action: GetOrCreateAction;
807
+ }>;
808
+ /**
809
+ * Options for edge findByEndpoints operations.
810
+ */
811
+ type EdgeFindByEndpointsOptions<E extends AnyEdgeType> = Readonly<{
812
+ /**
813
+ * Edge property fields to include in the match alongside the (from, to) endpoints.
814
+ * When omitted, matches on endpoints only (returns first live edge).
815
+ */
816
+ matchOn?: readonly (keyof z.input<E["schema"]>)[];
817
+ /** Property values to match against when matchOn is specified. */
818
+ props?: Partial<z.input<E["schema"]>>;
819
+ }>;
820
+ /**
821
+ * Options for edge getOrCreateByEndpoints operations.
822
+ */
823
+ type EdgeGetOrCreateByEndpointsOptions<E extends AnyEdgeType> = Readonly<{
824
+ /**
825
+ * Edge property fields to include in the match key alongside the (from, to) endpoints.
826
+ * Default: `[]` — match on endpoints only.
827
+ */
828
+ matchOn?: readonly (keyof z.input<E["schema"]>)[];
829
+ /** Existing record behavior. Default: "return" */
830
+ ifExists?: IfExistsMode;
831
+ }>;
779
832
  /**
780
833
  * A collection of nodes of a specific type.
781
834
  *
@@ -831,7 +884,7 @@ type NodeCollection<N extends NodeType> = Readonly<{
831
884
  * If a node with the given ID exists, updates it with the provided props.
832
885
  * Otherwise, creates a new node with that ID.
833
886
  */
834
- upsert: (id: string, props: z.input<N["schema"]>, options?: Readonly<{
887
+ upsertById: (id: string, props: z.input<N["schema"]>, options?: Readonly<{
835
888
  validFrom?: string;
836
889
  validTo?: string;
837
890
  }>) => Promise<Node<N>>;
@@ -853,7 +906,7 @@ type NodeCollection<N extends NodeType> = Readonly<{
853
906
  * For each item, if a node with the given ID exists, updates it.
854
907
  * Otherwise, creates a new node with that ID.
855
908
  */
856
- bulkUpsert: (items: readonly Readonly<{
909
+ bulkUpsertById: (items: readonly Readonly<{
857
910
  id: string;
858
911
  props: z.input<N["schema"]>;
859
912
  validFrom?: string;
@@ -879,6 +932,46 @@ type NodeCollection<N extends NodeType> = Readonly<{
879
932
  * that don't exist.
880
933
  */
881
934
  bulkDelete: (ids: readonly NodeId<N>[]) => Promise<void>;
935
+ /**
936
+ * Find a node by uniqueness constraint.
937
+ *
938
+ * Looks up a live node by the named constraint key computed from `props`.
939
+ * Returns the node if found, or undefined. Soft-deleted nodes are excluded.
940
+ *
941
+ * @param constraintName - Name of the uniqueness constraint to match on
942
+ * @param props - Properties to compute the constraint key from
943
+ */
944
+ findByConstraint: (constraintName: string, props: z.input<N["schema"]>) => Promise<Node<N> | undefined>;
945
+ /**
946
+ * Batch version of findByConstraint.
947
+ *
948
+ * Results are returned in the same order as the input items.
949
+ * Returns undefined for entries that don't match.
950
+ */
951
+ bulkFindByConstraint: (constraintName: string, items: readonly Readonly<{
952
+ props: z.input<N["schema"]>;
953
+ }>[]) => Promise<(Node<N> | undefined)[]>;
954
+ /**
955
+ * Get an existing node by uniqueness constraint, or create a new one.
956
+ *
957
+ * Looks up a node by the named constraint key computed from `props`.
958
+ * If found, returns it (optionally updating with `ifExists: "update"`).
959
+ * If not found, creates a new node. Soft-deleted matches are always resurrected.
960
+ *
961
+ * @param constraintName - Name of the uniqueness constraint to match on
962
+ * @param props - Full properties for create, or merge source for update
963
+ * @param options - Existing record behavior (default: "return")
964
+ */
965
+ getOrCreateByConstraint: (constraintName: string, props: z.input<N["schema"]>, options?: NodeGetOrCreateByConstraintOptions) => Promise<NodeGetOrCreateByConstraintResult<N>>;
966
+ /**
967
+ * Batch version of getOrCreateByConstraint.
968
+ *
969
+ * Results are returned in the same order as the input items.
970
+ * Atomic when the backend supports transactions.
971
+ */
972
+ bulkGetOrCreateByConstraint: (constraintName: string, items: readonly Readonly<{
973
+ props: z.input<N["schema"]>;
974
+ }>[], options?: NodeGetOrCreateByConstraintOptions) => Promise<NodeGetOrCreateByConstraintResult<N>[]>;
882
975
  }>;
883
976
  /**
884
977
  * Reference to a node endpoint (kind and id).
@@ -1011,7 +1104,7 @@ type EdgeCollection<E extends AnyEdgeType, From extends NodeType = NodeType, To
1011
1104
  * For each item, if an edge with the given ID exists, updates it.
1012
1105
  * Otherwise, creates a new edge with that ID.
1013
1106
  */
1014
- bulkUpsert: (items: readonly Readonly<{
1107
+ bulkUpsertById: (items: readonly Readonly<{
1015
1108
  id: string;
1016
1109
  from: TypedNodeRef<From>;
1017
1110
  to: TypedNodeRef<To>;
@@ -1041,6 +1134,41 @@ type EdgeCollection<E extends AnyEdgeType, From extends NodeType = NodeType, To
1041
1134
  * that don't exist.
1042
1135
  */
1043
1136
  bulkDelete: (ids: readonly string[]) => Promise<void>;
1137
+ /**
1138
+ * Find a live edge by endpoints and optional property fields.
1139
+ *
1140
+ * Returns the first matching live edge, or undefined.
1141
+ * Soft-deleted edges are excluded.
1142
+ *
1143
+ * @param from - Source node
1144
+ * @param to - Target node
1145
+ * @param options - Match criteria (matchOn fields and property values)
1146
+ */
1147
+ findByEndpoints: (from: TypedNodeRef<From>, to: TypedNodeRef<To>, options?: EdgeFindByEndpointsOptions<E>) => Promise<Edge<E> | undefined>;
1148
+ /**
1149
+ * Get an existing edge by endpoints and optional property fields, or create a new one.
1150
+ *
1151
+ * Matches edges of this kind between `(from, to)`. When `matchOn` specifies
1152
+ * property fields, only edges whose properties match on those fields are considered.
1153
+ * Soft-deleted matches are resurrected when cardinality allows.
1154
+ *
1155
+ * @param from - Source node
1156
+ * @param to - Target node
1157
+ * @param props - Full properties for create, or merge source for update
1158
+ * @param options - Match criteria and conflict resolution
1159
+ */
1160
+ getOrCreateByEndpoints: (from: TypedNodeRef<From>, to: TypedNodeRef<To>, props: z.input<E["schema"]>, options?: EdgeGetOrCreateByEndpointsOptions<E>) => Promise<EdgeGetOrCreateByEndpointsResult<E>>;
1161
+ /**
1162
+ * Batch version of getOrCreateByEndpoints.
1163
+ *
1164
+ * Results are returned in the same order as the input items.
1165
+ * Atomic when the backend supports transactions.
1166
+ */
1167
+ bulkGetOrCreateByEndpoints: (items: readonly Readonly<{
1168
+ from: TypedNodeRef<From>;
1169
+ to: TypedNodeRef<To>;
1170
+ props: z.input<E["schema"]>;
1171
+ }>[], options?: EdgeGetOrCreateByEndpointsOptions<E>) => Promise<EdgeGetOrCreateByEndpointsResult<E>[]>;
1044
1172
  }>;
1045
1173
  /**
1046
1174
  * Extract the union of 'from' node types from an EdgeRegistration.
@@ -1747,6 +1875,16 @@ declare class Store<G extends GraphDef> {
1747
1875
  * ```
1748
1876
  */
1749
1877
  transaction<T>(fn: (tx: TransactionContext<G>) => Promise<T>): Promise<T>;
1878
+ /**
1879
+ * Hard-deletes all data for this graph from the database.
1880
+ *
1881
+ * Removes all nodes, edges, uniqueness entries, embeddings, and schema versions
1882
+ * for this graph's ID. No hooks, no per-row logic. Wrapped in a transaction
1883
+ * when the backend supports it.
1884
+ *
1885
+ * The store is usable after clearing — new data can be created immediately.
1886
+ */
1887
+ clear(): Promise<void>;
1750
1888
  /**
1751
1889
  * Closes the store and releases underlying resources.
1752
1890
  *
@@ -1817,4 +1955,4 @@ declare function createStore<G extends GraphDef>(graph: G, backend: GraphBackend
1817
1955
  */
1818
1956
  declare function createStoreWithSchema<G extends GraphDef>(graph: G, backend: GraphBackend, options?: StoreOptions & SchemaManagerOptions): Promise<[Store<G>, SchemaValidationResult]>;
1819
1957
 
1820
- export { notExists as $, type AliasMap as A, type TransactionContext as B, type CreateQueryBuilderOptions as C, type TypedEdgeCollection as D, type EdgeAliasMap as E, type FieldAccessor as F, type TypedNodeRef as G, type HookContext as H, type UpdateEdgeInput as I, type UpdateNodeInput as J, createStore as K, createStoreWithSchema as L, embedding as M, type Node as N, type OperationHookContext as O, type PaginateOptions as P, QueryBuilder as Q, type RecursiveTraversalOptions as R, Store as S, TraversalBuilder as T, UnionableQuery as U, exists as V, fieldRef as W, getEmbeddingDimensions as X, inSubquery as Y, isEmbeddingSchema as Z, isParameterRef as _, type AggregateResult as a, notInSubquery as a0, param as a1, type CreateEdgeInput as b, type CreateNodeInput as c, type Edge as d, type EdgeAccessor as e, type EdgeCollection as f, type EmbeddingSchema as g, type EmbeddingValue as h, ExecutableAggregateQuery as i, ExecutableQuery as j, type NodeAccessor as k, type NodeAlias as l, type NodeCollection as m, type NodeRef as n, type PaginatedResult as o, type Predicate as p, PreparedQuery as q, type PropsAccessor as r, type QueryHookContext as s, type QueryOptions as t, type SelectContext as u, type SelectableEdge as v, type SelectableNode as w, type StoreHooks as x, type StoreOptions as y, type StreamOptions as z };
1958
+ export { embedding as $, type AliasMap as A, type SelectableEdge as B, type CreateQueryBuilderOptions as C, type SelectableNode as D, type EdgeAliasMap as E, type FieldAccessor as F, type GetOrCreateAction as G, type HookContext as H, type IfExistsMode as I, type StoreHooks as J, type StoreOptions as K, type StreamOptions as L, type TransactionContext as M, type Node as N, type OperationHookContext as O, type PaginateOptions as P, QueryBuilder as Q, type RecursiveTraversalOptions as R, Store as S, TraversalBuilder as T, type TypedEdgeCollection as U, type TypedNodeRef as V, UnionableQuery as W, type UpdateEdgeInput as X, type UpdateNodeInput as Y, createStore as Z, createStoreWithSchema as _, type AggregateResult as a, exists as a0, fieldRef as a1, getEmbeddingDimensions as a2, inSubquery as a3, isEmbeddingSchema as a4, isParameterRef as a5, notExists as a6, notInSubquery as a7, param as a8, type CreateEdgeInput as b, type CreateNodeInput as c, type Edge as d, type EdgeAccessor as e, type EdgeCollection as f, type EdgeFindByEndpointsOptions as g, type EdgeGetOrCreateByEndpointsOptions as h, type EdgeGetOrCreateByEndpointsResult as i, type EmbeddingSchema as j, type EmbeddingValue as k, ExecutableAggregateQuery as l, ExecutableQuery as m, type NodeAccessor as n, type NodeAlias as o, type NodeCollection as p, type NodeGetOrCreateByConstraintOptions as q, type NodeGetOrCreateByConstraintResult as r, type NodeRef as s, type PaginatedResult as t, type Predicate as u, PreparedQuery as v, type PropsAccessor as w, type QueryHookContext as x, type QueryOptions as y, type SelectContext as z };
@@ -572,6 +572,7 @@ type GraphBackend = Readonly<{
572
572
  insertUnique: (params: InsertUniqueParams) => Promise<void>;
573
573
  deleteUnique: (params: DeleteUniqueParams) => Promise<void>;
574
574
  checkUnique: (params: CheckUniqueParams) => Promise<UniqueRow | undefined>;
575
+ checkUniqueBatch?: (params: CheckUniqueBatchParams) => Promise<readonly UniqueRow[]>;
575
576
  getActiveSchema: (graphId: string) => Promise<SchemaVersionRow | undefined>;
576
577
  getSchemaVersion: (graphId: string, version: number) => Promise<SchemaVersionRow | undefined>;
577
578
  insertSchema: (params: InsertSchemaParams) => Promise<SchemaVersionRow>;
@@ -582,6 +583,11 @@ type GraphBackend = Readonly<{
582
583
  vectorSearch?: (params: VectorSearchParams) => Promise<readonly VectorSearchResult[]>;
583
584
  createVectorIndex?: (params: CreateVectorIndexParams) => Promise<void>;
584
585
  dropVectorIndex?: (params: DropVectorIndexParams) => Promise<void>;
586
+ /**
587
+ * Hard-deletes all data for a graph (nodes, edges, uniques, embeddings, schema versions).
588
+ * Intended for import-replacement workflows. No hooks, no per-row logic.
589
+ */
590
+ clearGraph: (graphId: string) => Promise<void>;
585
591
  execute: <T>(query: SQL) => Promise<readonly T[]>;
586
592
  /** Execute pre-compiled SQL text with bound parameters. Available on sync SQLite and pg backends. */
587
593
  executeRaw?: <T>(sqlText: string, params: readonly unknown[]) => Promise<readonly T[]>;
@@ -621,6 +627,19 @@ type CheckUniqueParams = Readonly<{
621
627
  nodeKind: string;
622
628
  constraintName: string;
623
629
  key: string;
630
+ /** If true, also returns soft-deleted entries. Used by get-or-create operations. */
631
+ includeDeleted?: boolean;
632
+ }>;
633
+ /**
634
+ * Parameters for batch-checking unique constraints.
635
+ */
636
+ type CheckUniqueBatchParams = Readonly<{
637
+ graphId: string;
638
+ nodeKind: string;
639
+ constraintName: string;
640
+ keys: readonly string[];
641
+ /** If true, also returns soft-deleted entries. Used by get-or-create operations. */
642
+ includeDeleted?: boolean;
624
643
  }>;
625
644
  /**
626
645
  * Parameters for inserting a schema version.
@@ -572,6 +572,7 @@ type GraphBackend = Readonly<{
572
572
  insertUnique: (params: InsertUniqueParams) => Promise<void>;
573
573
  deleteUnique: (params: DeleteUniqueParams) => Promise<void>;
574
574
  checkUnique: (params: CheckUniqueParams) => Promise<UniqueRow | undefined>;
575
+ checkUniqueBatch?: (params: CheckUniqueBatchParams) => Promise<readonly UniqueRow[]>;
575
576
  getActiveSchema: (graphId: string) => Promise<SchemaVersionRow | undefined>;
576
577
  getSchemaVersion: (graphId: string, version: number) => Promise<SchemaVersionRow | undefined>;
577
578
  insertSchema: (params: InsertSchemaParams) => Promise<SchemaVersionRow>;
@@ -582,6 +583,11 @@ type GraphBackend = Readonly<{
582
583
  vectorSearch?: (params: VectorSearchParams) => Promise<readonly VectorSearchResult[]>;
583
584
  createVectorIndex?: (params: CreateVectorIndexParams) => Promise<void>;
584
585
  dropVectorIndex?: (params: DropVectorIndexParams) => Promise<void>;
586
+ /**
587
+ * Hard-deletes all data for a graph (nodes, edges, uniques, embeddings, schema versions).
588
+ * Intended for import-replacement workflows. No hooks, no per-row logic.
589
+ */
590
+ clearGraph: (graphId: string) => Promise<void>;
585
591
  execute: <T>(query: SQL) => Promise<readonly T[]>;
586
592
  /** Execute pre-compiled SQL text with bound parameters. Available on sync SQLite and pg backends. */
587
593
  executeRaw?: <T>(sqlText: string, params: readonly unknown[]) => Promise<readonly T[]>;
@@ -621,6 +627,19 @@ type CheckUniqueParams = Readonly<{
621
627
  nodeKind: string;
622
628
  constraintName: string;
623
629
  key: string;
630
+ /** If true, also returns soft-deleted entries. Used by get-or-create operations. */
631
+ includeDeleted?: boolean;
632
+ }>;
633
+ /**
634
+ * Parameters for batch-checking unique constraints.
635
+ */
636
+ type CheckUniqueBatchParams = Readonly<{
637
+ graphId: string;
638
+ nodeKind: string;
639
+ constraintName: string;
640
+ keys: readonly string[];
641
+ /** If true, also returns soft-deleted entries. Used by get-or-create operations. */
642
+ includeDeleted?: boolean;
624
643
  }>;
625
644
  /**
626
645
  * Parameters for inserting a schema version.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicia-ai/typegraph",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "description": "TypeScript-first embedded knowledge graph library with ontological reasoning",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -183,7 +183,7 @@
183
183
  "@vitest/coverage-v8": "^4.0.18",
184
184
  "better-sqlite3": "^12.6.2",
185
185
  "drizzle-orm": "^0.45.1",
186
- "eslint": "^9.39.2",
186
+ "eslint": "^9.39.3",
187
187
  "fast-check": "^4.5.3",
188
188
  "pg": "^8.18.0",
189
189
  "sqlite-vec": "0.1.7-alpha.2",