nmtjs 0.15.0-beta.2 → 0.15.0-beta.21
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/dist/cli.d.ts +2 -0
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -0
- package/dist/entrypoints/cli.d.ts +1 -0
- package/dist/entrypoints/cli.js +1 -0
- package/dist/entrypoints/cli.js.map +1 -0
- package/dist/entrypoints/main.d.ts +5 -0
- package/dist/entrypoints/main.js +83 -15
- package/dist/entrypoints/main.js.map +1 -0
- package/dist/entrypoints/thread.d.ts +14 -0
- package/dist/entrypoints/thread.js +130 -24
- package/dist/entrypoints/thread.js.map +1 -0
- package/dist/entrypoints/worker.d.ts +3 -0
- package/dist/entrypoints/worker.js +4 -3
- package/dist/entrypoints/worker.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/{_exports/index.js → index.js} +9 -5
- package/dist/index.js.map +1 -0
- package/dist/resolver.d.ts +2 -0
- package/dist/resolver.js +1 -0
- package/dist/resolver.js.map +1 -0
- package/dist/runtime/application/api/api.d.ts +49 -0
- package/dist/runtime/application/api/api.js +193 -0
- package/dist/runtime/application/api/api.js.map +1 -0
- package/dist/runtime/application/api/constants.d.ts +14 -0
- package/dist/runtime/application/api/constants.js +8 -0
- package/dist/runtime/application/api/constants.js.map +1 -0
- package/dist/runtime/application/api/filters.d.ts +14 -0
- package/dist/runtime/application/api/filters.js +11 -0
- package/dist/runtime/application/api/filters.js.map +1 -0
- package/dist/runtime/application/api/guards.d.ts +13 -0
- package/dist/runtime/application/api/guards.js +8 -0
- package/dist/runtime/application/api/guards.js.map +1 -0
- package/dist/runtime/application/api/index.d.ts +8 -0
- package/dist/runtime/application/api/index.js +9 -0
- package/dist/runtime/application/api/index.js.map +1 -0
- package/dist/runtime/application/api/middlewares.d.ts +14 -0
- package/dist/runtime/application/api/middlewares.js +12 -0
- package/dist/runtime/application/api/middlewares.js.map +1 -0
- package/dist/runtime/application/api/procedure.d.ts +67 -0
- package/dist/runtime/application/api/procedure.js +50 -0
- package/dist/runtime/application/api/procedure.js.map +1 -0
- package/dist/runtime/application/api/router.d.ts +71 -0
- package/dist/runtime/application/api/router.js +51 -0
- package/dist/runtime/application/api/router.js.map +1 -0
- package/dist/runtime/application/api/types.d.ts +32 -0
- package/dist/runtime/application/api/types.js +2 -0
- package/dist/runtime/application/api/types.js.map +1 -0
- package/dist/runtime/application/config.d.ts +26 -0
- package/dist/runtime/application/config.js +21 -0
- package/dist/runtime/application/config.js.map +1 -0
- package/dist/runtime/application/constants.d.ts +2 -0
- package/dist/runtime/application/constants.js +2 -0
- package/dist/runtime/application/constants.js.map +1 -0
- package/dist/runtime/application/hook.d.ts +19 -0
- package/dist/runtime/application/hook.js +11 -0
- package/dist/runtime/application/hook.js.map +1 -0
- package/dist/runtime/application/hooks.d.ts +3 -0
- package/dist/runtime/application/hooks.js +4 -0
- package/dist/runtime/application/hooks.js.map +1 -0
- package/dist/runtime/application/index.d.ts +5 -0
- package/dist/runtime/application/index.js +6 -0
- package/dist/runtime/application/index.js.map +1 -0
- package/dist/runtime/constants.d.ts +8 -0
- package/dist/runtime/constants.js +5 -0
- package/dist/runtime/constants.js.map +1 -0
- package/dist/runtime/core/hooks.d.ts +4 -0
- package/dist/runtime/core/hooks.js +4 -0
- package/dist/runtime/core/hooks.js.map +1 -0
- package/dist/runtime/core/plugin.d.ts +8 -0
- package/dist/runtime/core/plugin.js +4 -0
- package/dist/runtime/core/plugin.js.map +1 -0
- package/dist/runtime/core/runtime.d.ts +27 -0
- package/dist/runtime/core/runtime.js +81 -0
- package/dist/runtime/core/runtime.js.map +1 -0
- package/dist/runtime/enums.d.ts +21 -0
- package/dist/runtime/enums.js +26 -0
- package/dist/runtime/enums.js.map +1 -0
- package/dist/runtime/index.d.ts +21 -0
- package/dist/runtime/index.js +22 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/injectables.d.ts +23 -0
- package/dist/runtime/injectables.js +20 -0
- package/dist/runtime/injectables.js.map +1 -0
- package/dist/runtime/jobs/job.d.ts +132 -0
- package/dist/runtime/jobs/job.js +68 -0
- package/dist/runtime/jobs/job.js.map +1 -0
- package/dist/runtime/jobs/manager.d.ts +113 -0
- package/dist/runtime/jobs/manager.js +210 -0
- package/dist/runtime/jobs/manager.js.map +1 -0
- package/dist/runtime/jobs/router.d.ts +266 -0
- package/dist/runtime/jobs/router.js +432 -0
- package/dist/runtime/jobs/router.js.map +1 -0
- package/dist/runtime/jobs/runner.d.ts +64 -0
- package/dist/runtime/jobs/runner.js +256 -0
- package/dist/runtime/jobs/runner.js.map +1 -0
- package/dist/runtime/jobs/step.d.ts +23 -0
- package/dist/runtime/jobs/step.js +18 -0
- package/dist/runtime/jobs/step.js.map +1 -0
- package/dist/runtime/jobs/ui.d.ts +3 -0
- package/dist/runtime/jobs/ui.js +17 -0
- package/dist/runtime/jobs/ui.js.map +1 -0
- package/dist/runtime/pubsub/manager.d.ts +48 -0
- package/dist/runtime/pubsub/manager.js +119 -0
- package/dist/runtime/pubsub/manager.js.map +1 -0
- package/dist/runtime/pubsub/redis.d.ts +16 -0
- package/dist/runtime/pubsub/redis.js +98 -0
- package/dist/runtime/pubsub/redis.js.map +1 -0
- package/dist/runtime/scheduler/index.d.ts +22 -0
- package/dist/runtime/scheduler/index.js +20 -0
- package/dist/runtime/scheduler/index.js.map +1 -0
- package/dist/runtime/server/applications.d.ts +52 -0
- package/dist/runtime/server/applications.js +133 -0
- package/dist/runtime/server/applications.js.map +1 -0
- package/dist/runtime/server/config.d.ts +121 -0
- package/dist/runtime/server/config.js +33 -0
- package/dist/runtime/server/config.js.map +1 -0
- package/dist/runtime/server/jobs.d.ts +41 -0
- package/dist/runtime/server/jobs.js +181 -0
- package/dist/runtime/server/jobs.js.map +1 -0
- package/dist/runtime/server/pool.d.ts +54 -0
- package/dist/runtime/server/pool.js +194 -0
- package/dist/runtime/server/pool.js.map +1 -0
- package/dist/runtime/server/proxy.d.ts +21 -0
- package/dist/runtime/server/proxy.js +79 -0
- package/dist/runtime/server/proxy.js.map +1 -0
- package/dist/runtime/server/server.d.ts +53 -0
- package/dist/runtime/server/server.js +90 -0
- package/dist/runtime/server/server.js.map +1 -0
- package/dist/runtime/store/index.d.ts +3 -0
- package/dist/runtime/store/index.js +23 -0
- package/dist/runtime/store/index.js.map +1 -0
- package/dist/runtime/types.d.ts +103 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/workers/application.d.ts +47 -0
- package/dist/runtime/workers/application.js +162 -0
- package/dist/runtime/workers/application.js.map +1 -0
- package/dist/runtime/workers/base.d.ts +16 -0
- package/dist/runtime/workers/base.js +46 -0
- package/dist/runtime/workers/base.js.map +1 -0
- package/dist/runtime/workers/cli.d.ts +1 -0
- package/dist/runtime/workers/cli.js +2 -0
- package/dist/runtime/workers/cli.js.map +1 -0
- package/dist/runtime/workers/job.d.ts +20 -0
- package/dist/runtime/workers/job.js +172 -0
- package/dist/runtime/workers/job.js.map +1 -0
- package/dist/typings.d.ts +5 -0
- package/dist/typings.js +4 -3
- package/dist/typings.js.map +1 -0
- package/dist/vite/builder.d.ts +5 -0
- package/dist/vite/builder.js +5 -1
- package/dist/vite/builder.js.map +1 -0
- package/dist/vite/config.d.ts +28 -0
- package/dist/vite/config.js +1 -0
- package/dist/vite/config.js.map +1 -0
- package/dist/vite/plugins.d.ts +2 -0
- package/dist/vite/plugins.js +1 -0
- package/dist/vite/plugins.js.map +1 -0
- package/dist/vite/runners/worker.d.ts +4 -0
- package/dist/vite/runners/worker.js +1 -0
- package/dist/vite/runners/worker.js.map +1 -0
- package/dist/vite/server.d.ts +3 -0
- package/dist/vite/server.js +6 -1
- package/dist/vite/server.js.map +1 -0
- package/dist/vite/servers/main.d.ts +8 -0
- package/dist/vite/servers/main.js +1 -0
- package/dist/vite/servers/main.js.map +1 -0
- package/dist/vite/servers/worker.d.ts +11 -0
- package/dist/vite/servers/worker.js +28 -0
- package/dist/vite/servers/worker.js.map +1 -0
- package/package.json +31 -18
- package/src/cli.ts +144 -0
- package/src/config.ts +64 -0
- package/src/entrypoints/cli.ts +13 -0
- package/src/entrypoints/main.ts +200 -0
- package/src/entrypoints/thread.ts +184 -0
- package/src/entrypoints/worker.ts +48 -0
- package/src/index.ts +82 -0
- package/src/resolver.ts +16 -0
- package/src/runtime/application/api/api.ts +265 -0
- package/src/runtime/application/api/constants.ts +22 -0
- package/src/runtime/application/api/filters.ts +39 -0
- package/src/runtime/application/api/guards.ts +29 -0
- package/src/runtime/application/api/index.ts +8 -0
- package/src/runtime/application/api/middlewares.ts +37 -0
- package/src/runtime/application/api/procedure.ts +229 -0
- package/src/runtime/application/api/router.ts +193 -0
- package/src/runtime/application/api/types.ts +124 -0
- package/src/runtime/application/config.ts +69 -0
- package/src/runtime/application/constants.ts +4 -0
- package/src/runtime/application/hook.ts +51 -0
- package/src/runtime/application/hooks.ts +3 -0
- package/src/runtime/application/index.ts +5 -0
- package/src/runtime/constants.ts +13 -0
- package/src/runtime/core/hooks.ts +5 -0
- package/src/runtime/core/plugin.ts +13 -0
- package/src/runtime/core/runtime.ts +109 -0
- package/src/runtime/enums.ts +24 -0
- package/src/runtime/index.ts +21 -0
- package/src/runtime/injectables.ts +61 -0
- package/src/runtime/jobs/job.ts +370 -0
- package/src/runtime/jobs/manager.ts +348 -0
- package/src/runtime/jobs/router.ts +896 -0
- package/src/runtime/jobs/runner.ts +320 -0
- package/src/runtime/jobs/step.ts +66 -0
- package/src/runtime/jobs/ui.ts +21 -0
- package/src/runtime/pubsub/manager.ts +211 -0
- package/src/runtime/pubsub/redis.ts +108 -0
- package/src/runtime/scheduler/index.ts +39 -0
- package/src/runtime/server/applications.ts +210 -0
- package/src/runtime/server/config.ts +158 -0
- package/src/runtime/server/jobs.ts +250 -0
- package/src/runtime/server/pool.ts +260 -0
- package/src/runtime/server/proxy.ts +118 -0
- package/src/runtime/server/server.ts +155 -0
- package/src/runtime/store/index.ts +30 -0
- package/src/runtime/types.ts +93 -0
- package/src/runtime/workers/application.ts +209 -0
- package/src/runtime/workers/base.ts +68 -0
- package/src/runtime/workers/cli.ts +0 -0
- package/src/runtime/workers/job.ts +153 -0
- package/src/typings.ts +30 -0
- package/src/vite/builder.ts +122 -0
- package/src/vite/config.ts +45 -0
- package/src/vite/plugins.ts +26 -0
- package/src/vite/runners/worker.ts +57 -0
- package/src/vite/server.ts +39 -0
- package/src/vite/servers/main.ts +34 -0
- package/src/vite/servers/worker.ts +143 -0
- package/dist/_exports/application.js +0 -1
- package/dist/_exports/common.js +0 -1
- package/dist/_exports/contract.js +0 -2
- package/dist/_exports/core.js +0 -1
- package/dist/_exports/gateway.js +0 -1
- package/dist/_exports/http-transport/bun.js +0 -1
- package/dist/_exports/http-transport/deno.js +0 -1
- package/dist/_exports/http-transport/node.js +0 -1
- package/dist/_exports/http-transport.js +0 -1
- package/dist/_exports/json-format.js +0 -1
- package/dist/_exports/protocol/client.js +0 -1
- package/dist/_exports/protocol/server.js +0 -1
- package/dist/_exports/protocol.js +0 -1
- package/dist/_exports/runtime/types.js +0 -1
- package/dist/_exports/runtime.js +0 -1
- package/dist/_exports/type.js +0 -2
- package/dist/_exports/ws-transport/bun.js +0 -1
- package/dist/_exports/ws-transport/deno.js +0 -1
- package/dist/_exports/ws-transport/node.js +0 -1
- package/dist/_exports/ws-transport.js +0 -1
- package/dist/command.js +0 -30
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createLogger } from '@nmtjs/core';
|
|
2
|
+
import { createStoreClient } from "../store/index.js";
|
|
3
|
+
import { ApplicationServerApplications } from "./applications.js";
|
|
4
|
+
import { ApplicationServerJobs } from "./jobs.js";
|
|
5
|
+
import { ApplicationServerProxy } from "./proxy.js";
|
|
6
|
+
export class ApplicationServer {
|
|
7
|
+
config;
|
|
8
|
+
applicationsConfig;
|
|
9
|
+
workerConfig;
|
|
10
|
+
runOptions;
|
|
11
|
+
logger;
|
|
12
|
+
applications;
|
|
13
|
+
jobRunners;
|
|
14
|
+
proxy;
|
|
15
|
+
store;
|
|
16
|
+
constructor(config, applicationsConfig, workerConfig, runOptions = {
|
|
17
|
+
applications: Object.keys(config.applications),
|
|
18
|
+
scheduler: false,
|
|
19
|
+
jobs: Boolean(config.jobs?.jobs.size),
|
|
20
|
+
}) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.applicationsConfig = applicationsConfig;
|
|
23
|
+
this.workerConfig = workerConfig;
|
|
24
|
+
this.runOptions = runOptions;
|
|
25
|
+
this.logger = createLogger(config.logger, 'Server');
|
|
26
|
+
this.logger.trace({ applications: applicationsConfig, workerConfig, runOptions }, 'ApplicationServer initialized');
|
|
27
|
+
}
|
|
28
|
+
async start() {
|
|
29
|
+
const { config, logger } = this;
|
|
30
|
+
logger.info('Starting application server...');
|
|
31
|
+
if (config.store) {
|
|
32
|
+
this.store = await createStoreClient(config.store);
|
|
33
|
+
await this.store.connect();
|
|
34
|
+
logger.debug('Store connected');
|
|
35
|
+
}
|
|
36
|
+
this.applications = new ApplicationServerApplications({
|
|
37
|
+
logger: this.logger,
|
|
38
|
+
workerConfig: this.workerConfig,
|
|
39
|
+
serverConfig: this.config,
|
|
40
|
+
applicationsConfig: this.applicationsConfig,
|
|
41
|
+
applications: this.runOptions.applications,
|
|
42
|
+
});
|
|
43
|
+
if (this.runOptions.jobs) {
|
|
44
|
+
if (!this.store) {
|
|
45
|
+
throw new Error('Jobs feature requires a store configuration. ' +
|
|
46
|
+
'Please configure `store` in your server config or disable jobs.');
|
|
47
|
+
}
|
|
48
|
+
this.jobRunners = new ApplicationServerJobs({
|
|
49
|
+
logger: this.logger,
|
|
50
|
+
workerConfig: this.workerConfig,
|
|
51
|
+
serverConfig: this.config,
|
|
52
|
+
store: this.store,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (this.config.proxy) {
|
|
56
|
+
this.proxy = new ApplicationServerProxy({
|
|
57
|
+
logger: this.logger,
|
|
58
|
+
config: this.config.proxy,
|
|
59
|
+
applications: this.applications,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
await this.applications.start();
|
|
63
|
+
if (this.runOptions.jobs) {
|
|
64
|
+
await this.jobRunners?.start();
|
|
65
|
+
}
|
|
66
|
+
if (this.runOptions.scheduler && config.jobs?.scheduler) {
|
|
67
|
+
throw new Error('JobsScheduler is currently a work in progress and not available. ' +
|
|
68
|
+
'Scheduled jobs will be supported in a future release.');
|
|
69
|
+
}
|
|
70
|
+
if (this.proxy) {
|
|
71
|
+
await this.proxy.start();
|
|
72
|
+
}
|
|
73
|
+
logger.info('Application server started');
|
|
74
|
+
}
|
|
75
|
+
async stop() {
|
|
76
|
+
this.logger.info('Stopping application server...');
|
|
77
|
+
// Stop proxy + stop accepting new jobs first
|
|
78
|
+
await this.proxy?.stop();
|
|
79
|
+
await this.jobRunners?.stop();
|
|
80
|
+
// Stop applications
|
|
81
|
+
await this.applications?.stop();
|
|
82
|
+
// Close store connection
|
|
83
|
+
if (this.store) {
|
|
84
|
+
this.logger.debug('Closing store...');
|
|
85
|
+
this.store.disconnect(false);
|
|
86
|
+
}
|
|
87
|
+
this.logger.info('Application server stopped');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/runtime/server/server.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAQ1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AA+BnD,MAAM,OAAO,iBAAiB;IAUjB;IAC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ED,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAA;QAElD,6CAA6C;QAC7C,MAAM,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,CAAA;QACxB,MAAM,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,CAAA;QAE7B,oBAAoB;QACpB,MAAM,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,CAAA;QAE/B,yBAAyB;QACzB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAA;YACrC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAC9B,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StoreType } from "../enums.js";
|
|
2
|
+
export async function createStoreClient(config) {
|
|
3
|
+
if (config.type === StoreType.Redis) {
|
|
4
|
+
const { Redis } = await import('ioredis').catch(() => {
|
|
5
|
+
throw new Error('ioredis package is not installed. Please install it to use Redis store.');
|
|
6
|
+
});
|
|
7
|
+
return new Redis({
|
|
8
|
+
...config.options,
|
|
9
|
+
lazyConnect: true,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
else if (config.type === StoreType.Valkey) {
|
|
13
|
+
const { Redis } = await import('iovalkey').catch(() => {
|
|
14
|
+
throw new Error('iovalkey package is not installed. Please install it to use Valkey store.');
|
|
15
|
+
});
|
|
16
|
+
return new Redis({
|
|
17
|
+
...config.options,
|
|
18
|
+
lazyConnect: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
throw new Error('Unsupported store');
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/store/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAS;IAET,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACnD,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAA;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,KAAK,CAAC;YACf,GAAG,MAAM,CAAC,OAAO;YACjB,WAAW,EAAE,IAAI;SAClB,CAA0B,CAAA;IAC7B,CAAC;SAAM,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC;QAC5C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACpD,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAA;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,KAAK,CAAC;YACf,GAAG,MAAM,CAAC,OAAO;YACjB,WAAW,EAAE,IAAI;SAClB,CAA0B,CAAA;IAC7B,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { HookTypes } from '@nmtjs/core';
|
|
2
|
+
import type { ProxyableTransportType } from '@nmtjs/gateway';
|
|
3
|
+
import type { Redis, RedisOptions } from 'ioredis';
|
|
4
|
+
import type { Redis as Valkey, RedisOptions as ValkeyOptions } from 'iovalkey';
|
|
5
|
+
import type { ApplicationConfig } from './application/config.ts';
|
|
6
|
+
import type { BaseRuntime } from './core/runtime.ts';
|
|
7
|
+
import type { LifecycleHook, StoreType } from './enums.ts';
|
|
8
|
+
export type WorkerThreadErrorOrigin = 'bootstrap' | 'start' | 'runtime';
|
|
9
|
+
export type ThreadErrorMessage = {
|
|
10
|
+
message: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
stack?: string;
|
|
13
|
+
origin: WorkerThreadErrorOrigin;
|
|
14
|
+
fatal: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type WorkerThreadError = Error & {
|
|
17
|
+
origin?: WorkerThreadErrorOrigin;
|
|
18
|
+
fatal?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type ServerPortMessageTypes = {
|
|
21
|
+
stop: undefined;
|
|
22
|
+
task: {
|
|
23
|
+
id: string;
|
|
24
|
+
task: WorkerJobTask;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type ThreadPortMessageTypes = {
|
|
28
|
+
ready: {
|
|
29
|
+
hosts?: {
|
|
30
|
+
type: ProxyableTransportType;
|
|
31
|
+
url: string;
|
|
32
|
+
}[];
|
|
33
|
+
};
|
|
34
|
+
error: ThreadErrorMessage;
|
|
35
|
+
task: {
|
|
36
|
+
id: string;
|
|
37
|
+
task: JobTaskResult;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export type ServerPortMessage = {
|
|
41
|
+
[K in keyof ServerPortMessageTypes]: {
|
|
42
|
+
type: K;
|
|
43
|
+
data: ServerPortMessageTypes[K];
|
|
44
|
+
};
|
|
45
|
+
}[keyof ServerPortMessageTypes];
|
|
46
|
+
export type ThreadPortMessage = {
|
|
47
|
+
[K in keyof ThreadPortMessageTypes]: {
|
|
48
|
+
type: K;
|
|
49
|
+
data: ThreadPortMessageTypes[K];
|
|
50
|
+
};
|
|
51
|
+
}[keyof ThreadPortMessageTypes];
|
|
52
|
+
export interface WorkerTask {
|
|
53
|
+
type?: string;
|
|
54
|
+
payload?: any;
|
|
55
|
+
}
|
|
56
|
+
export type WorkerJobTask = {
|
|
57
|
+
jobId: string;
|
|
58
|
+
jobName: string;
|
|
59
|
+
data: any;
|
|
60
|
+
};
|
|
61
|
+
export type JobTaskResult = {
|
|
62
|
+
[K in keyof JobTaskResultTypes]: {
|
|
63
|
+
type: K;
|
|
64
|
+
} & JobTaskResultTypes[K];
|
|
65
|
+
}[keyof JobTaskResultTypes];
|
|
66
|
+
export type JobTaskResultTypes = {
|
|
67
|
+
success: {
|
|
68
|
+
result?: unknown;
|
|
69
|
+
};
|
|
70
|
+
error: {
|
|
71
|
+
error: any;
|
|
72
|
+
};
|
|
73
|
+
unrecoverable_error: {
|
|
74
|
+
error: any;
|
|
75
|
+
};
|
|
76
|
+
job_not_found: {};
|
|
77
|
+
queue_job_not_found: {};
|
|
78
|
+
};
|
|
79
|
+
export interface LifecycleHookTypes extends HookTypes {
|
|
80
|
+
[LifecycleHook.BeforeInitialize]: (runtime: BaseRuntime) => any;
|
|
81
|
+
[LifecycleHook.AfterInitialize]: (runtime: BaseRuntime) => any;
|
|
82
|
+
[LifecycleHook.BeforeDispose]: (runtime: BaseRuntime) => any;
|
|
83
|
+
[LifecycleHook.AfterDispose]: (runtime: BaseRuntime) => any;
|
|
84
|
+
}
|
|
85
|
+
export type ApplicationDefinitionType = {
|
|
86
|
+
type: 'neemata';
|
|
87
|
+
definition: ApplicationConfig<any, any>;
|
|
88
|
+
} | {
|
|
89
|
+
type: 'custom';
|
|
90
|
+
definition: any;
|
|
91
|
+
};
|
|
92
|
+
export interface Applications extends Record<string, ApplicationDefinitionType> {
|
|
93
|
+
}
|
|
94
|
+
export type StoreTypes = {
|
|
95
|
+
[StoreType.Redis]: Redis;
|
|
96
|
+
[StoreType.Valkey]: Valkey;
|
|
97
|
+
};
|
|
98
|
+
export type StoreTypeOptions = {
|
|
99
|
+
[StoreType.Redis]: RedisOptions;
|
|
100
|
+
[StoreType.Valkey]: ValkeyOptions;
|
|
101
|
+
};
|
|
102
|
+
export type Store = StoreTypes[StoreType];
|
|
103
|
+
export type StoreOptions = StoreTypeOptions[StoreType];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Dependant } from '@nmtjs/core';
|
|
2
|
+
import type { GatewayOptions } from '@nmtjs/gateway';
|
|
3
|
+
import { Gateway } from '@nmtjs/gateway';
|
|
4
|
+
import type { ApplicationConfig } from '../application/config.ts';
|
|
5
|
+
import type { AnyFilter, AnyGuard, AnyMiddleware, AnyProcedure, AnyRouter, kDefaultProcedure as kDefaultProcedureKey } from '../application/index.ts';
|
|
6
|
+
import type { ServerConfig } from '../server/config.ts';
|
|
7
|
+
import { ApplicationApi } from '../application/api/api.ts';
|
|
8
|
+
import { ApplicationHooks } from '../application/hooks.ts';
|
|
9
|
+
import { kRootRouter } from '../application/index.ts';
|
|
10
|
+
import { BaseWorkerRuntime } from './base.ts';
|
|
11
|
+
export interface ApplicationWorkerRuntimeOptions {
|
|
12
|
+
name: string;
|
|
13
|
+
path: string;
|
|
14
|
+
transports: {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare class ApplicationWorkerRuntime extends BaseWorkerRuntime {
|
|
19
|
+
readonly config: ServerConfig;
|
|
20
|
+
readonly runtimeOptions: ApplicationWorkerRuntimeOptions;
|
|
21
|
+
protected appConfig: ApplicationConfig;
|
|
22
|
+
api: ApplicationApi;
|
|
23
|
+
applicationHooks: ApplicationHooks;
|
|
24
|
+
gateway: Gateway;
|
|
25
|
+
transports: GatewayOptions['transports'];
|
|
26
|
+
routers: Map<string | typeof kRootRouter, AnyRouter>;
|
|
27
|
+
procedures: Map<string | typeof kDefaultProcedureKey, {
|
|
28
|
+
procedure: AnyProcedure;
|
|
29
|
+
path: AnyRouter[];
|
|
30
|
+
}>;
|
|
31
|
+
filters: Set<AnyFilter>;
|
|
32
|
+
middlewares: Set<AnyMiddleware>;
|
|
33
|
+
guards: Set<AnyGuard>;
|
|
34
|
+
constructor(config: ServerConfig, runtimeOptions: ApplicationWorkerRuntimeOptions, appConfig: ApplicationConfig);
|
|
35
|
+
start(): Promise<{
|
|
36
|
+
url: string;
|
|
37
|
+
type: import("@nmtjs/gateway").ProxyableTransportType;
|
|
38
|
+
}[]>;
|
|
39
|
+
stop(): Promise<void>;
|
|
40
|
+
reload(appConfig: ApplicationConfig): Promise<void>;
|
|
41
|
+
initialize(): Promise<void>;
|
|
42
|
+
protected _initialize(): Promise<void>;
|
|
43
|
+
protected _dispose(): Promise<void>;
|
|
44
|
+
protected _dependents(): Generator<Dependant>;
|
|
45
|
+
protected registerApi(): void;
|
|
46
|
+
protected registerRouter(router: AnyRouter, path?: AnyRouter[]): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Gateway } from '@nmtjs/gateway';
|
|
2
|
+
import { JsonFormat } from '@nmtjs/json-format/server';
|
|
3
|
+
import { ProtocolFormats } from '@nmtjs/protocol/server';
|
|
4
|
+
import { ApplicationApi } from "../application/api/api.js";
|
|
5
|
+
import { ApplicationHooks } from "../application/hooks.js";
|
|
6
|
+
import { isProcedure, isRootRouter, isRouter, kDefaultProcedure, kRootRouter, } from "../application/index.js";
|
|
7
|
+
import { LifecycleHook, WorkerType } from "../enums.js";
|
|
8
|
+
import { BaseWorkerRuntime } from "./base.js";
|
|
9
|
+
export class ApplicationWorkerRuntime extends BaseWorkerRuntime {
|
|
10
|
+
config;
|
|
11
|
+
runtimeOptions;
|
|
12
|
+
appConfig;
|
|
13
|
+
api;
|
|
14
|
+
applicationHooks;
|
|
15
|
+
gateway;
|
|
16
|
+
transports;
|
|
17
|
+
routers = new Map();
|
|
18
|
+
procedures = new Map();
|
|
19
|
+
filters = new Set();
|
|
20
|
+
middlewares = new Set();
|
|
21
|
+
guards = new Set();
|
|
22
|
+
constructor(config, runtimeOptions, appConfig) {
|
|
23
|
+
super(config, {
|
|
24
|
+
logger: config.logger,
|
|
25
|
+
name: `Worker ${runtimeOptions.name}`,
|
|
26
|
+
plugins: appConfig.plugins,
|
|
27
|
+
}, WorkerType.Application);
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.runtimeOptions = runtimeOptions;
|
|
30
|
+
this.appConfig = appConfig;
|
|
31
|
+
this.applicationHooks = new ApplicationHooks();
|
|
32
|
+
this.api = new ApplicationApi({
|
|
33
|
+
timeout: this.appConfig.api.timeout,
|
|
34
|
+
container: this.container,
|
|
35
|
+
logger: this.logger,
|
|
36
|
+
filters: this.filters,
|
|
37
|
+
middlewares: this.middlewares,
|
|
38
|
+
guards: this.guards,
|
|
39
|
+
procedures: this.procedures,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async start() {
|
|
43
|
+
await this.initialize();
|
|
44
|
+
this.transports = {};
|
|
45
|
+
for (const key in this.runtimeOptions.transports) {
|
|
46
|
+
const options = this.runtimeOptions.transports[key];
|
|
47
|
+
const { factory, proxyable } = this.appConfig.transports[key];
|
|
48
|
+
this.transports[key] = { transport: await factory(options), proxyable };
|
|
49
|
+
}
|
|
50
|
+
this.gateway = new Gateway({
|
|
51
|
+
logger: this.logger,
|
|
52
|
+
container: this.container,
|
|
53
|
+
hooks: this.lifecycleHooks,
|
|
54
|
+
formats: new ProtocolFormats([new JsonFormat()]),
|
|
55
|
+
transports: this.transports,
|
|
56
|
+
api: this.api,
|
|
57
|
+
identity: this.appConfig.identity,
|
|
58
|
+
});
|
|
59
|
+
return await this.gateway.start().finally(async () => {
|
|
60
|
+
await this.lifecycleHooks.callHook(LifecycleHook.Start);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async stop() {
|
|
64
|
+
await this.gateway.stop();
|
|
65
|
+
await this.dispose();
|
|
66
|
+
await this.lifecycleHooks.callHook(LifecycleHook.Stop);
|
|
67
|
+
}
|
|
68
|
+
async reload(appConfig) {
|
|
69
|
+
await this.dispose();
|
|
70
|
+
this.appConfig = appConfig;
|
|
71
|
+
this.plugins = appConfig.plugins;
|
|
72
|
+
await this.initialize();
|
|
73
|
+
this.gateway.options.identity =
|
|
74
|
+
this.appConfig.identity ?? this.gateway.options.identity;
|
|
75
|
+
await this.gateway.reload();
|
|
76
|
+
}
|
|
77
|
+
async initialize() {
|
|
78
|
+
this.registerApi();
|
|
79
|
+
this.lifecycleHooks.addHooks(this.appConfig.lifecycleHooks);
|
|
80
|
+
await super.initialize();
|
|
81
|
+
}
|
|
82
|
+
async _initialize() {
|
|
83
|
+
await super._initialize();
|
|
84
|
+
for (const hook of this.appConfig.hooks) {
|
|
85
|
+
this.applicationHooks.hook(hook.name, async (...args) => {
|
|
86
|
+
const ctx = await this.container.createContext(hook.dependencies);
|
|
87
|
+
await hook.handler(ctx, ...args);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async _dispose() {
|
|
92
|
+
this.applicationHooks.removeAllHooks();
|
|
93
|
+
await super._dispose();
|
|
94
|
+
this.lifecycleHooks.removeHooks(this.appConfig.lifecycleHooks);
|
|
95
|
+
this.filters.clear();
|
|
96
|
+
this.middlewares.clear();
|
|
97
|
+
this.guards.clear();
|
|
98
|
+
this.routers.clear();
|
|
99
|
+
this.procedures.clear();
|
|
100
|
+
}
|
|
101
|
+
*_dependents() {
|
|
102
|
+
yield* this.appConfig.filters;
|
|
103
|
+
yield* this.appConfig.guards;
|
|
104
|
+
yield* this.appConfig.middlewares;
|
|
105
|
+
yield* this.appConfig.hooks;
|
|
106
|
+
for (const { procedure } of this.procedures.values()) {
|
|
107
|
+
yield procedure;
|
|
108
|
+
yield* procedure.guards;
|
|
109
|
+
yield* procedure.middlewares;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
registerApi() {
|
|
113
|
+
const { router, filters, guards, middlewares } = this.appConfig;
|
|
114
|
+
if (this.routers.has(kRootRouter)) {
|
|
115
|
+
throw new Error('Root router already registered');
|
|
116
|
+
}
|
|
117
|
+
if (!isRootRouter(router)) {
|
|
118
|
+
throw new Error('Root router must be a root router');
|
|
119
|
+
}
|
|
120
|
+
this.routers.set(kRootRouter, router);
|
|
121
|
+
this.registerRouter(router, []);
|
|
122
|
+
if (router.default) {
|
|
123
|
+
if (!isProcedure(router.default)) {
|
|
124
|
+
throw new Error('Root router default must be a procedure');
|
|
125
|
+
}
|
|
126
|
+
this.procedures.set(kDefaultProcedure, {
|
|
127
|
+
procedure: router.default,
|
|
128
|
+
path: [router],
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
for (const filter of filters)
|
|
132
|
+
this.filters.add(filter);
|
|
133
|
+
for (const middleware of middlewares)
|
|
134
|
+
this.middlewares.add(middleware);
|
|
135
|
+
for (const guard of guards)
|
|
136
|
+
this.guards.add(guard);
|
|
137
|
+
}
|
|
138
|
+
registerRouter(router, path = []) {
|
|
139
|
+
for (const route of Object.values(router.routes)) {
|
|
140
|
+
if (isRouter(route)) {
|
|
141
|
+
const name = route.contract.name;
|
|
142
|
+
if (!name)
|
|
143
|
+
throw new Error('Nested routers must have a name');
|
|
144
|
+
if (this.routers.has(name)) {
|
|
145
|
+
throw new Error(`Router ${String(name)} already registered`);
|
|
146
|
+
}
|
|
147
|
+
this.routers.set(name, route);
|
|
148
|
+
this.registerRouter(route, [...path, router]);
|
|
149
|
+
}
|
|
150
|
+
else if (isProcedure(route)) {
|
|
151
|
+
const name = route.contract.name;
|
|
152
|
+
if (!name)
|
|
153
|
+
throw new Error('Procedures must have a name');
|
|
154
|
+
if (this.procedures.has(name)) {
|
|
155
|
+
throw new Error(`Procedure ${name} already registered`);
|
|
156
|
+
}
|
|
157
|
+
this.procedures.set(name, { procedure: route, path: [...path, router] });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=application.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application.js","sourceRoot":"","sources":["../../../src/runtime/workers/application.ts"],"names":[],"mappings":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ACjD,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpB,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAA;gBAChC,IAAI,CAAC,IAAI;oBAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;gBAC7D,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC3B,MAAM,IAAI,KAAK,CAAC,UAAU,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;gBAC9D,CAAC;gBACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;gBAC7B,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC,CAAA;YAC/C,CAAC;iBAAM,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAA;gBAChC,IAAI,CAAC,IAAI;oBAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;gBACzD,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,qBAAqB,CAAC,CAAA;gBACzD,CAAC;gBACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;YAC1E,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BaseRuntimeOptions } from '../core/runtime.ts';
|
|
2
|
+
import type { WorkerType } from '../enums.ts';
|
|
3
|
+
import type { ServerConfig } from '../server/config.ts';
|
|
4
|
+
import { BaseRuntime } from '../core/runtime.ts';
|
|
5
|
+
import { JobManager } from '../jobs/manager.ts';
|
|
6
|
+
import { PubSubManager } from '../pubsub/manager.ts';
|
|
7
|
+
export declare abstract class BaseWorkerRuntime extends BaseRuntime {
|
|
8
|
+
readonly config: ServerConfig;
|
|
9
|
+
readonly workerType: WorkerType;
|
|
10
|
+
pubsub: PubSubManager;
|
|
11
|
+
jobManager?: JobManager;
|
|
12
|
+
constructor(config: ServerConfig, options: BaseRuntimeOptions, workerType: WorkerType);
|
|
13
|
+
initialize(): Promise<void>;
|
|
14
|
+
protected _initialize(): Promise<void>;
|
|
15
|
+
protected _dispose(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CoreInjectables, provide } from '@nmtjs/core';
|
|
2
|
+
import { BaseRuntime } from "../core/runtime.js";
|
|
3
|
+
import * as injectables from "../injectables.js";
|
|
4
|
+
import { JobManager } from "../jobs/manager.js";
|
|
5
|
+
import { PubSubManager } from "../pubsub/manager.js";
|
|
6
|
+
export class BaseWorkerRuntime extends BaseRuntime {
|
|
7
|
+
config;
|
|
8
|
+
workerType;
|
|
9
|
+
pubsub;
|
|
10
|
+
jobManager;
|
|
11
|
+
constructor(config, options, workerType) {
|
|
12
|
+
super(options);
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.workerType = workerType;
|
|
15
|
+
this.pubsub = new PubSubManager({
|
|
16
|
+
logger: this.logger,
|
|
17
|
+
container: this.container,
|
|
18
|
+
});
|
|
19
|
+
if (this.config.store) {
|
|
20
|
+
this.jobManager = new JobManager(this.config.store, this.config.jobs ? Array.from(this.config.jobs.jobs.values()) : []);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async initialize() {
|
|
24
|
+
const injections = [
|
|
25
|
+
provide(CoreInjectables.logger, this.logger),
|
|
26
|
+
provide(injectables.workerType, this.workerType),
|
|
27
|
+
provide(injectables.pubSubPublish, this.pubsub.publish.bind(this.pubsub)),
|
|
28
|
+
provide(injectables.pubSubSubscribe, this.pubsub.subscribe.bind(this.pubsub)),
|
|
29
|
+
];
|
|
30
|
+
if (this.config.store) {
|
|
31
|
+
injections.push(provide(injectables.storeConfig, this.config.store));
|
|
32
|
+
}
|
|
33
|
+
if (this.jobManager) {
|
|
34
|
+
injections.push(provide(injectables.jobManager, this.jobManager.publicInstance));
|
|
35
|
+
}
|
|
36
|
+
await this.container.provide(injections);
|
|
37
|
+
await super.initialize();
|
|
38
|
+
}
|
|
39
|
+
async _initialize() {
|
|
40
|
+
await this.jobManager?.initialize();
|
|
41
|
+
}
|
|
42
|
+
async _dispose() {
|
|
43
|
+
await this.jobManager?.terminate();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/runtime/workers/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAKtD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD,MAAM,OAAgB,iBAAkB,SAAQ,WAAW;IAK9C;IAEA;IANX,MAAM,CAAe;IACrB,UAAU,CAAa;IAEvB,YACW,MAAoB,EAC7B,OAA2B,EAClB,UAAsB;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAA;QAJL,WAAM,GAAN,MAAM,CAAc;QAEpB,eAAU,GAAV,UAAU,CAAY;QAI/B,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC;YAC9B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC,CAAA;QAEF,IAAI,IAA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C,WAAW;QACzB,MAAM,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,CAAA;IACrC,CAAC;IAES,KAAK,CAAC,QAAQ;QACtB,MAAM,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,CAAA;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/runtime/workers/cli.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MessagePort } from 'node:worker_threads';
|
|
2
|
+
import type { ServerConfig } from '../server/config.ts';
|
|
3
|
+
import { ApplicationWorkerJobRunner } from '../jobs/runner.ts';
|
|
4
|
+
import { BaseWorkerRuntime } from './base.ts';
|
|
5
|
+
export interface JobWorkerRuntimeOptions {
|
|
6
|
+
poolName: string;
|
|
7
|
+
port: MessagePort;
|
|
8
|
+
}
|
|
9
|
+
export declare class JobWorkerRuntime extends BaseWorkerRuntime {
|
|
10
|
+
readonly config: ServerConfig;
|
|
11
|
+
readonly runtimeOptions: JobWorkerRuntimeOptions;
|
|
12
|
+
jobRunner: ApplicationWorkerJobRunner;
|
|
13
|
+
constructor(config: ServerConfig, runtimeOptions: JobWorkerRuntimeOptions);
|
|
14
|
+
start(): Promise<void>;
|
|
15
|
+
stop(): Promise<void>;
|
|
16
|
+
initialize(): Promise<void>;
|
|
17
|
+
protected _initialize(): Promise<void>;
|
|
18
|
+
protected _dispose(): Promise<void>;
|
|
19
|
+
protected _dependents(): Generator<import("../index.ts").AnyJob, void, unknown>;
|
|
20
|
+
}
|