@workerstack/clients 1.0.0-rc.26 → 1.0.0-rc.27
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 +43 -43
- package/bin/{honey-clients.js → clients.js} +12 -12
- package/dist/cli.d.ts +3 -3
- package/dist/cli.js +14 -14
- package/dist/emit/cli/discovery.js +1 -1
- package/dist/emit/cli/install.js +2 -2
- package/dist/emit/cli/layout.js +1 -1
- package/dist/emit/cli/module.js +1 -1
- package/dist/emit/cli/release.js +1 -1
- package/dist/emit/csharp/errors.js +1 -1
- package/dist/emit/csharp/sdk-client.js +1 -1
- package/dist/emit/csharp/sdk-csproj.d.ts +1 -1
- package/dist/emit/csharp/sdk-csproj.js +2 -2
- package/dist/emit/csharp/sdk.d.ts +1 -1
- package/dist/emit/csharp/sdk.js +2 -2
- package/dist/emit/csharp/transport.js +2 -2
- package/dist/emit/csharp/types-record.d.ts +1 -1
- package/dist/emit/go/sdk-client.js +1 -1
- package/dist/emit/go/sdk.js +1 -1
- package/dist/emit/java/sdk-errors.js +5 -5
- package/dist/emit/java/sdk-op.d.ts +1 -1
- package/dist/emit/java/sdk.js +3 -3
- package/dist/emit/mcp/files.d.ts +1 -1
- package/dist/emit/mcp/mounted.js +2 -2
- package/dist/emit/mcp/runtime.js +1 -1
- package/dist/emit/mcp/server.js +1 -1
- package/dist/emit/python/errors.js +1 -1
- package/dist/emit/python/sdk-client.js +2 -2
- package/dist/emit/python/sdk-pyproject.js +4 -4
- package/dist/emit/python/sdk.d.ts +1 -1
- package/dist/emit/python/sdk.js +11 -11
- package/dist/emit/python/transport.js +1 -1
- package/dist/emit/rust/errors.js +2 -2
- package/dist/emit/rust/sdk-cargo.js +3 -3
- package/dist/emit/rust/sdk.d.ts +1 -1
- package/dist/emit/rust/sdk.js +2 -2
- package/dist/emit/shared/format.d.ts +1 -1
- package/dist/emit/shared/metadata.d.ts +1 -1
- package/dist/emit/shared/status-keys.d.ts +1 -1
- package/dist/emit/shared/status-keys.js +1 -1
- package/dist/emit/ts/app-client.js +2 -2
- package/dist/emit/ts/route-tree.js +1 -1
- package/dist/emit/ts/sdk-types-preamble.js +16 -16
- package/dist/emit/ts/sdk-types.js +6 -6
- package/dist/emit/ts/tanstack-query.js +5 -5
- package/dist/emit/ts/type-gen.d.ts +2 -2
- package/dist/emit/ts/type-gen.js +16 -16
- package/dist/extract/extract.js +3 -3
- package/dist/extract/serialize.js +1 -1
- package/dist/gen/args.js +3 -3
- package/dist/gen/formatters.d.ts +6 -6
- package/dist/gen/formatters.js +7 -7
- package/dist/gen/process.d.ts +3 -3
- package/dist/gen/process.js +7 -7
- package/dist/gen/targets.d.ts +3 -3
- package/dist/gen/targets.js +3 -3
- package/dist/gen/write.d.ts +1 -1
- package/dist/gen/write.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/ir/load.js +10 -10
- package/dist/ir/model.d.ts +4 -4
- package/dist/ir/sdk-model.d.ts +1 -1
- package/dist/ir/sdk-model.js +1 -1
- package/dist/ir/slots.d.ts +3 -3
- package/dist/ir/slots.js +10 -10
- package/dist/release/bootstrap.js +1 -1
- package/dist/release/bump-command.js +1 -1
- package/dist/release/cli.d.ts +4 -4
- package/dist/release/cli.js +6 -6
- package/dist/release/context.d.ts +1 -1
- package/dist/release/context.js +1 -1
- package/dist/release/digest.d.ts +1 -1
- package/dist/release/digest.js +2 -2
- package/dist/release/index.d.ts +1 -1
- package/dist/release/load.js +1 -1
- package/dist/release/manifest.js +1 -1
- package/dist/release/registries.js +3 -3
- package/dist/release/release-workflow.js +1 -1
- package/dist/release/spec-gate.d.ts +2 -2
- package/dist/release/spec-gate.js +2 -2
- package/dist/release/sync-command.d.ts +1 -1
- package/dist/release/sync-command.js +1 -1
- package/dist/release/sync-tree.js +1 -1
- package/dist/release/types.d.ts +6 -6
- package/dist/runtime/cli/body.go +1 -1
- package/dist/runtime/cli/config.go +3 -3
- package/dist/runtime/cli/discovery.go +1 -1
- package/dist/runtime/cli/format.go +1 -1
- package/dist/runtime/cli/log.go +1 -1
- package/dist/runtime/cli/output.go +1 -1
- package/dist/runtime/cli/params.go +1 -1
- package/dist/runtime/cli/run.go +1 -1
- package/dist/runtime/cli/socket.go +1 -1
- package/dist/runtime/cli/stream.go +1 -1
- package/dist/runtime/cli/target.go +1 -1
- package/dist/runtime/csharp/Adapters.cs +2 -2
- package/dist/runtime/csharp/Auth.cs +2 -2
- package/dist/runtime/csharp/Body.cs +3 -3
- package/dist/runtime/csharp/Config.cs +2 -2
- package/dist/runtime/csharp/Envelope.cs +3 -3
- package/dist/runtime/csharp/Errors.cs +10 -10
- package/dist/runtime/csharp/Events.cs +2 -2
- package/dist/runtime/csharp/Exchange.cs +4 -4
- package/dist/runtime/csharp/Handler.cs +3 -3
- package/dist/runtime/csharp/Hooks.cs +3 -3
- package/dist/runtime/csharp/Invalidation.cs +2 -2
- package/dist/runtime/csharp/Json.cs +2 -2
- package/dist/runtime/csharp/Log.cs +2 -2
- package/dist/runtime/csharp/Operation.cs +2 -2
- package/dist/runtime/csharp/Path.cs +2 -2
- package/dist/runtime/csharp/Query.cs +2 -2
- package/dist/runtime/csharp/Realtime.cs +2 -2
- package/dist/runtime/csharp/RealtimeLoop.cs +3 -3
- package/dist/runtime/csharp/Redirect.cs +2 -2
- package/dist/runtime/csharp/Result.cs +2 -2
- package/dist/runtime/csharp/Sse.cs +2 -2
- package/dist/runtime/csharp/Stale.cs +2 -2
- package/dist/runtime/csharp/Transport.cs +2 -2
- package/dist/runtime/csharp/TransportLongPoll.cs +2 -2
- package/dist/runtime/csharp/TransportSse.cs +2 -2
- package/dist/runtime/csharp/TransportWs.cs +2 -2
- package/dist/runtime/csharp/Wire.cs +2 -2
- package/dist/runtime/csharp/Ws.cs +2 -2
- package/dist/runtime/csharp/WsDial.cs +2 -2
- package/dist/runtime/go/auth.go +1 -1
- package/dist/runtime/go/body.go +2 -2
- package/dist/runtime/go/config.go +1 -1
- package/dist/runtime/go/errors.go +5 -5
- package/dist/runtime/go/export.go +10 -10
- package/dist/runtime/go/hooks.go +2 -2
- package/dist/runtime/go/invalidation.go +2 -2
- package/dist/runtime/go/log.go +1 -1
- package/dist/runtime/go/nullable.go +1 -1
- package/dist/runtime/go/options.go +1 -1
- package/dist/runtime/go/path.go +1 -1
- package/dist/runtime/go/query.go +2 -2
- package/dist/runtime/go/realtime.go +4 -4
- package/dist/runtime/go/realtime_loop.go +1 -1
- package/dist/runtime/go/redirect.go +2 -2
- package/dist/runtime/go/request.go +9 -9
- package/dist/runtime/go/result.go +2 -2
- package/dist/runtime/go/sse.go +3 -3
- package/dist/runtime/go/stale.go +1 -1
- package/dist/runtime/go/stream.go +2 -2
- package/dist/runtime/go/transport.go +2 -2
- package/dist/runtime/go/transport_longpoll.go +1 -1
- package/dist/runtime/go/transport_sse.go +2 -2
- package/dist/runtime/go/ws.go +1 -1
- package/dist/runtime/java/Answer.java +2 -2
- package/dist/runtime/java/ApiException.java +2 -2
- package/dist/runtime/java/BinaryBody.java +2 -2
- package/dist/runtime/java/Body.java +4 -4
- package/dist/runtime/java/Call.java +2 -2
- package/dist/runtime/java/CallLog.java +2 -2
- package/dist/runtime/java/ClientConfig.java +2 -2
- package/dist/runtime/java/ConnectionState.java +2 -2
- package/dist/runtime/java/Credential.java +2 -2
- package/dist/runtime/java/Deadline.java +2 -2
- package/dist/runtime/java/Decode.java +2 -2
- package/dist/runtime/java/Envelope.java +2 -2
- package/dist/runtime/java/ErrorEnvelope.java +3 -3
- package/dist/runtime/java/EventStream.java +2 -2
- package/dist/runtime/java/Exchange.java +2 -2
- package/dist/runtime/java/FilePart.java +2 -2
- package/dist/runtime/java/Flight.java +3 -3
- package/dist/runtime/java/Hooks.java +3 -3
- package/dist/runtime/java/Hops.java +2 -2
- package/dist/runtime/java/{HoneyException.java → HttpException.java} +4 -4
- package/dist/runtime/java/InvalidationConfig.java +2 -2
- package/dist/runtime/java/Json.java +3 -3
- package/dist/runtime/java/Keepalive.java +2 -2
- package/dist/runtime/java/LogEntry.java +2 -2
- package/dist/runtime/java/LongPollAdapter.java +2 -2
- package/dist/runtime/java/Operation.java +2 -2
- package/dist/runtime/java/Opt.java +2 -2
- package/dist/runtime/java/Pump.java +2 -2
- package/dist/runtime/java/RawResponse.java +2 -2
- package/dist/runtime/java/Realtime.java +2 -2
- package/dist/runtime/java/RealtimeLoop.java +4 -4
- package/dist/runtime/java/RedirectPolicy.java +2 -2
- package/dist/runtime/java/Redirects.java +2 -2
- package/dist/runtime/java/RequestContext.java +2 -2
- package/dist/runtime/java/RequestHook.java +2 -2
- package/dist/runtime/java/RequestOptions.java +2 -2
- package/dist/runtime/java/ResponseContext.java +2 -2
- package/dist/runtime/java/ResponseHook.java +2 -2
- package/dist/runtime/java/Result.java +2 -2
- package/dist/runtime/java/ResumableConnection.java +2 -2
- package/dist/runtime/java/SdkException.java +3 -3
- package/dist/runtime/java/Socket.java +2 -2
- package/dist/runtime/java/Sse.java +2 -2
- package/dist/runtime/java/SseAdapter.java +2 -2
- package/dist/runtime/java/SseEvent.java +2 -2
- package/dist/runtime/java/StaleMeta.java +2 -2
- package/dist/runtime/java/StaleTracker.java +2 -2
- package/dist/runtime/java/Transport.java +2 -2
- package/dist/runtime/java/TransportAdapter.java +2 -2
- package/dist/runtime/java/TransportConnection.java +2 -2
- package/dist/runtime/java/TransportKind.java +2 -2
- package/dist/runtime/java/TransportMessage.java +2 -2
- package/dist/runtime/java/TransportOptions.java +2 -2
- package/dist/runtime/java/TypedWebSocket.java +2 -2
- package/dist/runtime/java/UrlPath.java +2 -2
- package/dist/runtime/java/UrlQuery.java +2 -2
- package/dist/runtime/java/WsAdapter.java +2 -2
- package/dist/runtime/java/WsClose.java +2 -2
- package/dist/runtime/java/WsDial.java +2 -2
- package/dist/runtime/java/WsMessage.java +2 -2
- package/dist/runtime/mcp/call.ts +3 -3
- package/dist/runtime/mcp/result.ts +2 -2
- package/dist/runtime/python/__init__.py +1 -1
- package/dist/runtime/python/auth.py +1 -1
- package/dist/runtime/python/body.py +1 -1
- package/dist/runtime/python/config.py +1 -1
- package/dist/runtime/python/errors.py +11 -11
- package/dist/runtime/python/events.py +4 -4
- package/dist/runtime/python/exchange.py +1 -1
- package/dist/runtime/python/hooks.py +4 -4
- package/dist/runtime/python/invalidation.py +1 -1
- package/dist/runtime/python/log.py +1 -1
- package/dist/runtime/python/operation.py +1 -1
- package/dist/runtime/python/path.py +1 -1
- package/dist/runtime/python/query.py +1 -1
- package/dist/runtime/python/realtime.py +5 -5
- package/dist/runtime/python/redirect.py +1 -1
- package/dist/runtime/python/result.py +1 -1
- package/dist/runtime/python/send_async.py +4 -4
- package/dist/runtime/python/send_sync.py +3 -3
- package/dist/runtime/python/sse.py +1 -1
- package/dist/runtime/python/stale.py +1 -1
- package/dist/runtime/python/transport.py +1 -1
- package/dist/runtime/python/transport_longpoll.py +1 -1
- package/dist/runtime/python/transport_sse.py +1 -1
- package/dist/runtime/python/transport_ws.py +1 -1
- package/dist/runtime/python/ws.py +3 -3
- package/dist/runtime/rust/Cargo.lock +1 -1
- package/dist/runtime/rust/answer.rs +1 -1
- package/dist/runtime/rust/auth.rs +1 -1
- package/dist/runtime/rust/body.rs +2 -2
- package/dist/runtime/rust/call.rs +1 -1
- package/dist/runtime/rust/config.rs +1 -1
- package/dist/runtime/rust/envelope.rs +3 -3
- package/dist/runtime/rust/errors.rs +3 -3
- package/dist/runtime/rust/events.rs +1 -1
- package/dist/runtime/rust/exchange.rs +1 -1
- package/dist/runtime/rust/hooks.rs +1 -1
- package/dist/runtime/rust/invalidation.rs +1 -1
- package/dist/runtime/rust/log.rs +1 -1
- package/dist/runtime/rust/nullable.rs +1 -1
- package/dist/runtime/rust/path.rs +1 -1
- package/dist/runtime/rust/query.rs +1 -1
- package/dist/runtime/rust/realtime.rs +1 -1
- package/dist/runtime/rust/realtime_loop.rs +1 -1
- package/dist/runtime/rust/redirect.rs +1 -1
- package/dist/runtime/rust/request.rs +1 -1
- package/dist/runtime/rust/result.rs +1 -1
- package/dist/runtime/rust/sse.rs +1 -1
- package/dist/runtime/rust/stale.rs +1 -1
- package/dist/runtime/rust/transport.rs +1 -1
- package/dist/runtime/rust/transport_longpoll.rs +1 -1
- package/dist/runtime/rust/transport_sse.rs +1 -1
- package/dist/runtime/rust/transport_ws.rs +1 -1
- package/dist/runtime/rust/ws.rs +1 -1
- package/dist/runtime/ts/app-types.ts +5 -5
- package/dist/runtime/ts/app.ts +5 -5
- package/dist/runtime/ts/http.ts +3 -3
- package/dist/runtime/ts/path.ts +1 -1
- package/dist/runtime/ts/request.ts +1 -1
- package/dist/runtime/ts/sdk.ts +1 -1
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The vendored C# runtime, as the files a C# SDK ships under `Runtime/` (H9/F5): `runtime/csharp/*.cs`, read here
|
|
3
|
-
* and nowhere else (the F8 mutation target), each emitted as committed but for its one `namespace
|
|
3
|
+
* and nowhere else (the F8 mutation target), each emitted as committed but for its one `namespace Http.Runtime;`
|
|
4
4
|
* line, which becomes the SDK's own namespace (Fb2), so `using <RootNamespace>;` reaches the client, the config,
|
|
5
5
|
* the exceptions and the models alike. Every API ships the core, SSE among it; a WebSocket or realtime API adds the
|
|
6
6
|
* socket and its dial, and a realtime API the adapters and the connection (contract 50 §2).
|
|
@@ -45,7 +45,7 @@ const REALTIME = [
|
|
|
45
45
|
"TransportWs",
|
|
46
46
|
];
|
|
47
47
|
/* the one line each committed file holds, swapped for the SDK's namespace */
|
|
48
|
-
const NAMESPACE = /^namespace
|
|
48
|
+
const NAMESPACE = /^namespace Http\.Runtime;$/m;
|
|
49
49
|
/* a top-level type at column 0: its modifiers, its kind, its name (type parameters after it are not part of it) */
|
|
50
50
|
const TOP_LEVEL = /^(?:(?:public|internal|file|sealed|abstract|static|readonly|partial|unsafe)\s+)*(?:record\s+struct|record\s+class|class|record|struct|enum|interface)\s+([A-Za-z_]\w*)/gm;
|
|
51
51
|
/** The runtime file names an SDK with `features` ships, `.cs` included, in code-unit order. */
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* and a value stay three states; an open value is a bare `JsonElement`, already tri-state. A property spelling a
|
|
6
6
|
* member every record has, or the record's own name (CS0542), moves on to `…2`. An allOf is one record of its
|
|
7
7
|
* parts' fields, a key once, its first part's (Python's merge). An object that declares `additionalProperties`
|
|
8
|
-
* beside its fields keeps every other member in `[JsonExtensionData] Extra`, JsonElement-valued (
|
|
8
|
+
* beside its fields keeps every other member in `[JsonExtensionData] Extra`, JsonElement-valued (clients-a8's ruling,
|
|
9
9
|
* Rust's flattened map), claimed after the fields: `{ get; set; }`, since an init-only one goes through the
|
|
10
10
|
* deserialization constructor, which extension data cannot bind to.
|
|
11
11
|
*/
|
|
@@ -81,7 +81,7 @@ function newClient(root, ir, twins, types) {
|
|
|
81
81
|
const [doc, fallback] = server === undefined
|
|
82
82
|
? [
|
|
83
83
|
"Config.BaseURL is required: the API declares no server.",
|
|
84
|
-
`panic(${goString("
|
|
84
|
+
`panic(${goString("httpsdk: Config.BaseURL is empty and the API declares no server")})`,
|
|
85
85
|
]
|
|
86
86
|
: [`An empty Config.BaseURL defaults to the API's first server, ${server}.`, `cfg.BaseURL = ${goString(server)}`];
|
|
87
87
|
return [
|
package/dist/emit/go/sdk.js
CHANGED
|
@@ -17,7 +17,7 @@ import { goModulePath } from "./module-path.js";
|
|
|
17
17
|
import { clientDecls } from "./sdk-client.js";
|
|
18
18
|
import { goTopLevel, goTypeContext } from "./types.js";
|
|
19
19
|
/* the marker gopls and linters read, apart from the package doc by a blank line */
|
|
20
|
-
const MARKER = "// Code generated by
|
|
20
|
+
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
21
21
|
/* the WebSocket library and its go.sum lines, as the Go checksum database has them; the CLI's module requires them too */
|
|
22
22
|
export const WEBSOCKET = "github.com/coder/websocket v1.8.15";
|
|
23
23
|
export const WEBSOCKET_SUM = [
|
|
@@ -20,21 +20,21 @@ const STATUSES = [
|
|
|
20
20
|
];
|
|
21
21
|
/** The non-status errors: their base class, and their constructor's parameters after the message. */
|
|
22
22
|
const OTHER = [
|
|
23
|
-
{ base: "
|
|
23
|
+
{ base: "HttpException", cause: true, doc: "The call ran past its timeout.", name: "ApiTimeoutException" },
|
|
24
24
|
{
|
|
25
|
-
base: "
|
|
25
|
+
base: "HttpException",
|
|
26
26
|
cause: true,
|
|
27
27
|
doc: "No answer: the connection failed or broke.",
|
|
28
28
|
name: "ApiConnectionException",
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
|
-
base: "
|
|
31
|
+
base: "HttpException",
|
|
32
32
|
cause: false,
|
|
33
33
|
doc: "A path param that is empty, `.` or `..`: nothing is sent.",
|
|
34
34
|
name: "PathParamException",
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
|
-
base: "
|
|
37
|
+
base: "HttpException",
|
|
38
38
|
cause: false,
|
|
39
39
|
doc: "A client or call configured in a way it cannot send.",
|
|
40
40
|
name: "ConfigException",
|
|
@@ -46,7 +46,7 @@ const OTHER = [
|
|
|
46
46
|
name: "DecodeException",
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
base: "
|
|
49
|
+
base: "HttpException",
|
|
50
50
|
cause: true,
|
|
51
51
|
doc: "A hook or the auth refresh threw; its error is the cause.",
|
|
52
52
|
name: "HookException",
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* answers the type and throws an error status; its twin on the client's `safe()` mirror is sdk-mirror.ts's (bit 21 i6).
|
|
5
5
|
* A body is sent by its declared media type:
|
|
6
6
|
* JSON as the mapper writes it, a form urlencoded, text as its raw bytes, binary as sized bytes or a one-shot stream,
|
|
7
|
-
* multipart as hand-built parts under a `
|
|
7
|
+
* multipart as hand-built parts under a `clients-<uuid>` boundary.
|
|
8
8
|
*/
|
|
9
9
|
import type { IRSchema } from "../../ir/model.ts";
|
|
10
10
|
import type { SdkOp } from "../../ir/sdk-model.ts";
|
package/dist/emit/java/sdk.js
CHANGED
|
@@ -20,9 +20,9 @@ import { WS_FILES } from "./ws.js";
|
|
|
20
20
|
import { sdkModel } from "../../ir/sdk-model.js";
|
|
21
21
|
import { toIR } from "../../ir/build.js";
|
|
22
22
|
/** The marker on line 1 of every emitted file. */
|
|
23
|
-
const MARKER = "// @generated by
|
|
23
|
+
const MARKER = "// @generated by clients. DO NOT EDIT.";
|
|
24
24
|
/* the package line of every vendored runtime file */
|
|
25
|
-
const RUNTIME_PACKAGE = /^package
|
|
25
|
+
const RUNTIME_PACKAGE = /^package http\.runtime;$/m;
|
|
26
26
|
/** The validated package for `options`. */
|
|
27
27
|
function packageOf(options) {
|
|
28
28
|
const groupId = validateGroupId(options.groupId ?? "com.example");
|
|
@@ -93,7 +93,7 @@ const OPERATION_FILES = [
|
|
|
93
93
|
"Exchange",
|
|
94
94
|
"Flight",
|
|
95
95
|
"FilePart",
|
|
96
|
-
"
|
|
96
|
+
"HttpException",
|
|
97
97
|
"Hops",
|
|
98
98
|
"Hooks",
|
|
99
99
|
"LogEntry",
|
package/dist/emit/mcp/files.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A tool's file argument as its inputSchema shows it (bit 21 c): the provisional file-uploads extension's FileInput
|
|
3
3
|
* (its draft at PR head 6101d34), an object schema marked `x-mcp-file` requiring the members the draft
|
|
4
|
-
* requires (id, mimeType, size, digest), the digest's algorithm SHA-256; or
|
|
4
|
+
* requires (id, mimeType, size, digest), the digest's algorithm SHA-256; or clients' `{path}`, a file the stdio server
|
|
5
5
|
* reads under its root. Members a type alone would state are not declared (a host taking the extension knows them, and
|
|
6
6
|
* a model is not to see them): runtime/mcp/files.ts checks the values, 38 tokens a file argument spared. A mounted
|
|
7
7
|
* tool's (bit 21 g) takes an https URL in place of the path. The emitter's half of the extension: its keyword is named
|
package/dist/emit/mcp/mounted.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The MCP handler an app mounts (bit 21 e, H24.3): the
|
|
2
|
+
* The MCP handler an app mounts (bit 21 e, H24.3): the backend plugin's `codegen.mcp` output, from the app's own
|
|
3
3
|
* document. Its entry holds the tool table and the handler (`mcpHandler`) over the portable runtime and the API's own
|
|
4
4
|
* TS SDK, each in the companion directory beside it; @workerstack/backend/mcp's `mcp(app, path, mcpHandler)` mounts it.
|
|
5
5
|
* Each call runs in-process through the app. The handler is `secured` when any tool's operation requires a credential
|
|
@@ -15,7 +15,7 @@ import { literal } from "./literal.js";
|
|
|
15
15
|
import { MCP_PORTABLE, mcpRuntimeSource } from "./runtime.js";
|
|
16
16
|
import { resolved } from "./server.js";
|
|
17
17
|
import { isTool, toolsOf, untoolable } from "./tools.js";
|
|
18
|
-
const MARKER = "// Code generated by
|
|
18
|
+
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
19
19
|
/* a directory name a relative import names */
|
|
20
20
|
const DIR = /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/;
|
|
21
21
|
/** `op`'s security requirements: its own, else the document's. */
|
package/dist/emit/mcp/runtime.js
CHANGED
|
@@ -37,7 +37,7 @@ export const MCP_STANDALONE = [
|
|
|
37
37
|
];
|
|
38
38
|
/* an import of a sibling runtime module, on one line or several */
|
|
39
39
|
const SIBLING_IMPORT = /^import\s+(?:type\s+)?\{[^}]*\}\s+from\s+"\.\/[\w-]+\.ts"\n/gm;
|
|
40
|
-
const MARKER = "// Code generated by
|
|
40
|
+
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
41
41
|
/** The vendored runtime as one module: `names` (the standalone package's by default) in order, sibling imports dropped. */
|
|
42
42
|
export function mcpRuntimeSource(names = MCP_STANDALONE) {
|
|
43
43
|
const modules = names.map((name) => readFileSync(new URL(`../../runtime/mcp/${name}.ts`, import.meta.url), "utf8")
|
package/dist/emit/mcp/server.js
CHANGED
|
@@ -21,7 +21,7 @@ const NAME = /^(?=.{1,60}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
|
21
21
|
const ENV_PREFIX = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
22
22
|
/* a server name as the MCP registry's server.json schema (2025-12-11) takes it: a reverse-DNS namespace, `/`, a name */
|
|
23
23
|
const MCP_NAME = /^(?=.{3,200}$)[a-zA-Z0-9.-]+\/[a-zA-Z0-9._-]+$/;
|
|
24
|
-
const MARKER = "// Code generated by
|
|
24
|
+
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
25
25
|
/** The options with their defaults filled, each refused unless it matches its grammar (F2). */
|
|
26
26
|
export function resolved(options, title) {
|
|
27
27
|
const name = options.name ?? binaryNameOf(title);
|
|
@@ -13,7 +13,7 @@ function envelopeKeys(model) {
|
|
|
13
13
|
}));
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Every declared key in code-unit order with its schema: `x-
|
|
16
|
+
* Every declared key in code-unit order with its schema: `x-backend-errors`' (the first operation by id to declare
|
|
17
17
|
* the key, so the document's path order never changes it), then an envelope's keys, which carry none (Rust's rule).
|
|
18
18
|
*/
|
|
19
19
|
function declaredKeys(model) {
|
|
@@ -117,8 +117,8 @@ const plansIn = (node, accessors) => [
|
|
|
117
117
|
];
|
|
118
118
|
/** The client's title line: the API's title, through the escape layer. */
|
|
119
119
|
export const clientTitle = (ir) => pyDocLines(ir.info.title === undefined
|
|
120
|
-
? "The API's client, generated by
|
|
121
|
-
: `The ${ir.info.title} client, generated by
|
|
120
|
+
? "The API's client, generated by clients."
|
|
121
|
+
: `The ${ir.info.title} client, generated by clients.`)[0];
|
|
122
122
|
/**
|
|
123
123
|
* client.py's body for `ir`: the defaults (with the `ErrorKey` the runtime reads a key into), the operations'
|
|
124
124
|
* constants, the resource classes (sync, then async), `SDK` and `AsyncSDK`; and every method's call plan.
|
|
@@ -20,8 +20,8 @@ export const PYTHON_CLASSIFIERS = [
|
|
|
20
20
|
"Programming Language :: Python :: 3.14",
|
|
21
21
|
"Typing :: Typed",
|
|
22
22
|
];
|
|
23
|
-
/*
|
|
24
|
-
const MANIFEST = ".
|
|
23
|
+
/* clients' own record of what it wrote (gen/write.ts MANIFEST), which no sdist ships */
|
|
24
|
+
const MANIFEST = ".clients-generated.json";
|
|
25
25
|
/** The lowest httpx2 every emitted package accepts. */
|
|
26
26
|
export const HTTPX2_FLOOR = "2.12.0";
|
|
27
27
|
/** The dependency string every emitted package declares (`httpx2[ws]` when it needs WebSockets). */
|
|
@@ -30,7 +30,7 @@ export const HTTPX2 = `httpx2>=${HTTPX2_FLOOR},<3`;
|
|
|
30
30
|
const KEYWORDS = " False None True and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield match case type _ ";
|
|
31
31
|
/** `name` when it is an import name a package may take: lower snake case, no keyword, not the runtime's. */
|
|
32
32
|
export function validatePackageName(name) {
|
|
33
|
-
if (!/^[a-z][a-z0-9_]*$/.test(name) || KEYWORDS.includes(` ${name} `) || name === "
|
|
33
|
+
if (!/^[a-z][a-z0-9_]*$/.test(name) || KEYWORDS.includes(` ${name} `) || name === "_http") {
|
|
34
34
|
throw new Error(`Invalid package name: "${name}"`);
|
|
35
35
|
}
|
|
36
36
|
return name;
|
|
@@ -80,7 +80,7 @@ function urls(metadata) {
|
|
|
80
80
|
export function pyproject(pkg, ws, metadata = {}) {
|
|
81
81
|
const dependency = ws ? HTTPX2.replace("httpx2", "httpx2[ws]") : HTTPX2;
|
|
82
82
|
return [
|
|
83
|
-
"# @generated by
|
|
83
|
+
"# @generated by clients. DO NOT EDIT.",
|
|
84
84
|
"[build-system]",
|
|
85
85
|
'requires = ["hatchling>=1.27"]',
|
|
86
86
|
'build-backend = "hatchling.build"',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PythonCallPlan } from "./sdk-plan.ts";
|
|
2
2
|
import { type Metadata, type PackageIdentity } from "../shared/metadata.ts";
|
|
3
3
|
export type PythonSdkOptions = {
|
|
4
|
-
/** the import name; `
|
|
4
|
+
/** the import name; `http_sdk` by default, its distribution name with `-` for `_` */
|
|
5
5
|
readonly packageName?: string;
|
|
6
6
|
/** the package version; `0.1.0` by default */
|
|
7
7
|
readonly version?: string;
|
package/dist/emit/python/sdk.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* `src/<pkg>/types.py` (every component, then every hoisted declaration, in name order, then the `ErrorKey`
|
|
4
4
|
* StrEnum when the API declares error keys), `client.py` (the
|
|
5
5
|
* resource classes and the `SDK` and `AsyncSDK` clients, each with its `safe` mirror), `__init__.py` (the package
|
|
6
|
-
* root's exports), an empty `py.typed`, and the vendored runtime under `
|
|
6
|
+
* root's exports), an empty `py.typed`, and the vendored runtime under `_http/`. Every `.py` file and the manifest
|
|
7
7
|
* carry the marker. A client always raises; `client.safe` answers the same calls as a `Result` (bit 21 i2), so there
|
|
8
8
|
* is no error-mode option.
|
|
9
9
|
*/
|
|
@@ -19,8 +19,8 @@ import { pyproject, validatePackageName, validateVersion } from "./sdk-pyproject
|
|
|
19
19
|
import { needsWebSocket, runtimeExports, runtimeFiles } from "./transport.js";
|
|
20
20
|
import { pyTopLevel, pyTypeContext } from "./types.js";
|
|
21
21
|
/* the marker ruff, mypy and linguist read */
|
|
22
|
-
const MARKER = "# @generated by
|
|
23
|
-
/* where client.py imports each runtime name from, under `.
|
|
22
|
+
const MARKER = "# @generated by clients. DO NOT EDIT.";
|
|
23
|
+
/* where client.py imports each runtime name from, under `._http.` */
|
|
24
24
|
const RUNTIME = {
|
|
25
25
|
AsyncRealtimeTransport: "realtime",
|
|
26
26
|
AsyncTransport: "send_async",
|
|
@@ -60,9 +60,9 @@ const spelled = (text) => new Set(Array.from(text.replace(/"""[\s\S]*?"""|"(?:[^
|
|
|
60
60
|
function clientFile(ir, env, body) {
|
|
61
61
|
const doc = pyDocLines([clientTitle(ir), ir.info.description].filter((part) => part !== undefined).join("\n\n"));
|
|
62
62
|
const used = spelled(body.lines.join("\n"));
|
|
63
|
-
const
|
|
63
|
+
const runtimeNames = new Map();
|
|
64
64
|
for (const name of ["ClientConfig", "Defaults", "Safe", "SyncTransport", env.transport, ...env.imports].filter((n) => n in RUNTIME))
|
|
65
|
-
|
|
65
|
+
runtimeNames.set(RUNTIME[name], [...(runtimeNames.get(RUNTIME[name]) ?? []), name]);
|
|
66
66
|
const sections = [
|
|
67
67
|
["from __future__ import annotations"],
|
|
68
68
|
[
|
|
@@ -71,9 +71,9 @@ function clientFile(ir, env, body) {
|
|
|
71
71
|
...importLine("typing", [...env.at.typing, "Self"]),
|
|
72
72
|
],
|
|
73
73
|
[
|
|
74
|
-
...[...
|
|
74
|
+
...[...runtimeNames.keys()]
|
|
75
75
|
.sort(compareCodeUnits)
|
|
76
|
-
.flatMap((module) => importLine(`.
|
|
76
|
+
.flatMap((module) => importLine(`._http.${module}`, runtimeNames.get(module))),
|
|
77
77
|
...importLine(".types", body.types.filter((name) => used.has(name))),
|
|
78
78
|
],
|
|
79
79
|
];
|
|
@@ -83,7 +83,7 @@ function clientFile(ir, env, body) {
|
|
|
83
83
|
function initFile(ir, runtime, types) {
|
|
84
84
|
const modules = Object.entries(runtime).map(([file, source]) => [file.replace(/\.py$/, ""), runtimeExports(source)]);
|
|
85
85
|
const lines = [
|
|
86
|
-
...modules.flatMap(([module, names]) => importLine(`.
|
|
86
|
+
...modules.flatMap(([module, names]) => importLine(`._http.${module}`, names)),
|
|
87
87
|
...importLine(".client", ["SDK", "AsyncSDK"]),
|
|
88
88
|
...importLine(".types", types),
|
|
89
89
|
];
|
|
@@ -93,7 +93,7 @@ function initFile(ir, runtime, types) {
|
|
|
93
93
|
/** The package's files for `document`, and the call plan of every method in them. */
|
|
94
94
|
function emitPython(document, options, metadata = {}) {
|
|
95
95
|
const pkg = {
|
|
96
|
-
name: validatePackageName(options.packageName ?? "
|
|
96
|
+
name: validatePackageName(options.packageName ?? "http_sdk"),
|
|
97
97
|
version: validateVersion(options.version ?? "0.1.0"),
|
|
98
98
|
};
|
|
99
99
|
const ir = toIR(document, { deriveOperationIds: true });
|
|
@@ -133,9 +133,9 @@ function emitPython(document, options, metadata = {}) {
|
|
|
133
133
|
[`${root}/types.py`]: pyFile([typesDoc[0]], [
|
|
134
134
|
["from __future__ import annotations"],
|
|
135
135
|
[...(errorKey === null ? [] : ["from enum import StrEnum"]), ...importLine("typing", at.typing)],
|
|
136
|
-
importLine(".
|
|
136
|
+
importLine("._http.body", env.typesImports),
|
|
137
137
|
], decls.map(([, text]) => text)),
|
|
138
|
-
...Object.fromEntries(Object.entries(runtime).map(([name, source]) => [`${root}/
|
|
138
|
+
...Object.fromEntries(Object.entries(runtime).map(([name, source]) => [`${root}/_http/${name}`, source])),
|
|
139
139
|
};
|
|
140
140
|
const sorted = Object.fromEntries(Object.entries(files).sort(([a], [b]) => compareCodeUnits(a, b)));
|
|
141
141
|
return { files: sorted, notices: env.notices, pkg, plans: client.plans };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The vendored Python runtime, as the files a Python SDK ships under `src/<pkg>/
|
|
2
|
+
* The vendored Python runtime, as the files a Python SDK ships under `src/<pkg>/_http/` (H9/F5):
|
|
3
3
|
* `runtime/python/*.py`, read here and nowhere else (the F8 mutation target), emitted verbatim. The WebSocket
|
|
4
4
|
* module ships for a WebSocket or realtime API and the realtime modules for a realtime API, so a plain HTTP SDK
|
|
5
5
|
* carries neither them nor the `httpx2[ws]` extra.
|
package/dist/emit/rust/errors.js
CHANGED
|
@@ -13,7 +13,7 @@ function envelopeKeys(model) {
|
|
|
13
13
|
}));
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Every declared key in code-unit order with its schema: `x-
|
|
16
|
+
* Every declared key in code-unit order with its schema: `x-backend-errors`' (the first operation by id to
|
|
17
17
|
* declare the key, so the document's path order never changes it), then an envelope's keys, which carry none.
|
|
18
18
|
*/
|
|
19
19
|
function declaredKeys(model) {
|
|
@@ -86,7 +86,7 @@ const TAIL = [
|
|
|
86
86
|
"}",
|
|
87
87
|
"",
|
|
88
88
|
"impl crate::ApiError {",
|
|
89
|
-
" ///
|
|
89
|
+
" /// backend's error key in the body: the declared one it names, else `Other`; `None` without one.",
|
|
90
90
|
" pub fn key(&self) -> Option<ErrorKey> {",
|
|
91
91
|
" self.raw_key().map(ErrorKey::from)",
|
|
92
92
|
" }",
|
|
@@ -29,7 +29,7 @@ const DEPENDENCIES = [
|
|
|
29
29
|
[WEBSOCKET, '{ version = "0.30.0", default-features = false, features = ["connect", "rustls-tls-native-roots"] }'],
|
|
30
30
|
["url", '"2.5.8"'],
|
|
31
31
|
];
|
|
32
|
-
const MARKER = "# @generated by
|
|
32
|
+
const MARKER = "# @generated by clients. DO NOT EDIT.";
|
|
33
33
|
/* a semver version: it lands inside a TOML string, so nothing else may */
|
|
34
34
|
const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
35
35
|
/* crates.io's keyword: ASCII, a letter or digit first, then letters, digits, `_`, `-` or `+`, at most 20 characters;
|
|
@@ -60,7 +60,7 @@ export function crateIdentity(options) {
|
|
|
60
60
|
homepage: checked("homepage", options.homepage, HTTPS_URL),
|
|
61
61
|
keywords: listed("keywords", options.keywords, CRATE_KEYWORD),
|
|
62
62
|
license: checked("license", options.license, SPDX_EXPRESSION),
|
|
63
|
-
name: validateCrateName(options.crateName ?? "
|
|
63
|
+
name: validateCrateName(options.crateName ?? "http-sdk"),
|
|
64
64
|
repository: checked("repository", options.repository, HTTPS_URL),
|
|
65
65
|
version: validateCrateVersion(options.version ?? "0.1.0"),
|
|
66
66
|
};
|
|
@@ -106,7 +106,7 @@ export function cargoToml(crate, ws, shipped = NONE_SHIPPED) {
|
|
|
106
106
|
...metadata(crate),
|
|
107
107
|
...(shipped.readme ? [`readme = "${README}"`] : []),
|
|
108
108
|
/* what the published crate holds beside Cargo.toml and its lock, which cargo always packs: its README and
|
|
109
|
-
* license file when it ships them;
|
|
109
|
+
* license file when it ships them; clients' manifest and anything else written beside the crate stay out */
|
|
110
110
|
`include = ${toml(["/src", ...(shipped.readme ? [`/${README}`] : []), ...(shipped.licenseFile ? [`/${LICENSE}`] : [])])}`,
|
|
111
111
|
"",
|
|
112
112
|
"[lib]",
|
package/dist/emit/rust/sdk.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type CrateOptions } from "./sdk-cargo.ts";
|
|
|
2
2
|
import { type PackageIdentity, type Shipped } from "../shared/metadata.ts";
|
|
3
3
|
import type { RustCallPlan } from "./sdk-plan.ts";
|
|
4
4
|
/**
|
|
5
|
-
* The crate's options: its name (`
|
|
5
|
+
* The crate's options: its name (`http-sdk` by default), version (`0.1.0` by default) and what crates.io shows,
|
|
6
6
|
* `keywords` and `categories` each a list or the CLI's comma-separated value. `cargo publish` refuses a crate with
|
|
7
7
|
* no description and no license.
|
|
8
8
|
*/
|
package/dist/emit/rust/sdk.js
CHANGED
|
@@ -18,7 +18,7 @@ import { packageOn } from "../shared/metadata.js";
|
|
|
18
18
|
import { clientDecls } from "./sdk-client.js";
|
|
19
19
|
import { rustTopLevel, rustTypeContext } from "./types.js";
|
|
20
20
|
/* the marker rustfmt and linguist read */
|
|
21
|
-
const MARKER = "// @generated by
|
|
21
|
+
const MARKER = "// @generated by clients. DO NOT EDIT.";
|
|
22
22
|
/** Each component's declaration in code-unit order, its description as its rustdoc. */
|
|
23
23
|
function componentDecls(ir, at) {
|
|
24
24
|
return Object.keys(ir.schemas)
|
|
@@ -38,7 +38,7 @@ const rustFile = (doc, decls) => [MARKER, `//! ${doc}`, ...decls.flatMap((decl)
|
|
|
38
38
|
*/
|
|
39
39
|
function libFile(info, runtime, own) {
|
|
40
40
|
const title = info.title === undefined ? "The API's client" : `The ${info.title} client`;
|
|
41
|
-
const doc = [`${title}, generated by
|
|
41
|
+
const doc = [`${title}, generated by clients.`, info.description].filter((part) => part !== undefined);
|
|
42
42
|
const exports = runtime.flatMap(([module, source]) => {
|
|
43
43
|
const items = publicItems(source).sort(compareCodeUnits);
|
|
44
44
|
if (items.length < 2)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* resolve (optional peers, like ts-morph for extract). Without one a file goes out as emitted, which
|
|
5
5
|
* is already valid source.
|
|
6
6
|
*/
|
|
7
|
-
/** The oxfmt options emitted code is formatted with:
|
|
7
|
+
/** The oxfmt options emitted code is formatted with: clients' own style. */
|
|
8
8
|
export type FormatOptions = {
|
|
9
9
|
readonly printWidth: number;
|
|
10
10
|
readonly semi: boolean;
|
|
@@ -76,7 +76,7 @@ export declare const iconName: (path: string) => string;
|
|
|
76
76
|
/** What `metadata` ships beside the code. */
|
|
77
77
|
export declare const shippedOf: (metadata: Metadata) => Shipped;
|
|
78
78
|
/**
|
|
79
|
-
* A registry a generated package publishes to, by the id
|
|
79
|
+
* A registry a generated package publishes to, by the id clients' manifest records it under: `go` is the module proxy
|
|
80
80
|
* (`go install <module>@<version>`), `mcp-registry` the MCP registry.
|
|
81
81
|
*/
|
|
82
82
|
export type Registry = "crates.io" | "go" | "jsr" | "maven-central" | "mcp-registry" | "npm" | "nuget" | "pypi";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HTTP status code →
|
|
2
|
+
* HTTP status code → backend's status key (`201` → `created`), as backend's response vocabulary names
|
|
3
3
|
* them (gen never imports backend, H2). tests/integration/codegen-tables.test.ts answers each key through a real app, so the two cannot drift.
|
|
4
4
|
*/
|
|
5
5
|
export declare const STATUS_KEYS: Readonly<Record<number, string>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HTTP status code →
|
|
2
|
+
* HTTP status code → backend's status key (`201` → `created`), as backend's response vocabulary names
|
|
3
3
|
* them (gen never imports backend, H2). tests/integration/codegen-tables.test.ts answers each key through a real app, so the two cannot drift.
|
|
4
4
|
*/
|
|
5
5
|
export const STATUS_KEYS = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The app-typed front (F1): `createClient<typeof app>(config)`, vendored into an app's `_gen/`. It
|
|
3
|
-
* reads the app's `$routes` phantom structurally (D3), so the files import nothing from
|
|
3
|
+
* reads the app's `$routes` phantom structurally (D3), so the files import nothing from backend.
|
|
4
4
|
*/
|
|
5
5
|
import { FULL_RUNTIME, runtimeSource } from "./http.js";
|
|
6
6
|
const VALUES = [
|
|
@@ -40,7 +40,7 @@ const TYPES = [
|
|
|
40
40
|
"ConnectionState",
|
|
41
41
|
"ErrorEnvelope",
|
|
42
42
|
"FieldError",
|
|
43
|
-
"
|
|
43
|
+
"HttpClient",
|
|
44
44
|
"InferRoutes",
|
|
45
45
|
"LogEntry",
|
|
46
46
|
"OnRequestContext",
|
|
@@ -191,7 +191,7 @@ function routeLine(route, intern) {
|
|
|
191
191
|
parts.push(`mt: ${intern.expr(route.mt)}`);
|
|
192
192
|
return `\t[${intern.expr(route.id)}]: ${parts.length > 0 ? `{ ${parts.join(", ")} }` : "{}"}`;
|
|
193
193
|
}
|
|
194
|
-
const HEAD = `import type { RouteTree, TreeNode } from "@workerstack/backend/tree"
|
|
194
|
+
const HEAD = `import type { RouteTree, TreeNode } from "@workerstack/backend/http/tree"
|
|
195
195
|
|
|
196
196
|
function S<T>(o: Record<string, T>): Record<string, T> {
|
|
197
197
|
return Object.assign(Object.create(null) as Record<string, T>, o)
|
|
@@ -6,10 +6,10 @@ export const RESERVED = [
|
|
|
6
6
|
"Blob",
|
|
7
7
|
"ErrorEnvelope",
|
|
8
8
|
"ErrorField",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
9
|
+
"HttpArgs",
|
|
10
|
+
"HttpCall",
|
|
11
|
+
"HttpSafe",
|
|
12
|
+
"HttpStream",
|
|
13
13
|
"HttpOptions",
|
|
14
14
|
"Omit",
|
|
15
15
|
"Promise",
|
|
@@ -52,7 +52,7 @@ export type WsOptions = { protocols?: string | string[]; reconnectToken?: string
|
|
|
52
52
|
const CALLS = `
|
|
53
53
|
type ErrorField = { error_key: string; message: string; path: string }
|
|
54
54
|
|
|
55
|
-
/**
|
|
55
|
+
/** backend's error envelope at one status, its error keys as literals. */
|
|
56
56
|
export type ErrorEnvelope<TStatus extends number, TKey extends string> = {
|
|
57
57
|
error_key: TKey
|
|
58
58
|
fields: Record<string, ErrorField[]>
|
|
@@ -66,32 +66,32 @@ export type ErrorEnvelope<TStatus extends number, TKey extends string> = {
|
|
|
66
66
|
declare const answer: unique symbol
|
|
67
67
|
|
|
68
68
|
/** A call's input: optional when none of its fields is required. */
|
|
69
|
-
type
|
|
69
|
+
type HttpArgs<I, O> = {} extends I ? [input?: I & O] : [input: I & O]
|
|
70
70
|
|
|
71
71
|
/** A REST operation: its raw overload and its value, an error status thrown; its declared errors and headers. */
|
|
72
|
-
type
|
|
72
|
+
type HttpCall<I, D, E = never, H = never> = {
|
|
73
73
|
(input: I & HttpOptions & { raw: true }): Promise<Response>
|
|
74
|
-
(...input:
|
|
74
|
+
(...input: HttpArgs<I, HttpOptions & { raw?: false }>): Promise<D>
|
|
75
75
|
readonly [answer]?: [E, H]
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/** An event stream, sent when its iteration starts; its opening answer's declared errors. */
|
|
79
|
-
type
|
|
80
|
-
(...input:
|
|
79
|
+
type HttpStream<I, V, E = never> = {
|
|
80
|
+
(...input: HttpArgs<I, SseOptions>): AsyncIterable<V>
|
|
81
81
|
readonly [answer]?: [E, never]
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/** \`client.safe\`: every REST and stream call answering a Result, never throwing an API answer; a connection as is. */
|
|
85
|
-
export type
|
|
85
|
+
export type HttpSafe<T> = {
|
|
86
86
|
[K in keyof T]: `;
|
|
87
87
|
/* the safe mirror's REST and stream arms */
|
|
88
88
|
const SAFE_ARMS = ` ? {
|
|
89
89
|
(input: I & HttpOptions & { raw: true }): Promise<Result<Response, E>>
|
|
90
|
-
(...input:
|
|
90
|
+
(...input: HttpArgs<I, HttpOptions & { raw?: false }>): Promise<Result<D, E, H>>
|
|
91
91
|
}
|
|
92
|
-
: T[K] extends
|
|
93
|
-
? (...input:
|
|
94
|
-
:
|
|
92
|
+
: T[K] extends HttpStream<infer I, infer V, infer E>
|
|
93
|
+
? (...input: HttpArgs<I, SseOptions>) => Promise<Result<AsyncIterable<V>, E>>
|
|
94
|
+
: HttpSafe<T[K]>
|
|
95
95
|
}
|
|
96
96
|
`;
|
|
97
97
|
/** The input fields every call takes, by transport, and the safe twin's types, for an API with `features`. */
|
|
@@ -103,7 +103,7 @@ export function shared(features) {
|
|
|
103
103
|
const realtime = features.realtime
|
|
104
104
|
? `export type RealtimeCallOptions = Omit<HttpOptions, "idempotencyKey" | "timeout"> & RealtimeOptions\n`
|
|
105
105
|
: "";
|
|
106
|
-
const rest = "T[K] extends
|
|
106
|
+
const rest = "T[K] extends HttpCall<infer I, infer D, infer E, infer H>";
|
|
107
107
|
const safe = connections.length === 0
|
|
108
108
|
? rest
|
|
109
109
|
: `T[K] extends (...input: never[]) => ${connections.join(" | ")}\n\t\t? T[K]\n\t\t: ${rest}`;
|
|
@@ -80,7 +80,7 @@ function dataOf(op, types) {
|
|
|
80
80
|
return "Uint8Array<ArrayBuffer>";
|
|
81
81
|
return schema ? irToTs(schema, types) : "unknown";
|
|
82
82
|
}
|
|
83
|
-
/** The declared error bodies by concrete status;
|
|
83
|
+
/** The declared error bodies by concrete status; backend's envelope with its keys as literals. */
|
|
84
84
|
function errorsOf(op, types, resolve) {
|
|
85
85
|
const entries = op.errorStatuses.flatMap((status) => {
|
|
86
86
|
const response = op.ir.responses[String(status)];
|
|
@@ -102,7 +102,7 @@ function headersOf(op) {
|
|
|
102
102
|
const fields = [...byName].sort(([a], [b]) => compareCodeUnits(a, b));
|
|
103
103
|
return objectText(fields.map(([name, required]) => `${quoteKey(name)}${required ? "" : "?"}: string`));
|
|
104
104
|
}
|
|
105
|
-
/** `op`'s member line `name`: a REST call a
|
|
105
|
+
/** `op`'s member line `name`: a REST call a HttpCall, a stream a HttpStream, defaults dropped; a connection its method. */
|
|
106
106
|
function signature(name, op, ctx) {
|
|
107
107
|
const input = inputOf(op, ctx);
|
|
108
108
|
const arg = (extra) => {
|
|
@@ -122,11 +122,11 @@ function signature(name, op, ctx) {
|
|
|
122
122
|
if (sse) {
|
|
123
123
|
const events = sseEventSchema(op.ir, ctx.resolve);
|
|
124
124
|
const event = events === undefined ? "SSEEvent" : `SSEEvent<${irToTs(events, ctx.types)}>`;
|
|
125
|
-
return `${key}:
|
|
125
|
+
return `${key}: HttpStream<${[input.type, event, ...(errors === null ? [] : [errors])].join(", ")}>`;
|
|
126
126
|
}
|
|
127
127
|
const headers = headersOf(op);
|
|
128
128
|
const tail = headers === null ? (errors === null ? [] : [errors]) : [errors ?? "never", headers];
|
|
129
|
-
return `${key}:
|
|
129
|
+
return `${key}: HttpCall<${[input.type, dataOf(op, ctx.types), ...tail].join(", ")}>`;
|
|
130
130
|
}
|
|
131
131
|
/* every line break a comment splits at, as the shared comment writers split (escape.ts) */
|
|
132
132
|
const LINE_BREAKS = /\r\n|\r|\n|\u2028|\u2029/;
|
|
@@ -184,7 +184,7 @@ function configText(name, server, runtimeConfig) {
|
|
|
184
184
|
export function sdkTypesText(ir, name, runtime) {
|
|
185
185
|
const model = sdkModel(ir);
|
|
186
186
|
/* the SDK named `SDK` declares `SDKConfig`, so the runtime's own is imported under another name */
|
|
187
|
-
const aliases = name === "SDK" ? { SDKConfig: "
|
|
187
|
+
const aliases = name === "SDK" ? { SDKConfig: "HttpSDKConfig" } : {};
|
|
188
188
|
const runtimeConfig = aliases["SDKConfig"] ?? "SDKConfig";
|
|
189
189
|
const own = [
|
|
190
190
|
name,
|
|
@@ -206,7 +206,7 @@ ${members(memberTree(ir.tree), ctx, "\t").join("\n")}
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
/** \`client.safe\`: every operation, a call answering a Result. */
|
|
209
|
-
export type ${name}Safe =
|
|
209
|
+
export type ${name}Safe = HttpSafe<${name}Operations>
|
|
210
210
|
`;
|
|
211
211
|
return `${importText(body, runtime, aliases)}
|
|
212
212
|
${body}`;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* file beside the SDK, plus the types that make its surfaces exact for this document.
|
|
5
5
|
*
|
|
6
6
|
* The vendoring mirrors `http.ts`'s `runtimeSource`, with one difference it cannot share: those modules
|
|
7
|
-
* import only each other, so dropping every sibling import is enough. These import
|
|
7
|
+
* import only each other, so dropping every sibling import is enough. These import clients' runtime too
|
|
8
8
|
* (`../ts/sdk.ts`), and the emitted file needs those names from `./<stem>.runtime.gen`, so the specifier is
|
|
9
9
|
* rewritten rather than dropped.
|
|
10
10
|
*/
|
|
@@ -16,7 +16,7 @@ import { memberTree } from "./service-map.js";
|
|
|
16
16
|
const QUERY_MODULES = ["invalidate", "query"];
|
|
17
17
|
/* an import of a module beside this one: now the same file, so the names are already in scope */
|
|
18
18
|
const SIBLING_IMPORT = /^import\s+(?:type\s+)?\{[^}]*\}\s+from\s+"\.\/[\w-]+\.ts"\n/gm;
|
|
19
|
-
/* an import of
|
|
19
|
+
/* an import of clients' own runtime, which the emitted file reads from `<stem>.runtime.gen` */
|
|
20
20
|
const RUNTIME_IMPORT = /^import\s+(type\s+)?\{([^}]*)\}\s+from\s+"\.\.\/ts\/[\w-]+\.ts"\n/gm;
|
|
21
21
|
/* query-core, which stays exactly as written: type-only, so nothing has to resolve at run time */
|
|
22
22
|
const QUERY_CORE_IMPORT = /^import\s+type\s+\{([^}]*)\}\s+from\s+"@tanstack\/query-core"\n/gm;
|
|
@@ -36,7 +36,7 @@ function namesOf(clauses) {
|
|
|
36
36
|
*/
|
|
37
37
|
export function tanstackQuerySource(runtime) {
|
|
38
38
|
const core = [];
|
|
39
|
-
const
|
|
39
|
+
const runtimeNames = [];
|
|
40
40
|
const bodies = QUERY_MODULES.map((name) => {
|
|
41
41
|
const text = readFileSync(new URL(`../../runtime/ts-tanstack-query/${name}.ts`, import.meta.url), "utf8");
|
|
42
42
|
return text
|
|
@@ -45,7 +45,7 @@ export function tanstackQuerySource(runtime) {
|
|
|
45
45
|
return "";
|
|
46
46
|
})
|
|
47
47
|
.replace(RUNTIME_IMPORT, (_, __, named) => {
|
|
48
|
-
|
|
48
|
+
runtimeNames.push(named);
|
|
49
49
|
return "";
|
|
50
50
|
})
|
|
51
51
|
.replace(SIBLING_IMPORT, "")
|
|
@@ -53,7 +53,7 @@ export function tanstackQuerySource(runtime) {
|
|
|
53
53
|
});
|
|
54
54
|
const imports = [
|
|
55
55
|
`import type { ${namesOf(core).join(", ")} } from "@tanstack/query-core"`,
|
|
56
|
-
`import type { ${namesOf(
|
|
56
|
+
`import type { ${namesOf(runtimeNames).join(", ")} } from "./${runtime}.js"`,
|
|
57
57
|
];
|
|
58
58
|
return `${imports.join("\n")}\n\n${bodies.join("\n\n")}\n`;
|
|
59
59
|
}
|