@bakit/service 3.2.1 → 4.0.1

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.
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var url = require('url');
4
+ var service = require('@bakit/service');
5
+
6
+ // src/lib/internal/service.ts
7
+ async function start() {
8
+ let { BAKIT_SERVICE_NAME, BAKIT_SERVICE_PATH } = process.env;
9
+ if (typeof BAKIT_SERVICE_NAME != "string")
10
+ throw new Error("BAKIT_SERVICE_NAME is not defined");
11
+ if (typeof BAKIT_SERVICE_PATH != "string")
12
+ throw new Error("BAKIT_SERVICE_PATH is not defined");
13
+ let module = await import(url.pathToFileURL(BAKIT_SERVICE_PATH).toString()), { service: service$1, initialize, onReady } = module;
14
+ if (!(service$1 instanceof service.Service))
15
+ throw new Error(`Service "${BAKIT_SERVICE_NAME}" is not an instance of Service`);
16
+ setupShutdown(service$1), typeof initialize == "function" && await Promise.resolve(initialize()), await service$1.ensureServerBound(), typeof onReady == "function" && await Promise.resolve(onReady());
17
+ }
18
+ async function setupShutdown(service) {
19
+ let shutdown = async () => {
20
+ let runtime = service.runtime;
21
+ runtime?.role === "server" && await new Promise((resolve) => {
22
+ runtime.transport.on("close", resolve), runtime.transport.close();
23
+ }), process.exit(0);
24
+ };
25
+ process.on("SIGINT", shutdown), process.on("SIGTERM", shutdown);
26
+ }
27
+ start();
@@ -0,0 +1,25 @@
1
+ import { pathToFileURL } from 'url';
2
+ import { Service } from '@bakit/service';
3
+
4
+ // src/lib/internal/service.ts
5
+ async function start() {
6
+ let { BAKIT_SERVICE_NAME, BAKIT_SERVICE_PATH } = process.env;
7
+ if (typeof BAKIT_SERVICE_NAME != "string")
8
+ throw new Error("BAKIT_SERVICE_NAME is not defined");
9
+ if (typeof BAKIT_SERVICE_PATH != "string")
10
+ throw new Error("BAKIT_SERVICE_PATH is not defined");
11
+ let module = await import(pathToFileURL(BAKIT_SERVICE_PATH).toString()), { service, initialize, onReady } = module;
12
+ if (!(service instanceof Service))
13
+ throw new Error(`Service "${BAKIT_SERVICE_NAME}" is not an instance of Service`);
14
+ setupShutdown(service), typeof initialize == "function" && await Promise.resolve(initialize()), await service.ensureServerBound(), typeof onReady == "function" && await Promise.resolve(onReady());
15
+ }
16
+ async function setupShutdown(service) {
17
+ let shutdown = async () => {
18
+ let runtime = service.runtime;
19
+ runtime?.role === "server" && await new Promise((resolve) => {
20
+ runtime.transport.on("close", resolve), runtime.transport.close();
21
+ }), process.exit(0);
22
+ };
23
+ process.on("SIGINT", shutdown), process.on("SIGTERM", shutdown);
24
+ }
25
+ start();
package/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "@bakit/service",
3
- "version": "3.2.1",
3
+ "version": "4.0.1",
4
4
  "description": "Service manager for bakit framework",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "import": "./dist/index.js",
9
- "types": "./dist/index.d.ts"
8
+ "import": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "require": {
13
+ "types": "./dist/index.d.cts",
14
+ "default": "./dist/index.cjs"
15
+ }
10
16
  }
11
17
  },
12
18
  "files": [
@@ -28,10 +34,8 @@
28
34
  "author": "louiszn",
29
35
  "license": "MIT",
30
36
  "dependencies": {
31
- "p-queue": "^9.1.0",
32
- "msgpackr": "^1.11.8",
33
37
  "type-fest": "^4.41.0",
34
- "@bakit/utils": "^2.0.0"
38
+ "@bakit/utils": "^2.3.0"
35
39
  },
36
40
  "devDependencies": {
37
41
  "@types/ws": "^8.18.1",