Skip to content

Commit

Permalink
backport PR 308 (dht ops helper fix) (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthme authored Dec 17, 2024
1 parent 4c44de4 commit 06e32c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
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];
}

0 comments on commit 06e32c9

Please sign in to comment.