@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51

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.
Files changed (239) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +99 -51
  2. package/@cds-models/CardanoAgentService/index.js +15 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +358 -0
  4. package/@cds-models/CardanoBackendService/index.js +41 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
  6. package/@cds-models/CardanoIndexerService/index.js +74 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +417 -57
  8. package/@cds-models/CardanoODataService/index.js +42 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +45 -19
  10. package/@cds-models/CardanoSignService/index.js +4 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
  12. package/@cds-models/CardanoTransactionService/index.js +5 -0
  13. package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
  14. package/@cds-models/CardanoWorkerService/index.js +2 -0
  15. package/@cds-models/index.d.ts +114 -4
  16. package/@cds-models/index.js +20 -4
  17. package/@cds-models/odatano/cardano/index.d.ts +451 -32
  18. package/@cds-models/odatano/cardano/index.js +48 -0
  19. package/README.md +103 -167
  20. package/db/schema.cds +2455 -1705
  21. package/db/types.cds +456 -295
  22. package/package.json +41 -53
  23. package/scripts/deploy-schema.mjs +113 -0
  24. package/scripts/migrate-schema.mjs +528 -0
  25. package/scripts/migrate-slot-leader.mjs +96 -0
  26. package/src/index.d.ts +20 -21
  27. package/src/index.js +45 -31
  28. package/src/plugin.js +17 -35
  29. package/srv/blockchain/asset-decimals.d.ts +7 -0
  30. package/srv/blockchain/asset-decimals.js +91 -0
  31. package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
  32. package/srv/blockchain/backends/blockfrost-backend.js +125 -215
  33. package/srv/blockchain/backends/call-signal.d.ts +7 -0
  34. package/srv/blockchain/backends/call-signal.js +22 -0
  35. package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
  36. package/srv/blockchain/backends/cardano-backend.js +29 -5
  37. package/srv/blockchain/backends/koios-backend.d.ts +108 -170
  38. package/srv/blockchain/backends/koios-backend.js +488 -482
  39. package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
  40. package/srv/blockchain/backends/odatano-backend.js +211 -0
  41. package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
  42. package/srv/blockchain/backends/ogmios-backend.js +683 -327
  43. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
  44. package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
  45. package/srv/blockchain/cardano-client.d.ts +71 -241
  46. package/srv/blockchain/cardano-client.js +354 -322
  47. package/srv/blockchain/cardano-indexer.d.ts +295 -283
  48. package/srv/blockchain/cardano-indexer.js +1690 -502
  49. package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
  50. package/srv/blockchain/cardano-tx-builder.js +164 -140
  51. package/srv/blockchain/circuit-breaker.d.ts +2 -13
  52. package/srv/blockchain/circuit-breaker.js +11 -15
  53. package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
  54. package/srv/blockchain/crawler/account-snapshots.js +173 -0
  55. package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
  56. package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
  57. package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
  58. package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
  59. package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
  60. package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
  61. package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
  62. package/srv/blockchain/crawler/certificate-backfill.js +174 -0
  63. package/srv/blockchain/crawler/crawler.d.ts +125 -81
  64. package/srv/blockchain/crawler/crawler.js +738 -167
  65. package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
  66. package/srv/blockchain/crawler/credential-backfill.js +101 -0
  67. package/srv/blockchain/crawler/hooks.d.ts +2 -17
  68. package/srv/blockchain/crawler/index.d.ts +1 -8
  69. package/srv/blockchain/crawler/index.js +31 -17
  70. package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
  71. package/srv/blockchain/crawler/input-asset-copies.js +161 -0
  72. package/srv/blockchain/crawler/key-pages.d.ts +12 -0
  73. package/srv/blockchain/crawler/key-pages.js +48 -0
  74. package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
  75. package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
  76. package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
  77. package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
  78. package/srv/blockchain/crawler/sync-state.d.ts +31 -47
  79. package/srv/blockchain/crawler/sync-state.js +135 -128
  80. package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
  81. package/srv/blockchain/crawler/transaction-backfill.js +271 -0
  82. package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
  83. package/srv/blockchain/crawler/utxo-set-import.js +399 -0
  84. package/srv/blockchain/crawler/window-plan.d.ts +31 -0
  85. package/srv/blockchain/crawler/window-plan.js +59 -0
  86. package/srv/blockchain/ledger-state.d.ts +62 -0
  87. package/srv/blockchain/ledger-state.js +521 -0
  88. package/srv/blockchain/pending-spends.d.ts +16 -0
  89. package/srv/blockchain/pending-spends.js +81 -0
  90. package/srv/blockchain/pool-metadata.d.ts +15 -0
  91. package/srv/blockchain/pool-metadata.js +132 -0
  92. package/srv/blockchain/request-coalescer.d.ts +2 -16
  93. package/srv/blockchain/request-coalescer.js +2 -16
  94. package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
  95. package/srv/blockchain/signing/cose-verifier.js +146 -70
  96. package/srv/blockchain/signing/external-signer.d.ts +15 -115
  97. package/srv/blockchain/signing/external-signer.js +22 -131
  98. package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
  99. package/srv/blockchain/signing/failed-recheck.js +135 -0
  100. package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
  101. package/srv/blockchain/signing/hsm-signer.js +28 -79
  102. package/srv/blockchain/signing/landing-proof.d.ts +60 -0
  103. package/srv/blockchain/signing/landing-proof.js +224 -0
  104. package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
  105. package/srv/blockchain/signing/signature-verifier.js +71 -87
  106. package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
  107. package/srv/blockchain/signing/submission-finalizer.js +280 -86
  108. package/srv/blockchain/stored-chain.d.ts +19 -0
  109. package/srv/blockchain/stored-chain.js +258 -0
  110. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
  111. package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
  112. package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
  113. package/srv/blockchain/transaction-presence.d.ts +12 -0
  114. package/srv/blockchain/transaction-presence.js +29 -0
  115. package/srv/blockchain/transaction-rows.d.ts +12 -0
  116. package/srv/blockchain/transaction-rows.js +44 -0
  117. package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
  118. package/srv/blockchain/wallet-worker/build-request.js +40 -353
  119. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
  120. package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
  121. package/srv/blockchain/wallet-worker/index.d.ts +1 -1
  122. package/srv/blockchain/wallet-worker/index.js +3 -11
  123. package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
  124. package/srv/blockchain/wallet-worker/invalidation.js +128 -0
  125. package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
  126. package/srv/blockchain/wallet-worker/job-store.js +200 -273
  127. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
  128. package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
  129. package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
  130. package/srv/blockchain/wallet-worker/signers.js +4 -12
  131. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
  132. package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
  133. package/srv/cardano-agent-service.cds +122 -84
  134. package/srv/cardano-agent-service.js +12 -9
  135. package/srv/cardano-backend-service.cds +81 -0
  136. package/srv/cardano-backend-service.d.ts +2 -0
  137. package/srv/cardano-backend-service.js +259 -0
  138. package/srv/cardano-indexer-service.cds +393 -18
  139. package/srv/cardano-indexer-service.d.ts +5 -1
  140. package/srv/cardano-indexer-service.js +477 -16
  141. package/srv/cardano-service.cds +426 -269
  142. package/srv/cardano-service.js +640 -217
  143. package/srv/cardano-sign-service.cds +211 -180
  144. package/srv/cardano-sign-service.js +210 -287
  145. package/srv/cardano-tx-service.cds +462 -370
  146. package/srv/cardano-tx-service.js +283 -800
  147. package/srv/cardano-ui.cds +16 -16
  148. package/srv/cardano-worker-service.cds +141 -125
  149. package/srv/cardano-worker-service.js +104 -61
  150. package/srv/cbor/cip68.d.ts +13 -0
  151. package/srv/cbor/cip68.js +56 -0
  152. package/srv/cbor/index.d.ts +3 -1
  153. package/srv/cbor/index.js +9 -1
  154. package/srv/cbor/parse.d.ts +30 -18
  155. package/srv/cbor/parse.js +44 -9
  156. package/srv/cbor/plutus-data-json.d.ts +20 -0
  157. package/srv/cbor/plutus-data-json.js +32 -0
  158. package/srv/config.d.ts +117 -0
  159. package/srv/config.js +419 -0
  160. package/srv/server.d.ts +15 -110
  161. package/srv/server.js +83 -405
  162. package/srv/utils/agent-access.d.ts +11 -0
  163. package/srv/utils/agent-access.js +86 -0
  164. package/srv/utils/agent-grants-config.d.ts +0 -46
  165. package/srv/utils/agent-grants-config.js +17 -85
  166. package/srv/utils/agent-grants.d.ts +106 -122
  167. package/srv/utils/agent-grants.js +538 -237
  168. package/srv/utils/agent-token-auth.d.ts +4 -99
  169. package/srv/utils/agent-token-auth.js +62 -186
  170. package/srv/utils/backend-request-handler.d.ts +3 -17
  171. package/srv/utils/backend-request-handler.js +3 -18
  172. package/srv/utils/build-request.d.ts +52 -0
  173. package/srv/utils/build-request.js +487 -0
  174. package/srv/utils/collections.d.ts +4 -10
  175. package/srv/utils/collections.js +14 -10
  176. package/srv/utils/const.d.ts +32 -75
  177. package/srv/utils/const.js +40 -80
  178. package/srv/utils/crypto.d.ts +3 -12
  179. package/srv/utils/crypto.js +11 -25
  180. package/srv/utils/db-indexes.d.ts +31 -0
  181. package/srv/utils/db-indexes.js +185 -0
  182. package/srv/utils/db-kind.d.ts +23 -0
  183. package/srv/utils/db-kind.js +42 -0
  184. package/srv/utils/db-sanitize.d.ts +20 -0
  185. package/srv/utils/db-sanitize.js +80 -0
  186. package/srv/utils/deep-json.d.ts +6 -0
  187. package/srv/utils/deep-json.js +240 -0
  188. package/srv/utils/detached-run.d.ts +41 -0
  189. package/srv/utils/detached-run.js +101 -0
  190. package/srv/utils/epoch-slots.d.ts +14 -0
  191. package/srv/utils/epoch-slots.js +45 -0
  192. package/srv/utils/error-codes.d.ts +26 -75
  193. package/srv/utils/error-codes.js +27 -72
  194. package/srv/utils/errors.d.ts +55 -187
  195. package/srv/utils/errors.js +161 -235
  196. package/srv/utils/lease.d.ts +20 -0
  197. package/srv/utils/lease.js +62 -0
  198. package/srv/utils/liveness.d.ts +12 -0
  199. package/srv/utils/liveness.js +35 -0
  200. package/srv/utils/mappers.d.ts +111 -223
  201. package/srv/utils/mappers.js +432 -371
  202. package/srv/utils/navigation.d.ts +17 -0
  203. package/srv/utils/navigation.js +52 -0
  204. package/srv/utils/network-context.d.ts +0 -1
  205. package/srv/utils/network-context.js +9 -15
  206. package/srv/utils/paging.d.ts +31 -0
  207. package/srv/utils/paging.js +43 -0
  208. package/srv/utils/pg-inline-json.d.ts +8 -0
  209. package/srv/utils/pg-inline-json.js +58 -0
  210. package/srv/utils/pg-order-nulls.d.ts +14 -0
  211. package/srv/utils/pg-order-nulls.js +54 -0
  212. package/srv/utils/plutus-placeholders.d.ts +16 -22
  213. package/srv/utils/plutus-placeholders.js +62 -33
  214. package/srv/utils/rate-limiter.d.ts +2 -21
  215. package/srv/utils/rate-limiter.js +5 -17
  216. package/srv/utils/readiness.d.ts +12 -0
  217. package/srv/utils/readiness.js +29 -0
  218. package/srv/utils/reference-script.d.ts +19 -0
  219. package/srv/utils/reference-script.js +84 -0
  220. package/srv/utils/resolution.d.ts +13 -0
  221. package/srv/utils/resolution.js +47 -0
  222. package/srv/utils/result-numbers.d.ts +15 -0
  223. package/srv/utils/result-numbers.js +61 -0
  224. package/srv/utils/row-values.d.ts +7 -0
  225. package/srv/utils/row-values.js +27 -0
  226. package/srv/utils/service-events.d.ts +0 -24
  227. package/srv/utils/service-events.js +3 -25
  228. package/srv/utils/signing-helper.d.ts +3 -20
  229. package/srv/utils/signing-helper.js +35 -64
  230. package/srv/utils/tx-build-helper.d.ts +25 -105
  231. package/srv/utils/tx-build-helper.js +108 -156
  232. package/srv/utils/tx-request-parsers.d.ts +82 -33
  233. package/srv/utils/tx-request-parsers.js +401 -49
  234. package/srv/utils/tx-utils.d.ts +3 -27
  235. package/srv/utils/tx-utils.js +32 -50
  236. package/srv/utils/types.d.ts +294 -232
  237. package/srv/utils/types.js +2 -22
  238. package/srv/utils/validators.d.ts +22 -92
  239. package/srv/utils/validators.js +60 -170
