-
Notifications
You must be signed in to change notification settings - Fork 2
/
CoreClient.ts
122 lines (102 loc) · 3.77 KB
/
CoreClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { Invoker, Uri, WrapError, WrapperEnv } from ".";
import { IUriResolutionContext, IUriResolver } from "../uri-resolution";
import { UriResolverHandler } from "./UriResolver";
import { ReadonlyUriMap } from "./UriMap";
import { WrapManifest } from "@polywrap/wrap-manifest-types-js";
import { Result } from "@polywrap/result";
// $start: CoreClient.ts
/** Core Client configuration that can be passed to the PolywrapClient or PolywrapCoreClient constructors */
export interface CoreClientConfig {
/** register interface implementations */
readonly interfaces?: ReadonlyUriMap<readonly Uri[]>;
/** set environmental variables for a wrapper */
readonly envs?: ReadonlyUriMap<WrapperEnv>;
/** configure URI resolution for redirects, packages, and wrappers */
readonly resolver: Readonly<IUriResolver<unknown>>;
}
/** Options for CoreClient's getFile method */
export interface GetFileOptions {
/** file path from wrapper root */
path: string;
/** file encoding */
encoding?: "utf-8" | string;
}
/** Options for CoreClient's getImplementations method */
export interface GetImplementationsOptions {
/** If true, follow redirects to resolve URIs */
applyResolution?: boolean;
/** Use and update an existing resolution context */
resolutionContext?: IUriResolutionContext;
}
/** Options for CoreClient's validate method */
export interface ValidateOptions {
/** Validate full ABI */
abi?: boolean;
/** Recursively validate import URIs */
recursive?: boolean;
}
/** CoreClient invokes wrappers and interacts with wrap packages. */
export interface CoreClient extends Invoker, UriResolverHandler<unknown> {
/**
* Returns the configuration used to instantiate the client
*
* @returns an immutable core client config
*/
getConfig(): CoreClientConfig;
/**
* returns all interfaces from the configuration used to instantiate the client
*
* @returns a Set of interfaces and their registered implementations
*/
getInterfaces(): ReadonlyUriMap<readonly Uri[]> | undefined;
/**
* returns all env registrations from the configuration used to instantiate the client
*
* @returns an array of env objects containing wrapper environmental variables
*/
getEnvs(): ReadonlyUriMap<WrapperEnv> | undefined;
/**
* returns an env (a set of environmental variables) from the configuration used to instantiate the client
*
* @param uri - the URI used to register the env
* @returns an env, or undefined if an env is not found at the given URI
*/
getEnvByUri(uri: Uri): WrapperEnv | undefined;
/**
* returns the URI resolver from the configuration used to instantiate the client
*
* @returns an object that implements the IUriResolver interface
*/
getResolver(): IUriResolver<unknown>;
/**
* returns a package's wrap manifest
*
* @param uri - a wrap URI
* @returns a Result containing the WrapManifest if the request was successful
*/
getManifest(uri: Uri): Promise<Result<WrapManifest, WrapError>>;
/**
* returns a file contained in a wrap package
*
* @param uri - a wrap URI
* @param options - { path: string; encoding?: "utf-8" | string }
* @returns a Promise of a Result containing a file if the request was successful
*/
getFile(
uri: Uri,
options: GetFileOptions
): Promise<Result<string | Uint8Array, WrapError>>;
/**
* returns the interface implementations associated with an interface URI
* from the configuration used to instantiate the client
*
* @param uri - a wrap URI
* @param options - { applyResolution?: boolean; resolutionContext?: IUriResolutionContext }
* @returns a Result containing URI array if the request was successful
*/
getImplementations(
uri: Uri,
options: GetImplementationsOptions
): Promise<Result<Uri[], WrapError>>;
}
// $end