Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(human-readable): parameter validation and strict mode #138

Closed
wants to merge 24 commits into from

Conversation

Raiden1411
Copy link
Collaborator

@Raiden1411 Raiden1411 commented May 18, 2023

Description

Adds parameter validation to parseAbiParameter and parseAbiParameters.
Changes StrictAbiType to Strict.

Additional Information

  • I read the contributing guide
  • I added documentation related to the changes made.
  • I added or updated tests related to the changes made.

Your ENS/address:


PR-Codex overview

This PR adds parameter validation and stricter checks to parseAbiParameter and parseAbiParameters. It also renames StrictAbiType to Strict and enforces stricter checks on human-readable ABIs. Notable changes include:

  • Adds parameter validation to parseAbiParameter and parseAbiParameters
  • Renames StrictAbiType to Strict
  • Enforces stricter checks on human-readable ABIs
  • Updates various types and interfaces to use InferredAbi instead of Abi
  • Adds new utility types such as ExtractAbiParseErrors, Flatten, IsEmptyObject, IsArrayString, Pop, IsNever, and Range

The following files were skipped due to too many changes: docs/api/human.md, src/human-readable/types/structs.ts, src/types.ts, src/human-readable/types/utils.test-d.ts, src/utils.ts, src/human-readable/parseAbiParameter.test-d.ts, src/human-readable/types/signatures-test-d.ts, src/human-readable/types/signatures.ts, src/human-readable/parseAbiParameters.test-d.ts, src/human-readable/parseAbiParameter.ts, src/human-readable/parseAbiParameters.ts, src/abi.ts, src/human-readable/types/utils.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@changeset-bot
Copy link

changeset-bot bot commented May 18, 2023

🦋 Changeset detected

Latest commit: e90ae65

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@commit-lint
Copy link

commit-lint bot commented May 18, 2023

Features

  • parameter validation and strict mode (835538e)
  • inferred abi types (c397940)

Chore

Bug Fixes

  • bug fixes && small refactor (3e688f0)

Code Refactoring

Contributors

Raiden1411

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

@vercel
Copy link

vercel bot commented May 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
abitype ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 15, 2023 4:06pm

@github-actions
Copy link
Contributor

github-actions bot commented May 18, 2023

Size Change: +62 B (0%)

Total Size: 47.1 kB

Filename Size Change
dist/cjs/human-readable/types/signatures-test-d.js 465 B +27 B (+6%) 🔍
dist/esm/human-readable/types/signatures-test-d.js 400 B +35 B (+10%) ⚠️
ℹ️ View Unchanged
Filename Size
dist/cjs/abi.js 123 B
dist/cjs/config.js 126 B
dist/cjs/errors.js 577 B
dist/cjs/human-readable/errors/abiItem.js 537 B
dist/cjs/human-readable/errors/abiParameter.js 804 B
dist/cjs/human-readable/errors/signature.js 420 B
dist/cjs/human-readable/errors/splitParameters.js 404 B
dist/cjs/human-readable/errors/struct.js 338 B
dist/cjs/human-readable/formatAbi.js 294 B
dist/cjs/human-readable/formatAbiItem.js 420 B
dist/cjs/human-readable/formatAbiParameter.js 487 B
dist/cjs/human-readable/formatAbiParameters.js 313 B
dist/cjs/human-readable/parseAbi.js 348 B
dist/cjs/human-readable/parseAbiItem.js 439 B
dist/cjs/human-readable/parseAbiParameter.js 470 B
dist/cjs/human-readable/parseAbiParameters.js 527 B
dist/cjs/human-readable/runtime/cache.js 616 B
dist/cjs/human-readable/runtime/signatures.js 777 B
dist/cjs/human-readable/runtime/structs.js 1.03 kB
dist/cjs/human-readable/runtime/utils.js 2.13 kB
dist/cjs/human-readable/types/signatures.js 127 B
dist/cjs/human-readable/types/structs.js 127 B
dist/cjs/human-readable/types/utils.js 124 B
dist/cjs/index.js 743 B
dist/cjs/narrow.js 169 B
dist/cjs/regex.js 362 B
dist/cjs/test.js 597 B
dist/cjs/test/abis.js 5.93 kB
dist/cjs/test/human-readable.js 3.6 kB
dist/cjs/types.js 124 B
dist/cjs/utils.js 124 B
dist/cjs/version.js 149 B
dist/cjs/zod.js 1.41 kB
dist/esm/abi.js 62 B
dist/esm/config.js 65 B
dist/esm/errors.js 524 B
dist/esm/human-readable/errors/abiItem.js 454 B
dist/esm/human-readable/errors/abiParameter.js 674 B
dist/esm/human-readable/errors/signature.js 339 B
dist/esm/human-readable/errors/splitParameters.js 345 B
dist/esm/human-readable/errors/struct.js 282 B
dist/esm/human-readable/formatAbi.js 214 B
dist/esm/human-readable/formatAbiItem.js 339 B
dist/esm/human-readable/formatAbiParameter.js 405 B
dist/esm/human-readable/formatAbiParameters.js 230 B
dist/esm/human-readable/parseAbi.js 267 B
dist/esm/human-readable/parseAbiItem.js 353 B
dist/esm/human-readable/parseAbiParameter.js 383 B
dist/esm/human-readable/parseAbiParameters.js 436 B
dist/esm/human-readable/runtime/cache.js 554 B
dist/esm/human-readable/runtime/signatures.js 567 B
dist/esm/human-readable/runtime/structs.js 942 B
dist/esm/human-readable/runtime/utils.js 2.03 kB
dist/esm/human-readable/types/signatures.js 69 B
dist/esm/human-readable/types/structs.js 66 B
dist/esm/human-readable/types/utils.js 64 B
dist/esm/index.js 345 B
dist/esm/narrow.js 97 B
dist/esm/regex.js 284 B
dist/esm/test.js 298 B
dist/esm/test/abis.js 5.8 kB
dist/esm/test/human-readable.js 3.49 kB
dist/esm/types.js 64 B
dist/esm/utils.js 64 B
dist/esm/version.js 82 B
dist/esm/zod.js 1.25 kB

