@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
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.INDEX_UNLOCK_STATEMENT = exports.INDEX_LOCK_STATEMENT = exports.INVALID_INDEXES_STATEMENT = exports.DROPPED_DB_INDEXES = exports.DB_INDEXES = void 0;
7
+ exports.indexStatement = indexStatement;
8
+ exports.ensureDbIndexes = ensureDbIndexes;
9
+ // Secondary indexes the CDS model cannot declare, created at start. Temporal keys start with validFrom,
10
+ // so lookups by business key would scan without them. Failures are logged, never fatal.
11
+ // HANA is skipped because it has no CREATE INDEX IF NOT EXISTS.
12
+ const cds_1 = __importDefault(require("@sap/cds"));
13
+ const logger = cds_1.default.log('DbIndexes');
14
+ /** Every entry answers a query the service or the crawler actually runs. */
15
+ exports.DB_INDEXES = Object.freeze([
16
+ // Blocks: latest (ORDER BY height DESC), byHeight, crawler `height in`, rollback `slot >`, epoch filters
17
+ { name: 'odatano_cardano_blocks_height', table: 'odatano_cardano_Blocks', columns: 'height' },
18
+ // CAP renders `$orderby=height desc` as DESC NULLS LAST, which the plain ASC NULLS LAST
19
+ // index cannot serve backwards; the plain one stays for ASC and equality.
20
+ { name: 'odatano_cardano_blocks_height_desc', table: 'odatano_cardano_Blocks', columns: 'height DESC', postgres: 'height DESC NULLS LAST' },
21
+ { name: 'odatano_cardano_blocks_slot', table: 'odatano_cardano_Blocks', columns: 'slot' },
22
+ { name: 'odatano_cardano_blocks_epoch', table: 'odatano_cardano_Blocks', columns: 'epochNumber' },
23
+ // the first block at or after a point in time (`$filter=time ge …&$orderby=time`)
24
+ // CAP sorts a nullable column as ASC NULLS FIRST or DESC NULLS LAST on PostgreSQL; this serves both
25
+ { name: 'odatano_cardano_blocks_time', table: 'odatano_cardano_Blocks', columns: 'time', postgres: 'time NULLS FIRST' },
26
+ // block counts per pool (Pools.blocksEpoch / blocksMinted from crawled blocks)
27
+ { name: 'odatano_cardano_blocks_slotleader', table: 'odatano_cardano_Blocks', columns: 'slotLeader, slot' },
28
+ // Transactions of a block in block order (rollback `blockHash in`, GetBlockTransactions)
29
+ { name: 'odatano_cardano_transactions_block_idx', table: 'odatano_cardano_Transactions', columns: 'blockHash, txIndex' },
30
+ { name: 'odatano_cardano_transactions_height', table: 'odatano_cardano_Transactions', columns: 'blockHeight' },
31
+ // Input/output rows back to their transaction (`tx` association, stale-seq check of the crawler)
32
+ { name: 'odatano_cardano_transactions_txseq', table: 'odatano_cardano_Transactions', columns: 'txSeq' },
33
+ // GetMetadataByTxHash, rollback
34
+ { name: 'odatano_cardano_transactionmetadata_tx', table: 'odatano_cardano_TransactionMetadata', columns: 'tx_hash' },
35
+ { name: 'odatano_cardano_transactionmetadata_label_seq', table: 'odatano_cardano_TransactionMetadata', columns: 'id, txSeq' },
36
+ // rollback `txHash in` (key is unit, txHash); newest events of a unit
37
+ { name: 'odatano_cardano_assethistory_tx', table: 'odatano_cardano_AssetHistory', columns: 'txHash' },
38
+ { name: 'odatano_cardano_assethistory_unit_height', table: 'odatano_cardano_AssetHistory', columns: 'unit, blockHeight DESC', postgres: 'unit, blockHeight DESC NULLS LAST' },
39
+ // temporal entities: the business key behind validFrom
40
+ { name: 'odatano_cardano_assets_unit', table: 'odatano_cardano_Assets', columns: 'unit' },
41
+ { name: 'odatano_cardano_addresses_address', table: 'odatano_cardano_Addresses', columns: 'address' },
42
+ { name: 'odatano_cardano_addressutxos_address', table: 'odatano_cardano_AddressUTxOs', columns: 'address_address' },
43
+ { name: 'odatano_cardano_addressassets_address', table: 'odatano_cardano_AddressAssets', columns: 'address_address' },
44
+ { name: 'odatano_cardano_utxoassets_address', table: 'odatano_cardano_UTxOAssets', columns: 'utxo_address_address' },
45
+ // rollback `hash in` / `utxo_hash in`: the keys start with validFrom and the address
46
+ { name: 'odatano_cardano_addressutxos_hash', table: 'odatano_cardano_AddressUTxOs', columns: 'hash' },
47
+ { name: 'odatano_cardano_utxoassets_hash', table: 'odatano_cardano_UTxOAssets', columns: 'utxo_hash' },
48
+ // rollback `snapshotSlot >`: the keys start with the epoch
49
+ { name: 'odatano_cardano_poolepochsnapshots_slot', table: 'odatano_cardano_PoolEpochSnapshots', columns: 'snapshotSlot' },
50
+ { name: 'odatano_cardano_drepepochsnapshots_slot', table: 'odatano_cardano_DrepEpochSnapshots', columns: 'snapshotSlot' },
51
+ { name: 'odatano_cardano_epochledgersnapshots_slot', table: 'odatano_cardano_EpochLedgerSnapshots', columns: 'snapshotSlot' },
52
+ { name: 'odatano_cardano_addresstransactions_tx', table: 'odatano_cardano_AddressTransactions', columns: 'tx_hash' },
53
+ { name: 'odatano_cardano_accounts_stake', table: 'odatano_cardano_Accounts', columns: 'stakeAddress' },
54
+ { name: 'odatano_cardano_pools_poolid', table: 'odatano_cardano_Pools', columns: 'poolId' },
55
+ { name: 'odatano_cardano_dreps_drepid', table: 'odatano_cardano_Dreps', columns: 'drepId' },
56
+ // agent token lane: one lookup by token hash per request
57
+ { name: 'odatano_cardano_cardanoagentgrants_token', table: 'odatano_cardano_CardanoAgentGrants', columns: 'tokenHash' },
58
+ // crawler-fed ledger state: "who spent this output" and delegation per stake key / pool / DRep
59
+ { name: 'odatano_cardano_transactioninputs_spent', table: 'odatano_cardano_TransactionInputs', columns: 'spentTxHash, spentOutputIndex' },
60
+ // outputs to / inputs from a payment credential in slot order (txSeq); datum lookup by hash across txs
61
+ { name: 'odatano_cardano_transactionoutputs_paycred', table: 'odatano_cardano_TransactionOutputs', columns: 'utxo_paymentCredential, txSeq' },
62
+ { name: 'odatano_cardano_transactioninputs_paycred', table: 'odatano_cardano_TransactionInputs', columns: 'utxoData_paymentCredential, txSeq' },
63
+ { name: 'odatano_cardano_transactiondatums_hash', table: 'odatano_cardano_TransactionDatums', columns: 'dataHash' },
64
+ { name: 'odatano_cardano_transactioncertificates_stake', table: 'odatano_cardano_TransactionCertificates', columns: 'stakeAddress' },
65
+ { name: 'odatano_cardano_transactioncertificates_pool', table: 'odatano_cardano_TransactionCertificates', columns: 'poolId' },
66
+ { name: 'odatano_cardano_transactioncertificates_drep', table: 'odatano_cardano_TransactionCertificates', columns: 'drepId' },
67
+ { name: 'odatano_cardano_transactionwithdrawals_stake', table: 'odatano_cardano_TransactionWithdrawals', columns: 'stakeAddress' },
68
+ // all accounts of one epoch; the key starts with the stake address
69
+ { name: 'odatano_cardano_accountepochsnapshots_epoch', table: 'odatano_cardano_AccountEpochSnapshots', columns: 'epoch' },
70
+ // crawler-fed UTxO set: open rows per address, "who spent", stake-key rollups, asset holders
71
+ { name: 'odatano_cardano_ledgerutxos_address', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentTxHash' },
72
+ // newest created and spent rows of an address (latest transactions from the UTxO set)
73
+ { name: 'odatano_cardano_ledgerutxos_address_created', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, createdSlot' },
74
+ { name: 'odatano_cardano_ledgerutxos_address_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentSlot' },
75
+ { name: 'odatano_cardano_ledgerutxos_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'spentTxHash' },
76
+ { name: 'odatano_cardano_ledgerutxos_paycred', table: 'odatano_cardano_LedgerUTxOs', columns: 'utxo_paymentCredential, spentTxHash' },
77
+ { name: 'odatano_cardano_ledgeraddresses_stake', table: 'odatano_cardano_LedgerAddresses', columns: 'stakeAddress' },
78
+ { name: 'odatano_cardano_ledgeraddresses_paycred', table: 'odatano_cardano_LedgerAddresses', columns: 'paymentCredential' },
79
+ { name: 'odatano_cardano_ledgerutxoassets_unit', table: 'odatano_cardano_LedgerUTxOAssets', columns: 'unit' },
80
+ { name: 'odatano_cardano_ledgeraddressassets_unit', table: 'odatano_cardano_LedgerAddressAssets', columns: 'unit' },
81
+ // wallet worker: jobs by status, and the jobs of one wallet with its next due job in dispatch order
82
+ { name: 'odatano_cardano_cardanowalletjobs_status', table: 'odatano_cardano_CardanoWalletJobs', columns: 'status' },
83
+ { name: 'odatano_cardano_cardanowalletjobs_next', table: 'odatano_cardano_CardanoWalletJobs', columns: 'walletId, status, priority, createdAt' },
84
+ ]);
85
+ /** Indexes a composite entry above replaces; dropped at start. */
86
+ exports.DROPPED_DB_INDEXES = Object.freeze([
87
+ 'odatano_cardano_transactions_block',
88
+ 'odatano_cardano_cardanowalletjobs_due',
89
+ 'odatano_cardano_cardanowalletjobs_wallet',
90
+ ]);
91
+ /** The statement for one entry; exported so tests pin the shape. */
92
+ function indexStatement(spec, kind = 'sqlite') {
93
+ if (kind !== 'postgres')
94
+ return `CREATE INDEX IF NOT EXISTS ${spec.name} ON ${spec.table} (${spec.columns})`;
95
+ // CONCURRENTLY keeps the table writable while a large index builds
96
+ return `CREATE INDEX CONCURRENTLY IF NOT EXISTS ${spec.name} ON ${spec.table} (${spec.postgres ?? spec.columns})`;
97
+ }
98
+ // PostgreSQL builds an index CONCURRENTLY only outside a transaction, and every statement of the
99
+ // service runs inside one. A connection from the service's own factory runs it outside.
100
+ async function withOwnConnection(db, fn) {
101
+ const factory = db.factory;
102
+ if (!factory)
103
+ throw new Error('the PostgreSQL service has no connection factory');
104
+ const dbc = await factory.create();
105
+ try {
106
+ const schema = db.options?.credentials?.schema;
107
+ if (schema)
108
+ await dbc.query(`SET search_path TO "${schema.replace(/"/g, '""')}", public`);
109
+ return await fn(async (sql, params) => (await dbc.query(sql, params)).rows);
110
+ }
111
+ finally {
112
+ await factory.destroy(dbc);
113
+ }
114
+ }
115
+ /** Names of our indexes in this schema that are invalid; only a failed concurrent build leaves one. */
116
+ exports.INVALID_INDEXES_STATEMENT = 'SELECT c.relname AS name FROM pg_index i JOIN pg_class c ON c.oid = i.indexrelid JOIN pg_namespace n ON n.oid = c.relnamespace ' +
117
+ 'WHERE NOT i.indisvalid AND n.nspname = current_schema() AND c.relname = ANY($1)';
118
+ // One instance at a time builds the indexes. An index another instance is still building is
119
+ // invalid too, so without this lock a second start would drop it and kill that build.
120
+ exports.INDEX_LOCK_STATEMENT = "SELECT pg_try_advisory_lock(hashtext('odatano_db_indexes.' || current_schema())) AS locked";
121
+ exports.INDEX_UNLOCK_STATEMENT = "SELECT pg_advisory_unlock(hashtext('odatano_db_indexes.' || current_schema()))";
122
+ /** Creates every missing index; a failing statement is logged and skipped, the others still run. */
123
+ async function ensureDbIndexes(runner = cds_1.default.db) {
124
+ const ensured = [];
125
+ const failed = [];
126
+ if (!runner) {
127
+ logger.debug('no database service connected, indexes skipped');
128
+ return { ensured, failed };
129
+ }
130
+ const kind = String(runner.kind ?? 'sqlite');
131
+ if (kind === 'hana') {
132
+ logger.info('HANA: secondary indexes not created (column store, no IF NOT EXISTS)');
133
+ return { ensured, failed };
134
+ }
135
+ const ensure = async (run) => {
136
+ const concurrently = kind === 'postgres' ? 'CONCURRENTLY ' : '';
137
+ if (kind === 'postgres') {
138
+ const invalid = await run(exports.INVALID_INDEXES_STATEMENT, [exports.DB_INDEXES.map(s => s.name)]);
139
+ for (const { name } of invalid ?? []) {
140
+ logger.warn(`index ${name} is invalid after an interrupted build; rebuilding it`);
141
+ await run(`DROP INDEX CONCURRENTLY IF EXISTS ${name}`)
142
+ .catch((err) => logger.warn(`invalid index ${name} not dropped: ${String(err?.message ?? err)}`));
143
+ }
144
+ }
145
+ for (const name of exports.DROPPED_DB_INDEXES) {
146
+ await run(`DROP INDEX ${concurrently}IF EXISTS ${name}`)
147
+ .catch((err) => logger.warn(`index ${name} not dropped: ${String(err?.message ?? err)}`));
148
+ }
149
+ for (const spec of exports.DB_INDEXES) {
150
+ try {
151
+ await run(indexStatement(spec, kind));
152
+ ensured.push(spec.name);
153
+ }
154
+ catch (err) {
155
+ failed.push(spec.name);
156
+ logger.warn(`index ${spec.name} on ${spec.table} not ensured: ${String(err?.message ?? err)}`);
157
+ }
158
+ }
159
+ };
160
+ if (kind === 'postgres') {
161
+ const skipped = await withOwnConnection(runner, async (run) => {
162
+ const [lock] = await run(exports.INDEX_LOCK_STATEMENT);
163
+ if (!lock?.locked)
164
+ return true;
165
+ try {
166
+ await ensure(run);
167
+ }
168
+ finally {
169
+ await run(exports.INDEX_UNLOCK_STATEMENT).catch(() => undefined);
170
+ }
171
+ return false;
172
+ });
173
+ if (skipped) {
174
+ logger.info('another instance is building the indexes; skipped here');
175
+ return { ensured, failed };
176
+ }
177
+ }
178
+ else {
179
+ await ensure((sql, params) => runner.run(sql, params));
180
+ }
181
+ if (failed.length === 0)
182
+ logger.info(`${ensured.length} indexes ensured`);
183
+ return { ensured, failed };
184
+ }
185
+ //# sourceMappingURL=db-indexes.js.map
@@ -0,0 +1,23 @@
1
+ /** Kind of the connected database; '' before it connects. */
2
+ export declare function connectedDbKind(): string;
3
+ /** Kind the configuration names, known before the database connects. */
4
+ export declare function configuredDbKind(): string;
5
+ /** Dialect of the hand-written bulk statements. */
6
+ export type BulkSqlKind = 'postgres' | 'sqlite';
7
+ /** The bulk dialect of `kind`; null for a database the statements are not written for. */
8
+ export declare function bulkSqlKind(kind?: string): BulkSqlKind | null;
9
+ /** A column of a JSON fill record and its PostgreSQL type. */
10
+ export type FillColumn = [column: string, pgType: string];
11
+ export interface JsonFillSpec {
12
+ table: string;
13
+ /** Key columns, matched between the table row `t` and the record `v`. */
14
+ keys: FillColumn[];
15
+ /** Further columns the records carry. */
16
+ values: FillColumn[];
17
+ /** SET list; refers to the table as `t` and to the record as `v`. */
18
+ set: string;
19
+ /** Extra condition on `t`. */
20
+ where?: string;
21
+ }
22
+ export declare function jsonFillUpdate(kind: BulkSqlKind, spec: JsonFillSpec): string;
23
+ //# sourceMappingURL=db-kind.d.ts.map
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.connectedDbKind = connectedDbKind;
7
+ exports.configuredDbKind = configuredDbKind;
8
+ exports.bulkSqlKind = bulkSqlKind;
9
+ exports.jsonFillUpdate = jsonFillUpdate;
10
+ const cds_1 = __importDefault(require("@sap/cds"));
11
+ /** Kind of the connected database; '' before it connects. */
12
+ function connectedDbKind() {
13
+ return cds_1.default.db?.kind ?? '';
14
+ }
15
+ /** Kind the configuration names, known before the database connects. */
16
+ function configuredDbKind() {
17
+ const db = cds_1.default.env.requires?.db;
18
+ return typeof db?.kind === 'string' ? db.kind : '';
19
+ }
20
+ /** The bulk dialect of `kind`; null for a database the statements are not written for. */
21
+ function bulkSqlKind(kind = connectedDbKind()) {
22
+ if (kind === 'postgres')
23
+ return 'postgres';
24
+ if (kind === 'sqlite' || kind === 'better-sqlite')
25
+ return 'sqlite';
26
+ return null;
27
+ }
28
+ // One UPDATE that joins a JSON array of records on the key, bound as the single parameter.
29
+ // The record fields are the column names in lower case.
30
+ function jsonFillUpdate(kind, spec) {
31
+ const columns = [...spec.keys, ...spec.values];
32
+ const extra = spec.where ? ` AND ${spec.where}` : '';
33
+ if (kind === 'postgres') {
34
+ const record = columns.map(([c, type]) => `${c.toLowerCase()} ${type}`).join(', ');
35
+ const match = spec.keys.map(([c]) => `t.${c} = v.${c.toLowerCase()}`).join(' AND ');
36
+ return `UPDATE ${spec.table} AS t SET ${spec.set} FROM json_to_recordset($1::json) AS v(${record}) WHERE ${match}${extra}`;
37
+ }
38
+ const record = columns.map(([c]) => `json_extract(value, '$.${c.toLowerCase()}') AS ${c}`).join(', ');
39
+ const match = spec.keys.map(([c]) => `t.${c} = v.${c}`).join(' AND ');
40
+ return `UPDATE ${spec.table} AS t SET ${spec.set} FROM (SELECT ${record} FROM json_each(?)) AS v WHERE ${match}${extra}`;
41
+ }
42
+ //# sourceMappingURL=db-kind.js.map
@@ -0,0 +1,20 @@
1
+ /** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
2
+ export declare function stripNulStrings<T>(row: T): T;
3
+ /** Sanitise a row array for the database; cheap when nothing needs changing. */
4
+ export declare function sanitizeRows<T>(rows: T[]): T[];
5
+ /** The slice of a db-service request the sanitizer looks at (structural, so tests can fake it). */
6
+ export interface DbWriteRequest {
7
+ query?: unknown;
8
+ target?: {
9
+ name?: string;
10
+ } | null;
11
+ }
12
+ /** `before` handler for the db service: strips U+0000 from INSERT / UPSERT / UPDATE rows in place. */
13
+ export declare function sanitizeDbRequest(req: DbWriteRequest): void;
14
+ interface HookableService {
15
+ before(event: string | string[], handler: (req: DbWriteRequest) => void): unknown;
16
+ }
17
+ /** Hooks the sanitizer into the database service once. Returns true when this call installed it. */
18
+ export declare function installDbSanitizer(db?: HookableService | undefined): boolean;
19
+ export {};
20
+ //# sourceMappingURL=db-sanitize.d.ts.map
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.stripNulStrings = stripNulStrings;
7
+ exports.sanitizeRows = sanitizeRows;
8
+ exports.sanitizeDbRequest = sanitizeDbRequest;
9
+ exports.installDbSanitizer = installDbSanitizer;
10
+ const cds_1 = __importDefault(require("@sap/cds"));
11
+ // Strips U+0000 from every row this plugin writes. PostgreSQL cannot store NUL in text,
12
+ // and one NUL fails a whole bulk write.
13
+ /** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
14
+ function stripNulStrings(row) {
15
+ if (typeof row === 'string')
16
+ return (row.includes('\u0000') ? row.replaceAll('\u0000', '') : row);
17
+ if (row === null || typeof row !== 'object' || Buffer.isBuffer(row))
18
+ return row;
19
+ if (Array.isArray(row)) {
20
+ let out = null;
21
+ for (let i = 0; i < row.length; i++) {
22
+ const v = stripNulStrings(row[i]);
23
+ if (v !== row[i]) {
24
+ out ??= [...row];
25
+ out[i] = v;
26
+ }
27
+ }
28
+ return (out ?? row);
29
+ }
30
+ let out = null;
31
+ for (const [k, v] of Object.entries(row)) {
32
+ const nv = stripNulStrings(v);
33
+ if (nv !== v) {
34
+ out ??= { ...row };
35
+ out[k] = nv;
36
+ }
37
+ }
38
+ return (out ?? row);
39
+ }
40
+ /** Sanitise a row array for the database; cheap when nothing needs changing. */
41
+ function sanitizeRows(rows) {
42
+ let out = null;
43
+ for (let i = 0; i < rows.length; i++) {
44
+ const r = stripNulStrings(rows[i]);
45
+ if (r !== rows[i]) {
46
+ out ??= [...rows];
47
+ out[i] = r;
48
+ }
49
+ }
50
+ return out ?? rows;
51
+ }
52
+ /** Only this plugin's entities are rewritten; a consumer's own data is never touched. */
53
+ const OWN_NAMESPACE = 'odatano.cardano.';
54
+ /** `before` handler for the db service: strips U+0000 from INSERT / UPSERT / UPDATE rows in place. */
55
+ function sanitizeDbRequest(req) {
56
+ if (!req.target?.name?.startsWith(OWN_NAMESPACE))
57
+ return;
58
+ const q = req.query;
59
+ if (!q || typeof q !== 'object')
60
+ return;
61
+ const ins = q.INSERT;
62
+ if (ins && Array.isArray(ins.entries))
63
+ ins.entries = sanitizeRows(ins.entries);
64
+ const ups = q.UPSERT;
65
+ if (ups && Array.isArray(ups.entries))
66
+ ups.entries = sanitizeRows(ups.entries);
67
+ const upd = q.UPDATE;
68
+ if (upd?.data && typeof upd.data === 'object')
69
+ upd.data = stripNulStrings(upd.data);
70
+ }
71
+ const installed = new WeakSet();
72
+ /** Hooks the sanitizer into the database service once. Returns true when this call installed it. */
73
+ function installDbSanitizer(db = cds_1.default.db) {
74
+ if (!db || typeof db.before !== 'function' || installed.has(db))
75
+ return false;
76
+ db.before(['CREATE', 'UPSERT', 'UPDATE'], sanitizeDbRequest);
77
+ installed.add(db);
78
+ return true;
79
+ }
80
+ //# sourceMappingURL=db-sanitize.js.map
@@ -0,0 +1,6 @@
1
+ import type { JSONValue } from './types';
2
+ /** JSON.stringify without a replacer. Big integers are written as plain digits. */
3
+ export declare function stringifyJson(root: unknown): string;
4
+ /** JSON.parse with long integer literals as bigint. No key rewrite and no field-specific rule. */
5
+ export declare function parseJson(text: string): JSONValue;
6
+ //# sourceMappingURL=deep-json.d.ts.map
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringifyJson = stringifyJson;
4
+ exports.parseJson = parseJson;
5
+ const native = JSON;
6
+ /** The Ogmios client's rule: an integer literal longer than 15 characters is read as bigint. */
7
+ const isBigLiteral = (src) => src.length > 15 && /^-?\d+$/.test(src);
8
+ /** Scalar text of a value, or undefined for what JSON leaves out (undefined, functions, symbols). */
9
+ function scalar(v) {
10
+ if (v === null)
11
+ return 'null';
12
+ switch (typeof v) {
13
+ case 'string': return JSON.stringify(v);
14
+ case 'number': return Number.isFinite(v) ? String(v) : 'null';
15
+ case 'bigint': return v.toString();
16
+ case 'boolean': return v ? 'true' : 'false';
17
+ default: return undefined;
18
+ }
19
+ }
20
+ // only objects are asked for toJSON; a bigint keeps its digits even with a toJSON polyfill
21
+ function withToJson(v, key) {
22
+ if (typeof v !== 'object' || v === null)
23
+ return v;
24
+ const toJSON = v.toJSON;
25
+ const r = typeof toJSON === 'function' ? toJSON.call(v, key) : v;
26
+ // a boxed primitive is written as the primitive, as JSON.stringify does
27
+ return r instanceof Number || r instanceof String || r instanceof Boolean || r instanceof BigInt ? r.valueOf() : r;
28
+ }
29
+ // a boxed BigInt is unboxed here, before the writer rejects it as a bigint
30
+ function replaceBigInt(_key, value) {
31
+ const v = value instanceof BigInt ? value.valueOf() : value;
32
+ return typeof v === 'bigint' ? native.rawJSON(v.toString()) : v;
33
+ }
34
+ /** JSON.stringify without a replacer. Big integers are written as plain digits. */
35
+ function stringifyJson(root) {
36
+ // a toJSON on BigInt.prototype (a common polyfill) would quote the digits before the replacer sees them
37
+ if (!('toJSON' in BigInt.prototype)) {
38
+ try {
39
+ const text = JSON.stringify(root, replaceBigInt);
40
+ if (text === undefined)
41
+ throw new TypeError('undefined has no JSON text');
42
+ return text;
43
+ }
44
+ catch (err) {
45
+ if (!(err instanceof RangeError))
46
+ throw err;
47
+ }
48
+ }
49
+ return stringifyJsonLoop(root);
50
+ }
51
+ function stringifyJsonLoop(root) {
52
+ let out = '';
53
+ const stack = [];
54
+ const open = new Set(); // containers on the current path, to refuse cycles like JSON.stringify
55
+ // writes a value; containers are pushed and written by the loop
56
+ const emit = (v, inArray) => {
57
+ if (typeof v === 'object' && v !== null) {
58
+ if (open.has(v))
59
+ throw new TypeError('Converting circular structure to JSON');
60
+ open.add(v);
61
+ if (Array.isArray(v)) {
62
+ out += '[';
63
+ stack.push({ kind: 'array', value: v, i: 0 });
64
+ }
65
+ else {
66
+ out += '{';
67
+ stack.push({ kind: 'object', value: v, keys: Object.keys(v), i: 0, wrote: false });
68
+ }
69
+ return true;
70
+ }
71
+ const s = scalar(v);
72
+ if (s === undefined) {
73
+ if (!inArray)
74
+ return false;
75
+ out += 'null';
76
+ return true;
77
+ }
78
+ out += s;
79
+ return true;
80
+ };
81
+ if (!emit(withToJson(root, ''), false))
82
+ throw new TypeError('undefined has no JSON text');
83
+ while (stack.length > 0) {
84
+ const top = stack[stack.length - 1];
85
+ if (top.kind === 'array') {
86
+ if (top.i >= top.value.length) {
87
+ out += ']';
88
+ open.delete(top.value);
89
+ stack.pop();
90
+ continue;
91
+ }
92
+ if (top.i > 0)
93
+ out += ',';
94
+ const i = top.i++;
95
+ emit(withToJson(top.value[i], String(i)), true);
96
+ }
97
+ else {
98
+ if (top.i >= top.keys.length) {
99
+ out += '}';
100
+ open.delete(top.value);
101
+ stack.pop();
102
+ continue;
103
+ }
104
+ const key = top.keys[top.i++];
105
+ const v = withToJson(top.value[key], key);
106
+ if ((typeof v !== 'object' || v === null) && scalar(v) === undefined)
107
+ continue;
108
+ out += (top.wrote ? ',' : '') + JSON.stringify(key) + ':';
109
+ top.wrote = true;
110
+ emit(v, false);
111
+ }
112
+ }
113
+ return out;
114
+ }
115
+ function reviveBigInt(_key, value, context) {
116
+ return typeof value === 'number' && context?.source !== undefined && isBigLiteral(context.source)
117
+ ? BigInt(context.source)
118
+ : value;
119
+ }
120
+ /** JSON.parse with long integer literals as bigint. No key rewrite and no field-specific rule. */
121
+ function parseJson(text) {
122
+ try {
123
+ return native.parse(text, reviveBigInt);
124
+ }
125
+ catch (err) {
126
+ if (!(err instanceof RangeError))
127
+ throw err;
128
+ return parseJsonLoop(text);
129
+ }
130
+ }
131
+ const NUMBER = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/y;
132
+ // JSON.parse checks the string body, including raw control characters
133
+ const STRING = /"(?:[^"\\]|\\.)*"/y;
134
+ const SPACE = /[ \t\n\r]*/y;
135
+ function parseJsonLoop(text) {
136
+ let pos = 0;
137
+ const fail = (what) => { throw new SyntaxError(`${what} in JSON at position ${pos}`); };
138
+ const skip = () => { SPACE.lastIndex = pos; SPACE.exec(text); pos = SPACE.lastIndex; };
139
+ const match = (re) => {
140
+ re.lastIndex = pos;
141
+ const m = re.exec(text);
142
+ if (!m)
143
+ return null;
144
+ pos = re.lastIndex;
145
+ return m[0];
146
+ };
147
+ const stack = [];
148
+ let result;
149
+ let done = false;
150
+ const put = (v) => {
151
+ const top = stack[stack.length - 1];
152
+ if (!top) {
153
+ result = v;
154
+ done = true;
155
+ return;
156
+ }
157
+ if (top.kind === 'array')
158
+ top.value.push(v);
159
+ else {
160
+ // an own property, as JSON.parse makes it, even for the key "__proto__"
161
+ if (top.key === '__proto__')
162
+ Object.defineProperty(top.value, top.key, { value: v, writable: true, enumerable: true, configurable: true });
163
+ else
164
+ top.value[top.key] = v;
165
+ top.key = null;
166
+ }
167
+ };
168
+ // after a value inside a container: a comma or the closing bracket
169
+ const close = () => {
170
+ while (stack.length > 0) {
171
+ skip();
172
+ const top = stack[stack.length - 1];
173
+ const c = text[pos];
174
+ if (c === ',') {
175
+ pos++;
176
+ return;
177
+ }
178
+ if ((top.kind === 'array' && c === ']') || (top.kind === 'object' && c === '}')) {
179
+ pos++;
180
+ stack.pop();
181
+ put(top.value);
182
+ continue;
183
+ }
184
+ fail(`Unexpected ${c === undefined ? 'end' : `token ${c}`}`);
185
+ }
186
+ };
187
+ while (!done) {
188
+ skip();
189
+ const top = stack[stack.length - 1];
190
+ if (top?.kind === 'object' && top.key === null) {
191
+ const k = match(STRING) ?? fail('Expected property name');
192
+ skip();
193
+ if (text[pos] !== ':')
194
+ fail('Expected colon');
195
+ pos++;
196
+ top.key = JSON.parse(k);
197
+ continue;
198
+ }
199
+ const c = text[pos];
200
+ if (c === '[' || c === '{') {
201
+ pos++;
202
+ skip();
203
+ const empty = text[pos] === (c === '[' ? ']' : '}');
204
+ if (empty) {
205
+ pos++;
206
+ put(c === '[' ? [] : {});
207
+ }
208
+ else {
209
+ stack.push(c === '[' ? { kind: 'array', value: [] } : { kind: 'object', value: {}, key: null });
210
+ continue;
211
+ }
212
+ }
213
+ else if (c === '"') {
214
+ put(JSON.parse(match(STRING) ?? fail('Bad string')));
215
+ }
216
+ else if (text.startsWith('true', pos)) {
217
+ pos += 4;
218
+ put(true);
219
+ }
220
+ else if (text.startsWith('false', pos)) {
221
+ pos += 5;
222
+ put(false);
223
+ }
224
+ else if (text.startsWith('null', pos)) {
225
+ pos += 4;
226
+ put(null);
227
+ }
228
+ else {
229
+ const n = match(NUMBER) ?? fail(`Unexpected ${c === undefined ? 'end' : `token ${c}`}`);
230
+ put(isBigLiteral(n) ? BigInt(n) : Number(n));
231
+ }
232
+ if (!done)
233
+ close();
234
+ }
235
+ skip();
236
+ if (pos < text.length)
237
+ fail(`Unexpected token ${text[pos]}`);
238
+ return result;
239
+ }
240
+ //# sourceMappingURL=deep-json.js.map
@@ -0,0 +1,41 @@
1
+ /** none: never started in this process. cancelled: stopped on request, the work done so far is kept. */
2
+ export type RunStatus = 'none' | 'running' | 'done' | 'failed' | 'cancelled';
3
+ export interface RunLifecycle {
4
+ status: RunStatus;
5
+ startedAt: string | null;
6
+ finishedAt: string | null;
7
+ error: string | null;
8
+ }
9
+ export interface RunControl<P> {
10
+ /** Records progress of this run. */
11
+ progress(p: Partial<P>): void;
12
+ /** True once the run was asked to stop. */
13
+ shouldStop(): boolean;
14
+ }
15
+ /** What a start hands back once its checks passed: the work, and the answer to the caller. */
16
+ export interface PreparedRun<P, A> {
17
+ initial?: Partial<P>;
18
+ run: (ctl: RunControl<P>) => Promise<Partial<P> | void>;
19
+ answer: A;
20
+ /** Name in the log line of a failure; default the run's own label. */
21
+ label?: string;
22
+ }
23
+ export declare class DetachedRun<P extends object> {
24
+ readonly label: string;
25
+ private readonly idle;
26
+ /** Fields shown as text, like the Int64 values of the other answers. */
27
+ private readonly textFields;
28
+ private state;
29
+ private stopRequested;
30
+ private readonly logger;
31
+ constructor(label: string, idle: P,
32
+ /** Fields shown as text, like the Int64 values of the other answers. */
33
+ textFields?: ReadonlyArray<keyof P>);
34
+ isBusy(): boolean;
35
+ /** The status fields of the last run; text fields as strings. */
36
+ snapshot(): Record<string, unknown>;
37
+ start<A>(prepare: () => Promise<PreparedRun<P, A>> | PreparedRun<P, A>): Promise<A>;
38
+ /** Asks a running run to stop at its next check. False when nothing runs. */
39
+ cancel(): boolean;
40
+ }
41
+ //# sourceMappingURL=detached-run.d.ts.map