Loris Leiva 159c18856d Fix CI (#330) 11 tháng trước cách đây
..
contextualValueNodes 159c18856d Fix CI (#330) 11 tháng trước cách đây
countNodes 159c18856d Fix CI (#330) 11 tháng trước cách đây
discriminatorNodes 159c18856d Fix CI (#330) 11 tháng trước cách đây
linkNodes 159c18856d Fix CI (#330) 11 tháng trước cách đây
pdaSeedNodes 159c18856d Fix CI (#330) 11 tháng trước cách đây
typeNodes 159c18856d Fix CI (#330) 11 tháng trước cách đây
valueNodes 159c18856d Fix CI (#330) 11 tháng trước cách đây
AccountNode.md e9d56c993f Rename Kinobi to Codama (#234) 1 năm trước cách đây
DefinedTypeNode.md e9d56c993f Rename Kinobi to Codama (#234) 1 năm trước cách đây
ErrorNode.md e9d56c993f Rename Kinobi to Codama (#234) 1 năm trước cách đây
InstructionAccountNode.md e9d56c993f Rename Kinobi to Codama (#234) 1 năm trước cách đây
InstructionArgumentNode.md e9d56c993f Rename Kinobi to Codama (#234) 1 năm trước cách đây
InstructionByteDeltaNode.md 4d0d3afb16 Add node documentation — Part 4: Top-level nodes (#99) 1 năm trước cách đây
InstructionNode.md e9d56c993f Rename Kinobi to Codama (#234) 1 năm trước cách đây
InstructionRemainingAccountsNode.md 4d0d3afb16 Add node documentation — Part 4: Top-level nodes (#99) 1 năm trước cách đây
PdaNode.md e9d56c993f Rename Kinobi to Codama (#234) 1 năm trước cách đây
ProgramNode.md e9d56c993f Rename Kinobi to Codama (#234) 1 năm trước cách đây
README.md 4d0d3afb16 Add node documentation — Part 4: Top-level nodes (#99) 1 năm trước cách đây
RootNode.md e9d56c993f Rename Kinobi to Codama (#234) 1 năm trước cách đây
_template.md cf3fe9183a Add node documentation — Part 5: Other nodes (#101) 1 năm trước cách đây

README.md

Node (abstract)

The Node type helper represents all available nodes. Note that Node is a type alias and cannot be used directly as a node. Instead you may use any node to satisfy the Node type. You can see all available nodes here.

Functions

Some helper functions are also available to work with nodes.

isNode(node, kind)

Type guard that checks if a node is of a specific kind or part of a list of kinds. If the provided node is null or undefined, the function returns false.

isNode(stringTypeNode('utf8'), 'stringTypeNode'); // true.
isNode(stringTypeNode('utf8'), 'numberTypeNode'); // false.
isNode(stringTypeNode('utf8'), ['stringTypeNode', 'numberTypeNode']); // true.
isNode(null, 'stringTypeNode'); // false.
isNode(undefined, 'stringTypeNode'); // false.

assertIsNode(node, kind)

Type guard that asserts that a node is of a specific kind or part of a list of kinds. If the provided node is null or undefined, the function throws an error.

assertIsNode(stringTypeNode('utf8'), 'stringTypeNode'); // Ok.
assertIsNode(stringTypeNode('utf8'), 'numberTypeNode'); // Throws an error.
assertIsNode(stringTypeNode('utf8'), ['stringTypeNode', 'numberTypeNode']); // Ok.
assertIsNode(null, 'stringTypeNode'); // Throws an error.
assertIsNode(undefined, 'stringTypeNode'); // Throws an error.

isNodeFilter(kind)

This function returns a function that acts as the isNode function but with a predefined kind or list of kinds to check against. This is a useful function to use in combination with array functions like filter.

myNodes.filter(isNodeFilter('stringTypeNode')); // Keep only string type nodes.
myNodes.filter(isNodeFilter(['stringTypeNode', 'numberTypeNode'])); // Keep only string and number type nodes.

assertIsNodeFilter(kind)

This function returns a function that acts as the assertIsNode function but with a predefined kind or list of kinds to check against. This is a useful function to use in combination with array functions like filter.

myNodes.filter(assertIsNodeFilter('stringTypeNode')); // Fail if there are non-string type node.
myNodes.filter(assertIsNodeFilter(['stringTypeNode', 'numberTypeNode'])); // Fail if there are nodes that are not string or number type nodes.

removeNullAndAssertIsNodeFilter(kind)

This function acts like the assertIsNodeFilter function below but removes null and undefined values before asserting the kind or kinds.

const myNodes = [null, stringTypeNode('utf8'), undefined, stringTypeNode('base58')];

myNodes.filter(removeNullAndAssertIsNodeFilter('stringTypeNode')); // Ok and removes null and undefined values.
myNodes.filter(removeNullAndAssertIsNodeFilter('numberTypeNode')); // Throws an error.
myNodes.filter(removeNullAndAssertIsNodeFilter(['stringTypeNode', 'numberTypeNode'])); // Ok and removes null and undefined values.