compressed-size-action


- Type `boolean`
- Default `false`

```ts twoslash
declare module 'abitype' {
export interface Config {
StrictAbiType: false
Strict: false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change it will affect type checking not only on types but also valid modifiers and parameter names. Kept as default so folks can hop in instead of out.

@codecov
Copy link

codecov bot commented May 18, 2023

Codecov Report

Merging #138 (e90ae65) into main (da06adb) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##             main     #138    +/-   ##
========================================
  Coverage   99.89%   99.90%            
========================================
  Files          21       21            
  Lines        1914     2029   +115     
  Branches      308      308            
========================================
+ Hits         1912     2027   +115     
  Misses          2        2            
Impacted Files Coverage Δ
src/human-readable/errors/abiParameter.ts 100.00% <100.00%> (ø)
src/human-readable/formatAbiParameter.ts 100.00% <100.00%> (ø)
src/human-readable/formatAbiParameters.ts 100.00% <100.00%> (ø)
src/human-readable/parseAbiParameter.ts 100.00% <100.00%> (ø)
src/human-readable/parseAbiParameters.ts 100.00% <100.00%> (ø)
src/human-readable/runtime/cache.ts 100.00% <100.00%> (ø)
src/human-readable/runtime/structs.ts 100.00% <100.00%> (ø)
src/zod.ts 100.00% <100.00%> (ø)

@@ -128,7 +129,7 @@ export type IsName<TName extends string> = TName extends ''
: false
export type ValidateName<
TName extends string,
CheckCharacters extends boolean = false,
CheckCharacters extends boolean = ResolvedConfig['Strict'],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now gets enabled once folks enable strict mode instead of always being false.

@@ -1,9 +1,9 @@
import type { AbiParameter } from '../../abi.js'
import type { InferredAbiParameter } from '../../abi.js'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to change this to InferredAbiParameter because while parsing structs with StrictAbiType = true it would cause some components to be never.

AllKeys extends keyof T = keyof T,
> = [AllKeys] extends [never] ? true : false

export type Flatten<
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also filters out all never types. It wasn't playing to well with never as members since never extends any[] is true.

@Raiden1411
Copy link
Collaborator Author

@tmm, made some comments on the files. Let me know what you think about this.

@Raiden1411 Raiden1411 marked this pull request as ready for review May 21, 2023 06:03
@Raiden1411 Raiden1411 requested a review from tmm May 21, 2023 06:03
@Raiden1411 Raiden1411 changed the title feat: parameter validation and strict mode feat(human-readable): parameter validation and strict mode Jun 13, 2023
@Raiden1411
Copy link
Collaborator Author

Will close this and break this down into seperate PRs. Currently doing to much on this one

@Raiden1411 Raiden1411 closed this Jun 23, 2023
@Raiden1411 Raiden1411 deleted the feat/param-validation branch June 23, 2023 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant