@xyo-network/react-archivist 7.5.7 → 7.5.11
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/browser/index.mjs +212 -300
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +150 -45
- package/src/components/Card/Card.stories.tsx +0 -82
- package/src/components/Card/Card.tsx +0 -22
- package/src/components/Card/CardActions.tsx +0 -9
- package/src/components/Card/CardContent.tsx +0 -42
- package/src/components/Card/CardHeader.tsx +0 -27
- package/src/components/Card/components/ArchivistParent.tsx +0 -26
- package/src/components/Card/components/ArchivistParents.tsx +0 -53
- package/src/components/Card/components/Stats/ArchivistStats.stories.tsx +0 -36
- package/src/components/Card/components/Stats/ArchivistStats.tsx +0 -60
- package/src/components/Card/components/Stats/MemoryArchivistStats.stories.tsx +0 -60
- package/src/components/Card/components/Stats/MemoryArchivistStats.tsx +0 -83
- package/src/components/Card/components/Stats/index.ts +0 -2
- package/src/components/Card/components/index.ts +0 -3
- package/src/components/Card/index.ts +0 -3
- package/src/components/Details/Details.stories.tsx +0 -74
- package/src/components/Details/Details.tsx +0 -74
- package/src/components/Details/index.ts +0 -1
- package/src/components/index.ts +0 -2
- package/src/hooks/index.ts +0 -2
- package/src/hooks/node/index.ts +0 -4
- package/src/hooks/node/useArchivistFromNode.tsx +0 -19
- package/src/hooks/node/useArchivistsFromNode.tsx +0 -28
- package/src/hooks/node/useWeakArchivistFromNode.tsx +0 -11
- package/src/hooks/node/useWeakArchivistsFromNode.tsx +0 -27
- package/src/hooks/queries/index.ts +0 -4
- package/src/hooks/queries/useArchivistAll.tsx +0 -22
- package/src/hooks/queries/useArchivistGet.tsx +0 -21
- package/src/hooks/queries/useWeakArchivistAll.tsx +0 -22
- package/src/hooks/queries/useWeakArchivistGet.tsx +0 -22
- package/src/index.ts +0 -2
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ArrowRightRounded as ArrowRightRoundedIcon } from '@mui/icons-material'
|
|
2
|
-
import {
|
|
3
|
-
Collapse, IconButton, List, Paper, Typography,
|
|
4
|
-
} from '@mui/material'
|
|
5
|
-
import type { FlexBoxProps } from '@xylabs/react-flexbox'
|
|
6
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
7
|
-
import type { ArchivistConfig } from '@xyo-network/archivist-model'
|
|
8
|
-
import React, { useState } from 'react'
|
|
9
|
-
|
|
10
|
-
import { ArchivistParent } from './ArchivistParent.tsx'
|
|
11
|
-
|
|
12
|
-
export interface ArchivistParentsProps extends FlexBoxProps {
|
|
13
|
-
config?: ArchivistConfig
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const ArchivistParents: React.FC<ArchivistParentsProps> = ({ config, ...props }) => {
|
|
17
|
-
const [parentArchivistCollapse, setParentArchivistCollapse] = useState(false)
|
|
18
|
-
|
|
19
|
-
const {
|
|
20
|
-
commit, read, write,
|
|
21
|
-
} = config?.parents ?? {}
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<>
|
|
25
|
-
{commit || read || write
|
|
26
|
-
? (
|
|
27
|
-
<FlexCol alignItems="start" {...props}>
|
|
28
|
-
<span onClick={() => setParentArchivistCollapse(!parentArchivistCollapse)}>
|
|
29
|
-
<Typography
|
|
30
|
-
variant="subtitle2"
|
|
31
|
-
sx={{ cursor: 'pointer', display: 'inline-block' }}
|
|
32
|
-
>
|
|
33
|
-
Parents
|
|
34
|
-
</Typography>
|
|
35
|
-
<IconButton size="small">
|
|
36
|
-
<ArrowRightRoundedIcon sx={{ rotate: parentArchivistCollapse ? '90deg' : '0deg', transition: 'all .25s' }} />
|
|
37
|
-
</IconButton>
|
|
38
|
-
</span>
|
|
39
|
-
<Collapse in={parentArchivistCollapse}>
|
|
40
|
-
<Paper elevation={2}>
|
|
41
|
-
<List>
|
|
42
|
-
<ArchivistParent archivistType="Commit" parentArchivists={commit} />
|
|
43
|
-
<ArchivistParent archivistType="Read" parentArchivists={read} />
|
|
44
|
-
<ArchivistParent archivistType="Write" parentArchivists={write} />
|
|
45
|
-
</List>
|
|
46
|
-
</Paper>
|
|
47
|
-
</Collapse>
|
|
48
|
-
</FlexCol>
|
|
49
|
-
)
|
|
50
|
-
: null}
|
|
51
|
-
</>
|
|
52
|
-
)
|
|
53
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryFn } from '@storybook/react-vite'
|
|
2
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
|
|
5
|
-
// import { Account } from '@xyo-network/account'
|
|
6
|
-
// import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
7
|
-
// import { Payload } from '@xyo-network/payload-model'
|
|
8
|
-
import { ArchivistStats } from './ArchivistStats.tsx'
|
|
9
|
-
|
|
10
|
-
// const account = Account.randomSync()
|
|
11
|
-
// const payload = () => ({ schema: 'network.xyo.payload', timestamp: Date.now() })
|
|
12
|
-
// const boundWitness = async () => await new BoundWitnessBuilder().payload(payload()).signer(account).build()
|
|
13
|
-
|
|
14
|
-
const StorybookEntry = {
|
|
15
|
-
component: ArchivistStats,
|
|
16
|
-
parameters: { docs: { page: null } },
|
|
17
|
-
title: 'modules/archivist/ArchivistStats',
|
|
18
|
-
} as Meta<typeof ArchivistStats>
|
|
19
|
-
|
|
20
|
-
const Template: StoryFn<typeof ArchivistStats> = ({ boundWitnesses, ...props }) => {
|
|
21
|
-
const [boundWitnessesProp] = usePromise(async () => (boundWitnesses ? await Promise.all(boundWitnesses) : []), [boundWitnesses])
|
|
22
|
-
return boundWitnessesProp ? <ArchivistStats boundWitnesses={boundWitnessesProp} {...props} /> : <div />
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const Default = Template.bind({})
|
|
26
|
-
const WithStats = Template.bind({})
|
|
27
|
-
WithStats.args = {
|
|
28
|
-
// addresses: { [account.address]: 1 },
|
|
29
|
-
// boundWitnesses: [boundWitness() as unknown as Payload],
|
|
30
|
-
// payloads: [payload(), boundWitness() as unknown as Payload],
|
|
31
|
-
schemas: { 'network.xyo.boundwitness': 1, 'network.xyo.payload': 1 },
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { Default, WithStats }
|
|
35
|
-
|
|
36
|
-
export default StorybookEntry
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Badge, Tooltip } from '@mui/material'
|
|
2
|
-
import { FlexRow } from '@xylabs/react-flexbox'
|
|
3
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
import { BsFileEarmarkCode } from 'react-icons/bs'
|
|
6
|
-
import {
|
|
7
|
-
VscOrganization, VscSymbolMethod, VscSymbolNamespace,
|
|
8
|
-
} from 'react-icons/vsc'
|
|
9
|
-
|
|
10
|
-
export interface ArchivistStatsProps {
|
|
11
|
-
addresses?: Record<string, number>
|
|
12
|
-
boundWitnesses?: Payload[] | null
|
|
13
|
-
payloads?: Payload[] | null
|
|
14
|
-
schemas?: Record<string, number>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const ArchivistStats: React.FC<ArchivistStatsProps> = ({
|
|
18
|
-
addresses, boundWitnesses, payloads, schemas,
|
|
19
|
-
}) => {
|
|
20
|
-
return (
|
|
21
|
-
<FlexRow gap={2} mr={0.5}>
|
|
22
|
-
{payloads?.length
|
|
23
|
-
? (
|
|
24
|
-
<Tooltip title="Payloads">
|
|
25
|
-
<Badge badgeContent={payloads?.length} color="primary">
|
|
26
|
-
<VscSymbolNamespace size={20} />
|
|
27
|
-
</Badge>
|
|
28
|
-
</Tooltip>
|
|
29
|
-
)
|
|
30
|
-
: null}
|
|
31
|
-
{boundWitnesses?.length
|
|
32
|
-
? (
|
|
33
|
-
<Tooltip title="Blocks">
|
|
34
|
-
<Badge badgeContent={boundWitnesses?.length} color="primary">
|
|
35
|
-
<VscSymbolMethod size={20} />
|
|
36
|
-
</Badge>
|
|
37
|
-
</Tooltip>
|
|
38
|
-
)
|
|
39
|
-
: null}
|
|
40
|
-
{Object.entries(schemas ?? {}).length > 0
|
|
41
|
-
? (
|
|
42
|
-
<Tooltip title="Schemas">
|
|
43
|
-
<Badge badgeContent={Object.entries(schemas ?? {}).length} color="primary">
|
|
44
|
-
<BsFileEarmarkCode size={20} />
|
|
45
|
-
</Badge>
|
|
46
|
-
</Tooltip>
|
|
47
|
-
)
|
|
48
|
-
: null}
|
|
49
|
-
{Object.entries(addresses ?? {}).length > 0
|
|
50
|
-
? (
|
|
51
|
-
<Tooltip title="Addresses">
|
|
52
|
-
<Badge badgeContent={Object.entries(addresses ?? {}).length} color="primary">
|
|
53
|
-
<VscOrganization size={20} />
|
|
54
|
-
</Badge>
|
|
55
|
-
</Tooltip>
|
|
56
|
-
)
|
|
57
|
-
: null}
|
|
58
|
-
</FlexRow>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryFn } from '@storybook/react-vite'
|
|
2
|
-
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
3
|
-
import { Account } from '@xyo-network/account'
|
|
4
|
-
import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
|
|
5
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
6
|
-
import { ArchivistInsertQuerySchema } from '@xyo-network/archivist-model'
|
|
7
|
-
import { QueryBoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
8
|
-
import { MemoryNode } from '@xyo-network/node-memory'
|
|
9
|
-
import { asSchema } from '@xyo-network/payload-model'
|
|
10
|
-
import React, { useState } from 'react'
|
|
11
|
-
|
|
12
|
-
import { MemoryArchivistsStats } from './MemoryArchivistStats.tsx'
|
|
13
|
-
|
|
14
|
-
const StorybookEntry = {
|
|
15
|
-
component: MemoryArchivistsStats,
|
|
16
|
-
parameters: { docs: { page: null } },
|
|
17
|
-
title: 'modules/archivist/MemoryArchivistsStats',
|
|
18
|
-
} as Meta<typeof MemoryArchivistsStats>
|
|
19
|
-
|
|
20
|
-
const Template: StoryFn<typeof MemoryArchivistsStats> = () => {
|
|
21
|
-
const [mod, setMod] = useState<ArchivistInstance>()
|
|
22
|
-
|
|
23
|
-
useAsyncEffect(
|
|
24
|
-
async () => {
|
|
25
|
-
if (!mod) {
|
|
26
|
-
const node = await MemoryNode.create({})
|
|
27
|
-
const newParentModule = await MemoryArchivist.create({})
|
|
28
|
-
const newModule = await MemoryArchivist.create({
|
|
29
|
-
config: {
|
|
30
|
-
name: 'MemoryArchivist',
|
|
31
|
-
parents: {
|
|
32
|
-
commit: [newParentModule.address], read: [newParentModule.address], write: [newParentModule.address],
|
|
33
|
-
},
|
|
34
|
-
schema: MemoryArchivistConfigSchema,
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
const payload = { schema: asSchema('network.xyo.payload', true) }
|
|
38
|
-
const insertQuery = { schema: ArchivistInsertQuerySchema }
|
|
39
|
-
const account = await Account.random()
|
|
40
|
-
const builder = new QueryBoundWitnessBuilder().payloads([insertQuery, payload]).signer(account).query(insertQuery)
|
|
41
|
-
const [insertQueryBoundWitness, payloads] = await builder.build()
|
|
42
|
-
await node.register(newParentModule)
|
|
43
|
-
await node.attach(newParentModule.address)
|
|
44
|
-
await node.register(newModule)
|
|
45
|
-
await node.attach(newModule.address)
|
|
46
|
-
await newModule.insert([insertQueryBoundWitness, ...payloads])
|
|
47
|
-
setMod(newModule)
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
[mod],
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
return <MemoryArchivistsStats archivist={mod} />
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const Default = Template.bind({})
|
|
57
|
-
|
|
58
|
-
export { Default }
|
|
59
|
-
|
|
60
|
-
export default StorybookEntry
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { EventUnsubscribeFunction } from '@xylabs/events'
|
|
2
|
-
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
3
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import { ArchivistAllQuerySchema } from '@xyo-network/archivist-model'
|
|
5
|
-
import { asBoundWitness, BoundWitnessSchema } from '@xyo-network/boundwitness-model'
|
|
6
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
7
|
-
import React, {
|
|
8
|
-
useCallback, useEffect, useMemo, useState,
|
|
9
|
-
} from 'react'
|
|
10
|
-
|
|
11
|
-
import { ArchivistStats } from './ArchivistStats.tsx'
|
|
12
|
-
|
|
13
|
-
export interface MemoryArchivistStatsProps {
|
|
14
|
-
archivist?: ArchivistInstance
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const MemoryArchivistsStats: React.FC<MemoryArchivistStatsProps> = ({ archivist }) => {
|
|
18
|
-
const [all, setAll] = useState<Payload[] | null>()
|
|
19
|
-
|
|
20
|
-
const getAll = useCallback(async (archivist?: ArchivistInstance) => {
|
|
21
|
-
const all = await archivist?.all?.()
|
|
22
|
-
setAll(all)
|
|
23
|
-
}, [])
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
const listeners: EventUnsubscribeFunction[] = []
|
|
27
|
-
|
|
28
|
-
if (archivist?.queries.includes(ArchivistAllQuerySchema)) {
|
|
29
|
-
const insertListener = archivist.on('inserted', async () => {
|
|
30
|
-
await getAll(archivist)
|
|
31
|
-
})
|
|
32
|
-
listeners.push(insertListener)
|
|
33
|
-
|
|
34
|
-
const clearListener = archivist.on('cleared', async () => {
|
|
35
|
-
await getAll(archivist)
|
|
36
|
-
})
|
|
37
|
-
listeners.push(clearListener)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return () => {
|
|
41
|
-
for (const listener of listeners) listener?.()
|
|
42
|
-
}
|
|
43
|
-
}, [archivist, getAll])
|
|
44
|
-
|
|
45
|
-
useAsyncEffect(
|
|
46
|
-
async () => {
|
|
47
|
-
if (archivist?.queries.includes(ArchivistAllQuerySchema)) {
|
|
48
|
-
await getAll(archivist)
|
|
49
|
-
} else {
|
|
50
|
-
setAll(null)
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
[archivist, getAll],
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
const payloads = useMemo(() => (all === null ? [] : all?.filter(payload => payload.schema !== BoundWitnessSchema)), [all])
|
|
57
|
-
const boundWitnesses = useMemo(() => (all === null ? [] : all?.filter(payload => payload.schema === BoundWitnessSchema)), [all])
|
|
58
|
-
const addresses = useMemo(() => {
|
|
59
|
-
const addressCounts: Record<string, number> = {}
|
|
60
|
-
if (all) {
|
|
61
|
-
for (const payload of all) {
|
|
62
|
-
const w = asBoundWitness(payload)
|
|
63
|
-
if (w?.addresses) {
|
|
64
|
-
for (const address of w.addresses) {
|
|
65
|
-
addressCounts[address] = (addressCounts[address] ?? 0) + 1
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return addressCounts
|
|
71
|
-
}, [all])
|
|
72
|
-
const schemas = useMemo(() => {
|
|
73
|
-
const schemaCounts: Record<string, number> = {}
|
|
74
|
-
if (all) {
|
|
75
|
-
for (const payload of all) {
|
|
76
|
-
schemaCounts[payload.schema] = (schemaCounts[payload.schema] ?? 0) + 1
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return schemaCounts
|
|
80
|
-
}, [all])
|
|
81
|
-
|
|
82
|
-
return <ArchivistStats addresses={addresses} boundWitnesses={boundWitnesses} payloads={payloads} schemas={schemas} />
|
|
83
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryFn } from '@storybook/react-vite'
|
|
2
|
-
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
3
|
-
import type { ArchivistModuleInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import { asSchema } from '@xyo-network/payload-model'
|
|
5
|
-
import { NodeProvider } from '@xyo-network/react-node'
|
|
6
|
-
import type { FC } from 'react'
|
|
7
|
-
import React, { useState } from 'react'
|
|
8
|
-
|
|
9
|
-
import { useWeakArchivistFromNode } from '../../hooks/index.ts'
|
|
10
|
-
import type { ArchivistDetailsProps } from './Details.tsx'
|
|
11
|
-
import { ArchivistDetails } from './Details.tsx'
|
|
12
|
-
|
|
13
|
-
const StorybookEntry = {
|
|
14
|
-
argTypes: {},
|
|
15
|
-
component: ArchivistDetails,
|
|
16
|
-
parameters: { docs: { page: null } },
|
|
17
|
-
title: 'modules/archivist/Details',
|
|
18
|
-
} as Meta<typeof ArchivistDetails>
|
|
19
|
-
|
|
20
|
-
const TemplateInner: StoryFn<typeof ArchivistDetails> = (args) => {
|
|
21
|
-
const [archivist] = useWeakArchivistFromNode()
|
|
22
|
-
|
|
23
|
-
return <ArchivistDetails address={archivist?.deref()?.address} {...args}></ArchivistDetails>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const TemplateInnerWithData: StoryFn<typeof ArchivistDetails> = (args) => {
|
|
27
|
-
const [archivist] = useWeakArchivistFromNode()
|
|
28
|
-
const [archivistWithData, setArchivistWithData] = useState<ArchivistModuleInstance>()
|
|
29
|
-
|
|
30
|
-
useAsyncEffect(
|
|
31
|
-
async (mounted) => {
|
|
32
|
-
if (archivist?.deref()) {
|
|
33
|
-
await archivist.deref()?.insert([{ schema: asSchema('network.xyo.test', true) }])
|
|
34
|
-
if (mounted()) {
|
|
35
|
-
setArchivistWithData(archivist.deref())
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
[archivist],
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
return <ArchivistDetails address={archivistWithData?.address} {...args}></ArchivistDetails>
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const TemplateInnerComponent = TemplateInner as FC<ArchivistDetailsProps>
|
|
46
|
-
|
|
47
|
-
const TemplateWithNoData: StoryFn<typeof ArchivistDetails> = args => (
|
|
48
|
-
<NodeProvider>
|
|
49
|
-
<TemplateInnerComponent {...args}></TemplateInnerComponent>
|
|
50
|
-
</NodeProvider>
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
const TemplateInnerWithDataComponent = TemplateInnerWithData as FC<ArchivistDetailsProps>
|
|
54
|
-
|
|
55
|
-
const TemplateWithData: StoryFn<typeof ArchivistDetails> = args => (
|
|
56
|
-
<NodeProvider>
|
|
57
|
-
<TemplateInnerWithDataComponent {...args}></TemplateInnerWithDataComponent>
|
|
58
|
-
</NodeProvider>
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
const WithNoArchivist = TemplateInner.bind({})
|
|
62
|
-
WithNoArchivist.args = {}
|
|
63
|
-
|
|
64
|
-
const WithNoData = TemplateWithNoData.bind({})
|
|
65
|
-
TemplateWithNoData.args = {}
|
|
66
|
-
|
|
67
|
-
const WithData = TemplateWithData.bind({})
|
|
68
|
-
TemplateWithData.args = {}
|
|
69
|
-
|
|
70
|
-
export {
|
|
71
|
-
WithData, WithNoArchivist, WithNoData,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export default StorybookEntry
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { ButtonGroup, Typography } from '@mui/material'
|
|
2
|
-
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
3
|
-
import { ButtonEx } from '@xylabs/react-button'
|
|
4
|
-
import type { FlexBoxProps } from '@xylabs/react-flexbox'
|
|
5
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
6
|
-
import { ArchivistClearQuerySchema, ArchivistCommitQuerySchema } from '@xyo-network/archivist-model'
|
|
7
|
-
import { QueryBoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
8
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
9
|
-
import React, { useState } from 'react'
|
|
10
|
-
|
|
11
|
-
import { useWeakArchivistFromNode } from '../../hooks/index.ts'
|
|
12
|
-
|
|
13
|
-
const testQueryCommit = { schema: ArchivistCommitQuerySchema }
|
|
14
|
-
const testQueryCommitBoundWitnessBuilder = new QueryBoundWitnessBuilder().query(testQueryCommit)
|
|
15
|
-
|
|
16
|
-
const testQueryClear = { schema: ArchivistClearQuerySchema }
|
|
17
|
-
const testQueryClearBoundWitnessBuilder = new QueryBoundWitnessBuilder().query(testQueryClear)
|
|
18
|
-
|
|
19
|
-
export interface ArchivistDetailsProps extends FlexBoxProps {
|
|
20
|
-
address?: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const ArchivistDetails: React.FC<ArchivistDetailsProps> = ({ address, ...props }) => {
|
|
24
|
-
const [archivist] = useWeakArchivistFromNode(address)
|
|
25
|
-
const [payloads, setPayloads] = useState<Payload[]>()
|
|
26
|
-
const [refresh, setRefresh] = useState(0)
|
|
27
|
-
const [queryableCommit, setQueryableCommit] = useState(false)
|
|
28
|
-
const [queryableClear, setQueryableClear] = useState(false)
|
|
29
|
-
|
|
30
|
-
useAsyncEffect(
|
|
31
|
-
async () => {
|
|
32
|
-
const instance = archivist?.deref()
|
|
33
|
-
if (instance) {
|
|
34
|
-
const [commitBW] = await testQueryCommitBoundWitnessBuilder.build()
|
|
35
|
-
const [clearBW] = await testQueryClearBoundWitnessBuilder.build()
|
|
36
|
-
setQueryableCommit(await instance?.queryable(commitBW, [testQueryCommit]))
|
|
37
|
-
setQueryableClear(await instance?.queryable(clearBW, [testQueryClear]))
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
[archivist],
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
useAsyncEffect(
|
|
44
|
-
async (mounted) => {
|
|
45
|
-
const payloads = await archivist?.deref()?.all?.()
|
|
46
|
-
if (mounted()) {
|
|
47
|
-
setPayloads(payloads)
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
[archivist, refresh],
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<FlexCol {...props}>
|
|
55
|
-
<Typography>{`Payloads: ${payloads ? payloads.length : '-'}`}</Typography>
|
|
56
|
-
<ButtonGroup>
|
|
57
|
-
<ButtonEx disabled={payloads?.length === 0 || !archivist || !queryableCommit} onClick={() => archivist?.deref()?.commit?.()}>
|
|
58
|
-
Commit
|
|
59
|
-
</ButtonEx>
|
|
60
|
-
<ButtonEx disabled={!archivist || !queryableClear} onClick={() => archivist?.deref()?.clear?.()}>
|
|
61
|
-
Clear
|
|
62
|
-
</ButtonEx>
|
|
63
|
-
<ButtonEx
|
|
64
|
-
disabled={!archivist}
|
|
65
|
-
onClick={() => {
|
|
66
|
-
setRefresh(refresh + 1)
|
|
67
|
-
}}
|
|
68
|
-
>
|
|
69
|
-
Refresh
|
|
70
|
-
</ButtonEx>
|
|
71
|
-
</ButtonGroup>
|
|
72
|
-
</FlexCol>
|
|
73
|
-
)
|
|
74
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Details.tsx'
|
package/src/components/index.ts
DELETED
package/src/hooks/index.ts
DELETED
package/src/hooks/node/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
-
import { asArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
-
import type { ModuleFromNodeConfig } from '@xyo-network/react-node'
|
|
4
|
-
import { useModuleFromNode } from '@xyo-network/react-node'
|
|
5
|
-
|
|
6
|
-
/** @deprecated use useWeakArchivistFromNode */
|
|
7
|
-
export const useArchivistFromNode = (
|
|
8
|
-
nameOrAddressOrInstance?: string | ArchivistInstance,
|
|
9
|
-
config?: ModuleFromNodeConfig,
|
|
10
|
-
): [ArchivistInstance | undefined, Error | undefined] => {
|
|
11
|
-
const [mod, error] = useModuleFromNode(nameOrAddressOrInstance, config)
|
|
12
|
-
const instance = asArchivistInstance(mod)
|
|
13
|
-
if (mod && !instance) {
|
|
14
|
-
const error = new Error(`Resolved module is not a ArchivistInstance [${mod.config?.schema}:${mod.config?.name}:${mod.address}]`)
|
|
15
|
-
console.error(error.message)
|
|
16
|
-
return [undefined, error]
|
|
17
|
-
}
|
|
18
|
-
return [instance, error]
|
|
19
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
-
import { isArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
-
import type { ModuleIdentifier } from '@xyo-network/module-model'
|
|
4
|
-
import type { ModuleFromNodeConfig } from '@xyo-network/react-node'
|
|
5
|
-
import { useModulesFromNode } from '@xyo-network/react-node'
|
|
6
|
-
|
|
7
|
-
/** @deprecated use useWeakArchivistsFromNode */
|
|
8
|
-
export const useArchivistsFromNode = (
|
|
9
|
-
ids?: ModuleIdentifier[],
|
|
10
|
-
config?: ModuleFromNodeConfig,
|
|
11
|
-
): [ArchivistInstance[] | null | undefined, Error | undefined] => {
|
|
12
|
-
const [modules, error] = useModulesFromNode(ids, config)
|
|
13
|
-
if (error) {
|
|
14
|
-
return [null, error]
|
|
15
|
-
}
|
|
16
|
-
return modules
|
|
17
|
-
? [
|
|
18
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
19
|
-
modules.reduce<ArchivistInstance[]>((prev, mod) => {
|
|
20
|
-
if (isArchivistInstance(mod)) {
|
|
21
|
-
prev.push(mod)
|
|
22
|
-
}
|
|
23
|
-
return prev
|
|
24
|
-
}, []),
|
|
25
|
-
undefined,
|
|
26
|
-
]
|
|
27
|
-
: [modules, error]
|
|
28
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
-
import { isArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
-
import type { WeakModuleFromNodeConfig } from '@xyo-network/react-node'
|
|
4
|
-
import { useWeakModuleFromNode } from '@xyo-network/react-node'
|
|
5
|
-
|
|
6
|
-
export const useWeakArchivistFromNode = (
|
|
7
|
-
nameOrAddressOrInstance?: string | ArchivistInstance,
|
|
8
|
-
config?: WeakModuleFromNodeConfig,
|
|
9
|
-
): [WeakRef<ArchivistInstance> | undefined, Error | undefined] => {
|
|
10
|
-
return useWeakModuleFromNode<ArchivistInstance>(nameOrAddressOrInstance, { identity: isArchivistInstance, ...config })
|
|
11
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { exists } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
-
import { asArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import type { ModuleIdentifier } from '@xyo-network/module-model'
|
|
5
|
-
import type { ModuleFromNodeConfig } from '@xyo-network/react-node'
|
|
6
|
-
import { useWeakModulesFromNode } from '@xyo-network/react-node'
|
|
7
|
-
|
|
8
|
-
export const useWeakArchivistsFromNode = (
|
|
9
|
-
ids?: ModuleIdentifier[],
|
|
10
|
-
config?: ModuleFromNodeConfig,
|
|
11
|
-
): [WeakRef<ArchivistInstance>[] | null | undefined, Error | undefined] => {
|
|
12
|
-
const [modules, error] = useWeakModulesFromNode(ids, config)
|
|
13
|
-
if (error) {
|
|
14
|
-
return [null, error]
|
|
15
|
-
}
|
|
16
|
-
return [
|
|
17
|
-
modules
|
|
18
|
-
?.map((mod) => {
|
|
19
|
-
const instance = asArchivistInstance(mod?.deref())
|
|
20
|
-
if (instance) {
|
|
21
|
-
return new WeakRef(instance)
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
.filter(exists) ?? [],
|
|
25
|
-
undefined,
|
|
26
|
-
]
|
|
27
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
-
import { useRefresh } from '@xyo-network/react-module'
|
|
4
|
-
import { useState } from 'react'
|
|
5
|
-
|
|
6
|
-
export const useArchivistAll = (archivist: ArchivistInstance) => {
|
|
7
|
-
const [error, setError] = useState<Error>()
|
|
8
|
-
const [enabled, refresh] = useRefresh()
|
|
9
|
-
|
|
10
|
-
const payloads = usePromise(async () => {
|
|
11
|
-
try {
|
|
12
|
-
if (enabled) {
|
|
13
|
-
return await archivist?.all?.()
|
|
14
|
-
}
|
|
15
|
-
} catch (ex) {
|
|
16
|
-
const error = ex as Error
|
|
17
|
-
setError(error)
|
|
18
|
-
}
|
|
19
|
-
}, [archivist, enabled])
|
|
20
|
-
|
|
21
|
-
return [payloads, error, refresh]
|
|
22
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
3
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
5
|
-
import type { RefreshCallback } from '@xyo-network/react-module'
|
|
6
|
-
import { useRefresh } from '@xyo-network/react-module'
|
|
7
|
-
|
|
8
|
-
export const useArchivistGet = <T extends Payload = Payload>(
|
|
9
|
-
archivist?: ArchivistInstance | null,
|
|
10
|
-
hashes?: Hash[],
|
|
11
|
-
): [T[] | undefined, Error | undefined, RefreshCallback] => {
|
|
12
|
-
const [enabled, refresh] = useRefresh()
|
|
13
|
-
|
|
14
|
-
const [payloads, error] = usePromise(async () => {
|
|
15
|
-
if (enabled && archivist && hashes) {
|
|
16
|
-
return (await archivist.get(hashes)) as WithStorageMeta<T>[]
|
|
17
|
-
}
|
|
18
|
-
}, [archivist, hashes, enabled])
|
|
19
|
-
|
|
20
|
-
return [payloads, error, refresh]
|
|
21
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
-
import { useRefresh } from '@xyo-network/react-module'
|
|
4
|
-
import { useState } from 'react'
|
|
5
|
-
|
|
6
|
-
export const useWeakArchivistAll = (archivist: WeakRef<ArchivistInstance>) => {
|
|
7
|
-
const [error, setError] = useState<Error>()
|
|
8
|
-
const [enabled, refresh] = useRefresh()
|
|
9
|
-
|
|
10
|
-
const payloads = usePromise(async () => {
|
|
11
|
-
try {
|
|
12
|
-
if (enabled) {
|
|
13
|
-
return await archivist?.deref()?.all?.()
|
|
14
|
-
}
|
|
15
|
-
} catch (ex) {
|
|
16
|
-
const error = ex as Error
|
|
17
|
-
setError(error)
|
|
18
|
-
}
|
|
19
|
-
}, [archivist, enabled])
|
|
20
|
-
|
|
21
|
-
return [payloads, error, refresh]
|
|
22
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
3
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
5
|
-
import type { RefreshCallback } from '@xyo-network/react-module'
|
|
6
|
-
import { useRefresh } from '@xyo-network/react-module'
|
|
7
|
-
|
|
8
|
-
export const useWeakArchivistGet = <T extends Payload = Payload>(
|
|
9
|
-
archivist?: WeakRef<ArchivistInstance> | null,
|
|
10
|
-
hashes?: Hash[],
|
|
11
|
-
): [T[] | undefined, Error | undefined, RefreshCallback] => {
|
|
12
|
-
const [enabled, refresh] = useRefresh()
|
|
13
|
-
|
|
14
|
-
const [payloads, error] = usePromise(async () => {
|
|
15
|
-
const archivistInstance = archivist?.deref()
|
|
16
|
-
if (enabled && archivistInstance && hashes) {
|
|
17
|
-
return (await archivistInstance.get(hashes)) as WithStorageMeta<T>[]
|
|
18
|
-
}
|
|
19
|
-
}, [archivist, hashes, enabled])
|
|
20
|
-
|
|
21
|
-
return [payloads, error, refresh]
|
|
22
|
-
}
|
package/src/index.ts
DELETED