@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.
Files changed (72) hide show
  1. package/ambient/image-modules.d.ts +58 -0
  2. package/package.json +30 -5
  3. package/src/_internal.d.ts +6110 -462
  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 +331 -0
  8. package/src/dialogs.d.ts +134 -0
  9. package/src/flux.d.ts +317 -0
  10. package/src/fonts.d.ts +51 -0
  11. package/src/fs.d.ts +16 -26
  12. package/src/global.d.ts +514 -31
  13. package/src/i18n.d.ts +33 -31
  14. package/src/iconPacks.d.ts +43 -0
  15. package/src/index.d.ts +16 -0
  16. package/src/marketplace.d.ts +50 -0
  17. package/src/metro/api.d.ts +10 -0
  18. package/src/metro/common.d.ts +34 -5
  19. package/src/metro/components.d.ts +100 -16
  20. package/src/metro/filters.d.ts +31 -16
  21. package/src/metro/index.d.ts +26097 -82
  22. package/src/metro/stores.d.ts +5 -0
  23. package/src/native.d.ts +123 -3
  24. package/src/patcher.d.ts +214 -57
  25. package/src/plugins.d.ts +55 -0
  26. package/src/settings.d.ts +9 -17
  27. package/src/shims.d.ts +5 -0
  28. package/src/storage.d.ts +80 -223
  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
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 {};
package/src/storage.d.ts CHANGED
@@ -1,253 +1,110 @@
1
1
  // Auto-generated by generate-plugin-sdk.ts - DO NOT EDIT
2
2
 
