Skip to content

Commit 22e6824

Browse files
refactor!: hoist bufferChainSyncEvent to projection package
BREAKING CHANGE: OgmiosObservableCardanoNode and bufferChainSyncEvent were moved from core package to projection package
1 parent e8f3f0b commit 22e6824

File tree

11 files changed

+59
-57
lines changed

11 files changed

+59
-57
lines changed

packages/core/src/CardanoNode/types/CardanoNode.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import type { Block, Lovelace, PoolId, Tip, VrfVkHex } from '../../Cardano';
12
import type { HealthCheckResponse } from '../../Provider';
2-
import type { Lovelace, PoolId, VrfVkHex } from '../../Cardano';
33
import type { Milliseconds } from '../../util';
44

55
export interface EraSummary {
@@ -48,3 +48,38 @@ export interface CardanoNode {
4848
*/
4949
healthCheck(): Promise<HealthCheckResponse>;
5050
}
51+
52+
// Similar to Ogmios.Point, but using Cardano.BlockId opaque string for hash
53+
export type Point = Pick<Tip, 'hash' | 'slot'>;
54+
export type Origin = 'origin';
55+
export type TipOrOrigin = Tip | Origin;
56+
export type PointOrOrigin = Point | Origin;
57+
export type Intersection = {
58+
point: PointOrOrigin;
59+
tip: TipOrOrigin;
60+
};
61+
62+
export enum ChainSyncEventType {
63+
RollForward,
64+
RollBackward
65+
}
66+
67+
export type RequestNext = () => void;
68+
69+
export interface WithRequestNext {
70+
requestNext: RequestNext;
71+
}
72+
73+
export interface ChainSyncRollForward extends WithRequestNext {
74+
tip: Tip;
75+
eventType: ChainSyncEventType.RollForward;
76+
block: Block;
77+
}
78+
79+
export interface ChainSyncRollBackward extends WithRequestNext {
80+
eventType: ChainSyncEventType.RollBackward;
81+
point: PointOrOrigin;
82+
tip: TipOrOrigin;
83+
}
84+
85+
export type ChainSyncEvent = ChainSyncRollForward | ChainSyncRollBackward;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './CardanoNode';
22
export * from './CardanoNodeErrors';
3-
export * from './ObservableCardanoNode';

packages/ogmios/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@cardano-ogmios/schema": "6.5.0",
5959
"@cardano-sdk/core": "workspace:~",
6060
"@cardano-sdk/crypto": "workspace:~",
61+
"@cardano-sdk/projection": "workspace:~",
6162
"@cardano-sdk/util": "workspace:~",
6263
"backoff-rxjs": "^7.0.0",
6364
"buffer": "5.7.1",

packages/ogmios/src/CardanoNode/OgmiosObservableCardanoNode/OgmiosObservableCardanoNode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import {
88
GeneralCardanoNodeErrorCode,
99
HealthCheckResponse,
1010
Milliseconds,
11-
ObservableCardanoNode,
12-
ObservableChainSync,
1311
PointOrOrigin,
1412
StakeDistribution,
1513
StateQueryErrorCode
@@ -49,6 +47,7 @@ import {
4947
withCoreCardanoNodeError
5048
} from '../queries';
5149
import isEqual from 'lodash/isEqual.js';
50+
import type { ObservableCardanoNode, ObservableChainSync } from '@cardano-sdk/projection';
5251
import type { Serialization } from '@cardano-sdk/core';
5352

5453
const ogmiosToCoreIntersection = (intersection: ChainSynchronization.Intersection) => ({

packages/projection/src/Bootstrap/fromCardanoNode.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
/* eslint-disable max-len */
22
/* eslint-disable jsdoc/valid-types */
33
/* eslint-disable @typescript-eslint/no-explicit-any */
4-
import {
5-
Cardano,
6-
ChainSyncEventType,
7-
Intersection,
8-
ObservableCardanoNode,
9-
ObservableChainSync,
10-
TipOrOrigin
11-
} from '@cardano-sdk/core';
4+
import { Cardano, ChainSyncEventType, Intersection, TipOrOrigin } from '@cardano-sdk/core';
125
import { Logger } from 'ts-log';
136
import { Observable, concat, defer, map, mergeMap, noop, of, switchMap, take, takeWhile, tap } from 'rxjs';
7+
import { ObservableCardanoNode, ObservableChainSync } from '../ObservableCardanoNode';
148
import { ProjectionEvent, StabilityWindowBuffer, UnifiedExtChainSyncEvent } from '../types';
159
import { contextLogger } from '@cardano-sdk/util';
1610
import { pointDescription } from '../util';

packages/core/src/CardanoNode/types/ObservableCardanoNode.ts renamed to packages/projection/src/ObservableCardanoNode.ts

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,15 @@
1-
import { bufferChainSyncEvent } from '../util/bufferChainSyncEvent';
2-
import type { Cardano, HealthCheckResponse, Serialization } from '../..';
3-
import type { EraSummary } from './CardanoNode';
1+
import { bufferChainSyncEvent } from './bufferChainSyncEvent';
2+
import type {
3+
Cardano,
4+
ChainSyncEvent,
5+
EraSummary,
6+
HealthCheckResponse,
7+
Intersection,
8+
PointOrOrigin,
9+
Serialization
10+
} from '@cardano-sdk/core';
411
import type { Observable } from 'rxjs';
512

6-
// Similar to Ogmios.Point, but using Cardano.BlockId opaque string for hash
7-
export type Point = Pick<Cardano.Tip, 'hash' | 'slot'>;
8-
export type Origin = 'origin';
9-
export type TipOrOrigin = Cardano.Tip | Origin;
10-
export type PointOrOrigin = Point | Origin;
11-
export type Intersection = {
12-
point: PointOrOrigin;
13-
tip: TipOrOrigin;
14-
};
15-
16-
export enum ChainSyncEventType {
17-
RollForward,
18-
RollBackward
19-
}
20-
21-
export type RequestNext = () => void;
22-
23-
export interface WithRequestNext {
24-
requestNext: RequestNext;
25-
}
26-
27-
export interface ChainSyncRollForward extends WithRequestNext {
28-
tip: Cardano.Tip;
29-
eventType: ChainSyncEventType.RollForward;
30-
block: Cardano.Block;
31-
}
32-
33-
export interface ChainSyncRollBackward extends WithRequestNext {
34-
eventType: ChainSyncEventType.RollBackward;
35-
point: PointOrOrigin;
36-
tip: TipOrOrigin;
37-
}
38-
39-
export type ChainSyncEvent = ChainSyncRollForward | ChainSyncRollBackward;
40-
4113
export interface ObservableChainSync {
4214
/** Observable that can be used to subscribe to Chain Sync events from `intersection`. */
4315
chainSync$: Observable<ChainSyncEvent>;

packages/core/src/CardanoNode/util/bufferChainSyncEvent.ts renamed to packages/projection/src/bufferChainSyncEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Observable } from 'rxjs';
2-
import { RequestNext, WithRequestNext } from '../types';
2+
import { RequestNext, WithRequestNext } from '@cardano-sdk/core';
33

44
export const bufferChainSyncEvent =
55
<T extends WithRequestNext>(length: number) =>

packages/projection/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ export * as InMemory from './InMemory';
22
export * as Bootstrap from './Bootstrap';
33
export * from './operators';
44
export * from './types';
5+
export * from './bufferChainSyncEvent';
6+
export * from './ObservableCardanoNode';

packages/projection/src/operators/withNetworkInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ObservableCardanoNode } from '@cardano-sdk/core';
1+
import { ObservableCardanoNode } from '../ObservableCardanoNode';
22
import { WithNetworkInfo } from '../types';
33
import { combineLatest, map, take } from 'rxjs';
44
import { withStaticContext } from './withStaticContext';

packages/core/test/CardanoNode/util/bufferChainSyncEvent.test.ts renamed to packages/projection/test/bufferChainSyncEvent.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* eslint-disable sonarjs/no-duplicate-string */
2-
import { BlockId, BlockNo, Slot, Tip } from '../../../src/Cardano';
3-
import { ChainSyncEvent, ChainSyncEventType, RequestNext } from '../../../src';
2+
import { Cardano, ChainSyncEvent, ChainSyncEventType, RequestNext } from '@cardano-sdk/core';
43
import { Observable, Subject, Subscription } from 'rxjs';
5-
import { bufferChainSyncEvent } from '../../../src/CardanoNode/util/bufferChainSyncEvent';
4+
import { bufferChainSyncEvent } from '../src/bufferChainSyncEvent';
65

76
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
87

@@ -20,7 +19,7 @@ class ChainSyncEventTestConsumer {
2019
complete: () => this.events.push('Consumer completed'),
2120
error: (error) => this.events.push(`Consumer error: ${error}`),
2221
next: (value) => {
23-
this.current = (value.tip as Tip).blockNo;
22+
this.current = (value.tip as Cardano.Tip).blockNo;
2423
this.events.push(`Got ${this.current}`);
2524
this.requestNext = value.requestNext;
2625
}
@@ -106,7 +105,7 @@ class ChainSyncEventTestProducer {
106105
requestNext: () => {
107106
this.canProduce = true;
108107
},
109-
tip: { blockNo: BlockNo(count), hash: '' as BlockId, slot: Slot(count) }
108+
tip: { blockNo: Cardano.BlockNo(count), hash: '' as Cardano.BlockId, slot: Cardano.Slot(count) }
110109
});
111110
}, 1);
112111
}

0 commit comments

Comments
 (0)