Files
google-drive-content-adapter/src
Peter.Morton 1fecaf52f7 Implement literal function body pattern for global variable functions
Changed architecture so .js files contain literal function bodies

Changes to googleDriveAdapterHelper.js:
1. Changed from object literal (\({...}\)) to return statement (return {...})
2. File now contains LITERAL BODY of a function
3. Updated header comment to explain this pattern
4. File is NO LONGER valid standalone JavaScript (has bare return)

Changes to server.js loadGlobalVariables():
1. Wrap loaded code in function: `(function() { ${code} })()`
2. Creates IIFE that executes the function body
3. Captures returned object from the function
4. Pattern applies to ALL .js files in globalVariables/

Pattern:
```javascript
// File: googleDriveAdapterHelper.js (literal function body)
class DocumentCountExceededError extends Error {...}
function generateRequestId() {...}

return {
  DocumentCountExceededError,
  generateRequestId,
  // ... all exports
};
```

```javascript
// server.js wraps it:
const wrappedCode = `(function() {
${code}
})()`;
const script = new vm.Script(wrappedCode, { filename: file });
const returnedObject = script.runInContext(context);
```

Benefits:
 Files represent pure function bodies
 Wrapping logic centralized in server.js
 Clear separation: content vs. execution wrapper
 Explicit return statement in function body
 Consistent pattern for all global variable functions
 Easy to understand: file = function body, server = wrapper

Testing:
✓ Server starts successfully
✓ Module loads: 'Loaded global functions: googleDriveAdapterHelper'
✓ Object captured: type=object, keys=11
✓ All functions accessible in VM context
✓ proxy.js can call googleDriveAdapterHelper.* functions

Note: googleDriveAdapterHelper.js will show syntax error if run standalone
(has bare return statement) - this is intentional, it's a function body!

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-07 12:31:23 -06:00
..
2026-03-06 23:34:00 -06:00