Skip to content

release: v2.8.0 - #69

Merged
Shinrai merged 8 commits into
masterfrom
release/2.8.0
Dec 27, 2025
Merged

Shinrai merged 8 commits into
masterfrom
release/2.8.0

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Dec 27, 2025 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

  • feat: Add dynamic API extension with addApi method (e7b613e)

🐛 Bug Fixes

No bug fixes

🔧 Other Changes

No other changes

🏷️ Release Information

👥 Contributors

Shinrai and others added 3 commits December 26, 2025 19:38
…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.
@cldmv-bot cldmv-bot Bot added semver: explicit This release uses an explicitly specified version rather than an auto-detected bump release Marks a pull request as a pending release — merge to publish a new version labels Dec 27, 2025
@Shinrai
Shinrai requested a review from Copilot December 27, 2025 04:00

This comment was marked as resolved.

…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.

This comment was marked as resolved.

- 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)

This comment was marked as resolved.

- 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

This comment was marked as resolved.

- 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)

This comment was marked as resolved.

…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)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Shinrai merged commit e10e7b4 into master 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
@Shinrai
Shinrai deleted the release/2.8.0 branch April 7, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release Marks a pull request as a pending release — merge to publish a new version semver: explicit This release uses an explicitly specified version rather than an auto-detected bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants