Skip to content

Commit

Permalink
Fixed encoding node
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Oct 17, 2024
1 parent 1b4a9c0 commit e253207
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/signals/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@holochain-open-dev/signals",
"version": "0.300.8",
"version": "0.300.9",
"description": "Holochain async-signals to build reusable holochain-open-dev modules",
"author": "[email protected]",
"main": "dist/index.js",
Expand Down
77 changes: 46 additions & 31 deletions packages/signals/src/holochain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export function collectionSignal<
maybeSet(
(links || []).filter(
link =>
link.create_link_hash.toString() !==
signal.create_link_action.hashed.hash.toString(),
encodeHashToBase64(link.create_link_hash) !==
encodeHashToBase64(signal.create_link_action.hashed.hash),
),
);
}
Expand Down Expand Up @@ -252,8 +252,9 @@ export function latestVersionOfEntrySignal<
const nlatestVersion = await fetchLatestVersion();
if (nlatestVersion) {
if (
latestVersion?.actionHash.toString() !==
nlatestVersion?.actionHash.toString()
!latestVersion ||
encodeHashToBase64(latestVersion.actionHash) !==
encodeHashToBase64(nlatestVersion.actionHash)
) {
latestVersion = nlatestVersion;
signal.set({
Expand Down Expand Up @@ -287,8 +288,10 @@ export function latestVersionOfEntrySignal<
if (
hcSignal.type === 'EntryUpdated' &&
latestVersion &&
latestVersion.actionHash.toString() ===
hcSignal.action.hashed.content.original_action_address.toString()
encodeHashToBase64(latestVersion.actionHash) ===
encodeHashToBase64(
hcSignal.action.hashed.content.original_action_address,
)
) {
latestVersion = new EntryRecord({
entry: {
Expand Down Expand Up @@ -383,8 +386,10 @@ export function allRevisionsOfEntrySignal<
allRevisions &&
allRevisions.find(
revision =>
revision.actionHash.toString() ===
hcSignal.action.hashed.content.original_action_address.toString(),
encodeHashToBase64(revision.actionHash) ===
encodeHashToBase64(
hcSignal.action.hashed.content.original_action_address,
),
)
) {
const newRevision = new EntryRecord<T>({
Expand Down Expand Up @@ -481,8 +486,9 @@ export function deletesForEntrySignal<

if (
hcSignal.type === 'EntryDeleted' &&
hcSignal.action.hashed.content.deletes_address.toString() ===
originalActionHash.toString()
encodeHashToBase64(
hcSignal.action.hashed.content.deletes_address,
) === encodeHashToBase64(originalActionHash)
) {
const lastDeletes = deletes ? deletes : [];
deletes = uniquifyActions([...lastDeletes, hcSignal.action]);
Expand Down Expand Up @@ -540,7 +546,7 @@ function areArrayHashesEqual(
if (array1.length !== array2.length) return false;

for (let i = 0; i < array1.length; i += 1) {
if (array1[i].toString() !== array2[i].toString()) {
if (encodeHashToBase64(array1[i]) !== encodeHashToBase64(array2[i])) {
return false;
}
}
Expand Down Expand Up @@ -637,27 +643,31 @@ export function liveLinksSignal<
if (hcSignal.type === 'LinkCreated') {
if (
linkType === hcSignal.link_type &&
(hcSignal.action.hashed.content.base_address.toString() ===
innerBaseAddress.toString() ||
retype(
hcSignal.action.hashed.content.base_address,
HashType.AGENT,
).toString() === innerBaseAddress.toString())
(encodeHashToBase64(
hcSignal.action.hashed.content.base_address,
) === encodeHashToBase64(innerBaseAddress) ||
encodeHashToBase64(
retype(
hcSignal.action.hashed.content.base_address,
HashType.AGENT,
),
) === encodeHashToBase64(innerBaseAddress))
) {
const lastLinks = links ? links : [];
maybeSet([...lastLinks, createLinkToLink(hcSignal.action)]);
}
} else if (hcSignal.type === 'LinkDeleted') {
if (
linkType === hcSignal.link_type &&
hcSignal.create_link_action.hashed.content.base_address.toString() ===
innerBaseAddress.toString()
encodeHashToBase64(
hcSignal.create_link_action.hashed.content.base_address,
) === encodeHashToBase64(innerBaseAddress)
) {
maybeSet(
(links ? links : []).filter(
link =>
link.create_link_hash.toString() !==
hcSignal.create_link_action.hashed.hash.toString(),
encodeHashToBase64(link.create_link_hash) !==
encodeHashToBase64(hcSignal.create_link_action.hashed.hash),
),
);
}
Expand Down Expand Up @@ -792,22 +802,23 @@ export function deletedLinksSignal<
if (hcSignal.type === 'LinkDeleted') {
if (
linkType === hcSignal.link_type &&
hcSignal.create_link_action.hashed.content.base_address.toString() ===
innerBaseAddress.toString()
encodeHashToBase64(
hcSignal.create_link_action.hashed.content.base_address,
) === encodeHashToBase64(innerBaseAddress)
) {
const lastDeletedLinks = deletedLinks ? deletedLinks : [];
const alreadyDeletedTargetIndex = lastDeletedLinks.findIndex(
([cl]) =>
cl.hashed.hash.toString() ===
hcSignal.create_link_action.hashed.hash.toString(),
encodeHashToBase64(cl.hashed.hash) ===
encodeHashToBase64(hcSignal.create_link_action.hashed.hash),
);

if (alreadyDeletedTargetIndex !== -1) {
if (
!lastDeletedLinks[alreadyDeletedTargetIndex][1].find(
dl =>
dl.hashed.hash.toString() ===
hcSignal.action.hashed.hash.toString(),
encodeHashToBase64(dl.hashed.hash) ===
encodeHashToBase64(hcSignal.action.hashed.hash),
)
) {
const clone = cloneDeep(deletedLinks);
Expand Down Expand Up @@ -912,14 +923,18 @@ export function queryLiveEntriesSignal<
if (
queriedEntries?.find(
e =>
e.actionHash.toString() ===
hcSignal.action.hashed.content.deletes_address.toString(),
encodeHashToBase64(e.actionHash) ===
encodeHashToBase64(
hcSignal.action.hashed.content.deletes_address,
),
)
) {
queriedEntries = queriedEntries.filter(
e =>
e.actionHash.toString() !==
hcSignal.action.hashed.content.deletes_address.toString(),
encodeHashToBase64(e.actionHash) !==
encodeHashToBase64(
hcSignal.action.hashed.content.deletes_address,
),
);
signal.set({
status: 'completed',
Expand Down

0 comments on commit e253207

Please sign in to comment.