Updated constitution.md to reflect the new loading pattern for global variables:
Version: 1.19.0 → 1.20.0 (MINOR)
Changes documented:
1. Section I.II: Updated googleDriveAdapterHelper.js pattern
- Files contain LITERAL BODY of a function
- Use bare 'return {...}' statement (NOT valid standalone JS)
- server.js wraps code in IIFE: (function() { <code> })()
- Clear separation: file = content, server = wrapper
2. Section I.V: Updated loadGlobalVariables() pattern
- Shows wrapping logic with code examples
- Explains IIFE creation and execution
- Documents context creation and object capture
3. Added comprehensive examples:
- Example file structure showing literal function body
- Example server.js wrapping logic with vm.Script
- Shows how return statement exports object
4. Version history updated:
- Documented architecture changes
- Explained rationale for pattern
- Listed benefits of approach
Key pattern documented:
✅ .js files in globalVariables/ contain function bodies with return
✅ Files are NOT valid standalone JavaScript (intentional)
✅ server.js wraps them: '(function() { <code> })()'
✅ Wrapping creates IIFE that executes and returns object
✅ Pattern applies to ALL .js files in globalVariables/
Benefits explained:
- Clear separation of content vs execution wrapper
- Explicit return statement documents exports
- Wrapping logic centralized in server.js
- Consistent pattern across all global variable functions
- Files clearly show their purpose (function bodies)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Changed from IIFE pattern to direct object literal evaluation
Rationale:
- Global variable functions should evaluate to an object directly
- IIFE wrapper was unnecessary complexity
- Simpler pattern: code evaluates to object, not function that returns object
- Matches intended architecture for vm.Script module loading
Changes:
1. Removed IIFE wrapper:
- Before: (function createHelpers() { ... return {...} })()
- After: ({ ... })
2. Removed function indentation (2 spaces throughout file)
3. Updated constitution.md:
- Pattern description: 'IIFE returning object' → 'evaluates to a single object'
- Clarified: 'not wrapped in IIFE'
- Updated all pattern references
Structure:
- File defines classes and functions at top level
- Final expression is object literal referencing all functions
- When executed via vm.Script, evaluates to the object
- Object is assigned to globalVariableContext.googleDriveAdapterHelper
Benefits:
✅ Simpler pattern (no function wrapper)
✅ Clearer intent (direct object evaluation)
✅ Matches architecture description
✅ Easier to understand and maintain
✅ Same functionality, cleaner implementation
Before (IIFE):
After (Object Literal):
Testing:
✓ Syntax validated
✓ Server starts successfully
✓ Module loads: 'Loaded global functions: googleDriveAdapterHelper'
✓ All function calls work correctly
✓ Request handling works as expected
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Version: 1.17.0 → 1.18.0 (MINOR: Function loading pattern documentation)
Changes:
- Document loadGlobalVariableFunctions() generic pattern
- Update VM context injection code example
- Update helpers.js loading documentation
- Document tempContext with full globalVMContext + globalVariableContext
- Fix duplicate req entry and renumber to 11 and 12
Key Documentation Updates:
1. Section I.II - helpers.js Pattern:
- Loaded by loadGlobalVariableFunctions() which scans ALL .js files
- Filename determines key: helpers.js → globalVariableContext.helpers
- Executed in tempContext with full VM globals access
2. Section I.V - VM Context Injection Pattern:
- Replaced specific helpers loading code with generic pattern
- Documents loadGlobalVariableFunctions() scanning all .js files
- Shows tempContext creation with {...globalVMContext, ...globalVariableContext}
- Documents 4-step loading process with filename-to-key mapping
3. Section I.V - Helper Functions Module:
- Added Generic Loading Pattern section
- Documents full access to VM globals (axios, jwt, crypto, etc.)
- Documents access to previously loaded JSON data and functions
- Added note about extensibility (utils.js, validators.js, etc.)
Architecture Notes:
- Generic pattern: any .js file in globalVariables/ auto-loaded
- tempContext includes all dependencies from both contexts
- Function modules can access same globals as proxy.js
- Supports multiple function modules without code changes
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>