-
Notifications
You must be signed in to change notification settings - Fork 196
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
refactor: move some utils to common, clean up #1068
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
examples/minimal/packages/client-phaser/src/layers/network/contractComponents.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": ["../../.eslintrc"], | ||
"rules": { | ||
"@typescript-eslint/explicit-function-return-type": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { TableId } from "./TableId"; | ||
|
||
describe("TableId", () => { | ||
it("can convert to hex string", () => { | ||
const tableId = new TableId("namespace", "name"); | ||
expect(tableId.toHex()).toMatchInlineSnapshot( | ||
'"0x6e616d657370616365000000000000006e616d65000000000000000000000000"' | ||
); | ||
}); | ||
|
||
it("throws when converting namespaces >16 bytes", () => { | ||
const tableId = new TableId("AVeryLongNamespace", "name"); | ||
expect(() => tableId.toHex()).toThrowErrorMatchingInlineSnapshot(` | ||
"Size cannot exceed 16 bytes. Given size: 18 bytes. | ||
|
||
Version: [email protected]" | ||
`); | ||
}); | ||
|
||
it("throws when converting names >16 bytes", () => { | ||
const tableId = new TableId("namespace", "AnUnnecessarilyLongName"); | ||
expect(() => tableId.toHex()).toThrowErrorMatchingInlineSnapshot(` | ||
"Size cannot exceed 16 bytes. Given size: 23 bytes. | ||
|
||
Version: [email protected]" | ||
`); | ||
}); | ||
|
||
it("can convert from hex string", () => { | ||
const tableId = TableId.fromHex("0x6e616d657370616365000000000000006e616d65000000000000000000000000"); | ||
expect(tableId.namespace).toMatchInlineSnapshot('"namespace"'); | ||
expect(tableId.name).toMatchInlineSnapshot('"name"'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Hex, stringToHex, hexToString, sliceHex, concatHex } from "viem"; | ||
|
||
export class TableId { | ||
namespace: string; | ||
name: string; | ||
|
||
constructor(namespace: string, name: string) { | ||
this.namespace = namespace; | ||
this.name = name; | ||
} | ||
|
||
toString(): string { | ||
return `TableId<${this.namespace || "[empty]"}:${this.name || "[empty]"}>`; | ||
} | ||
|
||
toHex(): Hex { | ||
return TableId.toHex(this.namespace, this.name); | ||
} | ||
|
||
static toHex(namespace: string, name: string): Hex { | ||
return concatHex([stringToHex(namespace, { size: 16 }), stringToHex(name, { size: 16 })]); | ||
} | ||
|
||
static fromHex(hex: Hex): TableId { | ||
const namespace = hexToString(sliceHex(hex, 0, 16)).replace(/\0+$/, ""); | ||
const name = hexToString(sliceHex(hex, 16, 32)).replace(/\0+$/, ""); | ||
return new TableId(namespace, name); | ||
} | ||
|
||
/** @deprecated Don't use this! This is a temporary hack for v2<>v1 compatibility until we can write v2 client libraries. This is here so it stays close to the formatting of `toString()` above. */ | ||
static parse(tableIdString: string): TableId | null { | ||
const match = tableIdString.match(/^TableId<(.+?):(.+?)>$/); | ||
if (!match) return null; | ||
const [, namespace, name] = match; | ||
return new TableId(namespace === "[empty]" ? "" : namespace, name === "[empty]" ? "" : name); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we rename this to
ResourceSelector
? Or have a base classResourceSelector
this inherits from? (See #999 (comment))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh I like that better, will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, gonna save this for later! in searching the codebase for
TableId
, we have a lot of matches and so might wanna rethink the boundaries of this (i.e. when to use "resource selector" vs "table ID")