@openstrap/plugin-contract 0.1.0 → 0.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.
- package/package.json +2 -1
- package/ports/FileSystem.d.ts +42 -0
- package/ports/Network.d.ts +23 -0
- package/ports/Process.d.ts +35 -0
- package/ports/Transport.d.ts +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openstrap/plugin-contract",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The shape an OpenStrap plugin has. Types only: no runtime code, so a plugin depends on the contract and never on OpenStrap.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"*.d.ts",
|
|
13
|
+
"ports/*.d.ts",
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
15
16
|
"license": "UNLICENSED",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type FileAccess = "executable" | "private" | "readable";
|
|
2
|
+
|
|
3
|
+
export type FileSystemWriteOptions = {
|
|
4
|
+
mode?: number;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type TextFileWriteOptions = FileSystemWriteOptions & {
|
|
8
|
+
access?: FileAccess;
|
|
9
|
+
strategy?: "atomic";
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type RemovePathOptions = {
|
|
13
|
+
force?: boolean;
|
|
14
|
+
recursive?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type BinaryFileWriteOptions = FileSystemWriteOptions & {
|
|
18
|
+
access?: FileAccess;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export interface FileSystemAPI {
|
|
22
|
+
copyFile(source: string, destination: string): Promise<void>;
|
|
23
|
+
createDirectory(path: string, options?: FileSystemWriteOptions): Promise<void>;
|
|
24
|
+
createExclusiveDirectory(path: string): Promise<boolean>;
|
|
25
|
+
executable(path: string): Promise<boolean>;
|
|
26
|
+
mode(path: string): Promise<number | null>;
|
|
27
|
+
joinPath(...parts: string[]): string;
|
|
28
|
+
parentPath(path: string): string;
|
|
29
|
+
resolvePathWithin(directory: string, ...parts: string[]): string;
|
|
30
|
+
setAccess(path: string, access: FileAccess): Promise<void>;
|
|
31
|
+
readTextFile(path: string): Promise<string | null>;
|
|
32
|
+
removePath(path: string, options?: RemovePathOptions): Promise<void>;
|
|
33
|
+
writeTextFile(path: string, content: string, options?: TextFileWriteOptions): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* The bytes of a file, or null when there is no such file.
|
|
36
|
+
*
|
|
37
|
+
* Separate from `readTextFile` because a decoding is a decision: an executable
|
|
38
|
+
* read as UTF-8 comes back corrupted, and the corruption is silent.
|
|
39
|
+
*/
|
|
40
|
+
readFile(path: string): Promise<Buffer | null>;
|
|
41
|
+
writeFile(path: string, content: Buffer, options?: BinaryFileWriteOptions): Promise<void>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type DownloadResult = {
|
|
2
|
+
bytes: number;
|
|
3
|
+
sha256: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type NetworkRequest = {
|
|
7
|
+
body?: string;
|
|
8
|
+
headers: Record<string, string>;
|
|
9
|
+
method: "GET" | "POST";
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type NetworkResponse = {
|
|
14
|
+
body: string;
|
|
15
|
+
status: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface NetworkAPI {
|
|
19
|
+
download(url: string, destination: string): Promise<DownloadResult>;
|
|
20
|
+
endpointReady(url: string, timeoutMs: number): Promise<boolean>;
|
|
21
|
+
readText(url: string): Promise<string>;
|
|
22
|
+
request(url: string, request: NetworkRequest): Promise<NetworkResponse>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type SystemCommand = {
|
|
2
|
+
command: string;
|
|
3
|
+
args: string[];
|
|
4
|
+
cwd: string;
|
|
5
|
+
environment?: Record<string, string | undefined>;
|
|
6
|
+
/** UTF-8 input delivered to the program's stdin, never through arguments or environment. */
|
|
7
|
+
stdin?: string;
|
|
8
|
+
stdio: "ignore" | "inherit";
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type CapturedSystemCommand = Omit<SystemCommand, "stdio">;
|
|
12
|
+
|
|
13
|
+
export type DetachedProcessCommand = {
|
|
14
|
+
command: string;
|
|
15
|
+
args: string[];
|
|
16
|
+
cwd: string;
|
|
17
|
+
environment?: Record<string, string | undefined>;
|
|
18
|
+
stdoutLog: string;
|
|
19
|
+
stderrLog: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ProcessOutput = {
|
|
23
|
+
exitCode: number | null;
|
|
24
|
+
stdout: string;
|
|
25
|
+
stderr: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export interface ProcessAPI {
|
|
29
|
+
capture(command: CapturedSystemCommand): Promise<ProcessOutput>;
|
|
30
|
+
processRunning(pid: number): Promise<boolean>;
|
|
31
|
+
run(command: SystemCommand): Promise<void>;
|
|
32
|
+
startDetachedProcess(command: DetachedProcessCommand): Promise<number>;
|
|
33
|
+
stopDetachedProcess(pid: number, timeoutMs: number): Promise<void>;
|
|
34
|
+
succeeds(command: SystemCommand): Promise<boolean>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FileSystemAPI } from "./FileSystem.js";
|
|
2
|
+
import type { NetworkAPI } from "./Network.js";
|
|
3
|
+
import type { ProcessAPI } from "./Process.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A channel of access to a target, plus the operations performed through it.
|
|
7
|
+
*
|
|
8
|
+
* Progress output and the openstrap process environment are deliberately absent:
|
|
9
|
+
* they belong to the host process, not to the channel. The port also returns no
|
|
10
|
+
* derived data — deciding which operating system a target runs is fact collection,
|
|
11
|
+
* not transport.
|
|
12
|
+
*/
|
|
13
|
+
export type Transport = {
|
|
14
|
+
fileSystem: FileSystemAPI;
|
|
15
|
+
network: NetworkAPI;
|
|
16
|
+
processes: ProcessAPI;
|
|
17
|
+
};
|