@codama/renderers-js 1.3.5 → 1.4.1
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/LICENSE +1 -1
- package/dist/index.browser.cjs +3247 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.mjs +3300 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.node.cjs +1742 -1956
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +1644 -1866
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.react-native.mjs +3300 -0
- package/dist/index.react-native.mjs.map +1 -0
- package/dist/types/fragments/accountFetchHelpers.d.ts +2 -4
- package/dist/types/fragments/accountFetchHelpers.d.ts.map +1 -1
- package/dist/types/fragments/accountPage.d.ts +8 -0
- package/dist/types/fragments/accountPage.d.ts.map +1 -0
- package/dist/types/fragments/accountPdaHelpers.d.ts +3 -5
- package/dist/types/fragments/accountPdaHelpers.d.ts.map +1 -1
- package/dist/types/fragments/accountSizeHelpers.d.ts +3 -4
- package/dist/types/fragments/accountSizeHelpers.d.ts.map +1 -1
- package/dist/types/fragments/accountType.d.ts +3 -5
- package/dist/types/fragments/accountType.d.ts.map +1 -1
- package/dist/types/fragments/discriminatorCondition.d.ts +2 -3
- package/dist/types/fragments/discriminatorCondition.d.ts.map +1 -1
- package/dist/types/fragments/discriminatorConstants.d.ts +5 -6
- package/dist/types/fragments/discriminatorConstants.d.ts.map +1 -1
- package/dist/types/fragments/errorPage.d.ts +6 -0
- package/dist/types/fragments/errorPage.d.ts.map +1 -0
- package/dist/types/fragments/index.d.ts +11 -3
- package/dist/types/fragments/index.d.ts.map +1 -1
- package/dist/types/fragments/indexPage.d.ts +6 -0
- package/dist/types/fragments/indexPage.d.ts.map +1 -0
- package/dist/types/fragments/instructionAccountMeta.d.ts.map +1 -1
- package/dist/types/fragments/instructionAccountTypeParam.d.ts +2 -3
- package/dist/types/fragments/instructionAccountTypeParam.d.ts.map +1 -1
- package/dist/types/fragments/instructionByteDelta.d.ts +3 -4
- package/dist/types/fragments/instructionByteDelta.d.ts.map +1 -1
- package/dist/types/fragments/instructionData.d.ts +3 -5
- package/dist/types/fragments/instructionData.d.ts.map +1 -1
- package/dist/types/fragments/instructionExtraArgs.d.ts +3 -5
- package/dist/types/fragments/instructionExtraArgs.d.ts.map +1 -1
- package/dist/types/fragments/instructionFunction.d.ts +3 -5
- package/dist/types/fragments/instructionFunction.d.ts.map +1 -1
- package/dist/types/fragments/instructionInputDefault.d.ts +2 -3
- package/dist/types/fragments/instructionInputDefault.d.ts.map +1 -1
- package/dist/types/fragments/instructionInputResolved.d.ts +2 -3
- package/dist/types/fragments/instructionInputResolved.d.ts.map +1 -1
- package/dist/types/fragments/instructionInputType.d.ts +2 -4
- package/dist/types/fragments/instructionInputType.d.ts.map +1 -1
- package/dist/types/fragments/instructionPage.d.ts +9 -0
- package/dist/types/fragments/instructionPage.d.ts.map +1 -0
- package/dist/types/fragments/instructionParseFunction.d.ts +2 -4
- package/dist/types/fragments/instructionParseFunction.d.ts.map +1 -1
- package/dist/types/fragments/instructionRemainingAccounts.d.ts +3 -4
- package/dist/types/fragments/instructionRemainingAccounts.d.ts.map +1 -1
- package/dist/types/fragments/instructionType.d.ts +2 -3
- package/dist/types/fragments/instructionType.d.ts.map +1 -1
- package/dist/types/fragments/pdaFunction.d.ts +2 -3
- package/dist/types/fragments/pdaFunction.d.ts.map +1 -1
- package/dist/types/fragments/pdaPage.d.ts +7 -0
- package/dist/types/fragments/pdaPage.d.ts.map +1 -0
- package/dist/types/fragments/programAccounts.d.ts +3 -4
- package/dist/types/fragments/programAccounts.d.ts.map +1 -1
- package/dist/types/fragments/programConstant.d.ts +6 -0
- package/dist/types/fragments/programConstant.d.ts.map +1 -0
- package/dist/types/fragments/programInstructions.d.ts +3 -4
- package/dist/types/fragments/programInstructions.d.ts.map +1 -1
- package/dist/types/fragments/programPage.d.ts +6 -0
- package/dist/types/fragments/programPage.d.ts.map +1 -0
- package/dist/types/fragments/rootIndexPage.d.ts +10 -0
- package/dist/types/fragments/rootIndexPage.d.ts.map +1 -0
- package/dist/types/fragments/sharedPage.d.ts +3 -0
- package/dist/types/fragments/sharedPage.d.ts.map +1 -0
- package/dist/types/fragments/type.d.ts +2 -4
- package/dist/types/fragments/type.d.ts.map +1 -1
- package/dist/types/fragments/typeCodec.d.ts +2 -4
- package/dist/types/fragments/typeCodec.d.ts.map +1 -1
- package/dist/types/fragments/typeDecoder.d.ts +2 -4
- package/dist/types/fragments/typeDecoder.d.ts.map +1 -1
- package/dist/types/fragments/typeDiscriminatedUnionHelpers.d.ts +3 -4
- package/dist/types/fragments/typeDiscriminatedUnionHelpers.d.ts.map +1 -1
- package/dist/types/fragments/typeEncoder.d.ts +2 -4
- package/dist/types/fragments/typeEncoder.d.ts.map +1 -1
- package/dist/types/fragments/typePage.d.ts +7 -0
- package/dist/types/fragments/typePage.d.ts.map +1 -0
- package/dist/types/fragments/typeWithCodec.d.ts +2 -4
- package/dist/types/fragments/typeWithCodec.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/fragment.d.ts +12 -8
- package/dist/types/utils/fragment.d.ts.map +1 -1
- package/dist/types/utils/importMap.d.ts +17 -0
- package/dist/types/utils/importMap.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +4 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/nameTransformers.d.ts.map +1 -0
- package/dist/types/utils/options.d.ts +40 -0
- package/dist/types/utils/options.d.ts.map +1 -0
- package/dist/types/{TypeManifest.d.ts → utils/typeManifest.d.ts} +2 -2
- package/dist/types/utils/typeManifest.d.ts.map +1 -0
- package/dist/types/visitors/getRenderMapVisitor.d.ts +3 -0
- package/dist/types/visitors/getRenderMapVisitor.d.ts.map +1 -0
- package/dist/types/{getTypeManifestVisitor.d.ts → visitors/getTypeManifestVisitor.d.ts} +1 -2
- package/dist/types/visitors/getTypeManifestVisitor.d.ts.map +1 -0
- package/dist/types/visitors/index.d.ts +4 -0
- package/dist/types/visitors/index.d.ts.map +1 -0
- package/dist/types/visitors/renderVisitor.d.ts +3 -0
- package/dist/types/visitors/renderVisitor.d.ts.map +1 -0
- package/package.json +26 -21
- package/dist/templates/fragments/accountFetchHelpers.njk +0 -43
- package/dist/templates/fragments/accountPdaHelpers.njk +0 -25
- package/dist/templates/fragments/accountSizeHelpers.njk +0 -3
- package/dist/templates/fragments/instructionExtraArgs.njk +0 -4
- package/dist/templates/fragments/instructionFunction.njk +0 -62
- package/dist/templates/fragments/instructionInputType.njk +0 -16
- package/dist/templates/fragments/instructionParseFunction.njk +0 -81
- package/dist/templates/fragments/instructionType.njk +0 -18
- package/dist/templates/fragments/pdaFunction.njk +0 -33
- package/dist/templates/fragments/program.njk +0 -3
- package/dist/templates/fragments/programErrors.njk +0 -36
- package/dist/templates/fragments/type.njk +0 -12
- package/dist/templates/fragments/typeCodec.njk +0 -6
- package/dist/templates/fragments/typeDecoder.njk +0 -6
- package/dist/templates/fragments/typeDiscriminatedUnionHelpers.njk +0 -23
- package/dist/templates/fragments/typeEncoder.njk +0 -6
- package/dist/templates/layout.njk +0 -9
- package/dist/templates/macros.njk +0 -12
- package/dist/templates/pages/accountsIndex.njk +0 -9
- package/dist/templates/pages/accountsPage.njk +0 -12
- package/dist/templates/pages/definedTypesIndex.njk +0 -9
- package/dist/templates/pages/definedTypesPage.njk +0 -9
- package/dist/templates/pages/errorsIndex.njk +0 -9
- package/dist/templates/pages/errorsPage.njk +0 -8
- package/dist/templates/pages/instructionsIndex.njk +0 -9
- package/dist/templates/pages/instructionsPage.njk +0 -14
- package/dist/templates/pages/pdasIndex.njk +0 -9
- package/dist/templates/pages/pdasPage.njk +0 -8
- package/dist/templates/pages/programsIndex.njk +0 -9
- package/dist/templates/pages/programsPage.njk +0 -10
- package/dist/templates/pages/rootIndex.njk +0 -26
- package/dist/templates/pages/sharedPage.njk +0 -106
- package/dist/types/ImportMap.d.ts +0 -15
- package/dist/types/ImportMap.d.ts.map +0 -1
- package/dist/types/TypeManifest.d.ts.map +0 -1
- package/dist/types/fragments/program.d.ts +0 -7
- package/dist/types/fragments/program.d.ts.map +0 -1
- package/dist/types/fragments/programErrors.d.ts +0 -7
- package/dist/types/fragments/programErrors.d.ts.map +0 -1
- package/dist/types/getRenderMapVisitor.d.ts +0 -30
- package/dist/types/getRenderMapVisitor.d.ts.map +0 -1
- package/dist/types/getTypeManifestVisitor.d.ts.map +0 -1
- package/dist/types/nameTransformers.d.ts.map +0 -1
- package/dist/types/renderVisitor.d.ts +0 -11
- package/dist/types/renderVisitor.d.ts.map +0 -1
- package/dist/types/utils/render.d.ts +0 -4
- package/dist/types/utils/render.d.ts.map +0 -1
- /package/dist/types/{nameTransformers.d.ts → utils/nameTransformers.d.ts} +0 -0
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
{{ inputTypeFragment }}
|
|
2
|
-
|
|
3
|
-
export {{ 'async' if useAsync }} function {{ functionName }}{{ typeParamsFragment }}({% if hasInput %}input: {{ inputTypeCallFragment }}, {% endif %}config?: { programAddress?: TProgramAddress } ): {{ getReturnType(instructionTypeFragment) }} {
|
|
4
|
-
// Program address.
|
|
5
|
-
const programAddress = config?.programAddress ?? {{ programAddressConstant }};
|
|
6
|
-
|
|
7
|
-
{% if hasAccounts %}
|
|
8
|
-
// Original accounts.
|
|
9
|
-
const originalAccounts = {
|
|
10
|
-
{% for account in instruction.accounts %}
|
|
11
|
-
{{ account.name | camelCase }}: { value: input.{{ account.name | camelCase }} ?? null, isWritable: {{ "true" if account.isWritable else "false" }} },
|
|
12
|
-
{% endfor %}
|
|
13
|
-
};
|
|
14
|
-
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
|
|
15
|
-
{% endif %}
|
|
16
|
-
|
|
17
|
-
{% if hasAnyArgs %}
|
|
18
|
-
// Original args.
|
|
19
|
-
const args = { ...input, {{ renamedArgs }} };
|
|
20
|
-
{% endif %}
|
|
21
|
-
|
|
22
|
-
{% if hasResolver %}
|
|
23
|
-
// Resolver scope.
|
|
24
|
-
const resolverScope = { programAddress{{ ', accounts' if hasAccounts }}{{ ', args' if hasAnyArgs }} };
|
|
25
|
-
{% endif %}
|
|
26
|
-
|
|
27
|
-
{{ resolvedFragment }}
|
|
28
|
-
|
|
29
|
-
{% if hasAccounts %}
|
|
30
|
-
const getAccountMeta = getAccountMetaFactory(programAddress, '{{ 'omitted' if instruction.optionalAccountStrategy === 'omitted' else 'programId' }}');
|
|
31
|
-
{% endif %}
|
|
32
|
-
const instruction = {
|
|
33
|
-
{%- if hasAccounts -%}
|
|
34
|
-
accounts: [
|
|
35
|
-
{% for account in instruction.accounts %}
|
|
36
|
-
getAccountMeta(accounts.{{ account.name | camelCase }}),
|
|
37
|
-
{% endfor %}
|
|
38
|
-
{% if hasRemainingAccounts %}
|
|
39
|
-
...remainingAccounts,
|
|
40
|
-
{% endif %}
|
|
41
|
-
]
|
|
42
|
-
{%- if hasLegacyOptionalAccounts -%}
|
|
43
|
-
.filter(<T>(x: T | undefined): x is T => x !== undefined)
|
|
44
|
-
{% endif %}
|
|
45
|
-
,
|
|
46
|
-
{%- elif hasRemainingAccounts -%}
|
|
47
|
-
accounts: remainingAccounts,
|
|
48
|
-
{% endif %}
|
|
49
|
-
programAddress,
|
|
50
|
-
{% if hasDataArgs %}
|
|
51
|
-
data: {{ encoderFunction }}.encode(args as {{ argsTypeFragment }}),
|
|
52
|
-
{% elif hasData %}
|
|
53
|
-
data: {{ encoderFunction }}.encode({}),
|
|
54
|
-
{% endif %}
|
|
55
|
-
} as {{ instructionTypeFragment }};
|
|
56
|
-
|
|
57
|
-
{% if hasByteDeltas %}
|
|
58
|
-
return Object.freeze({ ...instruction, byteDelta });
|
|
59
|
-
{% else %}
|
|
60
|
-
return instruction;
|
|
61
|
-
{% endif %}
|
|
62
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{% import "macros.njk" as macros %}
|
|
2
|
-
|
|
3
|
-
export type {{ instructionInputType }}
|
|
4
|
-
{%- if instruction.accounts.length > 0 -%}
|
|
5
|
-
<
|
|
6
|
-
{%- for account in instruction.accounts -%}
|
|
7
|
-
TAccount{{ account.name | pascalCase }} extends string = string,
|
|
8
|
-
{% endfor %}
|
|
9
|
-
>
|
|
10
|
-
{% endif %}
|
|
11
|
-
= {{ customDataArgumentsFragment }} {
|
|
12
|
-
{{ accountsFragment -}}
|
|
13
|
-
{{ dataArgumentsFragment -}}
|
|
14
|
-
{{ extraArgumentsFragment -}}
|
|
15
|
-
{{ remainingAccountsFragment }}
|
|
16
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
{% import "macros.njk" as macros %}
|
|
2
|
-
|
|
3
|
-
export type {{ instructionParsedType }}<
|
|
4
|
-
TProgram extends string = typeof {{ programAddressConstant }},
|
|
5
|
-
{% if hasAccounts %}
|
|
6
|
-
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
7
|
-
{% endif %}
|
|
8
|
-
> = {
|
|
9
|
-
programAddress: Address<TProgram>;
|
|
10
|
-
{% if hasAccounts %}
|
|
11
|
-
accounts: {
|
|
12
|
-
{% for account in instruction.accounts %}
|
|
13
|
-
{% if account.docs.length > 0 %}
|
|
14
|
-
{{ macros.docblock(account.docs) }}
|
|
15
|
-
{% endif %}
|
|
16
|
-
{{ account.name | camelCase }}{{ '?' if account.isOptional }}: TAccountMetas[{{ loop.index0 }}]{{ ' | undefined' if account.isOptional }},
|
|
17
|
-
{% endfor %}
|
|
18
|
-
};
|
|
19
|
-
{% endif %}
|
|
20
|
-
{% if hasData %}
|
|
21
|
-
data: {{ dataTypeFragment }};
|
|
22
|
-
{% endif %}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export function {{ instructionParseFunction }}<
|
|
26
|
-
TProgram extends string,
|
|
27
|
-
{% if hasAccounts %}
|
|
28
|
-
TAccountMetas extends readonly AccountMeta[],
|
|
29
|
-
{% endif %}
|
|
30
|
-
>(
|
|
31
|
-
instruction: Instruction<TProgram>
|
|
32
|
-
{% if hasAccounts %}
|
|
33
|
-
& InstructionWithAccounts<TAccountMetas>
|
|
34
|
-
{% endif %}
|
|
35
|
-
{% if hasData %}
|
|
36
|
-
& InstructionWithData<ReadonlyUint8Array>
|
|
37
|
-
{% endif %}
|
|
38
|
-
): {{ instructionParsedType }}<TProgram {{ ', TAccountMetas' if hasAccounts }}> {
|
|
39
|
-
{% if hasAccounts %}
|
|
40
|
-
if (instruction.accounts.length < {{ minimumNumberOfAccounts }}) {
|
|
41
|
-
// TODO: Coded error.
|
|
42
|
-
throw new Error('Not enough accounts');
|
|
43
|
-
}
|
|
44
|
-
let accountIndex = 0;
|
|
45
|
-
const getNextAccount = () => {
|
|
46
|
-
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
47
|
-
accountIndex += 1;
|
|
48
|
-
return accountMeta;
|
|
49
|
-
}
|
|
50
|
-
{% if hasOptionalAccounts and instruction.optionalAccountStrategy === 'omitted' %}
|
|
51
|
-
let optionalAccountsRemaining = instruction.accounts.length - {{ minimumNumberOfAccounts }};
|
|
52
|
-
const getNextOptionalAccount = () => {
|
|
53
|
-
if (optionalAccountsRemaining === 0) return undefined;
|
|
54
|
-
optionalAccountsRemaining -= 1;
|
|
55
|
-
return getNextAccount();
|
|
56
|
-
};
|
|
57
|
-
{% elif hasOptionalAccounts %}
|
|
58
|
-
const getNextOptionalAccount = () => {
|
|
59
|
-
const accountMeta = getNextAccount();
|
|
60
|
-
return accountMeta.address === {{ programAddressConstant }} ? undefined : accountMeta;
|
|
61
|
-
};
|
|
62
|
-
{% endif %}
|
|
63
|
-
{% endif %}
|
|
64
|
-
return {
|
|
65
|
-
programAddress: instruction.programAddress,
|
|
66
|
-
{% if hasAccounts %}
|
|
67
|
-
accounts: {
|
|
68
|
-
{% for account in instruction.accounts %}
|
|
69
|
-
{% if account.isOptional %}
|
|
70
|
-
{{ account.name | camelCase }}: getNextOptionalAccount(),
|
|
71
|
-
{% else %}
|
|
72
|
-
{{ account.name | camelCase }}: getNextAccount(),
|
|
73
|
-
{% endif %}
|
|
74
|
-
{% endfor %}
|
|
75
|
-
},
|
|
76
|
-
{% endif %}
|
|
77
|
-
{% if hasData %}
|
|
78
|
-
data: {{ decoderFunction }}.decode(instruction.data),
|
|
79
|
-
{% endif %}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{% import "macros.njk" as macros %}
|
|
2
|
-
|
|
3
|
-
export type {{ instructionType }}<
|
|
4
|
-
TProgram extends string = typeof {{ programAddressConstant }},
|
|
5
|
-
{% if hasAccounts %}
|
|
6
|
-
{{ accountTypeParams }},
|
|
7
|
-
{% endif %}
|
|
8
|
-
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
9
|
-
> = Instruction<TProgram>
|
|
10
|
-
{% if hasData %}
|
|
11
|
-
& InstructionWithData<ReadonlyUint8Array>
|
|
12
|
-
{% endif %}
|
|
13
|
-
{% if hasAccounts %}
|
|
14
|
-
& InstructionWithAccounts<[{{ accountMetas }}, ...TRemainingAccounts]>
|
|
15
|
-
{% else %}
|
|
16
|
-
& InstructionWithAccounts<TRemainingAccounts>
|
|
17
|
-
{% endif %}
|
|
18
|
-
;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{% import "macros.njk" as macros %}
|
|
2
|
-
|
|
3
|
-
{% if hasVariableSeeds %}
|
|
4
|
-
export type {{ pdaSeedsType }} = {
|
|
5
|
-
{% for seed in seeds %}
|
|
6
|
-
{% if seed.kind === 'variablePdaSeedNode' %}
|
|
7
|
-
{{ macros.docblock(seed.docs) }}
|
|
8
|
-
{{ seed.name | camelCase }}: {{ seed.typeManifest.looseType.content }};
|
|
9
|
-
{% endif %}
|
|
10
|
-
{% endfor %}
|
|
11
|
-
}
|
|
12
|
-
{% endif %}
|
|
13
|
-
|
|
14
|
-
{{ macros.docblock(pdaDocs) }}
|
|
15
|
-
export async function {{ findPdaFunction }}(
|
|
16
|
-
{% if hasVariableSeeds %}
|
|
17
|
-
seeds: {{ pdaSeedsType }},
|
|
18
|
-
{% endif %}
|
|
19
|
-
config: { programAddress?: Address | undefined } = {},
|
|
20
|
-
): Promise<ProgramDerivedAddress> {
|
|
21
|
-
const { programAddress = '{{ programAddress }}' as Address<'{{ programAddress }}'> } = config;
|
|
22
|
-
return await getProgramDerivedAddress({ programAddress, seeds: [
|
|
23
|
-
{% for seed in seeds %}
|
|
24
|
-
{% if seed.kind === 'constantPdaSeedNode' and seed.value.kind === 'programIdValueNode' %}
|
|
25
|
-
getAddressEncoder().encode(programAddress),
|
|
26
|
-
{% elif seed.kind === 'constantPdaSeedNode' %}
|
|
27
|
-
{{ seed.typeManifest.encoder.content }}.encode({{ seed.valueManifest.content }}),
|
|
28
|
-
{% else %}
|
|
29
|
-
{{ seed.typeManifest.encoder.content }}.encode(seeds.{{ seed.name | camelCase }}),
|
|
30
|
-
{% endif %}
|
|
31
|
-
{% endfor %}
|
|
32
|
-
]});
|
|
33
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{% import "macros.njk" as macros %}
|
|
2
|
-
|
|
3
|
-
{% for error in errors | sort(false, false, 'code') %}
|
|
4
|
-
{{ macros.docblock(error.docs) }}
|
|
5
|
-
export const {{ getProgramErrorConstant(error.name) }} = 0x{{ error.code.toString(16) }}; // {{ error.code }}
|
|
6
|
-
{% endfor %}
|
|
7
|
-
|
|
8
|
-
export type {{ programErrorUnion }} =
|
|
9
|
-
{% for error in errors | sort(false, false, 'name') %}
|
|
10
|
-
| typeof {{ getProgramErrorConstant(error.name) }}
|
|
11
|
-
{% endfor %};
|
|
12
|
-
|
|
13
|
-
let {{ programErrorMessagesMap }}: Record<{{ programErrorUnion }}, string> | undefined;
|
|
14
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
15
|
-
{{ programErrorMessagesMap }} = {
|
|
16
|
-
{% for error in errors | sort(false, false, 'name') %}
|
|
17
|
-
[{{ getProgramErrorConstant(error.name) }}]: `{{ escapeProgramErrorMessage(error.message) }}`,
|
|
18
|
-
{% endfor %}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function {{ programGetErrorMessageFunction }}(code: {{ programErrorUnion }}): string {
|
|
23
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
24
|
-
return ({{ programErrorMessagesMap }} as Record<{{ programErrorUnion }}, string>)[code];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return 'Error message not available in production bundles.';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function {{ programIsErrorFunction }}<TProgramErrorCode extends {{ programErrorUnion }}>(
|
|
31
|
-
error: unknown,
|
|
32
|
-
transactionMessage: { instructions: Record<number, { programAddress: Address }> },
|
|
33
|
-
code?: TProgramErrorCode,
|
|
34
|
-
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> & Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
|
|
35
|
-
return isProgramError<TProgramErrorCode>(error, transactionMessage, {{ programAddressConstant }}, code);
|
|
36
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{% import "macros.njk" as macros %}
|
|
2
|
-
|
|
3
|
-
{{ macros.docblock(docs) }}
|
|
4
|
-
{% if manifest.isEnum %}
|
|
5
|
-
export enum {{ strictName }} {{ manifest.strictType.content }};
|
|
6
|
-
|
|
7
|
-
export type {{ looseName }} = {{ strictName }};
|
|
8
|
-
{% else %}
|
|
9
|
-
export type {{ strictName }} = {{ manifest.strictType.content }};
|
|
10
|
-
|
|
11
|
-
export type {{ looseName }} = {{ manifest.looseType.content if manifest.strictType.content != manifest.looseType.content else strictName }};
|
|
12
|
-
{% endif %}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Data Enum Helpers.
|
|
2
|
-
{% for variant in typeNode.variants %}
|
|
3
|
-
{% if variant.kind === 'enumStructVariantTypeNode' %}
|
|
4
|
-
export function {{ discriminatedUnionFunction }}(kind: '{{ getVariant(variant.name) }}', data: GetDiscriminatedUnionVariantContent<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>): GetDiscriminatedUnionVariant<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>;
|
|
5
|
-
{% elif variant.kind === 'enumTupleVariantTypeNode' %}
|
|
6
|
-
export function {{ discriminatedUnionFunction }}(kind: '{{ getVariant(variant.name) }}', data: GetDiscriminatedUnionVariantContent<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>['fields']): GetDiscriminatedUnionVariant<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>;
|
|
7
|
-
{% else %}
|
|
8
|
-
export function {{ discriminatedUnionFunction }}(kind: '{{ getVariant(variant.name) }}'): GetDiscriminatedUnionVariant<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>;
|
|
9
|
-
{% endif %}
|
|
10
|
-
{% endfor %}
|
|
11
|
-
export function {{ discriminatedUnionFunction }}<K extends {{ looseName }}['{{ discriminatedUnionDiscriminator }}'], Data>(
|
|
12
|
-
kind: K,
|
|
13
|
-
data?: Data,
|
|
14
|
-
) {
|
|
15
|
-
return Array.isArray(data) ? { {{ discriminatedUnionDiscriminator }}: kind, fields: data } : { {{ discriminatedUnionDiscriminator }}: kind, ...(data ?? {}) };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function {{ isDiscriminatedUnionFunction }}<K extends {{ strictName }}['{{ discriminatedUnionDiscriminator }}']>(
|
|
19
|
-
kind: K,
|
|
20
|
-
value: {{ strictName }},
|
|
21
|
-
): value is {{ strictName }} & { {{ discriminatedUnionDiscriminator }}: K } {
|
|
22
|
-
return value.{{ discriminatedUnionDiscriminator }} === kind;
|
|
23
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{# Write a docblock from an array of strings. #}
|
|
2
|
-
{% macro docblock(docs) %}
|
|
3
|
-
{%- if docs.length === 1 -%}
|
|
4
|
-
/** {{ docs[0] }} */
|
|
5
|
-
{%- elif docs.length > 1 -%}
|
|
6
|
-
/**
|
|
7
|
-
{% for doc in docs %}
|
|
8
|
-
* {{ doc }}
|
|
9
|
-
{% endfor %}
|
|
10
|
-
*/
|
|
11
|
-
{% endif %}
|
|
12
|
-
{% endmacro %}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{% extends "layout.njk" %}
|
|
2
|
-
{% import "macros.njk" as macros %}
|
|
3
|
-
|
|
4
|
-
{% block main %}
|
|
5
|
-
{{ imports }}
|
|
6
|
-
|
|
7
|
-
{{ accountDiscriminatorConstantsFragment }}
|
|
8
|
-
{{ accountTypeFragment }}
|
|
9
|
-
{{ accountFetchHelpersFragment }}
|
|
10
|
-
{{ accountSizeHelpersFragment }}
|
|
11
|
-
{{ accountPdaHelpersFragment }}
|
|
12
|
-
{% endblock %}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{% extends "layout.njk" %}
|
|
2
|
-
{% import "macros.njk" as macros %}
|
|
3
|
-
|
|
4
|
-
{% block main %}
|
|
5
|
-
{{ imports }}
|
|
6
|
-
|
|
7
|
-
{{ instructionDiscriminatorConstantsFragment }}
|
|
8
|
-
{{ instructionTypeFragment }}
|
|
9
|
-
{{ instructionDataFragment }}
|
|
10
|
-
{{ instructionExtraArgsFragment }}
|
|
11
|
-
{{ instructionFunctionAsyncFragment }}
|
|
12
|
-
{{ instructionFunctionSyncFragment }}
|
|
13
|
-
{{ instructionParseFunctionFragment }}
|
|
14
|
-
{% endblock %}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{% extends "layout.njk" %}
|
|
2
|
-
|
|
3
|
-
{% block main %}
|
|
4
|
-
{% if hasAnythingToExport %}
|
|
5
|
-
{% if accountsToExport.length > 0 %}
|
|
6
|
-
export * from './accounts';
|
|
7
|
-
{% endif %}
|
|
8
|
-
{% if programsWithErrorsToExport.length > 0 %}
|
|
9
|
-
export * from './errors';
|
|
10
|
-
{% endif %}
|
|
11
|
-
{% if instructionsToExport.length > 0 %}
|
|
12
|
-
export * from './instructions';
|
|
13
|
-
{% endif %}
|
|
14
|
-
{% if pdasToExport.length > 0 %}
|
|
15
|
-
export * from './pdas';
|
|
16
|
-
{% endif %}
|
|
17
|
-
{% if programsToExport.length > 0 %}
|
|
18
|
-
export * from './programs';
|
|
19
|
-
{% endif %}
|
|
20
|
-
{% if definedTypesToExport.length > 0 %}
|
|
21
|
-
export * from './types';
|
|
22
|
-
{% endif %}
|
|
23
|
-
{% else %}
|
|
24
|
-
export default {};
|
|
25
|
-
{% endif %}
|
|
26
|
-
{% endblock %}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
{% extends "layout.njk" %}
|
|
2
|
-
{% import "macros.njk" as macros %}
|
|
3
|
-
|
|
4
|
-
{% block main %}
|
|
5
|
-
{{ imports }}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Asserts that the given value is not null or undefined.
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export function expectSome<T>(value: T | null | undefined): T {
|
|
12
|
-
if (value === null || value === undefined) {
|
|
13
|
-
throw new Error('Expected a value but received null or undefined.');
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Asserts that the given value is a PublicKey.
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
export function expectAddress<T extends string = string>(
|
|
23
|
-
value: Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null | undefined
|
|
24
|
-
): Address<T> {
|
|
25
|
-
if (!value) {
|
|
26
|
-
throw new Error('Expected a Address.');
|
|
27
|
-
}
|
|
28
|
-
if (typeof value === 'object' && "address" in value) {
|
|
29
|
-
return value.address;
|
|
30
|
-
}
|
|
31
|
-
if (Array.isArray(value)) {
|
|
32
|
-
return value[0] as Address<T>;
|
|
33
|
-
}
|
|
34
|
-
return value as Address<T>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Asserts that the given value is a PDA.
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
|
-
export function expectProgramDerivedAddress<T extends string = string>(
|
|
42
|
-
value: Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null | undefined
|
|
43
|
-
): ProgramDerivedAddress<T> {
|
|
44
|
-
if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) {
|
|
45
|
-
throw new Error('Expected a ProgramDerivedAddress.');
|
|
46
|
-
}
|
|
47
|
-
return value;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Asserts that the given value is a TransactionSigner.
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
export function expectTransactionSigner<T extends string = string>(
|
|
55
|
-
value: Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null | undefined
|
|
56
|
-
): TransactionSigner<T> {
|
|
57
|
-
if (!value || !isTransactionSigner(value)) {
|
|
58
|
-
throw new Error('Expected a TransactionSigner.');
|
|
59
|
-
}
|
|
60
|
-
return value;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Defines an instruction account to resolve.
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
export type ResolvedAccount<T extends string = string, U extends Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null = Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null> = {
|
|
68
|
-
isWritable: boolean;
|
|
69
|
-
value: U;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Defines an instruction that stores additional bytes on-chain.
|
|
74
|
-
* @internal
|
|
75
|
-
*/
|
|
76
|
-
export type InstructionWithByteDelta = {
|
|
77
|
-
byteDelta: number;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Get account metas and signers from resolved accounts.
|
|
82
|
-
* @internal
|
|
83
|
-
*/
|
|
84
|
-
export function getAccountMetaFactory(
|
|
85
|
-
programAddress: Address,
|
|
86
|
-
optionalAccountStrategy: 'omitted' | 'programId',
|
|
87
|
-
) {
|
|
88
|
-
return (account: ResolvedAccount): AccountMeta | AccountSignerMeta | undefined => {
|
|
89
|
-
if (!account.value) {
|
|
90
|
-
if (optionalAccountStrategy === 'omitted') return;
|
|
91
|
-
return Object.freeze({ address: programAddress, role: AccountRole.READONLY });
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;
|
|
95
|
-
return Object.freeze({
|
|
96
|
-
address: expectAddress(account.value),
|
|
97
|
-
role: isTransactionSigner(account.value) ? upgradeRoleToSigner(writableRole) : writableRole,
|
|
98
|
-
...(isTransactionSigner(account.value) ? { signer: account.value } : {})
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function isTransactionSigner<TAddress extends string = string>(value: Address<TAddress> | ProgramDerivedAddress<TAddress> | TransactionSigner<TAddress>): value is TransactionSigner<TAddress> {
|
|
104
|
-
return !!value && typeof value === 'object' && 'address' in value && kitIsTransactionSigner(value);
|
|
105
|
-
}
|
|
106
|
-
{% endblock %}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { TypeManifest } from './TypeManifest';
|
|
2
|
-
import { Fragment } from './utils';
|
|
3
|
-
export declare class ImportMap {
|
|
4
|
-
protected readonly _imports: Map<string, Set<string>>;
|
|
5
|
-
protected readonly _aliases: Map<string, Record<string, string>>;
|
|
6
|
-
add(module: string, imports: Set<string> | string[] | string): ImportMap;
|
|
7
|
-
remove(module: string, imports: Set<string> | string[] | string): ImportMap;
|
|
8
|
-
mergeWith(...others: (Fragment | ImportMap)[]): ImportMap;
|
|
9
|
-
mergeWithManifest(manifest: TypeManifest): ImportMap;
|
|
10
|
-
addAlias(module: string, name: string, alias: string): ImportMap;
|
|
11
|
-
isEmpty(): boolean;
|
|
12
|
-
resolve(dependencies?: Record<string, string>, useGranularImports?: boolean): Map<string, Set<string>>;
|
|
13
|
-
toString(dependencies?: Record<string, string>, useGranularImports?: boolean): string;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=ImportMap.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ImportMap.d.ts","sourceRoot":"","sources":["../../src/ImportMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AA8CnC,qBAAa,SAAS;IAClB,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAa;IAElE,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAa;IAE7E,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS;IASxE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS;IAa3E,SAAS,CAAC,GAAG,MAAM,EAAE,CAAC,QAAQ,GAAG,SAAS,CAAC,EAAE,GAAG,SAAS;IAezD,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS;IAIpD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS;IAOhE,OAAO,IAAI,OAAO;IAIlB,OAAO,CAAC,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAAE,kBAAkB,UAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IA2BxG,QAAQ,CAAC,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAAE,kBAAkB,UAAQ,GAAG,MAAM;CA0B1F"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TypeManifest.d.ts","sourceRoot":"","sources":["../../src/TypeManifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA4B,MAAM,SAAS,CAAC;AAE7D,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;IAChC,OAAO,EAAE,QAAQ,CAAC;IAClB,OAAO,EAAE,QAAQ,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,QAAQ,CAAC;IACpB,UAAU,EAAE,QAAQ,CAAC;IACrB,KAAK,EAAE,QAAQ,CAAC;CACnB,CAAC,CAAC;AAEH,wBAAgB,YAAY,CAAC,KAAK,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,YAAY,CAU5E;AAED,wBAAgB,kBAAkB,CAC9B,SAAS,EAAE,YAAY,EAAE,EACzB,OAAO,GAAE;IACL,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;IAC5C,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;IAC3C,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;CAC1C,GACP,YAAY,CAYd"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ProgramNode } from '@codama/nodes';
|
|
2
|
-
import type { GlobalFragmentScope } from '../getRenderMapVisitor';
|
|
3
|
-
import { Fragment } from '../utils';
|
|
4
|
-
export declare function getProgramFragment(scope: Pick<GlobalFragmentScope, 'nameApi'> & {
|
|
5
|
-
programNode: ProgramNode;
|
|
6
|
-
}): Fragment;
|
|
7
|
-
//# sourceMappingURL=program.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../../src/fragments/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAsB,QAAQ,EAAwB,MAAM,UAAU,CAAC;AAE9E,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,GAAG;IAC1C,WAAW,EAAE,WAAW,CAAC;CAC5B,GACF,QAAQ,CAUV"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ProgramNode } from '@codama/nodes';
|
|
2
|
-
import type { GlobalFragmentScope } from '../getRenderMapVisitor';
|
|
3
|
-
import { Fragment } from '../utils';
|
|
4
|
-
export declare function getProgramErrorsFragment(scope: Pick<GlobalFragmentScope, 'nameApi'> & {
|
|
5
|
-
programNode: ProgramNode;
|
|
6
|
-
}): Fragment;
|
|
7
|
-
//# sourceMappingURL=programErrors.d.ts.map
|