Skip to content

Expose Decorator

This file defines the Expose decorator, which is used to mark class methods as exposed to a worker in the @sodacore/core library. When used in combination with the @Worker decorator, it allows specific methods to be proxied and executed within the worker context.


Features

  • Method Exposure: Marks methods to be accessible and callable from the worker.
  • Metadata Management: Collects all exposed methods in metadata for later retrieval and proxying.

Usage

typescript
import Expose from './decorator/expose';

class MyWorkerClass {
	@Expose()
	doWork() {
		// This method can be called from the worker context
	}
}
  • Use @Expose() on any method you want to make available to the worker.
  • Typically used alongside the @Worker decorator on the class.

API

Expose(): MethodDecorator

  • Returns: A method decorator that registers the method as exposed to the worker.

How It Works

  • Retrieves the current list of exposed methods from the worker metadata.
  • Adds the decorated method's property key to the list.
  • Updates the metadata with the new list of exposed methods.

Notes

  • Only methods decorated with @Expose will be proxied and callable from the worker context.
  • Designed to be used in worker-enabled classes for fine-grained control over method exposure.

Released under the Apache-2.0 License.