Skip to content

Conversation

@mfbz
Copy link
Contributor

@mfbz mfbz commented Jun 9, 2025

Close #2263

As suggested by @jribbink in #2263 comment, I removed enums and substituted them with their type compatible version like this:

const SomeEnum = {
  FOO: "foo"
} as const

type SomeEnum = (typeof SomeEnum)[keyof typeof SomeEnum]

Furthermore, I adjusted some files to support the new type usage instead of enums

@mfbz mfbz requested a review from a team as a code owner June 9, 2025 17:00
@changeset-bot
Copy link

changeset-bot bot commented Jun 9, 2025

🦋 Changeset detected

Latest commit: 884328d

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

This PR includes changesets to release 16 packages
Name Type
@onflow/fcl-core Minor
@onflow/typedefs Minor
@onflow/sdk Minor
@onflow/fcl Minor
@onflow/fcl-react-native Minor
@onflow/fcl-ethereum-provider Major
@onflow/transport-http Minor
@onflow/util-logger Minor
@onflow/util-rpc Minor
@onflow/fcl-wc Major
@onflow/fcl-rainbowkit-adapter Major
@onflow/fcl-wagmi-adapter Major
@onflow/kit Major
@onflow/config Patch
@onflow/types Patch
@onflow/util-template Patch

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

