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(world): add namespaceLabel to system config #3057

Merged
merged 11 commits into from
Aug 23, 2024

Conversation

holic
Copy link
Member

@holic holic commented Aug 22, 2024

goes with #3039 and closes some gaps we had there

Copy link

changeset-bot bot commented Aug 22, 2024

🦋 Changeset detected

Latest commit: 9e46c16

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

This PR includes changesets to release 26 packages
Name Type
@latticexyz/config Patch
@latticexyz/store Patch
@latticexyz/cli Patch
@latticexyz/world Patch
@latticexyz/protocol-parser Patch
@latticexyz/query Patch
@latticexyz/store-sync Patch
@latticexyz/world-modules Patch
@latticexyz/dev-tools Patch
@latticexyz/explorer Patch
@latticexyz/react Patch
@latticexyz/store-indexer Patch
@latticexyz/world-module-metadata Patch
mock-game-contracts Patch
ts-benchmarks Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/common Patch
create-mud Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/utils 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

@holic holic marked this pull request as ready for review August 22, 2024 18:06
@holic holic requested a review from alvrs as a code owner August 22, 2024 18:06
readonly name: string;
/**
* Table's resource ID.
Copy link
Contributor

Choose a reason for hiding this comment

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

Like the property descriptions. Just curious is there a reason why it uses single-line comments in packages/cli/src/deploy/common.ts but then multi-line comments here, even for single line comments?

Copy link
Member Author

Choose a reason for hiding this comment

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

that file is internal, so not as important to have good docs and those are mostly internal notes

the tsdoc here will get included as part of your IDE tooltips and maybe eventually generated into documentation

@@ -24,13 +24,39 @@ export type Schema = {
};

export type Table = {
/**
* Human-readable label for this table. Used as config keys, library names, and filenames.
* Labels are not length constrained like resource names, but special characters should be avoided to be compatible with the filesystem, Solidity compiler, etc.
Copy link
Contributor

@karooolis karooolis Aug 23, 2024

Choose a reason for hiding this comment

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

Wonder if these special characters should be specified here? I realize "special character" has a pretty universal meaning but it can still be unclear if "-" is allowed, for example. Having said that, curious if there are any other constraints like can a label start with number, etc?

Copy link
Member Author

@holic holic Aug 23, 2024

Choose a reason for hiding this comment

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

I don't know the range of special characters in various OS's so I'll leave it to user discretion

if a label has a non-fs compatible character, they'll know quickly because tablegen/worldgen will fail to write files named with those labels

Comment on lines +27 to 28
namespaceLabel: "",
type: "table",
Copy link
Contributor

@karooolis karooolis Aug 23, 2024

Choose a reason for hiding this comment

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

just wonder why only these two properties are used as TABLE_DEFAULTS? Why is namespace not part of, and all the other properties in TableInput type?

Copy link
Contributor

@karooolis karooolis Aug 23, 2024

Choose a reason for hiding this comment

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

I see now, namespace defaults to namespaceLabel in resolveSystem.

@@ -171,8 +176,10 @@ export function resolveTable<input extends TableInput, scope extends Scope = Abi
input: input,
scope: scope = AbiTypeScope as unknown as scope,
): resolveTable<input, scope> {
const namespaceLabel = input.namespaceLabel ?? TABLE_DEFAULTS.namespace;
const namespaceLabel = input.namespaceLabel ?? TABLE_DEFAULTS.namespaceLabel;
// validate ensures this is length constrained
const namespace = input.namespace ?? namespaceLabel;
Copy link
Contributor

@karooolis karooolis Aug 23, 2024

Choose a reason for hiding this comment

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

I find it slightly odd that namespace is assigned with namespaceLabel in case it's undefined. This means that namespaceLabel is treated as the default ID. I'd expect it to be in reverse but I suspect it's due to some constraints I'm not aware of yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

namespaceLabel is the "entry point" and the strongly typed thing, which propagates to the namespace if it meets namespace criteria (<=14 chars) of the resource ID, otherwise throws in the validate function and requires either adjusting the label or specifying an explicit namespace

Copy link
Contributor

@karooolis karooolis left a comment

Choose a reason for hiding this comment

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

Some nits and questions but looks good to me!

* Human-readable label for this table's namespace. Used for namespace config keys and directory names.
* Defaults to the nearest namespace in the config or root namespace if not set.
*/
readonly namespaceLabel?: string;
Copy link
Contributor

@karooolis karooolis Aug 23, 2024

Choose a reason for hiding this comment

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

probably too big of a change now and not worth the effort but wonder if defining namespace as its own type would make sense e.g:

type NamespaceInput = {
  id: string;
  label?: string;
}

type Table Input = {
  namespace?: NamespaceInput;
  // ...
}

Copy link
Member Author

@holic holic Aug 23, 2024

Choose a reason for hiding this comment

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

this would be a breaking change unfortunately

namespaceLabel here won't actually be used by users, it's inferred/propagated from outer context (tables defined inside a namespace in the store/world config)

@holic holic merged commit 04c675c into main Aug 23, 2024
12 of 13 checks passed
@holic holic deleted the holic/system-namespace-label branch August 23, 2024 10:32
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.

2 participants