@vornrun/connector-sdk 0.6.1 → 0.7.0-beta.10
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/README.md +150 -2
- package/dist/chunk-XOP6JKBX.js +2220 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +89 -9
- package/dist/index.d.ts +103 -418
- package/dist/index.js +58 -34
- package/dist/packaging-DFTuP4fr.d.ts +882 -0
- package/package.json +3 -1
- package/dist/chunk-457KOZUU.js +0 -773
package/dist/cli.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { B as BundleRequest, a as BundleOutput } from './packaging-DFTuP4fr.js';
|
|
3
|
+
|
|
2
4
|
interface CliDeps {
|
|
3
5
|
load(modulePath: string): Promise<unknown>;
|
|
4
6
|
write(line: string): void;
|
|
5
7
|
env?: NodeJS.ProcessEnv;
|
|
8
|
+
/** Directory module paths resolve from; defaults to the working directory. */
|
|
9
|
+
cwd?: string;
|
|
10
|
+
/** Replaced in tests so pack does not shell out to a bundler. */
|
|
11
|
+
bundle?(request: BundleRequest): Promise<BundleOutput>;
|
|
12
|
+
/** Writes a scaffold file or a receipt; replaced in tests so nothing touches disk. */
|
|
13
|
+
writeFile?(path: string, contents: string): Promise<void>;
|
|
14
|
+
/** Replaced in tests beside writeFile. */
|
|
15
|
+
exists?(path: string): boolean;
|
|
6
16
|
}
|
|
7
17
|
declare function runCli(argv: string[], deps: CliDeps): Promise<number>;
|
|
8
18
|
|
package/dist/cli.js
CHANGED
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
checkConnector,
|
|
4
3
|
connectionSetup,
|
|
5
4
|
connectorManifest,
|
|
5
|
+
esbuildBundle,
|
|
6
6
|
formatFindings,
|
|
7
|
+
packConnector,
|
|
7
8
|
resolveConfig,
|
|
9
|
+
runConformance,
|
|
8
10
|
runPoll,
|
|
11
|
+
scaffoldFiles,
|
|
9
12
|
serveConnector
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-XOP6JKBX.js";
|
|
11
14
|
|
|
12
15
|
// src/cli.ts
|
|
13
16
|
import { pathToFileURL } from "url";
|
|
14
|
-
import {
|
|
15
|
-
|
|
17
|
+
import { existsSync } from "fs";
|
|
18
|
+
import { dirname, join, resolve } from "path";
|
|
19
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
20
|
+
var USAGE = `vorn-connector <command> <module | id> [options]
|
|
16
21
|
|
|
17
22
|
Commands:
|
|
23
|
+
new <id> Scaffold a new connector, ready to build
|
|
18
24
|
manifest <module> Print the connector manifest as JSON
|
|
19
25
|
setup <module> [trigger] Print the Vorn connection settings to paste
|
|
20
26
|
check <module> Verify the connector against Vorn's contract
|
|
27
|
+
pack <module> Build an installable .vorn.tgz pack
|
|
21
28
|
poll <module> <trigger> Run one poll against the current environment
|
|
22
29
|
serve <module> Serve the connector on stdio (what Vorn runs)
|
|
23
30
|
|
|
24
31
|
Options:
|
|
25
32
|
--since <iso> Lower bound passed to poll
|
|
26
33
|
--limit <n> Maximum items to request
|
|
27
|
-
--live Let check poll for real using the environment
|
|
28
|
-
|
|
34
|
+
--live Let check poll for real using the environment
|
|
35
|
+
--mock Run every action against served HTTP, not the network
|
|
36
|
+
--receipt <file> Where check writes what it verified, as JSON
|
|
37
|
+
--out <dir> Directory new and pack write to
|
|
38
|
+
--name <name> Display name for a new connector
|
|
39
|
+
--repo-conventions Scaffold a package shaped for the connectors repository`;
|
|
40
|
+
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["live", "mock", "repo-conventions"]);
|
|
29
41
|
function parseArgs(args) {
|
|
30
42
|
const flags = {};
|
|
31
43
|
const positional = [];
|
|
@@ -67,11 +79,36 @@ async function runCli(argv, deps) {
|
|
|
67
79
|
return command ? 0 : 1;
|
|
68
80
|
}
|
|
69
81
|
if (!modulePath) {
|
|
70
|
-
deps.write(`Missing
|
|
82
|
+
deps.write(`Missing <${command === "new" ? "id" : "module"}> argument
|
|
71
83
|
|
|
72
84
|
${USAGE}`);
|
|
73
85
|
return 1;
|
|
74
86
|
}
|
|
87
|
+
if (command === "new") {
|
|
88
|
+
const { flags: flags2 } = parseArgs(rest);
|
|
89
|
+
if (!deps.writeFile) {
|
|
90
|
+
deps.write("This build cannot write files");
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
const files = scaffoldFiles({
|
|
94
|
+
id: modulePath,
|
|
95
|
+
...flags2.name !== void 0 && { name: flags2.name },
|
|
96
|
+
...flags2["repo-conventions"] === "true" && { repoConventions: true }
|
|
97
|
+
});
|
|
98
|
+
const root = join(flags2.out ?? deps.cwd ?? ".", modulePath);
|
|
99
|
+
if ((deps.exists ?? existsSync)(root)) {
|
|
100
|
+
deps.write(`${root} already exists; a scaffold never overwrites`);
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
for (const file of files) {
|
|
104
|
+
await deps.writeFile(join(root, file.path), file.contents);
|
|
105
|
+
}
|
|
106
|
+
deps.write(`Created ${modulePath} in ${root}`);
|
|
107
|
+
for (const file of files) deps.write(` ${file.path}`);
|
|
108
|
+
deps.write(`
|
|
109
|
+
Next: cd ${root} && yarn install && yarn check`);
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
75
112
|
const connector = pickConnector(await deps.load(modulePath), modulePath);
|
|
76
113
|
const { flags, positional } = parseArgs(rest);
|
|
77
114
|
switch (command) {
|
|
@@ -95,14 +132,33 @@ ${USAGE}`);
|
|
|
95
132
|
return 0;
|
|
96
133
|
}
|
|
97
134
|
case "check": {
|
|
98
|
-
const
|
|
135
|
+
const packaged = flags.mock === "true" ? {
|
|
136
|
+
mock: true,
|
|
137
|
+
packageDir: deps.cwd ?? process.cwd(),
|
|
138
|
+
entry: modulePath,
|
|
139
|
+
bundle: deps.bundle ?? esbuildBundle
|
|
140
|
+
} : {};
|
|
141
|
+
const run = await runConformance(connector, {
|
|
142
|
+
...packaged,
|
|
99
143
|
...flags.live === "true" && {
|
|
100
144
|
live: true,
|
|
101
145
|
config: resolveConfig(connector, deps.env ?? process.env)
|
|
102
146
|
}
|
|
103
147
|
});
|
|
148
|
+
const { findings } = run;
|
|
104
149
|
const errors = findings.filter((item) => item.level === "error");
|
|
105
150
|
if (findings.length > 0) deps.write(formatFindings(findings));
|
|
151
|
+
if (flags.receipt !== void 0) {
|
|
152
|
+
if (run.receipt) {
|
|
153
|
+
const write = deps.writeFile ?? ((path, contents) => writeFile(path, contents));
|
|
154
|
+
await write(flags.receipt, `${JSON.stringify(run.receipt, null, 2)}
|
|
155
|
+
`);
|
|
156
|
+
deps.write(`Verified ${run.receipt.checks.join(", ")} \u2014 wrote ${flags.receipt}`);
|
|
157
|
+
} else {
|
|
158
|
+
deps.write(`No receipt written: nothing could be vouched for`);
|
|
159
|
+
if (errors.length === 0) return 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
106
162
|
deps.write(
|
|
107
163
|
errors.length > 0 ? `
|
|
108
164
|
${errors.length} error(s), ${findings.length - errors.length} warning(s)` : `
|
|
@@ -110,6 +166,26 @@ ${connector.id} passed with ${findings.length} warning(s)`
|
|
|
110
166
|
);
|
|
111
167
|
return errors.length > 0 ? 1 : 0;
|
|
112
168
|
}
|
|
169
|
+
case "pack": {
|
|
170
|
+
const result = await packConnector(connector, {
|
|
171
|
+
entry: modulePath,
|
|
172
|
+
...flags.out !== void 0 && { outDir: flags.out },
|
|
173
|
+
...deps.cwd !== void 0 && { resolveDir: deps.cwd },
|
|
174
|
+
...deps.bundle !== void 0 && { bundle: deps.bundle }
|
|
175
|
+
});
|
|
176
|
+
if (result.findings.length > 0) deps.write(formatFindings(result.findings));
|
|
177
|
+
const errors = result.findings.filter((item) => item.level === "error");
|
|
178
|
+
if (!result.file) {
|
|
179
|
+
deps.write(`
|
|
180
|
+
${errors.length} error(s) \u2014 nothing was packed`);
|
|
181
|
+
return 1;
|
|
182
|
+
}
|
|
183
|
+
deps.write(
|
|
184
|
+
`
|
|
185
|
+
Packed ${connector.id} ${connector.version} to ${result.file} (${Math.max(1, Math.round((result.bytes ?? 0) / 1024))} KB)`
|
|
186
|
+
);
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
113
189
|
case "poll": {
|
|
114
190
|
const triggerType = positional[0];
|
|
115
191
|
if (!triggerType) {
|
|
@@ -146,7 +222,11 @@ if (invokedDirectly) {
|
|
|
146
222
|
runCli(process.argv.slice(2), {
|
|
147
223
|
load: (modulePath) => modulePath.startsWith(".") || modulePath.startsWith("/") ? import(pathToFileURL(resolve(modulePath)).href) : import(modulePath),
|
|
148
224
|
write: (line) => process.stdout.write(`${line}
|
|
149
|
-
`)
|
|
225
|
+
`),
|
|
226
|
+
writeFile: async (path, contents) => {
|
|
227
|
+
await mkdir(dirname(path), { recursive: true });
|
|
228
|
+
await writeFile(path, contents);
|
|
229
|
+
}
|
|
150
230
|
}).then((code) => {
|
|
151
231
|
process.exitCode = code;
|
|
152
232
|
}).catch((error) => {
|