codama-renderers-dart 0.5.1 → 0.5.4

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.
Files changed (37) hide show
  1. package/{readme.md → README.md} +16 -43
  2. package/dist/index.browser.cjs +345 -124
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +346 -125
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.node.cjs +345 -124
  7. package/dist/index.node.cjs.map +1 -1
  8. package/dist/index.node.js +346 -125
  9. package/dist/index.node.js.map +1 -1
  10. package/dist/index.react-native.js +346 -125
  11. package/dist/index.react-native.js.map +1 -1
  12. package/dist/types/fragments/accountPage.d.ts.map +1 -1
  13. package/dist/types/fragments/errorPage.d.ts.map +1 -1
  14. package/dist/types/fragments/instructionPage.d.ts.map +1 -1
  15. package/dist/types/fragments/pdaPage.d.ts.map +1 -1
  16. package/dist/types/fragments/programPage.d.ts.map +1 -1
  17. package/dist/types/utils/nameTransformers.d.ts +5 -0
  18. package/dist/types/utils/nameTransformers.d.ts.map +1 -1
  19. package/dist/types/utils/valueNodes.d.ts +4 -0
  20. package/dist/types/utils/valueNodes.d.ts.map +1 -1
  21. package/dist/types/visitors/getRenderMapVisitor.d.ts.map +1 -1
  22. package/dist/types/visitors/getTypeManifestVisitor.d.ts +1 -1
  23. package/dist/types/visitors/getTypeManifestVisitor.d.ts.map +1 -1
  24. package/dist/types/visitors/renderVisitor.d.ts.map +1 -1
  25. package/package.json +7 -7
  26. package/src/fragments/accountPage.ts +2 -1
  27. package/src/fragments/errorPage.ts +8 -5
  28. package/src/fragments/instructionPage.ts +54 -17
  29. package/src/fragments/pdaPage.ts +7 -14
  30. package/src/fragments/programPage.ts +3 -2
  31. package/src/fragments/typePage.ts +102 -19
  32. package/src/utils/formatCode.ts +2 -2
  33. package/src/utils/nameTransformers.ts +39 -1
  34. package/src/utils/valueNodes.ts +24 -1
  35. package/src/visitors/getRenderMapVisitor.ts +30 -5
  36. package/src/visitors/getTypeManifestVisitor.ts +123 -81
  37. package/src/visitors/renderVisitor.ts +11 -13
