Skip to content

Commit

Permalink
Merge pull request #3 from jdnichollsc/main
Browse files Browse the repository at this point in the history
fix register client async method
  • Loading branch information
jdnichollsc authored Nov 1, 2022
2 parents 0987039 + 4d2cf45 commit 499aaf6
Show file tree
Hide file tree
Showing 26 changed files with 3,338 additions and 1,785 deletions.
14 changes: 14 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# don't ever lint node_modules
node_modules

# don't lint build output (make sure it's set to your correct build folder name)
dist

# don't lint nyc coverage output
coverage

.eslintrc.js

.babel.config.js

lib/**/*.spec.ts
29 changes: 14 additions & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
module.exports = {
parser: "@typescript-eslint/parser",
parser: '@typescript-eslint/parser',
parserOptions: {
project: "tsconfig.json",
sourceType: "module",
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ["@typescript-eslint/eslint-plugin"],
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint",
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-types": "off",
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-types': 'off',
},
};
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,79 @@ export class AppController {
}
```

## Advanced Options

- Creating the Worker connection:
```ts
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TemporalModule } from 'nestjs-temporal';
import { bundleWorkflowCode, NativeConnection, Runtime } from '@temporalio/worker';
import * as path from 'path';

@Module({
imports: [
TempModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => {
Runtime.install({});
const temporalHost = config.get('app.temporalHost');
const connection = await NativeConnection.connect({
address: temporalHost,
});
const workflowBundle = await bundleWorkflowCode({
workflowsPath: path.join(__dirname, './workflows'),
});

return {
connection,
taskQueue: 'default',
workflowBundle,
};
},
}),
ClientModule,
],
})
export class AppModule {}
```

- Creating the client connection:
```ts
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TemporalModule } from 'nestjs-temporal';
import { Connection } from '@temporalio/client';