@@ -1,36 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ConfigError = exports.HsmError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
3
+ exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ChainSyncFrameError = exports.ChainSyncStalledError = exports.ChainSyncClosedError = exports.ConfigError = exports.HsmError = exports.ERROR_TEXT_MAX = exports.SubmitOutcomeUnknownError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ChainPointMismatchError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
4
4
  exports.isNotFoundOnAllBackends = isNotFoundOnAllBackends;
5
+ exports.isBackendVerdict = isBackendVerdict;
6
+ exports.isSubmitRejection = isSubmitRejection;
5
7
  exports.isPostgrestServerErrorCode = isPostgrestServerErrorCode;
6
8
  exports.getErrorStatus = getErrorStatus;
7
9
  exports.getErrorMessage = getErrorMessage;
10
+ exports.errorText = errorText;
11
+ exports.nodeRejectionReason = nodeRejectionReason;
12
+ exports.submitRejection = submitRejection;
8
13
  exports.normalizeBackendError = normalizeBackendError;
9
14
  exports.rejectInvalid = rejectInvalid;
10
15
  exports.rejectMissing = rejectMissing;
11
16
  exports.throwIfValidationErrors = throwIfValidationErrors;
12
17
  const error_codes_1 = require("./error-codes");
13
- /**
14
- * Backend Errors Implementation
15
- * Defines typed errors for backend communication issues
16
- */
17
- /**
18
- * BackendError Base class for all backend-related errors
19
- */
18
+ /** Typed errors for backend communication and request validation. */
19
+ /** Base class for all backend-related errors. */
20
20
  class BackendError extends Error {
21
21
  statusCode;
22
22
  code;
23
23
  backendName;
24
24
  originalError;
25
25
  target;
26
- /** Constructor
27
- * @param message error message string
28
- * @param statusCode error status code
29
- * @param code error code
30
- * @param backendName name of the backend where the error originated
31
- * @param originalError original error object
32
- * @param target target resource (if applicable)
33
- */
34
26
  constructor(message, statusCode = 500, code = error_codes_1.ERROR_CODES.INTERNAL_ERROR, backendName, originalError, target) {
35
27
  super(message);
36
28
  this.statusCode = statusCode;
@@ -40,94 +32,55 @@ class BackendError extends Error {
40
32
  this.target = target;
41
33
  this.name = this.constructor.name;
42
34
  Error.captureStackTrace(this, this.constructor);
35
+ // CAP copies enumerable fields into the response body; these stay server-side
36
+ for (const key of ['name', 'backendName', 'originalError'])
37
+ Object.defineProperty(this, key, { enumerable: false });
43
38
  }
44
39
  }
45
40
  exports.BackendError = BackendError;
46
- /**
47
- * NotFoundError - Resource not found in backend (404)
48
- * This is NOT a provider error - it's a valid response indicating the resource doesn't exist
49
- * Examples: transaction hash not found, address has no UTxOs
50
- */
41
+ /** Resource not found (404); a valid response, not a provider fault. */
51
42
  class NotFoundError extends BackendError {
52
- /** Constructor
53
- * @param resource name of the resource that was not found
54
- * @param backendName name of the backend where the error originated
55
- * @param originalError original error object
56
- */
57
43
  constructor(resource, backendName, originalError) {
58
44
  super(`${resource} not found`, 404, error_codes_1.ERROR_CODES.NOT_FOUND, backendName, originalError);
59
45
  }
60
46
  }
61
47
  exports.NotFoundError = NotFoundError;
62
- /**
63
- * TransactionValidationError - Transaction failed validation (400)
64
- * Indicates that the transaction failed validation checks
65
- * Examples: wrong signature, tampered CBOR, invalid witnesses
66
- */
48
+ /** Transaction failed validation (400): wrong signature, tampered CBOR, invalid witnesses. `code` may be `TX_PARSE_FAILED`. */
67
49
  class TransactionValidationError extends BackendError {
68
- /** Constructor
69
- * @param message detailed validation failure message
70
- * @param originalError original error object
71
- * @param code optional override (e.g. `TX_PARSE_FAILED` for CBOR decode failures);
72
- * defaults to `TX_VALIDATION_FAILED`.
73
- */
74
50
  constructor(message, originalError, code = error_codes_1.ERROR_CODES.TX_VALIDATION_FAILED) {
75
51
  super(message, 400, code, undefined, originalError);
76
52
  }
77
53
  }
78
54
  exports.TransactionValidationError = TransactionValidationError;
79
- /**
80
- * ScriptValidationError - Plutus script validation failed on the ledger (400)
81
- * Distinguishes a clean ledger rejection (PlutusFailure, CekError, overspent
82
- * budget, script hash mismatch) from provider outages (503). The transaction
83
- * was well-formed enough to reach phase-2 validation — retrying against a
84
- * different provider will not help; the tx shape itself is the problem.
85
- */
55
+ /** Ledger phase-2 script rejection (400): PlutusFailure, CekError, budget, hash mismatch. Not retryable on another provider. */
86
56
  class ScriptValidationError extends BackendError {
87
- /** Constructor
88
- * @param message detailed script failure message (typically from ledger)
89
- * @param originalError original error object
90
- */
91
57
  constructor(message, originalError) {
92
58
  super(message, 400, error_codes_1.ERROR_CODES.SCRIPT_VALIDATION_FAILURE, undefined, originalError);
93
59
  }
94
60
  }
95
61
  exports.ScriptValidationError = ScriptValidationError;
96
- /**
97
- * TransactionAlreadySubmittedError - Transaction already exists (409)
98
- * Indicates that the transaction has already been submitted (duplicate/replay)
99
- * Examples: same txHash already in mempool or on chain
100
- */
62
+ // 409: the crawler cursor block is not on this instance's chain. A 4xx keeps its message in
63
+ // production, so a remote crawler receives the `CHAIN_POINT_MISMATCH:` marker it recovers on.
64
+ class ChainPointMismatchError extends BackendError {
65
+ constructor(message, backendName) {
66
+ super(message, 409, error_codes_1.ERROR_CODES.CHAIN_POINT_MISMATCH, backendName);
67
+ }
68
+ }
69
+ exports.ChainPointMismatchError = ChainPointMismatchError;
70
+ /** Transaction already in mempool or on chain (409). */
101
71
  class TransactionAlreadySubmittedError extends BackendError {
102
72
  txHash;
103
- /** Constructor
104
- * @param txHash the transaction hash that was already submitted
105
- * @param originalError original error object
106
- */
107
73
  constructor(txHash, originalError) {
108
74
  super(`Transaction ${txHash} already exists in mempool or on chain`, 409, error_codes_1.ERROR_CODES.TX_ALREADY_SUBMITTED, undefined, originalError);
109
75
  this.txHash = txHash;
110
76
  }
111
77
  }
112
78
  exports.TransactionAlreadySubmittedError = TransactionAlreadySubmittedError;
113
- /**
114
- * InsufficientFundsError - Not enough funds or assets available (400)
115
- * Indicates that the address does not have enough of a specific asset to complete the transaction
116
- * Examples: trying to send more ADA than available, not enough native tokens
117
- */
79
+ // 400: not enough of an asset. The amounts are 0n when unknown, and then detail replaces them in the message.
118
80
  class InsufficientFundsError extends BackendError {
119
81
  assetUnit;
120
82
  required;
121
83
  available;
122
- /** Constructor
123
- * @param assetUnit the asset unit that is insufficient (e.g., "lovelace" or "policyId.assetName")
124
- * @param required the required amount (0n when unknown)
125
- * @param available the available amount (0n when unknown)
126
- * @param originalError original error object
127
- * @param detail human-readable cause shown INSTEAD of the amounts — use when
128
- * the amounts are unknown; "required 0, available 0" reads as
129
- * nonsense from the consumer's perspective
130
- */
131
84
  constructor(assetUnit, required, available, originalError, detail) {
132
85
  super(detail
133
86
  ? `Insufficient ${assetUnit}: ${detail}`
@@ -138,18 +91,10 @@ class InsufficientFundsError extends BackendError {
138
91
  }
139
92
  }
140
93
  exports.InsufficientFundsError = InsufficientFundsError;
141
- /**
142
- * MixedAssetsError - UTxO contains mixed assets when pure ADA is required (400)
143
- * Indicates that a UTxO contains native assets in addition to ADA, but the operation requires ADA-only UTxOs
144
- */
94
+ /** UTxO carries native assets where ADA-only is required (400). `utxoRef` is `txHash#outputIndex`. */
145
95
  class MixedAssetsError extends BackendError {
146
96
  utxoRef;
147
97
  assets;
148
- /** Constructor
149
- * @param utxoRef UTxO reference (txHash#outputIndex)
150
- * @param assets list of non-ADA assets found in the UTxO
151
- * @param originalError original error object
152
- */
153
98
  constructor(utxoRef, assets, originalError) {
154
99
  super(`UTxO ${utxoRef} contains non-ADA assets: ${assets.join(', ')}`, 400, error_codes_1.ERROR_CODES.INVALID_INPUT, undefined, originalError, utxoRef);
155
100
  this.utxoRef = utxoRef;
@@ -157,18 +102,8 @@ class MixedAssetsError extends BackendError {
157
102
  }
158
103
  }
159
104
  exports.MixedAssetsError = MixedAssetsError;
160
- /**
161
- * ProviderUnavailableError - Provider unavailable or timeout (503)
162
- * Indicates a temporary issue - retrying may help
163
- * Examples: network timeout, 5xx errors, service down
164
- */
105
+ /** Provider unavailable or timed out (503); retryable. `timeoutMs` is appended to the message. */
165
106
  class ProviderUnavailableError extends BackendError {
166
- /** Constructor
167
- * @param message error message string
168
- * @param backendName name of the backend where the error originated
169
- * @param timeoutMs optional timeout duration in milliseconds
170
- * @param originalError original error object
171
- */
172
107
  constructor(message, backendName, timeoutMs, originalError) {
173
108
  const msg = timeoutMs
174
109
  ? `${message} (timeout after ${timeoutMs}ms)`
@@ -177,18 +112,8 @@ class ProviderUnavailableError extends BackendError {
177
112
  }
178
113
  }
179
114
  exports.ProviderUnavailableError = ProviderUnavailableError;
180
- /**
181
- * RateLimitError - Provider rate limit exceeded (429)
182
- * Indicates too many requests - client should back off and retry later
183
- * Examples: Blockfrost 10 req/sec limit, Koios tier limits
184
- */
115
+ /** Provider rate limit exceeded (429). `retryAfter` is in seconds. */
185
116
  class RateLimitError extends BackendError {
186
- /** Constructor
187
- * @param message error message string
188
- * @param backendName name of the backend where the error originated
189
- * @param retryAfter optional retry-after duration in seconds
190
- * @param originalError original error object
191
- */
192
117
  constructor(message, backendName, retryAfter, originalError) {
193
118
  const msg = retryAfter
194
119
  ? `${message} (retry after ${retryAfter}s)`
@@ -197,37 +122,20 @@ class RateLimitError extends BackendError {
197
122
  }
198
123
  }
199
124
  exports.RateLimitError = RateLimitError;
200
- /**
201
- * AllBackendsFailedError - All backends failed
202
- * Aggregates multiple backend errors and returns the most relevant status
203
- */
125
+ // Every backend failed. It answers 404 only when every backend said 404, else the last other error.
126
+ // With no error at all every backend was skipped, so 503.
204
127
  class AllBackendsFailedError extends BackendError {
205
128
  errors;
206
- /** Constructor
207
- * @param errors array of backend errors
208
- * @param originalError original error object
209
- */
210
- constructor(errors, originalError) {
211
- const lastError = errors[errors.length - 1];
212
- super(
213
- // Empty errors == every backend was *skipped* (e.g. all declared the method
214
- // unsupported), so nothing actually failed/connected: surface 503 (no provider
215
- // available) rather than 502 (which implies an upstream backend returned a bad
216
- // response). A real backend failure carries its own statusCode via lastError.
217
- `All backends failed: ${lastError?.message ?? 'unknown error'}`, lastError?.statusCode ?? 503, lastError?.code ?? error_codes_1.ERROR_CODES.PROVIDER_UNAVAILABLE, undefined, originalError);
129
+ /** @param skipped why backends were not called at all, e.g. `koios: circuit open` */
130
+ constructor(errors, originalError, skipped = []) {
131
+ const decisive = [...errors].reverse().find((e) => e.statusCode !== 404) ?? errors[errors.length - 1];
132
+ const noneCalled = skipped.length ? `no backend available (${skipped.join('; ')})` : 'unknown error';
133
+ super(`All backends failed: ${decisive?.message ?? noneCalled}`, decisive?.statusCode ?? 503, decisive?.code ?? error_codes_1.ERROR_CODES.PROVIDER_UNAVAILABLE, undefined, originalError);
218
134
  this.errors = errors;
219
135
  }
220
136
  }
221
137
  exports.AllBackendsFailedError = AllBackendsFailedError;
222
- /**
223
- * True when the error proves the resource is absent on EVERY backend that was
224
- * consulted: either a direct NotFoundError, or an AllBackendsFailedError whose
225
- * collected per-backend errors are all 404s. CardanoClient's failover wraps
226
- * per-backend errors (including 404s) into AllBackendsFailedError, so callers
227
- * that need "definitively not found" (e.g. the wallet-worker's dropped-tx
228
- * detection) must use this instead of `instanceof NotFoundError`. A mixed
229
- * result (one backend 404, another 500) is NOT proof of absence.
230
- */
138
+ // True when every consulted backend answered 404. A mixed result is not proof of absence.
231
139
  function isNotFoundOnAllBackends(err) {
232
140
  if (err instanceof NotFoundError)
233
141
  return true;
@@ -235,65 +143,96 @@ function isNotFoundOnAllBackends(err) {
235
143
  && err.errors.length > 0
236
144
  && err.errors.every((e) => e instanceof NotFoundError || e.statusCode === 404);
237
145
  }
238
- /**
239
- * PostgreSQL error-code classes that indicate a fault in the provider's own
240
- * database/deployment rather than in our request. Koios (PostgREST) surfaces
241
- * these as HTTP 400 — e.g. code '42703' ("column … does not exist") from a
242
- * half-migrated SQL function on one load-balanced instance, or '57014'
243
- * (statement timeout) under load. Client-input errors (class 22, invalid text
244
- * representation etc.) are deliberately NOT listed — those remain 4xx.
245
- * Classes: 08 connection, 42 syntax/undefined object, 53 insufficient
246
- * resources, 57 operator intervention (incl. query_canceled), 58 system
247
- * error, XX internal error.
248
- */
146
+ // A 4xx a healthy backend gave about the request itself. A rate limit is not one, and 401, 402
147
+ // and 403 arrive as 503 from normalizeBackendError.
148
+ function isBackendVerdict(err) {
149
+ return err instanceof BackendError && !(err instanceof AllBackendsFailedError)
150
+ && err.statusCode >= 400 && err.statusCode < 500 && err.statusCode !== 429;
151
+ }
152
+ // True when every backend that was asked refused the transaction itself. A timeout, a 5xx or a
153
+ // rate limit is no verdict: the transaction may have been accepted before the answer was lost.
154
+ function isSubmitRejection(err) {
155
+ if (err instanceof AllBackendsFailedError)
156
+ return err.errors.length > 0 && err.errors.every(isBackendVerdict);
157
+ return isBackendVerdict(err);
158
+ }
159
+ /** A submit failed without a verdict (503). The record stays open and the server keeps resolving it. */
160
+ class SubmitOutcomeUnknownError extends BackendError {
161
+ txHash;
162
+ constructor(txHash, originalError) {
163
+ const cause = originalError instanceof Error ? ` (${originalError.message})` : '';
164
+ super(`Submit of transaction ${txHash} got no verdict${cause}. It may still reach the chain: read its status before sending a replacement.`, 503, error_codes_1.ERROR_CODES.SUBMIT_OUTCOME_UNKNOWN, undefined, originalError);
165
+ this.txHash = txHash;
166
+ }
167
+ }
168
+ exports.SubmitOutcomeUnknownError = SubmitOutcomeUnknownError;
169
+ // PostgreSQL error classes that mean a provider-side fault. Koios returns them as HTTP 400.
170
+ // Client-input classes such as 22 stay 4xx.
249
171
  const PG_SERVER_ERROR_CODE_CLASSES = ['08', '42', '53', '57', '58', 'XX'];
250
172
  /** True when a PostgREST error body's `code` denotes a provider-side SQL fault. */
251
173
  function isPostgrestServerErrorCode(code) {
252
174
  return typeof code === 'string' && PG_SERVER_ERROR_CODE_CLASSES.some(c => code.startsWith(c));
253
175
  }
254
- /**
255
- * Utility functions to extract status and message from HttpErrorLike
256
- * @param err error object
257
- * @returns {number} status code
258
- */
176
+ /** HTTP status of an HttpErrorLike, default 500. */
259
177
  function getErrorStatus(err) {
260
178
  const e = (err ?? {});
261
- return e.status ?? e.response?.status ?? 500;
179
+ return e.status ?? e.status_code ?? e.response?.status ?? 500;
262
180
  }
263
- /**
264
- * Utility functions to extract status and message from HttpErrorLike
265
- * @param err error object
266
- * @returns {string} error message
267
- */
181
+ /** Message of an HttpErrorLike: `response.data.error` (Koios), else `message`. */
268
182
  function getErrorMessage(err) {
269
183
  const e = (err ?? {});
270
- // Check Axios response.data.error (Koios format)
271
184
  if (e.response?.data?.error)
272
185
  return e.response.data.error;
273
- // Check direct message property
274
186
  if (e.message)
275
187
  return e.message;
276
188
  return 'Unknown error';
277
189
  }
278
- /**
279
- * Normalizes any backend error into a typed BackendError
280
- *
281
- * Priority (checked in order):
282
- * 1. TX Submission — Already submitted/duplicate → 409
283
- * 2. TX Submission — Plutus script validation failure → 400 (ScriptValidationError)
284
- * 3. TX Submission — Validation/Signature errors → 400
285
- * 4. Message indicates "not found" → 404 (even if provider returns 5xx)
286
- * 5. Rate limiting (status 429 or message patterns) → 429
287
- * 6. Explicit 404 status → 404
288
- * 7. 5xx errors → 503 (Provider unavailable, retry-able)
289
- * 8. Other 4xx → 503
290
- * 9. Unknown/network errors → 503 (default fallback)
291
- */
190
+ /** Characters of an error text kept in a stored status or log line. */
191
+ exports.ERROR_TEXT_MAX = 500;
192
+ /** Message of any thrown value, at most ERROR_TEXT_MAX characters. */
193
+ function errorText(err) {
194
+ return (err instanceof Error ? err.message : String(err)).slice(0, exports.ERROR_TEXT_MAX);
195
+ }
196
+ /** The `error` entries of a cardano-submit-api rejection, else the body as text. */
197
+ function nodeRejectionReason(body) {
198
+ const errors = [];
199
+ const walk = (v) => {
200
+ if (!v || typeof v !== 'object')
201
+ return;
202
+ const o = v;
203
+ if (Array.isArray(o.error))
204
+ errors.push(...o.error.map(String));
205
+ else if (typeof o.error === 'string')
206
+ errors.push(o.error);
207
+ for (const child of Object.values(o))
208
+ walk(child);
209
+ };
210
+ walk(typeof body === 'string' ? (() => { try {
211
+ return JSON.parse(body);
212
+ }
213
+ catch {
214
+ return undefined;
215
+ } })() : body);
216
+ const text = errors.length > 0 ? errors.join('; ') : (typeof body === 'string' ? body : JSON.stringify(body));
217
+ return text.slice(0, 1000);
218
+ }
219
+ // A node's refusal of a submitted transaction. Already-submitted and script failures keep their class.
220
+ function submitRejection(reason, backendName, err) {
221
+ const known = normalizeBackendError(new Error(reason), backendName);
222
+ if (known.statusCode === 409 || known instanceof ScriptValidationError)
223
+ return known;
224
+ return new TransactionValidationError(`node rejected the transaction: ${reason}`, err);
225
+ }
226
+ /** Ogmios JSON-RPC code of a failed script evaluation. */
227
+ const OGMIOS_SCRIPT_EXECUTION_FAILURE = 3010;
228
+ /** Characters of Ogmios error data kept in a message. */
229
+ const OGMIOS_DETAIL_MAX = 2000;
230
+ // Turns any backend error into a typed BackendError. Ogmios script failures are matched by JSON-RPC code.
231
+ // Message hints are checked in a fixed priority order before the HTTP status.
292
232
  function normalizeBackendError(err, backendName) {
293
- // Already normalized
294
233
  if (err instanceof BackendError)
295
234
  return err;
296
- // Check for uninitialized backend client (TypeError from calling methods on null/undefined client)
235
+ // TypeError from calling a method on an uninitialized (null) backend client
297
236
  if (err instanceof TypeError &&
298
237
  (err.message.includes('Cannot read properties of null') ||
299
238
  err.message.includes('Cannot read properties of undefined') ||
@@ -301,10 +240,16 @@ function normalizeBackendError(err, backendName) {
301
240
  err.message.includes('undefined is not an object'))) {
302
241
  return new BackendInitError(backendName || 'unknown', new Error('Backend client not initialized - call init() first'));
303
242
  }
243
+ // Ogmios evaluateTransaction 3010: a script failed. Its data names each failing validator.
244
+ const rpc = err;
245
+ if (rpc?.code === OGMIOS_SCRIPT_EXECUTION_FAILURE) {
246
+ const detail = rpc.data === undefined ? '' : ` ${JSON.stringify(rpc.data).slice(0, OGMIOS_DETAIL_MAX)}`;
247
+ return new ScriptValidationError(`Script validation failed (${rpc.code}): ${String(rpc.message ?? '')}${detail}`, err);
248
+ }
304
249
  const message = getErrorMessage(err);
305
250
  const status = getErrorStatus(err);
306
251
  const messageLower = message.toLowerCase();
307
- // Priority 1: TX Submission - Already submitted/duplicate → 409
252
+ // Already submitted / duplicate: 409
308
253
  const alreadySubmittedHints = [
309
254
  'already exists',
310
255
  'already submitted',
@@ -314,13 +259,10 @@ function normalizeBackendError(err, backendName) {
314
259
  'in mempool',
315
260
  ];
316
261
  if (alreadySubmittedHints.some(h => messageLower.includes(h))) {
317
- // Try to extract txHash from message
318
262
  const txHashMatch = message.match(/([a-f0-9]{64})/i);
319
263
  return new TransactionAlreadySubmittedError(txHashMatch?.[1] || 'unknown', err);
320
264
  }
321
- // Priority 2: TX Submission - Plutus script validation → 400 (ScriptValidationError)
322
- // Must precede the generic validation block: these are ledger phase-2 rejections
323
- // (tx was well-formed), not provider outages and not generic witness/CBOR issues.
265
+ // Ledger phase-2 script rejection: 400, before the generic validation hints
324
266
  const scriptValidationHints = [
325
267
  'plutusfailure',
326
268
  'plutus failure',
@@ -337,9 +279,7 @@ function normalizeBackendError(err, backendName) {
337
279
  if (scriptValidationHints.some(h => messageLower.includes(h))) {
338
280
  return new ScriptValidationError(`Script validation failed: ${message}`, err);
339
281
  }
340
- // Priority 3a: Address-shaped lookup errors → 404. MUST precede the generic
341
- // validation hints — 'malformed' there used to shadow 'malformed address',
342
- // turning a Blockfrost 400 on a read into a TransactionValidationError.
282
+ // Address-shaped lookup errors: 404, before 'malformed' in the validation hints can catch them
343
283
  const addressNotFoundHints = [
344
284
  'invalid address',
345
285
  'malformed address',
@@ -347,7 +287,7 @@ function normalizeBackendError(err, backendName) {
347
287
  if (addressNotFoundHints.some(h => messageLower.includes(h))) {
348
288
  return new NotFoundError('Resource', backendName, err);
349
289
  }
350
- // Priority 3: TX Submission - Validation/Signature errors → 400
290
+ // Validation / signature errors: 400
351
291
  const validationErrorHints = [
352
292
  'signature',
353
293
  'witness',
@@ -360,22 +300,14 @@ function normalizeBackendError(err, backendName) {
360
300
  if (validationErrorHints.some(h => messageLower.includes(h))) {
361
301
  return new TransactionValidationError(`Transaction validation failed: ${message}`, err);
362
302
  }
363
- // Priority 3b: PostgREST server-side SQL faults surfaced as HTTP 400 (Koios).
364
- // Body shape: { code: '42703', message: 'column … does not exist' } (broken
365
- // SQL function on one LB instance) or { code: '57014' } (statement timeout).
366
- // These are provider faults, not request validation — classify as retry-able
367
- // 503 so multi-backend failover and the circuit breaker treat them like any
368
- // other provider outage. Checked before Priority 4: the PostgREST message
369
- // ("column … does not exist") would otherwise be misread as a resource 404.
303
+ // PostgREST server-side SQL faults arrive as HTTP 400 with a PG code: retryable 503 for failover.
304
+ // Before the not-found hints, whose 'does not exist' would match "column ... does not exist".
370
305
  const pgErrorBody = err?.response?.data;
371
306
  if ((status === 400 || status === 422) && isPostgrestServerErrorCode(pgErrorBody?.code)) {
372
307
  return new ProviderUnavailableError(`Provider database error (${pgErrorBody?.code}): ${pgErrorBody?.message ?? message}`, backendName, undefined, err);
373
308
  }
374
- // Priority 4: Message indicates "not found" or equivalent → always 404.
375
- // This also handles providers returning wrong status codes for missing
376
- // resources. Deliberately NOT here: 'not available' / bare 'no data' — those
377
- // also appear in provider OUTAGE messages, and classifying an outage as 404
378
- // would make it circuit-breaker-exempt (4xx) on top of hiding the 503.
309
+ // Not-found messages: 404 regardless of status. 'not available' / bare 'no data' are excluded,
310
+ // they also appear in outage messages and a 404 would be circuit-breaker-exempt.
379
311
  const notFoundHints = [
380
312
  'not found',
381
313
  'has not been found',
@@ -388,42 +320,38 @@ function normalizeBackendError(err, backendName) {
388
320
  if (notFoundHints.some(h => messageLower.includes(h))) {
389
321
  return new NotFoundError('Resource', backendName, err);
390
322
  }
391
- // Priority 5: Rate limiting detection (status 429 or message patterns)
323
+ // Rate limiting: status 429 or message patterns
392
324
  if (status === 429 ||
393
325
  messageLower.includes('rate limit') ||
394
326
  messageLower.includes('too many requests') ||
395
327
  messageLower.includes('quota exceeded')) {
396
- // Try to extract retry-after header
397
328
  const headers = err.response?.headers;
398
329
  const retryAfter = headers?.["retry-after"] ||
399
330
  headers?.["x-ratelimit-reset"];
400
331
  return new RateLimitError(message || 'Rate limit exceeded', backendName, retryAfter ? parseInt(retryAfter, 10) : undefined, err);
401
332
  }
402
- // Priority 6: Explicit 404 status
403
333
  if (status === 404) {
404
334
  return new NotFoundError('Resource', backendName, err);
405
335
  }
406
- // Priority 7: 5xx errors → Provider unavailable (retry-able)
336
+ // 5xx: provider unavailable (retryable)
407
337
  if (status >= 500) {
408
338
  return new ProviderUnavailableError(message || 'Provider returned server error', backendName, undefined, err);
409
339
  }
410
- // Priority 8: Other 4xx → differentiate by status code
340
+ // Other 4xx by status code
411
341
  if (status === 400 || status === 422) {
412
342
  return new TransactionValidationError(message || `Provider returned ${status}: invalid request`, err);
413
343
  }
414
- if (status === 401 || status === 403) {
415
- return new BackendError(`Provider authentication failed (${status}): ${message}`, status, error_codes_1.ERROR_CODES.PROVIDER_UNAVAILABLE, backendName, err);
344
+ // A refused key is the provider's fault, not the request's: another backend may answer.
345
+ if (status === 401 || status === 402 || status === 403) {
346
+ return new ProviderUnavailableError(`Provider authentication failed (${status}): ${message}`, backendName, undefined, err);
416
347
  }
417
348
  if (status >= 400) {
418
349
  return new ProviderUnavailableError(message || 'Provider request failed', backendName, undefined, err);
419
350
  }
420
- // Priority 9: Unknown/network errors → treat as unavailable (default fallback)
351
+ // Unknown / network errors: unavailable
421
352
  return new ProviderUnavailableError(message || 'Unknown backend error', backendName, undefined, err);
422
353
  }
423
- /**
424
- * HsmError - Error related to HSM operations (signing, session, key access)
425
- * Indicates that the Hardware Security Module is unavailable or signing failed
426
- */
354
+ /** HSM operation failed (session, key access, signing). */
427
355
  class HsmError extends BackendError {
428
356
  constructor(message, statusCode = 503, code = error_codes_1.ERROR_CODES.HSM_UNAVAILABLE, originalError) {
429
357
  super(message, statusCode, code, 'hsm', originalError);
@@ -431,10 +359,7 @@ class HsmError extends BackendError {
431
359
  }
432
360
  }
433
361
  exports.HsmError = HsmError;
434
- /**
435
- * ConfigError - Error in configuration settings
436
- * Captures configuration-related issues
437
- */
362
+ /** Configuration error. */
438
363
  class ConfigError extends Error {
439
364
  constructor(message) {
440
365
  super(message);
@@ -442,21 +367,41 @@ class ConfigError extends Error {
442
367
  }
443
368
  }
444
369
  exports.ConfigError = ConfigError;
445
- /**
446
- * BackendInitError - Error initializing a specific backend
447
- * Captures backend name and original error
448
- */
370
+ /** The Ogmios chain-sync socket closed without being asked to. */
371
+ class ChainSyncClosedError extends ProviderUnavailableError {
372
+ }
373
+ exports.ChainSyncClosedError = ChainSyncClosedError;
374
+ /** Chain-sync closed before delivering block `height`; the crawler fetches it over pagination. */
375
+ class ChainSyncStalledError extends BackendError {
376
+ height;
377
+ constructor(height, reason) {
378
+ super(`Ogmios chain-sync closed before delivering block ${height}: ${reason}`, 503, error_codes_1.ERROR_CODES.PROVIDER_UNAVAILABLE, 'ogmios');
379
+ this.height = height;
380
+ }
381
+ }
382
+ exports.ChainSyncStalledError = ChainSyncStalledError;
383
+ /** Unparsable chain-sync frame. Names the block when readable, so the crawler can fetch it by pagination. */
384
+ class ChainSyncFrameError extends BackendError {
385
+ height;
386
+ id;
387
+ constructor(height, id, reason) {
388
+ super(`Ogmios chain-sync frame for block ${height ?? '?'} ${id ?? ''} could not be parsed: ${reason}`, 503, error_codes_1.ERROR_CODES.PROVIDER_UNAVAILABLE, 'ogmios');
389
+ this.height = height;
390
+ this.id = id;
391
+ }
392
+ }
393
+ exports.ChainSyncFrameError = ChainSyncFrameError;
394
+ /** A backend failed to initialize. */
449
395
  class BackendInitError extends BackendError {
450
396
  constructor(backendName, originalError) {
451
- super(`Failed to initialize backend: ${backendName}`, 500, error_codes_1.ERROR_CODES.INTERNAL_ERROR, backendName, originalError);
397
+ super(originalError != null
398
+ ? `Failed to initialize backend: ${backendName} (${getErrorMessage(originalError)})`
399
+ : `Failed to initialize backend: ${backendName}`, 500, error_codes_1.ERROR_CODES.INTERNAL_ERROR, backendName, originalError);
452
400
  this.name = 'BackendInitError';
453
401
  }
454
402
  }
455
403
  exports.BackendInitError = BackendInitError;
456
- /**
457
- * AllBackendsInitFailedError - All backends failed to initialize
458
- * Aggregates multiple backend initialization errors
459
- */
404
+ /** Every backend failed to initialize. */
460
405
  class AllBackendsInitFailedError extends Error {
461
406
  errors;
462
407
  constructor(errors) {
@@ -469,34 +414,15 @@ class AllBackendsInitFailedError extends Error {
469
414
  }
470
415
  }
471
416
  exports.AllBackendsInitFailedError = AllBackendsInitFailedError;
472
- /**
473
- * Function to reject requests with standardized error messages
474
- * @param req - The incoming request
475
- * @param ctx - Context string for the error
476
- * @param message - Detailed error message
477
- * @param target - Optional target resource
478
- * @throws {BackendError} BackendError with 400 status code
479
- */
417
+ /** Throws a 400 INVALID_INPUT BackendError `<ctx>: <message>`. */
480
418
  function rejectInvalid(req, ctx, message, target) {
481
419
  throw new BackendError(`${ctx}: ${message}`, 400, error_codes_1.ERROR_CODES.INVALID_INPUT, undefined, undefined, target);
482
420
  }
483
- /**
484
- * Function to reject requests for missing required fields
485
- * @param req - The incoming request
486
- * @param ctx - Context string for the error
487
- * @param field - Name of the missing field
488
- * @throws {BackendError} BackendError with 400 status code
489
- */
421
+ /** Throws a 400 INVALID_INPUT BackendError for a missing required field. */
490
422
  function rejectMissing(req, ctx, field) {
491
423
  throw new BackendError(`${ctx}: ${field} is required`, 400, error_codes_1.ERROR_CODES.INVALID_INPUT, undefined, undefined, field);
492
424
  }
493
- /**
494
- * Throw BackendError for the first validation error in the list
495
- * @param req - The incoming request
496
- * @param ctx - Context string for the error
497
- * @param errors - Array of validation errors from validateTransactionInputs
498
- * @throws {BackendError} if errors array is not empty
499
- */
425
+ /** Throws a BackendError for the first validation error, if any. */
500
426
  function throwIfValidationErrors(req, ctx, errors) {
501
427
  if (errors.length === 0)
502
428
  return;
@@ -0,0 +1,20 @@
1
+ import type { Transaction as CapTransaction } from '@sap/cds';
2
+ /** The row that holds a lease. */
3
+ export interface LeaseRow {
4
+ entity: unknown;
5
+ key: Record<string, unknown>;
6
+ /** Column values every acquire and renewal requires in its WHERE. */
7
+ requires?: Record<string, unknown>;
8
+ /** The same requirement on a row read back, for the adapters' own value forms. */
9
+ holds?: (row: Record<string, unknown>) => boolean;
10
+ }
11
+ export interface LeaseTiming {
12
+ now?: Date;
13
+ ttlMs: number;
14
+ }
15
+ export declare function tryAcquireLease(db: CapTransaction, lease: LeaseRow, owner: string, timing: LeaseTiming, admit?: (row: Record<string, unknown>) => boolean): Promise<boolean>;
16
+ /** Extends the caller's lease, with `set` written in the same statement. False when it is lost. */
17
+ export declare function renewLease(db: CapTransaction, lease: LeaseRow, owner: string, timing: LeaseTiming, set?: Record<string, unknown>): Promise<boolean>;
18
+ /** Gives up only the caller's lease, so a former owner never clears its successor. */
19
+ export declare function releaseLease(db: CapTransaction, lease: LeaseRow, owner: string, set?: Record<string, unknown>): Promise<void>;
20
+ //# sourceMappingURL=lease.d.ts.map