@@ -6,6 +6,8 @@ A [Codama](https://github.com/codama-idl/codama) renderer that generates Dart co
6
6
 
7
7
  Given a Codama IDL (Interface Description Language) describing a Solana program, this renderer produces a complete Dart package with typed account classes, instruction builders, codec functions, error definitions, PDA helpers, and barrel exports.
8
8
 
9
+ Numeric prefix codecs retain the declared byte order, and pre/post offset types retain their cursor or padding strategy. Constant PDA integer seeds use the matching Dart integer type; malformed hexadecimal seeds and unsupported byte encodings are rejected.
10
+
9
11
  Fixed-size Codama types generate non-truncating encoders. Values within the declared byte capacity are zero-padded, while over-capacity values throw before any malformed bytes can be emitted. For UTF-8 strings, capacity is measured in encoded bytes rather than Dart code units.
10
12
 
11
13
  ## Installation
@@ -13,18 +15,14 @@ Fixed-size Codama types generate non-truncating encoders. Values within the decl
13
15
  ```bash
14
16
  pnpm add codama-renderers-dart
15
17
  # or
16
-
17
- [![pub package](https://img.shields.io/pub/v/codama-renderers-dart.svg)](https://pub.dev/packages/codama-renderers-dart)
18
- [![CI](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml)
19
- [![Coverage](https://codecov.io/gh/openbudgetfun/solana_kit/branch/main/graph/badge.svg?flag=codama-renderers-dart)](https://codecov.io/gh/openbudgetfun/solana_kit?flag=codama-renderers-dart)
20
18
  npm install codama-renderers-dart
21
19
  ```
22
20
 
23
- ## Quick Start
21
+ ## Quick start
24
22
 
25
23
  ### Programmatic API
26
24
 
27
- ```typescript
25
+ ```ts
28
26
  import { renderVisitor } from "codama-renderers-dart";
29
27
  import { visit } from "@codama/visitors-core";
30
28
  import { rootNode, programNode /* ... */ } from "@codama/nodes";
@@ -43,7 +41,9 @@ visit(root, renderVisitor("lib/src/generated", {
43
41
 
44
42
  `renderVisitor` accepts parsed Codama JSON as well as roots made with Codama constructors. Pina omits empty collections from its serialized IDLs; the renderer restores those structural defaults on an internal copy before traversal, leaving the parsed object unchanged.
45
43
 
46
- ```typescript
44
+ IDL names may contain letters, digits, underscores, hyphens, and spaces; names containing path separators, quotes, or other source syntax are rejected. Documentation and string values are escaped before they enter generated Dart. Rendering resolves all output before clearing the previous generated directory, so invalid IDLs do not delete an existing client. Formatter paths are passed as literal process arguments. Numeric defaults, counts, sizes, and error codes are validated before they are written as source. Duplicate generated paths are rejected, including names reserved for category barrel files, so nodes cannot silently replace one another.
45
+
46
+ ```ts
47
47
  import { readFile } from "node:fs/promises";
48
48
  import { visit } from "@codama/visitors-core";
49
49
  import { renderVisitor } from "codama-renderers-dart";
@@ -76,7 +76,7 @@ Then run:
76
76
  codama run dart
77
77
  ```
78
78
 
79
- ## Generated Output Structure
79
+ ## Generated output structure
80
80
 
81
81
  For a program called `myProgram`, the renderer generates:
82
82
 
@@ -104,7 +104,7 @@ lib/src/generated/
104
104
  my_pda.dart # PDA seeds class + finder function
105
105
  ```
106
106
 
107
- ## Generated Code Patterns
107
+ ## Generated code patterns
108
108
 
109
109
  ### Accounts
110
110
 
@@ -164,9 +164,11 @@ Account and instruction decoders validate every declared constant, field, and si
164
164
 
165
165
  Top-level instruction decoders require exact input consumption. Account decoders always reject truncated data, but accept unread trailing capacity unless the account declares a `sizeDiscriminatorNode`; size-discriminated accounts reject both truncation and suffix bytes.
166
166
 
167
+ Accounts declared with `isSigner: "either"` expose an additional boolean such as `authorityIsSigner`, defaulting to `true`. Set it to `false` when the authority does not sign, including multisig authorities.
168
+
167
169
  Optional instruction accounts use Codama's `programId` strategy by default. When an optional account is absent, the builder emits a readonly program-address placeholder so every later account keeps its declared index. The account slot is removed only when the instruction explicitly selects the legacy `omitted` strategy.
168
170
 
169
- ### Scalar Enums
171
+ ### Scalar enums
170
172
 
171
173
  Scalar enums (all-empty variants) generate a Dart `enum` with index-based encoder/decoder:
172
174
 
@@ -183,7 +185,7 @@ Decoder<AccountStatus> getAccountStatusDecoder() { ... }
183
185
 
184
186
  The generated enum API is the same for `u8`, `u16`, `u32`, and `u64` discriminators. The renderer converts `u64` indices to and from `BigInt` at the codec boundary and rejects out-of-range discriminators before converting them to Dart enum indices.
185
187
 
186
- ### Data Enums (Discriminated Unions)
188
+ ### Data enums (discriminated unions)
187
189
 
188
190
  Data enums generate Dart 3 `sealed class` hierarchies:
189
191
 
@@ -231,7 +233,7 @@ Future<(Address, int)> findMyPdaPda({
231
233
  }) async { ... }
232
234
  ```
233
235
 
234
- ## Type Mapping
236
+ ## Type mapping
235
237
 
236
238
  | Codama Type | Dart Type | Codec |
237
239
  | ----------------------------------- | --------------- | -------------------------------- |
@@ -266,7 +268,7 @@ Future<(Address, int)> findMyPdaPda({
266
268
 
267
269
  All naming conventions are customizable:
268
270
 
269
- ```typescript
271
+ ```ts
270
272
  import { renderVisitor, createDartNameApi } from "codama-renderers-dart";
271
273
 
272
274
  const nameApi = {
@@ -277,7 +279,7 @@ const nameApi = {
277
279
  visit(root, renderVisitor("output", { nameApi }));
278
280
  ```
279
281
 
280
- ## Target Packages
282
+ ## Target packages
281
283
 
282
284
  Generated Dart code depends on these solana_kit packages:
283
285
 
@@ -311,39 +313,10 @@ Key source files:
311
313
  ## Development
312
314
 
313
315
  ```bash
314
- # Install dependencies
315
-
316
- [![pub package](https://img.shields.io/pub/v/codama-renderers-dart.svg)](https://pub.dev/packages/codama-renderers-dart)
317
- [![CI](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml)
318
- [![Coverage](https://codecov.io/gh/openbudgetfun/solana_kit/branch/main/graph/badge.svg?flag=codama-renderers-dart)](https://codecov.io/gh/openbudgetfun/solana_kit?flag=codama-renderers-dart)
319
316
  pnpm install
320
-
321
- # Type check
322
-
323
- [![pub package](https://img.shields.io/pub/v/codama-renderers-dart.svg)](https://pub.dev/packages/codama-renderers-dart)
324
- [![CI](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml)
325
- [![Coverage](https://codecov.io/gh/openbudgetfun/solana_kit/branch/main/graph/badge.svg?flag=codama-renderers-dart)](https://codecov.io/gh/openbudgetfun/solana_kit?flag=codama-renderers-dart)
326
317
  npx tsc --noEmit
327
-
328
- # Run tests
329
-
330
- [![pub package](https://img.shields.io/pub/v/codama-renderers-dart.svg)](https://pub.dev/packages/codama-renderers-dart)
331
- [![CI](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml)
332
- [![Coverage](https://codecov.io/gh/openbudgetfun/solana_kit/branch/main/graph/badge.svg?flag=codama-renderers-dart)](https://codecov.io/gh/openbudgetfun/solana_kit?flag=codama-renderers-dart)
333
318
  pnpm test
334
-
335
- # Watch mode
336
-
337
- [![pub package](https://img.shields.io/pub/v/codama-renderers-dart.svg)](https://pub.dev/packages/codama-renderers-dart)
338
- [![CI](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml)
339
- [![Coverage](https://codecov.io/gh/openbudgetfun/solana_kit/branch/main/graph/badge.svg?flag=codama-renderers-dart)](https://codecov.io/gh/openbudgetfun/solana_kit?flag=codama-renderers-dart)
340
319
  pnpm test:watch
341
-
342
- # Build
343
-
344
- [![pub package](https://img.shields.io/pub/v/codama-renderers-dart.svg)](https://pub.dev/packages/codama-renderers-dart)
345
- [![CI](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/openbudgetfun/solana_kit/actions/workflows/ci.yml)
346
- [![Coverage](https://codecov.io/gh/openbudgetfun/solana_kit/branch/main/graph/badge.svg?flag=codama-renderers-dart)](https://codecov.io/gh/openbudgetfun/solana_kit?flag=codama-renderers-dart)
347
320
  pnpm build
348
321
  ```
349
322