@petrarca/sonnet-graph 0.7.0 → 0.8.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.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import * as zustand from 'zustand';
2
- import { UseBoundStore, StoreApi } from 'zustand';
3
1
  import * as React from 'react';
4
2
  import React__default, { ReactNode } from 'react';
3
+ import * as zustand from 'zustand';
4
+ import { UseBoundStore, StoreApi } from 'zustand';
5
5
  import { GraphEdge, GraphNode } from 'reagraph';
6
6
  import cytoscape from 'cytoscape';
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -272,6 +272,107 @@ declare function normalizeGraph(nodes: VisualGraphNode[], edges: VisualGraphEdge
272
272
  */
273
273
  declare const EMPTY_NORMALIZED: VisualGraphNormalized;
274
274
 
275
+ /**
276
+ * Extracts graph elements from tabular Cypher query rows.
277
+ *
278
+ * cypher-graphdb (the underlying graph-database library) serializes a
279
+ * node/relationship RETURN-column value wrapped as `{ node: RawGraphNode }` /
280
+ * `{ edge: RawGraphEdge }` (its `serialize_model(with_type=True)` default,
281
+ * shared by every consumer of a cypher-graphdb-backed Cypher endpoint) --
282
+ * scalar columns (a property projection, an aggregate) are unwrapped plain
283
+ * values. A host whose backend returns query results as plain tabular rows
284
+ * (rather than a pre-shaped `{ nodes, edges }` response) uses this to decide
285
+ * whether a result is graph-shaped at all and to collect its elements, deduped
286
+ * by `id_` (the same node/edge commonly repeats across rows).
287
+ */
288
+ interface ExtractedGraphRows {
289
+ nodes: RawGraphNode[];
290
+ edges: RawGraphEdge[];
291
+ /** True if any row cell was a wrapped node/edge -- the result has something to draw. */
292
+ isGraph: boolean;
293
+ }
294
+ /** Scan tabular rows (each an array of RETURN-column cell values) for wrapped node/edge cells. */
295
+ declare function extractGraphFromRows(rows: unknown[][]): ExtractedGraphRows;
296
+
297
+ /**
298
+ * QueryEditor -- a pure, reusable query editor (no store or app dependencies).
299
+ *
300
+ * A props-based editor for graph query languages (Cypher, Datalog, ...): an
301
+ * auto-sizing textarea, Ctrl/Cmd+Enter to execute, an inline error alert with
302
+ * copy-to-clipboard, and an optional custom action-button slot. Every host
303
+ * (an app's own query bar, a graph workbench) drives it purely through props,
304
+ * so it carries none of the caller's state.
305
+ *
306
+ * Promoted into sonnet-graph from the cypher-graphdb explorer, decoupled from
307
+ * that app's clipboard hook (uses sonnet-core's copyTextToClipboard).
308
+ */
309
+
310
+ interface QueryEditorProps {
311
+ /** Current query text value. */
312
+ value: string;
313
+ /** Called when the user executes (Ctrl/Cmd+Enter or the Run button). */
314
+ onExecute: (query: string) => void;
315
+ /** Called when the query text changes. */
316
+ onChange?: (query: string) => void;
317
+ /** Whether execution is in progress. */
318
+ isLoading?: boolean;
319
+ /** Error message to display (null = none). */
320
+ error?: string | null;
321
+ /** Placeholder for the empty editor. */
322
+ placeholder?: string;
323
+ /** Minimum rows (default 1). */
324
+ minRows?: number;
325
+ /** Maximum rows before the textarea scrolls (default 12). */
326
+ maxRows?: number;
327
+ /** Extra class on the wrapper. */
328
+ className?: string;
329
+ /** Custom action buttons (replaces the default Run button). */
330
+ renderActions?: (props: {
331
+ onExecute: () => void;
332
+ isLoading: boolean;
333
+ }) => React__default.ReactNode;
334
+ }
335
+ declare function QueryEditor({ value, onExecute, onChange, isLoading, error, placeholder, minRows, maxRows, className, renderActions, }: QueryEditorProps): React__default.ReactElement;
336
+
337
+ /**
338
+ * createQueryHistoryStore -- a persisted list of recently-run query strings.
339
+ *
340
+ * A reusable Zustand store factory for a graph query editor's history: add()
341
+ * prepends (de-duping repeats), the list is capped, and it persists to
342
+ * localStorage under a caller-chosen key so history survives reloads. Language-
343
+ * and backend-agnostic (it stores plain query text), so any editor -- Cypher,
344
+ * Datalog -- can use it. The consuming app creates one instance and shares it
345
+ * between the query bar (which add()s on run) and the History dropdown.
346
+ */
347
+
348
+ interface QueryHistoryState {
349
+ queries: string[];
350
+ add: (query: string) => void;
351
+ clear: () => void;
352
+ }
353
+ type QueryHistoryStore = UseBoundStore<StoreApi<QueryHistoryState>>;
354
+ /**
355
+ * Build a persisted query-history store.
356
+ *
357
+ * @param persistKey localStorage key (unique per editor, e.g. "graph-query-history").
358
+ * @param limit max entries to retain (default 50).
359
+ */
360
+ declare function createQueryHistoryStore(persistKey: string, limit?: number): QueryHistoryStore;
361
+
362
+ /**
363
+ * QueryHistory -- a dropdown of recently-run queries.
364
+ *
365
+ * Reads a QueryHistoryStore (created by createQueryHistoryStore) and lets the
366
+ * user pick a past query (onSelect) or clear the list. Presentational + store-
367
+ * bound only; the consuming app decides what onSelect does (typically: load the
368
+ * query into the editor). Designed to sit in a QueryEditor's renderActions slot.
369
+ */
370
+
371
+ declare function QueryHistory({ store, onSelect, }: {
372
+ store: QueryHistoryStore;
373
+ onSelect: (query: string) => void;
374
+ }): React__default.ReactElement;
375
+
275
376
  /**
276
377
  * Extract display label from a node or edge using resolved display config.
277
378
  *
@@ -1961,4 +2062,204 @@ interface DeleteNodeDialogProps {
1961
2062
  }
1962
2063
  declare function DeleteNodeDialog({ open, onOpenChange, node, port, onDeleted, }: DeleteNodeDialogProps): React__default.ReactElement;
1963
2064
 
1964
- export { ActionPanel, type ActionPanelState, type ActionPanelStore, type CapabilitiesValidation, type Cardinality, type ColorPalette, type CreateEdgeInput, type CreateNodeInput, type CreateNodeWithRelationsInput, type CreateNodeWithRelationsResult, DeleteNodeDialog, type DeleteNodeDialogProps, EMPTY_NORMALIZED, EdgeFormSheet, type EdgeFormSheetProps, EdgeInfoCard, type EdgeTypeMode, type EdgeTypeView, type EdgeVisual, type EditMode$1 as EditMode, type EditableMode, type ExpandOptions, type ExpandResult, GraphA11yList, type GraphA11yListProps, type GraphCapabilities, type GraphCapabilitiesValidation, type GraphDataHook, type GraphDataStore, type GraphDisplayConfig, type EditMode as GraphEditMode, GraphEditToolbar, type GraphEditToolbarProps, type GraphExplorationDeps, type GraphExplorationStore, type GraphFilterStore, type GraphFocusAction, type GraphFocusStore, type GraphModel, type GraphModelCapabilities, type GraphModelDisplay, GraphModelEditor, type GraphModelEditorProps, type GraphModelProperty, type GraphMutationPort, type GraphProperties, type GraphProperty, type GraphRelation, type GraphRenderer, GraphRendererProvider, type GraphSchemaProvider, type GraphStatistics, type WorkspaceStores as GraphStoreBundle, GraphStoresContext, type GraphTypeSchema, GraphVisualizer, type GraphVisualizerProps, type LabelDisplayMap, type LiveGraphDataResult, ModelActionPanel, type ModelActionPanelProps, type ModelGraph, NodeFormSheet, type NodeFormSheetProps, NodeInfoCard, NodeTypeNameSheet, type NodeTypeNameSheetProps, type NodeTypeView, type NodeVisual, type NormalizedGraph, Overview, PropertyFormSheet, type PropertyFormSheetProps, type PropertyInput, type PropertyView, type RawGraphEdge, type RawGraphNode, type RelationCardinality, type RelationDef, type RelationDetailView, RelationFormSheet, type RelationFormSheetProps, type RelationInput, type RelationMap, type RelationView, type ResolvedCapabilities, type ResolvedGraphCapabilities, type SelectionStore, type StoreFactory, TypeDetailPanel, type TypeDetailPanelProps, type UpdateEdgeInput, type UpdateNodeInput, type UpdateNodeWithRelationsInput, type UpdateNodeWithRelationsResult, type VisualGraphEdge, type VisualGraphNode, type VisualGraphNormalized, type WorkspaceStores, type XGraph, addEdgeType, addNodeType, addRelation, buildColorPalette, buildColorPaletteFromNodes, capabilitiesSchema, cardinalityLabel, createActionPanelStore, createGraphDataStore, createGraphExplorationStore, createGraphFilterStore, createGraphFocusStore, createSelectionStore, deleteEdgeType, deleteEdgeTypeProperty, deleteNodeProperty, deleteNodeType, deleteRelation, deleteRelationProperty, edgeTypeView, editableRelations, enrichEdge, enrichEdges, enrichNode, enrichNodes, enrichSchemaWithRelations, extractDisplayLabel, extractRelationFields, findEdgeType, findType, graphCapabilitiesSchema, groupEdgesByRelation, hasProperties, hasRelationFields, initializeFormData, isEdgeType, isNodeType, isRawGraphNode, isRelationField, isVisualEdge, isVisualNode, modelToGraph, nodeTypeView, normalizeGraph, reconcileFilter, relationFieldName, relationTitle, relationTypeFromField, relationView, renameEdgeType, renameNodeType, resolveCapabilities, resolveGraphCapabilities, resolveRelationEdge, setEdgeTypeProperty, setNodeProperty, setRelationProperty, toCytoscapeEdge, toCytoscapeNode, toReagraphEdge, toReagraphNode, typeLabel, updateRelation, useActionPanelStore, useCytoscapeData, useGraphFocus, useGraphRenderer, useLiveGraphData, useReagraphData, useStableRef, useWorkspaceGraphData, useWorkspaceGraphExploration, useWorkspaceGraphFilter, useWorkspaceGraphFocus, useWorkspaceSelection, validateCapabilities, validateGraphCapabilities };
2065
+ /**
2066
+ * GraphFinder -- locate nodes and edges within the currently loaded graph.
2067
+ *
2068
+ * Three modes:
2069
+ * - Full-Text: natural-language, typo-tolerant search (Orama index over all
2070
+ * loaded elements).
2071
+ * - Expression: MistQL pipe expressions over the flattened graph
2072
+ * (e.g. ``Person | filter name == "John"``). Collections available:
2073
+ * nodes/edges/graph (all), vnodes/vedges/vgraph (visible only), and each
2074
+ * label (Person, ACTED_IN, ...).
2075
+ * - Both: expression filters first, then full-text searches that subset.
2076
+ *
2077
+ * Results are click-to-focus, double-click-to-focus-and-select on the canvas.
2078
+ * Renderer-agnostic: uses only the workspace stores and live graph data.
2079
+ */
2080
+
2081
+ declare function GraphFinder(): React__default.ReactElement;
2082
+
2083
+ /**
2084
+ * Graph finder types.
2085
+ *
2086
+ * Type definitions for the client-side graph finder: the Orama full-text
2087
+ * index over the loaded nodes/edges, its documents, results, and options.
2088
+ */
2089
+ /**
2090
+ * Orama document structure for indexing nodes and edges.
2091
+ *
2092
+ * Contains fallback fields (always present) that make any node/edge
2093
+ * searchable without a data-model schema.
2094
+ */
2095
+ interface OramaDocument {
2096
+ /** Unique ID (node or edge ID) */
2097
+ id_: string;
2098
+ /** Type: 'node' or 'edge' */
2099
+ type: "node" | "edge";
2100
+ /** Label (e.g. 'Person', 'ACTED_IN') */
2101
+ label_: string;
2102
+ /** Display name for UI */
2103
+ displayName: string;
2104
+ /** Concatenated text from all properties for full-text search */
2105
+ searchableText: string;
2106
+ /** JSON-stringified properties (fallback field) */
2107
+ properties_json: string;
2108
+ /** Whether this item is currently visible in the graph */
2109
+ isVisible: boolean;
2110
+ /** Start node ID (edges only) */
2111
+ start_id_?: string;
2112
+ /** End node ID (edges only) */
2113
+ end_id_?: string;
2114
+ }
2115
+ /** A finder full-text result with relevance score. */
2116
+ interface OramaSearchResult {
2117
+ /** The matched document */
2118
+ document: OramaDocument;
2119
+ /** Relevance score (higher = more relevant) */
2120
+ score: number;
2121
+ /** Matched terms (for highlighting) */
2122
+ positions?: Record<string, unknown>;
2123
+ }
2124
+ /** Finder index statistics for status display. */
2125
+ interface ServiceStats {
2126
+ totalIndexed: number;
2127
+ nodesIndexed: number;
2128
+ edgesIndexed: number;
2129
+ /** Timestamp of last index build */
2130
+ lastIndexBuild: number | null;
2131
+ /** Whether the index is ready to search */
2132
+ isReady: boolean;
2133
+ }
2134
+ /** Configuration for the finder's Orama search service. */
2135
+ interface OramaSearchServiceConfig {
2136
+ /** Enable debug logging (default: false) */
2137
+ debug?: boolean;
2138
+ /** Maximum nodes to index -- safety limit (default: 100000) */
2139
+ maxNodes?: number;
2140
+ /** Lazy initialization -- only build when needed (default: true) */
2141
+ lazyInit?: boolean;
2142
+ }
2143
+ /** Options for a full-text finder query. */
2144
+ interface SearchOptions {
2145
+ /** Search term (natural language query) */
2146
+ term: string;
2147
+ /** Filter by node/edge labels (optional) */
2148
+ labels?: string[];
2149
+ /** Only search visible items (default: false) */
2150
+ visibleOnly?: boolean;
2151
+ /** Maximum number of results (default: 50) */
2152
+ limit?: number;
2153
+ /** Include edge results (default: true) */
2154
+ includeEdges?: boolean;
2155
+ /** Include node results (default: true) */
2156
+ includeNodes?: boolean;
2157
+ /** Custom field boosting (optional) */
2158
+ boost?: Record<string, number>;
2159
+ }
2160
+ /**
2161
+ * Visibility tracking subset used when building documents.
2162
+ * A subset of the normalized graph shape.
2163
+ */
2164
+ interface NormalizedData {
2165
+ hiddenNodeIds: Set<string>;
2166
+ hiddenEdgeIds: Set<string>;
2167
+ }
2168
+
2169
+ /**
2170
+ * useGraphSearch -- full-text finder over the currently loaded graph.
2171
+ *
2172
+ * Wraps an OramaSearchService whose index is built on demand: not when the
2173
+ * finder opens, only when the user actually runs a full-text search. The
2174
+ * index covers ALL nodes/edges from the last query (``baseNormalized``, the
2175
+ * same source expression mode uses), independent of label filters or focus.
2176
+ * When the underlying data changes the index is marked dirty and rebuilt on
2177
+ * the next search.
2178
+ */
2179
+
2180
+ interface UseGraphSearchReturn {
2181
+ /** Run a full-text search; builds/rebuilds the index on demand. */
2182
+ search: (query: string, options?: Omit<SearchOptions, "term">) => Promise<OramaSearchResult[]>;
2183
+ /** Whether the index is initialized and current. */
2184
+ isReady: boolean;
2185
+ /** Whether the index is being (re)built. */
2186
+ isIndexing: boolean;
2187
+ /** Current index statistics (null before first build). */
2188
+ stats: ServiceStats | null;
2189
+ /** Any initialization/indexing error. */
2190
+ error: Error | null;
2191
+ }
2192
+ declare function useGraphSearch(): UseGraphSearchReturn;
2193
+
2194
+ /**
2195
+ * Orama full-text index for the graph finder.
2196
+ *
2197
+ * Maintains a client-side Orama index over the nodes/edges currently loaded
2198
+ * from a query. Uses a full rebuild when the index becomes dirty (simple and
2199
+ * fast for typical graphs) and lazily initializes only when first searched.
2200
+ */
2201
+
2202
+ declare class OramaSearchService {
2203
+ private db;
2204
+ private config;
2205
+ private isDirty;
2206
+ private isInitialized;
2207
+ private lastIndexBuild;
2208
+ private stats;
2209
+ constructor(config?: OramaSearchServiceConfig);
2210
+ /** Create the empty index with the finder schema (idempotent). */
2211
+ initialize(): Promise<void>;
2212
+ /** Drop all documents (recreates the index; Orama has no bulk delete). */
2213
+ clear(): Promise<void>;
2214
+ /** Mark the index stale so the next search rebuilds it. */
2215
+ markDirty(): void;
2216
+ /** Whether the index needs a (re)build before searching. */
2217
+ needsRebuild(): boolean;
2218
+ /** Rebuild the whole index from the given nodes and edges. */
2219
+ rebuildIndex(nodes: VisualGraphNode[], edges: VisualGraphEdge[], normalized?: NormalizedData): Promise<void>;
2220
+ /** Run a full-text query against the index. */
2221
+ search(options: SearchOptions): Promise<OramaSearchResult[]>;
2222
+ /** Current index statistics. */
2223
+ getStats(): ServiceStats;
2224
+ /** Whether the index is ready to serve searches. */
2225
+ isReady(): boolean;
2226
+ }
2227
+
2228
+ /**
2229
+ * Flatten a normalized graph into a query-friendly shape for the finder's
2230
+ * expression mode (MistQL). Node/edge properties are spread to the top level,
2231
+ * and collections are grouped by label, so queries like
2232
+ * ``Person | filter name == "John"`` or ``graph | filter name == "ABC"`` work.
2233
+ */
2234
+
2235
+ /** A node with its properties spread to the top level. */
2236
+ interface FlattenedNode {
2237
+ id_: number;
2238
+ label_: string;
2239
+ displayName: string;
2240
+ color: string;
2241
+ [key: string]: unknown;
2242
+ }
2243
+ /** An edge with its properties spread to the top level. */
2244
+ interface FlattenedEdge {
2245
+ id_: number;
2246
+ label_: string;
2247
+ start_id_: number;
2248
+ end_id_: number;
2249
+ [key: string]: unknown;
2250
+ }
2251
+ /** Flattened graph with raw, combined, and label-grouped collections. */
2252
+ interface FlattenedGraphData {
2253
+ nodes: FlattenedNode[];
2254
+ edges: FlattenedEdge[];
2255
+ /** All nodes and edges as a single array. */
2256
+ graph: Array<FlattenedNode | FlattenedEdge>;
2257
+ _labels: string[];
2258
+ _edgeLabels: string[];
2259
+ /** Dynamic label groups, e.g. Person / ACTED_IN. */
2260
+ [key: string]: unknown;
2261
+ }
2262
+ /** Flatten normalized graph data. Pure function -- no React hooks. */
2263
+ declare function flattenGraphData(normalized: NormalizedGraph): FlattenedGraphData;
2264
+
2265
+ export { ActionPanel, type ActionPanelState, type ActionPanelStore, type CapabilitiesValidation, type Cardinality, type ColorPalette, type CreateEdgeInput, type CreateNodeInput, type CreateNodeWithRelationsInput, type CreateNodeWithRelationsResult, DeleteNodeDialog, type DeleteNodeDialogProps, EMPTY_NORMALIZED, EdgeFormSheet, type EdgeFormSheetProps, EdgeInfoCard, type EdgeTypeMode, type EdgeTypeView, type EdgeVisual, type EditMode$1 as EditMode, type EditableMode, type ExpandOptions, type ExpandResult, type ExtractedGraphRows, type FlattenedEdge, type FlattenedGraphData, type FlattenedNode, GraphA11yList, type GraphA11yListProps, type GraphCapabilities, type GraphCapabilitiesValidation, type GraphDataHook, type GraphDataStore, type GraphDisplayConfig, type EditMode as GraphEditMode, GraphEditToolbar, type GraphEditToolbarProps, type GraphExplorationDeps, type GraphExplorationStore, type GraphFilterStore, GraphFinder, type GraphFocusAction, type GraphFocusStore, type GraphModel, type GraphModelCapabilities, type GraphModelDisplay, GraphModelEditor, type GraphModelEditorProps, type GraphModelProperty, type GraphMutationPort, type GraphProperties, type GraphProperty, type GraphRelation, type GraphRenderer, GraphRendererProvider, type GraphSchemaProvider, type GraphStatistics, type WorkspaceStores as GraphStoreBundle, GraphStoresContext, type GraphTypeSchema, GraphVisualizer, type GraphVisualizerProps, type LabelDisplayMap, type LiveGraphDataResult, ModelActionPanel, type ModelActionPanelProps, type ModelGraph, NodeFormSheet, type NodeFormSheetProps, NodeInfoCard, NodeTypeNameSheet, type NodeTypeNameSheetProps, type NodeTypeView, type NodeVisual, type NormalizedData, type NormalizedGraph, type OramaDocument, type OramaSearchResult, OramaSearchService, type OramaSearchServiceConfig, Overview, PropertyFormSheet, type PropertyFormSheetProps, type PropertyInput, type PropertyView, QueryEditor, type QueryEditorProps, QueryHistory, type QueryHistoryState, type QueryHistoryStore, type RawGraphEdge, type RawGraphNode, type RelationCardinality, type RelationDef, type RelationDetailView, RelationFormSheet, type RelationFormSheetProps, type RelationInput, type RelationMap, type RelationView, type ResolvedCapabilities, type ResolvedGraphCapabilities, type SearchOptions, type SelectionStore, type ServiceStats, type StoreFactory, TypeDetailPanel, type TypeDetailPanelProps, type UpdateEdgeInput, type UpdateNodeInput, type UpdateNodeWithRelationsInput, type UpdateNodeWithRelationsResult, type UseGraphSearchReturn, type VisualGraphEdge, type VisualGraphNode, type VisualGraphNormalized, type WorkspaceStores, type XGraph, addEdgeType, addNodeType, addRelation, buildColorPalette, buildColorPaletteFromNodes, capabilitiesSchema, cardinalityLabel, createActionPanelStore, createGraphDataStore, createGraphExplorationStore, createGraphFilterStore, createGraphFocusStore, createQueryHistoryStore, createSelectionStore, deleteEdgeType, deleteEdgeTypeProperty, deleteNodeProperty, deleteNodeType, deleteRelation, deleteRelationProperty, edgeTypeView, editableRelations, enrichEdge, enrichEdges, enrichNode, enrichNodes, enrichSchemaWithRelations, extractDisplayLabel, extractGraphFromRows, extractRelationFields, findEdgeType, findType, flattenGraphData, graphCapabilitiesSchema, groupEdgesByRelation, hasProperties, hasRelationFields, initializeFormData, isEdgeType, isNodeType, isRawGraphNode, isRelationField, isVisualEdge, isVisualNode, modelToGraph, nodeTypeView, normalizeGraph, reconcileFilter, relationFieldName, relationTitle, relationTypeFromField, relationView, renameEdgeType, renameNodeType, resolveCapabilities, resolveGraphCapabilities, resolveRelationEdge, setEdgeTypeProperty, setNodeProperty, setRelationProperty, toCytoscapeEdge, toCytoscapeNode, toReagraphEdge, toReagraphNode, typeLabel, updateRelation, useActionPanelStore, useCytoscapeData, useGraphFocus, useGraphRenderer, useGraphSearch, useLiveGraphData, useReagraphData, useStableRef, useWorkspaceGraphData, useWorkspaceGraphExploration, useWorkspaceGraphFilter, useWorkspaceGraphFocus, useWorkspaceSelection, validateCapabilities, validateGraphCapabilities };