@odatano/core 2.0.0-rc.11 → 2.0.0-rc.13

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.
@@ -1,5 +1,5 @@
1
1
  import { Transaction as TransactionProviderData, Address as AddressProviderData, UTxO as UtxosProviderData, TxInputLine as TxInputProviderData, TxOutputLine as TxOutputProviderData, Amount as AmountProviderData, NetworkInformation as NetworkInfoProviderData, BlockData as BlockProviderData, EpochData as EpochProviderData, MetadataLabelTx as MetadataLabelTxProviderData, PoolData as PoolProviderData, DrepData as DrepProviderData, AccountData as AccountProviderData, AssetInfo as AssetInfoProviderData, AssetHistoryEntry as AssetHistoryEntryProviderData, TxBuildResult as TransactionBuildResult, LedgerProtocolParameters as ProtocolParameters } from './types';
2
- import { Address as AddressRow, AddressAsset as AddressAssetRow, AddressUTxO as AddressUTxORow, UTxOAsset as UTxOAssetRow, Transaction as TransactionRow, TransactionInput as TransactionInputRow, TransactionInputAsset as TransactionInputAssetRow, TransactionOutput as TransactionOutputRow, TransactionOutputAsset as TransactionOutputAssetRow, NetworkInformation as NetworkInfoRow, TransactionMetadata as TransactionMetadataRow, Block as BlockRow, Epoch as EpochRow, Pool as PoolRow, Drep as DrepRow, Asset as AssetRow, AssetHistory as AssetHistoryRow, Account as AccountRow, LedgerProtocolParameter as ProtocolParameterRow, AddressTransaction as AddressTransactionRow } from '#cds-models/CardanoODataService';
2
+ import { Address as AddressRow, AddressAsset as AddressAssetRow, AddressUTxO as AddressUTxORow, UTxOAsset as UTxOAssetRow, Transaction as TransactionRow, TransactionInput as TransactionInputRow, TransactionInputAsset as TransactionInputAssetRow, TransactionOutput as TransactionOutputRow, TransactionOutputAsset as TransactionOutputAssetRow, NetworkInformation as NetworkInfoRow, TransactionMetadata as TransactionMetadataRow, Block as BlockRow, Epoch as EpochRow, Pool as PoolRow, Drep as DrepRow, PoolEpochSnapshot as PoolEpochSnapshotRow, DrepEpochSnapshot as DrepEpochSnapshotRow, Asset as AssetRow, AssetHistory as AssetHistoryRow, Account as AccountRow, LedgerProtocolParameter as ProtocolParameterRow, AddressTransaction as AddressTransactionRow } from '#cds-models/CardanoODataService';
3
3
  import type { TransactionBuild as TransactionBuildRow, TransactionBuildInput as TransactionBuildInputRow, TransactionBuildOutput as TransactionBuildOutputRow, TransactionSubmission as TransactionSubmissionRow, AddressTransactionBuild as AddressTransactionBuildRow } from '#cds-models/CardanoTransactionService';
4
4
  import type { AddressSigningRequest as AddressSigningRequestRow } from '#cds-models/CardanoSignService';
5
5
  import type { Request } from '@sap/cds';
