toolcraft-openapi 0.0.1 → 0.0.3
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 +3 -3
- package/dist/api-command.d.ts +3 -3
- package/dist/api-command.js +1 -1
- package/dist/auth/bearer-token-auth.js +3 -3
- package/dist/auth/types.d.ts +1 -1
- package/dist/bin/generate.js +2 -2
- package/dist/define-client.d.ts +1 -1
- package/dist/define-client.js +1 -1
- package/dist/generate.js +5 -5
- package/dist/http.js +1 -1
- package/dist/interpreter.js +1 -1
- package/dist/naming.js +2 -2
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +1 -1
- package/dist/spec-source.js +1 -1
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/cancel.d.ts +1 -1
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/cancel.js +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Scaffold for OpenAPI-driven toolcraft clients.
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
import { bearerTokenAuth, requestJson } from "
|
|
10
|
+
import { bearerTokenAuth, requestJson } from "toolcraft-openapi";
|
|
11
11
|
|
|
12
12
|
const auth = bearerTokenAuth({
|
|
13
13
|
serviceName: "internal-agent",
|
|
@@ -18,7 +18,7 @@ const auth = bearerTokenAuth({
|
|
|
18
18
|
|
|
19
19
|
## Generator CLI
|
|
20
20
|
|
|
21
|
-
`
|
|
21
|
+
`toolcraft-openapi-generate` reads an OpenAPI document from disk or a URL, writes generated
|
|
22
22
|
command files, and stores the current spec hash in `openapi.lock`.
|
|
23
23
|
|
|
24
24
|
- `--input <path-or-url>` — OpenAPI document to read. Defaults to `openapi.json`.
|
|
@@ -29,7 +29,7 @@ command files, and stores the current spec hash in `openapi.lock`.
|
|
|
29
29
|
### CI drift check
|
|
30
30
|
|
|
31
31
|
```sh
|
|
32
|
-
|
|
32
|
+
toolcraft-openapi-generate --check
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
## Exports
|
package/dist/api-command.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Command } from "
|
|
2
|
-
import { defineCommand } from "
|
|
3
|
-
import type { ObjectSchema } from "
|
|
1
|
+
import type { Command } from "toolcraft";
|
|
2
|
+
import { defineCommand } from "toolcraft";
|
|
3
|
+
import type { ObjectSchema } from "toolcraft-schema";
|
|
4
4
|
import type { OpenApiClientServices } from "./define-client.js";
|
|
5
5
|
type ApiScope = readonly ["cli", "mcp", "sdk"];
|
|
6
6
|
export declare function defineApiCommand<TParamsSchema extends ObjectSchema<any>>(config: Parameters<typeof defineCommand<OpenApiClientServices, string, TParamsSchema, undefined, unknown, ApiScope>>[0]): Command<OpenApiClientServices, TParamsSchema, undefined, unknown>;
|
package/dist/api-command.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineCommand, defineGroup, S, UserError } from "
|
|
1
|
+
import { defineCommand, defineGroup, S, UserError } from "toolcraft";
|
|
2
2
|
import { isCancel, password } from "@poe-code/design-system";
|
|
3
3
|
import { createSecretStore } from "auth-store";
|
|
4
4
|
import { requestJson } from "../http.js";
|
|
@@ -9,13 +9,13 @@ const loginParams = S.Object({
|
|
|
9
9
|
});
|
|
10
10
|
const emptyParams = S.Object({});
|
|
11
11
|
const KEYCHAIN_ACCOUNT = "token";
|
|
12
|
-
const DEFAULT_STORE_DIRECTORY = ".
|
|
12
|
+
const DEFAULT_STORE_DIRECTORY = ".toolcraft-openapi";
|
|
13
13
|
const DEFAULT_STORE_VERSION = "v1";
|
|
14
14
|
export function bearerTokenAuth(options) {
|
|
15
15
|
const commandPrefix = options.commandPrefix ?? DEFAULT_COMMAND_PREFIX;
|
|
16
16
|
const { store, backend } = createSecretStore({
|
|
17
17
|
fileStore: {
|
|
18
|
-
salt: `${options.serviceName}:
|
|
18
|
+
salt: `${options.serviceName}:toolcraft-openapi:${DEFAULT_STORE_VERSION}`,
|
|
19
19
|
defaultDirectory: DEFAULT_STORE_DIRECTORY,
|
|
20
20
|
defaultFileName: `${options.serviceName}.enc`,
|
|
21
21
|
},
|
package/dist/auth/types.d.ts
CHANGED
package/dist/bin/generate.js
CHANGED
|
@@ -4,7 +4,7 @@ import fs from "node:fs/promises";
|
|
|
4
4
|
import { realpathSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { UserError } from "
|
|
7
|
+
import { UserError } from "toolcraft";
|
|
8
8
|
import { generate } from "../generate.js";
|
|
9
9
|
import { readOpenApiLock, writeOpenApiLock } from "../lock.js";
|
|
10
10
|
import { parseOpenApiDocument, readOpenApiSourceText } from "../spec-source.js";
|
|
@@ -14,7 +14,7 @@ const DEFAULT_OPTIONS = {
|
|
|
14
14
|
lockPath: "openapi.lock",
|
|
15
15
|
outputDir: "src/generated"
|
|
16
16
|
};
|
|
17
|
-
const HELP_TEXT = `Usage:
|
|
17
|
+
const HELP_TEXT = `Usage: toolcraft-openapi-generate [options]
|
|
18
18
|
|
|
19
19
|
Options:
|
|
20
20
|
--input <path-or-url> OpenAPI document to read (default: openapi.json)
|
package/dist/define-client.d.ts
CHANGED
package/dist/define-client.js
CHANGED
package/dist/generate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserError } from "
|
|
1
|
+
import { UserError } from "toolcraft";
|
|
2
2
|
import { METHOD_DEFAULTS, deriveNoun, deriveVerb, isIdentifierName, normalizeParamName, toCamelCase, toPascalCase } from "./naming.js";
|
|
3
3
|
import { groupByNoun } from "./group-by-noun.js";
|
|
4
4
|
import { renderPreflightBlock, renderRequestShape } from "./interpreter.js";
|
|
@@ -845,8 +845,8 @@ function createCommandFile(options) {
|
|
|
845
845
|
`operation-id: ${options.operationId}`
|
|
846
846
|
]);
|
|
847
847
|
lines.push(requiresUserError
|
|
848
|
-
? 'import { S, UserError } from "
|
|
849
|
-
: 'import { S } from "
|
|
848
|
+
? 'import { S, UserError } from "toolcraft";'
|
|
849
|
+
: 'import { S } from "toolcraft";', 'import { requestJson, defineApiCommand } from "toolcraft-openapi";', "", `export const ${options.exportName} = defineApiCommand({`, ` name: ${JSON.stringify(options.verb)},`);
|
|
850
850
|
if (options.description !== undefined) {
|
|
851
851
|
lines.push(` description: ${JSON.stringify(options.description)},`);
|
|
852
852
|
}
|
|
@@ -1087,7 +1087,7 @@ function createIndexFile(commands) {
|
|
|
1087
1087
|
};
|
|
1088
1088
|
}
|
|
1089
1089
|
const lines = createGeneratedTypeScriptFileLines();
|
|
1090
|
-
lines.push('import { defineGroup } from "
|
|
1090
|
+
lines.push('import { defineGroup } from "toolcraft";');
|
|
1091
1091
|
for (const { commands: nounCommands } of groups) {
|
|
1092
1092
|
for (const command of nounCommands) {
|
|
1093
1093
|
lines.push(`import { ${command.exportName} } from ${JSON.stringify(`./${command.filePath.replace(/\.ts$/, ".js")}`)};`);
|
|
@@ -1114,7 +1114,7 @@ function createGeneratedTypeScriptFile(bodyLines, metadataLines = []) {
|
|
|
1114
1114
|
function createGeneratedTypeScriptFileLines(metadataLines = []) {
|
|
1115
1115
|
return [
|
|
1116
1116
|
"/**",
|
|
1117
|
-
" * Generated by
|
|
1117
|
+
" * Generated by toolcraft-openapi.",
|
|
1118
1118
|
...metadataLines.map((line) => ` * ${line}`),
|
|
1119
1119
|
" */"
|
|
1120
1120
|
];
|
package/dist/http.js
CHANGED
package/dist/interpreter.js
CHANGED
package/dist/naming.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserError } from "
|
|
1
|
+
import { UserError } from "toolcraft";
|
|
2
2
|
export const METHOD_DEFAULTS = {
|
|
3
3
|
delete: {
|
|
4
4
|
collection: "delete",
|
|
@@ -49,7 +49,7 @@ export function deriveVerb(method, path, operation, operationId, noun) {
|
|
|
49
49
|
if (derived !== undefined) {
|
|
50
50
|
return derived;
|
|
51
51
|
}
|
|
52
|
-
throw new UserError(`Operation ${JSON.stringify(operationId)} is missing an operationId, so
|
|
52
|
+
throw new UserError(`Operation ${JSON.stringify(operationId)} is missing an operationId, so toolcraft-openapi cannot derive a stable command verb.`);
|
|
53
53
|
}
|
|
54
54
|
export function normalizeParamName(name) {
|
|
55
55
|
return toCamelCase(name);
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CommandNode } from "
|
|
1
|
+
import { type CommandNode } from "toolcraft";
|
|
2
2
|
import { type DefineClientOptions, type DefinedClient, type OpenApiClientServices } from "./define-client.js";
|
|
3
3
|
import { type OpenApiDocument } from "./generate.js";
|
|
4
4
|
import { type OpenApiSourceFileSystem } from "./spec-source.js";
|
package/dist/runtime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
-
import { defineCommand, defineGroup, S } from "
|
|
2
|
+
import { defineCommand, defineGroup, S } from "toolcraft";
|
|
3
3
|
import { defineClient } from "./define-client.js";
|
|
4
4
|
import { collectSchemaOptionEntries, collectGeneratedCommands } from "./generate.js";
|
|
5
5
|
import { groupByNoun } from "./group-by-noun.js";
|
package/dist/spec-source.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { parse as parseYaml } from "yaml";
|
|
4
|
-
import { UserError } from "
|
|
4
|
+
import { UserError } from "toolcraft";
|
|
5
5
|
export async function readOpenApiSourceText(input, services) {
|
|
6
6
|
const inputUrl = input instanceof URL ? input : tryParseUrl(input);
|
|
7
7
|
const sourceLabel = formatSourceLabel(input);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { isCancel } from "@clack/
|
|
1
|
+
export { isCancel } from "@clack/prompts";
|
|
2
2
|
export declare function cancel(msg?: string): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft-openapi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "rm -rf dist && tsc",
|
|
15
|
-
"test": "cd ../.. && vitest run packages/
|
|
16
|
-
"test:unit": "cd ../.. && vitest run packages/
|
|
15
|
+
"test": "cd ../.. && vitest run packages/toolcraft-openapi/src/*.test.ts",
|
|
16
|
+
"test:unit": "cd ../.. && vitest run packages/toolcraft-openapi/src/*.test.ts",
|
|
17
17
|
"prepack": "node ../../scripts/manage-bundled-workspace-deps.mjs prepare . @poe-code/design-system auth-store",
|
|
18
18
|
"postpack": "node ../../scripts/manage-bundled-workspace-deps.mjs cleanup . @poe-code/design-system auth-store"
|
|
19
19
|
},
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"bin": {
|
|
24
|
-
"
|
|
24
|
+
"toolcraft-openapi-generate": "dist/bin/generate.js"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@clack/core": "^1.0.0",
|
|
28
28
|
"@clack/prompts": "^1.0.0",
|
|
29
29
|
"@poe-code/design-system": "^0.0.1",
|
|
30
|
-
"toolcraft": "^0.0.1",
|
|
31
30
|
"auth-store": "^0.0.1",
|
|
32
31
|
"chalk": "^5.6.2",
|
|
33
32
|
"console-table-printer": "^2.15.0",
|
|
33
|
+
"toolcraft": "^0.0.3",
|
|
34
34
|
"yaml": "^2.8.2"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
|
41
41
|
"url": "git+https://github.com/poe-platform/poe-code.git",
|
|
42
|
-
"directory": "packages/
|
|
42
|
+
"directory": "packages/toolcraft-openapi"
|
|
43
43
|
},
|
|
44
44
|
"bundleDependencies": [
|
|
45
45
|
"@poe-code/design-system",
|