@helyx/core 0.1.20 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.21
4
+
5
+ ### Patch Changes
6
+
7
+ - Harden startup cleanup, lease ownership, database transaction handling, worker shutdown, and stale-work fencing across the hosted and self-hosted runtime.
8
+
3
9
  ## 0.1.20
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,8 @@
1
+ export type AsyncCleanup = () => void | Promise<void>;
2
+ export declare class AsyncCleanupStack {
3
+ #private;
4
+ defer(cleanup: AsyncCleanup): void;
5
+ close(): Promise<void>;
6
+ fail(cause: unknown): Promise<never>;
7
+ }
8
+ //# sourceMappingURL=async-cleanup-stack.d.ts.map
@@ -0,0 +1,41 @@
1
+ export class AsyncCleanupStack {
2
+ #cleanups = [];
3
+ #closing;
4
+ defer(cleanup) {
5
+ if (this.#closing)
6
+ throw new Error("Cannot register cleanup after shutdown has started");
7
+ this.#cleanups.push(cleanup);
8
+ }
9
+ close() {
10
+ if (this.#closing)
11
+ return this.#closing;
12
+ this.#closing = this.#drain();
13
+ return this.#closing;
14
+ }
15
+ async fail(cause) {
16
+ try {
17
+ await this.close();
18
+ }
19
+ catch (cleanupError) {
20
+ throw new AggregateError([cause, cleanupError], "Startup and cleanup both failed", { cause: cleanupError });
21
+ }
22
+ throw cause;
23
+ }
24
+ async #drain() {
25
+ const failures = [];
26
+ for (const cleanup of this.#cleanups.reverse()) {
27
+ try {
28
+ await cleanup();
29
+ }
30
+ catch (error) {
31
+ failures.push(error);
32
+ }
33
+ }
34
+ this.#cleanups.length = 0;
35
+ if (failures.length === 1)
36
+ throw failures[0];
37
+ if (failures.length > 1)
38
+ throw new AggregateError(failures, "Multiple runtime cleanups failed");
39
+ }
40
+ }
41
+ //# sourceMappingURL=async-cleanup-stack.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { HealthResult, Logger, ModuleDefinition, ModulePermissionConfiguration, PermissionActor, GuildAccessPolicy, HelyxAccessLevel, PermissionPolicy, ServiceAccess } from "@helyx/sdk";
2
+ export * from "./async-cleanup-stack.js";
2
3
  export type RuntimeState = "created" | "starting" | "running" | "stopping" | "stopped" | "failed";
3
4
  export interface ModuleHealth {
4
5
  id: string;
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { orderModuleManifests, parseModuleManifest, } from "@helyx/module-manifest";
2
+ export * from "./async-cleanup-stack.js";
2
3
  export class ServiceRegistry {
3
4
  #services;
4
5
  constructor(services = new Map()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helyx/core",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "Module lifecycle and runtime registry for Helyx.",
5
5
  "keywords": [
6
6
  "helyx",