@xyo-network/xl1-protocol-sdk 1.17.2 → 1.17.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts +6 -0
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts.map +1 -0
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts +42 -0
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts.map +1 -0
- package/dist/neutral/CreatableProvider/CreatableProviderRegistry.d.ts +12 -0
- package/dist/neutral/CreatableProvider/CreatableProviderRegistry.d.ts.map +1 -0
- package/dist/neutral/CreatableProvider/LabeledCreatableProviderFactory.d.ts +12 -0
- package/dist/neutral/CreatableProvider/LabeledCreatableProviderFactory.d.ts.map +1 -0
- package/dist/neutral/CreatableProvider/ProviderFactory.d.ts +14 -0
- package/dist/neutral/CreatableProvider/ProviderFactory.d.ts.map +1 -0
- package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts +48 -0
- package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts.map +1 -0
- package/dist/neutral/CreatableProvider/ProviderFactoryLocatorInstance.d.ts +39 -0
- package/dist/neutral/CreatableProvider/ProviderFactoryLocatorInstance.d.ts.map +1 -0
- package/dist/neutral/CreatableProvider/index.d.ts +8 -0
- package/dist/neutral/CreatableProvider/index.d.ts.map +1 -0
- package/dist/neutral/block/hydrate/flattenHydratedBlock.d.ts +3 -1
- package/dist/neutral/block/hydrate/flattenHydratedBlock.d.ts.map +1 -1
- package/dist/neutral/config/Bridge.d.ts +27 -0
- package/dist/neutral/config/Bridge.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +12 -0
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/index.d.ts +1 -0
- package/dist/neutral/config/index.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +1 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +749 -212
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/map/AsyncMap.d.ts +36 -0
- package/dist/neutral/map/AsyncMap.d.ts.map +1 -0
- package/dist/neutral/map/MapType.d.ts +8 -7
- package/dist/neutral/map/MapType.d.ts.map +1 -1
- package/dist/neutral/map/SyncMap.d.ts +35 -0
- package/dist/neutral/map/SyncMap.d.ts.map +1 -0
- package/dist/neutral/map/index.d.ts +2 -2
- package/dist/neutral/map/index.d.ts.map +1 -1
- package/dist/neutral/model/Provider.d.ts +8 -0
- package/dist/neutral/model/Provider.d.ts.map +1 -0
- package/dist/neutral/model/index.d.ts +1 -0
- package/dist/neutral/model/index.d.ts.map +1 -1
- package/dist/neutral/primitives/rewardFromBlockNumber.d.ts.map +1 -1
- package/dist/neutral/provider/DataLake.d.ts +5 -1
- package/dist/neutral/provider/DataLake.d.ts.map +1 -1
- package/dist/neutral/provider/viewer/NetworkStake/NetworkStakeViewer.d.ts +4 -1
- package/dist/neutral/provider/viewer/NetworkStake/NetworkStakeViewer.d.ts.map +1 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/ByPositionViewer.d.ts +4 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/ByPositionViewer.d.ts.map +1 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/ByStakerViewer.d.ts +4 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/ByStakerViewer.d.ts.map +1 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/ByStepViewer.d.ts +4 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/ByStepViewer.d.ts.map +1 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/TotalViewer.d.ts +4 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/TotalViewer.d.ts.map +1 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/Viewer.d.ts +4 -1
- package/dist/neutral/provider/viewer/NetworkStake/Rewards/Viewer.d.ts.map +1 -1
- package/dist/neutral/provider/viewer/XyoViewer.d.ts +6 -3
- package/dist/neutral/provider/viewer/XyoViewer.d.ts.map +1 -1
- package/dist/neutral/services/Chain/ChainService.d.ts +1 -1
- package/dist/neutral/services/Chain/ChainService.d.ts.map +1 -1
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +11 -5
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +12 -6
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts.map +1 -1
- package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts +7 -3
- package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts.map +1 -1
- package/dist/neutral/simple/chain/SimpleChainViewer.d.ts +6 -3
- package/dist/neutral/simple/chain/SimpleChainViewer.d.ts.map +1 -1
- package/dist/neutral/simple/chainStake/SimpleChainStakeViewer.d.ts +6 -3
- package/dist/neutral/simple/chainStake/SimpleChainStakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/chainStakeEvents/SimpleChainStakeEventsViewer.d.ts +6 -3
- package/dist/neutral/simple/chainStakeEvents/SimpleChainStakeEventsViewer.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts +18 -0
- package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts.map +1 -0
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts +8 -7
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts +7 -15
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts +7 -4
- package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts.map +1 -1
- package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts +13 -5
- package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts.map +1 -1
- package/dist/neutral/transaction/hydrateTransaction.d.ts +2 -0
- package/dist/neutral/transaction/hydrateTransaction.d.ts.map +1 -1
- package/dist/neutral/viewers/AccountBalance.d.ts +4 -3
- package/dist/neutral/viewers/AccountBalance.d.ts.map +1 -1
- package/dist/neutral/viewers/Block.d.ts +4 -1
- package/dist/neutral/viewers/Block.d.ts.map +1 -1
- package/dist/neutral/viewers/BlockReward.d.ts +4 -1
- package/dist/neutral/viewers/BlockReward.d.ts.map +1 -1
- package/dist/neutral/viewers/Chain.d.ts +4 -1
- package/dist/neutral/viewers/Chain.d.ts.map +1 -1
- package/dist/neutral/viewers/ChainContract.d.ts +4 -1
- package/dist/neutral/viewers/ChainContract.d.ts.map +1 -1
- package/dist/neutral/viewers/ChainStakeViewer.d.ts +4 -1
- package/dist/neutral/viewers/ChainStakeViewer.d.ts.map +1 -1
- package/dist/neutral/viewers/Mempool.d.ts +4 -1
- package/dist/neutral/viewers/Mempool.d.ts.map +1 -1
- package/dist/neutral/viewers/NetworkStakeStepReward.d.ts +6 -1
- package/dist/neutral/viewers/NetworkStakeStepReward.d.ts.map +1 -1
- package/dist/neutral/viewers/Stake.d.ts +7 -3
- package/dist/neutral/viewers/Stake.d.ts.map +1 -1
- package/dist/neutral/viewers/StakeEvents.d.ts +4 -1
- package/dist/neutral/viewers/StakeEvents.d.ts.map +1 -1
- package/dist/neutral/viewers/StakeIntent.d.ts +4 -2
- package/dist/neutral/viewers/StakeIntent.d.ts.map +1 -1
- package/dist/neutral/viewers/StakeTotals.d.ts +4 -1
- package/dist/neutral/viewers/StakeTotals.d.ts.map +1 -1
- package/dist/neutral/viewers/StepStake.d.ts +4 -1
- package/dist/neutral/viewers/StepStake.d.ts.map +1 -1
- package/dist/neutral/viewers/StepViewer.d.ts +4 -2
- package/dist/neutral/viewers/StepViewer.d.ts.map +1 -1
- package/dist/neutral/viewers/TimeSync.d.ts +4 -1
- package/dist/neutral/viewers/TimeSync.d.ts.map +1 -1
- package/dist/neutral/viewers/TransferBalance.d.ts +5 -2
- package/dist/neutral/viewers/TransferBalance.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/CreatableProvider/AbstractCreatableProvider.ts +17 -0
- package/src/CreatableProvider/CreatableProvider.ts +68 -0
- package/src/CreatableProvider/CreatableProviderRegistry.ts +85 -0
- package/src/CreatableProvider/LabeledCreatableProviderFactory.ts +22 -0
- package/src/CreatableProvider/ProviderFactory.ts +59 -0
- package/src/CreatableProvider/ProviderFactoryLocator.ts +102 -0
- package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +47 -0
- package/src/CreatableProvider/index.ts +7 -0
- package/src/block/hydrate/flattenHydratedBlock.ts +19 -1
- package/src/config/Bridge.ts +101 -3
- package/src/config/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/map/AsyncMap.ts +32 -0
- package/src/map/MapType.ts +13 -7
- package/src/map/SyncMap.ts +32 -0
- package/src/map/index.ts +2 -2
- package/src/model/Provider.ts +15 -0
- package/src/model/index.ts +1 -0
- package/src/payloads/netBalancesForPayloads.ts +1 -1
- package/src/payloads/netSchemasForPayloads.ts +1 -1
- package/src/payloads/netTransfersForPayloads.ts +1 -1
- package/src/primitives/rewardFromBlockNumber.ts +3 -3
- package/src/provider/DataLake.ts +7 -1
- package/src/provider/viewer/NetworkStake/NetworkStakeViewer.ts +5 -1
- package/src/provider/viewer/NetworkStake/Rewards/ByPositionViewer.ts +6 -1
- package/src/provider/viewer/NetworkStake/Rewards/ByStakerViewer.ts +7 -1
- package/src/provider/viewer/NetworkStake/Rewards/ByStepViewer.ts +6 -1
- package/src/provider/viewer/NetworkStake/Rewards/TotalViewer.ts +6 -1
- package/src/provider/viewer/NetworkStake/Rewards/Viewer.ts +5 -1
- package/src/provider/viewer/XyoViewer.ts +9 -5
- package/src/services/Chain/ChainService.ts +1 -1
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +15 -11
- package/src/simple/block/SimpleBlockViewer.ts +12 -6
- package/src/simple/blockReward/SimpleBlockRewardViewer.ts +12 -8
- package/src/simple/chain/SimpleChainViewer.ts +11 -8
- package/src/simple/chainStake/SimpleChainStakeViewer.ts +14 -8
- package/src/simple/chainStakeEvents/SimpleChainStakeEventsViewer.ts +12 -7
- package/src/simple/datalake/AbstractSimpleDataLake.ts +64 -0
- package/src/simple/datalake/SimpleDataLakeRunner.ts +14 -11
- package/src/simple/datalake/SimpleDataLakeViewer.ts +15 -48
- package/src/simple/mempool/SimpleMempoolViewer.ts +11 -7
- package/src/simple/timesync/SimpleTimeSyncViewer.ts +20 -7
- package/src/summary/primitives/balances/balancesSummary.ts +3 -2
- package/src/summary/primitives/schemas/schemasSummary.ts +1 -2
- package/src/summary/primitives/transfers/transfersSummary.ts +3 -2
- package/src/transaction/hydrateTransaction.ts +18 -1
- package/src/viewers/AccountBalance.ts +8 -2
- package/src/viewers/Block.ts +6 -1
- package/src/viewers/BlockReward.ts +6 -1
- package/src/viewers/Chain.ts +6 -1
- package/src/viewers/ChainContract.ts +6 -1
- package/src/viewers/ChainStakeViewer.ts +6 -1
- package/src/viewers/Mempool.ts +6 -1
- package/src/viewers/NetworkStakeStepReward.ts +8 -1
- package/src/viewers/Stake.ts +9 -3
- package/src/viewers/StakeEvents.ts +6 -1
- package/src/viewers/StakeIntent.ts +5 -2
- package/src/viewers/StakeTotals.ts +6 -1
- package/src/viewers/StepStake.ts +6 -1
- package/src/viewers/StepViewer.ts +5 -2
- package/src/viewers/TimeSync.ts +6 -1
- package/src/viewers/TransferBalance.ts +7 -2
- package/dist/neutral/map/AsynchronousMap.d.ts +0 -15
- package/dist/neutral/map/AsynchronousMap.d.ts.map +0 -1
- package/dist/neutral/map/SynchronousMap.d.ts +0 -14
- package/dist/neutral/map/SynchronousMap.d.ts.map +0 -1
- package/src/map/AsynchronousMap.ts +0 -16
- package/src/map/SynchronousMap.ts +0 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepViewer.d.ts","sourceRoot":"","sources":["../../../src/viewers/StepViewer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAEzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"StepViewer.d.ts","sourceRoot":"","sources":["../../../src/viewers/StepViewer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAEzE,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAA;AAEzE,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,iBAAiB;IAGhC,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;IAErD,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAA;IAGtF,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;IAGlD,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;IAG7C,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;IAEnD,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,CAAA;IAGjF,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;CACxE;AAED,eAAO,MAAM,iBAAiB,EAAG,YAAqB,CAAA;AACtD,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAA;AAExD,MAAM,WAAW,UAAW,SAAQ,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB,CAAC;IAChF,OAAO,CAAC,EAAE,6BAA6B,CAAA;CACxC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Promisable } from '@xylabs/sdk-js';
|
|
2
2
|
import type { TimeDomain, TimePayload } from '@xyo-network/xl1-protocol';
|
|
3
|
+
import type { Provider } from '../model/index.ts';
|
|
3
4
|
export interface TimeSyncViewerMethods {
|
|
4
5
|
/** Convert time between different domains */
|
|
5
6
|
convertTime(fromDomain: TimeDomain, toDomain: TimeDomain, from: number): Promisable<number>;
|
|
@@ -10,6 +11,8 @@ export interface TimeSyncViewerMethods {
|
|
|
10
11
|
/** Create a TimePayload with the current time from all configured domains */
|
|
11
12
|
currentTimePayload(): Promisable<TimePayload>;
|
|
12
13
|
}
|
|
13
|
-
export
|
|
14
|
+
export declare const TimeSyncViewerMoniker: "TimeSyncViewer";
|
|
15
|
+
export type TimeSyncViewerMoniker = typeof TimeSyncViewerMoniker;
|
|
16
|
+
export interface TimeSyncViewer extends TimeSyncViewerMethods, Provider<TimeSyncViewerMoniker> {
|
|
14
17
|
}
|
|
15
18
|
//# sourceMappingURL=TimeSync.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeSync.d.ts","sourceRoot":"","sources":["../../../src/viewers/TimeSync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAExE,MAAM,WAAW,qBAAqB;IACpC,6CAA6C;IAC7C,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;IAE3F,8CAA8C;IAC9C,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAE7D,8CAA8C;IAC9C,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAA;IAE3E,6EAA6E;IAC7E,kBAAkB,IAAI,UAAU,CAAC,WAAW,CAAC,CAAA;CAC9C;AAED,MAAM,WAAW,cAAe,SAAQ,qBAAqB;CAAG"}
|
|
1
|
+
{"version":3,"file":"TimeSync.d.ts","sourceRoot":"","sources":["../../../src/viewers/TimeSync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAExE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD,MAAM,WAAW,qBAAqB;IACpC,6CAA6C;IAC7C,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;IAE3F,8CAA8C;IAC9C,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAE7D,8CAA8C;IAC9C,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAA;IAE3E,6EAA6E;IAC7E,kBAAkB,IAAI,UAAU,CAAC,WAAW,CAAC,CAAA;CAC9C;AAED,eAAO,MAAM,qBAAqB,EAAG,gBAAyB,CAAA;AAC9D,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAA;AAEhE,MAAM,WAAW,cAAe,SAAQ,qBAAqB,EAAE,QAAQ,CAAC,qBAAqB,CAAC;CAAG"}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import type { Address, Promisable } from '@xylabs/sdk-js';
|
|
2
2
|
import type { Signed } from '@xyo-network/boundwitness-model';
|
|
3
3
|
import type { AttoXL1, BlockBoundWitness, TransactionBoundWitness, Transfer, XL1BlockRange } from '@xyo-network/xl1-protocol';
|
|
4
|
+
import type { Provider } from '../model/index.ts';
|
|
4
5
|
export type TransferBalanceHistoryItem = [
|
|
5
6
|
Signed<BlockBoundWitness>,
|
|
6
7
|
Signed<TransactionBoundWitness> | null,
|
|
7
8
|
Transfer
|
|
8
9
|
];
|
|
9
|
-
export type TransferPair = [
|
|
10
|
+
export type TransferPair = [Address, Address];
|
|
10
11
|
export interface TransferBalancesViewerMethods {
|
|
11
12
|
transferBalances(address: Address[]): Promisable<Partial<Record<Address, Record<Address, AttoXL1>>>>;
|
|
12
13
|
transferBalancesHistories(address: Address[]): Promisable<Partial<Record<Address, Record<Address, TransferBalanceHistoryItem[]>>>>;
|
|
13
14
|
transferPairBalances(address: TransferPair[]): Promisable<Partial<Record<Address, Record<Address, AttoXL1>>>>;
|
|
14
15
|
transferPairBalancesHistories(address: TransferPair[]): Promisable<Partial<Record<Address, Record<Address, TransferBalanceHistoryItem[]>>>>;
|
|
15
16
|
}
|
|
16
|
-
export
|
|
17
|
+
export declare const TransferBalanceViewerMoniker: "TransferBalanceViewer";
|
|
18
|
+
export type TransferBalanceViewerMoniker = typeof TransferBalanceViewerMoniker;
|
|
19
|
+
export interface TransferBalanceViewer extends TransferBalancesViewerMethods, Provider<TransferBalanceViewerMoniker> {
|
|
17
20
|
transferBalance(address: Address): Promisable<AttoXL1>;
|
|
18
21
|
transferBalanceHistory(address: Address, range?: XL1BlockRange): Promisable<TransferBalanceHistoryItem[]>;
|
|
19
22
|
transferPairBalance(address: TransferPair): Promisable<AttoXL1>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransferBalance.d.ts","sourceRoot":"","sources":["../../../src/viewers/TransferBalance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EAAE,uBAAuB,EAAE,QAAQ,EACpD,aAAa,EACd,MAAM,2BAA2B,CAAA;AAElC,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,CAAC,iBAAiB,CAAC;IACzB,MAAM,CAAC,uBAAuB,CAAC,GAAG,IAAI;IACtC,QAAQ;CACT,CAAA;AACD,MAAM,MAAM,YAAY,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"TransferBalance.d.ts","sourceRoot":"","sources":["../../../src/viewers/TransferBalance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EAAE,uBAAuB,EAAE,QAAQ,EACpD,aAAa,EACd,MAAM,2BAA2B,CAAA;AAElC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,CAAC,iBAAiB,CAAC;IACzB,MAAM,CAAC,uBAAuB,CAAC,GAAG,IAAI;IACtC,QAAQ;CACT,CAAA;AACD,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AAE7C,MAAM,WAAW,6BAA6B;IAC5C,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;IACpG,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAClI,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7G,6BAA6B,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;CAC5I;AAED,eAAO,MAAM,4BAA4B,EAAG,uBAAgC,CAAA;AAC5E,MAAM,MAAM,4BAA4B,GAAG,OAAO,4BAA4B,CAAA;AAE9E,MAAM,WAAW,qBAAsB,SAAQ,6BAA6B,EAAE,QAAQ,CAAC,4BAA4B,CAAC;IAClH,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;IACtD,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,UAAU,CAAC,0BAA0B,EAAE,CAAC,CAAA;IACzG,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;IAC/D,0BAA0B,CAAC,OAAO,EAAE,YAAY,GAAG,UAAU,CAAC,0BAA0B,EAAE,CAAC,CAAA;CAC5F"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/xl1-protocol-sdk",
|
|
4
|
-
"version": "1.17.
|
|
4
|
+
"version": "1.17.6",
|
|
5
5
|
"description": "XYO Layer One SDK Protocol",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"!**/*.test.*"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@xylabs/
|
|
43
|
-
"@xylabs/
|
|
42
|
+
"@xylabs/hex": "~5.0.51",
|
|
43
|
+
"@xylabs/sdk-js": "~5.0.51",
|
|
44
44
|
"@xyo-network/account": "~5.2.17",
|
|
45
45
|
"@xyo-network/account-model": "~5.2.17",
|
|
46
46
|
"@xyo-network/archivist-memory": "~5.2.17",
|
|
@@ -51,17 +51,18 @@
|
|
|
51
51
|
"@xyo-network/payload-model": "~5.2.17",
|
|
52
52
|
"@xyo-network/wallet": "~5.2.17",
|
|
53
53
|
"@xyo-network/wallet-model": "~5.2.17",
|
|
54
|
-
"@xyo-network/xl1-protocol": "~1.14.
|
|
54
|
+
"@xyo-network/xl1-protocol": "~1.14.17",
|
|
55
55
|
"async-mutex": "~0.5.0",
|
|
56
56
|
"ethers": "^6.16.0",
|
|
57
57
|
"lru-cache": "^11.2.4",
|
|
58
58
|
"zod": "~4.1.13"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@types/node": "~24.10.
|
|
61
|
+
"@types/node": "~24.10.3",
|
|
62
|
+
"@xylabs/events": "~5.0.51",
|
|
62
63
|
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
|
63
64
|
"@xylabs/tsconfig": "~7.2.8",
|
|
64
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
65
|
+
"@xylabs/vitest-extended": "~5.0.51",
|
|
65
66
|
"@xyo-network/account": "~5.2.17",
|
|
66
67
|
"@xyo-network/boundwitness-validator": "~5.2.17",
|
|
67
68
|
"axios": "^1.13.2",
|
|
@@ -79,4 +80,4 @@
|
|
|
79
80
|
"publishConfig": {
|
|
80
81
|
"access": "public"
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AbstractCreatable } from '@xylabs/sdk-js'
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
CreatableProvider,
|
|
5
|
+
CreatableProviderEventData, CreatableProviderFactory, CreatableProviderInstance, CreatableProviderParams,
|
|
6
|
+
} from './CreatableProvider.ts'
|
|
7
|
+
import { ProviderFactory } from './ProviderFactory.ts'
|
|
8
|
+
|
|
9
|
+
export abstract class AbstractCreatableProvider<TParams extends CreatableProviderParams = CreatableProviderParams,
|
|
10
|
+
TEventData extends CreatableProviderEventData = CreatableProviderEventData> extends AbstractCreatable<TParams, TEventData> {
|
|
11
|
+
static factory<TModule extends CreatableProviderInstance>(
|
|
12
|
+
this: CreatableProvider<TModule>,
|
|
13
|
+
params?: Partial<TModule['params']>,
|
|
14
|
+
): CreatableProviderFactory<TModule> {
|
|
15
|
+
return ProviderFactory.withParams<TModule>(this, params)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { EventData } from '@xylabs/events'
|
|
2
|
+
import type {
|
|
3
|
+
Creatable, CreatableInstance, CreatableParams, EmptyObject,
|
|
4
|
+
Labels, WithOptionalLabels,
|
|
5
|
+
} from '@xylabs/sdk-js'
|
|
6
|
+
|
|
7
|
+
import type { ProviderMoniker } from '../model/index.ts'
|
|
8
|
+
import type { LabeledCreatableProviderFactory } from './LabeledCreatableProviderFactory.ts'
|
|
9
|
+
import type { ProviderFactoryLocatorInstance } from './ProviderFactoryLocatorInstance.ts'
|
|
10
|
+
|
|
11
|
+
export interface CreatableProviderParams<TConfig extends EmptyObject = EmptyObject> extends CreatableParams {
|
|
12
|
+
config?: TConfig
|
|
13
|
+
locator?: ProviderFactoryLocatorInstance
|
|
14
|
+
}
|
|
15
|
+
export interface CreatableProviderEventData extends EventData {}
|
|
16
|
+
|
|
17
|
+
export interface CreatableProviderInstance<TParams extends CreatableProviderParams = CreatableProviderParams,
|
|
18
|
+
TEventData extends CreatableProviderEventData = CreatableProviderEventData>
|
|
19
|
+
extends CreatableInstance<TParams, TEventData> {}
|
|
20
|
+
|
|
21
|
+
export interface CreatableProviderFactory<T extends CreatableProviderInstance = CreatableProviderInstance>
|
|
22
|
+
extends Omit<CreatableProvider<T>, 'create' | 'createHandler' | 'paramsHandler'> {
|
|
23
|
+
creatableProvider: CreatableProvider<T>
|
|
24
|
+
defaultParams?: Partial<T['params']>
|
|
25
|
+
|
|
26
|
+
labels?: Labels
|
|
27
|
+
|
|
28
|
+
create(
|
|
29
|
+
this: CreatableProviderFactory<T>,
|
|
30
|
+
params?: Partial<T['params']>): Promise<T>
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface LabeledCreatableProvider<T extends CreatableProviderInstance = CreatableProviderInstance> extends CreatableProvider<T>, WithOptionalLabels {
|
|
35
|
+
factory(params?: Partial<T['params']>): LabeledCreatableProviderFactory<T>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface CreatableProvider<T extends CreatableProviderInstance = CreatableProviderInstance> extends Creatable<T> {
|
|
39
|
+
defaultMoniker: ProviderMoniker
|
|
40
|
+
monikers: ProviderMoniker[]
|
|
41
|
+
factory(params?: Partial<T['params']>): CreatableProviderFactory<T>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Class annotation to be used to decorate Providers which support
|
|
46
|
+
* an asynchronous creation pattern
|
|
47
|
+
* @returns The decorated Provider requiring it implement the members
|
|
48
|
+
* of the CreatableProvider as statics properties/methods
|
|
49
|
+
*/
|
|
50
|
+
export function creatableProvider<TProvider extends CreatableProviderInstance = CreatableProviderInstance>() {
|
|
51
|
+
return <U extends CreatableProvider<TProvider>>(constructor: U) => {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
53
|
+
constructor
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Class annotation to be used to decorate Providers which support
|
|
59
|
+
* an asynchronous creation pattern
|
|
60
|
+
* @returns The decorated Provider requiring it implement the members
|
|
61
|
+
* of the CreatableProvider as statics properties/methods
|
|
62
|
+
*/
|
|
63
|
+
export function labeledCreatableProvider<TProvider extends CreatableProviderInstance = CreatableProviderInstance>() {
|
|
64
|
+
return <U extends LabeledCreatableProvider<TProvider>>(constructor: U) => {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
66
|
+
constructor
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Labels } from '@xylabs/sdk-js'
|
|
2
|
+
import { isTruthy } from '@xylabs/sdk-js'
|
|
3
|
+
|
|
4
|
+
import type { ProviderMoniker } from '../model/index.ts'
|
|
5
|
+
import type { CreatableProviderFactory, CreatableProviderInstance } from './CreatableProvider.ts'
|
|
6
|
+
import type { LabeledCreatableProviderFactory } from './LabeledCreatableProviderFactory.ts'
|
|
7
|
+
|
|
8
|
+
export interface CreatableProviderRegistry {
|
|
9
|
+
[key: string]: (CreatableProviderFactory | LabeledCreatableProviderFactory)[] | undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const buildProviderFactory = <TProvider extends CreatableProviderInstance>(
|
|
13
|
+
provider: CreatableProviderFactory<TProvider>,
|
|
14
|
+
labels?: Labels,
|
|
15
|
+
): LabeledCreatableProviderFactory<TProvider> => {
|
|
16
|
+
const factory: LabeledCreatableProviderFactory<TProvider> = {
|
|
17
|
+
// Destructure instance properties
|
|
18
|
+
...provider,
|
|
19
|
+
|
|
20
|
+
monikers: provider.monikers,
|
|
21
|
+
// Copy static methods
|
|
22
|
+
create: provider.create.bind(provider) as LabeledCreatableProviderFactory<TProvider>['create'],
|
|
23
|
+
|
|
24
|
+
// Merge module & supplied labels
|
|
25
|
+
labels: { ...(provider as LabeledCreatableProviderFactory).labels, ...labels },
|
|
26
|
+
}
|
|
27
|
+
return factory
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const registerCreatableProviderFactory = <TProvider extends CreatableProviderInstance>(
|
|
31
|
+
registry: CreatableProviderRegistry,
|
|
32
|
+
factory: CreatableProviderFactory<TProvider> | LabeledCreatableProviderFactory<TProvider>,
|
|
33
|
+
labels?: Labels,
|
|
34
|
+
/** register this as the primary factory for every schema it supports */
|
|
35
|
+
primary: boolean | ProviderMoniker | ProviderMoniker[] = false,
|
|
36
|
+
) => {
|
|
37
|
+
const primaryMonikers
|
|
38
|
+
= primary !== true && isTruthy(primary)
|
|
39
|
+
? Array.isArray(primary)
|
|
40
|
+
? primary
|
|
41
|
+
: [primary]
|
|
42
|
+
: []
|
|
43
|
+
|
|
44
|
+
for (const primaryMoniker of primaryMonikers) {
|
|
45
|
+
if (!factory.monikers.includes(primaryMoniker)) {
|
|
46
|
+
console.warn(`Primary moniker ${primary} not found in factory monikers`)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const isPrimaryForMoniker = (moniker: ProviderMoniker) => {
|
|
51
|
+
switch (typeof primary) {
|
|
52
|
+
case 'boolean': {
|
|
53
|
+
return primary
|
|
54
|
+
}
|
|
55
|
+
case 'string': {
|
|
56
|
+
return moniker === primary
|
|
57
|
+
}
|
|
58
|
+
case 'object': {
|
|
59
|
+
if (Array.isArray(primary)) {
|
|
60
|
+
return primary.includes(moniker)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Invalid primary value: ${primary}`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const factoryClone: LabeledCreatableProviderFactory<TProvider> = buildProviderFactory(factory, labels)
|
|
68
|
+
|
|
69
|
+
// add this default moniker as the first entry
|
|
70
|
+
registry[factoryClone.defaultMoniker] = [factoryClone, ...(registry[factoryClone.defaultMoniker] ?? [])]
|
|
71
|
+
for (const moniker of factoryClone.monikers) {
|
|
72
|
+
registry[moniker] = isPrimaryForMoniker(moniker) ? [factoryClone, ...(registry[moniker] ?? [])] : [...(registry[moniker] ?? []), factoryClone]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const registerCreatableProviderFactories = (
|
|
77
|
+
factories: (CreatableProviderFactory | LabeledCreatableProviderFactory)[],
|
|
78
|
+
registry: CreatableProviderRegistry = {},
|
|
79
|
+
primary = false,
|
|
80
|
+
) => {
|
|
81
|
+
for (const factory of factories) {
|
|
82
|
+
registerCreatableProviderFactory(registry, factory, undefined, primary)
|
|
83
|
+
}
|
|
84
|
+
return registry
|
|
85
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { WithOptionalLabels } from '@xylabs/sdk-js'
|
|
2
|
+
|
|
3
|
+
import type { CreatableProviderFactory, CreatableProviderInstance } from './CreatableProvider.ts'
|
|
4
|
+
|
|
5
|
+
export type LabeledCreatableProviderFactory<T extends CreatableProviderInstance = CreatableProviderInstance> = CreatableProviderFactory<T> & WithOptionalLabels
|
|
6
|
+
|
|
7
|
+
export const hasLabels = (factory: CreatableProviderFactory | LabeledCreatableProviderFactory): factory is LabeledCreatableProviderFactory => {
|
|
8
|
+
return (factory as LabeledCreatableProviderFactory).labels !== undefined
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Class annotation to be used to decorate Providers which support
|
|
13
|
+
* an asynchronous labeled creation factory pattern
|
|
14
|
+
* @returns The decorated Provider requiring it implement the members
|
|
15
|
+
* of the CreatableProvider as statics properties/methods
|
|
16
|
+
*/
|
|
17
|
+
export function labeledCreatableProviderFactory<TProvider extends CreatableProviderInstance = CreatableProviderInstance>() {
|
|
18
|
+
return <U extends LabeledCreatableProviderFactory<TProvider>>(constructor: U) => {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
20
|
+
constructor
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Labels, WithOptionalLabels } from '@xylabs/sdk-js'
|
|
2
|
+
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
CreatableProvider, CreatableProviderFactory, CreatableProviderInstance,
|
|
6
|
+
} from './CreatableProvider.ts'
|
|
7
|
+
|
|
8
|
+
export class ProviderFactory<TProvider extends CreatableProviderInstance> implements CreatableProviderFactory<TProvider> {
|
|
9
|
+
creatableProvider: CreatableProvider<TProvider>
|
|
10
|
+
|
|
11
|
+
defaultMoniker: CreatableProvider<TProvider>['monikers'][number]
|
|
12
|
+
|
|
13
|
+
defaultParams?: Partial<TProvider['params']>
|
|
14
|
+
|
|
15
|
+
labels?: Labels
|
|
16
|
+
|
|
17
|
+
monikers: CreatableProvider<TProvider>['monikers']
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
creatableProvider: CreatableProvider<TProvider>,
|
|
21
|
+
params?: Partial<TProvider['params']>,
|
|
22
|
+
labels: Labels = {},
|
|
23
|
+
) {
|
|
24
|
+
this.creatableProvider = creatableProvider
|
|
25
|
+
this.defaultParams = params
|
|
26
|
+
this.defaultMoniker = creatableProvider.defaultMoniker
|
|
27
|
+
this.monikers = creatableProvider.monikers
|
|
28
|
+
assertEx(this.monikers.includes(this.defaultMoniker), () => 'defaultMoniker must be in monikers')
|
|
29
|
+
this.labels = Object.assign({}, (creatableProvider as WithOptionalLabels).labels ?? {}, labels ?? {})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static withParams<T extends CreatableProviderInstance>(
|
|
33
|
+
creatableProvider: CreatableProvider<T>,
|
|
34
|
+
params?: Partial<T['params']>,
|
|
35
|
+
labels: Labels = {},
|
|
36
|
+
) {
|
|
37
|
+
return new ProviderFactory<T>(creatableProvider, params, labels)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
create(this: CreatableProviderFactory<TProvider>, params?: Partial<TProvider['params']>): Promise<TProvider> {
|
|
41
|
+
const mergedParams: TProvider['params'] = {
|
|
42
|
+
...this.defaultParams,
|
|
43
|
+
...params,
|
|
44
|
+
config: {
|
|
45
|
+
...this.defaultParams?.config,
|
|
46
|
+
...params?.config,
|
|
47
|
+
},
|
|
48
|
+
} as TProvider['params']
|
|
49
|
+
return this.creatableProvider.create<TProvider>(mergedParams)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
factory<T extends CreatableProviderInstance>(
|
|
53
|
+
this: CreatableProviderFactory<T>,
|
|
54
|
+
params?: Partial<T['params']>,
|
|
55
|
+
labels: Labels = {},
|
|
56
|
+
): CreatableProviderFactory<T> {
|
|
57
|
+
return new ProviderFactory<T>(this.creatableProvider, params, labels)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { hasAllLabels, type Labels } from '@xylabs/sdk-js'
|
|
2
|
+
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
+
|
|
4
|
+
import type { ProviderMoniker } from '../model/index.ts'
|
|
5
|
+
import type { CreatableProviderFactory } from './CreatableProvider.ts'
|
|
6
|
+
import { type CreatableProviderRegistry, registerCreatableProviderFactory } from './CreatableProviderRegistry.ts'
|
|
7
|
+
import { hasLabels, type LabeledCreatableProviderFactory } from './LabeledCreatableProviderFactory.ts'
|
|
8
|
+
import type { ProviderFactoryLocatorInstance } from './ProviderFactoryLocatorInstance.ts'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A class which encapsulates the Service Locator Pattern for Provider Factories
|
|
12
|
+
*/
|
|
13
|
+
export class ProviderFactoryLocator implements ProviderFactoryLocatorInstance {
|
|
14
|
+
protected readonly _registry: CreatableProviderRegistry
|
|
15
|
+
|
|
16
|
+
private _frozen = false
|
|
17
|
+
|
|
18
|
+
constructor(registry: CreatableProviderRegistry = {}) {
|
|
19
|
+
this._registry = registry
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The current registry for the module factory
|
|
24
|
+
*/
|
|
25
|
+
get registry(): Readonly<CreatableProviderRegistry> {
|
|
26
|
+
return this._registry
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static empty() {
|
|
30
|
+
return new ProviderFactoryLocator({})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static standard() {
|
|
34
|
+
return new ProviderFactoryLocator({})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
freeze() {
|
|
38
|
+
this._frozen = true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Locates a provider factory that matches the supplied schema and labels
|
|
43
|
+
* @param schema The config schema for the provider
|
|
44
|
+
* @param labels The labels for the provider factory
|
|
45
|
+
* @returns A provider factory that matches the supplied schema and labels or throws if one is not found
|
|
46
|
+
*/
|
|
47
|
+
locate(moniker: ProviderMoniker, labels?: Labels): CreatableProviderFactory | LabeledCreatableProviderFactory {
|
|
48
|
+
return assertEx(
|
|
49
|
+
this.tryLocate(moniker, labels),
|
|
50
|
+
|
|
51
|
+
() => `No module factory for the supplied config schema [${moniker}]${labels ? ` & labels [${JSON.stringify(labels)}]` : ''} registered`,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
merge(locator: ProviderFactoryLocatorInstance): ProviderFactoryLocatorInstance {
|
|
56
|
+
const registry = { ...this.registry }
|
|
57
|
+
for (const moniker in locator.registry) {
|
|
58
|
+
if (registry[moniker]) {
|
|
59
|
+
registry[moniker].push(...(locator.registry[moniker] ?? []))
|
|
60
|
+
} else {
|
|
61
|
+
registry[moniker] = locator.registry[moniker]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return new ProviderFactoryLocator(registry)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Registers a single module factory (with optional tags) with the locator
|
|
69
|
+
* @param factory The factory to register
|
|
70
|
+
* @param labels The labels for the module factory
|
|
71
|
+
*/
|
|
72
|
+
register(factory: CreatableProviderFactory, labels?: Labels, primary: boolean | ProviderMoniker | ProviderMoniker[] = false): this {
|
|
73
|
+
assertEx(!this._frozen, () => 'Cannot register a module factory after the locator has been frozen')
|
|
74
|
+
registerCreatableProviderFactory(this._registry, factory, labels, primary)
|
|
75
|
+
return this
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Registers multiple module factories with the locator
|
|
80
|
+
* @param factories The factories to register
|
|
81
|
+
*/
|
|
82
|
+
registerMany(factories: CreatableProviderFactory[]): this {
|
|
83
|
+
for (const factory of factories) {
|
|
84
|
+
this.register(factory)
|
|
85
|
+
}
|
|
86
|
+
return this
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Tries to locate a module factory that matches the supplied schema and labels
|
|
91
|
+
* @param schema The config schema for the module
|
|
92
|
+
* @param labels The labels for the module factory
|
|
93
|
+
* @returns A module factory that matches the supplied schema and labels or undefined
|
|
94
|
+
*/
|
|
95
|
+
tryLocate(moniker: ProviderMoniker, labels?: Labels): CreatableProviderFactory | LabeledCreatableProviderFactory | undefined {
|
|
96
|
+
return labels
|
|
97
|
+
// Find the first factory that has labels and has all the labels provided
|
|
98
|
+
? (this._registry[moniker]?.filter(hasLabels).find(factory => hasAllLabels(factory?.labels, labels)) ?? this._registry[moniker]?.[0])
|
|
99
|
+
// Otherwise, return the first factory
|
|
100
|
+
: this._registry[moniker]?.[0]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Labels } from '@xylabs/sdk-js'
|
|
2
|
+
|
|
3
|
+
import type { ProviderMoniker } from '../model/index.ts'
|
|
4
|
+
import type { CreatableProviderFactory } from './CreatableProvider.ts'
|
|
5
|
+
import type { CreatableProviderRegistry } from './CreatableProviderRegistry.ts'
|
|
6
|
+
import type { LabeledCreatableProviderFactory } from './LabeledCreatableProviderFactory.ts'
|
|
7
|
+
|
|
8
|
+
export interface ProviderFactoryLocatorInstance {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The current registry for the module factory
|
|
12
|
+
*/
|
|
13
|
+
registry: Readonly<CreatableProviderRegistry>
|
|
14
|
+
|
|
15
|
+
freeze(): void
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Locates a module factory that matches the supplied schema and labels
|
|
19
|
+
* @param schema The config schema for the module
|
|
20
|
+
* @param labels The labels for the module factory
|
|
21
|
+
* @returns A module factory that matches the supplied schema and labels or throws if one is not found
|
|
22
|
+
*/
|
|
23
|
+
locate(schema: string, labels?: Labels): CreatableProviderFactory | LabeledCreatableProviderFactory
|
|
24
|
+
|
|
25
|
+
merge(locator: ProviderFactoryLocatorInstance): ProviderFactoryLocatorInstance
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Registers a single module factory (with optional tags) with the locator
|
|
29
|
+
* @param factory The factory to register
|
|
30
|
+
* @param labels The labels for the module factory
|
|
31
|
+
*/
|
|
32
|
+
register(factory: CreatableProviderFactory, labels?: Labels, primary?: boolean | ProviderMoniker | ProviderMoniker[]): ProviderFactoryLocatorInstance
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Registers multiple module factories with the locator
|
|
36
|
+
* @param factories The factories to register
|
|
37
|
+
*/
|
|
38
|
+
registerMany(factories: CreatableProviderFactory[]): ProviderFactoryLocatorInstance
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Tries to locate a module factory that matches the supplied schema and labels
|
|
42
|
+
* @param schema The config schema for the module
|
|
43
|
+
* @param labels The labels for the module factory
|
|
44
|
+
* @returns A module factory that matches the supplied schema and labels or undefined
|
|
45
|
+
*/
|
|
46
|
+
tryLocate(schema: string, labels?: Labels): CreatableProviderFactory | LabeledCreatableProviderFactory | undefined
|
|
47
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './AbstractCreatableProvider.ts'
|
|
2
|
+
export * from './CreatableProvider.ts'
|
|
3
|
+
export * from './CreatableProviderRegistry.ts'
|
|
4
|
+
export * from './LabeledCreatableProviderFactory.ts'
|
|
5
|
+
export * from './ProviderFactory.ts'
|
|
6
|
+
export * from './ProviderFactoryLocator.ts'
|
|
7
|
+
export * from './ProviderFactoryLocatorInstance.ts'
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import type { Payload } from '@xyo-network/payload-model'
|
|
2
|
-
import type
|
|
2
|
+
import { type BlockBoundWitness, toHydratedBlock } from '@xyo-network/xl1-protocol'
|
|
3
3
|
|
|
4
4
|
export const flattenHydratedBlock = <B extends BlockBoundWitness, P extends Payload>(hydratedBlock: [B, P[]]): (P | B)[] => {
|
|
5
5
|
const [blk, blkPayloads] = hydratedBlock
|
|
6
6
|
return [...blkPayloads, blk]
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
export const tryUnflattenHydratedBlock = <
|
|
10
|
+
B extends BlockBoundWitness,
|
|
11
|
+
P extends Payload,
|
|
12
|
+
>(flattened: (P | B)[]): [B, P[]] | undefined => {
|
|
13
|
+
// Last element is the block
|
|
14
|
+
const blk = flattened.at(-1) as B
|
|
15
|
+
|
|
16
|
+
// All previous elements are payloads
|
|
17
|
+
const payloads = flattened.slice(0, -1) as P[]
|
|
18
|
+
|
|
19
|
+
return toHydratedBlock([blk, payloads])
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const unflattenHydratedBlock = <
|
|
23
|
+
B extends BlockBoundWitness,
|
|
24
|
+
P extends Payload,
|
|
25
|
+
>(flattened: (P | B)[]): [B, P[]] => toHydratedBlock(tryUnflattenHydratedBlock(flattened), true) as [B, P[]]
|