Repository navigation
release: v2.8.0 - #69
Merged
Merged
Conversation
…Api() method to dynamically extend the Slothlet API at runtime by loading modules from a folder and merging them at a specified dotted path (e.g., 'runtime.plugins'). Supports both lazy and eager loading modes, creates intermediate objects automatically, and updates live bindings. Added comprehensive test suite in tests/test-add-api.mjs.
…handling - Add input validation for apiPath (empty strings, leading/trailing/consecutive dots) - Fix error handling to avoid wrapping directory check errors - Fix debug logging to handle both objects and functions (Object.keys safety) - Add null checks for intermediate path navigation - Support functions as intermediate values (slothlet function.property pattern) - Prevent extension through primitives while allowing objects and functions - Add comprehensive test coverage for edge cases (merge, function extension, primitives) All tests pass with 6 test suites validating eager/lazy modes and error handling.
- Create SlothletAPI type definition with shutdown, addApi, and describe methods - Update slothlet function return type from generic Promise<function|object> to Promise<SlothletAPI> - Provides proper TypeScript IntelliSense and type checking for API management methods - Includes specific function signatures with parameter types and return types All precommit validation passed (6/6 steps)
- Add race condition warning in JSDoc documentation for concurrent calls - Normalize apiPath by trimming whitespace before use (consistency fix) - Add folderPath type validation to prevent unclear errors - Add warning when function overwrites existing non-function value (data loss prevention) - Update TypeScript return types to use SlothletAPI across all entry points - Add test cases for whitespace-only apiPath and non-string folderPath All fixes verified with precommit validation (6/6 steps passed) Addresses: - Concurrent call race conditions (documentation) - Whitespace handling inconsistency in apiPath validation - Missing type validation for folderPath parameter - Silent data loss when function overwrites object - TypeScript type inconsistency in entry points
- Add allowApiOverwrite option (default true) to prevent accidental endpoint overwrites - Normalize apiPath with trim() and update error message clarity - Add comprehensive folderPath type validation - Handle null/undefined/primitive newModules cases with appropriate warnings - Make management methods conditionally enumerable (shutdown based on user-defined, addApi/describe always false) - Fix mutateLiveBindingFunction to copy non-enumerable management methods - Add extensive JSDoc documentation with race condition warnings - Update README with allowApiOverwrite config and concurrency warning - Add test coverage for edge cases (non-string params, whitespace-only paths) - Update TypeScript types for all entry points to include SlothletAPI All precommit validation passed (6/6 steps)
…e typedef - Add allowApiOverwrite parameter documentation to index.mjs and index.cjs - Update SlothletAPI typedef for describe method with accurate return types - Add comprehensive test coverage for allowApiOverwrite configuration - Test both object and function overwrites with allow/prevent scenarios All precommit validation passed (6/6 steps)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 13 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Shinrai
approved these changes
Dec 27, 2025
Shinrai
pushed a commit
that referenced
this pull request
Feb 11, 2026
# release: v2.8.0 - Dynamic API Extension and Management Methods
## 🎯 Major Features
### Dynamic API Extension with `addApi()` Method
Implemented `addApi(apiPath, folderPath)` method to dynamically extend the Slothlet API at runtime by loading modules from a folder and merging them at a specified dotted path (e.g., `runtime.plugins`, `services.external`).
**Key Capabilities:**
- Load and merge API modules at runtime without restarting the application
- Support for deeply nested paths with automatic intermediate object creation
- Full compatibility with both lazy and eager loading modes
- Automatic live binding updates for multi-instance isolation
- Slothlet's function.property pattern support (can extend functions with properties)
### Management Methods with Proper TypeScript Support
Added comprehensive TypeScript definitions for all management methods:
- `shutdown()` - Cleanup and resource disposal with conditional enumerable
- `addApi(apiPath, folderPath)` - Dynamic API extension
- `describe(showAll?)` - API metadata with accurate return type signatures
## 🛡️ Configuration & Safety
### New `allowApiOverwrite` Configuration Option
- **Default:** `true` (backwards compatible)
- **Purpose:** Prevent accidental endpoint overwrites during dynamic API extension
- **Behavior:**
- When `false`: Logs warning and skips overwrite attempts
- When `true`: Allows overwrites with data loss warnings
### Input Validation & Error Handling
- Normalize `apiPath` by trimming whitespace before validation
- Validate `folderPath` parameter type to prevent unclear errors
- Handle null/undefined/primitive `newModules` cases with warnings
- Prevent empty path segments (consecutive dots, leading/trailing dots)
- Clear error messages: "non-empty, non-whitespace string"
## 🐛 Critical Fixes
### Fixed Non-Enumerable Management Methods Issue
Fixed `mutateLiveBindingFunction` to properly copy non-enumerable management methods:
- Previously used `Object.entries()` which only copies enumerable properties
- Now explicitly copies `shutdown`, `addApi`, and `describe` with property descriptors
- Ensures management methods are accessible in all contexts (ESM and CJS)
### Conditional Enumerable Properties
- `shutdown`: enumerable when user-defined shutdown exists, non-enumerable when management-only
- `addApi`: always non-enumerable (hidden from API iteration)
- `describe`: non-enumerable by default (management method)
### TypeScript Type Consistency
Updated all entry points (`index.mjs`, `index.cjs`) to return `SlothletAPI` type:
```typescript
SlothletAPI {
shutdown: () => Promise<void>
addApi: (apiPath: string, folderPath: string) => Promise<void>
describe: (showAll?: boolean) => ((string|symbol)[]|object|Promise<object>)
}
```
## 📚 Documentation
### JSDoc Enhancements
- Added comprehensive JSDoc for `addApi()` method with examples
- Race condition warning for concurrent `addApi` calls
- Documented shallow merge behavior for Object.assign
- Explained intermediate path navigation (function.property pattern)
- Added parameter documentation to all entry points
### README Updates
- Configuration section for `allowApiOverwrite` option
- Examples showing enable/disable overwrite protection
- Concurrency warning for `addApi` method usage
- Complete API extension workflow examples
## 🧪 Test Coverage
### Comprehensive `addApi` Test Suite
Added `tests/test-add-api.mjs` with 7 test scenarios:
1. **Eager mode** - Basic API extension with immediate loading
2. **Lazy mode** - API extension with proxy-based lazy loading
3. **Nested paths** - Deep path creation (`level1.level2.level3`)
4. **Error handling** - Non-existent folders, invalid parameters, empty segments
5. **Merging** - Adding to existing objects without data loss
6. **Function extension** - Adding properties to functions (slothlet pattern)
7. **allowApiOverwrite** - Testing overwrite prevention and permission
### Test Results
- All 26 test cases passing
- Edge case coverage: whitespace-only paths, non-string parameters, null/undefined handling
- Validation: Full precommit suite passing (6/6 steps)
## 📝 Migration Guide
### Enabling Overwrite Protection
```javascript
const api = await slothlet({
dir: './api',
allowApiOverwrite: false // Prevent accidental overwrites
});
// First call succeeds
await api.addApi('plugins.auth', './plugins/auth');
// Second call to same path logs warning and skips
await api.addApi('plugins.auth', './plugins/oauth');
// Warning: Skipping addApi: API path "plugins.auth" already exists
```
### Dynamic API Extension Example
```javascript
const api = await slothlet({ dir: './api' });
// Extend API at runtime
await api.addApi('runtime.newFeature', './features/new-feature');
// Access new API immediately
const result = api.runtime.newFeature.someMethod();
```
## ✅ Validation
All precommit validation steps passed:
- ✅ API Structure Debug (576ms)
- ✅ Node Test Suite - 26 tests passed (22164ms)
- ✅ Build Distribution (1029ms)
- ✅ Node ViTest Suite (1808ms)
- ✅ Build TypeScript Types (2425ms)
- ✅ Validate TypeScript (33829ms)
---
**Full Changelog:** v2.7.1...v2.8.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 What's Changed
💥 Breaking Changes
No breaking changes
✨ Features
🐛 Bug Fixes
No bug fixes
🔧 Other Changes
No other changes
🏷️ Release Information
👥 Contributors