@start9labs/start-sdk 0.4.0-beta.2 → 0.4.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/base/lib/Effects.d.ts +4 -22
- package/base/lib/actions/index.d.ts +5 -5
- package/base/lib/actions/index.js.map +1 -1
- package/base/lib/actions/input/builder/inputSpec.d.ts +10 -25
- package/base/lib/actions/input/builder/inputSpec.js +0 -17
- package/base/lib/actions/input/builder/inputSpec.js.map +1 -1
- package/base/lib/actions/input/builder/list.d.ts +8 -23
- package/base/lib/actions/input/builder/list.js +0 -17
- package/base/lib/actions/input/builder/list.js.map +1 -1
- package/base/lib/actions/input/builder/value.d.ts +318 -53
- package/base/lib/actions/input/builder/value.js +280 -17
- package/base/lib/actions/input/builder/value.js.map +1 -1
- package/base/lib/actions/input/builder/variants.d.ts +8 -23
- package/base/lib/actions/input/builder/variants.js +0 -17
- package/base/lib/actions/input/builder/variants.js.map +1 -1
- package/base/lib/actions/input/inputSpecConstants.d.ts +6 -6
- package/base/lib/actions/input/inputSpecConstants.js.map +1 -1
- package/base/lib/actions/setupActions.d.ts +10 -11
- package/base/lib/actions/setupActions.js +24 -11
- package/base/lib/actions/setupActions.js.map +1 -1
- package/base/lib/dependencies/setupDependencies.d.ts +1 -3
- package/base/lib/dependencies/setupDependencies.js +3 -12
- package/base/lib/dependencies/setupDependencies.js.map +1 -1
- package/base/lib/index.d.ts +1 -0
- package/base/lib/index.js +2 -1
- package/base/lib/index.js.map +1 -1
- package/base/lib/inits/index.d.ts +2 -0
- package/base/lib/inits/index.js +19 -0
- package/base/lib/inits/index.js.map +1 -0
- package/base/lib/inits/setupInit.d.ts +11 -0
- package/base/lib/inits/setupInit.js +69 -0
- package/base/lib/inits/setupInit.js.map +1 -0
- package/base/lib/inits/setupUninit.d.ts +7 -0
- package/base/lib/inits/setupUninit.js +14 -0
- package/base/lib/inits/setupUninit.js.map +1 -0
- package/base/lib/interfaces/setupInterfaces.d.ts +2 -4
- package/base/lib/interfaces/setupInterfaces.js +8 -19
- package/base/lib/interfaces/setupInterfaces.js.map +1 -1
- package/base/lib/osBindings/AddCategoryParams.d.ts +0 -2
- package/base/lib/osBindings/AddPackageToCategoryParams.d.ts +5 -0
- package/base/lib/osBindings/AddPackageToCategoryParams.js +3 -0
- package/base/lib/osBindings/AddPackageToCategoryParams.js.map +1 -0
- package/base/lib/osBindings/Category.d.ts +0 -2
- package/base/lib/osBindings/Category.js +1 -0
- package/base/lib/osBindings/Category.js.map +1 -1
- package/base/lib/osBindings/FileType.d.ts +1 -0
- package/base/lib/osBindings/{UnsetPublicParams.js → FileType.js} +1 -1
- package/base/lib/osBindings/FileType.js.map +1 -0
- package/base/lib/osBindings/GetOsVersionParams.d.ts +4 -3
- package/base/lib/osBindings/GetPackageParams.d.ts +1 -1
- package/base/lib/osBindings/MainStatus.d.ts +0 -2
- package/base/lib/osBindings/MountTarget.d.ts +2 -0
- package/base/lib/osBindings/PackageDataEntry.d.ts +1 -2
- package/base/lib/osBindings/RemoveAdminParams.d.ts +4 -0
- package/base/lib/osBindings/RemoveAdminParams.js +3 -0
- package/base/lib/osBindings/RemoveAdminParams.js.map +1 -0
- package/base/lib/osBindings/RemoveAssetParams.d.ts +4 -0
- package/base/lib/osBindings/{NetworkInterfaceSetPublicParams.js → RemoveAssetParams.js} +1 -1
- package/base/lib/osBindings/RemoveAssetParams.js.map +1 -0
- package/base/lib/osBindings/RemovePackageFromCategoryParams.d.ts +5 -0
- package/base/lib/osBindings/RemovePackageFromCategoryParams.js +3 -0
- package/base/lib/osBindings/RemovePackageFromCategoryParams.js.map +1 -0
- package/base/lib/osBindings/RemovePackageParams.d.ts +6 -0
- package/base/lib/osBindings/RemovePackageParams.js +3 -0
- package/base/lib/osBindings/RemovePackageParams.js.map +1 -0
- package/base/lib/osBindings/index.d.ts +6 -3
- package/base/lib/types.d.ts +20 -33
- package/base/lib/types.js +8 -0
- package/base/lib/types.js.map +1 -1
- package/base/lib/util/GetSystemSmtp.js +7 -2
- package/base/lib/util/GetSystemSmtp.js.map +1 -1
- package/base/lib/util/getServiceInterface.d.ts +10 -0
- package/base/lib/util/getServiceInterface.js +41 -1
- package/base/lib/util/getServiceInterface.js.map +1 -1
- package/base/lib/util/getServiceInterfaces.js +6 -1
- package/base/lib/util/getServiceInterfaces.js.map +1 -1
- package/base/lib/util/index.d.ts +0 -1
- package/base/lib/util/index.js +1 -3
- package/base/lib/util/index.js.map +1 -1
- package/package/lib/StartSdk.d.ts +106 -546
- package/package/lib/StartSdk.js +81 -410
- package/package/lib/StartSdk.js.map +1 -1
- package/package/lib/backup/Backups.d.ts +15 -3
- package/package/lib/backup/Backups.js +47 -5
- package/package/lib/backup/Backups.js.map +1 -1
- package/package/lib/backup/setupBackups.d.ts +5 -2
- package/package/lib/backup/setupBackups.js +7 -5
- package/package/lib/backup/setupBackups.js.map +1 -1
- package/package/lib/health/HealthCheck.js +1 -1
- package/package/lib/health/HealthCheck.js.map +1 -1
- package/package/lib/health/checkFns/runHealthScript.d.ts +2 -1
- package/package/lib/health/checkFns/runHealthScript.js +1 -1
- package/package/lib/health/checkFns/runHealthScript.js.map +1 -1
- package/package/lib/index.d.ts +0 -3
- package/package/lib/index.js +1 -8
- package/package/lib/index.js.map +1 -1
- package/package/lib/inits/index.d.ts +2 -3
- package/package/lib/inits/index.js +16 -3
- package/package/lib/inits/index.js.map +1 -1
- package/package/lib/inits/setupInit.d.ts +7 -13
- package/package/lib/inits/setupInit.js +22 -48
- package/package/lib/inits/setupInit.js.map +1 -1
- package/package/lib/inits/setupInstall.d.ts +10 -10
- package/package/lib/inits/setupInstall.js.map +1 -1
- package/package/lib/inits/setupUninit.d.ts +7 -0
- package/package/lib/inits/setupUninit.js +14 -0
- package/package/lib/inits/setupUninit.js.map +1 -0
- package/package/lib/inits/setupUninstall.d.ts +5 -5
- package/package/lib/inits/setupUninstall.js.map +1 -1
- package/package/lib/mainFn/CommandController.d.ts +4 -13
- package/package/lib/mainFn/CommandController.js +28 -49
- package/package/lib/mainFn/CommandController.js.map +1 -1
- package/package/lib/mainFn/Daemon.d.ts +13 -14
- package/package/lib/mainFn/Daemon.js +44 -12
- package/package/lib/mainFn/Daemon.js.map +1 -1
- package/package/lib/mainFn/Daemons.d.ts +34 -33
- package/package/lib/mainFn/Daemons.js +30 -10
- package/package/lib/mainFn/Daemons.js.map +1 -1
- package/package/lib/mainFn/HealthDaemon.d.ts +6 -6
- package/package/lib/mainFn/HealthDaemon.js +30 -14
- package/package/lib/mainFn/HealthDaemon.js.map +1 -1
- package/package/lib/mainFn/Mounts.d.ts +38 -43
- package/package/lib/mainFn/Mounts.js +19 -48
- package/package/lib/mainFn/Mounts.js.map +1 -1
- package/package/lib/mainFn/Oneshot.d.ts +21 -0
- package/package/lib/mainFn/Oneshot.js +31 -0
- package/package/lib/mainFn/Oneshot.js.map +1 -0
- package/package/lib/mainFn/index.d.ts +1 -1
- package/package/lib/store/getStore.js +7 -2
- package/package/lib/store/getStore.js.map +1 -1
- package/package/lib/test/inputSpecBuilder.test.js +0 -8
- package/package/lib/test/inputSpecBuilder.test.js.map +1 -1
- package/package/lib/test/output.d.ts +2 -38
- package/package/lib/test/output.sdk.d.ts +239 -887
- package/package/lib/test/output.sdk.js +0 -1
- package/package/lib/test/output.sdk.js.map +1 -1
- package/package/lib/util/Drop.d.ts +1 -0
- package/package/lib/util/Drop.js +17 -4
- package/package/lib/util/Drop.js.map +1 -1
- package/package/lib/util/GetSslCertificate.js +7 -2
- package/package/lib/util/GetSslCertificate.js.map +1 -1
- package/package/lib/util/SubContainer.d.ts +160 -44
- package/package/lib/util/SubContainer.js +215 -99
- package/package/lib/util/SubContainer.js.map +1 -1
- package/package/lib/util/fileHelper.d.ts +41 -15
- package/package/lib/util/fileHelper.js +72 -27
- package/package/lib/util/fileHelper.js.map +1 -1
- package/package/lib/version/VersionGraph.d.ts +20 -5
- package/package/lib/version/VersionGraph.js +85 -18
- package/package/lib/version/VersionGraph.js.map +1 -1
- package/package.json +10 -11
- package/base/lib/osBindings/NetworkInterfaceSetPublicParams.d.ts +0 -4
- package/base/lib/osBindings/NetworkInterfaceSetPublicParams.js.map +0 -1
- package/base/lib/osBindings/UnsetPublicParams.d.ts +0 -3
- package/base/lib/osBindings/UnsetPublicParams.js.map +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupUninit = setupUninit;
|
|
4
|
+
function setupUninit(...uninits) {
|
|
5
|
+
return async (opts) => {
|
|
6
|
+
for (const uninit of uninits) {
|
|
7
|
+
if ("uninit" in uninit)
|
|
8
|
+
await uninit.uninit(opts.effects, opts.target);
|
|
9
|
+
else
|
|
10
|
+
await uninit(opts.effects, opts.target);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=setupUninit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupUninit.js","sourceRoot":"","sources":["../../../../package/lib/inits/setupUninit.ts"],"names":[],"mappings":";;AAeA,kCASC;AATD,SAAgB,WAAW,CACzB,GAAG,OAAoC;IAEvC,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,QAAQ,IAAI,MAAM;gBAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;;gBACjE,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAC9C,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as T from "../../../base/lib/types";
|
|
2
|
-
export type UninstallFn<Manifest extends T.SDKManifest
|
|
2
|
+
export type UninstallFn<Manifest extends T.SDKManifest> = (opts: {
|
|
3
3
|
effects: T.Effects;
|
|
4
4
|
}) => Promise<null | void | undefined>;
|
|
5
|
-
export declare class Uninstall<Manifest extends T.SDKManifest
|
|
6
|
-
readonly fn: UninstallFn<Manifest
|
|
5
|
+
export declare class Uninstall<Manifest extends T.SDKManifest> {
|
|
6
|
+
readonly fn: UninstallFn<Manifest>;
|
|
7
7
|
private constructor();
|
|
8
|
-
static of<Manifest extends T.SDKManifest
|
|
8
|
+
static of<Manifest extends T.SDKManifest>(fn: UninstallFn<Manifest>): Uninstall<Manifest>;
|
|
9
9
|
uninstall({ effects, nextVersion, }: Parameters<T.ExpectedExports.packageUninit>[0]): Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
export declare function setupUninstall<Manifest extends T.SDKManifest
|
|
11
|
+
export declare function setupUninstall<Manifest extends T.SDKManifest>(fn: UninstallFn<Manifest>): Uninstall<Manifest>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupUninstall.js","sourceRoot":"","sources":["../../../../package/lib/inits/setupUninstall.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"setupUninstall.js","sourceRoot":"","sources":["../../../../package/lib/inits/setupUninstall.ts"],"names":[],"mappings":";;;AAsBA,wCAIC;AArBD,MAAa,SAAS;IACpB,YAA6B,EAAyB;QAAzB,OAAE,GAAF,EAAE,CAAuB;IAAG,CAAC;IAC1D,MAAM,CAAC,EAAE,CAAiC,EAAyB;QACjE,OAAO,IAAI,SAAS,CAAC,EAAE,CAAC,CAAA;IAC1B,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,EACd,OAAO,EACP,WAAW,GACoC;QAC/C,IAAI,CAAC,WAAW;YACd,MAAM,IAAI,CAAC,EAAE,CAAC;gBACZ,OAAO;aACR,CAAC,CAAA;IACN,CAAC;CACF;AAfD,8BAeC;AAED,SAAgB,cAAc,CAC5B,EAAyB;IAEzB,OAAO,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import * as T from "../../../base/lib/types";
|
|
2
|
-
import {
|
|
2
|
+
import { SubContainer } from "../util/SubContainer";
|
|
3
3
|
import { Drop } from "../util";
|
|
4
|
-
export declare class CommandController extends Drop {
|
|
4
|
+
export declare class CommandController<Manifest extends T.SDKManifest> extends Drop {
|
|
5
5
|
readonly runningAnswer: Promise<unknown>;
|
|
6
6
|
private state;
|
|
7
7
|
private readonly subcontainer;
|
|
8
8
|
private process;
|
|
9
9
|
readonly sigtermTimeout: number;
|
|
10
10
|
private constructor();
|
|
11
|
-
static of<Manifest extends T.SDKManifest>():
|
|
12
|
-
imageId: keyof Manifest["images"] & T.ImageId;
|
|
13
|
-
sharedRun?: boolean;
|
|
14
|
-
} | SubContainer, command: T.CommandType, options: {
|
|
15
|
-
subcontainerName?: string;
|
|
11
|
+
static of<Manifest extends T.SDKManifest>(): (effects: T.Effects, subcontainer: SubContainer<Manifest>, command: T.CommandType, options: {
|
|
16
12
|
sigtermTimeout?: number;
|
|
17
|
-
mounts?: {
|
|
18
|
-
mountpoint: string;
|
|
19
|
-
options: MountOptions;
|
|
20
|
-
}[];
|
|
21
13
|
runAsInit?: boolean;
|
|
22
14
|
env?: {
|
|
23
15
|
[variable: string]: string;
|
|
@@ -26,8 +18,7 @@ export declare class CommandController extends Drop {
|
|
|
26
18
|
user?: string | undefined;
|
|
27
19
|
onStdout?: (chunk: Buffer | string | any) => void;
|
|
28
20
|
onStderr?: (chunk: Buffer | string | any) => void;
|
|
29
|
-
}) => Promise<CommandController
|
|
30
|
-
get subContainerHandle(): SubContainerHandle;
|
|
21
|
+
}) => Promise<CommandController<Manifest>>;
|
|
31
22
|
wait({ timeout }?: {
|
|
32
23
|
timeout?: number | undefined;
|
|
33
24
|
}): Promise<unknown>;
|
|
@@ -37,7 +37,6 @@ exports.CommandController = void 0;
|
|
|
37
37
|
const _1 = require(".");
|
|
38
38
|
const types_1 = require("../../../base/lib/types");
|
|
39
39
|
const T = __importStar(require("../../../base/lib/types"));
|
|
40
|
-
const SubContainer_1 = require("../util/SubContainer");
|
|
41
40
|
const util_1 = require("../util");
|
|
42
41
|
const fs = __importStar(require("node:fs/promises"));
|
|
43
42
|
class CommandController extends util_1.Drop {
|
|
@@ -51,43 +50,28 @@ class CommandController extends util_1.Drop {
|
|
|
51
50
|
}
|
|
52
51
|
static of() {
|
|
53
52
|
return async (effects, subcontainer, command, options) => {
|
|
54
|
-
let commands;
|
|
55
|
-
if (command instanceof T.UseEntrypoint) {
|
|
56
|
-
const imageMeta = await fs
|
|
57
|
-
.readFile(`/media/startos/images/${subcontainer.imageId}.json`, {
|
|
58
|
-
encoding: "utf8",
|
|
59
|
-
})
|
|
60
|
-
.catch(() => "{}")
|
|
61
|
-
.then(JSON.parse);
|
|
62
|
-
commands = imageMeta.entrypoint ?? [];
|
|
63
|
-
commands.concat(...(command.overridCmd ?? imageMeta.cmd ?? []));
|
|
64
|
-
}
|
|
65
|
-
else
|
|
66
|
-
commands = (0, util_1.splitCommand)(command);
|
|
67
|
-
const subc = subcontainer instanceof SubContainer_1.SubContainer
|
|
68
|
-
? subcontainer
|
|
69
|
-
: await (async () => {
|
|
70
|
-
const subc = await SubContainer_1.SubContainer.of(effects, subcontainer, options?.subcontainerName || commands.join(" "));
|
|
71
|
-
try {
|
|
72
|
-
for (let mount of options.mounts || []) {
|
|
73
|
-
await subc.mount(mount.options, mount.mountpoint);
|
|
74
|
-
}
|
|
75
|
-
return subc;
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
await subc.destroy();
|
|
79
|
-
throw e;
|
|
80
|
-
}
|
|
81
|
-
})();
|
|
82
53
|
try {
|
|
54
|
+
let commands;
|
|
55
|
+
if (command instanceof T.UseEntrypoint) {
|
|
56
|
+
const imageMeta = await fs
|
|
57
|
+
.readFile(`/media/startos/images/${subcontainer.imageId}.json`, {
|
|
58
|
+
encoding: "utf8",
|
|
59
|
+
})
|
|
60
|
+
.catch(() => "{}")
|
|
61
|
+
.then(JSON.parse);
|
|
62
|
+
commands = imageMeta.entrypoint ?? [];
|
|
63
|
+
commands = commands.concat(...(command.overridCmd ?? imageMeta.cmd ?? []));
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
commands = (0, util_1.splitCommand)(command);
|
|
83
67
|
let childProcess;
|
|
84
68
|
if (options.runAsInit) {
|
|
85
|
-
childProcess = await
|
|
69
|
+
childProcess = await subcontainer.launch(commands, {
|
|
86
70
|
env: options.env,
|
|
87
71
|
});
|
|
88
72
|
}
|
|
89
73
|
else {
|
|
90
|
-
childProcess = await
|
|
74
|
+
childProcess = await subcontainer.spawn(commands, {
|
|
91
75
|
env: options.env,
|
|
92
76
|
stdio: options.onStdout || options.onStderr ? "pipe" : "inherit",
|
|
93
77
|
});
|
|
@@ -113,51 +97,46 @@ class CommandController extends util_1.Drop {
|
|
|
113
97
|
}
|
|
114
98
|
});
|
|
115
99
|
});
|
|
116
|
-
return new CommandController(answer, state,
|
|
100
|
+
return new CommandController(answer, state, subcontainer, childProcess, options.sigtermTimeout);
|
|
117
101
|
}
|
|
118
102
|
catch (e) {
|
|
119
|
-
await
|
|
103
|
+
await subcontainer.destroy();
|
|
120
104
|
throw e;
|
|
121
105
|
}
|
|
122
106
|
};
|
|
123
107
|
}
|
|
124
|
-
get subContainerHandle() {
|
|
125
|
-
return new SubContainer_1.SubContainerHandle(this.subcontainer);
|
|
126
|
-
}
|
|
127
108
|
async wait({ timeout = types_1.NO_TIMEOUT } = {}) {
|
|
128
|
-
const self = this.weak();
|
|
129
109
|
if (timeout > 0)
|
|
130
110
|
setTimeout(() => {
|
|
131
|
-
|
|
111
|
+
this.term();
|
|
132
112
|
}, timeout);
|
|
133
113
|
try {
|
|
134
|
-
return await
|
|
114
|
+
return await this.runningAnswer;
|
|
135
115
|
}
|
|
136
116
|
finally {
|
|
137
|
-
if (!
|
|
138
|
-
|
|
117
|
+
if (!this.state.exited) {
|
|
118
|
+
this.process.kill("SIGKILL");
|
|
139
119
|
}
|
|
140
|
-
await
|
|
120
|
+
await this.subcontainer.destroy();
|
|
141
121
|
}
|
|
142
122
|
}
|
|
143
123
|
async term({ signal = types_1.SIGTERM, timeout = this.sigtermTimeout } = {}) {
|
|
144
|
-
const self = this.weak();
|
|
145
124
|
try {
|
|
146
|
-
if (!
|
|
125
|
+
if (!this.state.exited) {
|
|
147
126
|
if (signal !== "SIGKILL") {
|
|
148
127
|
setTimeout(() => {
|
|
149
|
-
if (!
|
|
150
|
-
|
|
128
|
+
if (!this.state.exited)
|
|
129
|
+
this.process.kill("SIGKILL");
|
|
151
130
|
}, timeout);
|
|
152
131
|
}
|
|
153
|
-
if (!
|
|
132
|
+
if (!this.process.kill(signal)) {
|
|
154
133
|
console.error(`failed to send signal ${signal} to pid ${this.process.pid}`);
|
|
155
134
|
}
|
|
156
135
|
}
|
|
157
|
-
await
|
|
136
|
+
await this.runningAnswer;
|
|
158
137
|
}
|
|
159
138
|
finally {
|
|
160
|
-
await
|
|
139
|
+
await this.subcontainer.destroy();
|
|
161
140
|
}
|
|
162
141
|
}
|
|
163
142
|
onDrop() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandController.js","sourceRoot":"","sources":["../../../../package/lib/mainFn/CommandController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wBAA2C;AAC3C,mDAA6D;AAE7D,2DAA4C;
|
|
1
|
+
{"version":3,"file":"CommandController.js","sourceRoot":"","sources":["../../../../package/lib/mainFn/CommandController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wBAA2C;AAC3C,mDAA6D;AAE7D,2DAA4C;AAE5C,kCAA4C;AAE5C,qDAAsC;AAGtC,MAAa,iBAAkD,SAAQ,WAAI;IACzE,YACW,aAA+B,EAChC,KAA0B,EACjB,YAAoC,EAC7C,OAAwB,EACvB,iBAAyB,0BAAuB;QAEzD,KAAK,EAAE,C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G,EAAE,CAC7D,CAAA;gBACH,CAAC;YACH,CAAC;YAED,MAAM,IAAI,CAAC,aAAa,CAAA;QAC1B,CAAC;gBAAS,CAAC;YACT,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAA;QACnC,CAAC;IACH,CAAC;IACD,MAAM;QACJ,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAClC,CAAC;CACF;AAvID,8CAuIC"}
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import * as T from "../../../base/lib/types";
|
|
2
|
-
import {
|
|
2
|
+
import { Drop } from "../util";
|
|
3
|
+
import { SubContainer, SubContainerRc } from "../util/SubContainer";
|
|
3
4
|
import { CommandController } from "./CommandController";
|
|
4
5
|
/**
|
|
5
6
|
* This is a wrapper around CommandController that has a state of off, where the command shouldn't be running
|
|
6
7
|
* and the others state of running, where it will keep a living running command
|
|
7
8
|
*/
|
|
8
|
-
export declare class Daemon {
|
|
9
|
+
export declare class Daemon<Manifest extends T.SDKManifest> extends Drop {
|
|
10
|
+
private subcontainer;
|
|
9
11
|
private startCommand;
|
|
12
|
+
readonly oneshot: boolean;
|
|
13
|
+
protected onExitSuccessFns: (() => void)[];
|
|
10
14
|
private commandController;
|
|
11
15
|
private shouldBeRunning;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
static of<Manifest extends T.SDKManifest>():
|
|
15
|
-
|
|
16
|
-
sharedRun?: boolean;
|
|
17
|
-
} | SubContainer, command: T.CommandType, options: {
|
|
18
|
-
subcontainerName?: string;
|
|
19
|
-
mounts?: {
|
|
20
|
-
mountpoint: string;
|
|
21
|
-
options: MountOptions;
|
|
22
|
-
}[];
|
|
16
|
+
protected exitedSuccess: boolean;
|
|
17
|
+
protected constructor(subcontainer: SubContainer<Manifest>, startCommand: () => Promise<CommandController<Manifest>>, oneshot?: boolean, onExitSuccessFns?: (() => void)[]);
|
|
18
|
+
static of<Manifest extends T.SDKManifest>(): (effects: T.Effects, subcontainer: SubContainer<Manifest>, command: T.CommandType, options: {
|
|
19
|
+
runAsInit?: boolean;
|
|
23
20
|
env?: {
|
|
24
21
|
[variable: string]: string;
|
|
25
22
|
} | undefined;
|
|
@@ -28,7 +25,7 @@ export declare class Daemon {
|
|
|
28
25
|
onStdout?: (chunk: Buffer | string | any) => void;
|
|
29
26
|
onStderr?: (chunk: Buffer | string | any) => void;
|
|
30
27
|
sigtermTimeout?: number;
|
|
31
|
-
}) => Promise<Daemon
|
|
28
|
+
}) => Promise<Daemon<Manifest>>;
|
|
32
29
|
start(): Promise<void>;
|
|
33
30
|
term(termOptions?: {
|
|
34
31
|
signal?: NodeJS.Signals | undefined;
|
|
@@ -38,4 +35,6 @@ export declare class Daemon {
|
|
|
38
35
|
signal?: NodeJS.Signals | undefined;
|
|
39
36
|
timeout?: number | undefined;
|
|
40
37
|
}): Promise<void>;
|
|
38
|
+
subcontainerRc(): SubContainerRc<Manifest>;
|
|
39
|
+
onDrop(): void;
|
|
41
40
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Daemon = void 0;
|
|
4
4
|
const asError_1 = require("../../../base/lib/util/asError");
|
|
5
|
+
const util_1 = require("../util");
|
|
6
|
+
const SubContainer_1 = require("../util/SubContainer");
|
|
5
7
|
const CommandController_1 = require("./CommandController");
|
|
6
8
|
const TIMEOUT_INCREMENT_MS = 1000;
|
|
7
9
|
const MAX_TIMEOUT_MS = 30000;
|
|
@@ -9,19 +11,23 @@ const MAX_TIMEOUT_MS = 30000;
|
|
|
9
11
|
* This is a wrapper around CommandController that has a state of off, where the command shouldn't be running
|
|
10
12
|
* and the others state of running, where it will keep a living running command
|
|
11
13
|
*/
|
|
12
|
-
class Daemon {
|
|
13
|
-
constructor(startCommand) {
|
|
14
|
+
class Daemon extends util_1.Drop {
|
|
15
|
+
constructor(subcontainer, startCommand, oneshot = false, onExitSuccessFns = []) {
|
|
16
|
+
super();
|
|
17
|
+
this.subcontainer = subcontainer;
|
|
14
18
|
this.startCommand = startCommand;
|
|
19
|
+
this.oneshot = oneshot;
|
|
20
|
+
this.onExitSuccessFns = onExitSuccessFns;
|
|
15
21
|
this.commandController = null;
|
|
16
22
|
this.shouldBeRunning = false;
|
|
17
|
-
|
|
18
|
-
get subContainerHandle() {
|
|
19
|
-
return this.commandController?.subContainerHandle;
|
|
23
|
+
this.exitedSuccess = false;
|
|
20
24
|
}
|
|
21
25
|
static of() {
|
|
22
26
|
return async (effects, subcontainer, command, options) => {
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
if (subcontainer instanceof SubContainer_1.SubContainerOwned)
|
|
28
|
+
subcontainer = subcontainer.rc();
|
|
29
|
+
const startCommand = () => CommandController_1.CommandController.of()(effects, subcontainer.rc(), command, options);
|
|
30
|
+
return new Daemon(subcontainer, startCommand);
|
|
25
31
|
};
|
|
26
32
|
}
|
|
27
33
|
async start() {
|
|
@@ -29,18 +35,37 @@ class Daemon {
|
|
|
29
35
|
return;
|
|
30
36
|
}
|
|
31
37
|
this.shouldBeRunning = true;
|
|
38
|
+
this.exitedSuccess = false;
|
|
32
39
|
let timeoutCounter = 0;
|
|
33
|
-
|
|
40
|
+
(async () => {
|
|
34
41
|
while (this.shouldBeRunning) {
|
|
35
42
|
if (this.commandController)
|
|
36
|
-
await this.commandController
|
|
43
|
+
await this.commandController
|
|
44
|
+
.term({})
|
|
45
|
+
.catch((err) => console.error(err));
|
|
37
46
|
this.commandController = await this.startCommand();
|
|
38
|
-
await this.commandController.wait().
|
|
47
|
+
if ((await this.commandController.wait().then((_) => true, (err) => {
|
|
48
|
+
console.error(err);
|
|
49
|
+
return false;
|
|
50
|
+
})) &&
|
|
51
|
+
this.oneshot) {
|
|
52
|
+
for (const fn of this.onExitSuccessFns) {
|
|
53
|
+
try {
|
|
54
|
+
fn();
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.error("EXIT_SUCCESS handler", e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
this.onExitSuccessFns = [];
|
|
61
|
+
this.exitedSuccess = true;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
39
64
|
await new Promise((resolve) => setTimeout(resolve, timeoutCounter));
|
|
40
65
|
timeoutCounter += TIMEOUT_INCREMENT_MS;
|
|
41
|
-
timeoutCounter = Math.
|
|
66
|
+
timeoutCounter = Math.min(MAX_TIMEOUT_MS, timeoutCounter);
|
|
42
67
|
}
|
|
43
|
-
}).catch((err) => {
|
|
68
|
+
})().catch((err) => {
|
|
44
69
|
console.error((0, asError_1.asError)(err));
|
|
45
70
|
});
|
|
46
71
|
}
|
|
@@ -53,6 +78,13 @@ class Daemon {
|
|
|
53
78
|
?.term({ ...termOptions })
|
|
54
79
|
.catch((e) => console.error((0, asError_1.asError)(e)));
|
|
55
80
|
this.commandController = null;
|
|
81
|
+
await this.subcontainer.destroy();
|
|
82
|
+
}
|
|
83
|
+
subcontainerRc() {
|
|
84
|
+
return this.subcontainer.rc();
|
|
85
|
+
}
|
|
86
|
+
onDrop() {
|
|
87
|
+
this.stop().catch((e) => console.error((0, asError_1.asError)(e)));
|
|
56
88
|
}
|
|
57
89
|
}
|
|
58
90
|
exports.Daemon = Daemon;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Daemon.js","sourceRoot":"","sources":["../../../../package/lib/mainFn/Daemon.ts"],"names":[],"mappings":";;;AACA,4DAAwD;
|
|
1
|
+
{"version":3,"file":"Daemon.js","sourceRoot":"","sources":["../../../../package/lib/mainFn/Daemon.ts"],"names":[],"mappings":";;;AACA,4DAAwD;AACxD,kCAA8B;AAC9B,uDAI6B;AAC7B,2DAAuD;AAEvD,MAAM,oBAAoB,GAAG,IAAI,CAAA;AACjC,MAAM,cAAc,GAAG,KAAK,CAAA;AAC5B;;;GAGG;AAEH,MAAa,MAAuC,SAAQ,WAAI;IAI9D,YACU,YAAoC,EACpC,YAAwD,EACvD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e,GAAG,KAAK,CAAA;QAC5B,MAAM,IAAI,CAAC,iBAAiB;YAC1B,EAAE,IAAI,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC;aACzB,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAA,iBAAO,EAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC1C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAA;QAC7B,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAA;IACnC,CAAC;IACD,cAAc;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,CAAA;IAC/B,CAAC;IACD,MAAM;QACJ,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAA,iBAAO,EAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACrD,CAAC;CACF;AA7GD,wBA6GC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { HealthCheckResult } from "../health/checkFns";
|
|
2
2
|
import { Trigger } from "../trigger";
|
|
3
3
|
import * as T from "../../../base/lib/types";
|
|
4
|
-
import {
|
|
5
|
-
import { ExecSpawnable, MountOptions, SubContainer } from "../util/SubContainer";
|
|
4
|
+
import { SubContainer } from "../util/SubContainer";
|
|
6
5
|
import * as CP from "node:child_process";
|
|
7
6
|
export { Daemon } from "./Daemon";
|
|
8
7
|
export { CommandController } from "./CommandController";
|
|
@@ -10,6 +9,7 @@ import { HealthDaemon } from "./HealthDaemon";
|
|
|
10
9
|
import { Daemon } from "./Daemon";
|
|
11
10
|
import { CommandController } from "./CommandController";
|
|
12
11
|
import { HealthCheck } from "../health/HealthCheck";
|
|
12
|
+
import { Manifest } from "../test/output.sdk";
|
|
13
13
|
export declare const cpExec: typeof CP.exec.__promisify__;
|
|
14
14
|
export declare const cpExecFile: typeof CP.execFile.__promisify__;
|
|
15
15
|
export type Ready = {
|
|
@@ -29,7 +29,7 @@ export type Ready = {
|
|
|
29
29
|
})
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
fn: (
|
|
32
|
+
fn: (subcontainer: SubContainer<Manifest>) => Promise<HealthCheckResult> | HealthCheckResult;
|
|
33
33
|
/**
|
|
34
34
|
* A duration in milliseconds to treat a failing health check as "starting"
|
|
35
35
|
*
|
|
@@ -38,40 +38,33 @@ export type Ready = {
|
|
|
38
38
|
gracePeriod?: number;
|
|
39
39
|
trigger?: Trigger;
|
|
40
40
|
};
|
|
41
|
-
type
|
|
41
|
+
type NewDaemonParams<Manifest extends T.SDKManifest> = {
|
|
42
42
|
/** The command line command to start the daemon */
|
|
43
43
|
command: T.CommandType;
|
|
44
44
|
/** Information about the subcontainer in which the daemon runs */
|
|
45
|
-
subcontainer:
|
|
46
|
-
|
|
47
|
-
imageId: keyof Manifest["images"] & T.ImageId;
|
|
48
|
-
/**
|
|
49
|
-
* Whether or not to share the `/run` directory with the parent container.
|
|
50
|
-
* This is useful if you are trying to connect to a service that exposes a unix domain socket or auth cookie via the `/run` directory
|
|
51
|
-
*/
|
|
52
|
-
sharedRun?: boolean;
|
|
53
|
-
} | SubContainer;
|
|
54
|
-
/** For mounting the necessary volumes. Syntax: sdk.Mounts.of().addVolume() */
|
|
55
|
-
mounts: Mounts<Manifest>;
|
|
45
|
+
subcontainer: SubContainer<Manifest>;
|
|
46
|
+
runAsInit?: boolean;
|
|
56
47
|
env?: Record<string, string>;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
requires: Exclude<Ids, Id>[];
|
|
48
|
+
cwd?: string;
|
|
49
|
+
user?: string;
|
|
60
50
|
sigtermTimeout?: number;
|
|
61
51
|
onStdout?: (chunk: Buffer | string | any) => void;
|
|
62
52
|
onStderr?: (chunk: Buffer | string | any) => void;
|
|
63
53
|
};
|
|
54
|
+
type AddDaemonParams<Manifest extends T.SDKManifest, Ids extends string, Id extends string> = (NewDaemonParams<Manifest> | {
|
|
55
|
+
daemon: Daemon<Manifest>;
|
|
56
|
+
}) & {
|
|
57
|
+
ready: Ready;
|
|
58
|
+
/** An array of IDs of prior daemons whose successful initializations are required before this daemon will initialize */
|
|
59
|
+
requires: Exclude<Ids, Id>[];
|
|
60
|
+
};
|
|
61
|
+
type AddOneshotParams<Manifest extends T.SDKManifest, Ids extends string, Id extends string> = NewDaemonParams<Manifest> & {
|
|
62
|
+
/** An array of IDs of prior daemons whose successful initializations are required before this daemon will initialize */
|
|
63
|
+
requires: Exclude<Ids, Id>[];
|
|
64
|
+
};
|
|
64
65
|
type ErrorDuplicateId<Id extends string> = `The id '${Id}' is already used`;
|
|
65
|
-
export declare const runCommand: <Manifest extends T.SDKManifest>() =>
|
|
66
|
-
imageId: keyof Manifest["images"] & string;
|
|
67
|
-
sharedRun?: boolean;
|
|
68
|
-
}, command: T.CommandType, options: {
|
|
69
|
-
subcontainerName?: string;
|
|
66
|
+
export declare const runCommand: <Manifest extends T.SDKManifest>() => (effects: T.Effects, subcontainer: SubContainer<Manifest, T.Effects>, command: T.CommandType, options: {
|
|
70
67
|
sigtermTimeout?: number;
|
|
71
|
-
mounts?: {
|
|
72
|
-
mountpoint: string;
|
|
73
|
-
options: MountOptions;
|
|
74
|
-
}[] | undefined;
|
|
75
68
|
runAsInit?: boolean;
|
|
76
69
|
env?: {
|
|
77
70
|
[variable: string]: string;
|
|
@@ -80,7 +73,7 @@ export declare const runCommand: <Manifest extends T.SDKManifest>() => <A extend
|
|
|
80
73
|
user?: string | undefined;
|
|
81
74
|
onStdout?: ((chunk: Buffer | string | any) => void) | undefined;
|
|
82
75
|
onStderr?: ((chunk: Buffer | string | any) => void) | undefined;
|
|
83
|
-
}) => Promise<CommandController
|
|
76
|
+
}) => Promise<CommandController<Manifest>>;
|
|
84
77
|
/**
|
|
85
78
|
* A class for defining and controlling the service daemons
|
|
86
79
|
```ts
|
|
@@ -107,9 +100,9 @@ Daemons.of({
|
|
|
107
100
|
export declare class Daemons<Manifest extends T.SDKManifest, Ids extends string> implements T.DaemonBuildable {
|
|
108
101
|
readonly effects: T.Effects;
|
|
109
102
|
readonly started: (onTerm: () => PromiseLike<void>) => PromiseLike<null>;
|
|
110
|
-
readonly daemons: Promise<Daemon
|
|
103
|
+
readonly daemons: Promise<Daemon<Manifest>>[];
|
|
111
104
|
readonly ids: Ids[];
|
|
112
|
-
readonly healthDaemons: HealthDaemon[];
|
|
105
|
+
readonly healthDaemons: HealthDaemon<Manifest>[];
|
|
113
106
|
readonly healthChecks: HealthCheck[];
|
|
114
107
|
private constructor();
|
|
115
108
|
/**
|
|
@@ -130,10 +123,18 @@ export declare class Daemons<Manifest extends T.SDKManifest, Ids extends string>
|
|
|
130
123
|
/**
|
|
131
124
|
* Returns the complete list of daemons, including the one defined here
|
|
132
125
|
* @param id
|
|
133
|
-
* @param
|
|
134
|
-
* @returns
|
|
126
|
+
* @param options
|
|
127
|
+
* @returns a new Daemons object
|
|
128
|
+
*/
|
|
129
|
+
addDaemon<Id extends string>(id: "" extends Id ? never : ErrorDuplicateId<Id> extends Id ? never : Id extends Ids ? ErrorDuplicateId<Id> : Id, options: AddDaemonParams<Manifest, Ids, Id>): Daemons<Manifest, Ids | Id>;
|
|
130
|
+
/**
|
|
131
|
+
* Returns the complete list of daemons, including a "oneshot" daemon one defined here
|
|
132
|
+
* a oneshot daemon is a command that executes once when started, and is considered "running" once it exits successfully
|
|
133
|
+
* @param id
|
|
134
|
+
* @param options
|
|
135
|
+
* @returns a new Daemons object
|
|
135
136
|
*/
|
|
136
|
-
|
|
137
|
+
addOneshot<Id extends string>(id: "" extends Id ? never : ErrorDuplicateId<Id> extends Id ? never : Id extends Ids ? ErrorDuplicateId<Id> : Id, options: AddOneshotParams<Manifest, Ids, Id>): Daemons<Manifest, Ids | Id>;
|
|
137
138
|
term(): Promise<void>;
|
|
138
139
|
build(): Promise<this>;
|
|
139
140
|
}
|
|
@@ -43,6 +43,7 @@ Object.defineProperty(exports, "CommandController", { enumerable: true, get: fun
|
|
|
43
43
|
const HealthDaemon_1 = require("./HealthDaemon");
|
|
44
44
|
const Daemon_2 = require("./Daemon");
|
|
45
45
|
const CommandController_2 = require("./CommandController");
|
|
46
|
+
const Oneshot_1 = require("./Oneshot");
|
|
46
47
|
exports.cpExec = (0, node_util_1.promisify)(CP.exec);
|
|
47
48
|
exports.cpExecFile = (0, node_util_1.promisify)(CP.execFile);
|
|
48
49
|
const runCommand = () => CommandController_2.CommandController.of();
|
|
@@ -95,22 +96,41 @@ class Daemons {
|
|
|
95
96
|
/**
|
|
96
97
|
* Returns the complete list of daemons, including the one defined here
|
|
97
98
|
* @param id
|
|
98
|
-
* @param
|
|
99
|
-
* @returns
|
|
99
|
+
* @param options
|
|
100
|
+
* @returns a new Daemons object
|
|
100
101
|
*/
|
|
101
102
|
addDaemon(
|
|
102
103
|
// prettier-ignore
|
|
103
104
|
id, options) {
|
|
104
|
-
const
|
|
105
|
-
|
|
105
|
+
const daemon = "daemon" in options
|
|
106
|
+
? Promise.resolve(options.daemon)
|
|
107
|
+
: Daemon_2.Daemon.of()(this.effects, options.subcontainer, options.command, {
|
|
108
|
+
...options,
|
|
109
|
+
});
|
|
110
|
+
const healthDaemon = new HealthDaemon_1.HealthDaemon(daemon, options.requires
|
|
111
|
+
.map((x) => this.ids.indexOf(x))
|
|
112
|
+
.filter((x) => x >= 0)
|
|
113
|
+
.map((id) => this.healthDaemons[id]), id, this.ids, options.ready, this.effects);
|
|
114
|
+
const daemons = this.daemons.concat(daemon);
|
|
115
|
+
const ids = [...this.ids, id];
|
|
116
|
+
const healthDaemons = [...this.healthDaemons, healthDaemon];
|
|
117
|
+
return new Daemons(this.effects, this.started, daemons, ids, healthDaemons, this.healthChecks);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the complete list of daemons, including a "oneshot" daemon one defined here
|
|
121
|
+
* a oneshot daemon is a command that executes once when started, and is considered "running" once it exits successfully
|
|
122
|
+
* @param id
|
|
123
|
+
* @param options
|
|
124
|
+
* @returns a new Daemons object
|
|
125
|
+
*/
|
|
126
|
+
addOneshot(id, options) {
|
|
127
|
+
const daemon = Oneshot_1.Oneshot.of()(this.effects, options.subcontainer, options.command, {
|
|
106
128
|
...options,
|
|
107
|
-
mounts: options.mounts.build(),
|
|
108
|
-
subcontainerName: id,
|
|
109
129
|
});
|
|
110
|
-
const healthDaemon = new HealthDaemon_1.HealthDaemon(daemon,
|
|
130
|
+
const healthDaemon = new HealthDaemon_1.HealthDaemon(daemon, options.requires
|
|
111
131
|
.map((x) => this.ids.indexOf(x))
|
|
112
132
|
.filter((x) => x >= 0)
|
|
113
|
-
.map((id) => this.healthDaemons[id]), id, this.ids,
|
|
133
|
+
.map((id) => this.healthDaemons[id]), id, this.ids, "EXIT_SUCCESS", this.effects);
|
|
114
134
|
const daemons = this.daemons.concat(daemon);
|
|
115
135
|
const ids = [...this.ids, id];
|
|
116
136
|
const healthDaemons = [...this.healthDaemons, healthDaemon];
|
|
@@ -119,7 +139,7 @@ class Daemons {
|
|
|
119
139
|
async term() {
|
|
120
140
|
try {
|
|
121
141
|
this.healthChecks.forEach((health) => health.stop());
|
|
122
|
-
for (let result of await Promise.allSettled(this.healthDaemons.map((x) => x.term(
|
|
142
|
+
for (let result of await Promise.allSettled(this.healthDaemons.map((x) => x.term()))) {
|
|
123
143
|
if (result.status === "rejected") {
|
|
124
144
|
console.error(result.reason);
|
|
125
145
|
}
|
|
@@ -131,7 +151,7 @@ class Daemons {
|
|
|
131
151
|
}
|
|
132
152
|
async build() {
|
|
133
153
|
for (const daemon of this.healthDaemons) {
|
|
134
|
-
await daemon.
|
|
154
|
+
await daemon.init();
|
|
135
155
|
}
|
|
136
156
|
for (const health of this.healthChecks) {
|
|
137
157
|
health.start();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Daemons.js","sourceRoot":"","sources":["../../../../package/lib/mainFn/Daemons.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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