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

Chore/replace enums with companion pattern approach #1083

Conversation

lukasaric
Copy link
Contributor

@lukasaric lukasaric commented Apr 17, 2024

Solves #1077

Motivation and Resolution

To increase the type safety, this PR introduces the enum replacement with the companion pattern approach.
To have a better understanding, here's a good thread on why it would be good to avoid enums in TS

Don't use Enums in Typescript, they are very dangerous

RPC version (if applicable)

Usage related changes

n.a

Development related changes

Here's the example of before vs after usage:

BEFORE

export enum NetworkName {
  SN_MAIN = 'SN_MAIN',
  SN_GOERLI = 'SN_GOERLI',
  SN_SEPOLIA = 'SN_SEPOLIA',
}

AFTER

export const NetworkName = {
  SN_MAIN: 'SN_MAIN',
  SN_GOERLI: 'SN_GOERLI',
  SN_SEPOLIA: 'SN_SEPOLIA',
} as const;

// eslint-disable-next-line @typescript-eslint/no-redeclare -- intentionally naming the variable the same as the type
export type NetworkName = (typeof NetworkName)[keyof typeof NetworkName];

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Linked the issues which this PR resolves
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

@lukasaric lukasaric marked this pull request as draft April 17, 2024 06:10
@lukasaric lukasaric changed the base branch from develop to next-version April 17, 2024 07:47
@lukasaric lukasaric changed the base branch from next-version to develop April 17, 2024 07:47
Luka Saric added 3 commits April 17, 2024 10:55
…n-approach

# Conflicts:
#	src/types/api/rpcspec_0_7/nonspec.ts
#	src/wallet/account.ts
#	src/wallet/connect.ts
src/constants.ts Outdated Show resolved Hide resolved
@ivpavici ivpavici requested a review from tabaktoni May 6, 2024 13:14
semantic-release-bot and others added 2 commits May 21, 2024 08:44
# [6.9.0](starknet-io/starknet.js@v6.8.0...v6.9.0) (2024-05-21)

### Bug Fixes

