1
>
/*---------------------------------------------------------------------------------------------
uriIpc.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 { VSBuffer } from './buffer.js';
7
>
import { MarshalledObject } from './marshalling.js';
8
>
import { MarshalledId } from './marshallingIds.js';
9
>
import { URI, UriComponents } from './uri.js';
10
>
11
>
export interface IURITransformer {
12
>
transformIncoming(uri: UriComponents): UriComponents;
13
>
transformOutgoing(uri: UriComponents): UriComponents;
14
>
transformOutgoingURI(uri: URI): URI;
15
>
transformOutgoingScheme(scheme: string): string;
16
>
}
17
>
18
>
export interface UriParts {
19
>
scheme: string;
20
>
authority?: string;
21
>
path?: string;
22
>
query?: string;
23
>
fragment?: string;
24
>
}
25
>
26
>
export interface IRawURITransformer {
27
>
transformIncoming(uri: UriParts): UriParts;
28
>
transformOutgoing(uri: UriParts): UriParts;
29
>
transformOutgoingScheme(scheme: string): string;
30
>
}
31
>
32
function toJSON(uri: URI): UriComponents {
33
return uri.toJSON();
34
}
36
>
export class URITransformer implements IURITransformer {
37
>
38
>
private readonly _uriTransformer: IRawURITransformer;
39
>
40
>
constructor(uriTransformer: IRawURITransformer) {
41
this._uriTransformer = uriTransformer;
42
}
44
>
public transformIncoming(uri: UriComponents): UriComponents {
45
const result = this._uriTransformer.transformIncoming(uri);
46
return (result === uri ? uri : toJSON(URI.from(result)));
47
}
49
>
public transformOutgoing(uri: UriComponents): UriComponents {
50
const result = this._uriTransformer.transformOutgoing(uri);
51
return (result === uri ? uri : toJSON(URI.from(result)));
52
}
54
>
public transformOutgoingURI(uri: URI): URI {
55
const result = this._uriTransformer.transformOutgoing(uri);
56
return (result === uri ? uri : URI.from(result));
57
}
59
>
public transformOutgoingScheme(scheme: string): string {
60
return this._uriTransformer.transformOutgoingScheme(scheme);
61
}
63
>
64
>
export const DefaultURITransformer: IURITransformer = new class {
65
>
transformIncoming(uri: UriComponents) {
66
return uri;
67
}
69
>
transformOutgoing(uri: UriComponents): UriComponents {
70
return uri;
71
}
73
>
transformOutgoingURI(uri: URI): URI {
74
return uri;
75
}
77
>
transformOutgoingScheme(scheme: string): string {
78
return scheme;
79
}
81
>
82
function _transformOutgoingURIs(obj: any, transformer: IURITransformer, depth: number): any {
83