@@ -131,6 +131,31 @@ export declare function mapTransactionMetadata(providerLabels: MetadataLabelTxPr
131
131
  * (the caller skips the row — a NaN key would fail the whole bulk write)
132
132
  */
133
133
  export declare function metadataIdFor(label: string | number): number | string | null;
134
+ /**
135
+ * Map a pool observation at an epoch boundary into a snapshot row. Unlike mapPool() this
136
+ * carries no temporal validity: the row is dated by (epoch, snapshotSlot) and stays valid
137
+ * forever, because it states what was true then, not what is cached now.
138
+ * @param providerPoolData pool data from provider
139
+ * @param epoch epoch the snapshot belongs to
140
+ * @param at slot and block time of the block that triggered the snapshot
141
+ * @returns {PoolEpochSnapshotRow} mapped snapshot row
142
+ */
143
+ export declare function mapPoolSnapshot(providerPoolData: PoolProviderData, epoch: number, at: {
144
+ slot: number;
145
+ time: number;
146
+ }): PoolEpochSnapshotRow;
147
+ /**
148
+ * Map a DRep observation at an epoch boundary into a snapshot row. Non-temporal, same
149
+ * reasoning as mapPoolSnapshot().
150
+ * @param providerDrepData drep data from provider
151
+ * @param epoch epoch the snapshot belongs to
152
+ * @param at slot and block time of the block that triggered the snapshot
153
+ * @returns {DrepEpochSnapshotRow} mapped snapshot row
154
+ */
155
+ export declare function mapDrepSnapshot(providerDrepData: DrepProviderData, epoch: number, at: {
156
+ slot: number;
157
+ time: number;
158
+ }): DrepEpochSnapshotRow;
134
159
  /**
135
160
  * Map Pool Data
136
161
  * Converts provider pool data into PoolRow format
@@ -148,6 +173,34 @@ export declare function mapPool(providerPoolData: PoolProviderData, max_age: num
148
173
  * @returns {AssetRow} mapped asset row
149
174
  */
150
175
  export declare function mapAsset(providerAssetInfo: AssetInfoProviderData, max_age: number): AssetRow;
176
+ /**
177
+ * Fixed validity stamp for a crawler-written bare `Assets` row. Epoch zero, so the row is
178
+ * born expired (hidden by CAP's temporal filter) and its `(validFrom, unit)` key can never
179
+ * collide with a real, wall-clock-stamped slice from mapAsset().
180
+ */
181
+ export declare const BARE_ASSET_STAMP = "1970-01-01T00:00:00.000Z";
182
+ /**
183
+ * Map a bare asset row from an asset unit alone — everything derivable without a provider
184
+ * call: policyId, assetNameHex, the decoded name and the CIP-14 fingerprint. Used by the
185
+ * crawler to keep the `Assets` catalogue complete for units it meets in a block, at zero
186
+ * network cost (FR "crawler coverage for analytics").
187
+ *
188
+ * The row is stamped as ALREADY EXPIRED (`validTo === validFrom`). That is deliberate: CAP's
189
+ * temporal filter hides it from OData reads, so the first keyed read still counts as a miss
190
+ * and the existing lazy path enriches it through indexAsset() with supply and registry data —
191
+ * while an analytics consumer reading the database directly already sees the full catalogue
192
+ * (and can exclude the placeholders with `validTo > validFrom`).
193
+ *
194
+ * Both stamps are the FIXED epoch sentinel, not `now`. `Assets` is temporal, so its primary
195
+ * key is `(validFrom, unit)`: a wall-clock stamp would make the same unit a new row on every
196
+ * sighting and could collide with a slice the lazy path writes in the same millisecond, which
197
+ * inside the crawler's block transaction means a failed block. With the sentinel the bare row
198
+ * is one fixed, idempotent row per unit that no `mapAsset()` slice can ever alias.
199
+ *
200
+ * @param unit asset unit (policyId + assetNameHex)
201
+ * @returns {AssetRow | null} bare row, or null when the unit is not a native asset unit
202
+ */
203
+ export declare function mapBareAsset(unit: string): AssetRow | null;
151
204
  /**
152
205
  * Map Asset History entries to row format. No temporal stamping — mint/burn
153
206
  * events are immutable; UPSERT keyed on (unit, txHash) is idempotent.
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BARE_ASSET_STAMP = void 0;
6
7
  exports.mapTransaction = mapTransaction;
7
8
  exports.mapTransactionInputs = mapTransactionInputs;
8
9
  exports.mapTransactionInputAssets = mapTransactionInputAssets;
@@ -18,8 +19,11 @@ exports.mapBlock = mapBlock;
18
19
  exports.mapEpoch = mapEpoch;
19
20
  exports.mapTransactionMetadata = mapTransactionMetadata;
20
21
  exports.metadataIdFor = metadataIdFor;
22
+ exports.mapPoolSnapshot = mapPoolSnapshot;
23
+ exports.mapDrepSnapshot = mapDrepSnapshot;
21
24
  exports.mapPool = mapPool;
22
25
  exports.mapAsset = mapAsset;
26
+ exports.mapBareAsset = mapBareAsset;
23
27
  exports.mapAssetHistory = mapAssetHistory;
24
28
  exports.mapDrep = mapDrep;
25
29
  exports.mapAccount = mapAccount;
@@ -43,6 +47,7 @@ const client_1 = require("@cardano-ogmios/client");
43
47
  const cardano_costmodels_ts_1 = require("@harmoniclabs/cardano-costmodels-ts");
44
48
  const logger = cds_1.default.log('mappers');
45
49
  const errors_1 = require("./errors");
50
+ const const_1 = require("./const");
46
51
  /**
47
52
  * Maximum age for cached/indexed data in milliseconds
48
53
  */
@@ -514,6 +519,55 @@ function metadataIdFor(label) {
514
519
  const safe = wrapped >= BigInt(Number.MIN_SAFE_INTEGER) && wrapped <= BigInt(Number.MAX_SAFE_INTEGER);
515
520
  return safe ? Number(wrapped) : wrapped.toString();
516
521
  }
522
+ /**
523
+ * Map a pool observation at an epoch boundary into a snapshot row. Unlike mapPool() this
524
+ * carries no temporal validity: the row is dated by (epoch, snapshotSlot) and stays valid
525
+ * forever, because it states what was true then, not what is cached now.
526
+ * @param providerPoolData pool data from provider
527
+ * @param epoch epoch the snapshot belongs to
528
+ * @param at slot and block time of the block that triggered the snapshot
529
+ * @returns {PoolEpochSnapshotRow} mapped snapshot row
530
+ */
531
+ function mapPoolSnapshot(providerPoolData, epoch, at) {
532
+ return {
533
+ poolId: providerPoolData.poolId,
534
+ epoch,
535
+ snapshotSlot: at.slot,
536
+ snapshotTime: at.time,
537
+ blocksMinted: providerPoolData.blocksMinted,
538
+ blocksEpoch: providerPoolData.blocksEpoch,
539
+ liveStake: providerPoolData.liveStake,
540
+ liveSize: Number(providerPoolData.liveSize),
541
+ liveSaturation: Number(providerPoolData.liveSaturation),
542
+ liveDelegators: providerPoolData.liveDelegators,
543
+ activeStake: providerPoolData.activeStake,
544
+ activeSize: Number(providerPoolData.activeSize),
545
+ pledge: providerPoolData.pledge,
546
+ margin: Number(providerPoolData.margin),
547
+ fixedCost: providerPoolData.fixedCost,
548
+ };
549
+ }
550
+ /**
551
+ * Map a DRep observation at an epoch boundary into a snapshot row. Non-temporal, same
552
+ * reasoning as mapPoolSnapshot().
553
+ * @param providerDrepData drep data from provider
554
+ * @param epoch epoch the snapshot belongs to
555
+ * @param at slot and block time of the block that triggered the snapshot
556
+ * @returns {DrepEpochSnapshotRow} mapped snapshot row
557
+ */
558
+ function mapDrepSnapshot(providerDrepData, epoch, at) {
559
+ return {
560
+ drepId: providerDrepData.drepId,
561
+ epoch,
562
+ snapshotSlot: at.slot,
563
+ snapshotTime: at.time,
564
+ amount: providerDrepData.amount,
565
+ hasScript: providerDrepData.hasScript,
566
+ lastActiveEpoch: providerDrepData.lastActiveEpoch,
567
+ retired: providerDrepData.retired,
568
+ expired: providerDrepData.expired,
569
+ };
570
+ }
517
571
  /**
518
572
  * Map Pool Data
519
573
  * Converts provider pool data into PoolRow format
@@ -584,6 +638,63 @@ function mapAsset(providerAssetInfo, max_age) {
584
638
  validTo,
585
639
  };
586
640
  }
641
+ /**
642
+ * Fixed validity stamp for a crawler-written bare `Assets` row. Epoch zero, so the row is
643
+ * born expired (hidden by CAP's temporal filter) and its `(validFrom, unit)` key can never
644
+ * collide with a real, wall-clock-stamped slice from mapAsset().
645
+ */
646
+ exports.BARE_ASSET_STAMP = '1970-01-01T00:00:00.000Z';
647
+ /**
648
+ * Map a bare asset row from an asset unit alone — everything derivable without a provider
649
+ * call: policyId, assetNameHex, the decoded name and the CIP-14 fingerprint. Used by the
650
+ * crawler to keep the `Assets` catalogue complete for units it meets in a block, at zero
651
+ * network cost (FR "crawler coverage for analytics").
652
+ *
653
+ * The row is stamped as ALREADY EXPIRED (`validTo === validFrom`). That is deliberate: CAP's
654
+ * temporal filter hides it from OData reads, so the first keyed read still counts as a miss
655
+ * and the existing lazy path enriches it through indexAsset() with supply and registry data —
656
+ * while an analytics consumer reading the database directly already sees the full catalogue
657
+ * (and can exclude the placeholders with `validTo > validFrom`).
658
+ *
659
+ * Both stamps are the FIXED epoch sentinel, not `now`. `Assets` is temporal, so its primary
660
+ * key is `(validFrom, unit)`: a wall-clock stamp would make the same unit a new row on every
661
+ * sighting and could collide with a slice the lazy path writes in the same millisecond, which
662
+ * inside the crawler's block transaction means a failed block. With the sentinel the bare row
663
+ * is one fixed, idempotent row per unit that no `mapAsset()` slice can ever alias.
664
+ *
665
+ * @param unit asset unit (policyId + assetNameHex)
666
+ * @returns {AssetRow | null} bare row, or null when the unit is not a native asset unit
667
+ */
668
+ function mapBareAsset(unit) {
669
+ // The canonical definition of a unit — 56 hex policy + 0..32 bytes of name, even length.
670
+ // Reusing it keeps the catalogue from inventing a second, looser notion of "asset unit"
671
+ // than isAssetUnit() enforces on the API surface.
672
+ if (!const_1.ASSET_UNIT_REGEX.test(unit))
673
+ return null;
674
+ const policyId = unit.slice(0, 56);
675
+ const assetNameHex = unit.slice(56);
676
+ return {
677
+ unit,
678
+ policyId,
679
+ assetNameHex,
680
+ // decodeAssetName falls back to the hex string for non-text and NUL-bearing names
681
+ assetName: assetNameHex.length > 0 ? decodeAssetName(assetNameHex) : '',
682
+ fingerprint: computeCip14Fingerprint(policyId, assetNameHex),
683
+ totalSupply: null,
684
+ mintOrBurnCount: null,
685
+ initialMintTxHash: null,
686
+ initialMintTime: null,
687
+ onchainMetadata: null,
688
+ registryName: null,
689
+ registryTicker: null,
690
+ registryDecimals: null,
691
+ registryDescription: null,
692
+ registryUrl: null,
693
+ registryLogo: null,
694
+ validFrom: exports.BARE_ASSET_STAMP,
695
+ validTo: exports.BARE_ASSET_STAMP,
696
+ };
697
+ }
587
698
  /**
588
699
  * Map Asset History entries to row format. No temporal stamping — mint/burn
589
700
  * events are immutable; UPSERT keyed on (unit, txHash) is idempotent.
@@ -68,8 +68,8 @@ export interface Transaction {
68
68
  /**
69
69
  * Phase-2 validity as the ledger applied it. True when the script phase failed: the
70
70
  * declared inputs and outputs were not applied, the collateral inputs were consumed and
71
- * only the collateral return was produced. Only the Ogmios chain-sync path reports it;
72
- * the historical backends leave it undefined.
71
+ * only the collateral return was produced. Reported by the Ogmios chain-sync path
72
+ * (`spends`) and by Blockfrost (`valid_contract`); Koios leaves it undefined.
73
73
  */
74
74
  spendsCollaterals?: boolean;
75
75
  /**
@@ -79,6 +79,14 @@ export interface Transaction {
79
79
  * charge then has to be derived from the resolved collateral inputs minus the return.
80
80
  */
81
81
  totalCollateral?: Lovelace | string | null;
82
+ /**
83
+ * Net mint/burn per asset unit as the ledger applied it, signed — a negative quantity is a
84
+ * burn. Ogmios (`mint`) and Koios (`assets_minted`) report it natively; Blockfrost has no
85
+ * such field and leaves it undefined, so the indexer derives the delta from the transaction's
86
+ * (fully resolved) input and output assets instead — which needs `isReference`/`isCollateral`
87
+ * and `spendsCollaterals` to be set on that path too. Never carries `lovelace`.
88
+ */
89
+ mint?: Amount[];
82
90
  /** Tx size in bytes; null when the source cannot provide it (Ogmios chain-sync). */
83
91
  size: number | null;
84
92
  blockTime: number;
@@ -202,6 +210,7 @@ export interface PoolData {
202
210
  blocksEpoch: number;
203
211
  liveStake: string;
204
212
  liveSize: number;
213
+ /** Fraction of the ideal (saturated) pool size, NOT percent: 0.7542 = 75.42 %. */
205
214
  liveSaturation: number;
206
215
  liveDelegators: number;
207
216
  activeStake: string;
@@ -20,7 +20,7 @@ export declare function validateJsonWithLimits(jsonString: string, fieldName: st
20
20
  */
21
21
  export declare function isTxHash(s: unknown): s is string;
22
22
  /**
23
- * Asset unit: concatenation of policy ID (56 hex chars) + asset name (0-128 hex chars)
23
+ * Asset unit: concatenation of policy ID (56 hex chars) + asset name (0-64 hex chars)
24
24
  * @param s - The raw value to validate against asset unit format
25
25
  * @returns { boolean } true if v is a valid asset unit false otherwise
26
26
  */
@@ -139,7 +139,7 @@ function isTxHash(s) {
139
139
  return typeof s === "string" && const_1.TX_HASH_REGEX.test(s);
140
140
  }
141
141
  /**
142
- * Asset unit: concatenation of policy ID (56 hex chars) + asset name (0-128 hex chars)
142
+ * Asset unit: concatenation of policy ID (56 hex chars) + asset name (0-64 hex chars)
143
143
  * @param s - The raw value to validate against asset unit format
144
144
  * @returns { boolean } true if v is a valid asset unit false otherwise
145
145
  */
@@ -147,7 +147,7 @@ function isAssetUnit(s) {
147
147
  if (typeof s !== "string")
148
148
  return false;
149
149
  const t = s.trim();
150
- // Regex ensures: 56-192 hex chars, even length, valid hex
150
+ // Regex ensures: 56-120 hex chars, even length, valid hex
151
151
  return const_1.ASSET_UNIT_REGEX.test(t);
152
152
  }
153
153
  /**