rust-kgdb 0.6.81 → 0.6.83

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.
@@ -0,0 +1,339 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * ================================================================================
4
+ * RpcFederationProxy: DCAT DPROD Catalog Demo
5
+ * Enterprise Data Product Registry
6
+ * ================================================================================
7
+ *
8
+ * HyperFederate implements a DCAT DPROD-compliant data product catalog:
9
+ * - Register data products with full metadata
10
+ * - Track sources, schemas, quality metrics, lineage
11
+ * - Discovery via catalog queries
12
+ * - Governance workflows via DPROD ontology
13
+ *
14
+ * DCAT DPROD Ontology (W3C aligned):
15
+ * - dprod:DataProduct - Curated data asset
16
+ * - dprod:DataCatalog - Discovery registry
17
+ * - dprod:InputPort / dprod:OutputPort - Data endpoints
18
+ * - dprod:Schema - Structural metadata
19
+ * - dprod:DataQuality - Quality metrics
20
+ * - dprod:DataLineage - W3C PROV provenance
21
+ *
22
+ * Architecture:
23
+ * - Catalog stored in KGDB as RDF triples (ontology-native)
24
+ * - Heavy lifting in Rust core
25
+ * - TypeScript SDK provides thin RPC proxy layer
26
+ *
27
+ * Run: node examples/rpc-catalog-dprod-demo.js
28
+ *
29
+ * @requires HyperFederate server running at http://localhost:30180
30
+ */
31
+
32
+ const {
33
+ RpcFederationProxy,
34
+ ProofDAG
35
+ } = require('../index.js')
36
+
37
+ // ================================================================================
38
+ // DEMO: DCAT DPROD Catalog
39
+ // ================================================================================
40
+
41
+ async function runDemo() {
42
+ console.log('╔══════════════════════════════════════════════════════════════════════╗')
43
+ console.log('║ RpcFederationProxy: DCAT DPROD Catalog Demo ║')
44
+ console.log('║ Enterprise Data Product Registry ║')
45
+ console.log('╚══════════════════════════════════════════════════════════════════════╝\n')
46
+
47
+ // Create RpcFederationProxy
48
+ const federation = new RpcFederationProxy({
49
+ endpoint: process.env.HYPERFEDERATE_URL || 'http://localhost:30180',
50
+ identityId: 'data-product-owner-001'
51
+ })
52
+
53
+ console.log(`Federation Endpoint: ${federation.endpoint}`)
54
+ console.log(`Identity ID: ${federation.identityId}`)
55
+ console.log()
56
+
57
+ // ============================================================================
58
+ // 1. Register Data Products
59
+ // ============================================================================
60
+ console.log('1. Register Data Products in Catalog')
61
+ console.log('═'.repeat(70))
62
+
63
+ const dataProducts = [
64
+ {
65
+ name: 'High Risk Customer Analysis',
66
+ description: 'Cross-domain risk scoring combining Knowledge Graph risk assessments with Snowflake transactional data and BigQuery demographics',
67
+ sources: ['kgdb', 'snowflake', 'bigquery'],
68
+ outputPort: '/api/v1/products/high-risk-customers/query',
69
+ schema: {
70
+ columns: [
71
+ { name: 'kg_entity', type: 'STRING' },
72
+ { name: 'risk_score', type: 'FLOAT64' },
73
+ { name: 'entity_types', type: 'ARRAY<STRING>' },
74
+ { name: 'customer_name', type: 'STRING' },
75
+ { name: 'account_balance', type: 'DECIMAL(15,2)' },
76
+ { name: 'name_popularity', type: 'INT64' }
77
+ ]
78
+ },
79
+ quality: {
80
+ completeness: 0.98,
81
+ accuracy: 0.95,
82
+ timeliness: 0.99,
83
+ consistency: 0.97
84
+ },
85
+ owner: 'team-risk-analytics'
86
+ },
87
+ {
88
+ name: 'Customer 360 View',
89
+ description: 'Unified customer view combining KG relationships, transaction history, and demographic enrichment',
90
+ sources: ['kgdb', 'snowflake', 'bigquery'],
91
+ outputPort: '/api/v1/products/customer-360/query',
92
+ schema: {
93
+ columns: [
94
+ { name: 'customer_id', type: 'STRING' },
95
+ { name: 'full_name', type: 'STRING' },
96
+ { name: 'relationships', type: 'ARRAY<STRING>' },
97
+ { name: 'total_transactions', type: 'INT64' },
98
+ { name: 'lifetime_value', type: 'DECIMAL(15,2)' }
99
+ ]
100
+ },
101
+ quality: {
102
+ completeness: 0.96,
103
+ accuracy: 0.94
104
+ },
105
+ owner: 'team-customer-success'
106
+ },
107
+ {
108
+ name: 'Fraud Network Detection',
109
+ description: 'Graph-based fraud pattern detection using motif search and PageRank analysis',
110
+ sources: ['kgdb'],
111
+ outputPort: '/api/v1/products/fraud-networks/query',
112
+ schema: {
113
+ columns: [
114
+ { name: 'network_id', type: 'STRING' },
115
+ { name: 'entities', type: 'ARRAY<STRING>' },
116
+ { name: 'pattern_type', type: 'STRING' },
117
+ { name: 'risk_score', type: 'FLOAT64' },
118
+ { name: 'pagerank', type: 'FLOAT64' }
119
+ ]
120
+ },
121
+ quality: {
122
+ completeness: 0.92,
123
+ accuracy: 0.88
124
+ },
125
+ owner: 'team-fraud-detection'
126
+ }
127
+ ]
128
+
129
+ for (const product of dataProducts) {
130
+ console.log(` Registering: ${product.name}`)
131
+ console.log(` Sources: ${product.sources.join(', ')}`)
132
+ console.log(` Owner: ${product.owner}`)
133
+ console.log(` Columns: ${product.schema.columns.length}`)
134
+ console.log(` Quality: completeness=${product.quality.completeness}, accuracy=${product.quality.accuracy}`)
135
+ console.log()
136
+
137
+ try {
138
+ const result = await federation.registerDataProduct(product)
139
+ console.log(` Registered with ID: ${result.id}`)
140
+ console.log()
141
+ } catch (error) {
142
+ console.log(` [Demo mode - Would register to catalog]`)
143
+ console.log()
144
+ }
145
+ }
146
+
147
+ // ============================================================================
148
+ // 2. List Catalog
149
+ // ============================================================================
150
+ console.log('2. List Data Products in Catalog')
151
+ console.log('═'.repeat(70))
152
+
153
+ try {
154
+ const catalog = await federation.listCatalog()
155
+ console.log(` Found ${catalog.length} data products:`)
156
+ for (const product of catalog) {
157
+ console.log(` - ${product.name} (${product.owner})`)
158
+ }
159
+ console.log()
160
+ } catch (error) {
161
+ console.log(` [Demo mode - Would list catalog entries]`)
162
+ console.log()
163
+ }
164
+
165
+ // ============================================================================
166
+ // 3. Filter Catalog
167
+ // ============================================================================
168
+ console.log('3. Filter Catalog by Owner')
169
+ console.log('═'.repeat(70))
170
+
171
+ try {
172
+ const riskProducts = await federation.listCatalog({ owner: 'team-risk-analytics' })
173
+ console.log(` Products owned by team-risk-analytics:`)
174
+ for (const product of riskProducts) {
175
+ console.log(` - ${product.name}`)
176
+ }
177
+ console.log()
178
+ } catch (error) {
179
+ console.log(` [Demo mode - Would filter by owner]`)
180
+ console.log()
181
+ }
182
+
183
+ // ============================================================================
184
+ // 4. DCAT DPROD Ontology Structure
185
+ // ============================================================================
186
+ console.log('4. DCAT DPROD Ontology Structure')
187
+ console.log('═'.repeat(70))
188
+ console.log(`
189
+ The catalog uses W3C DCAT-aligned DPROD ontology:
190
+
191
+ ┌─────────────────────────────────────────────────────────────────────┐
192
+ │ dprod:DataProduct (High Risk Customer Analysis) │
193
+ ├─────────────────────────────────────────────────────────────────────┤
194
+ │ dprod:name "High Risk Customer Analysis" │
195
+ │ dprod:description "Cross-domain risk scoring..." │
196
+ │ dprod:owner "team-risk-analytics" │
197
+ │ dprod:registeredIn <urn:catalog:hyperfederate> │
198
+ ├─────────────────────────────────────────────────────────────────────┤
199
+ │ dprod:hasInputPort │
200
+ │ ├─ <urn:port:kgdb> (Knowledge Graph) │
201
+ │ ├─ <urn:port:snowflake> (Snowflake TPC-H) │
202
+ │ └─ <urn:port:bigquery> (BigQuery Public Data) │
203
+ │ │
204
+ │ dprod:hasOutputPort │
205
+ │ └─ <urn:port:api/products/high-risk-customers/query> │
206
+ ├─────────────────────────────────────────────────────────────────────┤
207
+ │ dprod:hasSchema │
208
+ │ ├─ kg_entity: STRING │
209
+ │ ├─ risk_score: FLOAT64 │
210
+ │ ├─ entity_types: ARRAY<STRING> │
211
+ │ └─ ... │
212
+ ├─────────────────────────────────────────────────────────────────────┤
213
+ │ dprod:hasQuality │
214
+ │ ├─ completeness: 0.98 │
215
+ │ ├─ accuracy: 0.95 │
216
+ │ ├─ timeliness: 0.99 │
217
+ │ └─ consistency: 0.97 │
218
+ ├─────────────────────────────────────────────────────────────────────┤
219
+ │ dprod:hasLineage (W3C PROV) │
220
+ │ ├─ prov:wasGeneratedBy <urn:activity:federation-query> │
221
+ │ └─ prov:wasDerivedFrom <urn:source:kgdb>, <urn:source:snowflake> │
222
+ └─────────────────────────────────────────────────────────────────────┘
223
+ `)
224
+
225
+ // ============================================================================
226
+ // 5. Query Catalog via SPARQL
227
+ // ============================================================================
228
+ console.log('5. Query Catalog via SPARQL (Self-Describing)')
229
+ console.log('═'.repeat(70))
230
+ console.log(`
231
+ Since catalog is stored as RDF, we can query it via SPARQL:
232
+
233
+ SELECT ?product ?name ?owner ?quality WHERE {
234
+ ?product a dprod:DataProduct ;
235
+ dprod:name ?name ;
236
+ dprod:owner ?owner ;
237
+ dprod:hasQuality ?q .
238
+ ?q dprod:accuracy ?quality .
239
+ FILTER(?quality > 0.9)
240
+ }
241
+
242
+ Or via federated SQL:
243
+
244
+ SELECT * FROM graph_search('
245
+ PREFIX dprod: <https://gonnect.ai/domains/dprod#>
246
+ SELECT ?name ?owner ?accuracy WHERE {
247
+ ?product a dprod:DataProduct ;
248
+ dprod:name ?name ;
249
+ dprod:owner ?owner ;
250
+ dprod:hasQuality [ dprod:accuracy ?accuracy ] .
251
+ FILTER(?accuracy > 0.9)
252
+ }
253
+ ')
254
+ `)
255
+
256
+ // ============================================================================
257
+ // 6. ProofDAG with Catalog Evidence
258
+ // ============================================================================
259
+ console.log('6. ProofDAG with Catalog Evidence')
260
+ console.log('═'.repeat(70))
261
+
262
+ const proof = new ProofDAG('Data product catalog for enterprise risk analytics')
263
+
264
+ // Add catalog registration as evidence
265
+ const catalogNode = proof.addCatalogEvidence(
266
+ proof.rootId,
267
+ 'High Risk Customer Analysis',
268
+ ['kgdb', 'snowflake', 'bigquery'],
269
+ 'dprod-001'
270
+ )
271
+
272
+ console.log(` Root claim: ${proof.rootClaim}`)
273
+ console.log(` Evidence type: catalog`)
274
+ console.log(` Proof hash: ${proof.computeHash()}`)
275
+ console.log()
276
+
277
+ // ============================================================================
278
+ // 7. Enterprise Governance Workflow
279
+ // ============================================================================
280
+ console.log('7. Enterprise Governance Workflow')
281
+ console.log('═'.repeat(70))
282
+ console.log(`
283
+ DPROD supports enterprise governance workflows:
284
+
285
+ ┌──────────────────────────────────────────────────────────────┐
286
+ │ Data Product Lifecycle │
287
+ ├──────────────────────────────────────────────────────────────┤
288
+ │ │
289
+ │ 1. DRAFT → Owner creates product definition │
290
+ │ │ │
291
+ │ ▼ │
292
+ │ 2. REVIEW → Data steward reviews schema + quality │
293
+ │ │ │
294
+ │ ▼ │
295
+ │ 3. APPROVED → Governance team approves for production │
296
+ │ │ │
297
+ │ ▼ │
298
+ │ 4. PUBLISHED → Product available in catalog │
299
+ │ │ │
300
+ │ ▼ │
301
+ │ 5. MONITORING → Quality metrics tracked continuously │
302
+ │ │
303
+ └──────────────────────────────────────────────────────────────┘
304
+
305
+ Approvals tracked via dprod:ApprovalWorkflow in KGDB.
306
+ `)
307
+
308
+ // ============================================================================
309
+ // Summary
310
+ // ============================================================================
311
+ console.log('╔══════════════════════════════════════════════════════════════════════╗')
312
+ console.log('║ Demo Complete! ║')
313
+ console.log('╚══════════════════════════════════════════════════════════════════════╝')
314
+ console.log(`
315
+ DCAT DPROD Catalog Benefits:
316
+ - Standards-Based: W3C DCAT alignment for interoperability
317
+ - Self-Describing: Stored as RDF, queryable via SPARQL
318
+ - Quality Tracking: Completeness, accuracy, timeliness metrics
319
+ - Lineage: W3C PROV-compatible provenance tracking
320
+ - Governance: Approval workflows for enterprise compliance
321
+ - Discovery: Filter by owner, sources, quality thresholds
322
+
323
+ Unique HyperFederate Capabilities:
324
+ - Catalog entries can include federated query definitions
325
+ - Virtual tables can be promoted to data products
326
+ - Full lineage across KGDB + Snowflake + BigQuery
327
+ - Real-time quality monitoring via SQL analytics
328
+
329
+ Architecture Principle:
330
+ - Catalog storage in Rust KGDB core (RDF native)
331
+ - SPARQL for self-describing queries
332
+ - TypeScript SDK provides thin RPC proxy layer
333
+
334
+ Audit Log Entries: ${federation.getAuditLog().length}
335
+ `)
336
+ }
337
+
338
+ // Run the demo
339
+ runDemo().catch(console.error)
@@ -0,0 +1,273 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * ================================================================================
4
+ * RpcFederationProxy: Federated SQL Demo
5
+ * Cross-Database Queries via WASM RPC Proxy
6
+ * ================================================================================
7
+ *
8
+ * This demo showcases RpcFederationProxy from the rust-kgdb SDK:
9
+ * - Query across KGDB + Snowflake + BigQuery in single SQL statement
10
+ * - 7 Semantic UDFs (similar_to, neighbors, entity_type, etc.)
11
+ * - 9 Table Functions (graph_search, pagerank, vector_search, etc.)
12
+ * - Capability-based security with WasmSandbox
13
+ * - Full provenance tracking with audit log
14
+ *
15
+ * Architecture:
16
+ * - TypeScript SDK: Thin RPC proxy layer
17
+ * - Rust Core: Heavy lifting (DataFusion, Arrow, Vortex, HDRF partitioning)
18
+ *
19
+ * Run: node examples/rpc-federation-sql-demo.js
20
+ *
21
+ * @requires HyperFederate server running at http://localhost:30180
22
+ */
23
+
24
+ const {
25
+ RpcFederationProxy,
26
+ FEDERATION_TOOLS,
27
+ GraphDB,
28
+ WasmSandbox,
29
+ ProofDAG
30
+ } = require('../index.js')
31
+
32
+ // ================================================================================
33
+ // DEMO: Federated SQL Queries
34
+ // ================================================================================
35
+
36
+ async function runDemo() {
37
+ console.log('╔══════════════════════════════════════════════════════════════════════╗')
38
+ console.log('║ RpcFederationProxy: Federated SQL Demo ║')
39
+ console.log('║ Cross-Database Queries via WASM RPC Proxy ║')
40
+ console.log('╚══════════════════════════════════════════════════════════════════════╝\n')
41
+
42
+ // Create RpcFederationProxy with custom config
43
+ const federation = new RpcFederationProxy({
44
+ endpoint: process.env.HYPERFEDERATE_URL || 'http://localhost:30180',
45
+ timeout: 30000,
46
+ identityId: 'demo-user-001',
47
+ // WasmSandbox provides capability-based security
48
+ sandbox: new WasmSandbox({
49
+ capabilities: ['ReadKG', 'ExecuteTool', 'Federation'],
50
+ fuelLimit: 100000
51
+ })
52
+ })
53
+
54
+ console.log(`Federation Endpoint: ${federation.endpoint}`)
55
+ console.log(`Session ID: ${federation.sessionId}`)
56
+ console.log(`Identity ID: ${federation.identityId}`)
57
+ console.log(`Initial Fuel: ${federation.getFuelRemaining()}`)
58
+ console.log()
59
+
60
+ // ============================================================================
61
+ // 1. List available federation tools
62
+ // ============================================================================
63
+ console.log('1. Available Federation Tools (Category Theory: Typed Morphisms)')
64
+ console.log('═'.repeat(70))
65
+ for (const [name, tool] of Object.entries(FEDERATION_TOOLS)) {
66
+ console.log(` ${name}`)
67
+ console.log(` Input: ${tool.input}`)
68
+ console.log(` Output: ${tool.output}`)
69
+ console.log(` Domain: ${tool.domain}`)
70
+ console.log()
71
+ }
72
+
73
+ // ============================================================================
74
+ // 2. Simple SQL query
75
+ // ============================================================================
76
+ console.log('2. Simple SQL Query')
77
+ console.log('═'.repeat(70))
78
+ try {
79
+ const simpleResult = await federation.query('SELECT 1 + 2 as result, NOW() as timestamp')
80
+ console.log(` Columns: ${simpleResult.columns.join(', ')}`)
81
+ console.log(` Rows: ${JSON.stringify(simpleResult.rows, null, 2)}`)
82
+ console.log(` Duration: ${simpleResult.duration}ms`)
83
+ console.log()
84
+ } catch (error) {
85
+ console.log(` [Skipped - Server not running: ${error.message}]`)
86
+ console.log()
87
+ }
88
+
89
+ // ============================================================================
90
+ // 3. KGDB + Snowflake Federation Query
91
+ // ============================================================================
92
+ console.log('3. KGDB + Snowflake Federation Query')
93
+ console.log('═'.repeat(70))
94
+ const kgSfQuery = `
95
+ -- Federation: KGDB (Knowledge Graph) + Snowflake (TPC-H)
96
+ WITH kg_entities AS (
97
+ SELECT * FROM graph_search('
98
+ PREFIX finance: <https://gonnect.ai/domains/finance#>
99
+ PREFIX tpch: <https://gonnect.ai/tpch#>
100
+ SELECT ?person ?custKey WHERE {
101
+ ?person a finance:Person ;
102
+ tpch:custKey ?custKey .
103
+ } LIMIT 10
104
+ ')
105
+ )
106
+ SELECT
107
+ kg.person AS kg_entity,
108
+ kg.custKey,
109
+ sf.C_NAME,
110
+ sf.C_ACCTBAL
111
+ FROM kg_entities kg
112
+ JOIN snowflake_tpch.CUSTOMER sf
113
+ ON CAST(kg.custKey AS INTEGER) = sf.C_CUSTKEY
114
+ LIMIT 10
115
+ `
116
+ console.log(` Query:\n${kgSfQuery.trim().split('\n').map(l => ' ' + l).join('\n')}`)
117
+ console.log()
118
+ try {
119
+ const result = await federation.query(kgSfQuery)
120
+ console.log(` Result: ${result.rowCount} rows in ${result.duration}ms`)
121
+ console.log(` Sources: ${result.metadata.sources?.join(', ')}`)
122
+ console.log()
123
+ } catch (error) {
124
+ console.log(` [Demo mode - Server not running]`)
125
+ console.log()
126
+ }
127
+
128
+ // ============================================================================
129
+ // 4. Three-Way Federation: KGDB + Snowflake + BigQuery
130
+ // ============================================================================
131
+ console.log('4. Three-Way Federation: KGDB + Snowflake + BigQuery')
132
+ console.log('═'.repeat(70))
133
+ const threeWayQuery = `
134
+ -- Three-way federation: KGDB + Snowflake + BigQuery
135
+ WITH
136
+ kg_risk AS (
137
+ SELECT * FROM graph_search('
138
+ PREFIX finance: <https://gonnect.ai/domains/finance#>
139
+ PREFIX tpch: <https://gonnect.ai/tpch#>
140
+ SELECT ?person ?custKey ?riskScore WHERE {
141
+ ?risk finance:assessedFor ?person ;
142
+ finance:riskScore ?riskScore .
143
+ ?person tpch:custKey ?custKey .
144
+ FILTER(?riskScore > 0.7)
145
+ } LIMIT 5
146
+ ')
147
+ ),
148
+ sf_cust AS (
149
+ SELECT C_CUSTKEY, C_NAME, C_ACCTBAL
150
+ FROM snowflake_tpch.CUSTOMER
151
+ LIMIT 100
152
+ )
153
+ SELECT
154
+ kg.person AS kg_entity,
155
+ kg.riskScore,
156
+ sf.C_NAME,
157
+ sf.C_ACCTBAL,
158
+ bq.name AS popular_name,
159
+ bq.number AS birth_count
160
+ FROM kg_risk kg
161
+ JOIN sf_cust sf ON CAST(kg.custKey AS INTEGER) = sf.C_CUSTKEY
162
+ LEFT JOIN bigquery_public.usa_1910_current bq
163
+ ON LOWER(SPLIT_PART(sf.C_NAME, ' ', 1)) = LOWER(bq.name)
164
+ WHERE bq.year = 2000
165
+ LIMIT 10
166
+ `
167
+ console.log(` Query: Three-way federation across KGDB + Snowflake + BigQuery`)
168
+ console.log()
169
+
170
+ // ============================================================================
171
+ // 5. Semantic UDF Examples (7 AI-Powered Functions)
172
+ // ============================================================================
173
+ console.log('5. Semantic UDFs (7 AI-Powered Functions)')
174
+ console.log('═'.repeat(70))
175
+ const udfs = [
176
+ { name: 'similar_to', example: "similar_to('<http://ex.org/Entity1>', 0.7)" },
177
+ { name: 'text_search', example: "text_search('high risk fraud', 5)" },
178
+ { name: 'neighbors', example: "neighbors('<http://ex.org/Entity1>', 2)" },
179
+ { name: 'graph_pattern', example: "graph_pattern('<http://ex.org/Entity1>', NULL, NULL)" },
180
+ { name: 'sparql_query', example: "sparql_query('SELECT ?s WHERE { ?s a <http://ex.org/Person> }')" },
181
+ { name: 'entity_type', example: "entity_type('<http://ex.org/Entity1>')" },
182
+ { name: 'entity_properties', example: "entity_properties('<http://ex.org/Entity1>')" }
183
+ ]
184
+ for (const udf of udfs) {
185
+ console.log(` ${udf.name}`)
186
+ console.log(` Example: SELECT ${udf.example}`)
187
+ console.log()
188
+ }
189
+
190
+ // ============================================================================
191
+ // 6. Table Functions (9 Graph Analytics)
192
+ // ============================================================================
193
+ console.log('6. Table Functions (9 Graph Analytics)')
194
+ console.log('═'.repeat(70))
195
+ const tableFunctions = [
196
+ { name: 'graph_search', desc: 'SPARQL → SQL bridge' },
197
+ { name: 'vector_search', desc: 'Semantic similarity search' },
198
+ { name: 'pagerank', desc: 'PageRank centrality' },
199
+ { name: 'connected_components', desc: 'Community detection' },
200
+ { name: 'shortest_paths', desc: 'Path finding' },
201
+ { name: 'triangle_count', desc: 'Graph density measure' },
202
+ { name: 'label_propagation', desc: 'Community detection' },
203
+ { name: 'datalog_reason', desc: 'Datalog inference' },
204
+ { name: 'motif_search', desc: 'Graph pattern matching' }
205
+ ]
206
+ for (const fn of tableFunctions) {
207
+ console.log(` ${fn.name.padEnd(25)} - ${fn.desc}`)
208
+ }
209
+ console.log()
210
+
211
+ // ============================================================================
212
+ // 7. Audit Log (Provenance Tracking)
213
+ // ============================================================================
214
+ console.log('7. Audit Log (Provenance Tracking - Proof Theory)')
215
+ console.log('═'.repeat(70))
216
+ const auditLog = federation.getAuditLog()
217
+ console.log(` Total entries: ${auditLog.length}`)
218
+ for (const entry of auditLog.slice(0, 3)) {
219
+ console.log(` - Action: ${entry.action}`)
220
+ console.log(` Duration: ${entry.duration}ms`)
221
+ console.log(` Rows: ${entry.rows}`)
222
+ console.log(` Timestamp: ${entry.timestamp}`)
223
+ console.log()
224
+ }
225
+
226
+ // ============================================================================
227
+ // 8. ProofDAG with Federation Evidence
228
+ // ============================================================================
229
+ console.log('8. ProofDAG with Federation Evidence')
230
+ console.log('═'.repeat(70))
231
+ const proof = new ProofDAG('High-risk customers identified across 3 data sources')
232
+
233
+ // Add federation evidence to the proof
234
+ const fedNode = proof.addFederationEvidence(
235
+ proof.rootId,
236
+ threeWayQuery,
237
+ ['kgdb', 'snowflake', 'bigquery'],
238
+ 42, // rowCount
239
+ 890, // duration
240
+ { planHash: 'abc123', cached: false }
241
+ )
242
+ console.log(` Root claim: ${proof.rootClaim}`)
243
+ console.log(` Proof hash: ${proof.computeHash()}`)
244
+ console.log(` Verification: ${JSON.stringify(proof.verify())}`)
245
+ console.log()
246
+
247
+ // ============================================================================
248
+ // Summary
249
+ // ============================================================================
250
+ console.log('╔══════════════════════════════════════════════════════════════════════╗')
251
+ console.log('║ Demo Complete! ║')
252
+ console.log('╚══════════════════════════════════════════════════════════════════════╝')
253
+ console.log(`
254
+ Key Capabilities Demonstrated:
255
+ - RpcFederationProxy: Thin SDK proxy to Rust HyperFederate server
256
+ - Cross-Database SQL: KGDB + Snowflake + BigQuery in single query
257
+ - 7 Semantic UDFs: AI-powered functions in SQL context
258
+ - 9 Table Functions: Graph analytics via SQL
259
+ - WasmSandbox: Capability-based security with fuel metering
260
+ - ProofDAG: Full provenance tracking (W3C PROV compatible)
261
+
262
+ Architecture Principle:
263
+ - Heavy lifting in Rust core (DataFusion, Arrow, Vortex, HDRF)
264
+ - TypeScript SDK is thin RPC proxy layer
265
+ - Category Theory: Tools as typed morphisms (Input → Output)
266
+ - Proof Theory: Every answer has verifiable reasoning chain
267
+
268
+ Fuel Remaining: ${federation.getFuelRemaining()}
269
+ `)
270
+ }
271
+
272
+ // Run the demo
273
+ runDemo().catch(console.error)