-
Couldn't load subscription status.
- Fork 138
Plugins Implementation #1794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Plugins Implementation #1794
Changes from 14 commits
ac699ec
6580484
ec44d6c
0f8361c
a6f8bfb
748a1c9
6d16100
03957fd
ba37fd8
604e65f
f85cc33
b01a63e
118c0b9
7ab11f3
bd2dad0
6e94e0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { ScheduleClient } from './schedule-client'; | |
| import { QueryRejectCondition, WorkflowService } from './types'; | ||
| import { WorkflowClient } from './workflow-client'; | ||
| import { TaskQueueClient } from './task-queue-client'; | ||
| import { ClientPlugin } from './plugin'; | ||
|
|
||
| export interface ClientOptions extends BaseClientOptions { | ||
| /** | ||
|
|
@@ -15,6 +16,14 @@ export interface ClientOptions extends BaseClientOptions { | |
| */ | ||
| interceptors?: ClientInterceptors; | ||
|
|
||
| /** | ||
| * List of plugins to register with the client. | ||
| * | ||
| * Plugins allow you to extend and customize the behavior of Temporal clients through a chain of | ||
| * responsibility pattern. They can intercept and modify client creation. | ||
| */ | ||
| plugins?: ClientPlugin[]; | ||
|
|
||
| workflow?: { | ||
| /** | ||
| * Should a query be rejected by closed and failed workflows | ||
|
|
@@ -32,6 +41,7 @@ export type LoadedClientOptions = LoadedWithDefaults<ClientOptions>; | |
| */ | ||
| export class Client extends BaseClient { | ||
| public readonly options: LoadedClientOptions; | ||
|
|
||
| /** | ||
| * Workflow sub-client - use to start and interact with Workflows | ||
| */ | ||
|
|
@@ -52,9 +62,21 @@ export class Client extends BaseClient { | |
| public readonly taskQueue: TaskQueueClient; | ||
|
|
||
| constructor(options?: ClientOptions) { | ||
| options = options ?? {}; | ||
|
|
||
| // Add client plugins from the connection | ||
| options.plugins = (options.plugins ?? []).concat(options.connection?.plugins ?? []); | ||
|
|
||
| // Process plugins first to allow them to modify connect configuration | ||
| for (const plugin of options?.plugins ?? []) { | ||
| if (plugin.configureClient !== undefined) { | ||
| options = plugin.configureClient(options); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would we ever expect/support a plugin altering the plugin list? I'm not sure I can think of a reason for doing this, but the current implementation would allow altering the list, but the iteration wouldn't change. e.g. a removed plugin can still alter the options/added plugin will not get a chance to alter the options There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't intend to support that. If you have an idea of how to enforce that, we could. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could leverage Running the configurations becomes a little more awkward as you have to destructure It doesn't warn/error if the user tries to alter the plugin list, but any changes they make won't be respected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
|
|
||
| super(options); | ||
|
|
||
| const { interceptors, workflow, ...commonOptions } = options ?? {}; | ||
| const { interceptors, workflow, plugins, ...commonOptions } = options; | ||
|
|
||
| this.workflow = new WorkflowClient({ | ||
| ...commonOptions, | ||
|
|
@@ -95,6 +117,7 @@ export class Client extends BaseClient { | |
| workflow: { | ||
| queryRejectCondition: this.workflow.options.queryRejectCondition, | ||
| }, | ||
| plugins: plugins ?? [], | ||
chris-olszewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import type { ClientOptions } from './client'; | ||
|
|
||
| /** | ||
| * Plugin to control the configuration of a native connection. | ||
| */ | ||
| export interface ClientPlugin { | ||
| /** | ||
| * Gets the name of this plugin. | ||
| */ | ||
| get name(): string; | ||
|
|
||
| /** | ||
| * Hook called when creating a client to allow modification of configuration. | ||
| * | ||
| * This method is called during client creation and allows plugins to modify | ||
| * the client configuration before the client is fully initialized. | ||
| */ | ||
| configureClient?(options: ClientOptions): ClientOptions; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "name": "@temporalio/plugin", | ||
| "version": "1.13.0", | ||
| "description": "Library for plugin creation", | ||
| "main": "lib/index.js", | ||
| "types": "./lib/index.d.ts", | ||
| "keywords": [ | ||
| "temporal", | ||
| "workflow", | ||
| "worker", | ||
| "plugin" | ||
| ], | ||
| "author": "Temporal Technologies Inc. <[email protected]>", | ||
| "license": "MIT", | ||
| "dependencies": {}, | ||
| "bugs": { | ||
| "url": "https://github.com/temporalio/sdk-typescript/issues" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/temporalio/sdk-typescript.git", | ||
| "directory": "packages/plugin" | ||
| }, | ||
| "homepage": "https://github.com/temporalio/sdk-typescript/tree/main/packages/plugin", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 18.0.0" | ||
| }, | ||
| "files": [ | ||
| "src", | ||
| "lib" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { SimplePlugin, SimplePluginOptions } from './plugin'; |
Uh oh!
There was an error while loading. Please reload this page.