@unbound-app/api 0.9.0 → 1.1.0
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/ambient/image-modules.d.ts +58 -0
- package/package.json +30 -5
- package/src/_internal.d.ts +6110 -462
- package/src/{utils.d.ts → _types.d.ts} +10 -0
- package/src/assets.d.ts +64 -26
- package/src/builtins.d.ts +17 -0
- package/src/commands.d.ts +331 -0
- package/src/dialogs.d.ts +134 -0
- package/src/flux.d.ts +317 -0
- package/src/fonts.d.ts +51 -0
- package/src/fs.d.ts +16 -26
- package/src/global.d.ts +514 -31
- package/src/i18n.d.ts +33 -31
- package/src/iconPacks.d.ts +43 -0
- package/src/index.d.ts +16 -0
- package/src/marketplace.d.ts +50 -0
- package/src/metro/api.d.ts +10 -0
- package/src/metro/common.d.ts +34 -5
- package/src/metro/components.d.ts +100 -16
- package/src/metro/filters.d.ts +31 -16
- package/src/metro/index.d.ts +26097 -82
- package/src/metro/stores.d.ts +5 -0
- package/src/native.d.ts +123 -3
- package/src/patcher.d.ts +214 -57
- package/src/plugins.d.ts +55 -0
- package/src/settings.d.ts +9 -17
- package/src/shims.d.ts +5 -0
- package/src/storage.d.ts +80 -223
- package/src/sync.d.ts +51 -0
- package/src/themes.d.ts +43 -0
- package/src/toasts.d.ts +62 -9
- package/src/ui.d.ts +650 -0
- package/src/updates.d.ts +25 -0
- package/src/utils/index.d.ts +53 -0
- package/src/utils/react/index.d.ts +82 -0
- package/testing/fake-api.ts +256 -0
- package/testing/fake-components.ts +183 -0
- package/testing/fake-feedback.ts +258 -0
- package/testing/fake-fs.ts +54 -0
- package/testing/fake-java.ts +513 -0
- package/testing/fake-locales.ts +85 -0
- package/testing/fake-metro.ts +346 -0
- package/testing/fake-native-bridge.ts +98 -0
- package/testing/fake-native.ts +211 -0
- package/testing/fake-objc.ts +388 -0
- package/testing/fake-plugins.ts +176 -0
- package/testing/fake-react-native-modules.ts +362 -0
- package/testing/fake-react-native.ts +180 -0
- package/testing/fake-react.ts +54 -0
- package/testing/fake-settings-panel.ts +173 -0
- package/testing/fake-settings.ts +428 -0
- package/testing/fake-timers.ts +74 -0
- package/testing/fake-utils.ts +216 -0
- package/testing/icu-format.ts +132 -0
- package/testing/icu-parse.ts +277 -0
- package/testing/index.ts +42 -0
- package/testing/install-addon-globals.ts +260 -0
- package/testing/listener-registry.ts +39 -0
- package/testing/memory-storage.ts +149 -0
- package/testing/plugin-files.ts +155 -0
- package/testing/plugin-lifecycle.ts +149 -0
- package/testing/plugin-types.ts +34 -0
- package/testing/preset.ts +263 -0
- package/testing/react-patcher.ts +154 -0
- package/testing/react-value.ts +3 -0
- package/testing/recorders.ts +183 -0
- package/testing/recording-patcher.ts +173 -0
- package/testing/render.ts +84 -0
- package/testing/session.ts +77 -0
- package/testing/test-node.ts +163 -0
- package/testing/test-renderer.ts +753 -0
- package/testing/unfrozen-elements.ts +49 -0
package/src/metro/stores.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// Auto-generated by generate-plugin-sdk.ts - DO NOT EDIT
|
|
2
2
|
|
|
3
|
+
/** Discord's `AccessibilityStore` Flux store, holding the user's accessibility settings; found on first access. */
|
|
3
4
|
export declare const Accessibility: any;
|
|
5
|
+
/** Discord's `GuildStore` Flux store, holding the servers the user is in; found on first access. */
|
|
4
6
|
export declare const Guilds: any;
|
|
7
|
+
/** Discord's `ThemeStore` Flux store, holding the theme Discord shows; found on first access. */
|
|
8
|
+
export declare const Theme: any;
|
|
9
|
+
/** Discord's `UserStore` Flux store, holding the users the client knows; found on first access. */
|
|
5
10
|
export declare const Users: any;
|
|
6
11
|
|
|
7
12
|
export {};
|
package/src/native.d.ts
CHANGED
|
@@ -2,51 +2,115 @@
|
|
|
2
2
|
|
|
3
3
|
export type {
|
|
4
4
|
NativeAssociationKey,
|
|
5
|
+
NativeBatchReference,
|
|
6
|
+
NativeBatchStep,
|
|
5
7
|
NativeCallOptions,
|
|
8
|
+
NativeCancelablePromise,
|
|
6
9
|
NativeClassHandle,
|
|
10
|
+
NativeDebugBridge,
|
|
11
|
+
NativeDebugEnvironment,
|
|
12
|
+
NativeDebugEvaluation,
|
|
7
13
|
NativeFFIBridge,
|
|
8
14
|
NativeFFISignature,
|
|
9
15
|
NativeFFIType,
|
|
10
16
|
NativeFFITypeName,
|
|
11
17
|
NativeFabricBridge,
|
|
12
18
|
NativeFabricFrame,
|
|
19
|
+
NativeFabricMountOptions,
|
|
13
20
|
NativeFabricSize,
|
|
14
21
|
NativeFabricSurface,
|
|
15
22
|
NativeHandle,
|
|
16
23
|
NativeHookContext,
|
|
17
24
|
NativeHookHandlers,
|
|
18
25
|
NativeHookOptions,
|
|
26
|
+
NativeHookPayload,
|
|
19
27
|
NativeHookToken,
|
|
28
|
+
NativeJavaArgument,
|
|
29
|
+
NativeJavaAssociationKey,
|
|
30
|
+
NativeJavaBatchOperation,
|
|
31
|
+
NativeJavaBridge,
|
|
32
|
+
NativeJavaCallPlan,
|
|
33
|
+
NativeJavaClassDescription,
|
|
34
|
+
NativeJavaFieldDescription,
|
|
35
|
+
NativeJavaHandle,
|
|
36
|
+
NativeJavaHandleValue,
|
|
37
|
+
NativeJavaHookEvent,
|
|
38
|
+
NativeJavaHookOptions,
|
|
39
|
+
NativeJavaHookToken,
|
|
40
|
+
NativeJavaHooksBridge,
|
|
41
|
+
NativeJavaMethodDescription,
|
|
42
|
+
NativeJavaReference,
|
|
43
|
+
NativeJavaValue,
|
|
20
44
|
NativeObjCBridge,
|
|
45
|
+
NativeObjCCallPlan,
|
|
21
46
|
NativeObjectHandle,
|
|
22
47
|
NativePlatformBridge,
|
|
23
48
|
NativePluginBridge,
|
|
24
49
|
NativePluginCapability,
|
|
25
50
|
NativePluginError,
|
|
26
51
|
NativePluginErrorCode,
|
|
52
|
+
NativePluginPlatform,
|
|
27
53
|
NativePointer,
|
|
54
|
+
NativeRuntimeBridge,
|
|
55
|
+
NativeRuntimeEventName,
|
|
56
|
+
NativeRuntimeEventToken,
|
|
57
|
+
NativeSerializableObject,
|
|
28
58
|
NativeStruct,
|
|
29
59
|
NativeThreadPolicy,
|
|
60
|
+
NativeUIArgument,
|
|
61
|
+
NativeUIBridge,
|
|
62
|
+
NativeUICallback,
|
|
63
|
+
NativeUIScope,
|
|
64
|
+
NativeViewSearchOptions,
|
|
65
|
+
NativeViewSnapshotNode,
|
|
66
|
+
NativeViewSnapshotOptions,
|
|
30
67
|
PluginContext,
|
|
31
68
|
} from './_internal';
|
|
32
|
-
import type {
|
|
69
|
+
import type {
|
|
70
|
+
NativePlatformBridge,
|
|
71
|
+
NativePluginCapability,
|
|
72
|
+
NativePluginPlatform,
|
|
73
|
+
NativeResourceCounts,
|
|
74
|
+
} from './_internal';
|
|
75
|
+
import * as React$1 from 'react';
|
|
76
|
+
import { ComponentType } from 'react';
|
|
77
|
+
/** The loader's platform bridge, read from `globalThis.NativePlatform` at import; `undefined` when no loader injected it. */
|
|
33
78
|
declare const NativePlatform$1: NativePlatformBridge | undefined;
|
|
34
79
|
|
|
80
|
+
/** Thrown when a plugin uses a Capability its manifest does not declare, or declares one that is unknown or the native bridge lacks. */
|
|
35
81
|
export declare class NativePluginCapabilityError extends Error {
|
|
82
|
+
/** A stable code to match on instead of the message. */
|
|
36
83
|
readonly code = 'NATIVE_PLUGIN_CAPABILITY_DENIED';
|
|
84
|
+
/** The Capability that was missing or refused. */
|
|
37
85
|
readonly capability: NativePluginCapability;
|
|
38
86
|
constructor(capability: NativePluginCapability);
|
|
39
87
|
}
|
|
88
|
+
/** Thrown when native work is called through a plugin's scope after the scope was disposed, such as after the plugin stopped. */
|
|
40
89
|
export declare class NativePluginDisposedError extends Error {
|
|
90
|
+
/** A stable code to match on instead of the message. */
|
|
41
91
|
readonly code = 'NATIVE_PLUGIN_SCOPE_DISPOSED';
|
|
42
92
|
constructor();
|
|
43
93
|
}
|
|
94
|
+
/** Thrown when the loader does not provide the native plugin bridge, or the part of it a call needs. */
|
|
44
95
|
export declare class NativePluginUnavailableError extends Error {
|
|
96
|
+
/** A stable code to match on instead of the message. */
|
|
45
97
|
readonly code = 'NATIVE_PLUGIN_UNAVAILABLE';
|
|
46
98
|
}
|
|
99
|
+
/** Thrown when the host platform is not one the addon runs on, by its manifest or the handlers given to `definePlatform`. */
|
|
100
|
+
export declare class NativePluginUnsupportedPlatformError extends Error {
|
|
101
|
+
/** A stable code to match on instead of the message. */
|
|
102
|
+
readonly code = 'NATIVE_PLUGIN_PLATFORM_EXCLUDED';
|
|
103
|
+
/** The platforms the addon does run on. */
|
|
104
|
+
readonly platforms: readonly NativePluginPlatform[];
|
|
105
|
+
constructor(platforms: readonly NativePluginPlatform[], platform: string);
|
|
106
|
+
}
|
|
107
|
+
/** Thrown when the native plugin API is older than the manifest's `minNativePluginApi`. */
|
|
47
108
|
export declare class NativePluginVersionError extends Error {
|
|
109
|
+
/** A stable code to match on instead of the message. */
|
|
48
110
|
readonly code = 'NATIVE_PLUGIN_API_VERSION_UNSUPPORTED';
|
|
111
|
+
/** The native plugin API version the loader provides. */
|
|
49
112
|
readonly installedApi: string;
|
|
113
|
+
/** The manifest's `minNativePluginApi`. */
|
|
50
114
|
readonly requiredApi: string;
|
|
51
115
|
constructor(requiredApi: string, installedApi: string);
|
|
52
116
|
}
|
|
@@ -56,6 +120,13 @@ export declare const BundleInfo: BundleInfoType;
|
|
|
56
120
|
export declare const BundleManager: DCDBundleManagerType;
|
|
57
121
|
/** The resolved native device module, exposing hardware and OS details. */
|
|
58
122
|
export declare const DeviceInfo: DeviceInfoType;
|
|
123
|
+
/**
|
|
124
|
+
* @description Selects the Platform handler for the host platform, so an addon branches on the platform in one place.
|
|
125
|
+
* @template Handler What each platform's handler provides.
|
|
126
|
+
* @param handlers The handler for each platform the addon runs on.
|
|
127
|
+
* @returns The host platform's handler.
|
|
128
|
+
*/
|
|
129
|
+
export declare function definePlatform<Handler>(handlers: PlatformHandlers<Handler>): Handler;
|
|
59
130
|
/**
|
|
60
131
|
* @description Resolves the first available native module matching any of the given names, checking both `NativeModules` and the `TurboModuleRegistry`.
|
|
61
132
|
* @template T The type of the resolved native module.
|
|
@@ -63,47 +134,81 @@ export declare const DeviceInfo: DeviceInfoType;
|
|
|
63
134
|
* @returns The first matching native module.
|
|
64
135
|
*/
|
|
65
136
|
export declare function getNativeModule<T>(...names: string[]): T;
|
|
137
|
+
/**
|
|
138
|
+
* @description Reads how many native resources the loader holds: installed hooks, mounted surfaces, cached hook return values and Java handles still referenced from JavaScript.
|
|
139
|
+
* @returns The counts, or `undefined` when the loader does not report them.
|
|
140
|
+
*/
|
|
141
|
+
export declare function getNativeResources(): NativeResourceCounts | undefined;
|
|
66
142
|
/**
|
|
67
143
|
* @description Reads Hermes' runtime metadata, such as the bytecode version, GC, and build channel.
|
|
68
144
|
* @returns The runtime property map, or an empty object when Hermes internals are unavailable.
|
|
69
145
|
*/
|
|
70
146
|
export declare function getRuntimeProperties(): HermesRuntimeProperties;
|
|
147
|
+
/**
|
|
148
|
+
* @description Checks whether the native bridge on this device provides a capability, so an addon can
|
|
149
|
+
* fall back when the other platform lacks it.
|
|
150
|
+
* @param capability The capability to look for.
|
|
151
|
+
* @returns Whether the bridge provides it.
|
|
152
|
+
*/
|
|
153
|
+
export declare function has(capability: NativePluginCapability): boolean;
|
|
71
154
|
/**
|
|
72
155
|
* @description Persists pending settings to storage, then reloads the native bundle.
|
|
73
156
|
*/
|
|
74
157
|
export declare function reload(): Promise<void>;
|
|
75
158
|
/** Build and release metadata reported by the native client info module. */
|
|
76
159
|
export type BundleInfoType = {
|
|
160
|
+
/** Discord's app version, shown in Unbound's settings beside `Build`. */
|
|
77
161
|
Version: string;
|
|
162
|
+
/** The Discord release channel the app was built for. */
|
|
78
163
|
ReleaseChannel: string;
|
|
164
|
+
/** Reported by Discord's native client info module; Unbound does not read it. */
|
|
79
165
|
Manifest: string;
|
|
166
|
+
/** Discord's build number; Unbound's Metro cache is invalidated when it changes. */
|
|
80
167
|
Build: string;
|
|
168
|
+
/** The Sentry DSN Discord reports crashes to. */
|
|
81
169
|
SentryDsn: string;
|
|
170
|
+
/** The device's vendor identifier, which Discord sends in its analytics properties. */
|
|
82
171
|
DeviceVendorID: string;
|
|
172
|
+
/** The build of the over-the-air JavaScript bundle, reported by Discord's native client info module. */
|
|
83
173
|
OTABuild: string;
|
|
174
|
+
/** The Sentry DSN Discord reports crashes to on staff builds. */
|
|
84
175
|
SentryStaffDsn: string;
|
|
176
|
+
/** The app's bundle identifier. */
|
|
85
177
|
Identifier: string;
|
|
178
|
+
/** The Sentry DSN Discord reports crashes to on alpha and beta builds. */
|
|
86
179
|
SentryAlphaBetaDsn: string;
|
|
87
180
|
};
|
|
88
181
|
/** The native `BundleUpdaterManager` module surface for OTA updates and reloading the bundle. */
|
|
89
182
|
export type DCDBundleManagerType = {
|
|
183
|
+
/** Reports whether the first OTA bundle has been downloaded; Discord does not document what it resolves to. */
|
|
90
184
|
getInitialBundleDownloaded: UndocumentedNativeMethod;
|
|
185
|
+
/** Reports whether the first OTA update check has run; Discord does not document what it resolves to. */
|
|
91
186
|
getInitialOtaUpdateChecked: UndocumentedNativeMethod;
|
|
187
|
+
/** Checks for an OTA bundle update, then reloads the app. */
|
|
92
188
|
checkForUpdateAndReload(): void;
|
|
189
|
+
/** Reloads the JavaScript bundle; {@link reload} persists settings first, so prefer it. */
|
|
93
190
|
reload(): void;
|
|
191
|
+
/** Reads the directory OTA bundles are stored in; Discord does not document what it resolves to. */
|
|
94
192
|
getOtaRootPath: UndocumentedNativeMethod;
|
|
193
|
+
/** Reads the contents of Discord's build override cookie; Discord does not document what it resolves to. */
|
|
95
194
|
getBuildOverrideCookieContents: UndocumentedNativeMethod;
|
|
195
|
+
/** Sets the build override cookie header; Discord does not document its argument or result. */
|
|
96
196
|
setBuildOverrideCookieHeader: UndocumentedNativeMethod;
|
|
197
|
+
/** Reads the OTA manifest info; Discord does not document what it resolves to. */
|
|
97
198
|
getManifestInfo: UndocumentedNativeMethod;
|
|
199
|
+
/** React Native event-emitter hook: tells the native module a listener for `eventName` was added. */
|
|
98
200
|
addListener(eventName: string): void;
|
|
201
|
+
/** React Native event-emitter hook: tells the native module `count` listeners were removed. */
|
|
99
202
|
removeListeners(count: number): void;
|
|
100
203
|
};
|
|
101
204
|
/** The constant directory paths exposed by the native `DCDFileManager`. */
|
|
102
205
|
export type DCDFileManagerConstants = {
|
|
206
|
+
/** The absolute path to the app's cache directory. */
|
|
103
207
|
CacheDirPath: string;
|
|
208
|
+
/** The absolute path to the app's documents directory, where Unbound keeps its files. */
|
|
104
209
|
DocumentsDirPath: string;
|
|
105
210
|
};
|
|
106
|
-
/**
|
|
211
|
+
/** How the native file manager encodes file contents: UTF-8 text or base64 for binary data. */
|
|
107
212
|
export type DCDFileManagerEncoding = 'utf-8' | 'utf8' | 'base64';
|
|
108
213
|
/** The native `DCDFileManager` module surface for reading, writing, and inspecting files. */
|
|
109
214
|
export type DCDFileManagerType = {
|
|
@@ -124,22 +229,37 @@ export type DCDFileManagerType = {
|
|
|
124
229
|
} & DCDFileManagerConstants;
|
|
125
230
|
/** Hardware and OS details reported by the native device module. */
|
|
126
231
|
export type DeviceInfoType = {
|
|
232
|
+
/** Whether the system task bar is shown, as Discord's native device module reports it. */
|
|
127
233
|
isTaskBarEnabled: boolean;
|
|
234
|
+
/** The maximum CPU frequency as a numeric string; empty when unknown. */
|
|
128
235
|
maxCpuFreq: string;
|
|
236
|
+
/** The system-on-chip's name. */
|
|
129
237
|
socName: string;
|
|
238
|
+
/** The device model; `iPad` on an iPad, which Discord checks to detect iPadOS. */
|
|
130
239
|
deviceModel: string;
|
|
240
|
+
/** Whether the device is a tablet. */
|
|
131
241
|
isTablet: boolean;
|
|
242
|
+
/** Whether the system uses gesture navigation instead of navigation buttons. */
|
|
132
243
|
isGestureNavigationEnabled: boolean;
|
|
244
|
+
/** The device's product name, as Discord's native device module reports it. */
|
|
133
245
|
deviceProduct: string;
|
|
246
|
+
/** The operating system version. */
|
|
134
247
|
systemVersion: string;
|
|
248
|
+
/** The device's manufacturer. */
|
|
135
249
|
deviceManufacturer: string;
|
|
250
|
+
/** The device's brand. */
|
|
136
251
|
deviceBrand: string;
|
|
252
|
+
/** The device's RAM size as a numeric string; empty when unknown. */
|
|
137
253
|
ramSize: string;
|
|
254
|
+
/** The device's name, as Discord's native device module reports it. */
|
|
138
255
|
device: string;
|
|
139
256
|
};
|
|
257
|
+
/** What `HermesInternal.getRuntimeProperties()` reports; empty when the engine is not Hermes. */
|
|
140
258
|
export type HermesRuntimeProperties = ReturnType<HermesInternalObject['getRuntimeProperties']>;
|
|
259
|
+
/** One Platform handler per platform an addon runs on. */
|
|
260
|
+
export type PlatformHandlers<Handler> = Partial<Record<NativePluginPlatform, Handler>>;
|
|
261
|
+
/** A native method Discord exposes without documenting what its promise resolves to. */
|
|
141
262
|
export type UndocumentedNativeMethod = () => Promise<unknown>;
|
|
142
|
-
|
|
143
263
|
export { NativePlatform$1 as NativePlatform };
|
|
144
264
|
|
|
145
265
|
export {};
|
package/src/patcher.d.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
// Auto-generated by generate-plugin-sdk.ts - DO NOT EDIT
|
|
2
2
|
|
|
3
|
+
import * as React$1 from 'react';
|
|
4
|
+
import { JSXElementConstructor, ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
/** The kinds of patch: before, instead and after. */
|
|
7
|
+
declare const PatchType$1: typeof PatchType;
|
|
8
|
+
declare enum PatchType {
|
|
9
|
+
Before = 0,
|
|
10
|
+
Instead = 1,
|
|
11
|
+
After = 2,
|
|
12
|
+
}
|
|
13
|
+
/** The symbol a patched method carries, pointing at its patch state. */
|
|
14
|
+
export declare const PATCH_SYMBOL: symbol;
|
|
15
|
+
/** Every module the patcher has patched, with its live patches. */
|
|
16
|
+
export declare const patches: PatchedModule[];
|
|
17
|
+
/**
|
|
18
|
+
* `before`, `instead` and `after` for React components. Each takes a `memo`, `forwardRef` or class component and
|
|
19
|
+
* finds its render, or the object and key holding any component, which a plain function component needs.
|
|
20
|
+
*/
|
|
21
|
+
export declare const react: ReactPatcher;
|
|
3
22
|
/**
|
|
4
23
|
* @description Runs a callback after a method, which can replace its result by returning a value.
|
|
5
24
|
* @template M The object holding the method.
|
|
@@ -10,20 +29,10 @@
|
|
|
10
29
|
* @param options Patch options.
|
|
11
30
|
* @returns A function removing the patch.
|
|
12
31
|
*/
|
|
13
|
-
declare function after
|
|
32
|
+
export declare function after<M extends PatchParent, P extends PropOf<M>>(
|
|
14
33
|
parent: M,
|
|
15
34
|
method: P,
|
|
16
|
-
callback:
|
|
17
|
-
options?: PatchOptions,
|
|
18
|
-
): () => void;
|
|
19
|
-
declare function after<M extends PatchParent, P extends PropOf<M>>(
|
|
20
|
-
parent: M,
|
|
21
|
-
method: P,
|
|
22
|
-
callback: PatchCallback<
|
|
23
|
-
M[P] extends (...args: infer Args) => any ? Args : any[],
|
|
24
|
-
M[P] extends (...args: any[]) => infer Res ? Res : any,
|
|
25
|
-
unknown extends ThisParameterType<M[P]> ? M : ThisParameterType<M[P]>
|
|
26
|
-
>,
|
|
35
|
+
callback: AfterCallback<ArgsOf<M[P]>, ResultOf<M[P]>, SelfOf<M, M[P]>>,
|
|
27
36
|
options?: PatchOptions,
|
|
28
37
|
): () => void;
|
|
29
38
|
/**
|
|
@@ -36,20 +45,10 @@ declare function after<M extends PatchParent, P extends PropOf<M>>(
|
|
|
36
45
|
* @param options Patch options.
|
|
37
46
|
* @returns A function removing the patch.
|
|
38
47
|
*/
|
|
39
|
-
declare function before
|
|
40
|
-
parent: M,
|
|
41
|
-
method: P,
|
|
42
|
-
callback: Parameters<typeof before<M, P>>[2],
|
|
43
|
-
options?: PatchOptions,
|
|
44
|
-
): () => void;
|
|
45
|
-
declare function before<M extends PatchParent, P extends PropOf<M>>(
|
|
48
|
+
export declare function before<M extends PatchParent, P extends PropOf<M>>(
|
|
46
49
|
parent: M,
|
|
47
50
|
method: P,
|
|
48
|
-
callback:
|
|
49
|
-
M[P] extends (...args: infer Args) => any ? Args : any[],
|
|
50
|
-
M[P] extends (...args: any[]) => infer Res ? Res : any,
|
|
51
|
-
unknown extends ThisParameterType<M[P]> ? M : ThisParameterType<M[P]>
|
|
52
|
-
>,
|
|
51
|
+
callback: BeforeCallback<ArgsOf<M[P]>, ResultOf<M[P]>, SelfOf<M, M[P]>>,
|
|
53
52
|
options?: PatchOptions,
|
|
54
53
|
): () => void;
|
|
55
54
|
/**
|
|
@@ -62,36 +61,12 @@ declare function before<M extends PatchParent, P extends PropOf<M>>(
|
|
|
62
61
|
* @param options Patch options.
|
|
63
62
|
* @returns A function removing the patch.
|
|
64
63
|
*/
|
|
65
|
-
declare function instead
|
|
64
|
+
export declare function instead<M extends PatchParent, P extends PropOf<M>>(
|
|
66
65
|
parent: M,
|
|
67
66
|
method: P,
|
|
68
|
-
callback:
|
|
67
|
+
callback: InsteadCallback<ArgsOf<M[P]>, ResultOf<M[P]>, SelfOf<M, M[P]>>,
|
|
69
68
|
options?: PatchOptions,
|
|
70
69
|
): () => void;
|
|
71
|
-
declare function instead<M extends PatchParent, P extends PropOf<M>>(
|
|
72
|
-
parent: M,
|
|
73
|
-
method: P,
|
|
74
|
-
callback: PatchCallback<
|
|
75
|
-
M[P] extends (...args: infer Args) => any ? Args : any[],
|
|
76
|
-
M[P] extends (...args: any[]) => infer Res ? Res : any,
|
|
77
|
-
unknown extends ThisParameterType<M[P]> ? M : ThisParameterType<M[P]>
|
|
78
|
-
>,
|
|
79
|
-
options?: PatchOptions,
|
|
80
|
-
): () => void;
|
|
81
|
-
//#region src/patcher.d.ts
|
|
82
|
-
export declare const PATCH_SYMBOL: unique symbol;
|
|
83
|
-
export declare const patches: PatchedModule[];
|
|
84
|
-
export declare enum PatchType {
|
|
85
|
-
Before = 0,
|
|
86
|
-
Instead = 1,
|
|
87
|
-
After = 2,
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* @description Creates a patcher whose patches share default options, so they can be removed together.
|
|
91
|
-
* @param defaultOptions A caller id, or options merged into every patch; a caller id is generated if missing.
|
|
92
|
-
* @returns The scoped patcher.
|
|
93
|
-
*/
|
|
94
|
-
export declare function createPatcher(defaultOptions: string | PatchOptions): PatcherInstance;
|
|
95
70
|
/**
|
|
96
71
|
* @description Removes every patch.
|
|
97
72
|
*/
|
|
@@ -134,23 +109,205 @@ export interface PatchedModule {
|
|
|
134
109
|
original: AnyFunction & AnyConstructor;
|
|
135
110
|
patches: Record<PatchType, Set<Patch<any, any, any>>>;
|
|
136
111
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
112
|
+
/**
|
|
113
|
+
* An `after` callback, whose return value replaces the result unless it is `undefined`.
|
|
114
|
+
* @template Args The method's arguments.
|
|
115
|
+
* @template Res The method's result.
|
|
116
|
+
* @template Self The method's `this`.
|
|
117
|
+
*/
|
|
118
|
+
export type AfterCallback<Args extends unknown[], Res, Self> = (
|
|
119
|
+
ctx: AfterContext<Args, Res, Self>,
|
|
120
|
+
) => Res | void;
|
|
121
|
+
/**
|
|
122
|
+
* The context an `after` callback receives, with the result so far.
|
|
123
|
+
* @template Args The method's arguments.
|
|
124
|
+
* @template Res The method's result.
|
|
125
|
+
* @template Self The method's `this`.
|
|
126
|
+
*/
|
|
127
|
+
export type AfterContext<Args extends unknown[], Res, Self> = BeforeContext<Args, Res, Self> & {
|
|
128
|
+
result: Res;
|
|
129
|
+
};
|
|
143
130
|
export type AnyConstructor = {
|
|
144
131
|
new (...args: any): any;
|
|
145
132
|
};
|
|
146
133
|
export type AnyFunction = (...args: any[]) => any;
|
|
147
134
|
export type AnyObject = Record<any, any>;
|
|
135
|
+
/** The arguments a patch receives for method `F`: its parameters, or its constructor's for a class. */
|
|
136
|
+
export type ArgsOf<F> =
|
|
137
|
+
IsUntyped<F> extends true
|
|
138
|
+
? F[]
|
|
139
|
+
: F extends AnyFunction
|
|
140
|
+
? Parameters<F>
|
|
141
|
+
: F extends AnyConstructor
|
|
142
|
+
? ConstructorParameters<F>
|
|
143
|
+
: never;
|
|
144
|
+
/**
|
|
145
|
+
* A `before` callback, which can replace the arguments by returning an array.
|
|
146
|
+
* @template Args The method's arguments.
|
|
147
|
+
* @template Res The method's result.
|
|
148
|
+
* @template Self The method's `this`.
|
|
149
|
+
*/
|
|
150
|
+
export type BeforeCallback<Args extends unknown[], Res, Self> = (
|
|
151
|
+
ctx: BeforeContext<Args, Res, Self>,
|
|
152
|
+
) => [...Args] | void;
|
|
153
|
+
/**
|
|
154
|
+
* The context a `before` callback receives.
|
|
155
|
+
* @template Args The method's arguments.
|
|
156
|
+
* @template Res The method's result.
|
|
157
|
+
* @template Self The method's `this`.
|
|
158
|
+
*/
|
|
159
|
+
export type BeforeContext<Args extends unknown[], Res, Self> = {
|
|
160
|
+
/** The arguments of this call; a `before` callback can return a new array to replace them. */
|
|
161
|
+
args: Args;
|
|
162
|
+
/** The `this` the method was called with. */
|
|
163
|
+
this: Self;
|
|
164
|
+
/** The unpatched method; call it with `ctx.this` and `ctx.args` to run the original behavior. */
|
|
165
|
+
original: (...args: Args) => Res;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* An `instead` callback, whose return value becomes the result unless it is `undefined`.
|
|
169
|
+
* @template Args The method's arguments.
|
|
170
|
+
* @template Res The method's result.
|
|
171
|
+
* @template Self The method's `this`.
|
|
172
|
+
*/
|
|
173
|
+
export type InsteadCallback<Args extends unknown[], Res, Self> = (
|
|
174
|
+
ctx: InsteadContext<Args, Res, Self>,
|
|
175
|
+
) => Res | void;
|
|
176
|
+
/**
|
|
177
|
+
* The context an `instead` callback receives.
|
|
178
|
+
* @template Args The method's arguments.
|
|
179
|
+
* @template Res The method's result.
|
|
180
|
+
* @template Self The method's `this`.
|
|
181
|
+
*/
|
|
182
|
+
export type InsteadContext<Args extends unknown[], Res, Self> = BeforeContext<Args, Res, Self>;
|
|
183
|
+
/** Whether `T` is `any`, so a patch on an untyped method or component keeps loose types. */
|
|
184
|
+
export type IsUntyped<T> = 0 extends 1 & T ? true : false;
|
|
148
185
|
export type PatchMethod = string;
|
|
149
186
|
export type PatchParent = AnyFunction | AnyObject;
|
|
150
187
|
export type PropOf<M> = {
|
|
151
188
|
[K in keyof M]: M[K] extends AnyFunction | AnyConstructor ? Extract<K, string> : never;
|
|
152
189
|
}[keyof M];
|
|
190
|
+
/**
|
|
191
|
+
* An `after` callback, whose return value replaces the rendered tree unless it is `undefined`.
|
|
192
|
+
* @template P The component's props.
|
|
193
|
+
* @template Self The class instance rendering, or `undefined` for a function component.
|
|
194
|
+
*/
|
|
195
|
+
export type ReactAfterCallback<P, Self> = (ctx: ReactAfterContext<P, Self>) => React$1.ReactNode;
|
|
196
|
+
/**
|
|
197
|
+
* The context an `after` callback of `patcher.react` receives, with the rendered tree.
|
|
198
|
+
* @template P The component's props.
|
|
199
|
+
* @template Self The class instance rendering, or `undefined` for a function component.
|
|
200
|
+
*/
|
|
201
|
+
export type ReactAfterContext<P, Self> = ReactBeforeContext<P, Self> & {
|
|
202
|
+
/** What the component rendered, after earlier patches. */
|
|
203
|
+
result: React$1.ReactNode;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* A `before` callback, which can replace a function component's props by returning new ones.
|
|
207
|
+
* @template P The component's props.
|
|
208
|
+
* @template Self The class instance rendering, or `undefined` for a function component.
|
|
209
|
+
*/
|
|
210
|
+
export type ReactBeforeCallback<P, Self> = (ctx: ReactBeforeContext<P, Self>) => P | void;
|
|
211
|
+
/**
|
|
212
|
+
* The context a `patcher.react` callback receives.
|
|
213
|
+
* @template P The component's props.
|
|
214
|
+
* @template Self The class instance rendering, or `undefined` for a function component.
|
|
215
|
+
*/
|
|
216
|
+
export type ReactBeforeContext<P, Self> = {
|
|
217
|
+
/** The props of this render. */
|
|
218
|
+
props: P;
|
|
219
|
+
/** The class instance rendering, or `undefined` for a function component. */
|
|
220
|
+
this: Self;
|
|
221
|
+
/** Renders the unpatched component; a class component ignores `props`. */
|
|
222
|
+
original: (props?: P) => React$1.ReactNode;
|
|
223
|
+
};
|
|
224
|
+
/** The callback a React patch of `Kind` takes, typed with the component's props and `this`. */
|
|
225
|
+
export type ReactCallbackOf<Kind extends PatchType, P, Self> = Kind extends PatchType.Before
|
|
226
|
+
? ReactBeforeCallback<P, Self>
|
|
227
|
+
: Kind extends PatchType.Instead
|
|
228
|
+
? ReactInsteadCallback<P, Self>
|
|
229
|
+
: ReactAfterCallback<P, Self>;
|
|
230
|
+
/**
|
|
231
|
+
* An `instead` callback, whose return value is rendered in place of the component.
|
|
232
|
+
* @template P The component's props.
|
|
233
|
+
* @template Self The class instance rendering, or `undefined` for a function component.
|
|
234
|
+
*/
|
|
235
|
+
export type ReactInsteadCallback<P, Self> = (
|
|
236
|
+
ctx: ReactInsteadContext<P, Self>,
|
|
237
|
+
) => React$1.ReactNode;
|
|
238
|
+
/**
|
|
239
|
+
* The context an `instead` callback of `patcher.react` receives.
|
|
240
|
+
* @template P The component's props.
|
|
241
|
+
* @template Self The class instance rendering, or `undefined` for a function component.
|
|
242
|
+
*/
|
|
243
|
+
export type ReactInsteadContext<P, Self> = ReactBeforeContext<P, Self>;
|
|
244
|
+
/** One `patcher.react` hook: takes a `memo`, `forwardRef` or class component, or the object and key holding any component. */
|
|
245
|
+
export type ReactPatch<Kind extends PatchType> = {
|
|
246
|
+
<C extends ReactPatchTarget>(
|
|
247
|
+
component: C,
|
|
248
|
+
callback: ReactCallbackOf<Kind, ReactPropsOf<C>, ReactSelfOf<C>>,
|
|
249
|
+
options?: PatchOptions,
|
|
250
|
+
): () => void;
|
|
251
|
+
<M extends PatchParent, K extends Extract<keyof M, string>>(
|
|
252
|
+
parent: M,
|
|
253
|
+
key: K,
|
|
254
|
+
callback: ReactCallbackOf<Kind, ReactPropsOf<M[K]>, ReactSelfOf<M[K]>>,
|
|
255
|
+
options?: PatchOptions,
|
|
256
|
+
): () => void;
|
|
257
|
+
};
|
|
258
|
+
/** A component `patcher.react` finds the render of by itself: a `memo`, a `forwardRef` or a class. */
|
|
259
|
+
export type ReactPatchTarget =
|
|
260
|
+
| React$1.JSXElementConstructor<never>
|
|
261
|
+
| {
|
|
262
|
+
$$typeof: symbol;
|
|
263
|
+
};
|
|
264
|
+
/** The `patcher.react` namespace: `before`, `instead` and `after` for React components. */
|
|
265
|
+
export type ReactPatcher = {
|
|
266
|
+
/** Runs a callback before a component renders; it can return new props for a function component. */
|
|
267
|
+
before: ReactPatch<PatchType.Before>;
|
|
268
|
+
/** Renders a callback's return value in place of a component; `ctx.original()` renders the component. */
|
|
269
|
+
instead: ReactPatch<PatchType.Instead>;
|
|
270
|
+
/** Runs a callback after a component renders; its return value replaces the tree unless it is `undefined`. */
|
|
271
|
+
after: ReactPatch<PatchType.After>;
|
|
272
|
+
};
|
|
273
|
+
/** The props component `C` renders with. */
|
|
274
|
+
export type ReactPropsOf<C> =
|
|
275
|
+
IsUntyped<C> extends true
|
|
276
|
+
? C
|
|
277
|
+
: C extends React$1.JSXElementConstructor<infer P>
|
|
278
|
+
? P
|
|
279
|
+
: C extends {
|
|
280
|
+
type: infer Inner;
|
|
281
|
+
}
|
|
282
|
+
? ReactPropsOf<Inner>
|
|
283
|
+
: C extends {
|
|
284
|
+
render: (props: infer P, ...rest: never[]) => React$1.ReactNode;
|
|
285
|
+
}
|
|
286
|
+
? P
|
|
287
|
+
: never;
|
|
288
|
+
/** The `this` component `C` renders with: a class component's instance, else `undefined`. */
|
|
289
|
+
export type ReactSelfOf<C> =
|
|
290
|
+
IsUntyped<C> extends true
|
|
291
|
+
? C
|
|
292
|
+
: C extends abstract new (...args: never[]) => infer Instance
|
|
293
|
+
? Instance
|
|
294
|
+
: C extends {
|
|
295
|
+
type: infer Inner;
|
|
296
|
+
}
|
|
297
|
+
? ReactSelfOf<Inner>
|
|
298
|
+
: undefined;
|
|
299
|
+
/** The result a patch receives for method `F`: its return value, or an instance for a class. */
|
|
300
|
+
export type ResultOf<F> =
|
|
301
|
+
IsUntyped<F> extends true
|
|
302
|
+
? F
|
|
303
|
+
: F extends AnyFunction
|
|
304
|
+
? ReturnType<F>
|
|
305
|
+
: F extends AnyConstructor
|
|
306
|
+
? InstanceType<F>
|
|
307
|
+
: never;
|
|
308
|
+
/** The `this` a patch receives: the method's declared `this`, else the object `M` holding it. */
|
|
309
|
+
export type SelfOf<M, F> = unknown extends ThisParameterType<F> ? M : ThisParameterType<F>;
|
|
153
310
|
|
|
154
|
-
export {
|
|
311
|
+
export { PatchType$1 as PatchType };
|
|
155
312
|
|
|
156
313
|
export {};
|
package/src/plugins.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Auto-generated by generate-plugin-sdk.ts - DO NOT EDIT
|
|
2
|
+
|
|
3
|
+
import type { AddonHandle, PushedManifest } from './_internal';
|
|
4
|
+
/** Stops a running plugin without changing its enabled state. */
|
|
5
|
+
declare const stop$1: (id: string) => void | Promise<void>;
|
|
6
|
+
/** Disables a plugin and stops it. */
|
|
7
|
+
export declare const disable: (id: string) => void;
|
|
8
|
+
/** Enables a plugin and starts it. */
|
|
9
|
+
export declare const enable: (id: string) => void | Promise<void>;
|
|
10
|
+
/** Every installed plugin, keyed by id. */
|
|
11
|
+
export declare const entities: ReadonlyMap<PropertyKey, AddonHandle>;
|
|
12
|
+
/** The error each plugin that failed to load or start threw, keyed by id. */
|
|
13
|
+
export declare const errors: ReadonlyMap<PropertyKey, Error>;
|
|
14
|
+
/** Reads one installed plugin by id. */
|
|
15
|
+
export declare const get: (id: string) => AddonHandle | undefined;
|
|
16
|
+
/** Lists every installed plugin. */
|
|
17
|
+
export declare const getAll: () => AddonHandle[];
|
|
18
|
+
/** Installs a plugin from its manifest URL. */
|
|
19
|
+
export declare const install: (url: string, digest?: string) => Promise<AddonHandle | undefined>;
|
|
20
|
+
/** Reports whether a plugin is enabled. */
|
|
21
|
+
export declare const isEnabled: (id: string) => boolean;
|
|
22
|
+
/** Swaps a plugin's bundle in place, keeping its enabled state. */
|
|
23
|
+
export declare const reload: (
|
|
24
|
+
id: string,
|
|
25
|
+
bundle: string,
|
|
26
|
+
manifest: PushedManifest,
|
|
27
|
+
bytecode?: string,
|
|
28
|
+
) => Promise<ReloadResult>;
|
|
29
|
+
/** Starts a plugin without changing its enabled state. */
|
|
30
|
+
export declare const start: (id: string) => void | Promise<void>;
|
|
31
|
+
/** How long each plugin's last start took, in milliseconds, keyed by id. */
|
|
32
|
+
export declare const startDurations: ReadonlyMap<string, number>;
|
|
33
|
+
/** Enables a disabled plugin, or disables an enabled one. */
|
|
34
|
+
export declare const toggle: (id: string) => void;
|
|
35
|
+
/** Stops and removes an installed plugin. */
|
|
36
|
+
export declare const uninstall: (id: string) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* @description Checks for updates, then applies this plugin's pending update.
|
|
39
|
+
* @param id The plugin's id.
|
|
40
|
+
* @returns Whether the plugin now runs a newer version.
|
|
41
|
+
*/
|
|
42
|
+
export declare function update(id: string): Promise<boolean>;
|
|
43
|
+
/** The outcome of an addon reload: success, or failure carrying the recorded error. */
|
|
44
|
+
export type ReloadResult =
|
|
45
|
+
| {
|
|
46
|
+
ok: true;
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
ok: false;
|
|
50
|
+
error: Error;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { stop$1 as stop };
|
|
54
|
+
|
|
55
|
+
export {};
|
package/src/settings.d.ts
CHANGED
|
@@ -2,29 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
export type { SettingsEntry } from './_internal';
|
|
4
4
|
import type { SettingsEntry } from './_internal';
|
|
5
|
-
import * as
|
|
6
|
-
import { ComponentType } from 'react';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
5
|
+
import * as React$1 from 'react';
|
|
6
|
+
import { ComponentType, ReactNode } from 'react';
|
|
7
|
+
/**
|
|
8
|
+
* @description Returns the current registry of settings entries.
|
|
9
|
+
* @returns A record of entry key to its {@link SettingsEntry}.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSections(): Record<string, SettingsEntry>;
|
|
13
12
|
/**
|
|
14
13
|
* @description Registers one or more settings entries into the section registry, warning on key collisions.
|
|
15
14
|
* @param entries The settings entries to register.
|
|
16
15
|
*/
|
|
17
|
-
export declare function
|
|
16
|
+
export declare function registerSection(...entries: SettingsEntry[]): void;
|
|
18
17
|
/**
|
|
19
18
|
* @description Removes one or more settings entries from the section registry by key.
|
|
20
19
|
* @param keys The entry keys to remove.
|
|
21
20
|
*/
|
|
22
|
-
export declare function
|
|
23
|
-
/**
|
|
24
|
-
* @description Returns the current registry of settings entries.
|
|
25
|
-
* @returns A record of entry key to its {@link SettingsEntry}.
|
|
26
|
-
*/
|
|
27
|
-
export declare function sections(): Record<string, SettingsEntry>;
|
|
28
|
-
export { _default as default };
|
|
29
|
-
|
|
21
|
+
export declare function removeSection(...keys: string[]): void;
|
|
30
22
|
export {};
|