@workerstack/clients 1.0.0-rc.29 → 1.0.0-rc.31
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 +548 -35
- package/assets/installers/examples/github.config.ts +17 -19
- package/assets/installers/examples/goreleaser.config.ts +16 -18
- package/assets/installers/examples/raw.config.ts +13 -15
- package/bin/clients.js +88 -68
- package/bin/installgen.js +18 -13
- package/dist/cli.d.ts +4 -4
- package/dist/cli.js +20 -12
- package/dist/emit/cli/channels.d.ts +2 -2
- package/dist/emit/cli/channels.js +18 -13
- package/dist/emit/cli/commands.d.ts +1 -1
- package/dist/emit/cli/commands.js +14 -8
- package/dist/emit/cli/discovery.d.ts +0 -6
- package/dist/emit/cli/discovery.js +9 -7
- package/dist/emit/cli/flags.d.ts +1 -3
- package/dist/emit/cli/flags.js +11 -5
- package/dist/emit/cli/install.d.ts +0 -8
- package/dist/emit/cli/install.js +3 -3
- package/dist/emit/cli/layout.d.ts +1 -1
- package/dist/emit/cli/layout.js +13 -10
- package/dist/emit/cli/module.d.ts +6 -6
- package/dist/emit/cli/module.js +10 -10
- package/dist/emit/cli/release.d.ts +0 -11
- package/dist/emit/cli/release.js +4 -4
- package/dist/emit/cli/skills.js +3 -3
- package/dist/emit/csharp/errors.js +4 -4
- package/dist/emit/csharp/json.js +8 -8
- package/dist/emit/csharp/realtime.js +3 -3
- package/dist/emit/csharp/sdk-answer.js +4 -4
- package/dist/emit/csharp/sdk-body.js +8 -6
- package/dist/emit/csharp/sdk-client.d.ts +3 -3
- package/dist/emit/csharp/sdk-client.js +2 -2
- package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
- package/dist/emit/csharp/sdk-csproj.js +10 -10
- package/dist/emit/csharp/sdk-doc.js +1 -1
- package/dist/emit/csharp/sdk-method.d.ts +18 -2
- package/dist/emit/csharp/sdk-method.js +24 -9
- package/dist/emit/csharp/sdk-plan.js +0 -1
- package/dist/emit/csharp/sdk.js +7 -4
- package/dist/emit/csharp/sse.d.ts +0 -2
- package/dist/emit/csharp/sse.js +7 -7
- package/dist/emit/csharp/transport.js +7 -7
- package/dist/emit/csharp/types-enum.js +3 -1
- package/dist/emit/csharp/types-messages.js +3 -3
- package/dist/emit/csharp/types-names.js +10 -12
- package/dist/emit/csharp/types-record.js +3 -3
- package/dist/emit/csharp/types-union.d.ts +1 -1
- package/dist/emit/csharp/types.d.ts +0 -1
- package/dist/emit/csharp/types.js +3 -3
- package/dist/emit/csharp/ws.js +2 -2
- package/dist/emit/go/errors.js +1 -1
- package/dist/emit/go/http.js +2 -2
- package/dist/emit/go/module-path.js +2 -2
- package/dist/emit/go/sdk-answer.js +1 -1
- package/dist/emit/go/sdk-body.js +11 -7
- package/dist/emit/go/sdk-client.js +1 -1
- package/dist/emit/go/sdk-method.d.ts +9 -0
- package/dist/emit/go/sdk-method.js +12 -3
- package/dist/emit/go/sdk-mirror.js +2 -2
- package/dist/emit/go/sdk-opts.d.ts +0 -2
- package/dist/emit/go/sdk-opts.js +3 -3
- package/dist/emit/go/sdk.d.ts +1 -1
- package/dist/emit/go/sdk.js +12 -11
- package/dist/emit/go/sse.js +1 -1
- package/dist/emit/go/types-names.js +5 -0
- package/dist/emit/go/types-struct.d.ts +2 -1
- package/dist/emit/go/types-struct.js +1 -1
- package/dist/emit/go/types.js +9 -9
- package/dist/emit/go/ws.js +6 -6
- package/dist/emit/java/gradle.d.ts +7 -9
- package/dist/emit/java/gradle.js +8 -8
- package/dist/emit/java/json.js +1 -1
- package/dist/emit/java/layout-ast.js +1 -1
- package/dist/emit/java/layout-decl.js +5 -4
- package/dist/emit/java/layout-doc.js +13 -7
- package/dist/emit/java/layout-dot.js +1 -1
- package/dist/emit/java/layout-strings.js +4 -5
- package/dist/emit/java/layout-types.js +7 -5
- package/dist/emit/java/layout-visitor.js +4 -3
- package/dist/emit/java/layout.js +5 -4
- package/dist/emit/java/models-names.js +5 -4
- package/dist/emit/java/models-record.d.ts +0 -1
- package/dist/emit/java/models-record.js +3 -3
- package/dist/emit/java/models-union.d.ts +1 -1
- package/dist/emit/java/models-union.js +1 -1
- package/dist/emit/java/models.d.ts +1 -2
- package/dist/emit/java/models.js +25 -16
- package/dist/emit/java/realtime.d.ts +5 -17
- package/dist/emit/java/realtime.js +1 -1
- package/dist/emit/java/sdk-client.d.ts +6 -6
- package/dist/emit/java/sdk-client.js +2 -1
- package/dist/emit/java/sdk-decl.js +2 -2
- package/dist/emit/java/sdk-errors.js +1 -1
- package/dist/emit/java/sdk-headers.js +2 -2
- package/dist/emit/java/sdk-mirror.js +2 -2
- package/dist/emit/java/sdk-models.d.ts +1 -1
- package/dist/emit/java/sdk-models.js +7 -7
- package/dist/emit/java/sdk-op.d.ts +7 -11
- package/dist/emit/java/sdk-op.js +22 -10
- package/dist/emit/java/sdk-params.d.ts +5 -5
- package/dist/emit/java/sdk-params.js +3 -2
- package/dist/emit/java/sdk-plan.js +0 -1
- package/dist/emit/java/sdk.d.ts +1 -1
- package/dist/emit/java/sdk.js +21 -14
- package/dist/emit/java/sse.d.ts +2 -4
- package/dist/emit/java/sse.js +6 -6
- package/dist/emit/java/ws.d.ts +2 -2
- package/dist/emit/java/ws.js +3 -4
- package/dist/emit/mcp/annotations.js +8 -4
- package/dist/emit/mcp/files.js +9 -9
- package/dist/emit/mcp/mounted.js +2 -2
- package/dist/emit/mcp/output-schema.js +3 -3
- package/dist/emit/mcp/registry.d.ts +0 -2
- package/dist/emit/mcp/registry.js +5 -4
- package/dist/emit/mcp/runtime.js +2 -2
- package/dist/emit/mcp/schema.js +22 -11
- package/dist/emit/mcp/server.d.ts +7 -7
- package/dist/emit/mcp/server.js +7 -6
- package/dist/emit/mcp/tools.js +7 -6
- package/dist/emit/python/errors.js +3 -3
- package/dist/emit/python/realtime.js +2 -2
- package/dist/emit/python/sdk-answer.d.ts +3 -7
- package/dist/emit/python/sdk-answer.js +2 -2
- package/dist/emit/python/sdk-body.js +4 -5
- package/dist/emit/python/sdk-client.js +5 -5
- package/dist/emit/python/sdk-doc.js +2 -2
- package/dist/emit/python/sdk-method.d.ts +11 -0
- package/dist/emit/python/sdk-method.js +20 -5
- package/dist/emit/python/sdk-plan.js +0 -1
- package/dist/emit/python/sdk-pyproject.d.ts +0 -2
- package/dist/emit/python/sdk-pyproject.js +8 -8
- package/dist/emit/python/sdk.d.ts +1 -1
- package/dist/emit/python/sdk.js +12 -8
- package/dist/emit/python/sse.d.ts +0 -2
- package/dist/emit/python/sse.js +2 -2
- package/dist/emit/python/transport.js +4 -4
- package/dist/emit/python/types-dict.d.ts +2 -2
- package/dist/emit/python/types-dict.js +1 -1
- package/dist/emit/python/types-names.js +2 -2
- package/dist/emit/python/types-union.js +1 -1
- package/dist/emit/python/types.js +3 -3
- package/dist/emit/python/ws.d.ts +2 -5
- package/dist/emit/python/ws.js +4 -4
- package/dist/emit/rust/errors.js +3 -3
- package/dist/emit/rust/http.js +4 -4
- package/dist/emit/rust/realtime.js +2 -2
- package/dist/emit/rust/sdk-body.js +8 -5
- package/dist/emit/rust/sdk-cargo.d.ts +16 -18
- package/dist/emit/rust/sdk-cargo.js +12 -12
- package/dist/emit/rust/sdk-client.d.ts +1 -1
- package/dist/emit/rust/sdk-client.js +3 -3
- package/dist/emit/rust/sdk-method.d.ts +12 -1
- package/dist/emit/rust/sdk-method.js +12 -4
- package/dist/emit/rust/sdk-opts.d.ts +2 -1
- package/dist/emit/rust/sdk-opts.js +2 -2
- package/dist/emit/rust/sdk-plan.js +0 -1
- package/dist/emit/rust/sdk.d.ts +1 -1
- package/dist/emit/rust/sdk.js +9 -6
- package/dist/emit/rust/sse.d.ts +0 -5
- package/dist/emit/rust/sse.js +2 -2
- package/dist/emit/rust/types-names.js +3 -3
- package/dist/emit/rust/types-struct.js +1 -1
- package/dist/emit/rust/types-union.d.ts +1 -1
- package/dist/emit/rust/types.js +7 -5
- package/dist/emit/rust/ws.d.ts +0 -11
- package/dist/emit/rust/ws.js +5 -5
- package/dist/emit/shared/escape.js +17 -17
- package/dist/emit/shared/format.js +1 -1
- package/dist/emit/shared/gofmt.js +1 -1
- package/dist/emit/shared/lang.js +10 -10
- package/dist/emit/shared/literals.d.ts +5 -0
- package/dist/emit/shared/literals.js +8 -0
- package/dist/emit/shared/metadata.d.ts +0 -6
- package/dist/emit/shared/metadata.js +8 -7
- package/dist/emit/shared/ruff.js +1 -1
- package/dist/emit/shared/rustfmt.js +1 -1
- package/dist/emit/shared/type-emitter.js +37 -20
- package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
- package/dist/emit/shared/unknown-type.constants.js +2 -0
- package/dist/emit/ts/http.d.ts +8 -2
- package/dist/emit/ts/http.js +51 -6
- package/dist/emit/ts/package.d.ts +14 -12
- package/dist/emit/ts/package.js +10 -8
- package/dist/emit/ts/route-tree.js +2 -2
- package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
- package/dist/emit/ts/sdk-types-preamble.js +12 -4
- package/dist/emit/ts/sdk-types.d.ts +0 -5
- package/dist/emit/ts/sdk-types.js +63 -19
- package/dist/emit/ts/sdk.d.ts +3 -1
- package/dist/emit/ts/sdk.js +44 -12
- package/dist/emit/ts/service-map.d.ts +7 -1
- package/dist/emit/ts/service-map.js +10 -1
- package/dist/emit/ts/single-flight-text.d.ts +3 -0
- package/dist/emit/ts/single-flight-text.js +38 -0
- package/dist/emit/ts/tanstack-query.d.ts +3 -2
- package/dist/emit/ts/tanstack-query.js +60 -35
- package/dist/emit/ts/type-gen.js +31 -18
- package/dist/emit/ts/webhooks.d.ts +0 -2
- package/dist/emit/ts/webhooks.js +3 -3
- package/dist/extract/chain.js +5 -4
- package/dist/extract/extract.js +5 -5
- package/dist/extract/serialize.d.ts +0 -2
- package/dist/extract/serialize.js +14 -15
- package/dist/extract/walk.js +15 -12
- package/dist/gen/args.js +9 -5
- package/dist/gen/formatters.js +5 -3
- package/dist/gen/process.js +2 -1
- package/dist/gen/shipped.js +2 -2
- package/dist/gen/switch-on.constants.d.ts +2 -0
- package/dist/gen/switch-on.constants.js +2 -0
- package/dist/gen/targets.d.ts +6 -7
- package/dist/gen/targets.js +11 -6
- package/dist/gen/write.js +4 -2
- package/dist/index.js +2 -2
- package/dist/installers/cli.d.ts +4 -4
- package/dist/installers/cli.js +24 -24
- package/dist/installers/commands/build.d.ts +4 -4
- package/dist/installers/commands/build.js +2 -3
- package/dist/installers/commands/check.d.ts +2 -2
- package/dist/installers/commands/check.js +11 -10
- package/dist/installers/commands/init.d.ts +2 -2
- package/dist/installers/commands/init.js +1 -2
- package/dist/installers/config/define-config.d.ts +16 -16
- package/dist/installers/config/define-config.js +1 -1
- package/dist/installers/config/hooks/bun.d.ts +6 -6
- package/dist/installers/config/hooks/node.js +1 -1
- package/dist/installers/config/load.d.ts +6 -8
- package/dist/installers/config/load.js +7 -8
- package/dist/installers/config/resolve.d.ts +1 -2
- package/dist/installers/config/resolve.js +28 -33
- package/dist/installers/config/types.d.ts +6 -6
- package/dist/installers/config/types.js +0 -1
- package/dist/installers/render/quote.js +3 -5
- package/dist/installers/render/render.d.ts +6 -6
- package/dist/installers/render/render.js +26 -26
- package/dist/installers/ui.d.ts +4 -4
- package/dist/installers/ui.js +3 -3
- package/dist/ir/build.d.ts +3 -3
- package/dist/ir/build.js +8 -5
- package/dist/ir/invalidate-reads.d.ts +17 -0
- package/dist/ir/invalidate-reads.js +104 -0
- package/dist/ir/load.d.ts +10 -0
- package/dist/ir/load.js +65 -18
- package/dist/ir/model.d.ts +2 -1
- package/dist/ir/model.js +0 -1
- package/dist/ir/read-method.constants.d.ts +2 -0
- package/dist/ir/read-method.constants.js +2 -0
- package/dist/ir/resolve-refs.js +2 -2
- package/dist/ir/resource-tree.js +2 -1
- package/dist/ir/route-tree-intern.js +1 -1
- package/dist/ir/schema.js +3 -3
- package/dist/ir/sdk-model.js +3 -3
- package/dist/ir/slots.js +13 -8
- package/dist/ir/streams.js +1 -1
- package/dist/release/bootstrap.d.ts +3 -3
- package/dist/release/bootstrap.js +7 -7
- package/dist/release/bump-args.js +4 -4
- package/dist/release/bump-command.d.ts +1 -1
- package/dist/release/bump-command.js +9 -10
- package/dist/release/bump.d.ts +5 -4
- package/dist/release/bump.js +2 -2
- package/dist/release/cli.d.ts +4 -4
- package/dist/release/cli.js +4 -4
- package/dist/release/codegen.js +1 -1
- package/dist/release/digest.js +5 -7
- package/dist/release/git.js +5 -8
- package/dist/release/load.js +4 -4
- package/dist/release/manifest.js +9 -10
- package/dist/release/oasdiff.d.ts +10 -15
- package/dist/release/oasdiff.js +5 -6
- package/dist/release/registries.d.ts +0 -11
- package/dist/release/registries.js +17 -17
- package/dist/release/release-state.d.ts +16 -13
- package/dist/release/release-workflow.js +5 -7
- package/dist/release/repo-settings.d.ts +2 -1
- package/dist/release/spec-gate.d.ts +0 -2
- package/dist/release/spec-gate.js +6 -10
- package/dist/release/sync-command.d.ts +2 -2
- package/dist/release/sync-command.js +1 -1
- package/dist/release/sync-tree.js +9 -13
- package/dist/release/sync.d.ts +6 -6
- package/dist/release/sync.js +12 -13
- package/dist/release/types.d.ts +22 -22
- package/dist/release/types.js +0 -1
- package/dist/release/version-files.d.ts +3 -4
- package/dist/release/version-files.js +4 -5
- package/dist/runtime/.oxfmtrc.jsonc +8 -0
- package/dist/runtime/csharp/Config.cs +9 -1
- package/dist/runtime/csharp/Exchange.cs +56 -4
- package/dist/runtime/csharp/Hooks.cs +9 -0
- package/dist/runtime/csharp/Operation.cs +6 -1
- package/dist/runtime/csharp/WsDial.cs +3 -1
- package/dist/runtime/go/config.go +5 -0
- package/dist/runtime/go/hooks.go +70 -0
- package/dist/runtime/go/request.go +6 -2
- package/dist/runtime/go/stream.go +4 -1
- package/dist/runtime/go/ws.go +3 -1
- package/dist/runtime/java/ClientConfig.java +11 -0
- package/dist/runtime/java/Flight.java +2 -12
- package/dist/runtime/java/Hooks.java +45 -0
- package/dist/runtime/java/InvalidateEvent.java +10 -0
- package/dist/runtime/java/InvalidateHook.java +12 -0
- package/dist/runtime/java/InvalidateTarget.java +7 -0
- package/dist/runtime/java/Operation.java +23 -3
- package/dist/runtime/java/Realtime.java +3 -1
- package/dist/runtime/java/WsDial.java +3 -0
- package/dist/runtime/mcp/files.ts +1 -1
- package/dist/runtime/mcp/http.ts +6 -2
- package/dist/runtime/mcp/listen.ts +1 -1
- package/dist/runtime/mcp/mount.ts +2 -2
- package/dist/runtime/mcp/protocol.ts +1 -1
- package/dist/runtime/python/config.py +8 -2
- package/dist/runtime/python/exchange.py +3 -1
- package/dist/runtime/python/hooks.py +110 -5
- package/dist/runtime/python/operation.py +2 -0
- package/dist/runtime/python/send_async.py +14 -2
- package/dist/runtime/python/send_sync.py +4 -2
- package/dist/runtime/python/ws.py +5 -1
- package/dist/runtime/rust/config.rs +6 -1
- package/dist/runtime/rust/exchange.rs +15 -3
- package/dist/runtime/rust/hooks.rs +127 -2
- package/dist/runtime/rust/log.rs +11 -3
- package/dist/runtime/rust/request.rs +17 -0
- package/dist/runtime/rust/ws.rs +9 -1
- package/dist/runtime/ts/config.ts +69 -0
- package/dist/runtime/ts/http.ts +12 -10
- package/dist/runtime/ts/request.ts +2 -0
- package/dist/runtime/ts/response.ts +7 -0
- package/dist/runtime/ts/sdk-invalidate.ts +82 -0
- package/dist/runtime/ts/sdk-single-flight.constants.ts +25 -0
- package/dist/runtime/ts/sdk-single-flight.ts +203 -0
- package/dist/runtime/ts/sdk-sse.ts +5 -1
- package/dist/runtime/ts/sdk-ws.ts +9 -3
- package/dist/runtime/ts/sdk.ts +55 -31
- package/dist/runtime/ts/single-flight-batch.ts +184 -0
- package/dist/runtime/ts/single-flight-body.ts +59 -0
- package/dist/runtime/ts/single-flight-run.ts +160 -0
- package/dist/runtime/ts/single-flight.constants.ts +31 -0
- package/dist/runtime/ts/single-flight.ts +158 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +96 -92
- package/dist/runtime/ts-tanstack-query/query.ts +140 -170
- package/package.json +12 -17
- package/references/INDEX.md +31 -0
- package/references/cli.md +33 -0
- package/references/configuring.md +29 -0
- package/references/documentation.md +15 -0
- package/references/errors.md +23 -0
- package/references/flags.md +104 -0
- package/references/gates.md +46 -0
- package/references/generate.md +29 -0
- package/references/install-scripts.md +28 -0
- package/references/install.md +38 -0
- package/references/license.md +8 -0
- package/references/mcp.md +76 -0
- package/references/output.md +45 -0
- package/references/overview.md +14 -0
- package/references/release-tooling.md +34 -0
- package/references/release.md +305 -0
- package/references/sdks.md +393 -0
- package/references/start.md +22 -0
- package/references/tdd.md +16 -0
- package/dist/emit/cli/index.d.ts +0 -1
- package/dist/emit/cli/index.js +0 -1
- package/dist/emit/csharp/index.d.ts +0 -1
- package/dist/emit/csharp/index.js +0 -1
- package/dist/emit/go/index.d.ts +0 -1
- package/dist/emit/go/index.js +0 -1
- package/dist/emit/java/index.d.ts +0 -2
- package/dist/emit/java/index.js +0 -2
- package/dist/emit/mcp/index.d.ts +0 -3
- package/dist/emit/mcp/index.js +0 -3
- package/dist/emit/python/index.d.ts +0 -1
- package/dist/emit/python/index.js +0 -1
- package/dist/emit/rust/index.d.ts +0 -1
- package/dist/emit/rust/index.js +0 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/** `text` with each unpaired UTF-16 surrogate as U+FFFD: no target can carry a lone surrogate to the wire. */
|
|
8
8
|
export function wellFormed(text) {
|
|
9
|
-
return text.
|
|
9
|
+
return text.replaceAll(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "\uFFFD");
|
|
10
10
|
}
|
|
11
11
|
const hex = (cp, width) => cp.toString(16).padStart(width, "0");
|
|
12
12
|
/**
|
|
@@ -19,10 +19,10 @@ export const invisible = (cp) => (cp >= 0x80 && cp <= 0x9f) ||
|
|
|
19
19
|
cp === 0x200f ||
|
|
20
20
|
(cp >= 0x202a && cp <= 0x202e) ||
|
|
21
21
|
(cp >= 0x2066 && cp <= 0x2069);
|
|
22
|
-
|
|
23
|
-
const NAMED = {
|
|
22
|
+
// the escapes every target spells alike
|
|
23
|
+
const NAMED = { 0x0a: "\\n", 0x0d: "\\r", 0x22: '\\"', 0x09: "\\t", 0x5c: "\\\\" };
|
|
24
24
|
const POLICIES = {
|
|
25
|
-
|
|
25
|
+
// C#'s \x takes one to four hex digits, so it is never written: \uHHHH, fixed width, for every escape
|
|
26
26
|
csharp: (cp) => cp < 0x20 || cp === 0x7f || cp === 0x2028 || cp === 0x2029 || cp === 0xfeff || invisible(cp)
|
|
27
27
|
? `\\u${hex(cp, 4)}`
|
|
28
28
|
: null,
|
|
@@ -31,13 +31,13 @@ const POLICIES = {
|
|
|
31
31
|
return `\\x${hex(cp, 2)}`;
|
|
32
32
|
return cp === 0xfeff || invisible(cp) ? `\\u${hex(cp, 4)}` : null;
|
|
33
33
|
},
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// Java has no \x: \uHHHH for every other control, DEL and the BOM. The apostrophe stays raw: javac takes it in
|
|
35
|
+
// "…", and the backslash's own escape keeps every \u in the text from becoming one (JLS 3.3)
|
|
36
36
|
java: (cp) => (cp < 0x20 || cp === 0x7f || cp === 0xfeff || invisible(cp) ? `\\u${hex(cp, 4)}` : null),
|
|
37
37
|
python: (cp) => {
|
|
38
38
|
if (cp < 0x20 || cp === 0x7f)
|
|
39
39
|
return `\\x${hex(cp, 2)}`;
|
|
40
|
-
|
|
40
|
+
// line separators and the BOM read as line ends or vanish in some tools: never raw
|
|
41
41
|
return cp === 0x2028 || cp === 0x2029 || cp === 0xfeff || invisible(cp) ? `\\u${hex(cp, 4)}` : null;
|
|
42
42
|
},
|
|
43
43
|
rust: (cp) => {
|
|
@@ -89,8 +89,8 @@ export function commentText(text) {
|
|
|
89
89
|
}
|
|
90
90
|
return out;
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
// every line break a comment writer splits at: a C# or JS lexer ends a line at U+2028 and U+2029 too (U+0085, C1,
|
|
93
|
+
// never reaches a writer raw: commentText shows it)
|
|
94
94
|
const LINE_BREAKS = /\r\n|\r|\n|\u2028|\u2029/;
|
|
95
95
|
/** Comment lines of `text` behind `marker` (`//`, `///`, `#`): each line break in it starts a new comment line. */
|
|
96
96
|
export function lineComment(text, marker, indent = "") {
|
|
@@ -100,13 +100,13 @@ export function lineComment(text, marker, indent = "") {
|
|
|
100
100
|
}
|
|
101
101
|
/** Text that stays inside a `/* … *\/` comment. */
|
|
102
102
|
export function blockCommentText(text) {
|
|
103
|
-
return commentText(text).
|
|
103
|
+
return commentText(text).replaceAll("*/", "* /").replaceAll("/*", "/ *");
|
|
104
104
|
}
|
|
105
105
|
/** Docstring body lines: backslashes and quotes escaped, so `"""`, a trailing `"` and `C:\users` are inert. */
|
|
106
106
|
export function pyDocLines(text) {
|
|
107
107
|
return commentText(text)
|
|
108
108
|
.split(LINE_BREAKS)
|
|
109
|
-
.map((line) => line.
|
|
109
|
+
.map((line) => line.replaceAll("\\", "\\\\").replaceAll('"', '\\"'));
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* XML doc text lines (C#'s `///`): split at every line break, `&`, `<` and `>` as entities, and U+FFFE and U+FFFF,
|
|
@@ -114,9 +114,9 @@ export function pyDocLines(text) {
|
|
|
114
114
|
*/
|
|
115
115
|
export function csDocLines(text) {
|
|
116
116
|
return commentText(text)
|
|
117
|
-
.
|
|
117
|
+
.replaceAll(/[\uFFFE\uFFFF]/g, (ch) => `\\u${hex(ch.codePointAt(0), 4)}`)
|
|
118
118
|
.split(LINE_BREAKS)
|
|
119
|
-
.map((line) => line.
|
|
119
|
+
.map((line) => line.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"));
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
122
|
* Comment text for Java: javac turns an eligible `\uXXXX` into its character in ANY source text before it lexes
|
|
@@ -124,7 +124,7 @@ export function csDocLines(text) {
|
|
|
124
124
|
* backslashes before a `u` is doubled, which leaves none of them eligible; `commentText` then shows the hidden
|
|
125
125
|
* characters as escapes it means javac to read.
|
|
126
126
|
*/
|
|
127
|
-
export const javaCommentText = (text) => commentText(wellFormed(text).
|
|
127
|
+
export const javaCommentText = (text) => commentText(wellFormed(text).replaceAll(/\\+(?=u)/g, (run) => run + run));
|
|
128
128
|
/** Java `//` lines of `text`: each line break starts a new line, the `\u` rule kept. */
|
|
129
129
|
export function javaLineComment(text, indent = "") {
|
|
130
130
|
return javaCommentText(text)
|
|
@@ -137,8 +137,8 @@ export function javaLineComment(text, indent = "") {
|
|
|
137
137
|
*/
|
|
138
138
|
export function javaDocLines(text) {
|
|
139
139
|
return javaCommentText(text)
|
|
140
|
-
.
|
|
141
|
-
.
|
|
140
|
+
.replaceAll("*/", "* /")
|
|
141
|
+
.replaceAll("/*", "/ *")
|
|
142
142
|
.split(LINE_BREAKS)
|
|
143
|
-
.map((line) => line.replace(/^(\s*)@/, "$1@").
|
|
143
|
+
.map((line) => line.replace(/^(\s*)@/, "$1@").replaceAll("{@", "{@"));
|
|
144
144
|
}
|
|
@@ -14,7 +14,7 @@ export async function formatFiles(files, formatters) {
|
|
|
14
14
|
if (formatter === undefined)
|
|
15
15
|
continue;
|
|
16
16
|
const { code, errors } = await formatter(name, text, EMIT_STYLE);
|
|
17
|
-
|
|
17
|
+
// an emitter wrote text that does not parse: a bug to surface, never a file to write
|
|
18
18
|
if (errors.length > 0)
|
|
19
19
|
throw new Error(`could not format ${name}: ${JSON.stringify(errors[0])}`);
|
|
20
20
|
out[name] = code;
|
|
@@ -19,7 +19,7 @@ export function gofmtFormatter(gofmt) {
|
|
|
19
19
|
child.on("error", (error) => resolve({ code: source, errors: [error.message] }));
|
|
20
20
|
child.on("close", (status) => resolve(status === 0 ? { code: stdout, errors: [] } : { code: source, errors: [stderr.trim()] }));
|
|
21
21
|
child.stdin.on("error", () => {
|
|
22
|
-
|
|
22
|
+
// a gofmt that never started: its spawn error answers
|
|
23
23
|
});
|
|
24
24
|
child.stdin.end(source);
|
|
25
25
|
});
|
package/dist/emit/shared/lang.js
CHANGED
|
@@ -11,8 +11,8 @@ export function compareCodeUnits(a, b) {
|
|
|
11
11
|
/** The ASCII alphanumeric words of `raw`: `user-id`, `user_id` and `userId` are all [user, id]. */
|
|
12
12
|
export function words(raw) {
|
|
13
13
|
return raw
|
|
14
|
-
.
|
|
15
|
-
.
|
|
14
|
+
.replaceAll(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
15
|
+
.replaceAll(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
|
|
16
16
|
.split(/[^A-Za-z0-9]+/)
|
|
17
17
|
.filter((word) => word.length > 0);
|
|
18
18
|
}
|
|
@@ -78,22 +78,22 @@ export class NameTable {
|
|
|
78
78
|
/** Whether `word` is one of the space-separated `list`. */
|
|
79
79
|
const listed = (list, word) => ` ${list} `.includes(` ${word} `);
|
|
80
80
|
const GO_RESERVED =
|
|
81
|
-
|
|
81
|
+
// keywords
|
|
82
82
|
"break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var " +
|
|
83
|
-
|
|
83
|
+
// predeclared identifiers
|
|
84
84
|
"any append bool byte cap clear close comparable complex complex128 complex64 copy delete error false float32 float64 imag int int16 int32 int64 int8 iota len make max min new nil panic print println real recover rune string true uint uint16 uint32 uint64 uint8 uintptr " +
|
|
85
|
-
|
|
85
|
+
// the packages generated Go imports
|
|
86
86
|
"bytes context errors fmt http io iter json multipart os slices strconv strings sync textproto time url websocket cobra cli sdk";
|
|
87
87
|
const RUST_KEYWORDS = "as break const continue crate else enum extern false fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait true type unsafe use where while async await dyn abstract become box do final macro override priv typeof unsized virtual yield try gen";
|
|
88
|
-
|
|
88
|
+
// keywords that cannot be raw identifiers: `r#self` is invalid
|
|
89
89
|
const RUST_NON_RAW = "crate self Self super extern _";
|
|
90
90
|
const RUST_PRELUDE = "Box Clone Copy Default Drop Eq Err Fn From HashMap Into Iterator None Ok Option Ord PartialEq PartialOrd Result Send Sized Some String Sync ToOwned ToString Vec Deserialize Serialize Deserialize_repr Serialize_repr Stream Arc";
|
|
91
91
|
const PY_RESERVED = "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 " +
|
|
92
|
-
|
|
92
|
+
// soft keywords and names generated code relies on
|
|
93
93
|
"match case type _ self cls";
|
|
94
|
-
|
|
94
|
+
// C#'s 77 reserved keywords (contract 45 §4.1): no identifier may be one unless `@`-escaped
|
|
95
95
|
const CS_RESERVED = "abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual void volatile while";
|
|
96
|
-
|
|
96
|
+
// C#'s contextual keywords: legal identifiers, `@`-escaped all the same so none reads as a keyword where it is one
|
|
97
97
|
const CS_CONTEXTUAL = "add allows and args async await by descending dynamic equals extension field file from get global group init into join let managed nameof nint not notnull nuint on or orderby partial record remove required scoped select set unmanaged value var when where with yield";
|
|
98
98
|
/** `name` unless empty (then `empty`), prefixed by `digitPrefix` when it starts with a digit. */
|
|
99
99
|
function guarded(name, empty, digitPrefix) {
|
|
@@ -141,7 +141,7 @@ export function pyClassName(raw) {
|
|
|
141
141
|
const name = guarded(pascalWords(raw), "Model", "N");
|
|
142
142
|
return listed(PY_RESERVED, name) ? `${name}_` : name;
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
// Java's keywords (JLS 3.9), its literals, `_`, and the restricted identifiers that cannot name a type
|
|
145
145
|
const JAVA_RESERVED = [
|
|
146
146
|
"abstract",
|
|
147
147
|
"assert",
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An optional property's type: under `exactOptionalPropertyTypes` a `k?: T` refuses the `undefined` a zod
|
|
3
|
+
* `.optional()` infers, so the generated type says it too; `unknown` already holds it.
|
|
4
|
+
*/
|
|
5
|
+
export declare function optionalType(type: string): string;
|
|
1
6
|
/** A property key in a type or object literal: bare when it is an identifier, a string literal otherwise. */
|
|
2
7
|
export declare function quoteKey(key: string): string;
|
|
3
8
|
/** The TypeScript literal type of a JSON `value` (an array as a tuple, an object field by field); else its type, or `unknown`. */
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
* escape layer (F2), never `JSON.stringify` alone.
|
|
4
4
|
*/
|
|
5
5
|
import { tsString } from "./escape.js";
|
|
6
|
+
import { UNKNOWN_TYPE } from "./unknown-type.constants.js";
|
|
6
7
|
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
8
|
+
/**
|
|
9
|
+
* An optional property's type: under `exactOptionalPropertyTypes` a `k?: T` refuses the `undefined` a zod
|
|
10
|
+
* `.optional()` infers, so the generated type says it too; `unknown` already holds it.
|
|
11
|
+
*/
|
|
12
|
+
export function optionalType(type) {
|
|
13
|
+
return type === UNKNOWN_TYPE ? type : `${type} | undefined`;
|
|
14
|
+
}
|
|
7
15
|
/** A property key in a type or object literal: bare when it is an identifier, a string literal otherwise. */
|
|
8
16
|
export function quoteKey(key) {
|
|
9
17
|
return IDENTIFIER.test(key) ? key : tsString(key);
|
|
@@ -28,12 +28,6 @@ export declare function personOf(value: string): {
|
|
|
28
28
|
};
|
|
29
29
|
/** One author: a name with no comma, angle bracket or control character, or that name then ` <email>`. */
|
|
30
30
|
export declare const AUTHOR: RegExp;
|
|
31
|
-
/** A path to a Markdown file: the README every registry renders, NuGet only in Markdown. */
|
|
32
|
-
export declare const MARKDOWN_PATH: RegExp;
|
|
33
|
-
/** A path to a PNG or JPEG image: the package icon, in the formats NuGet takes. */
|
|
34
|
-
export declare const IMAGE_PATH: RegExp;
|
|
35
|
-
/** One keyword: no space, comma or control character, at most 50 characters; a registry may hold it to less. */
|
|
36
|
-
export declare const KEYWORD: RegExp;
|
|
37
31
|
/**
|
|
38
32
|
* The fields of the package metadata block a run gives once (plan 39 8.2), which every target that publishes reads
|
|
39
33
|
* where its registry has a place for it; a target's own option of the same meaning wins. `--metadata-<field>` sets one
|
|
@@ -35,11 +35,11 @@ export function personOf(value) {
|
|
|
35
35
|
/** One author: a name with no comma, angle bracket or control character, or that name then ` <email>`. */
|
|
36
36
|
export const AUTHOR = /^(?=[^\p{Cc}\p{Cs}]{1,4000}$)[^<>,]*[^<>,\s][^<>,]*?(?: <[^\s<>@]+@[^\s<>@]+\.[^\s<>@]+>)?$/u;
|
|
37
37
|
/** A path to a Markdown file: the README every registry renders, NuGet only in Markdown. */
|
|
38
|
-
|
|
38
|
+
const MARKDOWN_PATH = /^(?=[^\p{Cc}\p{Cs}]{1,4000}$).*\.md$/iu;
|
|
39
39
|
/** A path to a PNG or JPEG image: the package icon, in the formats NuGet takes. */
|
|
40
|
-
|
|
40
|
+
const IMAGE_PATH = /^(?=[^\p{Cc}\p{Cs}]{1,4000}$).*\.(?:png|jpe?g)$/iu;
|
|
41
41
|
/** One keyword: no space, comma or control character, at most 50 characters; a registry may hold it to less. */
|
|
42
|
-
|
|
42
|
+
const KEYWORD = /^[^\s,\p{Cc}\p{Cs}]{1,50}$/u;
|
|
43
43
|
/**
|
|
44
44
|
* The fields of the package metadata block a run gives once (plan 39 8.2), which every target that publishes reads
|
|
45
45
|
* where its registry has a place for it; a target's own option of the same meaning wins. `--metadata-<field>` sets one
|
|
@@ -91,8 +91,9 @@ export function checkedMetadata(metadata) {
|
|
|
91
91
|
throw new Error("Invalid metadata: want an object of fields");
|
|
92
92
|
const entries = Object.entries(metadata).filter(([, value]) => value !== undefined);
|
|
93
93
|
for (const [field, value] of entries) {
|
|
94
|
-
if (!Object.hasOwn(GRAMMARS, field))
|
|
94
|
+
if (!Object.hasOwn(GRAMMARS, field)) {
|
|
95
95
|
throw new Error(`Invalid metadata: unknown field ${JSON.stringify(field)}, want one of ${METADATA_FIELDS.join(", ")}`);
|
|
96
|
+
}
|
|
96
97
|
const grammar = GRAMMARS[field];
|
|
97
98
|
if (!isListField(field)) {
|
|
98
99
|
if (typeof value !== "string" || !grammar.test(value))
|
|
@@ -107,12 +108,12 @@ export function checkedMetadata(metadata) {
|
|
|
107
108
|
}
|
|
108
109
|
return Object.fromEntries(entries);
|
|
109
110
|
}
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
// the names the README and the license file the block names take in every package's root: those each registry and
|
|
112
|
+
// forge reads (plan 39 8.7)
|
|
112
113
|
export const README = "README.md";
|
|
113
114
|
export const LICENSE = "LICENSE";
|
|
114
115
|
/** The name the icon at `path` ships under: `icon`, then its own extension in lower case. */
|
|
115
|
-
|
|
116
|
+
// IMAGE_PATH holds every icon path to an extension, so the last dot starts it
|
|
116
117
|
export const iconName = (path) => `icon${path.slice(path.lastIndexOf(".")).toLowerCase()}`;
|
|
117
118
|
/** What `metadata` ships beside the code. */
|
|
118
119
|
export const shippedOf = (metadata) => ({
|
package/dist/emit/shared/ruff.js
CHANGED
|
@@ -24,7 +24,7 @@ export function ruffFormatter(ruff) {
|
|
|
24
24
|
resolve(status === 0 ? { code: stdout, errors: [] } : { code: source, errors: [failure] });
|
|
25
25
|
});
|
|
26
26
|
child.stdin.on("error", () => {
|
|
27
|
-
|
|
27
|
+
// a ruff that never started or stopped reading: its spawn error or exit status answers
|
|
28
28
|
});
|
|
29
29
|
child.stdin.end(source);
|
|
30
30
|
});
|
|
@@ -25,7 +25,7 @@ export function rustfmtFormatter(rustfmt, edition = "2024") {
|
|
|
25
25
|
resolve(status === 0 ? { code: stdout, errors: [] } : { code: source, errors: [failure] });
|
|
26
26
|
});
|
|
27
27
|
child.stdin.on("error", () => {
|
|
28
|
-
|
|
28
|
+
// a rustfmt that never started or stopped reading: its spawn error or exit status answers
|
|
29
29
|
});
|
|
30
30
|
child.stdin.end(source);
|
|
31
31
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compareCodeUnits } from "./lang.js";
|
|
2
|
-
import { literalType, quoteKey } from "./literals.js";
|
|
3
|
-
|
|
2
|
+
import { literalType, optionalType, quoteKey } from "./literals.js";
|
|
3
|
+
// a cycle guard only: resolved documents carry no cycles, so legitimately deep nesting is kept
|
|
4
4
|
const MAX_DEPTH = 64;
|
|
5
5
|
/** Whether `type` holds `token` outside every bracket and string: `A | B` does, `{ a: A | B }` does not. */
|
|
6
6
|
function topLevel(type, token) {
|
|
@@ -14,14 +14,18 @@ function topLevel(type, token) {
|
|
|
14
14
|
else if (c === quote)
|
|
15
15
|
quote = null;
|
|
16
16
|
}
|
|
17
|
-
else if (c === '"' || c === "'" || c === "`")
|
|
17
|
+
else if (c === '"' || c === "'" || c === "`") {
|
|
18
18
|
quote = c;
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
else if ("({[<".includes(c)) {
|
|
20
21
|
depth++;
|
|
21
|
-
|
|
22
|
+
}
|
|
23
|
+
else if (")}]".includes(c) || (c === ">" && type[at - 1] !== "=")) {
|
|
22
24
|
depth--;
|
|
23
|
-
|
|
25
|
+
}
|
|
26
|
+
else if (depth === 0 && type.startsWith(token, at)) {
|
|
24
27
|
return true;
|
|
28
|
+
}
|
|
25
29
|
}
|
|
26
30
|
return false;
|
|
27
31
|
}
|
|
@@ -48,14 +52,16 @@ function scalarOf(ir) {
|
|
|
48
52
|
}
|
|
49
53
|
function objectOf(ir, emit) {
|
|
50
54
|
const extra = ir.additional === undefined || ir.additional === false ? null : emit(ir.additional);
|
|
51
|
-
|
|
55
|
+
// closed with nothing in it (z.object({})): the empty object, never an open record
|
|
52
56
|
if (ir.fields.length === 0)
|
|
53
57
|
return ir.additional === false ? "{}" : `Record<string, ${extra ?? "unknown"}>`;
|
|
54
58
|
const fields = [...ir.fields]
|
|
55
59
|
.sort((a, b) => compareCodeUnits(a.name, b.name))
|
|
56
|
-
.map((field) =>
|
|
60
|
+
.map((field) => field.required
|
|
61
|
+
? `${quoteKey(field.name)}: ${emit(field.schema)}`
|
|
62
|
+
: `${quoteKey(field.name)}?: ${optionalType(emit(field.schema))}`);
|
|
57
63
|
const shape = `{ ${fields.join("; ")} }`;
|
|
58
|
-
|
|
64
|
+
// an index signature beside fields of other types is TS2411; an intersection says the same
|
|
59
65
|
return extra === null ? shape : `${shape} & { [k: string]: ${extra} }`;
|
|
60
66
|
}
|
|
61
67
|
function tupleOf(ir, emit) {
|
|
@@ -70,28 +76,39 @@ function emitAt(ir, options, depth) {
|
|
|
70
76
|
return "unknown";
|
|
71
77
|
const emit = (child) => emitAt(child, options, depth + 1);
|
|
72
78
|
switch (ir.kind) {
|
|
73
|
-
case "scalar":
|
|
79
|
+
case "scalar": {
|
|
74
80
|
return scalarOf(ir);
|
|
75
|
-
|
|
81
|
+
}
|
|
82
|
+
case "const": {
|
|
76
83
|
return literalType(ir.value);
|
|
77
|
-
|
|
84
|
+
}
|
|
85
|
+
case "object": {
|
|
78
86
|
return objectOf(ir, emit);
|
|
79
|
-
|
|
87
|
+
}
|
|
88
|
+
case "array": {
|
|
80
89
|
return arrayOf(emit(ir.items));
|
|
81
|
-
|
|
90
|
+
}
|
|
91
|
+
case "tuple": {
|
|
82
92
|
return tupleOf(ir, emit);
|
|
83
|
-
|
|
93
|
+
}
|
|
94
|
+
case "union": {
|
|
84
95
|
return unionOf(ir.variants.map(emit));
|
|
85
|
-
|
|
96
|
+
}
|
|
97
|
+
case "allOf": {
|
|
86
98
|
return intersectionOf(ir.parts.map(emit));
|
|
87
|
-
|
|
99
|
+
}
|
|
100
|
+
case "nullable": {
|
|
88
101
|
return unionOf([emit(ir.inner), "null"]);
|
|
89
|
-
|
|
102
|
+
}
|
|
103
|
+
case "ref": {
|
|
90
104
|
return options.refName?.(ir.name) ?? "unknown";
|
|
91
|
-
|
|
105
|
+
}
|
|
106
|
+
case "binary": {
|
|
92
107
|
return options.binary ?? "string";
|
|
93
|
-
|
|
108
|
+
}
|
|
109
|
+
default: {
|
|
94
110
|
return "unknown";
|
|
111
|
+
}
|
|
95
112
|
}
|
|
96
113
|
}
|
|
97
114
|
/** The TypeScript type of `ir`. */
|
package/dist/emit/ts/http.d.ts
CHANGED
|
@@ -10,11 +10,17 @@ export type TsRuntimeFeatures = {
|
|
|
10
10
|
export declare const FULL_RUNTIME: TsRuntimeFeatures;
|
|
11
11
|
/** The runtime modules under `runtime/ts`, each after the ones it imports. */
|
|
12
12
|
export declare const RUNTIME_MODULES: readonly string[];
|
|
13
|
-
/** The runtime modules an SDK with `features` ships, in `RUNTIME_MODULES` order. */
|
|
14
|
-
export declare function runtimeModules(features: TsRuntimeFeatures): string[];
|
|
15
13
|
/** What the SDK of `ir` needs from the runtime: its operations' transports, never the app client. */
|
|
16
14
|
export declare function runtimeFeatures(ir: IR): TsRuntimeFeatures;
|
|
17
15
|
/** The Standard Webhooks verifier: it imports nothing, so the webhook file that carries it stands alone. */
|
|
18
16
|
export declare function webhookSource(): string;
|
|
17
|
+
/** The single-flight handler's runtime modules, each after the ones it imports. */
|
|
18
|
+
export declare const SINGLE_FLIGHT_MODULES: readonly string[];
|
|
19
|
+
/**
|
|
20
|
+
* The single-flight handler's runtime, for a file of its own beside the SDK (as the webhook verifier is): its
|
|
21
|
+
* modules joined, their imports of the client's runtime gathered into one import of `<stem>.runtime.gen.js`, so no
|
|
22
|
+
* browser bundle that leaves the file out carries any of it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function singleFlightSource(stem: string): string;
|
|
19
25
|
/** The runtime as one module, with `features`' transports: what `runtime.gen.ts` holds. */
|
|
20
26
|
export declare function runtimeSource(features: TsRuntimeFeatures): string;
|
package/dist/emit/ts/http.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* SSE or realtime API, the WebSocket ones for a WebSocket or realtime API, the realtime ones for a
|
|
6
6
|
* realtime API, and only the app client ships its own `createClient`. The webhook verifier is no part of it: it ships
|
|
7
7
|
* in its own file (`webhookSource`), so a receiver bundles nothing else. Both fronts emit it verbatim, so a test that runs the emitted client runs this text.
|
|
8
|
+
* The single-flight handler ships in a file of its own too (`singleFlightSource`), so a browser bundles none of it.
|
|
8
9
|
*/
|
|
9
10
|
import { readFileSync } from "node:fs";
|
|
10
11
|
import { sdkModel } from "../../ir/sdk-model.js";
|
|
12
|
+
import { compareCodeUnits } from "../shared/lang.js";
|
|
11
13
|
/** The app client's runtime: `createClient` and every transport, since it cannot know its routes'. */
|
|
12
14
|
export const FULL_RUNTIME = { app: true, realtime: true, sse: true, ws: true };
|
|
13
15
|
/** The runtime modules under `runtime/ts`, each after the ones it imports. */
|
|
@@ -32,18 +34,21 @@ export const RUNTIME_MODULES = [
|
|
|
32
34
|
"stale",
|
|
33
35
|
"app-types",
|
|
34
36
|
"app",
|
|
37
|
+
"sdk-invalidate",
|
|
38
|
+
"sdk-single-flight.constants",
|
|
39
|
+
"sdk-single-flight",
|
|
35
40
|
"sdk",
|
|
36
41
|
"sdk-sse",
|
|
37
42
|
"sdk-ws",
|
|
38
43
|
"sdk-realtime",
|
|
39
44
|
];
|
|
40
|
-
|
|
45
|
+
// the modules each transport adds; realtime dials over an event stream and a WebSocket, so it ships both
|
|
41
46
|
const SSE = ["sse", "stream", "sdk-sse"];
|
|
42
47
|
const WS = ["ws", "sdk-ws"];
|
|
43
48
|
const REALTIME = ["realtime", "realtime-connection", "realtime-transports", "sdk-realtime"];
|
|
44
49
|
const APP = ["app-types", "app"];
|
|
45
50
|
/** The runtime modules an SDK with `features` ships, in `RUNTIME_MODULES` order. */
|
|
46
|
-
|
|
51
|
+
function runtimeModules(features) {
|
|
47
52
|
const left = new Set([
|
|
48
53
|
...(features.sse || features.realtime ? [] : SSE),
|
|
49
54
|
...(features.ws || features.realtime ? [] : WS),
|
|
@@ -57,17 +62,57 @@ export function runtimeFeatures(ir) {
|
|
|
57
62
|
const streams = new Set(sdkModel(ir).ops.map((op) => op.stream));
|
|
58
63
|
return { app: false, realtime: streams.has("realtime"), sse: streams.has("sse"), ws: streams.has("ws") };
|
|
59
64
|
}
|
|
60
|
-
|
|
61
|
-
const SIBLING_IMPORT = /^import\s+(?:type\s+)?\{[^}]*\}\s+from\s+"\.\/[\w
|
|
65
|
+
// an import of a sibling runtime module, on one line or several
|
|
66
|
+
const SIBLING_IMPORT = /^import\s+(?:type\s+)?\{[^}]*\}\s+from\s+"\.\/[\w.-]+\.ts"\n/gm;
|
|
67
|
+
/** One runtime module's text, as written. */
|
|
68
|
+
function moduleText(name) {
|
|
69
|
+
return readFileSync(new URL(`../../runtime/ts/${name}.ts`, import.meta.url), "utf8");
|
|
70
|
+
}
|
|
62
71
|
/** One runtime module's source, without its imports of its siblings. */
|
|
63
72
|
function moduleSource(name) {
|
|
64
|
-
|
|
65
|
-
return text.replace(SIBLING_IMPORT, "").trim();
|
|
73
|
+
return moduleText(name).replaceAll(SIBLING_IMPORT, "").trim();
|
|
66
74
|
}
|
|
67
75
|
/** The Standard Webhooks verifier: it imports nothing, so the webhook file that carries it stands alone. */
|
|
68
76
|
export function webhookSource() {
|
|
69
77
|
return moduleSource("webhook");
|
|
70
78
|
}
|
|
79
|
+
/** The single-flight handler's runtime modules, each after the ones it imports. */
|
|
80
|
+
export const SINGLE_FLIGHT_MODULES = [
|
|
81
|
+
"single-flight.constants",
|
|
82
|
+
"single-flight-batch",
|
|
83
|
+
"single-flight-body",
|
|
84
|
+
"single-flight-run",
|
|
85
|
+
"single-flight",
|
|
86
|
+
];
|
|
87
|
+
// an import of a sibling runtime module, its names and its module captured
|
|
88
|
+
const SIBLING_NAMES = /^import\s+(type\s+)?\{([^}]*)\}\s+from\s+"\.\/([\w.-]+)\.ts"\n/gm;
|
|
89
|
+
// a type-only name of an import list
|
|
90
|
+
const TYPE_PREFIX = /^type /;
|
|
91
|
+
/** The names `text` imports from runtime modules outside `own`, each `type X` when only its type is imported. */
|
|
92
|
+
function runtimeImports(text, own) {
|
|
93
|
+
return [...text.matchAll(SIBLING_NAMES)]
|
|
94
|
+
.filter(([, , , module]) => !own.includes(String(module)))
|
|
95
|
+
.flatMap(([, typeOnly, names]) => String(names)
|
|
96
|
+
.split(",")
|
|
97
|
+
.map((name) => name.trim())
|
|
98
|
+
.filter((name) => name !== "")
|
|
99
|
+
.map((name) => (typeOnly === undefined ? name : `type ${name}`)));
|
|
100
|
+
}
|
|
101
|
+
/** `name` without its `type ` mark. */
|
|
102
|
+
function bare(name) {
|
|
103
|
+
return name.replace(TYPE_PREFIX, "");
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The single-flight handler's runtime, for a file of its own beside the SDK (as the webhook verifier is): its
|
|
107
|
+
* modules joined, their imports of the client's runtime gathered into one import of `<stem>.runtime.gen.js`, so no
|
|
108
|
+
* browser bundle that leaves the file out carries any of it.
|
|
109
|
+
*/
|
|
110
|
+
export function singleFlightSource(stem) {
|
|
111
|
+
const imported = new Set(SINGLE_FLIGHT_MODULES.flatMap((name) => runtimeImports(moduleText(name), SINGLE_FLIGHT_MODULES)));
|
|
112
|
+
const sorted = [...imported].toSorted((a, b) => compareCodeUnits(bare(a), bare(b)));
|
|
113
|
+
const modules = SINGLE_FLIGHT_MODULES.map(moduleSource).join("\n\n");
|
|
114
|
+
return `import { ${sorted.join(", ")} } from "./${stem}.runtime.gen.js"\n\n${modules}\n`;
|
|
115
|
+
}
|
|
71
116
|
/** The runtime as one module, with `features`' transports: what `runtime.gen.ts` holds. */
|
|
72
117
|
export function runtimeSource(features) {
|
|
73
118
|
return `${runtimeModules(features).map(moduleSource).join("\n\n")}\n`;
|
|
@@ -15,19 +15,21 @@ export declare function compiled(path: string, source: string, declaration: bool
|
|
|
15
15
|
code: string;
|
|
16
16
|
declaration: string;
|
|
17
17
|
};
|
|
18
|
-
/** The package.json fields the metadata fills
|
|
19
|
-
export
|
|
20
|
-
description?: string
|
|
21
|
-
keywords?: readonly string[]
|
|
22
|
-
homepage?: string
|
|
23
|
-
bugs?: string
|
|
24
|
-
license?: string
|
|
25
|
-
author?: string
|
|
26
|
-
repository?: {
|
|
27
|
-
type:
|
|
28
|
-
url: string;
|
|
29
|
-
}
|
|
18
|
+
/** The package.json fields the metadata fills: the TS SDK's and the MCP server's. */
|
|
19
|
+
export type NpmFields = {
|
|
20
|
+
readonly description?: string;
|
|
21
|
+
readonly keywords?: readonly string[];
|
|
22
|
+
readonly homepage?: string;
|
|
23
|
+
readonly bugs?: string;
|
|
24
|
+
readonly license?: string;
|
|
25
|
+
readonly author?: string;
|
|
26
|
+
readonly repository?: {
|
|
27
|
+
readonly type: "git";
|
|
28
|
+
readonly url: string;
|
|
29
|
+
};
|
|
30
30
|
};
|
|
31
|
+
/** The package.json fields the metadata fills, each only when given: the TS SDK's and the MCP server's. */
|
|
32
|
+
export declare function npmFields(metadata: Metadata): NpmFields;
|
|
31
33
|
/** The SDK with its package files, and the package as npm lists it, and JSR too when its name is scoped. */
|
|
32
34
|
export type GeneratedSdkPackage = GeneratedSdk & {
|
|
33
35
|
readonly packages: readonly PackageIdentity[];
|
package/dist/emit/ts/package.js
CHANGED
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
import { transformSync } from "oxc-transform";
|
|
12
12
|
import { checked, issuesUrl, LICENSE, NPM_NAME, packageOn, README, SEMVER, shippedOf, } from "../shared/metadata.js";
|
|
13
13
|
import { generateSdk } from "./sdk.js";
|
|
14
|
-
|
|
14
|
+
// the optional peer the TanStack adapter's types import, as npm and JSR range it
|
|
15
15
|
const QUERY_CORE = "@tanstack/query-core";
|
|
16
16
|
const QUERY_CORE_RANGE = "^5.0.0";
|
|
17
|
-
|
|
17
|
+
// each importable file's kind and the subpath it is exported at; the others are reached through the index
|
|
18
18
|
const SUBPATHS = {
|
|
19
19
|
index: ".",
|
|
20
|
+
"single-flight": "./single-flight",
|
|
20
21
|
"tanstack-query": "./tanstack-query",
|
|
21
22
|
webhook: "./webhook",
|
|
22
23
|
};
|
|
@@ -41,13 +42,14 @@ function exportsOf(files, stem, target) {
|
|
|
41
42
|
/** The package.json fields the metadata fills, each only when given: the TS SDK's and the MCP server's. */
|
|
42
43
|
export function npmFields(metadata) {
|
|
43
44
|
const { authors, description, homepage, keywords, license, repository } = metadata;
|
|
45
|
+
const author = authors?.[0];
|
|
44
46
|
return {
|
|
45
47
|
...(description === undefined ? {} : { description }),
|
|
46
48
|
...(keywords === undefined ? {} : { keywords }),
|
|
47
49
|
...(homepage === undefined ? {} : { homepage }),
|
|
48
50
|
...(repository === undefined ? {} : { bugs: issuesUrl(repository) }),
|
|
49
51
|
...(license === undefined ? {} : { license }),
|
|
50
|
-
...(
|
|
52
|
+
...(author === undefined ? {} : { author }),
|
|
51
53
|
...(repository === undefined
|
|
52
54
|
? {}
|
|
53
55
|
: { repository: { type: "git", url: `git+${repository.replace(/\.git$/, "")}.git` } }),
|
|
@@ -61,7 +63,7 @@ function packageJson(sdk, name, version, metadata) {
|
|
|
61
63
|
version,
|
|
62
64
|
...npmFields(metadata),
|
|
63
65
|
type: "module",
|
|
64
|
-
exports: exportsOf(sdk.files, sdk.stem, (file) => ({
|
|
66
|
+
exports: exportsOf(sdk.files, sdk.stem, (file) => ({ default: `./dist/${file}.js`, types: `./dist/${file}.d.ts` })),
|
|
65
67
|
files: ["dist"],
|
|
66
68
|
sideEffects: false,
|
|
67
69
|
engines: { node: ">=22" },
|
|
@@ -83,12 +85,12 @@ function jsrJson(sdk, name, version, metadata) {
|
|
|
83
85
|
...(metadata.license === undefined ? {} : { license: metadata.license }),
|
|
84
86
|
exports: exportsOf(sdk.files, sdk.stem, (file) => `./${file}.ts`),
|
|
85
87
|
...(tanstack ? { imports: { [QUERY_CORE]: `npm:${QUERY_CORE}@${QUERY_CORE_RANGE}` } } : {}),
|
|
86
|
-
|
|
88
|
+
// the runtime reads browser globals (FileList, WebSocket) where they exist: JSR checks it with them declared
|
|
87
89
|
compilerOptions: { lib: ["esnext", "dom", "dom.iterable"] },
|
|
88
|
-
|
|
90
|
+
// the sources' `.js` imports name their `.ts` files
|
|
89
91
|
unstable: ["sloppy-imports"],
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
// the README JSR shows and the license file beside the sources, each when the run ships it; npm packs both
|
|
93
|
+
// whatever `files` says
|
|
92
94
|
publish: { include: ["*.gen.ts", ...shippedNames(metadata)] },
|
|
93
95
|
};
|
|
94
96
|
return `${JSON.stringify(config, null, "\t")}\n`;
|
|
@@ -100,7 +100,7 @@ function emittedRoutes(tree) {
|
|
|
100
100
|
.filter((id) => leaves.has(id))
|
|
101
101
|
.map((id) => {
|
|
102
102
|
const entry = tree.routes[id];
|
|
103
|
-
|
|
103
|
+
// core's snapshot writes `mt: {}` for every route without meta: no key, no meta
|
|
104
104
|
const mt = entry.mt && Object.keys(entry.mt).length > 0 ? entry.mt : null;
|
|
105
105
|
if (mt !== null)
|
|
106
106
|
assertJsonMeta(id, mt);
|
|
@@ -218,7 +218,7 @@ export function generateRouteTree(tree) {
|
|
|
218
218
|
HEAD,
|
|
219
219
|
consts.length > 0 ? `${consts.join("\n")}\n` : "",
|
|
220
220
|
`export const tree: TreeNode = ${nodeText(tree.root, intern)}\n`,
|
|
221
|
-
|
|
221
|
+
// S typed by its entry: inferred from the literals, the union of entries would give each es the others' keys
|
|
222
222
|
`export const routes: RouteTree["routes"] = S<RouteTree["routes"][string]>({\n${routes.map((route) => routeLine(route, intern)).join(",\n")}\n})\n`,
|
|
223
223
|
shape ?? "",
|
|
224
224
|
meta.length > 0 ? `export const meta: ${metaType} = S({\n${meta.join(",\n")}\n})\n` : "",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* document becomes those types.
|
|
6
6
|
*/
|
|
7
7
|
import type { TsRuntimeFeatures } from "./http.ts";
|
|
8
|
-
export declare const RESERVED: string[];
|
|
8
|
+
export declare const RESERVED: readonly string[];
|
|
9
9
|
/** The input fields every call takes, by transport, and the safe twin's types, for an API with `features`. */
|
|
10
10
|
export declare function shared(features: TsRuntimeFeatures): string;
|
|
11
11
|
/** The runtime types this text names, in order: a document with no realtime route uses neither
|