-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from BAXUSNFT/main
fix: register client async method
- Loading branch information
Showing
17 changed files
with
192 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
lib/interfaces/shared-workflow-client-options.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { OnApplicationShutdown } from "@nestjs/common"; | ||
import { WorkflowClient, WorkflowClientOptions } from "@temporalio/client"; | ||
|
||
export function assignOnAppShutdownHook(client: WorkflowClient) { | ||
(client as unknown as OnApplicationShutdown).onApplicationShutdown = client.connection.close; | ||
return client; | ||
} | ||
|
||
export function getWorkflowClient(options?: WorkflowClientOptions) { | ||
const client = new WorkflowClient(options); | ||
return assignOnAppShutdownHook(client); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export function getQueueToken(name?: string): string { | ||
return name ? `TemporalQueue_${name}` : 'TemporalQueue_default'; | ||
} | ||
|
||
export function getAsyncQueueToken(name?: string): string { | ||
return name ? `TemporalAsyncQueue_${name}` : 'TemporalAsyncQueue_default'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './get-queue-options-token.util'; | ||
export * from './get-shared-config-token.util'; | ||
export * from './get-queue-token.util'; | ||
export * from './client.util'; | ||
export * from './provider.util'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Provider } from "@nestjs/common"; | ||
import { WorkflowClientOptions } from "@temporalio/client"; | ||
|
||
import { SharedWorkflowClientOptions } from "../interfaces/shared-workflow-client-options.interface"; | ||
import { SharedConnectionAsyncConfiguration, SharedRuntimeAsyncConfiguration, SharedWorkerAsyncConfiguration } from "../interfaces"; | ||
import { getWorkflowClient } from "./client.util"; | ||
import { getAsyncQueueToken, getQueueToken } from "./get-queue-token.util"; | ||
|
||
export function createAsyncProvider( | ||
provide: string, | ||
options?: | ||
| SharedWorkerAsyncConfiguration | ||
| SharedRuntimeAsyncConfiguration | ||
| SharedConnectionAsyncConfiguration | ||
| SharedWorkflowClientOptions, | ||
): Provider { | ||
if (options?.useFactory) { | ||
const { useFactory, inject } = options; | ||
return { | ||
provide, | ||
useFactory, | ||
inject: inject || [], | ||
}; | ||
} | ||
return { | ||
provide, | ||
useValue: options?.useValue || null, | ||
}; | ||
} | ||
|
||
export function createClientAsyncProvider( | ||
asyncOptions: SharedWorkflowClientOptions, | ||
): Provider[] { | ||
const name = asyncOptions.name ? asyncOptions.name : undefined; | ||
const optionsProvide = getAsyncQueueToken(name) | ||
const clientProvide = getQueueToken(name); | ||
return [ | ||
createAsyncProvider(optionsProvide, asyncOptions), | ||
{ | ||
provide: clientProvide, | ||
useFactory: (options?: WorkflowClientOptions) => getWorkflowClient(options), | ||
inject: [optionsProvide], | ||
}, | ||
]; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.