@ocap/resolver 1.30.21 → 1.30.23

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/esm/api.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { TIndexedTokenState } from "./types.mjs";
1
+ import { TIndexedTokenState as TIndexedTokenState$1 } from "./types.mjs";
2
2
  import { Router } from "express";
3
+ import { ILedger } from "@ocap/types";
3
4
 
4
5
  //#region src/api.d.ts
5
6
 
@@ -9,7 +10,8 @@ import { Router } from "express";
9
10
  interface IAPIResolver {
10
11
  getTokenState(params: {
11
12
  address: string;
12
- }): Promise<TIndexedTokenState | null>;
13
+ }): Promise<TIndexedTokenState$1 | null>;
14
+ ledger: ILedger;
13
15
  }
14
16
  /**
15
17
  * Parameters for createAPIHandler
package/esm/api.mjs CHANGED
@@ -46,6 +46,68 @@ function createAPIHandler({ resolver }) {
46
46
  res.setHeader("Content-Type", "image/svg+xml");
47
47
  res.send(svg);
48
48
  });
49
+ router.get("/health/ledger", async (_req, res) => {
50
+ try {
51
+ const health = await resolver.ledger.getHealth();
52
+ const lagThreshold = Number(process.env.LEDGER_HEALTH_LAG_THRESHOLD) || 1e3;
53
+ const ageThresholdMs = Number(process.env.LEDGER_HEALTH_AGE_THRESHOLD_MS) || 36e5;
54
+ const unfinalizedAgeThresholdMs = Number(process.env.LEDGER_HEALTH_UNFINALIZED_AGE_THRESHOLD_MS) || 3e5;
55
+ const now = Date.now();
56
+ const oldestUnfinalizedAgeMs = health.oldestUnfinalizedTimestamp ? now - health.oldestUnfinalizedTimestamp : null;
57
+ const lagViolation = health.checkpointLag > lagThreshold;
58
+ const ageViolation = lagViolation && health.checkpointAgeMs != null && health.checkpointAgeMs > ageThresholdMs;
59
+ const unfinalizedViolation = oldestUnfinalizedAgeMs != null && oldestUnfinalizedAgeMs > unfinalizedAgeThresholdMs;
60
+ const healthy = !lagViolation && !ageViolation && !unfinalizedViolation;
61
+ const formatDuration = (ms) => {
62
+ if (ms == null) return null;
63
+ const s = Math.floor(ms / 1e3);
64
+ const d = Math.floor(s / 86400);
65
+ const h = Math.floor(s % 86400 / 3600);
66
+ const m = Math.floor(s % 3600 / 60);
67
+ const sec = s % 60;
68
+ const parts = [];
69
+ if (d) parts.push(`${d}d`);
70
+ if (h) parts.push(`${h}h`);
71
+ if (m) parts.push(`${m}m`);
72
+ if (sec || parts.length === 0) parts.push(`${sec}s`);
73
+ return parts.join(" ");
74
+ };
75
+ const toIso = (ts) => ts ? new Date(ts).toISOString() : null;
76
+ res.json({
77
+ healthy,
78
+ latestSequence: health.latestSequence,
79
+ latestCheckpoint: health.latestCheckpoint ? {
80
+ ...health.latestCheckpoint,
81
+ timestampIso: toIso(health.latestCheckpoint.timestamp)
82
+ } : null,
83
+ checkpointLag: health.checkpointLag,
84
+ checkpointAgeMs: health.checkpointAgeMs,
85
+ checkpointAge: formatDuration(health.checkpointAgeMs),
86
+ unfinalizedCount: health.unfinalizedCount,
87
+ oldestUnfinalizedTimestamp: health.oldestUnfinalizedTimestamp,
88
+ oldestUnfinalizedTimestampIso: toIso(health.oldestUnfinalizedTimestamp),
89
+ oldestUnfinalizedAgeMs,
90
+ oldestUnfinalizedAge: formatDuration(oldestUnfinalizedAgeMs),
91
+ nowIso: new Date(now).toISOString(),
92
+ violations: {
93
+ lag: lagViolation,
94
+ age: ageViolation,
95
+ unfinalized: unfinalizedViolation
96
+ },
97
+ thresholds: {
98
+ checkpointLag: lagThreshold,
99
+ checkpointAgeMs: ageThresholdMs,
100
+ unfinalizedAgeMs: unfinalizedAgeThresholdMs
101
+ }
102
+ });
103
+ } catch (error) {
104
+ const message = error instanceof Error ? error.message : String(error);
105
+ res.status(500).json({
106
+ healthy: false,
107
+ error: message
108
+ });
109
+ }
110
+ });
49
111
  return router;
50
112
  }
51
113
 
package/lib/api.cjs CHANGED
@@ -47,6 +47,68 @@ function createAPIHandler({ resolver }) {
47
47
  res.setHeader("Content-Type", "image/svg+xml");
48
48
  res.send(svg);
49
49
  });
50
+ router.get("/health/ledger", async (_req, res) => {
51
+ try {
52
+ const health = await resolver.ledger.getHealth();
53
+ const lagThreshold = Number(process.env.LEDGER_HEALTH_LAG_THRESHOLD) || 1e3;
54
+ const ageThresholdMs = Number(process.env.LEDGER_HEALTH_AGE_THRESHOLD_MS) || 36e5;
55
+ const unfinalizedAgeThresholdMs = Number(process.env.LEDGER_HEALTH_UNFINALIZED_AGE_THRESHOLD_MS) || 3e5;
56
+ const now = Date.now();
57
+ const oldestUnfinalizedAgeMs = health.oldestUnfinalizedTimestamp ? now - health.oldestUnfinalizedTimestamp : null;
58
+ const lagViolation = health.checkpointLag > lagThreshold;
59
+ const ageViolation = lagViolation && health.checkpointAgeMs != null && health.checkpointAgeMs > ageThresholdMs;
60
+ const unfinalizedViolation = oldestUnfinalizedAgeMs != null && oldestUnfinalizedAgeMs > unfinalizedAgeThresholdMs;
61
+ const healthy = !lagViolation && !ageViolation && !unfinalizedViolation;
62
+ const formatDuration = (ms) => {
63
+ if (ms == null) return null;
64
+ const s = Math.floor(ms / 1e3);
65
+ const d = Math.floor(s / 86400);
66
+ const h = Math.floor(s % 86400 / 3600);
67
+ const m = Math.floor(s % 3600 / 60);
68
+ const sec = s % 60;
69
+ const parts = [];
70
+ if (d) parts.push(`${d}d`);
71
+ if (h) parts.push(`${h}h`);
72
+ if (m) parts.push(`${m}m`);
73
+ if (sec || parts.length === 0) parts.push(`${sec}s`);
74
+ return parts.join(" ");
75
+ };
76
+ const toIso = (ts) => ts ? new Date(ts).toISOString() : null;
77
+ res.json({
78
+ healthy,
79
+ latestSequence: health.latestSequence,
80
+ latestCheckpoint: health.latestCheckpoint ? {
81
+ ...health.latestCheckpoint,
82
+ timestampIso: toIso(health.latestCheckpoint.timestamp)
83
+ } : null,
84
+ checkpointLag: health.checkpointLag,
85
+ checkpointAgeMs: health.checkpointAgeMs,
86
+ checkpointAge: formatDuration(health.checkpointAgeMs),
87
+ unfinalizedCount: health.unfinalizedCount,
88
+ oldestUnfinalizedTimestamp: health.oldestUnfinalizedTimestamp,
89
+ oldestUnfinalizedTimestampIso: toIso(health.oldestUnfinalizedTimestamp),
90
+ oldestUnfinalizedAgeMs,
91
+ oldestUnfinalizedAge: formatDuration(oldestUnfinalizedAgeMs),
92
+ nowIso: new Date(now).toISOString(),
93
+ violations: {
94
+ lag: lagViolation,
95
+ age: ageViolation,
96
+ unfinalized: unfinalizedViolation
97
+ },
98
+ thresholds: {
99
+ checkpointLag: lagThreshold,
100
+ checkpointAgeMs: ageThresholdMs,
101
+ unfinalizedAgeMs: unfinalizedAgeThresholdMs
102
+ }
103
+ });
104
+ } catch (error) {
105
+ const message = error instanceof Error ? error.message : String(error);
106
+ res.status(500).json({
107
+ healthy: false,
108
+ error: message
109
+ });
110
+ }
111
+ });
50
112
  return router;
51
113
  }
52
114
 
package/lib/api.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { TIndexedTokenState } from "./types.cjs";
1
+ import { TIndexedTokenState as TIndexedTokenState$1 } from "./types.cjs";
2
+ import { ILedger } from "@ocap/types";
2
3
  import { Router } from "express";
3
4
 
4
5
  //#region src/api.d.ts
@@ -9,7 +10,8 @@ import { Router } from "express";
9
10
  interface IAPIResolver {
10
11
  getTokenState(params: {
11
12
  address: string;
12
- }): Promise<TIndexedTokenState | null>;
13
+ }): Promise<TIndexedTokenState$1 | null>;
14
+ ledger: ILedger;
13
15
  }
14
16
  /**
15
17
  * Parameters for createAPIHandler
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.30.21",
6
+ "version": "1.30.23",
7
7
  "description": "GraphQL resolver built upon ocap statedb and GQL layer",
8
8
  "type": "module",
9
9
  "main": "./lib/index.cjs",
@@ -49,20 +49,20 @@
49
49
  "tsdown": "^0.18.4"
50
50
  },
51
51
  "dependencies": {
52
- "@arcblock/did": "1.30.21",
53
- "@arcblock/did-ext": "1.30.21",
54
- "@arcblock/did-util": "1.30.21",
52
+ "@arcblock/did": "1.30.23",
53
+ "@arcblock/did-ext": "1.30.23",
54
+ "@arcblock/did-util": "1.30.23",
55
55
  "@arcblock/nft-display": "^3.2.3",
56
- "@arcblock/validator": "1.30.21",
57
- "@ocap/config": "1.30.21",
58
- "@ocap/indexdb": "1.30.21",
59
- "@ocap/mcrypto": "1.30.21",
60
- "@ocap/message": "1.30.21",
61
- "@ocap/state": "1.30.21",
62
- "@ocap/tx-protocols": "1.30.21",
63
- "@ocap/types": "1.30.21",
64
- "@ocap/util": "1.30.21",
65
- "@ocap/wallet": "1.30.21",
56
+ "@arcblock/validator": "1.30.23",
57
+ "@ocap/config": "1.30.23",
58
+ "@ocap/indexdb": "1.30.23",
59
+ "@ocap/mcrypto": "1.30.23",
60
+ "@ocap/message": "1.30.23",
61
+ "@ocap/state": "1.30.23",
62
+ "@ocap/tx-protocols": "1.30.23",
63
+ "@ocap/types": "1.30.23",
64
+ "@ocap/util": "1.30.23",
65
+ "@ocap/wallet": "1.30.23",
66
66
  "debug": "^4.4.3",
67
67
  "express": "^4.22.1",
68
68
  "lodash": "^4.17.23",