-
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.
fix(common): remove underscore prefix from root namespace labels (#2400)
- Loading branch information
Showing
6 changed files
with
39 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/common": patch | ||
--- | ||
|
||
`resourceToLabel` now correctly returns just the resource name if its in the root namespace. |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describe, it, expect, expectTypeOf } from "vitest"; | ||
import { resourceToLabel } from "./resourceToLabel"; | ||
|
||
describe("resourceToLabel", () => { | ||
it("creates a human-readable label for a resource", () => { | ||
const label = resourceToLabel({ namespace: "SomeNamespace", name: "SomeName" }); | ||
expect(label).toBe("SomeNamespace__SomeName"); | ||
expectTypeOf(label).toEqualTypeOf<"SomeNamespace__SomeName">(); | ||
}); | ||
|
||
it("creates a human-readable label for a root resource", () => { | ||
const label = resourceToLabel({ namespace: "", name: "SomeName" }); | ||
expect(label).toBe("SomeName"); | ||
expectTypeOf(label).toEqualTypeOf<"SomeName">(); | ||
}); | ||
}); |
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,16 @@ | ||
const rootNamespace = ""; | ||
|
||
export type ResourceLabel< | ||
namespace extends string = string, | ||
name extends string = string, | ||
> = namespace extends typeof rootNamespace ? name : `${namespace}__${name}`; | ||
|
||
export function resourceToLabel<namespace extends string, name extends string>({ | ||
namespace, | ||
name, | ||
}: { | ||
readonly namespace: namespace; | ||
readonly name: name; | ||
}): ResourceLabel<namespace, name> { | ||
return (namespace === rootNamespace ? name : `${namespace}__${name}`) as ResourceLabel<namespace, name>; | ||
} |