@wvb/bridge 0.1.0-next.3603a22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## bridge v0.1.0-next.3603a22
4
+
5
+ This release includes packages: [`@wvb/bridge`](https://www.npmjs.com/package/@wvb/bridge/v/0.1.0-next.3603a22)
6
+
7
+ - feat(bridge,electron,tauri): remove legacy invokes to unify in `@wvb/bridge` and add `BridgeError` (#178) (f3735bb)
8
+ - feat(bridge): impl universal bridge (#171) (e4cfd0d)
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @wvb/bridge
@@ -0,0 +1,198 @@
1
+ //#region src/error.d.ts
2
+ /**
3
+ * Bridge error data that respond from native.
4
+ */
5
+ interface BridgeErrorData {
6
+ code?: string;
7
+ message: string;
8
+ }
9
+ declare const BridgeErrorCode: {
10
+ /** `params` was missing or had the wrong shape/type. */readonly InvalidParams: "invalid_params"; /** A `remote.*` command was invoked but no remote is configured. */
11
+ readonly RemoteNotInitialized: "remote_not_initialized"; /** An `updater.*` command was invoked but no updater is configured. */
12
+ readonly UpdaterNotInitialized: "updater_not_initialized"; /** No handler is registered for the requested command name. */
13
+ readonly HandlerNotFound: "handler_not_found"; /** The handler returned a value that is not JSON-encodable. */
14
+ readonly UnencodableResult: "unencodable_result";
15
+ };
16
+ type BridgeErrorCode = (typeof BridgeErrorCode)[keyof typeof BridgeErrorCode];
17
+ /**
18
+ * Error thrown by `@wvb/bridge` when an `invoke()` command rejects, regardless of
19
+ * platform.
20
+ */
21
+ declare class BridgeError extends Error {
22
+ override readonly name = "BridgeError";
23
+ readonly code?: string;
24
+ static of(code: BridgeErrorCode | string, message?: string): BridgeError;
25
+ static from(value: unknown): BridgeError;
26
+ constructor(data: BridgeErrorData);
27
+ }
28
+ declare function isBridgeError(e: unknown): e is BridgeError;
29
+ declare function isBridgeErrorData(value: unknown): value is BridgeErrorData;
30
+ //#endregion
31
+ //#region src/invoke.d.ts
32
+ interface InvokeParams {
33
+ [key: string | number]: any;
34
+ }
35
+ /**
36
+ * Invokes a native bridge command and resolves its result.
37
+ * Before using the bridge, make sure native supports webview-bundle.
38
+ *
39
+ * Throws a {@link BridgeError} on failure.
40
+ */
41
+ declare function invoke<T = unknown>(name: string, params?: InvokeParams): Promise<T>;
42
+ //#endregion
43
+ //#region src/platform.d.ts
44
+ type PlatformType = "electron" | "tauri" | "android" | "ios";
45
+ declare const platform: {
46
+ type: PlatformType | undefined;
47
+ isElectron: boolean;
48
+ isTauri: boolean;
49
+ isAndroid: boolean;
50
+ isIos: boolean;
51
+ };
52
+ //#endregion
53
+ //#region src/remote.d.ts
54
+ /** List item of remote bundles. */
55
+ interface ListRemoteBundleInfo {
56
+ /** The name of the bundle. */
57
+ name: string;
58
+ /** The version of the bundle. */
59
+ version: string;
60
+ }
61
+ declare function listBundles$1(channel?: string): Promise<ListRemoteBundleInfo[]>;
62
+ /** Information of a remote bundle. */
63
+ interface RemoteBundleInfo {
64
+ /** The name of the bundle. */
65
+ name: string;
66
+ /** The version of the bundle. */
67
+ version: string;
68
+ /** "ETag" header value. */
69
+ etag?: string;
70
+ /** Integrity value to verify the bundle. */
71
+ integrity?: string;
72
+ /** Signature value to verify the bundle. */
73
+ signature?: string;
74
+ /** Last modified timestamp. (uses GMT) */
75
+ lastModified?: string;
76
+ }
77
+ declare function getInfo(bundleName: string, channel?: string): Promise<RemoteBundleInfo>;
78
+ declare function download$1(bundleName: string, channel?: string): Promise<RemoteBundleInfo>;
79
+ declare function downloadVersion(bundleName: string, version: string): Promise<RemoteBundleInfo>;
80
+ interface RemoteApi {
81
+ listBundles: typeof listBundles$1;
82
+ getInfo: typeof getInfo;
83
+ download: typeof download$1;
84
+ downloadVersion: typeof downloadVersion;
85
+ }
86
+ declare const remote: RemoteApi;
87
+ //#endregion
88
+ //#region src/source.d.ts
89
+ /**
90
+ * - builtin: Built-in bundle which is included in the application.
91
+ * - remote: Remote bundle which is downloaded from a remote server.
92
+ */
93
+ type BundleSourceType = "builtin" | "remote";
94
+ /**
95
+ * Bundle manifest metadata.
96
+ */
97
+ interface BundleManifestMetadata {
98
+ /** "ETag" header value. */
99
+ etag?: string;
100
+ /** Integrity value to verify the bundle. */
101
+ integrity?: string;
102
+ /** Signature value to verify the bundle. */
103
+ signature?: string;
104
+ /** Last modified timestamp. (uses GMT) */
105
+ lastModified?: string;
106
+ }
107
+ /**
108
+ * List item of bundle manifests.
109
+ */
110
+ interface ListBundleManifestItem {
111
+ /** The name of the bundle. */
112
+ name: string;
113
+ /** The version of the bundle. */
114
+ version: string;
115
+ /** Whether the bundle is currently active. */
116
+ current: boolean;
117
+ /** Bundle manifest metadata. */
118
+ metadata: BundleManifestMetadata;
119
+ }
120
+ /**
121
+ * List item of bundles.
122
+ */
123
+ interface ListBundleItem {
124
+ /** The type of the bundle. */
125
+ type: BundleSourceType;
126
+ /** The bundle item. */
127
+ item: ListBundleManifestItem;
128
+ }
129
+ /**
130
+ * Bundle source version.
131
+ */
132
+ interface BundleSourceVersion {
133
+ /** The type of the bundle source. */
134
+ type: BundleSourceType;
135
+ /** The version of the bundle. */
136
+ version: string;
137
+ }
138
+ declare function listBundles(): Promise<ListBundleItem[]>;
139
+ declare function loadVersion(bundleName: string): Promise<BundleSourceVersion | null>;
140
+ declare function updateVersion(bundleName: string, version: string): Promise<void>;
141
+ declare function resolveFilepath(bundleName: string): Promise<string>;
142
+ declare function getBuiltinBundleFilepath(bundleName: string, version: string): Promise<string>;
143
+ declare function getRemoteBundleFilepath(bundleName: string, version: string): Promise<string>;
144
+ declare function loadBuiltinMetadata(bundleName: string, version: string): Promise<BundleManifestMetadata | null>;
145
+ declare function loadRemoteMetadata(bundleName: string, version: string): Promise<BundleManifestMetadata | null>;
146
+ declare function unloadDescriptor(bundleName: string): Promise<boolean>;
147
+ declare function removeRemoteBundle(bundleName: string, version: string): Promise<boolean>;
148
+ declare function remoteRetainedVersions(bundleName: string): Promise<string[]>;
149
+ declare function pruneRemoteBundles(bundleName: string): Promise<string[]>;
150
+ interface SourceApi {
151
+ listBundles: typeof listBundles;
152
+ loadVersion: typeof loadVersion;
153
+ updateVersion: typeof updateVersion;
154
+ resolveFilepath: typeof resolveFilepath;
155
+ getBuiltinBundleFilepath: typeof getBuiltinBundleFilepath;
156
+ getRemoteBundleFilepath: typeof getRemoteBundleFilepath;
157
+ loadBuiltinMetadata: typeof loadBuiltinMetadata;
158
+ loadRemoteMetadata: typeof loadRemoteMetadata;
159
+ unloadDescriptor: typeof unloadDescriptor;
160
+ removeRemoteBundle: typeof removeRemoteBundle;
161
+ remoteRetainedVersions: typeof remoteRetainedVersions;
162
+ pruneRemoteBundles: typeof pruneRemoteBundles;
163
+ }
164
+ declare const source: SourceApi;
165
+ //#endregion
166
+ //#region src/updater.d.ts
167
+ declare function listRemotes(): Promise<ListRemoteBundleInfo[]>;
168
+ /** Information of an available bundle update. */
169
+ interface BundleUpdateInfo {
170
+ /** The name of the bundle. */
171
+ name: string;
172
+ /** The latest version available from the remote. */
173
+ version: string;
174
+ /** The version of the bundle currently installed locally. */
175
+ localVersion?: string;
176
+ /** Whether a new update is available. */
177
+ isAvailable: boolean;
178
+ /** "ETag" header value. */
179
+ etag?: string;
180
+ /** Integrity value to verify the bundle. */
181
+ integrity?: string;
182
+ /** Signature value to verify the bundle. */
183
+ signature?: string;
184
+ /** Last modified timestamp. (uses GMT) */
185
+ lastModified?: string;
186
+ }
187
+ declare function getUpdate(bundleName: string): Promise<BundleUpdateInfo>;
188
+ declare function download(bundleName: string, version?: string): Promise<RemoteBundleInfo>;
189
+ declare function install(bundleName: string, version: string): Promise<void>;
190
+ interface UpdaterApi {
191
+ listRemotes: typeof listRemotes;
192
+ getUpdate: typeof getUpdate;
193
+ download: typeof download;
194
+ install: typeof install;
195
+ }
196
+ declare const updater: UpdaterApi;
197
+ //#endregion
198
+ export { isBridgeErrorData as C, isBridgeError as S, InvokeParams as _, BundleSourceType as a, BridgeErrorCode as b, ListBundleManifestItem as c, ListRemoteBundleInfo as d, RemoteApi as f, platform as g, PlatformType as h, BundleManifestMetadata as i, SourceApi as l, remote as m, UpdaterApi as n, BundleSourceVersion as o, RemoteBundleInfo as p, updater as r, ListBundleItem as s, BundleUpdateInfo as t, source as u, invoke as v, BridgeErrorData as x, BridgeError as y };
@@ -0,0 +1,198 @@
1
+ //#region src/error.d.ts
2
+ /**
3
+ * Bridge error data that respond from native.
4
+ */
5
+ interface BridgeErrorData {
6
+ code?: string;
7
+ message: string;
8
+ }
9
+ declare const BridgeErrorCode: {
10
+ /** `params` was missing or had the wrong shape/type. */readonly InvalidParams: "invalid_params"; /** A `remote.*` command was invoked but no remote is configured. */
11
+ readonly RemoteNotInitialized: "remote_not_initialized"; /** An `updater.*` command was invoked but no updater is configured. */
12
+ readonly UpdaterNotInitialized: "updater_not_initialized"; /** No handler is registered for the requested command name. */
13
+ readonly HandlerNotFound: "handler_not_found"; /** The handler returned a value that is not JSON-encodable. */
14
+ readonly UnencodableResult: "unencodable_result";
15
+ };
16
+ type BridgeErrorCode = (typeof BridgeErrorCode)[keyof typeof BridgeErrorCode];
17
+ /**
18
+ * Error thrown by `@wvb/bridge` when an `invoke()` command rejects, regardless of
19
+ * platform.
20
+ */
21
+ declare class BridgeError extends Error {
22
+ override readonly name = "BridgeError";
23
+ readonly code?: string;
24
+ static of(code: BridgeErrorCode | string, message?: string): BridgeError;
25
+ static from(value: unknown): BridgeError;
26
+ constructor(data: BridgeErrorData);
27
+ }
28
+ declare function isBridgeError(e: unknown): e is BridgeError;
29
+ declare function isBridgeErrorData(value: unknown): value is BridgeErrorData;
30
+ //#endregion
31
+ //#region src/invoke.d.ts
32
+ interface InvokeParams {
33
+ [key: string | number]: any;
34
+ }
35
+ /**
36
+ * Invokes a native bridge command and resolves its result.
37
+ * Before using the bridge, make sure native supports webview-bundle.
38
+ *
39
+ * Throws a {@link BridgeError} on failure.
40
+ */
41
+ declare function invoke<T = unknown>(name: string, params?: InvokeParams): Promise<T>;
42
+ //#endregion
43
+ //#region src/platform.d.ts
44
+ type PlatformType = "electron" | "tauri" | "android" | "ios";
45
+ declare const platform: {
46
+ type: PlatformType | undefined;
47
+ isElectron: boolean;
48
+ isTauri: boolean;
49
+ isAndroid: boolean;
50
+ isIos: boolean;
51
+ };
52
+ //#endregion
53
+ //#region src/remote.d.ts
54
+ /** List item of remote bundles. */
55
+ interface ListRemoteBundleInfo {
56
+ /** The name of the bundle. */
57
+ name: string;
58
+ /** The version of the bundle. */
59
+ version: string;
60
+ }
61
+ declare function listBundles$1(channel?: string): Promise<ListRemoteBundleInfo[]>;
62
+ /** Information of a remote bundle. */
63
+ interface RemoteBundleInfo {
64
+ /** The name of the bundle. */
65
+ name: string;
66
+ /** The version of the bundle. */
67
+ version: string;
68
+ /** "ETag" header value. */
69
+ etag?: string;
70
+ /** Integrity value to verify the bundle. */
71
+ integrity?: string;
72
+ /** Signature value to verify the bundle. */
73
+ signature?: string;
74
+ /** Last modified timestamp. (uses GMT) */
75
+ lastModified?: string;
76
+ }
77
+ declare function getInfo(bundleName: string, channel?: string): Promise<RemoteBundleInfo>;
78
+ declare function download$1(bundleName: string, channel?: string): Promise<RemoteBundleInfo>;
79
+ declare function downloadVersion(bundleName: string, version: string): Promise<RemoteBundleInfo>;
80
+ interface RemoteApi {
81
+ listBundles: typeof listBundles$1;
82
+ getInfo: typeof getInfo;
83
+ download: typeof download$1;
84
+ downloadVersion: typeof downloadVersion;
85
+ }
86
+ declare const remote: RemoteApi;
87
+ //#endregion
88
+ //#region src/source.d.ts
89
+ /**
90
+ * - builtin: Built-in bundle which is included in the application.
91
+ * - remote: Remote bundle which is downloaded from a remote server.
92
+ */
93
+ type BundleSourceType = "builtin" | "remote";
94
+ /**
95
+ * Bundle manifest metadata.
96
+ */
97
+ interface BundleManifestMetadata {
98
+ /** "ETag" header value. */
99
+ etag?: string;
100
+ /** Integrity value to verify the bundle. */
101
+ integrity?: string;
102
+ /** Signature value to verify the bundle. */
103
+ signature?: string;
104
+ /** Last modified timestamp. (uses GMT) */
105
+ lastModified?: string;
106
+ }
107
+ /**
108
+ * List item of bundle manifests.
109
+ */
110
+ interface ListBundleManifestItem {
111
+ /** The name of the bundle. */
112
+ name: string;
113
+ /** The version of the bundle. */
114
+ version: string;
115
+ /** Whether the bundle is currently active. */
116
+ current: boolean;
117
+ /** Bundle manifest metadata. */
118
+ metadata: BundleManifestMetadata;
119
+ }
120
+ /**
121
+ * List item of bundles.
122
+ */
123
+ interface ListBundleItem {
124
+ /** The type of the bundle. */
125
+ type: BundleSourceType;
126
+ /** The bundle item. */
127
+ item: ListBundleManifestItem;
128
+ }
129
+ /**
130
+ * Bundle source version.
131
+ */
132
+ interface BundleSourceVersion {
133
+ /** The type of the bundle source. */
134
+ type: BundleSourceType;
135
+ /** The version of the bundle. */
136
+ version: string;
137
+ }
138
+ declare function listBundles(): Promise<ListBundleItem[]>;
139
+ declare function loadVersion(bundleName: string): Promise<BundleSourceVersion | null>;
140
+ declare function updateVersion(bundleName: string, version: string): Promise<void>;
141
+ declare function resolveFilepath(bundleName: string): Promise<string>;
142
+ declare function getBuiltinBundleFilepath(bundleName: string, version: string): Promise<string>;
143
+ declare function getRemoteBundleFilepath(bundleName: string, version: string): Promise<string>;
144
+ declare function loadBuiltinMetadata(bundleName: string, version: string): Promise<BundleManifestMetadata | null>;
145
+ declare function loadRemoteMetadata(bundleName: string, version: string): Promise<BundleManifestMetadata | null>;
146
+ declare function unloadDescriptor(bundleName: string): Promise<boolean>;
147
+ declare function removeRemoteBundle(bundleName: string, version: string): Promise<boolean>;
148
+ declare function remoteRetainedVersions(bundleName: string): Promise<string[]>;
149
+ declare function pruneRemoteBundles(bundleName: string): Promise<string[]>;
150
+ interface SourceApi {
151
+ listBundles: typeof listBundles;
152
+ loadVersion: typeof loadVersion;
153
+ updateVersion: typeof updateVersion;
154
+ resolveFilepath: typeof resolveFilepath;
155
+ getBuiltinBundleFilepath: typeof getBuiltinBundleFilepath;
156
+ getRemoteBundleFilepath: typeof getRemoteBundleFilepath;
157
+ loadBuiltinMetadata: typeof loadBuiltinMetadata;
158
+ loadRemoteMetadata: typeof loadRemoteMetadata;
159
+ unloadDescriptor: typeof unloadDescriptor;
160
+ removeRemoteBundle: typeof removeRemoteBundle;
161
+ remoteRetainedVersions: typeof remoteRetainedVersions;
162
+ pruneRemoteBundles: typeof pruneRemoteBundles;
163
+ }
164
+ declare const source: SourceApi;
165
+ //#endregion
166
+ //#region src/updater.d.ts
167
+ declare function listRemotes(): Promise<ListRemoteBundleInfo[]>;
168
+ /** Information of an available bundle update. */
169
+ interface BundleUpdateInfo {
170
+ /** The name of the bundle. */
171
+ name: string;
172
+ /** The latest version available from the remote. */
173
+ version: string;
174
+ /** The version of the bundle currently installed locally. */
175
+ localVersion?: string;
176
+ /** Whether a new update is available. */
177
+ isAvailable: boolean;
178
+ /** "ETag" header value. */
179
+ etag?: string;
180
+ /** Integrity value to verify the bundle. */
181
+ integrity?: string;
182
+ /** Signature value to verify the bundle. */
183
+ signature?: string;
184
+ /** Last modified timestamp. (uses GMT) */
185
+ lastModified?: string;
186
+ }
187
+ declare function getUpdate(bundleName: string): Promise<BundleUpdateInfo>;
188
+ declare function download(bundleName: string, version?: string): Promise<RemoteBundleInfo>;
189
+ declare function install(bundleName: string, version: string): Promise<void>;
190
+ interface UpdaterApi {
191
+ listRemotes: typeof listRemotes;
192
+ getUpdate: typeof getUpdate;
193
+ download: typeof download;
194
+ install: typeof install;
195
+ }
196
+ declare const updater: UpdaterApi;
197
+ //#endregion
198
+ export { isBridgeErrorData as C, isBridgeError as S, InvokeParams as _, BundleSourceType as a, BridgeErrorCode as b, ListBundleManifestItem as c, ListRemoteBundleInfo as d, RemoteApi as f, platform as g, PlatformType as h, BundleManifestMetadata as i, SourceApi as l, remote as m, UpdaterApi as n, BundleSourceVersion as o, RemoteBundleInfo as p, updater as r, ListBundleItem as s, BundleUpdateInfo as t, source as u, invoke as v, BridgeErrorData as x, BridgeError as y };