@unbound-app/api 0.11.0 → 1.1.1

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.
Files changed (72) hide show
  1. package/ambient/image-modules.d.ts +58 -0
  2. package/package.json +27 -4
  3. package/src/_internal.d.ts +2775 -139
  4. package/src/{utils.d.ts → _types.d.ts} +10 -0
  5. package/src/assets.d.ts +64 -26
  6. package/src/builtins.d.ts +17 -0
  7. package/src/commands.d.ts +101 -25
  8. package/src/dialogs.d.ts +90 -25
  9. package/src/flux.d.ts +317 -0
  10. package/src/fonts.d.ts +51 -0
  11. package/src/fs.d.ts +15 -24
  12. package/src/global.d.ts +173 -11
  13. package/src/i18n.d.ts +33 -31
  14. package/src/iconPacks.d.ts +43 -0
  15. package/src/index.d.ts +14 -0
  16. package/src/marketplace.d.ts +50 -0
  17. package/src/metro/api.d.ts +8 -0
  18. package/src/metro/common.d.ts +34 -5
  19. package/src/metro/components.d.ts +34 -25
  20. package/src/metro/filters.d.ts +31 -16
  21. package/src/metro/index.d.ts +26079 -83
  22. package/src/metro/stores.d.ts +5 -0
  23. package/src/native.d.ts +77 -5
  24. package/src/patcher.d.ts +214 -57
  25. package/src/plugins.d.ts +55 -0
  26. package/src/settings.d.ts +8 -16
  27. package/src/shims.d.ts +5 -0
  28. package/src/storage.d.ts +80 -224
  29. package/src/sync.d.ts +51 -0
  30. package/src/themes.d.ts +43 -0
  31. package/src/toasts.d.ts +62 -9
  32. package/src/ui.d.ts +650 -0
  33. package/src/updates.d.ts +25 -0
  34. package/src/utils/index.d.ts +53 -0
  35. package/src/utils/react/index.d.ts +82 -0
  36. package/testing/fake-api.ts +256 -0
  37. package/testing/fake-components.ts +183 -0
  38. package/testing/fake-feedback.ts +258 -0
  39. package/testing/fake-fs.ts +54 -0
  40. package/testing/fake-java.ts +513 -0
  41. package/testing/fake-locales.ts +85 -0
  42. package/testing/fake-metro.ts +346 -0
  43. package/testing/fake-native-bridge.ts +98 -0
  44. package/testing/fake-native.ts +211 -0
  45. package/testing/fake-objc.ts +388 -0
  46. package/testing/fake-plugins.ts +176 -0
  47. package/testing/fake-react-native-modules.ts +362 -0
  48. package/testing/fake-react-native.ts +180 -0
  49. package/testing/fake-react.ts +54 -0
  50. package/testing/fake-settings-panel.ts +173 -0
  51. package/testing/fake-settings.ts +428 -0
  52. package/testing/fake-timers.ts +74 -0
  53. package/testing/fake-utils.ts +216 -0
  54. package/testing/icu-format.ts +132 -0
  55. package/testing/icu-parse.ts +277 -0
  56. package/testing/index.ts +42 -0
  57. package/testing/install-addon-globals.ts +260 -0
  58. package/testing/listener-registry.ts +39 -0
  59. package/testing/memory-storage.ts +149 -0
  60. package/testing/plugin-files.ts +155 -0
  61. package/testing/plugin-lifecycle.ts +149 -0
  62. package/testing/plugin-types.ts +34 -0
  63. package/testing/preset.ts +263 -0
  64. package/testing/react-patcher.ts +154 -0
  65. package/testing/react-value.ts +3 -0
  66. package/testing/recorders.ts +183 -0
  67. package/testing/recording-patcher.ts +173 -0
  68. package/testing/render.ts +84 -0
  69. package/testing/session.ts +77 -0
  70. package/testing/test-node.ts +163 -0
  71. package/testing/test-renderer.ts +753 -0
  72. package/testing/unfrozen-elements.ts +49 -0
