apps/web/lib/workspace-context.ts
Metadata
- Purpose: Frontend data/service utility module.
- Domain:
applications - Language:
ts - Bytes: 1563
- Lines: 48
- Content hash (short):
6aba1919 - Source (start): apps/web/lib/workspace-context.ts:1
- Source (end): apps/web/lib/workspace-context.ts:48
Indexed Symbols
isWorkspaceId(line 7, function) - Implements is workspace id for module behavior.firstValue(line 11, function) - Implements first value for module behavior.workspaceIdFromSearchParams(line 18, function) - Implements workspace id from search params for module behavior.assertWorkspaceIdFromSearchParams(line 32, function) - Implements assert workspace id from search params for module behavior.withWorkspaceQuery(line 40, function) - Implements with workspace query for module behavior.
Markdown Headings (if applicable)
No markdown headings detected.
Source Preview
const WORKSPACE_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
export const WORKSPACE_QUERY_PARAM = "workspaceId";
export type SearchParamRecord = Record<string, string | string[] | undefined>;
export function isWorkspaceId(value: unknown): value is string {
return typeof value === "string" && WORKSPACE_ID_PATTERN.test(value.trim());
}
function firstValue(value: string | string[] | undefined): string | undefined {
if (Array.isArray(value)) {
return value[0];
}
return value;
}
export function workspaceIdFromSearchParams(searchParams: SearchParamRecord | URLSearchParams): string | null {
const value =
searchParams instanceof URLSearchParams
? searchParams.get(WORKSPACE_QUERY_PARAM) ?? undefined
: firstValue(searchParams[WORKSPACE_QUERY_PARAM]);
if (!value) {
return null;