-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol-parser): add new schema helpers (#2478)
- Loading branch information
Showing
11 changed files
with
54 additions
and
25 deletions.
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
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,9 @@ | ||
import { Table } from "@latticexyz/config"; | ||
|
||
export type getKeySchema<table extends Table> = { | ||
[fieldName in table["key"][number]]: table["schema"][fieldName]; | ||
}; | ||
|
||
export function getKeySchema<table extends Table>(table: table): getKeySchema<table> { | ||
return Object.fromEntries(table.key.map((fieldName) => [fieldName, table.schema[fieldName]])) as getKeySchema<table>; | ||
} |
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,10 @@ | ||
import { Schema } from "@latticexyz/config"; | ||
import { mapObject } from "@latticexyz/common/utils"; | ||
|
||
export type getSchemaTypes<schema extends Schema> = { | ||
readonly [k in keyof schema]: schema[k]["type"]; | ||
}; | ||
|
||
export function getSchemaTypes<schema extends Schema>(schema: schema): getSchemaTypes<schema> { | ||
return mapObject(schema, (value) => value.type); | ||
} |
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,11 @@ | ||
import { Table } from "@latticexyz/config"; | ||
|
||
export type getValueSchema<table extends Table> = { | ||
[fieldName in Exclude<keyof table["schema"], table["key"][number]>]: table["schema"][fieldName]; | ||
}; | ||
|
||
export function getValueSchema<table extends Table>(table: table): getValueSchema<table> { | ||
return Object.fromEntries( | ||
Object.entries(table.schema).filter(([fieldName]) => !table.key.includes(fieldName)), | ||
) as getValueSchema<table>; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.