infrahub-sdk 0.0.7 → 0.0.9

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/test-schema.ts ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Simple test script to load schema from a local Infrahub server
3
+ *
4
+ * Run with: npx ts-node test-schema.ts
5
+ */
6
+
7
+ import { InfrahubClient } from './src/index';
8
+
9
+ const INFRAHUB_URL = process.env.INFRAHUB_URL || 'http://localhost:8000';
10
+ const INFRAHUB_TOKEN = process.env.INFRAHUB_TOKEN || '';
11
+
12
+ async function main() {
13
+ console.log(`Connecting to Infrahub at ${INFRAHUB_URL}...`);
14
+
15
+ const client = new InfrahubClient({
16
+ address: INFRAHUB_URL,
17
+ token: INFRAHUB_TOKEN
18
+ });
19
+
20
+ try {
21
+ // Test 1: Get server info
22
+ console.log('\n--- Testing GET /api/info ---');
23
+ const infoResult = await client.rest.GET('/api/info') as any;
24
+ if (infoResult.error) {
25
+ console.error('Error:', infoResult.error);
26
+ } else {
27
+ console.log('Server Info:', JSON.stringify(infoResult.data, null, 2));
28
+ }
29
+
30
+ // Test 2: Get schema
31
+ console.log('\n--- Testing GET /api/schema ---');
32
+ const schemaResult = await client.rest.GET('/api/schema') as any;
33
+ if (schemaResult.error) {
34
+ console.error('Error:', schemaResult.error);
35
+ } else {
36
+ console.log('Schema loaded successfully!');
37
+ const data = schemaResult.data;
38
+ if (data && typeof data === 'object') {
39
+ if (data.nodes) {
40
+ console.log(`Number of nodes: ${data.nodes.length}`);
41
+ }
42
+ if (data.generics) {
43
+ console.log(`Number of generics: ${data.generics.length}`);
44
+ }
45
+ }
46
+ }
47
+
48
+ // Test 3: Get schema summary
49
+ console.log('\n--- Testing GET /api/schema/summary ---');
50
+ const summaryResult = await client.rest.GET('/api/schema/summary') as any;
51
+ if (summaryResult.error) {
52
+ console.error('Error:', summaryResult.error);
53
+ } else {
54
+ const summary = JSON.stringify(summaryResult.data, null, 2);
55
+ console.log('Schema Summary:', summary.length > 500 ? summary.substring(0, 500) + '...' : summary);
56
+ }
57
+
58
+ // Test 4: Get config
59
+ console.log('\n--- Testing GET /api/config ---');
60
+ const configResult = await client.rest.GET('/api/config') as any;
61
+ if (configResult.error) {
62
+ console.error('Error:', configResult.error);
63
+ } else {
64
+ const config = JSON.stringify(configResult.data, null, 2);
65
+ console.log('Config:', config.length > 500 ? config.substring(0, 500) + '...' : config);
66
+ }
67
+
68
+ console.log('\n--- All tests completed! ---');
69
+
70
+ } catch (error) {
71
+ console.error('Unexpected error:', error);
72
+ process.exit(1);
73
+ }
74
+ }
75
+
76
+ main();