@tsed/temporal 7.73.2 → 7.73.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/jest.config.js +0 -21
- package/lib/tsconfig.esm.tsbuildinfo +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/TemporalModule.ts +0 -39
- package/src/constants.ts +0 -1
- package/src/decorators/activity.spec.ts +0 -40
- package/src/decorators/activity.ts +0 -14
- package/src/decorators/temporal.spec.ts +0 -11
- package/src/decorators/temporal.ts +0 -11
- package/src/index.ts +0 -11
- package/src/interfaces/TemporalStore.ts +0 -9
- package/src/interfaces/interfaces.ts +0 -14
- package/src/services/TemporalFactory.ts +0 -55
- package/src/utils/worker.ts +0 -43
- package/tsconfig.esm.json +0 -39
- package/tsconfig.json +0 -39
package/src/TemporalModule.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {classOf} from "@tsed/core";
|
|
2
|
-
import {Logger} from "@tsed/common";
|
|
3
|
-
import {Inject, InjectorService, Module, Provider} from "@tsed/di";
|
|
4
|
-
import {PROVIDER_TYPE_TEMPORAL} from "./constants.js";
|
|
5
|
-
import {TemporalStore, TEMPORAL_STORE_KEY} from "./interfaces/TemporalStore.js";
|
|
6
|
-
import {TemporalClient} from "./services/TemporalFactory.js";
|
|
7
|
-
|
|
8
|
-
@Module()
|
|
9
|
-
export class TemporalModule {
|
|
10
|
-
@Inject()
|
|
11
|
-
protected logger!: Logger;
|
|
12
|
-
|
|
13
|
-
@Inject()
|
|
14
|
-
protected injector!: InjectorService;
|
|
15
|
-
|
|
16
|
-
@Inject()
|
|
17
|
-
protected client!: TemporalClient;
|
|
18
|
-
|
|
19
|
-
constructor(@Inject(PROVIDER_TYPE_TEMPORAL) private temporalServices: any[]) {}
|
|
20
|
-
|
|
21
|
-
public getActivities(): object {
|
|
22
|
-
return this.temporalServices.reduce((activities, instance) => Object.assign(activities, this.getActivitiesFromInstance(instance)), {});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
protected getActivitiesFromInstance(instance: any) {
|
|
26
|
-
const provider = this.injector.getProvider(classOf(instance))!;
|
|
27
|
-
const store = provider.store.get<TemporalStore>(TEMPORAL_STORE_KEY, {});
|
|
28
|
-
|
|
29
|
-
return Object.entries(store.activities || {}).reduce((activities, [propertyKey, {name}]) => {
|
|
30
|
-
const jobProcessor = instance[propertyKey].bind(instance);
|
|
31
|
-
const jobName = name || propertyKey;
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
...activities,
|
|
35
|
-
[jobName]: jobProcessor
|
|
36
|
-
};
|
|
37
|
-
}, {});
|
|
38
|
-
}
|
|
39
|
-
}
|
package/src/constants.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const PROVIDER_TYPE_TEMPORAL = "PROVIDER_TYPE_TEMPORAL";
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {Store} from "@tsed/core";
|
|
2
|
-
import {Activity} from "./activity.js";
|
|
3
|
-
import {Temporal} from "./temporal.js";
|
|
4
|
-
|
|
5
|
-
describe("@Activity()", () => {
|
|
6
|
-
it("should set metadata", () => {
|
|
7
|
-
@Temporal()
|
|
8
|
-
class Test {
|
|
9
|
-
@Activity()
|
|
10
|
-
testActivityDecorator() {
|
|
11
|
-
// test
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const store = Store.from(Test);
|
|
16
|
-
|
|
17
|
-
expect(store.get("temporal").activities).toEqual({
|
|
18
|
-
testActivityDecorator: {}
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should set options metadata", () => {
|
|
23
|
-
@Temporal()
|
|
24
|
-
class Test {
|
|
25
|
-
@Activity({
|
|
26
|
-
name: "testActivityDecoratorCustomName"
|
|
27
|
-
})
|
|
28
|
-
test() {
|
|
29
|
-
// test
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const store = Store.from(Test);
|
|
34
|
-
expect(store.get("temporal").activities).toEqual({
|
|
35
|
-
test: {
|
|
36
|
-
name: "testActivityDecoratorCustomName"
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {Store} from "@tsed/core";
|
|
2
|
-
import {TemporalStore, ActivityOptions, TEMPORAL_STORE_KEY} from "../interfaces/TemporalStore.js";
|
|
3
|
-
|
|
4
|
-
export function Activity(options: ActivityOptions = {}): MethodDecorator {
|
|
5
|
-
return (target: any, propertyKey: string | symbol) => {
|
|
6
|
-
const store: TemporalStore = {
|
|
7
|
-
activities: {
|
|
8
|
-
[propertyKey]: options
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
Store.from(target).merge(TEMPORAL_STORE_KEY, store);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {GlobalProviders} from "@tsed/di";
|
|
2
|
-
import {Temporal} from "./temporal.js";
|
|
3
|
-
|
|
4
|
-
describe("@Activity()", () => {
|
|
5
|
-
it("should set metadata", () => {
|
|
6
|
-
@Temporal()
|
|
7
|
-
class Test {}
|
|
8
|
-
|
|
9
|
-
expect(GlobalProviders.get(Test)?.useClass).toEqual(Test);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {useDecorators} from "@tsed/core";
|
|
2
|
-
import {Injectable} from "@tsed/di";
|
|
3
|
-
import {PROVIDER_TYPE_TEMPORAL} from "../constants.js";
|
|
4
|
-
|
|
5
|
-
export function Temporal(): ClassDecorator {
|
|
6
|
-
return useDecorators(
|
|
7
|
-
Injectable({
|
|
8
|
-
type: PROVIDER_TYPE_TEMPORAL
|
|
9
|
-
})
|
|
10
|
-
);
|
|
11
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Automatically generated by @tsed/barrels.
|
|
3
|
-
*/
|
|
4
|
-
export * from "./constants.js";
|
|
5
|
-
export * from "./decorators/activity.js";
|
|
6
|
-
export * from "./decorators/temporal.js";
|
|
7
|
-
export * from "./interfaces/interfaces.js";
|
|
8
|
-
export * from "./interfaces/TemporalStore.js";
|
|
9
|
-
export * from "./services/TemporalFactory.js";
|
|
10
|
-
export * from "./TemporalModule.js";
|
|
11
|
-
export * from "./utils/worker.js";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {ClientOptions, ConnectionOptions} from "@temporalio/client";
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
5
|
-
namespace TsED {
|
|
6
|
-
interface Configuration {
|
|
7
|
-
temporal?: {
|
|
8
|
-
enabled?: boolean;
|
|
9
|
-
connection?: ConnectionOptions;
|
|
10
|
-
client?: Omit<ClientOptions, "connection">;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {Configuration, registerProvider} from "@tsed/di";
|
|
2
|
-
import {Client, Connection} from "@temporalio/client";
|
|
3
|
-
import {Logger} from "@tsed/common";
|
|
4
|
-
|
|
5
|
-
export const TemporalConnection = Connection;
|
|
6
|
-
export type TemporalConnection = Connection;
|
|
7
|
-
|
|
8
|
-
export const TemporalClient = Client;
|
|
9
|
-
export type TemporalClient = Client;
|
|
10
|
-
|
|
11
|
-
registerProvider({
|
|
12
|
-
provide: TemporalConnection,
|
|
13
|
-
deps: [Configuration, Logger],
|
|
14
|
-
async useAsyncFactory(settings: Configuration, logger: Logger) {
|
|
15
|
-
const {temporal} = settings;
|
|
16
|
-
if (!temporal?.enabled) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
logger.info("Connecting to Temporal Server: ", temporal.connection?.address || "default");
|
|
22
|
-
const connection = await Connection.connect(temporal.connection);
|
|
23
|
-
logger.info("... connected to Temporal Server: ", temporal.connection?.address || "default");
|
|
24
|
-
return connection;
|
|
25
|
-
} catch (error) {
|
|
26
|
-
logger.error("Failed to connect to Temporal Server:", error);
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
registerProvider({
|
|
33
|
-
provide: TemporalClient,
|
|
34
|
-
deps: [Configuration, TemporalConnection],
|
|
35
|
-
useFactory(settings: Configuration, connection: TemporalConnection) {
|
|
36
|
-
const {temporal} = settings;
|
|
37
|
-
if (!temporal?.enabled) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const client = new TemporalClient({
|
|
42
|
-
connection,
|
|
43
|
-
...temporal.client
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
return client;
|
|
47
|
-
},
|
|
48
|
-
hooks: {
|
|
49
|
-
$onDestroy: async (client: Client | null) => {
|
|
50
|
-
if (client) {
|
|
51
|
-
await client.connection.close();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
package/src/utils/worker.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {PlatformBuilderSettings, PlatformTest} from "@tsed/common";
|
|
2
|
-
import {$log} from "@tsed/logger";
|
|
3
|
-
|
|
4
|
-
import {NativeConnection, NativeConnectionOptions, Worker, WorkerOptions} from "@temporalio/worker";
|
|
5
|
-
import {TemporalModule} from "../TemporalModule.js";
|
|
6
|
-
|
|
7
|
-
type BootstrapWorkerOptions = {
|
|
8
|
-
platform?: PlatformBuilderSettings;
|
|
9
|
-
worker: Omit<WorkerOptions, "activities">;
|
|
10
|
-
connection?: NativeConnection | NativeConnectionOptions;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export async function bootstrapWorker(mod: any, settings: BootstrapWorkerOptions) {
|
|
14
|
-
await PlatformTest.bootstrap(mod, settings.platform)();
|
|
15
|
-
const temporalioModule = PlatformTest.get<TemporalModule>(TemporalModule);
|
|
16
|
-
const activities = temporalioModule.getActivities();
|
|
17
|
-
$log.info('Starting temporal worker with queue "%s" and activities:', settings.worker.taskQueue);
|
|
18
|
-
|
|
19
|
-
if (Object.keys(activities).length > 0) {
|
|
20
|
-
$log.printTable(
|
|
21
|
-
Object.entries(activities).map((x) => ({
|
|
22
|
-
name: x[0],
|
|
23
|
-
activity: x[1].toString()
|
|
24
|
-
}))
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let connection: NativeConnection;
|
|
29
|
-
if (settings.connection instanceof NativeConnection) {
|
|
30
|
-
connection = settings.connection;
|
|
31
|
-
} else {
|
|
32
|
-
$log.info("Connecting to Temporal Server: ", settings.connection?.address || "default");
|
|
33
|
-
connection = await NativeConnection.connect(settings.connection);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const worker = await Worker.create({
|
|
37
|
-
connection,
|
|
38
|
-
...settings.worker,
|
|
39
|
-
activities
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return worker;
|
|
43
|
-
}
|
package/tsconfig.esm.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@tsed/typescript/tsconfig.node.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": ".",
|
|
5
|
-
"module": "ES2020",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"outDir": "./lib/esm",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"declarationDir": "./lib/types",
|
|
10
|
-
"composite": true,
|
|
11
|
-
"noEmit": false
|
|
12
|
-
},
|
|
13
|
-
"include": ["src", "src/**/*.json"],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"test",
|
|
17
|
-
"lib",
|
|
18
|
-
"benchmark",
|
|
19
|
-
"coverage",
|
|
20
|
-
"spec",
|
|
21
|
-
"**/*.benchmark.ts",
|
|
22
|
-
"**/*.spec.ts",
|
|
23
|
-
"keys",
|
|
24
|
-
"jest.config.js",
|
|
25
|
-
"**/__mock__/**",
|
|
26
|
-
"webpack.config.js"
|
|
27
|
-
],
|
|
28
|
-
"references": [
|
|
29
|
-
{
|
|
30
|
-
"path": "../../platform/common"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"path": "../../core"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"path": "../../di"
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@tsed/typescript/tsconfig.node.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": ".",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"outDir": "./lib/cjs",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"declarationDir": "./lib/types",
|
|
10
|
-
"composite": true,
|
|
11
|
-
"noEmit": false
|
|
12
|
-
},
|
|
13
|
-
"include": ["src", "src/**/*.json"],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"test",
|
|
17
|
-
"lib",
|
|
18
|
-
"benchmark",
|
|
19
|
-
"coverage",
|
|
20
|
-
"spec",
|
|
21
|
-
"**/*.benchmark.ts",
|
|
22
|
-
"**/*.spec.ts",
|
|
23
|
-
"keys",
|
|
24
|
-
"jest.config.js",
|
|
25
|
-
"**/__mock__/**",
|
|
26
|
-
"webpack.config.js"
|
|
27
|
-
],
|
|
28
|
-
"references": [
|
|
29
|
-
{
|
|
30
|
-
"path": "../../platform/common"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"path": "../../core"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"path": "../../di"
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|