-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
728e68b
commit 122bb39
Showing
30 changed files
with
303 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@metaplex-foundation/kinobi': minor | ||
--- | ||
|
||
Create Size nodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Node } from '../Node'; | ||
|
||
export type FixedSizeNode = { | ||
readonly kind: 'fixedSizeNode'; | ||
readonly size: number; | ||
}; | ||
|
||
export function fixedSizeNode(size: number): FixedSizeNode { | ||
return { kind: 'fixedSizeNode', size }; | ||
} | ||
|
||
export function isFixedSizeNode(node: Node | null): node is FixedSizeNode { | ||
return !!node && node.kind === 'fixedSizeNode'; | ||
} | ||
|
||
export function assertFixedSizeNode( | ||
node: Node | null | ||
): asserts node is FixedSizeNode { | ||
if (!isFixedSizeNode(node)) { | ||
throw new Error(`Expected fixedSizeNode, got ${node?.kind ?? 'null'}.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Node } from '../Node'; | ||
import { NumberTypeNode } from '../typeNodes'; | ||
|
||
export type PrefixedSizeNode = { | ||
readonly kind: 'prefixedSizeNode'; | ||
readonly prefix: NumberTypeNode; | ||
}; | ||
|
||
export function prefixedSizeNode(prefix: NumberTypeNode): PrefixedSizeNode { | ||
return { kind: 'prefixedSizeNode', prefix }; | ||
} | ||
|
||
export function isPrefixedSizeNode( | ||
node: Node | null | ||
): node is PrefixedSizeNode { | ||
return !!node && node.kind === 'prefixedSizeNode'; | ||
} | ||
|
||
export function assertPrefixedSizeNode( | ||
node: Node | null | ||
): asserts node is PrefixedSizeNode { | ||
if (!isPrefixedSizeNode(node)) { | ||
throw new Error(`Expected prefixedSizeNode, got ${node?.kind ?? 'null'}.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Node } from '../Node'; | ||
|
||
export type RemainderSizeNode = { | ||
readonly kind: 'remainderSizeNode'; | ||
}; | ||
|
||
export function remainderSizeNode(): RemainderSizeNode { | ||
return { kind: 'remainderSizeNode' }; | ||
} | ||
|
||
export function isRemainderSizeNode( | ||
node: Node | null | ||
): node is RemainderSizeNode { | ||
return !!node && node.kind === 'remainderSizeNode'; | ||
} | ||
|
||
export function assertRemainderSizeNode( | ||
node: Node | null | ||
): asserts node is RemainderSizeNode { | ||
if (!isRemainderSizeNode(node)) { | ||
throw new Error(`Expected remainderSizeNode, got ${node?.kind ?? 'null'}.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Node } from '../Node'; | ||
import type { FixedSizeNode } from './FixedSizeNode'; | ||
import type { PrefixedSizeNode } from './PrefixedSizeNode'; | ||
import type { RemainderSizeNode } from './RemainderSizeNode'; | ||
|
||
export const REGISTERED_SIZE_NODES = { | ||
fixedSizeNode: {} as FixedSizeNode, | ||
remainderSizeNode: {} as RemainderSizeNode, | ||
prefixedSizeNode: {} as PrefixedSizeNode, | ||
}; | ||
|
||
export const REGISTERED_SIZE_NODE_KEYS = Object.keys( | ||
REGISTERED_SIZE_NODES | ||
) as (keyof typeof REGISTERED_SIZE_NODES)[]; | ||
|
||
export type RegisteredSizeNodes = typeof REGISTERED_SIZE_NODES; | ||
|
||
export type SizeNode = RegisteredSizeNodes[keyof RegisteredSizeNodes]; | ||
|
||
export function isSizeNode(node: Node | null): node is SizeNode { | ||
return !!node && (REGISTERED_SIZE_NODE_KEYS as string[]).includes(node.kind); | ||
} | ||
|
||
export function assertSizeNode(node: Node | null): asserts node is SizeNode { | ||
if (!isSizeNode(node)) { | ||
throw new Error(`Expected typeNode, got ${node?.kind ?? 'null'}.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './FixedSizeNode'; | ||
export * from './PrefixedSizeNode'; | ||
export * from './RemainderSizeNode'; | ||
export * from './SizeNode'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.