@Module({
imports: [
TempModule.registerClientAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => {
const temporalHost = config.get('app.temporalHost');
const connection = await Connection.connect({
address: temporalHost,
});

return {
connection,
};
},
}),
],
})
export class ClientModule {}
```


## People

- Author - [Zegue kurt](https://github.com/KurtzL)
- Contributor - [Surya Prashanth](https://github.com/Prashant-Surya)
- Contributor - [AmirSaber Sharifi](https://github.com/amirsaber)
- Contributor - [J.D Nicholls](https://github.com/jdnichollsc)

## License

Expand Down
3 changes: 2 additions & 1 deletion lib/decorators/activities.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Scope, SetMetadata } from '@nestjs/common';
import { SCOPE_OPTIONS_METADATA } from '@nestjs/common/constants';
import { TEMPORAL_MODULE_ACTIVITIES } from '../temporal.constants';
import { ActivityOptions } from '@temporalio/workflow';

import { TEMPORAL_MODULE_ACTIVITIES } from '../temporal.constants';

export interface ActivitiesOptions extends ActivityOptions {
/**
* Specifies the name of the queue to subscribe to.
Expand Down
1 change: 1 addition & 0 deletions lib/decorators/activity.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SetMetadata } from '@nestjs/common';

import { TEMPORAL_MODULE_ACTIVITY } from '../temporal.constants';

export interface ActivityOptions {
Expand Down
1 change: 1 addition & 0 deletions lib/decorators/inject-temporal-client.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Inject } from '@nestjs/common';

import { getQueueToken } from '../utils';

export const InjectTemporalClient = (name?: string): ParameterDecorator =>
Expand Down
1 change: 1 addition & 0 deletions lib/decorators/workflow.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SetMetadata } from '@nestjs/common';

import { TEMPORAL_MODULE_WORKFLOW_METHOD } from '../temporal.constants';

export interface WorkflowMethodOptions {
Expand Down
1 change: 1 addition & 0 deletions lib/decorators/workflows.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Scope, SetMetadata } from '@nestjs/common';
import { SCOPE_OPTIONS_METADATA } from '@nestjs/common/constants';

import { TEMPORAL_MODULE_WORKFLOW } from '../temporal.constants';

export interface WorkflowsOptions {
Expand Down
5 changes: 4 additions & 1 deletion lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from './temporal-module-options.interface';
export * from './shared-temporal-config.interface';
export * from './shared-worker-config.interface';
export * from './shared-runtime-config.interface';
export * from './shared-connection-config.interface';
export * from './temporal-module.interface';
export * from './shared-workflow-client-options.interface';
30 changes: 30 additions & 0 deletions lib/interfaces/shared-connection-config.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { FactoryProvider, ModuleMetadata, Type } from '@nestjs/common';
import { NativeConnectionOptions } from '@temporalio/worker';

export interface SharedConnectionConfigurationFactory {
createSharedConfiguration(): Promise<NativeConnectionOptions> | NativeConnectionOptions;
}

export interface SharedConnectionAsyncConfiguration
extends Pick<ModuleMetadata, 'imports'> {
/**
* Existing Provider to be used.
*/
useExisting?: Type<SharedConnectionConfigurationFactory>;
/**
* Type (class name) of provider (instance to be registered and injected).
*/
useClass?: Type<SharedConnectionConfigurationFactory>;
/**
* Factory function that returns an instance of the provider to be injected.
*/
useFactory?: (...args: any[]) => Promise<NativeConnectionOptions> | NativeConnectionOptions;
/**
* Instance of a provider to be injected.
*/
useValue?: NativeConnectionOptions;
/**
* Optional list of providers to be injected into the context of the Factory function.
*/
inject?: FactoryProvider['inject'];
}
30 changes: 30 additions & 0 deletions lib/interfaces/shared-runtime-config.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { FactoryProvider, ModuleMetadata, Type } from '@nestjs/common';
import { RuntimeOptions } from '@temporalio/worker';

export interface SharedRuntimeConfigurationFactory {
createSharedConfiguration(): Promise<RuntimeOptions> | RuntimeOptions;
}

export interface SharedRuntimeAsyncConfiguration
extends Pick<ModuleMetadata, 'imports'> {
/**
* Existing Provider to be used.
*/
useExisting?: Type<SharedRuntimeConfigurationFactory>;
/**
* Type (class name) of provider (instance to be registered and injected).
*/
useClass?: Type<SharedRuntimeConfigurationFactory>;
/**
* Factory function that returns an instance of the provider to be injected.
*/
useFactory?: (...args: any[]) => Promise<RuntimeOptions> | RuntimeOptions;
/**
* Instance of a provider to be injected.
*/
useValue?: RuntimeOptions;
/**
* Optional list of providers to be injected into the context of the Factory function.
*/
inject?: FactoryProvider['inject'];
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface SharedWorkerAsyncConfiguration
* Factory function that returns an instance of the provider to be injected.
*/
useFactory?: (...args: any[]) => Promise<WorkerOptions> | WorkerOptions;
/**
* Instance of a provider to be injected.
*/
useValue?: WorkerOptions;
/**
* Optional list of providers to be injected into the context of the Factory function.
*/
Expand Down
31 changes: 31 additions & 0 deletions lib/interfaces/shared-workflow-client-options.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { FactoryProvider, ModuleMetadata, Type } from '@nestjs/common';
import { WorkflowClientOptions } from '@temporalio/client';

export interface SharedWorkflowClientOptionsFactory {
createSharedConfiguration(): Promise<WorkflowClientOptions> | WorkflowClientOptions;
}

export interface SharedWorkflowClientOptions
extends Pick<ModuleMetadata, 'imports'> {
name?: string;
/**
* Existing Provider to be used.
*/
useExisting?: Type<SharedWorkflowClientOptionsFactory>;
/**
* Type (class name) of provider (instance to be registered and injected).
*/
useClass?: Type<SharedWorkflowClientOptionsFactory>;
/**
* Factory function that returns an instance of the provider to be injected.
*/
useFactory?: (...args: any[]) => Promise<WorkflowClientOptions> | WorkflowClientOptions;
/**
* Instance of a provider to be injected.
*/
useValue?: WorkflowClientOptions;
/**
* Optional list of providers to be injected into the context of the Factory function.
*/
inject?: FactoryProvider['inject'];
}
3 changes: 2 additions & 1 deletion lib/interfaces/temporal-module.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DynamicModule } from '@nestjs/common';
import { WorkerOptions } from '@temporalio/worker';
import { SharedWorkerAsyncConfiguration } from './shared-temporal-config.interface';

import { SharedWorkerAsyncConfiguration } from './shared-worker-config.interface';
import { TemporalModuleOptions } from './temporal-module-options.interface';

export interface ITemporalModule {
Expand Down
1 change: 1 addition & 0 deletions lib/temporal-metadata.accessors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable, Type } from '@nestjs/common';
import { Reflector } from '@nestjs/core';

import {
TEMPORAL_MODULE_ACTIVITIES,
TEMPORAL_MODULE_ACTIVITY,
Expand Down
1 change: 1 addition & 0 deletions lib/temporal.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export const TEMPORAL_MODULE_WORKFLOW_METHOD =
export const TEMPORAL_WORKER_CONFIG = '_temporal_worker_config';
export const TEMPORAL_CORE_CONFIG = '_temporal_core_config';
export const TEMPORAL_CLIENT_CONFIG = '_temporal_client_config';
export const TEMPORAL_CONNECTION_CONFIG = '_temporal_connection_config';
Loading

0 comments on commit 499aaf6

Please sign in to comment.