-
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.
Implement ConstantValueNode type manifests (#200)
- Loading branch information
1 parent
3726e1f
commit 75f5f91
Showing
17 changed files
with
563 additions
and
433 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 | ||
--- | ||
|
||
Implement ConstantValueNode type manifests |
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 |
---|---|---|
@@ -1,35 +1,45 @@ | ||
import { Fragment, mergeFragments } from './fragments'; | ||
import { Fragment, fragment, mergeFragments } from './fragments'; | ||
|
||
export type TypeManifest = { | ||
isEnum: boolean; | ||
strictType: Fragment; | ||
looseType: Fragment; | ||
encoder: Fragment; | ||
decoder: Fragment; | ||
value: Fragment; | ||
}; | ||
|
||
export function typeManifest(): TypeManifest { | ||
return { | ||
isEnum: false, | ||
strictType: fragment(''), | ||
looseType: fragment(''), | ||
encoder: fragment(''), | ||
decoder: fragment(''), | ||
value: fragment(''), | ||
}; | ||
} | ||
|
||
export function mergeManifests( | ||
manifests: TypeManifest[], | ||
mergeTypes: (renders: string[]) => string, | ||
mergeCodecs: (renders: string[]) => string | ||
options: { | ||
mergeTypes?: (renders: string[]) => string; | ||
mergeCodecs?: (renders: string[]) => string; | ||
mergeValues?: (renders: string[]) => string; | ||
} = {} | ||
): TypeManifest { | ||
const { mergeTypes, mergeCodecs, mergeValues } = options; | ||
const merge = ( | ||
fragmentFn: (m: TypeManifest) => Fragment, | ||
mergeFn?: (r: string[]) => string | ||
) => | ||
mergeFn ? mergeFragments(manifests.map(fragmentFn), mergeFn) : fragment(''); | ||
return { | ||
isEnum: false, | ||
strictType: mergeFragments( | ||
manifests.map((m) => m.strictType), | ||
mergeTypes | ||
), | ||
looseType: mergeFragments( | ||
manifests.map((m) => m.looseType), | ||
mergeTypes | ||
), | ||
encoder: mergeFragments( | ||
manifests.map((m) => m.encoder), | ||
mergeCodecs | ||
), | ||
decoder: mergeFragments( | ||
manifests.map((m) => m.decoder), | ||
mergeCodecs | ||
), | ||
strictType: merge((m) => m.strictType, mergeTypes), | ||
looseType: merge((m) => m.looseType, mergeTypes), | ||
encoder: merge((m) => m.encoder, mergeCodecs), | ||
decoder: merge((m) => m.decoder, mergeCodecs), | ||
value: merge((m) => m.value, mergeValues), | ||
}; | ||
} |
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
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.