about summary refs log tree commit diff stats
path: root/js/scripting-lang/repl/demo_repl.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/repl/demo_repl.js')
-rw-r--r--js/scripting-lang/repl/demo_repl.js114
1 files changed, 114 insertions, 0 deletions
diff --git a/js/scripting-lang/repl/demo_repl.js b/js/scripting-lang/repl/demo_repl.js
new file mode 100644
index 0000000..8c42a28
--- /dev/null
+++ b/js/scripting-lang/repl/demo_repl.js
@@ -0,0 +1,114 @@
+#!/usr/bin/env node
+
+/**
+ * REPL Demonstration Script
+ * 
+ * This script demonstrates the harness-integrated REPL capabilities
+ * by running through comprehensive examples of TEA architecture.
+ */
+
+import { REPL } from './repl.js';
+
+async function demonstrateREPL() {
+    console.log('🚀 REPL Demonstration\n');
+    
+    const repl = new REPL();
+    
+    // Demonstrate basic state management
+    console.log('1️⃣ Basic State Management:');
+    await repl.executeScript(`/* Basic state management example */
+/* Create and process state */
+x : 5;
+y : 10;
+sum : x + y;
+result : { x, y, sum };
+/* Return processed state */
+result`);
+    repl.showState();
+    console.log('');
+    
+    // Demonstrate counter with state persistence
+    console.log('2️⃣ Counter with State Persistence:');
+    await repl.executeScript(`/* Counter example with state persistence */
+/* Simple counter logic */
+count : 0;
+new_count : count + 1;
+result : { count: new_count, name: "Counter" };
+/* Return updated state */
+result`);
+    repl.showState();
+    console.log('');
+    
+    // Demonstrate data processing pipeline
+    console.log('3️⃣ Data Processing Pipeline:');
+    await repl.executeScript(`/* Data processing pipeline */
+/* Process simple data */
+numbers : {1: 10, 2: 3, 3: 8};
+double : x -> x * 2;
+doubled : map @double numbers;
+result : { original: numbers, processed: doubled };
+/* Return processed result */
+result`);
+    repl.showState();
+    console.log('');
+    
+    // Demonstrate user management system
+    console.log('4️⃣ User Management System:');
+    await repl.executeScript(`/* User management system */
+/* Simple user validation */
+name : "Alice";
+age : 25;
+status : when age is age >= 18 then "valid" _ then "underage";
+user : { name, age, status };
+/* Return validated state */
+user`);
+    repl.showState();
+    console.log('');
+    
+    // Demonstrate error handling
+    console.log('5️⃣ Error Handling:');
+    await repl.executeScript(`/* Error handling example */
+/* Safe operations through harness */
+data : 10;
+safe_operation : when data is data > 0 then data / 2 _ then 0;
+result : { operation: "safe_division", result: safe_operation };
+/* Return safe result */
+result`);
+    repl.showState();
+    console.log('');
+    
+    // Demonstrate version history
+    console.log('6️⃣ Version History:');
+    repl.showHistory();
+    console.log('');
+    
+    // Demonstrate adapters
+    console.log('7️⃣ Available Adapters:');
+    repl.showAdapters();
+    console.log('');
+    
+    // Demonstrate state rollback
+    console.log('8️⃣ State Rollback:');
+    if (repl.currentVersion > 1) {
+        console.log(`Rolling back from version ${repl.currentVersion} to version 1...`);
+        await repl.rollbackToVersion(1);
+    } else {
+        console.log('Not enough versions for rollback demonstration');
+    }
+    console.log('');
+    
+    console.log('✅ REPL Demonstration Complete!');
+    console.log('\n🎯 Key Features Demonstrated:');
+    console.log('   • TEA Architecture (Model → Update → Commands → View)');
+    console.log('   • State Management with Versioning & History');
+    console.log('   • Command Processing (..emit, ..listen)');
+    console.log('   • Adapter Integration for Side Effects');
+    console.log('   • Pure Function Script Execution');
+    console.log('   • State Rollbacks & Branching');
+    console.log('   • Error Handling in Harness');
+    console.log('   • State Persistence & History');
+    console.log('\n🚀 Ready for interactive use! Run "bun run repl" to start.');
+}
+
+// Run the demonstration
+demonstrateREPL().catch(console.error); 
\ No newline at end of file