* cannot infer ts2742 types from starknet-types@0.7 ([starknet-io#1098](starknet-io#1098)) ([f1c3b8e](starknet-io@f1c3b8e))
* remove [warning] from typedoc for external usage ([starknet-io#1095](starknet-io#1095)) ([195186f](starknet-io@195186f)), closes [starknet-io#1121](starknet-io#1121) [starknet-io#1126](starknet-io#1126)

### Features

* add type coverage ([starknet-io#1120](starknet-io#1120)) ([eceda5d](starknet-io@eceda5d))
* provider.getL1MessageHash ([starknet-io#1123](starknet-io#1123)) ([1489cf2](starknet-io@1489cf2))

### Reverts

* Revert "chore: add examples to JsDoc for transaction.ts file (starknet-io#1105)" (starknet-io#1108) ([59eb01e](starknet-io@59eb01e)), closes [starknet-io#1105](starknet-io#1105) [starknet-io#1108](starknet-io#1108)
@lukasaric lukasaric marked this pull request as ready for review May 23, 2024 14:21
Copy link
Collaborator

@tabaktoni tabaktoni left a comment

Choose a reason for hiding this comment

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

lgtm

@ivpavici ivpavici changed the base branch from develop to next-version May 31, 2024 08:57
@ivpavici ivpavici merged commit 70a6dab into starknet-io:next-version May 31, 2024
3 checks passed
tabaktoni added a commit that referenced this pull request Jun 18, 2024
* test: add coverage option (#1131)

* test: add coverage option

* docs: add coverage of a single file

* feat: add coverage in automatic test suite

* fix: add 'run' to npm test  coverage script

* docs: jsdoc adds (#1133)

* docs: jsdoc for utils-provider and utils-classHash

* docs: add jsdoc in utils- stark and starknetid

* docs: add jsdoc to utils-shortstring, transaction, uint256

* docs: add  jsdoc for signer interface

* docs: add @return for class getters

* Chore/replace enums with companion pattern approach (#1083)

* test: test setup refactor & remove rpc sequencer

* fix: enable sequencer tests to run on goerli

* chore: format markdowns

* fix: remove unnecessary goerli describeIf comment

* chore: remove setup verifier & simplify envs check logic

* test: naming improvements

* test: update test setup data log for testnet

* test: change from goerli to sepolia

* test: rename from rpc testnet to testnet

* test: remove `TEST_PROVIDER_BASE_URL`

* chore: replace enums with companion pattern

* chore: convert caior option & result enums to consts

* chore: add `ValuesType<T>` type helper

* test: Improve tests performance (#1121)

* test: fix transaction retry interval fallback for devnet tests

* test: remove test.only

* chore: revert from describeIfNot to describeIf

* Update _test.yml (#1126)

* chore(release): 6.9.0 [skip ci]

# [6.9.0](v6.8.0...v6.9.0) (2024-05-21)

### Bug Fixes

* cannot infer ts2742 types from starknet-types@0.7 ([#1098](#1098)) ([f1c3b8e](f1c3b8e))
* remove [warning] from typedoc for external usage ([#1095](#1095)) ([195186f](195186f)), closes [#1121](#1121) [#1126](#1126)

### Features

* add type coverage ([#1120](#1120)) ([eceda5d](eceda5d))
* provider.getL1MessageHash ([#1123](#1123)) ([1489cf2](1489cf2))

### Reverts

* Revert "chore: add examples to JsDoc for transaction.ts file (#1105)" (#1108) ([59eb01e](59eb01e)), closes [#1105](#1105) [#1108](#1108)

* fix: use proper constants

---------

Co-authored-by: Luka Saric <luka.saric@scayle.com>
Co-authored-by: Ivan Pavičić <ivan.pavicic@live.com>
Co-authored-by: Toni Tabak <tabaktoni@gmail.com>
Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>

* refactor: remove functions useful for deprecated sequencer

* refactor: starknetid contracts on sepolia & remove old code (#1139)

* test: update starknetid naming mock contract

* fix: update starknetId contract addresses on sepolia

* refactor: remove unused code from getStarkName & getStarkProfile

* docs: update starknetId utils example results

* test: fix getStarknetIdContract test on sepolia

* fix: remove default from computeHintedClassHash to be able to export (#1142)

* fix: remove default from classhash/computeHintedClassHash to be able to export

* test: add test for computeHintedClassHash

* docs: utils/num docs (#1132)

* docs: added jsdocs to utils/num functions

* docs: extracted existing util/num tests to a separate file, added tests

* chore: num docs small fixes and refactoring

* Update src/utils/num.ts

---------

Co-authored-by: Ivan Pavičić <ivan.pavicic@live.com>

* docs: updated verious util function docs, added tests, refactoring (#1129)

* docs: updated verious util function docs, added tests, refactoring

* docs: json util jsdocs improvements

* chore: typo quickfix

* chore: added missing results to jsdoc examples

* chore: removed jsdoc from non-exported helper function

* chore: utils/json docs fixes and refactoring

* fix: export abi types

* clanup

* fix: types-js (#1147)

* fix: types-js

* chore: fix upp

* Dep/types js (#1153)

* fix: types-js

* chore: fix upp

* fix: types 0.0.7

* docs: merkle and selector docs/tests (#1152)

* docs: added docs for merkle and selector utils, moved selector to hash, added happy path tests

* chore: added example tag to jsdoc

* chore: remove obsolete folder (#1149)

* test: Improve tests performance (#1121)

* test: fix transaction retry interval fallback for devnet tests

* test: remove test.only

* Update _test.yml (#1126)

* chore(release): 6.9.0 [skip ci]

# [6.9.0](v6.8.0...v6.9.0) (2024-05-21)

### Bug Fixes

* cannot infer ts2742 types from starknet-types@0.7 ([#1098](#1098)) ([f1c3b8e](f1c3b8e))
* remove [warning] from typedoc for external usage ([#1095](#1095)) ([195186f](195186f)), closes [#1121](#1121) [#1126](#1126)

### Features

* add type coverage ([#1120](#1120)) ([eceda5d](eceda5d))
* provider.getL1MessageHash ([#1123](#1123)) ([1489cf2](1489cf2))

### Reverts

* Revert "chore: add examples to JsDoc for transaction.ts file (#1105)" (#1108) ([59eb01e](59eb01e)), closes [#1105](#1105) [#1108](#1108)

* Update amm.js

* chore: remove obsolete folder

---------

Co-authored-by: Luka Saric <32763694+lukasaric@users.noreply.github.com>
Co-authored-by: Ivan Pavičić <ivan.pavicic@live.com>
Co-authored-by: Toni Tabak <tabaktoni@gmail.com>
Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>

* Fix: public responseParser (#1154)

* fix: enable instance parser change

* Update __tests__/rpcProvider.test.ts

Co-authored-by: Petar Penović <pp@spaceshard.io>

* fix: export ResponseParser and RPCResponseParser

* chore: noob

---------

Co-authored-by: Petar Penović <pp@spaceshard.io>

* BUG: Nested events not handled (#1140)

* test: eth signer

* test: move secp256k1Point tests in a dedicated test file

* feat: helper for  transaction receipt

* simplify extends for account class

* feat: handling of cairo u512 type

* refactor: change name of variable : GetTxReceiptResponseWithoutHelper

* fix: double lines for same imports

* fix: solve an error in validate.ts initiated by pr 1007

* fix: correction of a word in guide

* docs: validateChecksumAddress

* fix: jsdoc correction

* docs: add tsdoc in utils/address.ts

* test: add extra fees

* fix: estimateFeeBulk include skipValidate in accountInvocationsFactory

* feat: add type guard to receipt response status methods

* fix: repair i128 typed data encoding and add typed data range checks

* chore: update left over StarkNet casing

* feat: bundle resolution, module, type import for walletacc

* feat: bundle resolution, module, type import for walletaccount

* chore: fix connect import

* chore: add get-starknet-core next as dependencie

* chore: import fix

* fix: estimateMessageFee - eth address format (#1040)

* fix: estimatemessagefee eth address format

* fix: implement requests

* docs: small guides cleanup (#1048)

* docs: fix nodeUrl code typo (#1046)

* docs: small guides cleanup

---------

Co-authored-by: Joel Mun <hj923@hotmail.com>

* fix(RpcProvider): allow client to provide `specVersion` in 0.7 provider

this saves an extra call on RPC for optionally-known information (like the `chainId` case).
also fixed speck -> spec typo

* fix: remove abis parameter from signer and account execute

* feat: configure u512 and Secp256k1Point for abiwan

* chore: bump dependencies

* chore: expose data gas consumed and data gas price for 0.7 rpc

* test: Improve tests performance (#1121)

* test: fix transaction retry interval fallback for devnet tests

* test: remove test.only

* Update _test.yml (#1126)

* chore(release): 6.9.0 [skip ci]

# [6.9.0](v6.8.0...v6.9.0) (2024-05-21)

### Bug Fixes

* cannot infer ts2742 types from starknet-types@0.7 ([#1098](#1098)) ([f1c3b8e](f1c3b8e))
* remove [warning] from typedoc for external usage ([#1095](#1095)) ([195186f](195186f)), closes [#1121](#1121) [#1126](#1126)

### Features

* add type coverage ([#1120](#1120)) ([eceda5d](eceda5d))
* provider.getL1MessageHash ([#1123](#1123)) ([1489cf2](1489cf2))

### Reverts

* Revert "chore: add examples to JsDoc for transaction.ts file (#1105)" (#1108) ([59eb01e](59eb01e)), closes [#1105](#1105) [#1108](#1108)

* fix: handling of events nested in Cairo components

* fix: change names of events in tests

* refactor: change type names

* test: adapt parseUDCEvent to events namespace

* refactor: implement reviewer requests

* refactor: add spec6 types

* Revert "Merge branch 'next-version' into nested-events"

This reverts commit 4c65e9b, reversing
changes made to 7702d9c.

* fix: remove events.ts  that came back after merge

* refactor: use of external types-js lib for events types

---------

Co-authored-by: gregory <10611760+gregoryguillou@users.noreply.github.com>
Co-authored-by: Toni Tabak <tabaktoni@gmail.com>
Co-authored-by: ivpavici <ivan.pavicic@live.com>
Co-authored-by: Petar Penovic <pp@spaceshard.io>
Co-authored-by: Joel Mun <hj923@hotmail.com>
Co-authored-by: Abraham Makovetsky <avimak@gmail.com>
Co-authored-by: Haroune Mohammedi <haroune.mohammedi@quadratic-labs.com>
Co-authored-by: Dhruv Kelawala <dhruvrk2000@gmail.com>
Co-authored-by: Luka Saric <32763694+lukasaric@users.noreply.github.com>
Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>

* feat: add handling of nonZero type (#1150)

* Guide for wallet account (#1156)

* docs: walletAccount guide

* fix: add all Ivan's proposals, except one

---------

Co-authored-by: Philippe ROSTAN <81040730+PhilippeR26@users.noreply.github.com>
Co-authored-by: Luka Saric <32763694+lukasaric@users.noreply.github.com>
Co-authored-by: Luka Saric <luka.saric@scayle.com>
Co-authored-by: Ivan Pavičić <ivan.pavicic@live.com>
Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
Co-authored-by: PhilippeR26 <philippe.rostan@yahoo.fr>
Co-authored-by: Iris <iris.devillars@gmail.com>
Co-authored-by: dsperac <dsperac@gmail.com>
Co-authored-by: alex <152680487+bodhi-crypo@users.noreply.github.com>
Co-authored-by: Petar Penović <pp@spaceshard.io>
Co-authored-by: gregory <10611760+gregoryguillou@users.noreply.github.com>
Co-authored-by: Joel Mun <hj923@hotmail.com>
Co-authored-by: Abraham Makovetsky <avimak@gmail.com>
Co-authored-by: Haroune Mohammedi <haroune.mohammedi@quadratic-labs.com>
Co-authored-by: Dhruv Kelawala <dhruvrk2000@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending need update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants