@t3mode/plugin-sdk 1.2.0 → 1.4.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/dist/index.d.ts CHANGED
@@ -42,20 +42,45 @@ export interface PluginUi {
42
42
  readonly row: (options: RowOptions) => HTMLElement;
43
43
  readonly button: (options: ButtonOptions) => HTMLButtonElement;
44
44
  }
45
- export interface LocalSocket {
46
- readonly name: string;
47
- write(data: Uint8Array): void;
48
- close(): void;
49
- onData(callback: (data: Uint8Array) => void): void;
50
- onClose(callback: (error?: string) => void): void;
45
+ /** A local fixed drive. */
46
+ export interface Disk {
47
+ /** The drive's root, such as `C:\`. */
48
+ readonly path: string;
49
+ /** Bytes. */
50
+ readonly total: number;
51
+ /** Bytes available to the user. */
52
+ readonly free: number;
53
+ }
54
+ /** A plugin's backend as its page code sees it. Null: no backend runs for it. */
55
+ export type BackendStatus = {
56
+ readonly state: "starting";
57
+ } | {
58
+ readonly state: "running";
59
+ } | {
60
+ readonly state: "restarting";
61
+ readonly crashes: number;
62
+ readonly error: string;
63
+ readonly retryAt: number;
64
+ } | {
65
+ readonly state: "failed";
66
+ readonly crashes: number;
67
+ readonly error: string;
68
+ };
69
+ /** The page side of a plugin's backend: messages to and from its own process. */
70
+ export interface PluginBackend {
71
+ /**
72
+ * Sends `data` (anything structured clone can copy) to the backend. Resolves false when no
73
+ * backend runs for the plugin, and the message is dropped.
74
+ */
75
+ readonly send: (data: unknown) => Promise<boolean>;
76
+ /** Called for every message the backend sends. */
77
+ readonly onMessage: (callback: (data: unknown) => void) => void;
78
+ /** Called now with the current status, then on every change. */
79
+ readonly onStatus: (callback: (status: BackendStatus | null) => void) => void;
51
80
  }
52
81
  export interface PluginApi<O extends OptionsSpec = OptionsSpec> {
53
82
  /** The id from the plugin's manifest.json. */
54
83
  readonly id: string;
55
- /** Connects to a local socket whose name must be declared in the manifest. */
56
- readonly sockets: {
57
- readonly connect: (name: string) => Promise<LocalSocket>;
58
- };
59
84
  readonly options: OptionValues<O>;
60
85
  /** Adds a stylesheet, removed when the plugin stops. */
61
86
  readonly css: (text: string) => void;
@@ -99,6 +124,16 @@ export interface PluginApi<O extends OptionsSpec = OptionsSpec> {
99
124
  /** The first hook state in the tree under the root of `node` that passes `test`. */
100
125
  readonly findHookState: <T>(node: Element, test: (value: unknown) => value is T, budget?: number) => T | undefined;
101
126
  };
127
+ /**
128
+ * Size and free space of each local fixed drive, cached for 30 seconds. Network and removable
129
+ * drives are left out. Added in SDK 1.3.0, so check for it before calling.
130
+ */
131
+ readonly disks?: () => Promise<ReadonlyArray<Disk>>;
132
+ /**
133
+ * The plugin's backend, the program its manifest's `backend` names. Added in SDK 1.4.0, so
134
+ * check for it before calling.
135
+ */
136
+ readonly backend?: PluginBackend;
102
137
  }
103
138
  export interface PluginDefinition<O extends OptionsSpec = OptionsSpec> {
104
139
  readonly options: O;
@@ -106,4 +141,29 @@ export interface PluginDefinition<O extends OptionsSpec = OptionsSpec> {
106
141
  start(api: PluginApi<O>): void;
107
142
  }
108
143
  /** Returns the definition unchanged, typing `api.options` from `options`. */
109
- export declare const definePlugin: <const O extends OptionsSpec>(definition: PluginDefinition<O>) => PluginDefinition<O>;
144
+ export declare const definePlugin: <const O extends OptionsSpec>(definition: PluginDefinition<O>) => PluginDefinition<O>;
145
+ /** What a backend's `start` gets. Added in SDK 1.4.0. */
146
+ export interface BackendApi {
147
+ /** The id from the plugin's manifest.json. */
148
+ readonly id: string;
149
+ /**
150
+ * The backend's own folder, `<home>/plugin-data/<id>/`. It exists when `start` runs, and is
151
+ * deleted when the plugin is removed.
152
+ */
153
+ readonly dataDir: string;
154
+ /** Sends `data` (anything structured clone can copy) to the plugin's page code. */
155
+ readonly send: (data: unknown) => void;
156
+ /** Called for every message the page code sends. Messages that came before are delivered too. */
157
+ readonly onMessage: (callback: (data: unknown) => void) => void;
158
+ /** A line in `<home>/logs/plugins/<id>.log`, where the backend's stdout and stderr go too. */
159
+ readonly log: (level: LogLevel, message: string) => void;
160
+ }
161
+ export interface BackendDefinition {
162
+ /**
163
+ * Called once when the process starts. The backend runs until the plugin is turned off,
164
+ * updated or removed, or T3 Code quits; a throw, a rejected promise or an exit is a crash.
165
+ */
166
+ start(api: BackendApi): void | Promise<void>;
167
+ }
168
+ /** Returns the definition unchanged: the default export of the plugin's backend script. */
169
+ export declare const defineBackend: (definition: BackendDefinition) => BackendDefinition;
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // src/index.ts
2
2
  /** Returns the definition unchanged, typing `api.options` from `options`. */
3
3
  const definePlugin = (definition) => definition;
4
- export { definePlugin };
4
+ /** Returns the definition unchanged: the default export of the plugin's backend script. */
5
+ const defineBackend = (definition) => definition;
6
+ export { defineBackend, definePlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t3mode/plugin-sdk",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "definePlugin and the plugin API types for t3mode, the plugin loader for T3 Code",
5
5
  "license": "MIT",
6
6
  "repository": {