1
>
/*---------------------------------------------------------------------------------------------
annotationsUri.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import type { URI } from './state/sessionState.js';
7
>
8
>
/**
9
>
* Helpers for building / parsing the URI clients subscribe to in order to
10
>
* receive an {@link import('./state/protocol/state.js').AnnotationsState}.
11
>
*
12
>
* Each session exposes exactly one annotations channel, nested under the
13
>
* session URI namespace:
14
>
*
15
>
* <sessionUri>/annotations
16
>
*
17
>
* Keeping the annotations URI nested under the session URI lets the server
18
>
* cleanly tear down a session's annotations when that session is disposed
19
>
* (the reverse-lookup is just a string-prefix scan, mirroring changesets).
20
>
*/
21
>
22
>
/** Marker injected into an annotations channel URI's path. */
23
>
const ANNOTATIONS_PATH_SEGMENT = '/annotations';
24
>
25
>
/** Returns the subscribable URI for a session's annotations channel. */
26
>
export function buildAnnotationsUri(sessionUri: URI): URI {
27
return `${sessionUri}${ANNOTATIONS_PATH_SEGMENT}`;
28
}
30
>
/**
31
>
* Parses an annotations channel URI back into its owning `sessionUri`, or
32
>
* returns `undefined` if `uri` is not an annotations channel URI.
33
>
*/
34
>
export function parseAnnotationsUri(uri: URI): { sessionUri: URI } | undefined {
35
if (!uri.endsWith(ANNOTATIONS_PATH_SEGMENT)) {
36
return undefined;