3
- import type { PredicateResult, Widen } from './utils';
4
- import type { SettingsValue } from './_internal';
5
- declare class EventEmitter<EventMap extends DefaultEventMap = DefaultEventMap> {
6
- events: EventCollections<EventMap>;
7
- onceEvents: OnceCollections<EventMap>;
8
- _symbolKeys: Set<symbol>;
9
- maxListeners: number;
10
- boundFuncs: undefined | Map<Listener, Listener>;
11
- emit: <EventKey extends keyof EventMap>(
12
- event: EventKey,
13
- ...args: Parameters<EventMap[EventKey]>
14
- ) => boolean;
15
- on: <EventKey extends keyof EventMap = string>(
16
- event: EventKey,
17
- listener: EventMap[EventKey],
18
- ) => this;
19
- once: <EventKey extends keyof EventMap = string>(
20
- event: EventKey,
21
- listener: EventMap[EventKey],
22
- ) => this;
23
- addListener: <EventKey extends keyof EventMap = string>(
24
- event: EventKey,
25
- listener: EventMap[EventKey],
26
- argsNum?: ArgsNum<EventMap[EventKey]>,
27
- ) => this;
28
- removeListener: <EventKey extends keyof EventMap = string>(
29
- event: EventKey,
30
- listener: EventMap[EventKey],
31
- ) => this;
32
- hasListeners: <EventKey extends keyof EventMap = string>(event: EventKey) => boolean;
33
- prependListener: <EventKey extends keyof EventMap = string>(
34
- event: EventKey,
35
- listener: EventMap[EventKey],
36
- ) => this;
37
- prependOnceListener: <EventKey extends keyof EventMap = string>(
38
- event: EventKey,
39
- listener: EventMap[EventKey],
40
- ) => this;
41
- off: <EventKey extends keyof EventMap = string>(
42
- event: EventKey,
43
- listener: EventMap[EventKey],
44
- ) => this;
45
- removeAllListeners: <EventKey extends keyof EventMap = string>(event?: EventKey) => this;
46
- setMaxListeners: (n: number) => this;
47
- getMaxListeners: () => number;
48
- listeners: <EventKey extends keyof EventMap = string>(event: EventKey) => EventMap[EventKey][];
49
- rawListeners: <EventKey extends keyof EventMap = string>(
50
- event: EventKey,
51
- ) => EventMap[EventKey][];
52
- eventNames: () => Array<string | symbol>;
53
- listenerCount: <EventKey extends keyof EventMap = string>(type: EventKey) => number;
54
- addListenerBound: <EventKey extends keyof EventMap = string>(
55
- event: EventKey,
56
- listener: EventMap[EventKey],
57
- bindTo?: unknown,
58
- argsNum?: ArgsNum<EventMap[EventKey]>,
59
- ) => this;
60
- removeListenerBound: <EventKey extends keyof EventMap = string>(
61
- event: EventKey,
62
- listener: EventMap[EventKey],
63
- ) => this;
64
- /**
65
- * @description Creates an emitter with no listeners.
66
- */
67
- constructor();
68
- get _eventsCount(): number;
69
- }
70
- declare class TaskCollection<Func extends Listener = Listener> {
71
- argsNum: number;
72
- _tasks: Tasks<Func>;
73
- length: number;
74
- call: (...args: Parameters<Func>) => void;
75
- /**
76
- * @description Creates a collection holding a single listener.
77
- * @param argsNum How many arguments each listener receives when more than one is registered.
78
- * @param task The first listener.
79
- */
80
- constructor(argsNum: number, task: Func);
81
- push(task: Func): void;
82
- insert(index: number, task: Func): void;
83
- removeLast(task: Func): void;
84
- growArgsNum(argsNum: number): void;
85
- rebuild(): void;
86
- tasksAsArray(): Func[];
87
- }
88
- declare const _default: {
89
- addListener: typeof addListener;
90
- get: typeof get;
91
- getStore: typeof getStore;
92
- off: <EventKey extends keyof EventMap = string>(
93
- event: EventKey,
94
- listener: EventMap[EventKey],
95
- ) => EventEmitter<EventMap>;
96
- on: <EventKey extends keyof EventMap = string>(
97
- event: EventKey,
98
- listener: EventMap[EventKey],
99
- ) => EventEmitter<EventMap>;
100
- persist: typeof persist;
101
- remove: typeof remove;
102
- removeListener: typeof removeListener;
103
- set: typeof set;
104
- useSettingsStore: typeof useSettingsStore;
105
- };
106
- export declare const off: <EventKey extends keyof EventMap = string>(
107
- event: EventKey,
108
- listener: EventMap[EventKey],
109
- ) => EventEmitter<EventMap>;
110
- export declare const on: <EventKey extends keyof EventMap = string>(
111
- event: EventKey,
112
- listener: EventMap[EventKey],
113
- ) => EventEmitter<EventMap>;
3
+ export type { SettingsSchema } from './_internal';
4
+ import type { PredicateResult, Widen } from './_types';
5
+ import type { SettingValue, SettingsObject, SettingsSchema, SettingsValue } from './_internal';
6
+ /**
7
+ * @description Binds a settings schema to a Bucket: reads apply defaults and writes are validated against the schema.
8
+ * Plugins reach it through `@unbound-app/settings`, which the build generates from their settings.ts.
9
+ * @param schema The settings schema.
10
+ * @param name The Bucket name. A plugin may omit it to use its own Bucket.
11
+ * @returns The settings, their hook and their reset.
12
+ * @throws When `name` is omitted outside a plugin.
13
+ */
14
+ export declare function define(schema: SettingsSchema, name?: string): DefinedSettings;
15
+ /**
16
+ * @description Returns the Bucket with the given name. The name is the key the Bucket is saved under on disk.
17
+ * @param name The Bucket name. A plugin may omit it to get its own Bucket, named after its id.
18
+ * @returns The Bucket, with every operation bound to `name`.
19
+ * @throws When `name` is omitted outside a plugin.
20
+ */
21
+ export declare function getBucket(name?: string): Bucket;
114
22
  /**
115
23
  * @description Registers a callback invoked on every settings change matching the predicate.
116
- * @param predicate Decides whether a given change should fire the callback.
24
+ * @param predicate Decides whether a given change should fire the callback. The payload names the Bucket in `store`.
117
25
  * @param callback Invoked with the payload of each matching change.
118
26
  * @returns A function that removes the listener.
119
27
  */
