Skip to content

feat: implement SDK class with capability composition#13

Merged
prosdev merged 1 commit intomainfrom
feature/task-6-sdk-class
Dec 17, 2025
Merged

feat: implement SDK class with capability composition#13
prosdev merged 1 commit intomainfrom
feature/task-6-sdk-class

Conversation

@prosdev
Copy link
Copy Markdown
Collaborator

@prosdev prosdev commented Dec 17, 2025

Implements #6 - Task #6: SDK Class

Summary

The main SDK class that brings everything together! This is the integration piece that composes all capabilities into a functional plugin system.

Core SDK Features

  • Plugin registration via use() with capability injection
  • Event-based lifecycle (sdk:init, sdk:ready, sdk:destroy)
  • Method chaining support (sdk.use().use().init())
  • Delegates to capabilities (Config, Emitter)
  • Proper initialization checks and cleanup

Capability Composition in use()

The magic happens in the use() method:

use(pluginFn: PluginFunction): this {
  // Create instances for this plugin
  const namespace = new Namespace();
  const expose = new Expose(this);
  
  // Compose Plugin object with all capabilities
  const plugin: Plugin = {
    ns: namespace.ns.bind(namespace),
    defaults: this.configInstance.defaults.bind(this.configInstance),
    on: this.emitter.on.bind(this.emitter),
    off: this.emitter.off.bind(this.emitter),
    emit: this.emitter.emit.bind(this.emitter),
    expose: expose.expose.bind(expose),
    mustEnable: () => this.configInstance.markRequired(namespace.name)
  };
  
  // Execute plugin with injected capabilities
  pluginFn(plugin, this, this.configInstance);
  
  return this;
}

Public API

Method Description
use(pluginFn) Register plugins
init() Initialize SDK (idempotent)
destroy() Clean up SDK
get/set() Config access
on/off/emit() Event handling
getAll() Get all config
isReady() Check initialization state

Usage Example

const sdk = new SDK({ name: 'my-sdk' });

sdk.use((plugin, instance, config) => {
  plugin.ns('analytics');
  plugin.defaults({ analytics: { endpoint: 'https://api.example.com' } });
  
  plugin.expose({
    track(event: string) {
      console.log('Tracking:', event);
    }
  });
  
  instance.on('sdk:ready', () => {
    console.log('Plugin ready!');
  });
});

await sdk.init();
sdk.track('page_view');

Testing

  • 52 comprehensive tests
  • 97.14% coverage on sdk.ts
  • Integration scenarios:
    • Plugin communication via events
    • Config sharing between plugins
    • Lifecycle event handling
    • Multiple plugins working together

Additional Changes

  • ✅ Added test:coverage script to package.json
  • ✅ Excluded barrel files (index.ts, use.ts) from coverage
  • Overall: 98.97% coverage, 192 tests passing
  • ✅ Comprehensive README for core package

Documentation

Added complete README with:

  • Quick start guide
  • Plugin creation tutorial
  • Core concepts and API reference
  • Advanced patterns
  • TypeScript support guide

Closes #6

- Quick start guide with examples
- Plugin creation tutorial
- Core concepts and capabilities
- Full API reference
- Advanced patterns (plugin communication, shared config)
- TypeScript support documentation
- Lifecycle events guide
@prosdev prosdev merged commit 1f10385 into main Dec 17, 2025
1 check passed
@prosdev prosdev mentioned this pull request Dec 17, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SDK Class

2 participants