@robosystems/client 0.2.0 → 0.2.2
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/extensions/GraphClient.d.ts +71 -0
- package/extensions/GraphClient.js +176 -0
- package/extensions/GraphClient.test.ts +285 -0
- package/extensions/GraphClient.ts +281 -0
- package/extensions/TableIngestClient.d.ts +1 -1
- package/extensions/TableIngestClient.js +20 -20
- package/extensions/TableIngestClient.test.ts +1 -1
- package/extensions/TableIngestClient.ts +23 -28
- package/extensions/hooks.d.ts +1 -1
- package/extensions/index.d.ts +5 -1
- package/extensions/index.js +14 -1
- package/extensions/index.test.ts +22 -0
- package/extensions/index.ts +15 -1
- package/package.json +1 -1
- package/sdk/sdk.gen.d.ts +528 -26
- package/sdk/sdk.gen.js +534 -32
- package/sdk/sdk.gen.ts +532 -30
- package/sdk/types.gen.d.ts +289 -82
- package/sdk/types.gen.ts +293 -82
- package/sdk-extensions/GraphClient.d.ts +71 -0
- package/sdk-extensions/GraphClient.js +176 -0
- package/sdk-extensions/GraphClient.test.ts +285 -0
- package/sdk-extensions/GraphClient.ts +281 -0
- package/sdk-extensions/TableIngestClient.d.ts +1 -1
- package/sdk-extensions/TableIngestClient.js +20 -20
- package/sdk-extensions/TableIngestClient.test.ts +1 -1
- package/sdk-extensions/TableIngestClient.ts +23 -28
- package/sdk-extensions/hooks.d.ts +1 -1
- package/sdk-extensions/index.d.ts +5 -1
- package/sdk-extensions/index.js +14 -1
- package/sdk-extensions/index.test.ts +22 -0
- package/sdk-extensions/index.ts +15 -1
- package/sdk.gen.d.ts +528 -26
- package/sdk.gen.js +534 -32
- package/sdk.gen.ts +532 -30
- package/types.gen.d.ts +289 -82
- package/types.gen.ts +293 -82
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export interface GraphMetadataInput {
|
|
2
|
+
graphName: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
schemaExtensions?: string[];
|
|
5
|
+
tags?: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface InitialEntityInput {
|
|
8
|
+
name: string;
|
|
9
|
+
uri: string;
|
|
10
|
+
category?: string;
|
|
11
|
+
sic?: string;
|
|
12
|
+
sicDescription?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface GraphInfo {
|
|
15
|
+
graphId: string;
|
|
16
|
+
graphName: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
schemaExtensions?: string[];
|
|
19
|
+
tags?: string[];
|
|
20
|
+
createdAt?: string;
|
|
21
|
+
status?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CreateGraphOptions {
|
|
24
|
+
createEntity?: boolean;
|
|
25
|
+
timeout?: number;
|
|
26
|
+
pollInterval?: number;
|
|
27
|
+
onProgress?: (message: string) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare class GraphClient {
|
|
30
|
+
private operationClient;
|
|
31
|
+
private config;
|
|
32
|
+
constructor(config: {
|
|
33
|
+
baseUrl: string;
|
|
34
|
+
credentials?: 'include' | 'same-origin' | 'omit';
|
|
35
|
+
headers?: Record<string, string>;
|
|
36
|
+
token?: string;
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Create a graph and wait for completion
|
|
40
|
+
*
|
|
41
|
+
* @param metadata - Graph metadata (name, description, etc.)
|
|
42
|
+
* @param initialEntity - Optional initial entity to create
|
|
43
|
+
* @param options - Additional options including:
|
|
44
|
+
* - createEntity: Whether to create the entity node and upload initial data.
|
|
45
|
+
* Only applies when initialEntity is provided. Set to false to
|
|
46
|
+
* create graph without populating entity data (useful for file-based ingestion).
|
|
47
|
+
* Defaults to true.
|
|
48
|
+
* - timeout: Maximum time to wait in milliseconds (default: 60000)
|
|
49
|
+
* - pollInterval: Time between status checks in milliseconds (default: 2000)
|
|
50
|
+
* - onProgress: Callback for progress updates
|
|
51
|
+
* @returns The graph ID when creation completes
|
|
52
|
+
*/
|
|
53
|
+
createGraphAndWait(metadata: GraphMetadataInput, initialEntity?: InitialEntityInput, options?: CreateGraphOptions): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Get information about a graph
|
|
56
|
+
*/
|
|
57
|
+
getGraphInfo(graphId: string): Promise<GraphInfo>;
|
|
58
|
+
/**
|
|
59
|
+
* List all graphs
|
|
60
|
+
*/
|
|
61
|
+
listGraphs(): Promise<GraphInfo[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Delete a graph
|
|
64
|
+
* Note: This will be implemented when the deleteGraph endpoint is available in the SDK
|
|
65
|
+
*/
|
|
66
|
+
deleteGraph(_graphId: string): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Clean up resources
|
|
69
|
+
*/
|
|
70
|
+
close(): void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.GraphClient = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Graph Management Client
|
|
7
|
+
* Provides high-level graph management operations with automatic operation monitoring
|
|
8
|
+
*/
|
|
9
|
+
const sdk_gen_1 = require("../sdk/sdk.gen");
|
|
10
|
+
const OperationClient_1 = require("./OperationClient");
|
|
11
|
+
class GraphClient {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.operationClient = new OperationClient_1.OperationClient(config);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a graph and wait for completion
|
|
18
|
+
*
|
|
19
|
+
* @param metadata - Graph metadata (name, description, etc.)
|
|
20
|
+
* @param initialEntity - Optional initial entity to create
|
|
21
|
+
* @param options - Additional options including:
|
|
22
|
+
* - createEntity: Whether to create the entity node and upload initial data.
|
|
23
|
+
* Only applies when initialEntity is provided. Set to false to
|
|
24
|
+
* create graph without populating entity data (useful for file-based ingestion).
|
|
25
|
+
* Defaults to true.
|
|
26
|
+
* - timeout: Maximum time to wait in milliseconds (default: 60000)
|
|
27
|
+
* - pollInterval: Time between status checks in milliseconds (default: 2000)
|
|
28
|
+
* - onProgress: Callback for progress updates
|
|
29
|
+
* @returns The graph ID when creation completes
|
|
30
|
+
*/
|
|
31
|
+
async createGraphAndWait(metadata, initialEntity, options = {}) {
|
|
32
|
+
const { createEntity = true, timeout = 60000, pollInterval = 2000, onProgress } = options;
|
|
33
|
+
if (!this.config.token) {
|
|
34
|
+
throw new Error('No API key provided. Set token in config.');
|
|
35
|
+
}
|
|
36
|
+
// Build initial entity if provided
|
|
37
|
+
let initialEntityData;
|
|
38
|
+
if (initialEntity) {
|
|
39
|
+
initialEntityData = {
|
|
40
|
+
name: initialEntity.name,
|
|
41
|
+
uri: initialEntity.uri,
|
|
42
|
+
category: initialEntity.category,
|
|
43
|
+
sic: initialEntity.sic,
|
|
44
|
+
sic_description: initialEntity.sicDescription,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// Build API metadata
|
|
48
|
+
const apiMetadata = {
|
|
49
|
+
graph_name: metadata.graphName,
|
|
50
|
+
description: metadata.description,
|
|
51
|
+
schema_extensions: metadata.schemaExtensions || [],
|
|
52
|
+
tags: metadata.tags || [],
|
|
53
|
+
};
|
|
54
|
+
if (onProgress) {
|
|
55
|
+
onProgress(`Creating graph: ${metadata.graphName}`);
|
|
56
|
+
}
|
|
57
|
+
// Create graph request - SDK expects options format, not data format
|
|
58
|
+
const response = await (0, sdk_gen_1.createGraph)({
|
|
59
|
+
body: {
|
|
60
|
+
metadata: apiMetadata,
|
|
61
|
+
initial_entity: initialEntityData || null,
|
|
62
|
+
create_entity: createEntity,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
// Check if we got immediate graph_id
|
|
66
|
+
const responseData = response.data;
|
|
67
|
+
if (responseData?.graph_id) {
|
|
68
|
+
if (onProgress) {
|
|
69
|
+
onProgress(`Graph created: ${responseData.graph_id}`);
|
|
70
|
+
}
|
|
71
|
+
return responseData.graph_id;
|
|
72
|
+
}
|
|
73
|
+
// Otherwise, we have an operation_id to monitor
|
|
74
|
+
if (responseData?.operation_id) {
|
|
75
|
+
const operationId = responseData.operation_id;
|
|
76
|
+
if (onProgress) {
|
|
77
|
+
onProgress(`Graph creation queued (operation: ${operationId})`);
|
|
78
|
+
}
|
|
79
|
+
// Poll operation status
|
|
80
|
+
const maxAttempts = Math.floor(timeout / pollInterval);
|
|
81
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
82
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
83
|
+
const statusResponse = await (0, sdk_gen_1.getOperationStatus)({
|
|
84
|
+
path: { operation_id: operationId },
|
|
85
|
+
});
|
|
86
|
+
const statusData = statusResponse.data;
|
|
87
|
+
const status = statusData?.status;
|
|
88
|
+
if (onProgress) {
|
|
89
|
+
onProgress(`Status: ${status} (attempt ${attempt + 1}/${maxAttempts})`);
|
|
90
|
+
}
|
|
91
|
+
if (status === 'completed') {
|
|
92
|
+
const result = statusData?.result;
|
|
93
|
+
const graphId = result?.graph_id;
|
|
94
|
+
if (graphId) {
|
|
95
|
+
if (onProgress) {
|
|
96
|
+
onProgress(`Graph created: ${graphId}`);
|
|
97
|
+
}
|
|
98
|
+
return graphId;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
throw new Error('Operation completed but no graph_id in result');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (status === 'failed') {
|
|
105
|
+
const error = statusData?.error || statusData?.message || 'Unknown error';
|
|
106
|
+
throw new Error(`Graph creation failed: ${error}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`Graph creation timed out after ${timeout}ms`);
|
|
110
|
+
}
|
|
111
|
+
throw new Error('No graph_id or operation_id in response');
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get information about a graph
|
|
115
|
+
*/
|
|
116
|
+
async getGraphInfo(graphId) {
|
|
117
|
+
if (!this.config.token) {
|
|
118
|
+
throw new Error('No API key provided. Set token in config.');
|
|
119
|
+
}
|
|
120
|
+
// Use getGraphs to list all graphs and find the one we want
|
|
121
|
+
// Note: This is a workaround since there's no dedicated getGraph endpoint yet
|
|
122
|
+
const response = await (0, sdk_gen_1.getGraphs)();
|
|
123
|
+
const graphs = response.data?.graphs || [];
|
|
124
|
+
const graph = graphs.find((g) => g.graph_id === graphId || g.id === graphId);
|
|
125
|
+
if (!graph) {
|
|
126
|
+
throw new Error(`Graph not found: ${graphId}`);
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
graphId: graph.graph_id || graph.id,
|
|
130
|
+
graphName: graph.graph_name || graph.name,
|
|
131
|
+
description: graph.description,
|
|
132
|
+
schemaExtensions: graph.schema_extensions,
|
|
133
|
+
tags: graph.tags,
|
|
134
|
+
createdAt: graph.created_at,
|
|
135
|
+
status: graph.status,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* List all graphs
|
|
140
|
+
*/
|
|
141
|
+
async listGraphs() {
|
|
142
|
+
if (!this.config.token) {
|
|
143
|
+
throw new Error('No API key provided. Set token in config.');
|
|
144
|
+
}
|
|
145
|
+
const response = await (0, sdk_gen_1.getGraphs)();
|
|
146
|
+
const graphs = response.data?.graphs || [];
|
|
147
|
+
return graphs.map((graph) => ({
|
|
148
|
+
graphId: graph.graph_id || graph.id,
|
|
149
|
+
graphName: graph.graph_name || graph.name,
|
|
150
|
+
description: graph.description,
|
|
151
|
+
schemaExtensions: graph.schema_extensions,
|
|
152
|
+
tags: graph.tags,
|
|
153
|
+
createdAt: graph.created_at,
|
|
154
|
+
status: graph.status,
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Delete a graph
|
|
159
|
+
* Note: This will be implemented when the deleteGraph endpoint is available in the SDK
|
|
160
|
+
*/
|
|
161
|
+
async deleteGraph(_graphId) {
|
|
162
|
+
throw new Error('deleteGraph is not yet implemented - waiting for SDK endpoint to be generated');
|
|
163
|
+
// TODO: Implement when deleteGraph endpoint is available
|
|
164
|
+
// const response = await deleteGraph({ path: { graph_id: _graphId } })
|
|
165
|
+
// if (response.status !== 200 && response.status !== 204) {
|
|
166
|
+
// throw new Error(`Failed to delete graph: ${response.status}`)
|
|
167
|
+
// }
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Clean up resources
|
|
171
|
+
*/
|
|
172
|
+
close() {
|
|
173
|
+
this.operationClient.closeAll();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.GraphClient = GraphClient;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import type { GraphMetadataInput, InitialEntityInput } from './GraphClient'
|
|
3
|
+
import { GraphClient } from './GraphClient'
|
|
4
|
+
|
|
5
|
+
// Helper to create proper mock Response objects
|
|
6
|
+
function createMockResponse(data: any, options: { ok?: boolean; status?: number } = {}) {
|
|
7
|
+
return {
|
|
8
|
+
ok: options.ok ?? true,
|
|
9
|
+
status: options.status ?? 200,
|
|
10
|
+
statusText: options.status === 200 ? 'OK' : 'Error',
|
|
11
|
+
headers: new Headers({ 'content-type': 'application/json' }),
|
|
12
|
+
json: async () => data,
|
|
13
|
+
text: async () => JSON.stringify(data),
|
|
14
|
+
blob: async () => new Blob([JSON.stringify(data)]),
|
|
15
|
+
arrayBuffer: async () => new TextEncoder().encode(JSON.stringify(data)).buffer,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('GraphClient', () => {
|
|
20
|
+
let graphClient: GraphClient
|
|
21
|
+
let mockFetch: any
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
graphClient = new GraphClient({
|
|
25
|
+
baseUrl: 'http://localhost:8000',
|
|
26
|
+
token: 'test-api-key',
|
|
27
|
+
headers: { 'X-API-Key': 'test-api-key' },
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// Mock global fetch
|
|
31
|
+
mockFetch = vi.fn()
|
|
32
|
+
global.fetch = mockFetch
|
|
33
|
+
|
|
34
|
+
// Reset all mocks
|
|
35
|
+
vi.clearAllMocks()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
describe('createGraphAndWait', () => {
|
|
39
|
+
const mockMetadata: GraphMetadataInput = {
|
|
40
|
+
graphName: 'Test Graph',
|
|
41
|
+
description: 'A test graph',
|
|
42
|
+
schemaExtensions: ['custom_prop'],
|
|
43
|
+
tags: ['test'],
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
it('should create graph with immediate response', async () => {
|
|
47
|
+
mockFetch.mockResolvedValueOnce(
|
|
48
|
+
createMockResponse({
|
|
49
|
+
graph_id: 'graph_123',
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const graphId = await graphClient.createGraphAndWait(mockMetadata)
|
|
54
|
+
|
|
55
|
+
expect(graphId).toBe('graph_123')
|
|
56
|
+
expect(mockFetch).toHaveBeenCalled()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('should create graph with initial entity', async () => {
|
|
60
|
+
const mockInitialEntity: InitialEntityInput = {
|
|
61
|
+
name: 'ACME Corp',
|
|
62
|
+
uri: 'https://example.com/acme',
|
|
63
|
+
category: 'Technology',
|
|
64
|
+
sic: '7372',
|
|
65
|
+
sicDescription: 'Prepackaged Software',
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
mockFetch.mockResolvedValueOnce(
|
|
69
|
+
createMockResponse({
|
|
70
|
+
graph_id: 'graph_456',
|
|
71
|
+
})
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
const graphId = await graphClient.createGraphAndWait(mockMetadata, mockInitialEntity)
|
|
75
|
+
|
|
76
|
+
expect(graphId).toBe('graph_456')
|
|
77
|
+
expect(mockFetch).toHaveBeenCalled()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('should poll operation status when queued', async () => {
|
|
81
|
+
// First call: createGraph returns operation_id
|
|
82
|
+
mockFetch.mockResolvedValueOnce(
|
|
83
|
+
createMockResponse({
|
|
84
|
+
operation_id: 'op_789',
|
|
85
|
+
})
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
// Second call: getOperationStatus returns pending
|
|
89
|
+
mockFetch.mockResolvedValueOnce(
|
|
90
|
+
createMockResponse({
|
|
91
|
+
status: 'pending',
|
|
92
|
+
})
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
// Third call: getOperationStatus returns completed
|
|
96
|
+
mockFetch.mockResolvedValueOnce(
|
|
97
|
+
createMockResponse({
|
|
98
|
+
status: 'completed',
|
|
99
|
+
result: {
|
|
100
|
+
graph_id: 'graph_completed',
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
const graphId = await graphClient.createGraphAndWait(mockMetadata, undefined, {
|
|
106
|
+
pollInterval: 100,
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
expect(graphId).toBe('graph_completed')
|
|
110
|
+
expect(mockFetch).toHaveBeenCalledTimes(3)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('should handle operation failure', async () => {
|
|
114
|
+
mockFetch
|
|
115
|
+
.mockResolvedValueOnce(
|
|
116
|
+
createMockResponse({
|
|
117
|
+
operation_id: 'op_fail',
|
|
118
|
+
})
|
|
119
|
+
)
|
|
120
|
+
.mockResolvedValueOnce(
|
|
121
|
+
createMockResponse({
|
|
122
|
+
status: 'failed',
|
|
123
|
+
error: 'Graph creation failed',
|
|
124
|
+
})
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
await expect(
|
|
128
|
+
graphClient.createGraphAndWait(mockMetadata, undefined, { pollInterval: 100 })
|
|
129
|
+
).rejects.toThrow('Graph creation failed')
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('should timeout if operation takes too long', async () => {
|
|
133
|
+
mockFetch
|
|
134
|
+
.mockResolvedValueOnce(
|
|
135
|
+
createMockResponse({
|
|
136
|
+
operation_id: 'op_timeout',
|
|
137
|
+
})
|
|
138
|
+
)
|
|
139
|
+
.mockResolvedValue(
|
|
140
|
+
createMockResponse({
|
|
141
|
+
status: 'pending',
|
|
142
|
+
})
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
await expect(
|
|
146
|
+
graphClient.createGraphAndWait(mockMetadata, undefined, {
|
|
147
|
+
timeout: 500,
|
|
148
|
+
pollInterval: 100,
|
|
149
|
+
})
|
|
150
|
+
).rejects.toThrow('timed out')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('should call onProgress callback', async () => {
|
|
154
|
+
mockFetch.mockResolvedValueOnce(
|
|
155
|
+
createMockResponse({
|
|
156
|
+
graph_id: 'graph_progress',
|
|
157
|
+
})
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
const onProgress = vi.fn()
|
|
161
|
+
|
|
162
|
+
await graphClient.createGraphAndWait(mockMetadata, undefined, { onProgress })
|
|
163
|
+
|
|
164
|
+
expect(onProgress).toHaveBeenCalledWith(expect.stringContaining('Creating graph'))
|
|
165
|
+
expect(onProgress).toHaveBeenCalledWith(expect.stringContaining('Graph created'))
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('should throw error if no token provided', async () => {
|
|
169
|
+
const clientNoToken = new GraphClient({
|
|
170
|
+
baseUrl: 'http://localhost:8000',
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
await expect(clientNoToken.createGraphAndWait(mockMetadata)).rejects.toThrow(
|
|
174
|
+
'No API key provided'
|
|
175
|
+
)
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
describe('getGraphInfo', () => {
|
|
180
|
+
it('should get graph info by ID', async () => {
|
|
181
|
+
mockFetch.mockResolvedValueOnce(
|
|
182
|
+
createMockResponse({
|
|
183
|
+
graphs: [
|
|
184
|
+
{
|
|
185
|
+
graph_id: 'graph_123',
|
|
186
|
+
graph_name: 'Test Graph',
|
|
187
|
+
description: 'Test description',
|
|
188
|
+
schema_extensions: ['prop1'],
|
|
189
|
+
tags: ['test'],
|
|
190
|
+
created_at: '2024-01-01T00:00:00Z',
|
|
191
|
+
status: 'active',
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
graph_id: 'graph_456',
|
|
195
|
+
graph_name: 'Other Graph',
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
})
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
const info = await graphClient.getGraphInfo('graph_123')
|
|
202
|
+
|
|
203
|
+
expect(info.graphId).toBe('graph_123')
|
|
204
|
+
expect(info.graphName).toBe('Test Graph')
|
|
205
|
+
expect(info.description).toBe('Test description')
|
|
206
|
+
expect(info.tags).toEqual(['test'])
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it('should throw error if graph not found', async () => {
|
|
210
|
+
mockFetch.mockResolvedValueOnce(
|
|
211
|
+
createMockResponse({
|
|
212
|
+
graphs: [
|
|
213
|
+
{
|
|
214
|
+
graph_id: 'graph_other',
|
|
215
|
+
graph_name: 'Other Graph',
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
})
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
await expect(graphClient.getGraphInfo('graph_notfound')).rejects.toThrow('Graph not found')
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('should throw error if no token provided', async () => {
|
|
225
|
+
const clientNoToken = new GraphClient({
|
|
226
|
+
baseUrl: 'http://localhost:8000',
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
await expect(clientNoToken.getGraphInfo('graph_123')).rejects.toThrow('No API key provided')
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
describe('listGraphs', () => {
|
|
234
|
+
it('should list all graphs', async () => {
|
|
235
|
+
mockFetch.mockResolvedValueOnce(
|
|
236
|
+
createMockResponse({
|
|
237
|
+
graphs: [
|
|
238
|
+
{
|
|
239
|
+
graph_id: 'graph_1',
|
|
240
|
+
graph_name: 'Graph 1',
|
|
241
|
+
description: 'First graph',
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
graph_id: 'graph_2',
|
|
245
|
+
graph_name: 'Graph 2',
|
|
246
|
+
tags: ['production'],
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
})
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
const graphs = await graphClient.listGraphs()
|
|
253
|
+
|
|
254
|
+
expect(graphs).toHaveLength(2)
|
|
255
|
+
expect(graphs[0].graphId).toBe('graph_1')
|
|
256
|
+
expect(graphs[0].graphName).toBe('Graph 1')
|
|
257
|
+
expect(graphs[1].graphId).toBe('graph_2')
|
|
258
|
+
expect(graphs[1].tags).toEqual(['production'])
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
it('should return empty array if no graphs', async () => {
|
|
262
|
+
mockFetch.mockResolvedValueOnce(
|
|
263
|
+
createMockResponse({
|
|
264
|
+
graphs: [],
|
|
265
|
+
})
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
const graphs = await graphClient.listGraphs()
|
|
269
|
+
|
|
270
|
+
expect(graphs).toEqual([])
|
|
271
|
+
})
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
describe('deleteGraph', () => {
|
|
275
|
+
it('should throw not implemented error', async () => {
|
|
276
|
+
await expect(graphClient.deleteGraph('graph_123')).rejects.toThrow('not yet implemented')
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
describe('close', () => {
|
|
281
|
+
it('should close without errors', () => {
|
|
282
|
+
expect(() => graphClient.close()).not.toThrow()
|
|
283
|
+
})
|
|
284
|
+
})
|
|
285
|
+
})
|