npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@temporal-contract/worker-nestjs

v0.0.2

Published

NestJS integration for temporal-contract worker

Downloads

183

Readme

@temporal-contract/worker-nestjs

NestJS integration for @temporal-contract/worker providing a type-safe way to define Temporal workers with activities.

Features

  • ConfigurableModuleBuilder Integration: Use NestJS's ConfigurableModuleBuilder for dynamic module configuration
  • Type-Safe Activities: All activities must be implemented upfront, enforced by TypeScript
  • Full Dependency Injection: Activities have access to NestJS services
  • Contract Validation: Automatic validation through the contract system

Installation

pnpm add @temporal-contract/worker-nestjs

Quick Start

1. Define Your Contract

See @temporal-contract/contract for contract definition.

2. Implement Activities

All activities must be provided upfront in the module configuration. Use declareActivitiesHandler to create type-safe activities.

// app.module.ts
import { Module } from '@nestjs/common';
import { TemporalModule } from '@temporal-contract/worker-nestjs';
import { NativeConnection } from '@temporalio/worker';
import { Future, Result } from '@temporal-contract/boxed';
import { ActivityError, declareActivitiesHandler } from '@temporal-contract/worker/activity';
import { orderProcessingContract } from './contract';

@Module({
  imports: [
    TemporalModule.forRootAsync({
      useFactory: async () => ({
        contract: orderProcessingContract,
        activities: declareActivitiesHandler({
          contract: orderProcessingContract,
          activities: {
            // Global activities
            log: ({ level, message }) => {
              console.log(`[${level}] ${message}`);
              return Future.value(Result.Ok(undefined));
            },

            // Workflow-specific activities
            processOrder: {
              processPayment: ({ customerId, amount }) => {
                return Future.make(async (resolve) => {
                  try {
                    // Implementation
                    resolve(Result.Ok({ transactionId: 'txn_123' }));
                  } catch (error) {
                    resolve(Result.Error(
                      new ActivityError('PAYMENT_FAILED', 'Payment failed', error)
                    ));
                  }
                });
              },
            },
          },
        }),
        connection: await NativeConnection.connect({ address: 'localhost:7233' }),
        workflowsPath: require.resolve('./workflows'),
      }),
    }),
  ],
})
export class AppModule {}

3. Start Your Application

The worker starts automatically when the NestJS application initializes and shuts down gracefully when the application closes.

// main.ts
import { NestFactory } from '@nestjs/common';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.createApplicationContext(AppModule);

  // Worker starts automatically during module initialization

  // Handle graceful shutdown
  process.on('SIGTERM', async () => {
    await app.close(); // Worker shuts down automatically
  });

  process.on('SIGINT', async () => {
    await app.close();
  });
}

bootstrap();

API Reference

TemporalModule

Dynamic NestJS module for configuring Temporal workers.

Methods

  • forRoot(options): Synchronous configuration
  • forRootAsync(options): Asynchronous configuration with factory pattern

TemporalService

Service managing the Temporal worker lifecycle.

Methods

  • getWorker(): Get the worker instance (throws if not initialized)

The service automatically:

  • Initializes and starts the worker when the module initializes (onModuleInit)
  • Shuts down the worker when the module is destroyed (onModuleDestroy)

bootstrap();


## Why This Approach?

1. **Type Safety**: TypeScript ensures all activities from the contract are implemented
2. **Explicit**: All activities defined in one place
3. **No Magic**: No decorators or reflection required

## License

MIT