Skip to content

Commit

Permalink
Simplify helper method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Dec 18, 2024
1 parent b0f596e commit b8f0c70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import type { ModuleIdentifier } from '@xyo-network/module-model'
import type { NodeInstance } from '@xyo-network/node-model'
import { NodeConfigSchema, type NodeInstance } from '@xyo-network/node-model'

import type { MemoryNodeParams } from '../MemoryNode.ts'
import { MemoryNode } from '../MemoryNode.ts'
import { attachToExistingNode } from './attachToExistingNode.ts'

export const attachToNewNode = async (source: NodeInstance, id: ModuleIdentifier, destinationParams: MemoryNodeParams): Promise<NodeInstance> => {
const DEFAULT_NODE_PARAMS = { config: { schema: NodeConfigSchema } }

export const attachToNewNode = async (
source: NodeInstance,
id: ModuleIdentifier,
destinationParams: MemoryNodeParams = DEFAULT_NODE_PARAMS,
): Promise<NodeInstance> => {
const destination = await MemoryNode.create(destinationParams)
return await attachToExistingNode(source, id, destination)
}
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ describe('MemoryNode', () => {
expect(prettyPrintDescription(description)).toMatchSnapshot()
})
it('clone-all', async () => {
const newNode = await MemoryNodeHelper.attachToNewNode(node, '*', { config: { schema: NodeConfigSchema } })
const newNode = await MemoryNodeHelper.attachToNewNode(node, '*')
const newNodeChildren = await newNode.publicChildren()
const nodeChildren = await node.publicChildren()
expect(newNodeChildren.length).toEqual(nodeChildren.length)
Expand All @@ -322,7 +322,7 @@ describe('MemoryNode', () => {
await node.register(mod)
await node.attach(mod.address, true)

const newNode = await MemoryNodeHelper.attachToNewNode(node, 'CloneModule', { config: { schema: NodeConfigSchema } })
const newNode = await MemoryNodeHelper.attachToNewNode(node, 'CloneModule')
const newNodeChild = await newNode.resolve('CloneModule')
const nodeChild = await node.resolve('CloneModule', { maxDepth: 1 })
expect(newNodeChild?.id).toEqual(nodeChild?.id)
Expand All @@ -336,7 +336,7 @@ describe('MemoryNode', () => {

try {
// this should except
await MemoryNodeHelper.attachToNewNode(node, 'CloneModulePrivate', { config: { schema: NodeConfigSchema } })
await MemoryNodeHelper.attachToNewNode(node, 'CloneModulePrivate')
expect(false).toBeTrue()
} catch (e) {
expect(e).toBeInstanceOf(Error)
Expand Down

0 comments on commit b8f0c70

Please sign in to comment.