mfbz and others added 6 commits June 9, 2025 19:18
* Added core types export (#2437)

Co-authored-by: mfbz <[email protected]>

* Refactored fcl-core current-user folder files to TypeScript (#2454)

* Refactored current-user folder with corresponding type definitions

* Renamed CurrentUserFull to CurrentUserService

* Improved CurrentUser interface

---------

Co-authored-by: mfbz <[email protected]>

* Refactored root files (#2479)

Co-authored-by: mfbz <[email protected]>

* Refactored serialize folder (#2476)

Co-authored-by: mfbz <[email protected]>

* Refactored fcl-core document folder files to TypeScript (#2464)

* Refactored document folder

* Update packages/fcl-core/src/document/document.ts

Co-authored-by: Jordan Ribbink <[email protected]>

---------

Co-authored-by: mfbz <[email protected]>
Co-authored-by: Jordan Ribbink <[email protected]>

* Refactored fcl-core utils folder files to TypeScript (#2477)

* Refactored utils folder

* Update packages/fcl-core/src/utils/chain-id/chain-id-watcher.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/utils/chain-id/chain-id-watcher.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Fixed minor typo

---------

Co-authored-by: mfbz <[email protected]>
Co-authored-by: Jordan Ribbink <[email protected]>

* Refactored fcl-core events folder files to TypeScript  (#2472)

* Refactored legacy events file

* Fixed for compatibility

---------

Co-authored-by: mfbz <[email protected]>

* Refactored fcl-core app utils folder files to TypeScript (#2442)

* Refactored app-utils folder

* Added new types export

* Update packages/fcl-core/src/fcl-core.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Cleaned up any usage

---------

Co-authored-by: mfbz <[email protected]>
Co-authored-by: Jordan Ribbink <[email protected]>

* Refactored fcl-core exec folder files to TypeScript (#2473)

* Completed exec folder refactoring

* Substituted correct current-user usage

* Improved mutate options interface

* Cleanup any usage

* Refactored any usage to only when needed

---------

Co-authored-by: mfbz <[email protected]>

* Refactored fcl-core discovery folder files to TypeScript (#2462)

* Refactored discovery folder

* Reused ActorContext from util-actor package

* Minor fix

---------

Co-authored-by: mfbz <[email protected]>

* Refactored fcl-core wallet-utils folder files to TypeScript (#2478)

* Refactored wallet-utils folder

* Made account proof data optional

* Update packages/fcl-core/src/wallet-utils/encode-account-proof.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/encode-account-proof.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/encode-account-proof.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Improved sendMsgToFCL msg param

* Update packages/fcl-core/src/wallet-utils/send-msg-to-fcl.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/CompositeSignature.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/on-message-from-fcl.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/send-msg-to-fcl.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/send-msg-to-fcl.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/send-msg-to-fcl.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/send-msg-to-fcl.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/send-msg-to-fcl.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/wallet-utils/send-msg-to-fcl.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Removed useless casts

---------

Co-authored-by: mfbz <[email protected]>
Co-authored-by: Jordan Ribbink <[email protected]>

* Fixed connection not working

* Refactored fcl-core interaction-template-utils folder files to TypeScript (#2474)

* Completed refactoring of interaction-template-utils folder

* Update packages/fcl-core/src/interaction-template-utils/generate-template-id/generate-template-id-1.1.0.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Improved dependency pin test

* Fixed console warn spy on tests

* Added suggestion

* Update packages/fcl-core/src/interaction-template-utils/generate-template-id/generate-template-id-1.0.0.ts

Co-authored-by: Jordan Ribbink <[email protected]>

* Update packages/fcl-core/src/interaction-template-utils/generate-template-id/generate-template-id.ts

Co-authored-by: Jordan Ribbink <[email protected]>

---------

Co-authored-by: mfbz <[email protected]>
Co-authored-by: Jordan Ribbink <[email protected]>

* Refactored fcl-core normalizers folder files to TypeScript (#2475)

* Refactored normalizers folder

* Fixed post merging issues

* Updated comments

* Updated service normalizers

* Update packages/fcl-core/src/normalizers/service/open-id.ts

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: mfbz <[email protected]>
Co-authored-by: Copilot <[email protected]>

* Big documentation update (#2532)

Co-authored-by: mfbz <[email protected]>

* Added changeset

---------

Co-authored-by: mfbz <[email protected]>
Co-authored-by: Jordan Ribbink <[email protected]>
Co-authored-by: Copilot <[email protected]>
* Refactored fcl package to TypeScript (#2492)

* Added direct core types export

* Minor version file refactor to ts

* Updated readme

---------

Co-authored-by: mfbz <[email protected]>

* Added changeset

---------

Co-authored-by: mfbz <[email protected]>
* Added core types and minor refactor (#2493)

Co-authored-by: mfbz <[email protected]>

* Added changeset

---------

Co-authored-by: mfbz <[email protected]>
@mfbz mfbz changed the base branch from master to feature/refactoring June 27, 2025 08:17
@chasefleming chasefleming requested a review from Copilot June 27, 2025 20:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR converts enums into constant objects with associated type extraction, improving type compatibility across the codebase.

  • Replaces enums with template literal style constant objects in various packages.
  • Updates type references to align with the new constant objects.
  • Adjusts error handling logic in the transaction module to accommodate the changes.

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/util-rpc/src/rpc-error.ts Converted RpcErrorCode to a constant object with type extraction.
packages/util-rpc/src/rpc-client.ts Replaced ReservedRpcMethods enum conversion with a constant object.
packages/util-logger/src/util-logger.ts Converted LEVELS enum to a constant object and updated type accordingly.
packages/typedefs/src/subscriptions.ts Converted SubscriptionTopic enum into a constant object and updated its type.
packages/typedefs/src/interaction.ts Replaced several enums (InteractionTag, InteractionStatus, TransactionRole, InteractionResolverKind) with constant objects and updated types.
packages/typedefs/src/index.ts Converted SignatureAlgorithm, HashAlgorithm, and TransactionExecutionStatus enums into constant objects with type extraction.
packages/typedefs/src/fvm-errors.ts Converted FvmErrorCode enum to a constant object with type extraction.
packages/transport-http/src/subscribe/models.ts Converted Action enum into a constant object and updated type references in message interfaces.
packages/transport-http/src/subscribe/handlers/*.ts Updated various subscription handlers to use constant object types instead of enums.
packages/sdk/src/resolve/resolve-accounts.ts Replaced ROLES enum with a constant object and updated type usage.
packages/fcl/src/discovery/rpc/requests.ts Converted DiscoveryNotification and FclRequest enums into constant objects with corresponding types.
packages/fcl-wc/src/constants.ts Converted FLOW_METHODS and REQUEST_TYPES enums to constant objects with type extraction.
packages/fcl-ethereum-provider/src/util/errors.ts Converted ProviderErrorCode enum into a constant object with type extraction.
packages/fcl-ethereum-provider/src/constants.ts Converted FlowNetwork, ContractType, and EventType enums into constant objects with updated types.
packages/fcl-core/src/transaction/transaction-error.ts Adjusted error type lookup to use a runtime search over FvmErrorCode keys.
.changeset/strong-onions-behave.md Updated changeset to reflect the conversion changes across packages.

this.type =
Object.keys(FvmErrorCode).find(
key => FvmErrorCode[key as keyof typeof FvmErrorCode] === code
) || "UNKNOWN_ERROR"
Copy link

Copilot AI Jun 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider creating a reverse mapping for FvmErrorCode to enable a constant-time lookup of the error type instead of iterating over keys at runtime, which may improve performance and clarity.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented!

mfbz and others added 3 commits June 28, 2025 00:44
* Added onflow/typedefs and onflow/types types into sdk package

* Updated first part of files

* Updated encode and decode folders

* Updated send.js

* Updated sdk resolve files

* Fixed build problems

* Updated wallet-utils folder

* Moved typedefs and types back to their package

* Fixed build

* Refactored more js to ts files

* Fixed tests

* Added onflow/types re-export from sdk

* Added missing onflow/types package to sdk

* Updated readme with typescript examples

* Fixed build error on type problem

* Added changeset file

* Docs generator implementation

* Fixed generation function complex types and duplicated entries

* Fixed docusaurus parsing problem

* Cleaned up types and docs

* Minor comments fix

* Cleaned up package lock

* Removed unused cast

* Added suport to conditional interaction callbacks in build

* After install update

* Fixed build-transaction input params

* Updated send function null check

* Re-added resolve comments to two special functions

* Added Voucher export from sdk

* Improved input params for send function

* Renamed InteractionCallback to InteractionBuilderFn

* Improve with central function definition from interaction file

* Improved atBlockId validator types

* Updated lock file

* Added autogenerated tag with link to templates

* Ordered generated functions alphabetically

* Updated generate-docs command so that package name is not needed

* Fixed docs-generator.config.js optional properties usage

* Improved generation with single exportable folder

* Added types folder generation

* Minor types template fixes

* Added link to core types in function page

* Added params types details in function page

* Added support for union types

* Strongly typed voucher intercept param

* Improved signing function interface and minor refactoring

* Improved output folder structure

* Improved generation and removed useless readme

* Added custom display name for package

* Added sdk docs-generator config

* Simplified package generation and config

* Updated generation location for function files

* Improved generation with package docs index

* Updated package-lock with docs-generator new dependencies

* Added docs generation to sdk package

* Moved autogenerated tag to header in a note

* Added handlebars files to prettierignore

* Updated package lock

* Updated comment explaining that docs are autogenerated

* Added a blank line between all headings/subheadings and content

* Added function name in frontmatter

* Updated package-lock

* Added big part of sdk documentation into functions jsdocs

* Minor fix for improved folder parsing

* Fixed docusaurus parsing problem

* Minor decode description update

* Improved package page generation for long descriptions

* Fixed docs generation and functions jsdoc comments

* Fixed examples rendering

* Improved function import

* Added more documentation and examples based on flow docs

* Updated types descriptions

* Other jsdocs improvements

* Minor templates update

* Added package description to docs generated

* Completed docs extraction and added packages docs generation script

* Added a fix for re-exported functions

* Fixed mdx escaping in examples

* Minor example fix

* Other docs fix

* Improved folder structure and added namespace extraction

* Fixed re-exported functions duplicated entries

* Fix multilevel export

* Improved jsdoc parsing

* Added missing jsdoc to withPrefix function

* Fixed root package file duplication problem

* Fixed jsdoc return description showing

* Fixed destructured param parsing

* Improved type codeblocks showing in namespace files

* Fixed types extraction

* Fixed multiple returns

* Fixed curly braces escaping and missing docs

* Updated packages descriptions for better docs generation

* Added sidebar position to 1 so packages-docs is always on top

* Improved typedefs page

* Fixed union types links

---------

Co-authored-by: mfbz <[email protected]>
@chasefleming
Copy link
Member

Is this going to break any existing typedefs usage?

@mfbz
Copy link
Contributor Author

mfbz commented Jun 29, 2025

Can you give an example? Consider that the usage is exactly the same:

Before:

enum SomeEnum {
  FOO = "foo"
}

// Usage
SomeEnum.FOO

After:

const SomeEnum = {
  FOO: "foo"
} as const
type SomeEnum = (typeof SomeEnum)[keyof typeof SomeEnum]

// Usage
SomeEnum.FOO

@mfbz mfbz changed the base branch from feature/refactoring to master June 30, 2025 21:52
@mfbz mfbz marked this pull request as draft August 15, 2025 21:07
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.

[FEATURE] Remove all enums and namespaces

3 participants