Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter Datapod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
Duniter Datapod
Commits
f145202e
Commit
f145202e
authored
7 months ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
refac inode gen
parent
d3b47dfd
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/processor.ts
+7
-13
7 additions, 13 deletions
src/processor.ts
src/scripts/buildNode.ts
+37
-0
37 additions, 0 deletions
src/scripts/buildNode.ts
src/scripts/rpcDatapod.ts
+2
-0
2 additions, 0 deletions
src/scripts/rpcDatapod.ts
with
46 additions
and
13 deletions
src/processor.ts
+
7
−
13
View file @
f145202e
...
...
@@ -224,21 +224,12 @@ export async function mergeInodesSync(
const
isAleaf
=
(
nodeA
as
IndexLeaf
).
leaf
!=
undefined
const
isBleaf
=
(
nodeB
as
IndexLeaf
).
leaf
!=
undefined
const
[
leafA
,
leafB
]
=
[
nodeA
as
IndexLeaf
,
nodeB
as
IndexLeaf
]
// these are not internal nodes, but leaves, and we should merge them
if
(
isAleaf
&&
isBleaf
)
{
// should only merge leaves with same key
assert
(
leafA
.
key
==
leafB
.
key
)
// these are not internal nodes, but leaves, and we should merge them
// problem: Set will not work on CIDs because they are objects and differ even if they have the same data
// const cidSet = new Set([...(nodeA as unknown as IndexLeaf).leaf, ...(nodeB as IndexLeaf).leaf])
// const cidListUniqueSorted = Array.from(cidSet).sort()
const
cidList
=
[...(
nodeA
as
IndexLeaf
).
leaf
,
...(
nodeB
as
IndexLeaf
).
leaf
]
const
cidListUniqueSorted
=
uniqueby
(
cidList
,
(
k
)
=>
k
.
toString
()).
sort
((
a
,
b
)
=>
a
.
toString
()
<
b
.
toString
()
?
-
1
:
1
)
const
newLeaf
:
IndexLeaf
=
{
leaf
:
cidListUniqueSorted
,
key
:
leafA
.
key
}
const
allCIDs
=
(
nodeA
as
IndexLeaf
).
leaf
.
concat
((
nodeB
as
IndexLeaf
).
leaf
)
const
newLeaf
=
arrayToLeaf
(
leafA
.
key
,
allCIDs
)
return
kubo
.
dag
.
put
(
newLeaf
).
then
((
cid
)
=>
{
// WIP pin des not work well
// kubo.pin.add(cid).catch((_e) => console.log(`📌📌 could not pin newly created leaf ${cid}`))
...
...
@@ -390,7 +381,10 @@ export function arrayToVinode(ctx: string, array: Array<[string, CID]>): IndexVi
/// transform array of cid to leaf object
export
function
arrayToLeaf
(
key
:
string
,
array
:
CID
[]):
IndexLeaf
{
return
{
key
,
leaf
:
array
.
sort
((
a
,
b
)
=>
(
a
.
toString
()
<
b
.
toString
()
?
-
1
:
1
))
}
const
cidListUniqueSorted
=
uniqueby
<
CID
>
(
array
,
(
k
)
=>
k
.
toString
()).
sort
((
a
,
b
)
=>
a
.
toString
()
<
b
.
toString
()
?
-
1
:
1
)
return
{
key
,
leaf
:
cidListUniqueSorted
}
}
/// concretize virtual node to CID
...
...
This diff is collapsed.
Click to expand it.
src/scripts/buildNode.ts
0 → 100644
+
37
−
0
View file @
f145202e
import
{
arrayToVinode
,
mergeInodesSyncCID
}
from
'
../processor
'
import
{
kubo
}
from
'
../kubo
'
import
type
{
CID
}
from
'
multiformats
'
import
{
emptyInode
}
from
'
../types
'
import
{
getAll
}
from
'
../interface
'
const
obj
=
{
index
:
'
request
'
,
fake
:
true
}
const
fakeRoot
=
emptyInode
(
'
fake_
'
)
// I should transform that into a unit test
async
function
main
()
{
const
rootCID
=
await
kubo
.
dag
.
put
(
fakeRoot
)
const
cid
=
await
kubo
.
dag
.
put
(
obj
)
const
items
:
Array
<
[
string
,
CID
]
>
=
[
[
'
123
'
,
cid
],
[
'
456
'
,
cid
],
[
'
456
'
,
cid
]
]
const
root
=
arrayToVinode
(
'
fake_
'
,
items
)
console
.
log
(
root
)
console
.
log
(
JSON
.
stringify
(
root
))
const
[
_
,
res
]
=
await
mergeInodesSyncCID
(
rootCID
,
root
)
console
.
log
(
res
)
const
collect
=
[]
for
await
(
const
item
of
getAll
(
res
))
{
collect
.
push
(
item
)
}
console
.
log
(
collect
)
}
main
()
This diff is collapsed.
Click to expand it.
src/scripts/rpcDatapod.ts
+
2
−
0
View file @
f145202e
...
...
@@ -27,6 +27,8 @@ async function doit() {
const
enc
=
new
TextEncoder
()
await
kubo
.
pubsub
.
publish
(
'
ddd
'
,
enc
.
encode
(
"
hello, I'm there
\n
"
))
console
.
log
(
'
published ;)
'
)
// makes sure that pinning does not work
await
kubo
.
dag
.
put
(
obj
,
{
pin
:
true
})
}
doit
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment