Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Backport dht op type helpers #309

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## \[Unreleased\]

### Added
### Changed
### Fixed
- Fix DhtOps helper functions `getChainOpType`, `getChainOpAction`, `getChainOpEntry` and `getChainOpSignature` to adhere to the new types
### Changed
### Removed

## 2024-12-01: v0.18.0-rc.1
Expand Down
42 changes: 23 additions & 19 deletions src/hdk/dht-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
/**
* @public
*/
export enum DhtOpType {
export enum ChainOpType {
StoreRecord = "StoreRecord",
StoreEntry = "StoreEntry",
RegisterAgentActivity = "RegisterAgentActivity",
Expand Down Expand Up @@ -53,23 +53,27 @@ export interface WarrantOp {
* @public
*/
export type ChainOp =
| { [DhtOpType.StoreRecord]: [Signature, Action, Entry | undefined] }
| { [DhtOpType.StoreEntry]: [Signature, NewEntryAction, Entry] }
| { [DhtOpType.RegisterAgentActivity]: [Signature, Action] }
| { [ChainOpType.StoreRecord]: [Signature, Action, Entry | undefined] }
| { [ChainOpType.StoreEntry]: [Signature, NewEntryAction, Entry] }
| { [ChainOpType.RegisterAgentActivity]: [Signature, Action] }
| {
[DhtOpType.RegisterUpdatedContent]: [
[ChainOpType.RegisterUpdatedContent]: [
Signature,
Update,
Entry | undefined
];
}
| {
[DhtOpType.RegisterUpdatedRecord]: [Signature, Update, Entry | undefined];
[ChainOpType.RegisterUpdatedRecord]: [
Signature,
Update,
Entry | undefined
];
}
| { [DhtOpType.RegisterDeletedBy]: [Signature, Delete] }
| { [DhtOpType.RegisterDeletedEntryAction]: [Signature, Delete] }
| { [DhtOpType.RegisterAddLink]: [Signature, CreateLink] }
| { [DhtOpType.RegisterRemoveLink]: [Signature, DeleteLink] };
| { [ChainOpType.RegisterDeletedBy]: [Signature, Delete] }
| { [ChainOpType.RegisterDeletedEntryAction]: [Signature, Delete] }
| { [ChainOpType.RegisterAddLink]: [Signature, CreateLink] }
| { [ChainOpType.RegisterRemoveLink]: [Signature, DeleteLink] };

/**
* @public
Expand Down Expand Up @@ -129,26 +133,26 @@ export type ActionHashAndSig = [ActionHash, Signature];
/**
* @public
*/
export function getDhtOpType(op: DhtOp): DhtOpType {
return Object.keys(op)[0] as DhtOpType;
export function getChainOpType(op: ChainOp): ChainOpType {
return Object.keys(op)[0] as ChainOpType;
}

/**
* @public
*/
export function getDhtOpAction(op: DhtOp): Action {
const opType = getDhtOpType(op);
export function getChainOpAction(op: ChainOp): Action {
const opType = getChainOpType(op);
const action = Object.values(op)[0][1];

if (opType === DhtOpType.RegisterAddLink) {
if (opType === ChainOpType.RegisterAddLink) {
return {
type: "CreateLink",
...action,
};
}
if (
opType === DhtOpType.RegisterUpdatedContent ||
opType === DhtOpType.RegisterUpdatedRecord
opType === ChainOpType.RegisterUpdatedContent ||
opType === ChainOpType.RegisterUpdatedRecord
) {
return {
type: "Update",
Expand All @@ -169,13 +173,13 @@ export function getDhtOpAction(op: DhtOp): Action {
/**
* @public
*/
export function getDhtOpEntry(op: DhtOp): Entry | undefined {
export function getChainOpEntry(op: ChainOp): Entry | undefined {
return Object.values(op)[0][2];
}

/**
* @public
*/
export function getDhtOpSignature(op: DhtOp): Signature {
export function getChainOpSignature(op: ChainOp): Signature {
return Object.values(op)[0][1];
}
Loading