120
- export declare function addListener(
121
- predicate: (payload: SettingsPayload) => PredicateResult,
28
+ export declare function onChange(
29
+ predicate: SettingsPredicate,
122
30
  callback: (payload: SettingsPayload) => void,
123
31
  ): () => void;
124
32
  /**
125
- * @description Removes an entire store and all of its keys, and emits `changed` and `cleared`.
126
- * @param store The store to clear.
127
- */
128
- export declare function clear(store: string): void;
129
- /**
130
- * @description Reads a value from a store by dot-separated key path, falling back to a default when absent.
131
- * @template T The type of the default value.
132
- * @param store The store to read from.
133
- * @param key The dot-separated key path within the store.
134
- * @param def The value to return when the key is not set.
135
- * @returns The stored value, or `def` if the key path is not present.
136
- */
137
- export declare function get<T>(store: string, key: string, def: T): Widen<T>;
138
- /**
139
- * @description Builds a store-scoped facade binding every settings operation to a single store name.
140
- * @param store The store name to scope every operation to.
141
- * @returns An object exposing `get`, `set`, `toggle`, `remove`, `clear`, `useSettingsStore`, and `addListener` bound to the store.
142
- */
143
- export declare function getStore(store: string): {
144
- set: (key: string, value: SettingsValue) => void;
145
- get: <T>(key: string, def: T) => Widen<T>;
146
- toggle: (key: string, def: boolean) => void;
147
- remove: (key: string) => void;
148
- clear: () => void;
149
- useSettingsStore: (predicate?: (payload: SettingsPayload) => PredicateResult) => {
150
- set: (key: string, value: SettingsValue) => void;
151
- get: <T>(key: string, def: T) => Widen<T>;
152
- toggle: (key: string, def: boolean) => void;
153
- remove: (key: string) => void;
154
- };
155
- addListener: (
156
- predicate: (payload: SettingsPayload) => PredicateResult,
157
- callback: (payload: SettingsPayload) => void,
158
- ) => () => EventEmitter<EventMap>;
159
- };
160
- /**
161
- * @description Serialises the current settings and writes them to disk.
162
- * @returns A promise that resolves once the settings file has been written.
33
+ * @description Saves the settings changed since the last call. Each change already reached the loader when it was made.
34
+ * @returns A promise that resolves once the loader has saved them.
163
35
  */
164
36
  export declare function persist(): Promise<void>;
165
37
  /**
166
- * @description Deletes a top-level key from a store, dropping the store entirely if it becomes empty, and emits `changed` and `removed`.
167
- * @param store The store to remove the key from.
168
- * @param key The key to delete.
169
- */
170
- export declare function remove(store: string, key: string): void;
171
- /**
172
- * @description Removes a previously registered settings change listener.
173
- * @param callback The listener to remove.
38
+ * @description Reads every Bucket at once. Most callers should read single keys, which stay in native code.
39
+ * @param options Set `includeSecrets` to read `displayAs: 'secret'` settings as they are; otherwise they are masked.
40
+ * @returns Every Bucket by name.
174
41
  */
175
- export declare function removeListener(callback: (payload: SettingsPayload) => void): void;
42
+ export declare function snapshot({ includeSecrets }?: { includeSecrets?: boolean }): SettingsStores;
176
43
  /**
177
- * @description Writes a value into a store at a dot-separated key path, creating intermediate objects, and emits `changed` and `set`.
178
- * @param store The store to write to.
179
- * @param key The dot-separated key path within the store.
180
- * @param value The value to store.
44
+ * @description React hook that re-renders the component whenever a matching change occurs in the Bucket.
45
+ * @param name The Bucket to subscribe to.
46
+ * @param predicate Optional filter deciding which changes trigger a re-render.
47
+ * @returns The Bucket, with every operation bound to `name`.
181
48
  */
182
- export declare function set(store: string, key: string, value: SettingsValue): void;
49
+ export declare function useBucket(name: string, predicate?: SettingsPredicate): Bucket;
183
50
  /**
184
- * @description Flips a boolean value at a key path against its current (or default) value, and emits `toggled`.
185
- * @param store The store to write to.
186
- * @param key The dot-separated key path within the store.
187
- * @param def The value to assume when the key is not yet set.
51
+ * @description React hook that selects from a Bucket, re-rendering only when the selection changes.
52
+ * @template T The value the selector returns.
53
+ * @param name The Bucket to read.
54
+ * @param selector Reads the value from the Bucket.
55
+ * @param isEqual Decides whether a new selection equals the last one, which skips the re-render. Defaults to `Object.is`.
56
+ * @returns The selector's latest value.
188
57
  */
189
- export declare function toggle(store: string, key: string, def: boolean): void;
190
- /**
191
- * @description React hook that re-renders the component whenever a matching change occurs in the store.
192
- * @param store The store to subscribe to.
193
- * @param predicate Optional filter deciding which changes trigger a re-render.
194
- * @returns An object exposing `get`, `set`, `toggle`, and `remove` bound to the store.
195
- */
196
- export declare function useSettingsStore(
197
- store: string,
198
- predicate?: (payload: SettingsPayload) => PredicateResult,
199
- ): {
200
- set: (key: string, value: SettingsValue) => void;
58
+ export declare function useSetting<T>(
59
+ name: string,
60
+ selector: (bucket: Bucket) => T,
61
+ isEqual?: (previous: T, next: T) => boolean,
62
+ ): T;
63
+ /** A Bucket: a named, persisted group of settings. Keys are dot-separated paths. */
64
+ export type Bucket = {
65
+ /** Reads a value, falling back to `def` when the key is not set. */
201
66
  get: <T>(key: string, def: T) => Widen<T>;
67
+ /** Writes a value, creating intermediate objects. */
68
+ set: (key: string, value: SettingsValue) => void;
69
+ /** Flips a boolean against its current value, or `def` when the key is not set. */
202
70
  toggle: (key: string, def: boolean) => void;
71
+ /** Deletes a value and prunes the objects it leaves empty. */
203
72
  remove: (key: string) => void;
73
+ /** Deletes every setting in the Bucket. */
74
+ clear: () => void;
204
75
  };
205
- /** The declared parameter count of a listener. */
206
- export type ArgsNum<T extends Listener> = Parameters<T>['length'];
207
- export type ClearedPayload = {
208
- store: string;
209
- };
210
- /** The event map of an untyped emitter. `__proto__` is reserved, as in tseep. */
211
- export type DefaultEventMap = Record<string | symbol, Listener> & {
212
- __proto__?: never;
213
- };
214
- export type EventCollections<EventMap extends DefaultEventMap> = {
215
- [eventName in keyof EventMap]?: TaskCollection<EventMap[eventName]>;
216
- };
217
- export type EventMap = {
218
- set: (payload: SetPayload) => void;
219
- changed: (payload: SettingsPayload) => void;
220
- cleared: (payload: ClearedPayload) => void;
221
- removed: (payload: RemovedPayload) => void;
222
- toggled: (payload: ToggledPayload) => void;
223
- };
224
- /** Any event listener. tseep's `any[]` parameters become `never[]`, which accepts every listener. */
225
- export type Listener = (...args: never[]) => Promise<unknown> | void;
226
- export type OnceCollections<EventMap extends DefaultEventMap> = {
227
- [eventName in keyof EventMap]?: EventMap[eventName][] | EventMap[eventName];
228
- };
229
- export type RemovedPayload = {
230
- store: string;
231
- key: string;
232
- };
233
- export type SetPayload = {
234
- store: string;
235
- key: string;
236
- value: SettingsValue;
76
+ /** What `storage.define` returns: a schema's settings, bound to one Bucket. */
77
+ export type DefinedSettings = {
78
+ /** The schema the settings were defined with. */
79
+ schema: SettingsSchema;
80
+ /** The settings as an object; assign a property, a section's too, to save it. */
81
+ values: SettingsValues;
82
+ /** Reads a setting by its dot-separated key; a stored value the schema rejects is logged, removed and read as the default. */
83
+ get: (key: string) => SettingValue;
84
+ /** Saves a setting by its dot-separated key; throws when the schema rejects the value. */
85
+ set: (key: string, value: SettingValue) => void;
86
+ /** Puts every setting back to its default, leaving other keys of the Bucket alone. */
87
+ reset: () => void;
88
+ /** React hook that reads a setting, or a section as an object, and re-renders when it changes. */
89
+ useSetting: (key: string) => SettingValue | SettingsValues;
90
+ /** React hook that re-renders on any change to the settings while `enabled`, and returns a number that changes with them. */
91
+ useVersion: (enabled?: boolean) => number;
237
92
  };
238
- /** Payload describing a settings change, passed to `changed` listeners and predicates. */
93
+ /** Payload describing a settings change, passed to `onChange` listeners and predicates. */
239
94
  export type SettingsPayload = {
95
+ /** The name of the Bucket that changed. */
240
96
  store: string;
97
+ /** The dot-separated key that changed, or `null` when the whole Bucket was cleared. */
241
98
  key: string | null;
99
+ /** The new value, or `undefined` when the key was removed or the Bucket cleared. */
242
100
  value: SettingsValue | undefined;
243
101
  };
244
- export type Tasks<Func> = Func[] | Func | null;
245
- export type ToggledPayload = {
246
- store: string;
247
- key: string;
248
- prev: boolean;
249
- value: boolean;
102
+ /** Decides whether a settings change should reach a listener. */
103
+ export type SettingsPredicate = (payload: SettingsPayload) => PredicateResult;
104
+ /** Every Bucket's settings, keyed by Bucket name, as the loader persists them. */
105
+ export type SettingsStores = Record<string, SettingsObject>;
106
+ /** A plugin's settings as an object: reads apply defaults, writes are validated and saved. Sections are nested objects. */
107
+ export type SettingsValues = {
108
+ [key: string]: SettingValue | SettingsValues;
250
109
  };
251
- export { _default as default };
252
-
253
110
  export {};
package/src/sync.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ // Auto-generated by generate-plugin-sdk.ts - DO NOT EDIT
2
+
3
+ /** The settings store Sync keeps its mode and last agreed document in. Never synced. */
4
+ export declare const SYNC_STORE = 'unbound::sync';
5
+ /**
6
+ * @description Deletes the stored document and turns syncing off on this device, so it is not
7
+ * uploaded again. Other devices keep what they have installed.
8
+ * @returns Whether the document was deleted. Failures are recorded as `lastError`.
9
+ */
10
+ export declare function deleteData(): Promise<boolean>;
11
+ /** @returns Which way automatic syncs move changes on this device. */
12
+ export declare function getMode(): SyncMode;
13
+ /**
14
+ * @returns Whether a sync is applying remote changes right now, so the changes it makes can be told apart.
15
+ */
16
+ export declare function isApplying(): boolean;
17
+ /** @returns Whether this device syncs automatically. */
18
+ export declare function isEnabled(): boolean;
19
+ /**
20
+ * @description Syncs now: reads the stored document, merges, applies remote changes here and saves
21
+ * the result. A call while a sync runs queues one more run after it, in this device's mode.
22
+ * @param strategy How to reconcile the two sides; this device's mode by default.
23
+ * @returns Whether the sync succeeded. Failures are recorded as `lastError` in {@link SYNC_STORE}.
24
+ */
25
+ export declare function now(strategy?: SyncStrategy): Promise<boolean>;
26
+ /**
27
+ * @description Settles how this device and an existing cloud setup combine on the first sync after
28
+ * signing in, then turns automatic syncing on.
29
+ * @param strategy `merge` keeps both, `pull` replaces this device's setup, `push` replaces the cloud's.
30
+ * @returns Whether the sync succeeded.
31
+ */
32
+ export declare function resolveFirstSync(strategy: SyncStrategy): Promise<boolean>;
33
+ /**
34
+ * @description Turns automatic syncing on or off, syncing right away when turned on.
35
+ * @param enabled Whether to sync automatically.
36
+ */
37
+ export declare function setEnabled(enabled: boolean): void;
38
+ /**
39
+ * @description Sets which way automatic syncs move changes, syncing right away when sync is on.
40
+ * @param mode The new mode.
41
+ */
42
+ export declare function setMode(mode: SyncMode): void;
43
+ /** Which way automatic syncs move changes on this device. */
44
+ export type SyncMode = 'two-way' | 'download' | 'upload';
45
+ /**
46
+ * How one sync reconciles the two sides: `merge` keeps changes from both, `pull` makes this device
47
+ * match the cloud, and `push` makes the cloud match this device.
48
+ */
49
+ export type SyncStrategy = 'merge' | 'pull' | 'push';
50
+
51
+ export {};
@@ -0,0 +1,43 @@
1
+ // Auto-generated by generate-plugin-sdk.ts - DO NOT EDIT
2
+
3
+ import type { AddonHandle, PushedManifest } from './_internal';
4
+ /** Disables a theme and removes it from the app. */
5
+ export declare const disable: (id: string) => void;
6
+ /** Enables a theme and applies it. */
7
+ export declare const enable: (id: string) => void | Promise<void>;
8
+ /** Reads one installed theme by id. */
9
+ export declare const get: (id: string) => AddonHandle | undefined;
10
+ /** Lists every installed theme. */
11
+ export declare const getAll: () => AddonHandle[];
12
+ /** Installs a theme from its manifest URL. */
13
+ export declare const install: (url: string, digest?: string) => Promise<AddonHandle | undefined>;
14
+ /** Reports whether a theme is enabled. */
15
+ export declare const isEnabled: (id: string) => boolean;
16
+ /** Swaps a theme's files in place, keeping its enabled state. */
17
+ export declare const reload: (
18
+ id: string,
19
+ bundle: string,
20
+ manifest: PushedManifest,
21
+ bytecode?: string,
22
+ ) => Promise<ReloadResult>;
23
+ /** Enables a disabled theme, or disables an enabled one. */
24
+ export declare const toggle: (id: string) => void;
25
+ /** Removes an installed theme. */
26
+ export declare const uninstall: (id: string) => Promise<void>;
27
+ /**
28
+ * @description Checks for updates, then applies this theme's pending update.
29
+ * @param id The theme's id.
30
+ * @returns Whether the theme now runs a newer version.
31
+ */
32
+ export declare function update(id: string): Promise<boolean>;
33
+ /** The outcome of an addon reload: success, or failure carrying the recorded error. */
34
+ export type ReloadResult =
35
+ | {
36
+ ok: true;
37
+ }
38
+ | {
39
+ ok: false;
40
+ error: Error;
41
+ };
42
+
43
+ export {};
package/src/toasts.d.ts CHANGED
@@ -1,20 +1,73 @@
1
1
  // Auto-generated by generate-plugin-sdk.ts - DO NOT EDIT
2
2
 
3
+ import type { MessageKey, FormatVars as MessageVars } from '@unbound-app/i18n';
4
+
3
5
  export type { ToastHandle, ToastOptions } from './_internal';
4
6
  import type { ToastHandle, ToastOptions } from './_internal';
5
- import * as ReactModule from 'react';
6
- import { ComponentType } from 'react';
7
+ import * as React$1 from 'react';
8
+ import { ComponentType, ReactElement } from 'react';
7
9
  import { ImageSourcePropType } from 'react-native';
8
-
9
- declare const _default: {
10
- showToast: typeof showToast;
11
- };
10
+ /**
11
+ * @description Shows an error toast with an X icon, titled "Something went wrong" in the user's language, with the
12
+ * error's own message as its text, and logs the error.
13
+ * @param cause What was thrown or rejected: an Error, a string or anything else.
14
+ * @returns A {@link ToastHandle} for controlling the shown toast.
15
+ */
16
+ export declare function error(cause: unknown): ToastHandle;
17
+ /**
18
+ * @description Shows an error toast titled by a message key, with the error's message as its text, and logs the error.
19
+ * @param key The title's message key.
20
+ * @param args The key's placeholder values when it has placeholders, then the error, then optional `icon`, `duration` and `id`.
21
+ * @returns A {@link ToastHandle} for controlling the shown toast.
22
+ */
23
+ export declare function error<K extends MessageKey>(
24
+ key: K,
25
+ ...args: MessageArgs<K, [error: unknown, options?: ToastShorthandOptions]>
26
+ ): ToastHandle;
27
+ /**
28
+ * @description Shows an info toast titled by a message key, with an info icon.
29
+ * @param key The message key.
30
+ * @param args The key's placeholder values when it has placeholders, then optional `icon`, `duration` and `id`.
31
+ * @returns A {@link ToastHandle} for controlling the shown toast.
32
+ */
33
+ export declare function info<K extends MessageKey>(
34
+ key: K,
35
+ ...args: MessageArgs<K, [options?: ToastShorthandOptions]>
36
+ ): ToastHandle;
12
37
  /**
13
38
  * @description Shows a toast, generating an id when one is not supplied.
14
39
  * @param options The toast options, optionally including a custom `id`.
15
40
  * @returns A {@link ToastHandle} for controlling the shown toast.
16
41
  */
17
- export declare function showToast(options: ToastOptions): ToastHandle;
18
- export { _default as default };
19
-
42
+ export declare function show(options: ToastOptions): ToastHandle;
43
+ /**
44
+ * @description Shows a success toast titled by a message key, with a check icon.
45
+ * @param key The message key.
46
+ * @param args The key's placeholder values when it has placeholders, then optional `icon`, `duration` and `id`.
47
+ * @returns A {@link ToastHandle} for controlling the shown toast.
48
+ */
49
+ export declare function success<K extends MessageKey>(
50
+ key: K,
51
+ ...args: MessageArgs<K, [options?: ToastShorthandOptions]>
52
+ ): ToastHandle;
53
+ /**
54
+ * @description Shows a warning toast titled by a message key, with a warning icon.
55
+ * @param key The message key.
56
+ * @param args The key's placeholder values when it has placeholders, then optional `icon`, `duration` and `id`.
57
+ * @returns A {@link ToastHandle} for controlling the shown toast.
58
+ */
59
+ export declare function warning<K extends MessageKey>(
60
+ key: K,
61
+ ...args: MessageArgs<K, [options?: ToastShorthandOptions]>
62
+ ): ToastHandle;
63
+ /**
64
+ * The arguments after a key, as `format(key, vars)` takes them: the key's placeholder values when it has
65
+ * placeholders, none when it has none, then `Tail`.
66
+ */
67
+ export type MessageArgs<
68
+ K extends MessageKey,
69
+ Tail extends unknown[] = [],
70
+ > = K extends keyof MessageVars ? [vars: MessageVars[K], ...Tail] : Tail;
71
+ /** The toast options a shorthand takes after its key and vars. */
72
+ export type ToastShorthandOptions = Pick<ToastOptions, 'icon' | 'duration' | 'id'>;
20
73
  export {};