@@ -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
@@ -16,17 +16,20 @@ export type {
16
16
  NativeFFITypeName,
17
17
  NativeFabricBridge,
18
18
  NativeFabricFrame,
19
+ NativeFabricMountOptions,
19
20
  NativeFabricSize,
20
21
  NativeFabricSurface,
21
22
  NativeHandle,
22
23
  NativeHookContext,
23
24
  NativeHookHandlers,
24
25
  NativeHookOptions,
26
+ NativeHookPayload,
25
27
  NativeHookToken,
26
28
  NativeJavaArgument,
27
29
  NativeJavaAssociationKey,
28
30
  NativeJavaBatchOperation,
29
31
  NativeJavaBridge,
32
+ NativeJavaCallPlan,
30
33
  NativeJavaClassDescription,
31
34
  NativeJavaFieldDescription,
32
35
  NativeJavaHandle,
@@ -39,6 +42,7 @@ export type {
39
42
  NativeJavaReference,
40
43
  NativeJavaValue,
41
44
  NativeObjCBridge,
45
+ NativeObjCCallPlan,
42
46
  NativeObjectHandle,
43
47
  NativePlatformBridge,
44
48
  NativePluginBridge,
@@ -53,6 +57,10 @@ export type {
53
57
  NativeSerializableObject,
54
58
  NativeStruct,
55
59
  NativeThreadPolicy,
60
+ NativeUIArgument,
61
+ NativeUIBridge,
62
+ NativeUICallback,
63
+ NativeUIScope,
56
64
  NativeViewSearchOptions,
57
65
  NativeViewSnapshotNode,
58
66
  NativeViewSnapshotOptions,
@@ -65,33 +73,44 @@ import type {
65
73
  NativeResourceCounts,
66
74
  } from './_internal';
67
75
  import * as React$1 from 'react';
68
- import { ReactNode } 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. */
69
78
  declare const NativePlatform$1: NativePlatformBridge | undefined;
70
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. */
71
81
  export declare class NativePluginCapabilityError extends Error {
82
+ /** A stable code to match on instead of the message. */
72
83
  readonly code = 'NATIVE_PLUGIN_CAPABILITY_DENIED';
84
+ /** The Capability that was missing or refused. */
73
85
  readonly capability: NativePluginCapability;
74
86
  constructor(capability: NativePluginCapability);
75
87
  }
88
+ /** Thrown when native work is called through a plugin's scope after the scope was disposed, such as after the plugin stopped. */
76
89
  export declare class NativePluginDisposedError extends Error {
90
+ /** A stable code to match on instead of the message. */
77
91
  readonly code = 'NATIVE_PLUGIN_SCOPE_DISPOSED';
78
92
  constructor();
79
93
  }
80
- export declare class NativePluginPlatformError extends Error {
81
- readonly code = 'NATIVE_PLUGIN_PLATFORM_UNSUPPORTED';
82
- constructor();
83
- }
94
+ /** Thrown when the loader does not provide the native plugin bridge, or the part of it a call needs. */
84
95
  export declare class NativePluginUnavailableError extends Error {
96
+ /** A stable code to match on instead of the message. */
85
97
  readonly code = 'NATIVE_PLUGIN_UNAVAILABLE';
86
98
  }
99
+ /** Thrown when the host platform is not one the addon runs on, by its manifest or the handlers given to `definePlatform`. */
87
100
  export declare class NativePluginUnsupportedPlatformError extends Error {
101
+ /** A stable code to match on instead of the message. */
88
102
  readonly code = 'NATIVE_PLUGIN_PLATFORM_EXCLUDED';
103
+ /** The platforms the addon does run on. */
89
104
  readonly platforms: readonly NativePluginPlatform[];
90
105
  constructor(platforms: readonly NativePluginPlatform[], platform: string);
91
106
  }
107
+ /** Thrown when the native plugin API is older than the manifest's `minNativePluginApi`. */
92
108
  export declare class NativePluginVersionError extends Error {
109
+ /** A stable code to match on instead of the message. */
93
110
  readonly code = 'NATIVE_PLUGIN_API_VERSION_UNSUPPORTED';
111
+ /** The native plugin API version the loader provides. */
94
112
  readonly installedApi: string;
113
+ /** The manifest's `minNativePluginApi`. */
95
114
  readonly requiredApi: string;
96
115
  constructor(requiredApi: string, installedApi: string);
97
116
  }
@@ -101,6 +120,13 @@ export declare const BundleInfo: BundleInfoType;
101
120
  export declare const BundleManager: DCDBundleManagerType;
102
121
  /** The resolved native device module, exposing hardware and OS details. */
103
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;
104
130
  /**
105
131
  * @description Resolves the first available native module matching any of the given names, checking both `NativeModules` and the `TurboModuleRegistry`.
106
132
  * @template T The type of the resolved native module.
@@ -118,41 +144,71 @@ export declare function getNativeResources(): NativeResourceCounts | undefined;
118
144
  * @returns The runtime property map, or an empty object when Hermes internals are unavailable.
119
145
  */
120
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;
121
154
  /**
122
155
  * @description Persists pending settings to storage, then reloads the native bundle.
123
156
  */
124
157
  export declare function reload(): Promise<void>;
125
158
  /** Build and release metadata reported by the native client info module. */
126
159
  export type BundleInfoType = {
160
+ /** Discord's app version, shown in Unbound's settings beside `Build`. */
127
161
  Version: string;
162
+ /** The Discord release channel the app was built for. */
128
163
  ReleaseChannel: string;
164
+ /** Reported by Discord's native client info module; Unbound does not read it. */
129
165
  Manifest: string;
166
+ /** Discord's build number; Unbound's Metro cache is invalidated when it changes. */
130
167
  Build: string;
168
+ /** The Sentry DSN Discord reports crashes to. */
131
169
  SentryDsn: string;
170
+ /** The device's vendor identifier, which Discord sends in its analytics properties. */
132
171
  DeviceVendorID: string;
172
+ /** The build of the over-the-air JavaScript bundle, reported by Discord's native client info module. */
133
173
  OTABuild: string;
174
+ /** The Sentry DSN Discord reports crashes to on staff builds. */
134
175
  SentryStaffDsn: string;
176
+ /** The app's bundle identifier. */
135
177
  Identifier: string;
178
+ /** The Sentry DSN Discord reports crashes to on alpha and beta builds. */
136
179
  SentryAlphaBetaDsn: string;
137
180
  };
138
181
  /** The native `BundleUpdaterManager` module surface for OTA updates and reloading the bundle. */
139
182
  export type DCDBundleManagerType = {
183
+ /** Reports whether the first OTA bundle has been downloaded; Discord does not document what it resolves to. */
140
184
  getInitialBundleDownloaded: UndocumentedNativeMethod;
185
+ /** Reports whether the first OTA update check has run; Discord does not document what it resolves to. */
141
186
  getInitialOtaUpdateChecked: UndocumentedNativeMethod;
187
+ /** Checks for an OTA bundle update, then reloads the app. */
142
188
  checkForUpdateAndReload(): void;
189
+ /** Reloads the JavaScript bundle; {@link reload} persists settings first, so prefer it. */
143
190
  reload(): void;
191
+ /** Reads the directory OTA bundles are stored in; Discord does not document what it resolves to. */
144
192
  getOtaRootPath: UndocumentedNativeMethod;
193
+ /** Reads the contents of Discord's build override cookie; Discord does not document what it resolves to. */
145
194
  getBuildOverrideCookieContents: UndocumentedNativeMethod;
195
+ /** Sets the build override cookie header; Discord does not document its argument or result. */
146
196
  setBuildOverrideCookieHeader: UndocumentedNativeMethod;
197
+ /** Reads the OTA manifest info; Discord does not document what it resolves to. */
147
198
  getManifestInfo: UndocumentedNativeMethod;
199
+ /** React Native event-emitter hook: tells the native module a listener for `eventName` was added. */
148
200
  addListener(eventName: string): void;
201
+ /** React Native event-emitter hook: tells the native module `count` listeners were removed. */
149
202
  removeListeners(count: number): void;
150
203
  };
151
204
  /** The constant directory paths exposed by the native `DCDFileManager`. */
152
205
  export type DCDFileManagerConstants = {
206
+ /** The absolute path to the app's cache directory. */
153
207
  CacheDirPath: string;
208
+ /** The absolute path to the app's documents directory, where Unbound keeps its files. */
154
209
  DocumentsDirPath: string;
155
210
  };
211
+ /** How the native file manager encodes file contents: UTF-8 text or base64 for binary data. */
156
212
  export type DCDFileManagerEncoding = 'utf-8' | 'utf8' | 'base64';
157
213
  /** The native `DCDFileManager` module surface for reading, writing, and inspecting files. */
158
214
  export type DCDFileManagerType = {
@@ -173,20 +229,36 @@ export type DCDFileManagerType = {
173
229
  } & DCDFileManagerConstants;
174
230
  /** Hardware and OS details reported by the native device module. */
175
231
  export type DeviceInfoType = {
232
+ /** Whether the system task bar is shown, as Discord's native device module reports it. */
176
233
  isTaskBarEnabled: boolean;
234
+ /** The maximum CPU frequency as a numeric string; empty when unknown. */
177
235
  maxCpuFreq: string;
236
+ /** The system-on-chip's name. */
178
237
  socName: string;
238
+ /** The device model; `iPad` on an iPad, which Discord checks to detect iPadOS. */
179
239
  deviceModel: string;
240
+ /** Whether the device is a tablet. */
180
241
  isTablet: boolean;
242
+ /** Whether the system uses gesture navigation instead of navigation buttons. */
181
243
  isGestureNavigationEnabled: boolean;
244
+ /** The device's product name, as Discord's native device module reports it. */
182
245
  deviceProduct: string;
246
+ /** The operating system version. */
183
247
  systemVersion: string;
248
+ /** The device's manufacturer. */
184
249
  deviceManufacturer: string;
250
+ /** The device's brand. */
185
251
  deviceBrand: string;
252
+ /** The device's RAM size as a numeric string; empty when unknown. */
186
253
  ramSize: string;
254
+ /** The device's name, as Discord's native device module reports it. */
187
255
  device: string;
188
256
  };
257
+ /** What `HermesInternal.getRuntimeProperties()` reports; empty when the engine is not Hermes. */
189
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. */
190
262
  export type UndocumentedNativeMethod = () => Promise<unknown>;
191
263
  export { NativePlatform$1 as NativePlatform };
192
264
 
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$1<M extends PatchParent, P extends PropOf<M>>(
32
+ export declare function after<M extends PatchParent, P extends PropOf<M>>(
14
33
  parent: M,
15
34
  method: P,
16
- callback: Parameters<typeof before<M, P>>[2],
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$1<M extends PatchParent, P extends PropOf<M>>(
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: PatchCallback<
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$1<M extends PatchParent, P extends PropOf<M>>(
64
+ export declare function instead<M extends PatchParent, P extends PropOf<M>>(
66
65
  parent: M,
67
66
  method: P,
68
- callback: Parameters<typeof before<M, P>>[2],
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
- export interface PatcherInstance {
138
- instead: typeof instead;
139
- before: typeof before;
140
- after: typeof after;
141
- unpatchAll: () => void;
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 { after$1 as after, before$1 as before, instead$1 as instead };
311
+ export { PatchType$1 as PatchType };
155
312
 
156
313
  export {};
@@ -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
@@ -3,28 +3,20 @@
3
3
  export type { SettingsEntry } from './_internal';
4
4
  import type { SettingsEntry } from './_internal';
5
5
  import * as React$1 from 'react';
6
- import { ComponentType } from 'react';
7
-
8
- declare const _default: {
9
- registerSettings: typeof registerSettings;
10
- removeSettings: typeof removeSettings;
11
- sections: typeof sections;
12
- };
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 registerSettings(...entries: SettingsEntry[]): void;
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 removeSettings(...keys: string[]): void;
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 {};
package/src/shims.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ // Auto-generated by generate-plugin-sdk.ts - DO NOT EDIT
2
+
3
+ /** Discord's copy of each library its bundle ships, by package name. A built plugin reads its library imports here. */
4
+ export declare const libraries: Record<string, any>;
5
+ export {};