@powersync/lib-services-framework 0.0.0-dev-20250611110033 → 0.0.0-dev-20250618131818
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.
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* A System can contain anything but should offer a `start` and `stop` operation
|
|
7
7
|
*/
|
|
8
|
+
import { ServiceError } from '@powersync/service-errors';
|
|
8
9
|
export type LifecycleCallback<T> = (singleton: T) => Promise<void> | void;
|
|
9
10
|
export type PartialLifecycle<T> = {
|
|
10
11
|
start?: LifecycleCallback<T>;
|
|
@@ -20,4 +21,5 @@ export declare class LifeCycledSystem {
|
|
|
20
21
|
withLifecycle: <T>(component: T, lifecycle: PartialLifecycle<T>) => T;
|
|
21
22
|
start: () => Promise<void>;
|
|
22
23
|
stop: () => Promise<void>;
|
|
24
|
+
stopWithError: (error: ServiceError) => Promise<never>;
|
|
23
25
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* A System can contain anything but should offer a `start` and `stop` operation
|
|
7
7
|
*/
|
|
8
8
|
import { container } from '../container.js';
|
|
9
|
+
import { logger } from '../logger/Logger.js';
|
|
9
10
|
export class LifeCycledSystem {
|
|
10
11
|
components = [];
|
|
11
12
|
constructor() {
|
|
@@ -28,5 +29,19 @@ export class LifeCycledSystem {
|
|
|
28
29
|
await lifecycle.stop?.(lifecycle.component);
|
|
29
30
|
}
|
|
30
31
|
};
|
|
32
|
+
stopWithError = async (error) => {
|
|
33
|
+
try {
|
|
34
|
+
logger.error('Stopping process due to fatal error', error);
|
|
35
|
+
await this.stop();
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
logger.error('Error while stopping', e);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
// Custom error code to distinguish from other common errors
|
|
42
|
+
logger.warn(`Exiting with code 151`);
|
|
43
|
+
process.exit(151);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
31
46
|
}
|
|
32
47
|
//# sourceMappingURL=LifeCycledSystem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LifeCycledSystem.js","sourceRoot":"","sources":["../../src/system/LifeCycledSystem.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"LifeCycledSystem.js","sourceRoot":"","sources":["../../src/system/LifeCycledSystem.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAc7C,MAAM,OAAO,gBAAgB;IAC3B,UAAU,GAA8B,EAAE,CAAC;IAE3C;QACE,SAAS,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,aAAa,GAAG,CAAI,SAAY,EAAE,SAA8B,EAAK,EAAE;QACrE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACnB,SAAS,EAAE,SAAS;YACpB,GAAG,SAAS;SACb,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,KAAK,GAAG,KAAK,IAAI,EAAE;QACjB,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACxC,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC;IAEF,IAAI,GAAG,KAAK,IAAI,EAAE;QAChB,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;YAClD,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC,CAAC;IAEF,aAAa,GAAG,KAAK,EAAE,KAAmB,EAAE,EAAE;QAC5C,IAAI,CAAC;YACH,MAAM,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;YAC3D,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC;QAC1C,CAAC;gBAAS,CAAC;YACT,4DAA4D;YAC5D,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,CAAC;CACH"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/lib-services-framework",
|
|
3
3
|
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-20250618131818",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"uuid": "^11.1.0",
|
|
25
25
|
"winston": "^3.13.0",
|
|
26
26
|
"zod": "^3.23.8",
|
|
27
|
-
"@powersync/service-errors": "0.0.0-dev-
|
|
27
|
+
"@powersync/service-errors": "0.0.0-dev-20250618131818"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/lodash": "^4.17.5",
|