-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workspaces): add more validation of basePath and names
- Loading branch information
Showing
8 changed files
with
448 additions
and
169 deletions.
There are no files selected for viewing
89 changes: 1 addition & 88 deletions
89
packages/sanity/src/studio/activeWorkspaceMatcher/__tests__/matchWorkspace.test.ts
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export {ActiveWorkspaceMatcherContext} from './ActiveWorkspaceMatcherContext' | ||
export {ActiveWorkspaceMatcher} from './ActiveWorkspaceMatcher' | ||
export {useActiveWorkspace} from './useActiveWorkspace' | ||
export {matchWorkspace, validateWorkspaceBasePaths} from './matchWorkspace' | ||
export {matchWorkspace} from './matchWorkspace' |
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
22 changes: 22 additions & 0 deletions
22
packages/sanity/src/studio/workspaces/WorkspaceValidationError.ts
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,22 @@ | ||
import type {WorkspaceLike} from './types' | ||
import {getWorkspaceIdentifier} from './validateWorkspaces' | ||
|
||
export interface WorkspaceValidationErrorOptions { | ||
workspace: WorkspaceLike | ||
index: number | ||
} | ||
|
||
/** | ||
* Thrown on workspace validation errors. Includes an identifier that is either the name of | ||
* the workspace, or in the case of a missing or invalid name, an index and a potential title | ||
*/ | ||
export class WorkspaceValidationError extends Error { | ||
index?: number | ||
identifier?: string | ||
|
||
constructor(message: string, options?: WorkspaceValidationErrorOptions) { | ||
super(message) | ||
this.index = options?.index | ||
this.identifier = options?.workspace && getWorkspaceIdentifier(options.workspace, options.index) | ||
} | ||
} |
Oops, something went wrong.