@toa.io/extensions.exposition 1.0.0-alpha.282 → 1.0.0-alpha.284
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/CHANGELOG.md +56 -0
- package/components/exposition.octets/manifest.toa.yaml +11 -0
- package/components/exposition.octets/types/index.d.ts +3 -0
- package/components/exposition.octets/types/toa.d.ts +41 -0
- package/components/identity.bans/operations/transit.js +1 -1
- package/components/identity.bans/tsconfig.json +1 -1
- package/components/identity.bans/tsconfig.tsbuildinfo +1 -1
- package/components/identity.bans/types/index.d.ts +3 -0
- package/components/identity.bans/types/toa.d.ts +34 -0
- package/components/identity.basic/manifest.toa.yaml +13 -2
- package/components/identity.basic/operations/add.js +1 -1
- package/components/identity.basic/operations/authenticate.js +1 -1
- package/components/identity.basic/operations/check.js +1 -1
- package/components/identity.basic/operations/delete.js +1 -1
- package/components/identity.basic/operations/incept.js +18 -2
- package/components/identity.basic/operations/info.js +1 -1
- package/components/identity.basic/operations/lib/credentials.js +1 -1
- package/components/identity.basic/operations/transit.js +3 -2
- package/components/identity.basic/source/add.ts +3 -3
- package/components/identity.basic/source/authenticate.ts +2 -2
- package/components/identity.basic/source/check.ts +1 -1
- package/components/identity.basic/source/delete.ts +2 -2
- package/components/identity.basic/source/incept.ts +31 -3
- package/components/identity.basic/source/info.ts +1 -1
- package/components/identity.basic/source/transit.ts +6 -4
- package/components/identity.basic/tsconfig.json +1 -1
- package/components/identity.basic/tsconfig.tsbuildinfo +1 -1
- package/components/identity.basic/types/index.d.ts +22 -0
- package/components/identity.basic/types/toa.d.ts +121 -0
- package/components/identity.clients/manifest.toa.yaml +243 -0
- package/components/identity.clients/operations/describe.js +44 -0
- package/components/identity.clients/operations/lib/Context.js +2 -0
- package/components/identity.clients/operations/lib/Entity.js +2 -0
- package/components/identity.clients/operations/lib/canonical.js +24 -0
- package/components/identity.clients/operations/lib/cimd.js +86 -0
- package/components/identity.clients/operations/lib/errors.js +5 -0
- package/components/identity.clients/operations/lib/index.js +7 -0
- package/components/identity.clients/operations/lib/redirect.js +32 -0
- package/components/identity.clients/operations/register.js +84 -0
- package/components/identity.clients/source/describe.ts +65 -0
- package/components/identity.clients/source/lib/Context.ts +38 -0
- package/components/identity.clients/source/lib/Entity.ts +31 -0
- package/components/identity.clients/source/lib/canonical.test.ts +43 -0
- package/components/identity.clients/source/lib/canonical.ts +27 -0
- package/components/identity.clients/source/lib/cimd.test.ts +120 -0
- package/components/identity.clients/source/lib/cimd.ts +107 -0
- package/components/identity.clients/source/lib/errors.ts +4 -0
- package/components/identity.clients/source/lib/index.ts +6 -0
- package/components/identity.clients/source/lib/redirect.test.ts +41 -0
- package/components/identity.clients/source/lib/redirect.ts +35 -0
- package/components/identity.clients/source/register.ts +125 -0
- package/components/identity.clients/tsconfig.json +10 -0
- package/components/identity.clients/tsconfig.tsbuildinfo +1 -0
- package/components/identity.clients/types/index.d.ts +3 -0
- package/components/identity.clients/types/toa.d.ts +109 -0
- package/components/identity.credentials/operations/list.js +1 -1
- package/components/identity.credentials/source/list.ts +2 -1
- package/components/identity.credentials/tsconfig.json +4 -2
- package/components/identity.credentials/tsconfig.tsbuildinfo +1 -1
- package/components/identity.credentials/types/index.d.ts +3 -0
- package/components/identity.credentials/types/toa.d.ts +30 -0
- package/components/identity.federation/manifest.toa.yaml +37 -1
- package/components/identity.federation/operations/authenticate.js +7 -3
- package/components/identity.federation/operations/create.js +1 -1
- package/components/identity.federation/operations/decode.js +1 -1
- package/components/identity.federation/operations/delete.js +1 -1
- package/components/identity.federation/operations/incept.js +6 -2
- package/components/identity.federation/operations/lib/Configuration.js +1 -1
- package/components/identity.federation/operations/lib/Ctx.js +1 -1
- package/components/identity.federation/operations/lib/Payload.js +1 -1
- package/components/identity.federation/operations/lib/decode.js +23 -9
- package/components/identity.federation/operations/lib/discovery.js +1 -1
- package/components/identity.federation/operations/lib/errors.js +5 -1
- package/components/identity.federation/operations/lib/exchange.js +12 -7
- package/components/identity.federation/operations/lib/index.js +2 -1
- package/components/identity.federation/operations/lib/jose.js +1 -1
- package/components/identity.federation/operations/lib/principal.js +14 -0
- package/components/identity.federation/operations/lib/resolve.js +1 -1
- package/components/identity.federation/operations/list.js +1 -1
- package/components/identity.federation/operations/types/Scheme.js +1 -1
- package/components/identity.federation/operations/types/configuration.js +1 -1
- package/components/identity.federation/operations/types/context.js +1 -1
- package/components/identity.federation/operations/types/entity.js +1 -1
- package/components/identity.federation/operations/types/index.js +1 -1
- package/components/identity.federation/source/authenticate.ts +9 -3
- package/components/identity.federation/source/incept.ts +7 -1
- package/components/identity.federation/source/lib/Ctx.ts +2 -2
- package/components/identity.federation/source/lib/decode.ts +25 -9
- package/components/identity.federation/source/lib/errors.ts +5 -0
- package/components/identity.federation/source/lib/exchange.ts +11 -7
- package/components/identity.federation/source/lib/index.ts +1 -0
- package/components/identity.federation/source/lib/principal.ts +17 -0
- package/components/identity.federation/source/types/configuration.ts +1 -1
- package/components/identity.federation/source/types/context.ts +6 -2
- package/components/identity.federation/tsconfig.json +4 -2
- package/components/identity.federation/tsconfig.tsbuildinfo +1 -1
- package/components/identity.federation/types/index.d.ts +3 -0
- package/components/identity.federation/types/toa.d.ts +127 -0
- package/components/identity.grants/manifest.toa.yaml +245 -0
- package/components/identity.grants/operations/authorize.js +54 -0
- package/components/identity.grants/operations/exchange.js +89 -0
- package/components/identity.grants/operations/lib/code.js +30 -0
- package/components/identity.grants/operations/lib/identify.js +15 -0
- package/components/identity.grants/operations/lib/index.js +3 -0
- package/components/identity.grants/operations/list.js +18 -0
- package/components/identity.grants/operations/revoke.js +25 -0
- package/components/identity.grants/source/authorize.ts +90 -0
- package/components/identity.grants/source/exchange.ts +130 -0
- package/components/identity.grants/source/lib/code.ts +39 -0
- package/components/identity.grants/source/lib/identify.ts +16 -0
- package/components/identity.grants/source/lib/index.ts +3 -0
- package/components/identity.grants/source/list.ts +28 -0
- package/components/identity.grants/source/revoke.ts +38 -0
- package/components/identity.grants/tsconfig.json +10 -0
- package/components/identity.grants/tsconfig.tsbuildinfo +1 -0
- package/components/identity.grants/types/index.d.ts +60 -0
- package/components/identity.grants/types/toa.d.ts +108 -0
- package/components/identity.keys/manifest.toa.yaml +1 -0
- package/components/identity.keys/operations/create.js +1 -1
- package/components/identity.keys/operations/disable.js +1 -1
- package/components/identity.keys/operations/revoke.js +1 -1
- package/components/identity.keys/source/create.ts +1 -1
- package/components/identity.keys/source/revoke.ts +1 -1
- package/components/identity.keys/tsconfig.json +1 -1
- package/components/identity.keys/tsconfig.tsbuildinfo +1 -1
- package/components/identity.keys/types/index.d.ts +3 -0
- package/components/identity.keys/types/toa.d.ts +47 -0
- package/components/identity.otp/operations/authenticate.js +1 -1
- package/components/identity.otp/operations/issue.js +1 -1
- package/components/identity.otp/operations/lib/Context.js +1 -1
- package/components/identity.otp/operations/lib/Entity.js +1 -1
- package/components/identity.otp/operations/lib/index.js +1 -1
- package/components/identity.otp/source/lib/Context.ts +4 -2
- package/components/identity.otp/tsconfig.json +1 -1
- package/components/identity.otp/tsconfig.tsbuildinfo +1 -1
- package/components/identity.otp/types/index.d.ts +3 -0
- package/components/identity.otp/types/toa.d.ts +56 -0
- package/components/identity.passkeys/manifest.toa.yaml +3 -0
- package/components/identity.passkeys/operations/authenticate.js +1 -1
- package/components/identity.passkeys/operations/challenge.js +1 -1
- package/components/identity.passkeys/operations/create.js +1 -1
- package/components/identity.passkeys/operations/delete.js +1 -1
- package/components/identity.passkeys/operations/lib/const.js +1 -1
- package/components/identity.passkeys/operations/list.js +1 -1
- package/components/identity.passkeys/operations/types/Configuration.js +1 -1
- package/components/identity.passkeys/operations/types/Context.js +1 -1
- package/components/identity.passkeys/operations/types/Passkey.js +1 -1
- package/components/identity.passkeys/operations/types/index.js +1 -1
- package/components/identity.passkeys/operations/use.js +1 -1
- package/components/identity.passkeys/source/authenticate.ts +1 -1
- package/components/identity.passkeys/source/challenge.ts +1 -1
- package/components/identity.passkeys/source/create.ts +1 -1
- package/components/identity.passkeys/source/types/Context.ts +2 -1
- package/components/identity.passkeys/source/use.ts +1 -1
- package/components/identity.passkeys/tsconfig.json +1 -1
- package/components/identity.passkeys/tsconfig.tsbuildinfo +1 -1
- package/components/identity.passkeys/types/index.d.ts +3 -0
- package/components/identity.passkeys/types/toa.d.ts +120 -0
- package/components/identity.roles/operations/grant.js +1 -1
- package/components/identity.roles/operations/lib/Entity.js +1 -1
- package/components/identity.roles/operations/list.js +1 -1
- package/components/identity.roles/operations/principal.js +29 -5
- package/components/identity.roles/source/principal.ts +33 -5
- package/components/identity.roles/tsconfig.json +1 -1
- package/components/identity.roles/tsconfig.tsbuildinfo +1 -1
- package/components/identity.roles/types/index.d.ts +3 -0
- package/components/identity.roles/types/toa.d.ts +43 -0
- package/components/identity.tokens/manifest.toa.yaml +34 -3
- package/components/identity.tokens/operations/authenticate.js +9 -1
- package/components/identity.tokens/operations/decrypt.js +3 -3
- package/components/identity.tokens/operations/encrypt.js +1 -1
- package/components/identity.tokens/operations/issue.js +3 -2
- package/components/identity.tokens/operations/lib/form.js +24 -0
- package/components/identity.tokens/operations/lib/index.js +2 -2
- package/components/identity.tokens/operations/lib/jose.js +1 -1
- package/components/identity.tokens/operations/lib/key.js +1 -1
- package/components/identity.tokens/operations/lib/pad.js +1 -1
- package/components/identity.tokens/operations/revoke.js +1 -1
- package/components/identity.tokens/source/authenticate.test.ts +8 -5
- package/components/identity.tokens/source/authenticate.ts +12 -1
- package/components/identity.tokens/source/decrypt.test.ts +1 -1
- package/components/identity.tokens/source/decrypt.ts +4 -3
- package/components/identity.tokens/source/encrypt.test.ts +1 -1
- package/components/identity.tokens/source/encrypt.ts +2 -1
- package/components/identity.tokens/source/issue.test.ts +71 -0
- package/components/identity.tokens/source/issue.ts +4 -2
- package/components/identity.tokens/source/lib/form.test.ts +25 -0
- package/components/identity.tokens/source/lib/form.ts +31 -0
- package/components/identity.tokens/source/lib/index.ts +2 -1
- package/components/identity.tokens/tsconfig.json +1 -1
- package/components/identity.tokens/tsconfig.tsbuildinfo +1 -1
- package/components/identity.tokens/types/index.d.ts +61 -0
- package/components/identity.tokens/types/toa.d.ts +113 -0
- package/documentation/access.md +13 -0
- package/documentation/cache.md +10 -1
- package/documentation/components.md +3 -0
- package/documentation/consent.md +101 -0
- package/documentation/identity.md +3 -1
- package/documentation/introspection.md +13 -5
- package/documentation/io.md +42 -2
- package/documentation/map.md +8 -0
- package/documentation/mcp.md +180 -0
- package/documentation/oauth.md +180 -0
- package/documentation/protocol.md +4 -0
- package/documentation/rpc.md +140 -0
- package/documentation/tree.md +3 -0
- package/features/auth.bearer.feature +120 -0
- package/features/cache.feature +46 -0
- package/features/identity.basic.feature +44 -0
- package/features/identity.federation.feature +2 -5
- package/features/introspection.feature +333 -0
- package/features/mcp.feature +687 -0
- package/features/oauth.clients.feature +195 -0
- package/features/oauth.discovery.feature +164 -0
- package/features/oauth.grants.feature +299 -0
- package/features/octets.cloudinary.feature +1 -0
- package/features/rpc.feature +429 -0
- package/features/steps/Cloudinary.ts +13 -0
- package/features/steps/Components.ts +0 -4
- package/features/steps/Gateway.ts +23 -2
- package/features/steps/Parameters.ts +22 -7
- package/features/steps/Realtime.ts +3 -0
- package/features/steps/components/echo/manifest.toa.yaml +3 -0
- package/features/steps/components/octets.tester/manifest.toa.yaml +2 -0
- package/features/steps/components/octets.tester/operations/redirect.js +6 -1
- package/features/steps/components/pots/manifest.toa.yaml +2 -0
- package/features/steps/components/users/manifest.toa.yaml +1 -0
- package/package.json +8 -6
- package/readme.md +6 -0
- package/schemas/annotation.cos.yaml +63 -0
- package/schemas/call.cos.yaml +18 -0
- package/source/Annotation.ts +54 -0
- package/source/Directive.test.ts +15 -15
- package/source/Directive.ts +77 -9
- package/source/Endpoint.test.ts +67 -0
- package/source/Endpoint.ts +31 -11
- package/source/Factory.ts +6 -2
- package/source/Gateway.ts +73 -11
- package/source/HTTP/Context.ts +7 -0
- package/source/HTTP/Server.ts +15 -5
- package/source/HTTP/exceptions.ts +2 -2
- package/source/HTTP/formats/form.ts +21 -0
- package/source/HTTP/formats/index.ts +17 -2
- package/source/HTTP/messages.test.ts +25 -1
- package/source/HTTP/messages.ts +20 -4
- package/source/Interception.ts +8 -2
- package/source/Introspection.ts +102 -0
- package/source/MCP/Server.ts +275 -0
- package/source/MCP/discover.ts +52 -0
- package/source/MCP/errors.ts +81 -0
- package/source/MCP/index.ts +1 -0
- package/source/MCP/schema.test.ts +85 -0
- package/source/MCP/schema.ts +87 -0
- package/source/MCP/tools.ts +156 -0
- package/source/MCP/types.ts +81 -0
- package/source/Query.ts +48 -8
- package/source/RPC/Context.ts +78 -0
- package/source/RPC/Dispatcher.ts +130 -0
- package/source/RPC/errors.test.ts +52 -0
- package/source/RPC/errors.ts +83 -0
- package/source/RPC/index.ts +1 -0
- package/source/RPC/names.test.ts +122 -0
- package/source/RPC/names.ts +182 -0
- package/source/RPC/types.ts +34 -0
- package/source/RTD/Directives.ts +52 -2
- package/source/RTD/Endpoint.ts +2 -1
- package/source/RTD/Method.ts +14 -11
- package/source/RTD/Node.ts +38 -7
- package/source/RTD/Route.ts +30 -3
- package/source/RTD/Tree.ts +37 -1
- package/source/RTD/expiration.test.ts +1 -1
- package/source/RTD/walk.test.ts +110 -0
- package/source/const.ts +15 -0
- package/source/deployment.ts +11 -1
- package/source/directives/auth/Anonymous.test.ts +38 -0
- package/source/directives/auth/Anonymous.ts +12 -0
- package/source/directives/auth/Anyone.ts +4 -0
- package/source/directives/auth/Authorization.ts +108 -22
- package/source/directives/auth/Delegate.test.ts +36 -0
- package/source/directives/auth/Delegate.ts +14 -0
- package/source/directives/auth/Echo.ts +5 -0
- package/source/directives/auth/Incept.ts +16 -10
- package/source/directives/auth/Role.ts +13 -0
- package/source/directives/auth/Rule.ts +29 -0
- package/source/directives/auth/Scheme.ts +5 -0
- package/source/directives/auth/schemes.test.ts +8 -4
- package/source/directives/auth/schemes.ts +22 -9
- package/source/directives/auth/types.ts +26 -2
- package/source/directives/cache/Cache.ts +14 -5
- package/source/directives/cache/Control.ts +0 -3
- package/source/directives/dev/Development.ts +1 -1
- package/source/directives/flow/Fetch.ts +1 -1
- package/source/directives/flow/Flow.ts +1 -1
- package/source/directives/index.ts +5 -2
- package/source/directives/io/Directive.ts +1 -1
- package/source/directives/io/IO.ts +34 -3
- package/source/directives/io/Input.ts +3 -2
- package/source/directives/io/Output.ts +10 -4
- package/source/directives/io/Status.test.ts +84 -0
- package/source/directives/io/Status.ts +46 -0
- package/source/directives/io/Throttle.ts +1 -1
- package/source/directives/io/lib/throttle/Quotas.ts +2 -2
- package/source/directives/map/Headers.ts +11 -0
- package/source/directives/map/Map.ts +10 -1
- package/source/directives/map/Mapping.ts +23 -0
- package/source/directives/map/Segments.ts +12 -0
- package/source/directives/mcp/MCP.ts +33 -0
- package/source/directives/mcp/Tool.test.ts +66 -0
- package/source/directives/mcp/Tool.ts +28 -0
- package/source/directives/mcp/index.ts +6 -0
- package/source/directives/oauth/Discovery.ts +70 -0
- package/source/directives/oauth/documents.ts +113 -0
- package/source/directives/oauth/index.ts +3 -0
- package/source/directives/octets/Delete.ts +1 -1
- package/source/directives/octets/Get.ts +1 -1
- package/source/directives/octets/Octets.ts +1 -1
- package/source/directives/octets/Workflow.ts +1 -1
- package/source/directives/octets/workflows/Execution.ts +1 -1
- package/source/directives/require/Directive.ts +1 -1
- package/source/directives/require/Headers.ts +1 -1
- package/source/directives/require/Require.ts +2 -2
- package/source/index.ts +6 -0
- package/source/octets.d.ts +17 -0
- package/source/schemas.ts +2 -0
- package/source/userland.ts +47 -0
- package/transpiled/Annotation.d.ts +41 -0
- package/transpiled/Directive.d.ts +18 -1
- package/transpiled/Directive.js +50 -6
- package/transpiled/Directive.js.map +1 -1
- package/transpiled/Endpoint.d.ts +9 -0
- package/transpiled/Endpoint.js +27 -11
- package/transpiled/Endpoint.js.map +1 -1
- package/transpiled/Factory.js +6 -2
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Gateway.d.ts +19 -2
- package/transpiled/Gateway.js +51 -9
- package/transpiled/Gateway.js.map +1 -1
- package/transpiled/HTTP/Context.d.ts +6 -0
- package/transpiled/HTTP/Context.js +6 -0
- package/transpiled/HTTP/Context.js.map +1 -1
- package/transpiled/HTTP/Server.d.ts +8 -1
- package/transpiled/HTTP/Server.js +4 -3
- package/transpiled/HTTP/Server.js.map +1 -1
- package/transpiled/HTTP/exceptions.d.ts +1 -1
- package/transpiled/HTTP/exceptions.js +2 -2
- package/transpiled/HTTP/exceptions.js.map +1 -1
- package/transpiled/HTTP/formats/form.d.ts +9 -0
- package/transpiled/HTTP/formats/form.js +18 -0
- package/transpiled/HTTP/formats/form.js.map +1 -0
- package/transpiled/HTTP/formats/index.d.ts +10 -2
- package/transpiled/HTTP/formats/index.js +10 -0
- package/transpiled/HTTP/formats/index.js.map +1 -1
- package/transpiled/HTTP/messages.d.ts +12 -0
- package/transpiled/HTTP/messages.js +12 -4
- package/transpiled/HTTP/messages.js.map +1 -1
- package/transpiled/Interception.d.ts +4 -1
- package/transpiled/Interception.js +4 -2
- package/transpiled/Interception.js.map +1 -1
- package/transpiled/Introspection.d.ts +40 -0
- package/transpiled/Introspection.js +50 -1
- package/transpiled/Introspection.js.map +1 -1
- package/transpiled/MCP/Server.d.ts +41 -0
- package/transpiled/MCP/Server.js +180 -0
- package/transpiled/MCP/Server.js.map +1 -0
- package/transpiled/MCP/discover.d.ts +13 -0
- package/transpiled/MCP/discover.js +29 -0
- package/transpiled/MCP/discover.js.map +1 -0
- package/transpiled/MCP/errors.d.ts +24 -0
- package/transpiled/MCP/errors.js +67 -0
- package/transpiled/MCP/errors.js.map +1 -0
- package/transpiled/MCP/index.d.ts +1 -0
- package/transpiled/MCP/index.js +2 -0
- package/transpiled/MCP/index.js.map +1 -0
- package/transpiled/MCP/schema.d.ts +18 -0
- package/transpiled/MCP/schema.js +64 -0
- package/transpiled/MCP/schema.js.map +1 -0
- package/transpiled/MCP/tools.d.ts +31 -0
- package/transpiled/MCP/tools.js +121 -0
- package/transpiled/MCP/tools.js.map +1 -0
- package/transpiled/MCP/types.d.ts +64 -0
- package/transpiled/MCP/types.js +13 -0
- package/transpiled/MCP/types.js.map +1 -0
- package/transpiled/Query.d.ts +7 -0
- package/transpiled/Query.js +38 -7
- package/transpiled/Query.js.map +1 -1
- package/transpiled/RPC/Context.d.ts +11 -0
- package/transpiled/RPC/Context.js +63 -0
- package/transpiled/RPC/Context.js.map +1 -0
- package/transpiled/RPC/Dispatcher.d.ts +19 -0
- package/transpiled/RPC/Dispatcher.js +100 -0
- package/transpiled/RPC/Dispatcher.js.map +1 -0
- package/transpiled/RPC/errors.d.ts +18 -0
- package/transpiled/RPC/errors.js +67 -0
- package/transpiled/RPC/errors.js.map +1 -0
- package/transpiled/RPC/index.d.ts +1 -0
- package/transpiled/RPC/index.js +2 -0
- package/transpiled/RPC/index.js.map +1 -0
- package/transpiled/RPC/names.d.ts +30 -0
- package/transpiled/RPC/names.js +121 -0
- package/transpiled/RPC/names.js.map +1 -0
- package/transpiled/RPC/types.d.ts +27 -0
- package/transpiled/RPC/types.js +8 -0
- package/transpiled/RPC/types.js.map +1 -0
- package/transpiled/RTD/Directives.d.ts +41 -2
- package/transpiled/RTD/Endpoint.d.ts +2 -1
- package/transpiled/RTD/Method.d.ts +8 -3
- package/transpiled/RTD/Method.js +12 -10
- package/transpiled/RTD/Method.js.map +1 -1
- package/transpiled/RTD/Node.d.ts +20 -2
- package/transpiled/RTD/Node.js +22 -4
- package/transpiled/RTD/Node.js.map +1 -1
- package/transpiled/RTD/Route.d.ts +2 -1
- package/transpiled/RTD/Route.js +27 -2
- package/transpiled/RTD/Route.js.map +1 -1
- package/transpiled/RTD/Tree.d.ts +3 -1
- package/transpiled/RTD/Tree.js +26 -0
- package/transpiled/RTD/Tree.js.map +1 -1
- package/transpiled/const.d.ts +12 -0
- package/transpiled/const.js +12 -0
- package/transpiled/const.js.map +1 -1
- package/transpiled/deployment.js +6 -0
- package/transpiled/deployment.js.map +1 -1
- package/transpiled/directives/auth/Anonymous.d.ts +6 -0
- package/transpiled/directives/auth/Anonymous.js +10 -0
- package/transpiled/directives/auth/Anonymous.js.map +1 -1
- package/transpiled/directives/auth/Anyone.d.ts +1 -0
- package/transpiled/directives/auth/Anyone.js +3 -0
- package/transpiled/directives/auth/Anyone.js.map +1 -1
- package/transpiled/directives/auth/Authorization.d.ts +28 -2
- package/transpiled/directives/auth/Authorization.js +87 -19
- package/transpiled/directives/auth/Authorization.js.map +1 -1
- package/transpiled/directives/auth/Delegate.d.ts +5 -0
- package/transpiled/directives/auth/Delegate.js +10 -0
- package/transpiled/directives/auth/Delegate.js.map +1 -1
- package/transpiled/directives/auth/Echo.d.ts +2 -0
- package/transpiled/directives/auth/Echo.js +4 -0
- package/transpiled/directives/auth/Echo.js.map +1 -1
- package/transpiled/directives/auth/Incept.d.ts +1 -1
- package/transpiled/directives/auth/Incept.js +13 -8
- package/transpiled/directives/auth/Incept.js.map +1 -1
- package/transpiled/directives/auth/Role.d.ts +2 -0
- package/transpiled/directives/auth/Role.js +9 -0
- package/transpiled/directives/auth/Role.js.map +1 -1
- package/transpiled/directives/auth/Rule.d.ts +5 -0
- package/transpiled/directives/auth/Rule.js +20 -0
- package/transpiled/directives/auth/Rule.js.map +1 -1
- package/transpiled/directives/auth/Scheme.d.ts +2 -0
- package/transpiled/directives/auth/Scheme.js +4 -0
- package/transpiled/directives/auth/Scheme.js.map +1 -1
- package/transpiled/directives/auth/schemes.d.ts +16 -4
- package/transpiled/directives/auth/schemes.js +20 -8
- package/transpiled/directives/auth/schemes.js.map +1 -1
- package/transpiled/directives/auth/types.d.ts +20 -2
- package/transpiled/directives/cache/Cache.d.ts +1 -1
- package/transpiled/directives/cache/Cache.js +10 -3
- package/transpiled/directives/cache/Cache.js.map +1 -1
- package/transpiled/directives/cache/Control.js +0 -2
- package/transpiled/directives/cache/Control.js.map +1 -1
- package/transpiled/directives/dev/Development.d.ts +1 -1
- package/transpiled/directives/dev/Development.js +1 -1
- package/transpiled/directives/dev/Development.js.map +1 -1
- package/transpiled/directives/flow/Flow.d.ts +1 -1
- package/transpiled/directives/flow/Flow.js +1 -1
- package/transpiled/directives/flow/Flow.js.map +1 -1
- package/transpiled/directives/index.js +4 -2
- package/transpiled/directives/index.js.map +1 -1
- package/transpiled/directives/io/Directive.d.ts +1 -1
- package/transpiled/directives/io/IO.d.ts +7 -1
- package/transpiled/directives/io/IO.js +25 -3
- package/transpiled/directives/io/IO.js.map +1 -1
- package/transpiled/directives/io/Input.d.ts +3 -2
- package/transpiled/directives/io/Input.js +2 -1
- package/transpiled/directives/io/Input.js.map +1 -1
- package/transpiled/directives/io/Output.d.ts +5 -3
- package/transpiled/directives/io/Output.js +8 -3
- package/transpiled/directives/io/Output.js.map +1 -1
- package/transpiled/directives/io/Status.d.ts +19 -0
- package/transpiled/directives/io/Status.js +34 -0
- package/transpiled/directives/io/Status.js.map +1 -0
- package/transpiled/directives/io/Throttle.d.ts +1 -1
- package/transpiled/directives/io/Throttle.js +1 -1
- package/transpiled/directives/io/Throttle.js.map +1 -1
- package/transpiled/directives/io/lib/throttle/Quotas.d.ts +1 -1
- package/transpiled/directives/io/lib/throttle/Quotas.js +2 -2
- package/transpiled/directives/io/lib/throttle/Quotas.js.map +1 -1
- package/transpiled/directives/map/Headers.d.ts +2 -0
- package/transpiled/directives/map/Headers.js +8 -0
- package/transpiled/directives/map/Headers.js.map +1 -1
- package/transpiled/directives/map/Map.d.ts +3 -1
- package/transpiled/directives/map/Map.js +7 -1
- package/transpiled/directives/map/Map.js.map +1 -1
- package/transpiled/directives/map/Mapping.d.ts +13 -0
- package/transpiled/directives/map/Mapping.js +20 -0
- package/transpiled/directives/map/Mapping.js.map +1 -1
- package/transpiled/directives/map/Segments.d.ts +3 -0
- package/transpiled/directives/map/Segments.js +9 -0
- package/transpiled/directives/map/Segments.js.map +1 -1
- package/transpiled/directives/mcp/MCP.d.ts +15 -0
- package/transpiled/directives/mcp/MCP.js +23 -0
- package/transpiled/directives/mcp/MCP.js.map +1 -0
- package/transpiled/directives/mcp/Tool.d.ts +13 -0
- package/transpiled/directives/mcp/Tool.js +23 -0
- package/transpiled/directives/mcp/Tool.js.map +1 -0
- package/transpiled/directives/mcp/index.d.ts +4 -0
- package/transpiled/directives/mcp/index.js +4 -0
- package/transpiled/directives/mcp/index.js.map +1 -0
- package/transpiled/directives/oauth/Discovery.d.ts +23 -0
- package/transpiled/directives/oauth/Discovery.js +55 -0
- package/transpiled/directives/oauth/Discovery.js.map +1 -0
- package/transpiled/directives/oauth/documents.d.ts +9 -0
- package/transpiled/directives/oauth/documents.js +82 -0
- package/transpiled/directives/oauth/documents.js.map +1 -0
- package/transpiled/directives/oauth/index.d.ts +2 -0
- package/transpiled/directives/oauth/index.js +3 -0
- package/transpiled/directives/oauth/index.js.map +1 -0
- package/transpiled/directives/octets/Octets.d.ts +1 -1
- package/transpiled/directives/octets/Octets.js +1 -1
- package/transpiled/directives/octets/Octets.js.map +1 -1
- package/transpiled/directives/require/Directive.d.ts +1 -1
- package/transpiled/directives/require/Headers.d.ts +1 -1
- package/transpiled/directives/require/Headers.js +1 -1
- package/transpiled/directives/require/Headers.js.map +1 -1
- package/transpiled/directives/require/Require.d.ts +1 -1
- package/transpiled/directives/require/Require.js +2 -2
- package/transpiled/directives/require/Require.js.map +1 -1
- package/transpiled/index.d.ts +2 -0
- package/transpiled/schemas.d.ts +2 -0
- package/transpiled/schemas.js +1 -0
- package/transpiled/schemas.js.map +1 -1
- package/transpiled/userland.d.ts +39 -0
- package/transpiled/userland.js +7 -0
- package/transpiled/userland.js.map +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/components/identity.bans/operations/transit.d.ts +0 -14
- package/components/identity.bans/operations/transit.js.map +0 -1
- package/components/identity.basic/operations/add.d.ts +0 -3
- package/components/identity.basic/operations/add.js.map +0 -1
- package/components/identity.basic/operations/authenticate.d.ts +0 -13
- package/components/identity.basic/operations/authenticate.js.map +0 -1
- package/components/identity.basic/operations/check.d.ts +0 -7
- package/components/identity.basic/operations/check.js.map +0 -1
- package/components/identity.basic/operations/delete.d.ts +0 -7
- package/components/identity.basic/operations/delete.js.map +0 -1
- package/components/identity.basic/operations/incept.d.ts +0 -12
- package/components/identity.basic/operations/incept.js.map +0 -1
- package/components/identity.basic/operations/info.d.ts +0 -10
- package/components/identity.basic/operations/info.js.map +0 -1
- package/components/identity.basic/operations/lib/credentials.d.ts +0 -5
- package/components/identity.basic/operations/lib/credentials.js.map +0 -1
- package/components/identity.basic/operations/transit.d.ts +0 -14
- package/components/identity.basic/operations/transit.js.map +0 -1
- package/components/identity.basic/operations/types.d.ts +0 -61
- package/components/identity.basic/operations/types.js +0 -2
- package/components/identity.basic/operations/types.js.map +0 -1
- package/components/identity.basic/source/types.ts +0 -69
- package/components/identity.credentials/operations/list.d.ts +0 -51
- package/components/identity.credentials/operations/list.js.map +0 -1
- package/components/identity.federation/operations/authenticate.d.ts +0 -16
- package/components/identity.federation/operations/authenticate.js.map +0 -1
- package/components/identity.federation/operations/create.d.ts +0 -8
- package/components/identity.federation/operations/create.js.map +0 -1
- package/components/identity.federation/operations/decode.d.ts +0 -3
- package/components/identity.federation/operations/decode.js.map +0 -1
- package/components/identity.federation/operations/delete.d.ts +0 -8
- package/components/identity.federation/operations/delete.js.map +0 -1
- package/components/identity.federation/operations/incept.d.ts +0 -11
- package/components/identity.federation/operations/incept.js.map +0 -1
- package/components/identity.federation/operations/lib/Configuration.d.ts +0 -39
- package/components/identity.federation/operations/lib/Configuration.js.map +0 -1
- package/components/identity.federation/operations/lib/Ctx.d.ts +0 -8
- package/components/identity.federation/operations/lib/Ctx.js.map +0 -1
- package/components/identity.federation/operations/lib/Payload.d.ts +0 -5
- package/components/identity.federation/operations/lib/Payload.js.map +0 -1
- package/components/identity.federation/operations/lib/decode.d.ts +0 -3
- package/components/identity.federation/operations/lib/decode.js.map +0 -1
- package/components/identity.federation/operations/lib/discovery.d.ts +0 -5
- package/components/identity.federation/operations/lib/discovery.js.map +0 -1
- package/components/identity.federation/operations/lib/errors.d.ts +0 -70
- package/components/identity.federation/operations/lib/errors.js.map +0 -1
- package/components/identity.federation/operations/lib/exchange.d.ts +0 -3
- package/components/identity.federation/operations/lib/exchange.js.map +0 -1
- package/components/identity.federation/operations/lib/index.d.ts +0 -4
- package/components/identity.federation/operations/lib/index.js.map +0 -1
- package/components/identity.federation/operations/lib/jose.d.ts +0 -1
- package/components/identity.federation/operations/lib/jose.js.map +0 -1
- package/components/identity.federation/operations/lib/resolve.d.ts +0 -3
- package/components/identity.federation/operations/lib/resolve.js.map +0 -1
- package/components/identity.federation/operations/list.d.ts +0 -7
- package/components/identity.federation/operations/list.js.map +0 -1
- package/components/identity.federation/operations/types/Scheme.d.ts +0 -1
- package/components/identity.federation/operations/types/Scheme.js.map +0 -1
- package/components/identity.federation/operations/types/configuration.d.ts +0 -22
- package/components/identity.federation/operations/types/configuration.js.map +0 -1
- package/components/identity.federation/operations/types/context.d.ts +0 -35
- package/components/identity.federation/operations/types/context.js.map +0 -1
- package/components/identity.federation/operations/types/entity.d.ts +0 -9
- package/components/identity.federation/operations/types/entity.js.map +0 -1
- package/components/identity.federation/operations/types/index.d.ts +0 -4
- package/components/identity.federation/operations/types/index.js.map +0 -1
- package/components/identity.keys/operations/create.d.ts +0 -22
- package/components/identity.keys/operations/create.js.map +0 -1
- package/components/identity.keys/operations/disable.d.ts +0 -5
- package/components/identity.keys/operations/disable.js.map +0 -1
- package/components/identity.keys/operations/revoke.d.ts +0 -15
- package/components/identity.keys/operations/revoke.js.map +0 -1
- package/components/identity.otp/operations/authenticate.d.ts +0 -12
- package/components/identity.otp/operations/authenticate.js.map +0 -1
- package/components/identity.otp/operations/issue.d.ts +0 -12
- package/components/identity.otp/operations/issue.js.map +0 -1
- package/components/identity.otp/operations/lib/Context.d.ts +0 -14
- package/components/identity.otp/operations/lib/Context.js.map +0 -1
- package/components/identity.otp/operations/lib/Entity.d.ts +0 -6
- package/components/identity.otp/operations/lib/Entity.js.map +0 -1
- package/components/identity.otp/operations/lib/index.d.ts +0 -1
- package/components/identity.otp/operations/lib/index.js.map +0 -1
- package/components/identity.passkeys/operations/authenticate.d.ts +0 -16
- package/components/identity.passkeys/operations/authenticate.js.map +0 -1
- package/components/identity.passkeys/operations/challenge.d.ts +0 -35
- package/components/identity.passkeys/operations/challenge.js.map +0 -1
- package/components/identity.passkeys/operations/create.d.ts +0 -19
- package/components/identity.passkeys/operations/create.js.map +0 -1
- package/components/identity.passkeys/operations/delete.d.ts +0 -8
- package/components/identity.passkeys/operations/delete.js.map +0 -1
- package/components/identity.passkeys/operations/lib/const.d.ts +0 -1
- package/components/identity.passkeys/operations/lib/const.js.map +0 -1
- package/components/identity.passkeys/operations/list.d.ts +0 -7
- package/components/identity.passkeys/operations/list.js.map +0 -1
- package/components/identity.passkeys/operations/types/Configuration.d.ts +0 -6
- package/components/identity.passkeys/operations/types/Configuration.js.map +0 -1
- package/components/identity.passkeys/operations/types/Context.d.ts +0 -15
- package/components/identity.passkeys/operations/types/Context.js.map +0 -1
- package/components/identity.passkeys/operations/types/Passkey.d.ts +0 -12
- package/components/identity.passkeys/operations/types/Passkey.js.map +0 -1
- package/components/identity.passkeys/operations/types/index.d.ts +0 -2
- package/components/identity.passkeys/operations/types/index.js.map +0 -1
- package/components/identity.passkeys/operations/use.d.ts +0 -16
- package/components/identity.passkeys/operations/use.js.map +0 -1
- package/components/identity.roles/operations/grant.d.ts +0 -10
- package/components/identity.roles/operations/grant.js.map +0 -1
- package/components/identity.roles/operations/lib/Entity.d.ts +0 -5
- package/components/identity.roles/operations/lib/Entity.js.map +0 -1
- package/components/identity.roles/operations/list.d.ts +0 -2
- package/components/identity.roles/operations/list.js.map +0 -1
- package/components/identity.roles/operations/principal.d.ts +0 -13
- package/components/identity.roles/operations/principal.js.map +0 -1
- package/components/identity.tokens/operations/authenticate.d.ts +0 -9
- package/components/identity.tokens/operations/authenticate.js.map +0 -1
- package/components/identity.tokens/operations/decrypt.d.ts +0 -15
- package/components/identity.tokens/operations/decrypt.js.map +0 -1
- package/components/identity.tokens/operations/encrypt.d.ts +0 -8
- package/components/identity.tokens/operations/encrypt.js.map +0 -1
- package/components/identity.tokens/operations/issue.d.ts +0 -24
- package/components/identity.tokens/operations/issue.js.map +0 -1
- package/components/identity.tokens/operations/lib/index.d.ts +0 -3
- package/components/identity.tokens/operations/lib/index.js.map +0 -1
- package/components/identity.tokens/operations/lib/jose.d.ts +0 -1
- package/components/identity.tokens/operations/lib/jose.js.map +0 -1
- package/components/identity.tokens/operations/lib/key.d.ts +0 -1
- package/components/identity.tokens/operations/lib/key.js.map +0 -1
- package/components/identity.tokens/operations/lib/pad.d.ts +0 -1
- package/components/identity.tokens/operations/lib/pad.js.map +0 -1
- package/components/identity.tokens/operations/lib/types.d.ts +0 -88
- package/components/identity.tokens/operations/lib/types.js +0 -2
- package/components/identity.tokens/operations/lib/types.js.map +0 -1
- package/components/identity.tokens/operations/revoke.d.ts +0 -2
- package/components/identity.tokens/operations/revoke.js.map +0 -1
- package/components/identity.tokens/source/lib/types.ts +0 -102
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as http from '../HTTP/index.js'
|
|
2
|
+
import { fork } from '../RPC/Context.js'
|
|
3
|
+
import { address, name, split } from '../RPC/names.js'
|
|
4
|
+
import { METHOD_NOT_FOUND, failure, refusal, response } from './errors.js'
|
|
5
|
+
import { annotations, input, output } from './schema.js'
|
|
6
|
+
import { FAMILY, MCP, type Tool as Declaration } from '../directives/mcp/index.js'
|
|
7
|
+
import type { Segment } from '../RTD/segment.js'
|
|
8
|
+
import type { Parameter, Tree } from '../RTD/index.js'
|
|
9
|
+
import type { Params, Result, Tool } from './types.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Every method this caller may reach that is published as a tool, named as the procedure
|
|
13
|
+
* it is.
|
|
14
|
+
*
|
|
15
|
+
* A method is a tool where it says so with `mcp:tool`, and a default denies: a tree holds
|
|
16
|
+
* what an application serves, and most of it is machinery a model has no business reading.
|
|
17
|
+
* What a caller may then do with one is what `auth` says. The tree is walked once and each
|
|
18
|
+
* method describes itself, which is where that is decided and where `io` and `map` say what
|
|
19
|
+
* may be sent.
|
|
20
|
+
*
|
|
21
|
+
* Sorted, because the revision asks for an order a client can cache on.
|
|
22
|
+
*/
|
|
23
|
+
export async function list (tree: Tree, context: http.Context): Promise<Tool[]> {
|
|
24
|
+
const tools: Tool[] = []
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* Each method is described as the procedure it would be, not as the request asking. What
|
|
28
|
+
* refuses a credentialed request at an `anonymous` route does not refuse the call a tool
|
|
29
|
+
* makes, and a list that says otherwise disagrees with what `tools/call` then does.
|
|
30
|
+
*/
|
|
31
|
+
const describing: http.Context = Object.create(context,
|
|
32
|
+
{ procedural: { value: true, enumerable: true } })
|
|
33
|
+
|
|
34
|
+
for (const { segments, verb, method } of tree.walk()) {
|
|
35
|
+
if (MCP.published(method.directives.declared<Declaration>(FAMILY)) === null)
|
|
36
|
+
continue
|
|
37
|
+
|
|
38
|
+
const named = name(segments, verb)
|
|
39
|
+
|
|
40
|
+
// a route a name cannot spell is a route nothing addresses, here or at `/.rpc`
|
|
41
|
+
if (named === null)
|
|
42
|
+
continue
|
|
43
|
+
|
|
44
|
+
const variables = parameters(segments)
|
|
45
|
+
const introspection = await method.explain(describing, variables)
|
|
46
|
+
|
|
47
|
+
if (introspection === null)
|
|
48
|
+
continue
|
|
49
|
+
|
|
50
|
+
const described = introspection.description
|
|
51
|
+
const schema = output(introspection)
|
|
52
|
+
const hints = annotations(verb)
|
|
53
|
+
|
|
54
|
+
// in the order the revision documents one, which is the order it is read in
|
|
55
|
+
const tool: Tool = {
|
|
56
|
+
name: named,
|
|
57
|
+
...described === undefined ? {} : { description: described },
|
|
58
|
+
inputSchema: input(introspection, variables.map((variable) => variable.name)),
|
|
59
|
+
...schema === undefined ? {} : { outputSchema: schema },
|
|
60
|
+
...hints === undefined ? {} : { annotations: hints }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
tools.push(tool)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return tools.sort((one, other) => one.name < other.name ? -1 : 1)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The call the tool is. Its arguments are the procedure's parameters, taken apart the way a
|
|
71
|
+
* request carries them, and what answers is the same `route` an ordinary request goes to.
|
|
72
|
+
*
|
|
73
|
+
* A name that is not a published tool is answered as no tool at all, whether or not a route
|
|
74
|
+
* would have taken it: what an application did not publish is not reachable here by guessing
|
|
75
|
+
* its name. What the caller may then do with one that is published is still `auth`'s to say.
|
|
76
|
+
*/
|
|
77
|
+
export async function call (scope: Scope, named: string, args: Params): Promise<Result> {
|
|
78
|
+
if (!published(scope.tree, named))
|
|
79
|
+
throw new http.NotFound(response(null,
|
|
80
|
+
failure(METHOD_NOT_FOUND, `'${named}' is not a tool this server publishes`)))
|
|
81
|
+
|
|
82
|
+
const { path, verb, variables } = address(named, args)
|
|
83
|
+
const { query, input: body } = split(args, variables)
|
|
84
|
+
const clone = fork(scope.context, path, verb, query, body)
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const message = await scope.route(clone)
|
|
88
|
+
|
|
89
|
+
// what `io:output` restricts, over this call's reply rather than the envelope
|
|
90
|
+
await http.shape(clone, message)
|
|
91
|
+
|
|
92
|
+
return result(message.body)
|
|
93
|
+
} catch (exception) {
|
|
94
|
+
/*
|
|
95
|
+
* What the route made of this call is a value a model reads and may correct itself by:
|
|
96
|
+
* an operation that refused, an argument `io:input` would not take, a record that is
|
|
97
|
+
* not there, an identity `auth` would not let it act on. A credential is none of those
|
|
98
|
+
* — that is the client's to fix and not the model's, so it is answered as it is — and
|
|
99
|
+
* neither is a fault of this server, which is a protocol error and stays one.
|
|
100
|
+
*/
|
|
101
|
+
if (exception instanceof http.ClientError && !(exception instanceof http.Unauthorized))
|
|
102
|
+
return { content: [{ type: 'text', text: refusal(exception) }], isError: true }
|
|
103
|
+
|
|
104
|
+
throw exception
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Everything a call needs that is not the call: the request it is of, and what answers it. */
|
|
109
|
+
export interface Scope {
|
|
110
|
+
context: http.Context
|
|
111
|
+
route: http.Processor
|
|
112
|
+
tree: Tree
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Whether the tree publishes this name as a tool. What `auth` makes of the caller is not
|
|
117
|
+
* asked here — the declaration is the route's and does not vary by who is calling, and the
|
|
118
|
+
* call that follows is authorized as any request to that route is.
|
|
119
|
+
*/
|
|
120
|
+
function published (tree: Tree, named: string): boolean {
|
|
121
|
+
for (const { segments, verb, method } of tree.walk())
|
|
122
|
+
if (name(segments, verb) === named)
|
|
123
|
+
return MCP.published(method.directives.declared<Declaration>(FAMILY)) !== null
|
|
124
|
+
|
|
125
|
+
return false
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function result (body: unknown): Result {
|
|
129
|
+
if (body === undefined || body === null)
|
|
130
|
+
return { content: [] }
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
content: [{ type: 'text', text: JSON.stringify(body) }],
|
|
134
|
+
structuredContent: body
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* What a route template takes, by name. Describing has no values for them — a template is
|
|
140
|
+
* not a path — and nothing that describes a method reads one.
|
|
141
|
+
*/
|
|
142
|
+
function parameters (segments: Segment[]): Parameter[] {
|
|
143
|
+
const params: Parameter[] = []
|
|
144
|
+
|
|
145
|
+
for (const segment of segments) {
|
|
146
|
+
if (segment.fragment !== null)
|
|
147
|
+
continue
|
|
148
|
+
|
|
149
|
+
if (segment.wildcard === true)
|
|
150
|
+
params.push({ name: '**', value: '' })
|
|
151
|
+
else if (segment.placeholder !== null)
|
|
152
|
+
params.push({ name: segment.placeholder, value: '' })
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return params
|
|
156
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** The revision this endpoint serves, where a request carries its own metadata. */
|
|
2
|
+
export const MODERN = '2026-07-28'
|
|
3
|
+
|
|
4
|
+
/** The newest revision reached by an `initialize` handshake, which is what clients still send. */
|
|
5
|
+
export const LEGACY = '2025-11-25'
|
|
6
|
+
|
|
7
|
+
export const VERSIONS = [MODERN, LEGACY]
|
|
8
|
+
|
|
9
|
+
/** The version every JSON-RPC message states, which is not the protocol's. */
|
|
10
|
+
export const JSONRPC = '2.0'
|
|
11
|
+
|
|
12
|
+
/** The prefix the revision reserves for itself in `_meta`. */
|
|
13
|
+
export const RESERVED = 'io.modelcontextprotocol/'
|
|
14
|
+
|
|
15
|
+
export const PROTOCOL_VERSION = RESERVED + 'protocolVersion'
|
|
16
|
+
export const CLIENT_CAPABILITIES = RESERVED + 'clientCapabilities'
|
|
17
|
+
export const SERVER_INFO = RESERVED + 'serverInfo'
|
|
18
|
+
|
|
19
|
+
export type Params = Record<string, unknown>
|
|
20
|
+
|
|
21
|
+
export interface Message {
|
|
22
|
+
jsonrpc: string
|
|
23
|
+
method: string
|
|
24
|
+
params?: Params
|
|
25
|
+
|
|
26
|
+
/** Absent makes this a notification, which is answered by not answering. */
|
|
27
|
+
id?: string | number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface Failure {
|
|
31
|
+
code: number
|
|
32
|
+
message: string
|
|
33
|
+
data?: unknown
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Response {
|
|
37
|
+
jsonrpc: string
|
|
38
|
+
id: string | number | null
|
|
39
|
+
result?: unknown
|
|
40
|
+
error?: Failure
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* How long a complete result may be held, and by whom. `private` is a result that is the
|
|
45
|
+
* caller's alone — a list `auth` filtered for their identity is not another caller's list.
|
|
46
|
+
*/
|
|
47
|
+
export interface Cache {
|
|
48
|
+
ttlMs: number
|
|
49
|
+
cacheScope: 'public' | 'private'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** What a tool answers with: what a model reads, and the reply itself. */
|
|
53
|
+
export interface Result {
|
|
54
|
+
content: Content[]
|
|
55
|
+
structuredContent?: unknown
|
|
56
|
+
|
|
57
|
+
/** The operation refused, which is something a model can read and correct. */
|
|
58
|
+
isError?: boolean
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Content {
|
|
62
|
+
type: 'text'
|
|
63
|
+
text: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface Tool {
|
|
67
|
+
name: string
|
|
68
|
+
|
|
69
|
+
/** what the operation states it is; absent where it states nothing */
|
|
70
|
+
description?: string
|
|
71
|
+
inputSchema: object
|
|
72
|
+
outputSchema?: object
|
|
73
|
+
annotations?: Annotations
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** What the verb says about the call, which the revision asks a client to treat as a hint. */
|
|
77
|
+
export interface Annotations {
|
|
78
|
+
readOnlyHint?: boolean
|
|
79
|
+
destructiveHint?: boolean
|
|
80
|
+
idempotentHint?: boolean
|
|
81
|
+
}
|
package/source/Query.ts
CHANGED
|
@@ -4,6 +4,7 @@ import * as http from './HTTP/index.js'
|
|
|
4
4
|
import { type Parameter } from './RTD/index.js'
|
|
5
5
|
import * as schemas from './schemas.js'
|
|
6
6
|
import { queryable } from './Mapping.js'
|
|
7
|
+
import { take } from './Introspection.js'
|
|
7
8
|
import type { Introspection, Schema } from './Introspection.js'
|
|
8
9
|
import type * as syntax from './RTD/syntax/index.js'
|
|
9
10
|
import type * as core from '@toa.io/core'
|
|
@@ -68,22 +69,43 @@ export class Query {
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
/**
|
|
73
|
+
* What the querystring carries: the parameters this method declares, taken out of the
|
|
74
|
+
* input because they are not the body's, and what a queryable method accepts besides.
|
|
75
|
+
*
|
|
76
|
+
* Only what it actually accepts — a criteria the declaration closes is refused, and so is
|
|
77
|
+
* a search where none was asked for.
|
|
78
|
+
*/
|
|
71
79
|
public explain (introspection: Introspection): Record<string, Schema> | null {
|
|
72
|
-
if (this.query?.parameters === undefined || introspection.input?.type !== 'object')
|
|
73
|
-
return null
|
|
74
|
-
|
|
75
80
|
let query: Record<string, Schema> | null = null
|
|
76
81
|
|
|
77
|
-
|
|
78
|
-
const
|
|
82
|
+
if (this.query?.parameters !== undefined)
|
|
83
|
+
for (const parameter of this.query.parameters) {
|
|
84
|
+
const schema = take(introspection, parameter)
|
|
85
|
+
|
|
86
|
+
// eslint-disable-next-line max-depth
|
|
87
|
+
if (schema === undefined)
|
|
88
|
+
continue
|
|
79
89
|
|
|
80
|
-
if (schema !== undefined) {
|
|
81
90
|
query ??= {}
|
|
82
91
|
query[parameter] = schema
|
|
83
92
|
}
|
|
84
93
|
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
if (!this.queryable)
|
|
95
|
+
return query
|
|
96
|
+
|
|
97
|
+
query ??= {}
|
|
98
|
+
|
|
99
|
+
if (!this.closed)
|
|
100
|
+
query.criteria = keyword('string',
|
|
101
|
+
'What to match, in RSQL: `state==hot`, `rank=gt=5;name==*tea*`.')
|
|
102
|
+
|
|
103
|
+
query.sort = keyword('string', 'What to order by: `rank:desc`, or `rank` for ascending.')
|
|
104
|
+
query.limit = bounded('How many at once.', this.query.limit!)
|
|
105
|
+
query.omit = bounded('How many to skip.', this.query.omit!)
|
|
106
|
+
|
|
107
|
+
if (this.searchable)
|
|
108
|
+
query.search = keyword('string', 'What to search the text index for.')
|
|
87
109
|
|
|
88
110
|
return query
|
|
89
111
|
}
|
|
@@ -202,6 +224,24 @@ interface CriteriaGroup {
|
|
|
202
224
|
operator: ',' | ';'
|
|
203
225
|
}
|
|
204
226
|
|
|
227
|
+
function keyword (type: string, description: string): Schema {
|
|
228
|
+
return { type, description } as unknown as Schema
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function bounded (description: string, bounds: syntax.Range): Schema {
|
|
232
|
+
const schema: Record<string, unknown> = {
|
|
233
|
+
type: 'integer',
|
|
234
|
+
description,
|
|
235
|
+
minimum: bounds.range[0],
|
|
236
|
+
maximum: bounds.range[1]
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (bounds.value !== undefined)
|
|
240
|
+
schema.default = bounds.value
|
|
241
|
+
|
|
242
|
+
return schema as unknown as Schema
|
|
243
|
+
}
|
|
244
|
+
|
|
205
245
|
export interface QueryString {
|
|
206
246
|
query: core.Query | null
|
|
207
247
|
parameters: Record<string, string> | null
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as http from '../HTTP/index.js'
|
|
2
|
+
import { Timing } from '../HTTP/Timing.js'
|
|
3
|
+
import type { Params } from './types.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One call, as a request the rest of the gateway can serve.
|
|
7
|
+
*
|
|
8
|
+
* The clone is the transport context except for what the call decides, so nothing
|
|
9
|
+
* downstream — the router, the directives, the endpoint, the mapping — knows it is one.
|
|
10
|
+
* It is derived from the context rather than built beside it, so everything not named
|
|
11
|
+
* here, `identity` included, is read through.
|
|
12
|
+
*/
|
|
13
|
+
// eslint-disable-next-line max-params
|
|
14
|
+
export function fork (context: http.Context, path: string, verb: string,
|
|
15
|
+
query: Params | undefined, input: unknown): http.Context {
|
|
16
|
+
const url = new URL(path, context.url)
|
|
17
|
+
|
|
18
|
+
if (query !== undefined)
|
|
19
|
+
for (const [name, value] of Object.entries(query))
|
|
20
|
+
url.searchParams.set(name, String(value))
|
|
21
|
+
|
|
22
|
+
const headers = { ...context.request.headers }
|
|
23
|
+
|
|
24
|
+
// a conditional is the envelope's, and a call would answer 304 to a question nobody asked
|
|
25
|
+
delete headers['if-match']
|
|
26
|
+
delete headers['if-none-match']
|
|
27
|
+
|
|
28
|
+
const request = Object.create(context.request, {
|
|
29
|
+
method: { value: verb, enumerable: true },
|
|
30
|
+
headers: { value: headers, enumerable: true }
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// its own, so an `io:output` restriction shapes this call's reply and no other
|
|
34
|
+
const pipelines: Pipelines = { body: [], response: [] }
|
|
35
|
+
|
|
36
|
+
return Object.create(context, {
|
|
37
|
+
/*
|
|
38
|
+
* A credential refuses an `anonymous` route because it would make the reply
|
|
39
|
+
* uncacheable. What a procedure answers is not a reply: it is a value in an envelope
|
|
40
|
+
* this gateway answers `no-store`, and the procedure's own headers are discarded.
|
|
41
|
+
*/
|
|
42
|
+
procedural: { value: true, enumerable: true },
|
|
43
|
+
url: { value: url, enumerable: true },
|
|
44
|
+
request: { value: request, enumerable: true },
|
|
45
|
+
pipelines: { value: pipelines, enumerable: true },
|
|
46
|
+
/*
|
|
47
|
+
* Its own, so that what the stages of a call take is measured per call and stays there.
|
|
48
|
+
* `server-timing` is a header, and a request carrying thirty-two calls would otherwise
|
|
49
|
+
* write ninety-six values into one — where a trace says the same thing, per call.
|
|
50
|
+
*/
|
|
51
|
+
timing: { value: new Timing(), enumerable: true },
|
|
52
|
+
body: {
|
|
53
|
+
value: async () => {
|
|
54
|
+
let value = input
|
|
55
|
+
|
|
56
|
+
for (const transform of pipelines.body)
|
|
57
|
+
value = await transform(value)
|
|
58
|
+
|
|
59
|
+
return value
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
/*
|
|
63
|
+
* The raw request is the envelope, and it has been read. `map:buffer` is the one
|
|
64
|
+
* directive that asks for it, and answering with a spent stream would hand the
|
|
65
|
+
* operation an empty string; refusing says what is actually the matter.
|
|
66
|
+
*/
|
|
67
|
+
buffer: {
|
|
68
|
+
value: () => {
|
|
69
|
+
throw new http.BadRequest('`map:buffer` reads the request, which a call is not')
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}) as http.Context
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface Pipelines {
|
|
76
|
+
body: Array<(input: unknown) => unknown>
|
|
77
|
+
response: Array<(output: http.OutgoingMessage) => void | Promise<void>>
|
|
78
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { console } from 'openspan'
|
|
2
|
+
import * as http from '../HTTP/index.js'
|
|
3
|
+
import * as schemas from '../schemas.js'
|
|
4
|
+
import { BATCH } from '../const.js'
|
|
5
|
+
import { address, split } from './names.js'
|
|
6
|
+
import { fork } from './Context.js'
|
|
7
|
+
import { BATCH_TOO_LARGE, INVALID_REQUEST, PARSE, failure, of, response } from './errors.js'
|
|
8
|
+
import { VERSION, type Call, type Response } from './types.js'
|
|
9
|
+
import type { RPC } from '../Annotation.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* JSON-RPC, as the calls a request carries.
|
|
13
|
+
*
|
|
14
|
+
* It clones the context per call and hands each clone back to the gateway: it holds no
|
|
15
|
+
* tree, no index and no knowledge of routing. Whether a name resolves, what it resolves
|
|
16
|
+
* to, and what the directives of that route do are answered by the same `route` an
|
|
17
|
+
* ordinary request goes through.
|
|
18
|
+
*/
|
|
19
|
+
export class Dispatcher {
|
|
20
|
+
private readonly batch: number
|
|
21
|
+
|
|
22
|
+
public constructor (options: RPC) {
|
|
23
|
+
this.batch = options.batch ?? BATCH
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async dispatch (context: http.Context,
|
|
27
|
+
route: http.Processor): Promise<http.OutgoingMessage> {
|
|
28
|
+
if (context.request.method !== 'POST')
|
|
29
|
+
throw new http.MethodNotAllowed(new Headers({ allow: 'POST' }))
|
|
30
|
+
|
|
31
|
+
const envelope = await this.read(context)
|
|
32
|
+
const batched = Array.isArray(envelope)
|
|
33
|
+
const calls = batched ? envelope : [envelope]
|
|
34
|
+
|
|
35
|
+
if (calls.length === 0)
|
|
36
|
+
throw new http.BadRequest(response(null,
|
|
37
|
+
failure(INVALID_REQUEST, 'A request carries at least one call')))
|
|
38
|
+
|
|
39
|
+
if (calls.length > this.batch)
|
|
40
|
+
throw new http.BadRequest(response(null,
|
|
41
|
+
failure(BATCH_TOO_LARGE, `A request carries at most ${this.batch} calls`)))
|
|
42
|
+
|
|
43
|
+
const answers: Response[] = []
|
|
44
|
+
|
|
45
|
+
// one after another: a request the caller writes should not become a fan-out they own
|
|
46
|
+
for (const call of calls) {
|
|
47
|
+
const answer = await this.answer(call, context, route)
|
|
48
|
+
|
|
49
|
+
if (answer !== null)
|
|
50
|
+
answers.push(answer)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// every call was a notification, and a notification is answered by not answering
|
|
54
|
+
if (answers.length === 0)
|
|
55
|
+
return { status: NO_CONTENT }
|
|
56
|
+
|
|
57
|
+
// a reply assembled from several is not one of them, and is not stored as if it were
|
|
58
|
+
return {
|
|
59
|
+
status: OK,
|
|
60
|
+
body: batched ? answers : answers[0],
|
|
61
|
+
headers: new Headers({ 'cache-control': 'no-store' })
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async answer (input: unknown, context: http.Context,
|
|
66
|
+
route: http.Processor): Promise<Response | null> {
|
|
67
|
+
const invalid = schemas.call.fit(input)
|
|
68
|
+
|
|
69
|
+
// it may have carried an id, but nothing about it is trustworthy enough to answer to
|
|
70
|
+
if (invalid !== null)
|
|
71
|
+
return response(null, failure(INVALID_REQUEST, invalid.message))
|
|
72
|
+
|
|
73
|
+
return await this.call(input as Call, context, route)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private async call (call: Call, context: http.Context,
|
|
77
|
+
route: http.Processor): Promise<Response | null> {
|
|
78
|
+
const notification = call.id === undefined
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const params = call.params ?? {}
|
|
82
|
+
const { path, verb, variables } = address(call.method, params)
|
|
83
|
+
const { query, input } = split(params, variables)
|
|
84
|
+
const clone = fork(context, path, verb, query, input)
|
|
85
|
+
|
|
86
|
+
// one span per call, so what the directives of that call open has somewhere to hang
|
|
87
|
+
const message = await console.span({ name: call.method, attributes: { id: call.id } },
|
|
88
|
+
async () => await route(clone))
|
|
89
|
+
|
|
90
|
+
// what `io:output` restricts, over this call's reply rather than the envelope
|
|
91
|
+
await http.shape(clone, message)
|
|
92
|
+
|
|
93
|
+
if (notification)
|
|
94
|
+
return null
|
|
95
|
+
|
|
96
|
+
return { jsonrpc: VERSION, id: call.id!, result: message.body ?? null }
|
|
97
|
+
} catch (exception) {
|
|
98
|
+
/*
|
|
99
|
+
* A credential belongs to the request. Refusing one call for it would leave the
|
|
100
|
+
* reply a 200, and the challenge that tells a client where to authenticate is
|
|
101
|
+
* attached to a 401 — so the whole envelope is refused instead.
|
|
102
|
+
*/
|
|
103
|
+
if (exception instanceof http.Unauthorized)
|
|
104
|
+
throw exception
|
|
105
|
+
|
|
106
|
+
if (notification) {
|
|
107
|
+
console.debug('Notification failed', { method: call.method, error: of(exception) })
|
|
108
|
+
|
|
109
|
+
return null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return { jsonrpc: VERSION, id: call.id!, error: of(exception) }
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A body the decoder refuses is a parse error; a media type it does not know is not. */
|
|
117
|
+
private async read (context: http.Context): Promise<unknown> {
|
|
118
|
+
try {
|
|
119
|
+
return await context.body()
|
|
120
|
+
} catch (exception) {
|
|
121
|
+
if (exception instanceof http.BadRequest)
|
|
122
|
+
throw new http.BadRequest(response(null, failure(PARSE, 'Parse error')))
|
|
123
|
+
|
|
124
|
+
throw exception
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const OK = 200
|
|
130
|
+
const NO_CONTENT = 204
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, it } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import * as http from '../HTTP/index.js'
|
|
5
|
+
import {
|
|
6
|
+
FORBIDDEN, INTERNAL, INVALID_PARAMS, METHOD_NOT_FOUND, REFUSED, of
|
|
7
|
+
} from './errors.js'
|
|
8
|
+
|
|
9
|
+
describe('of', () => {
|
|
10
|
+
it('should read a missing route as a missing method', () => {
|
|
11
|
+
assert.deepEqual(of(new http.NotFound('pots/_id/FETCH names no method')),
|
|
12
|
+
{ code: METHOD_NOT_FOUND, message: 'pots/_id/FETCH names no method' })
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('should read a verb the node does not declare as a missing method', () => {
|
|
16
|
+
assert.deepEqual(of(new http.MethodNotAllowed()),
|
|
17
|
+
{ code: METHOD_NOT_FOUND, message: 'Method not found' })
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should read a refused authorization as forbidden', () => {
|
|
21
|
+
assert.deepEqual(of(new http.Forbidden()), { code: FORBIDDEN, message: 'Forbidden' })
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('should read a bad request as invalid params', () => {
|
|
25
|
+
assert.deepEqual(of(new http.BadRequest('Query limit must be between 1 and 100')),
|
|
26
|
+
{ code: INVALID_PARAMS, message: 'Query limit must be between 1 and 100' })
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should carry the code an operation refused with', () => {
|
|
30
|
+
const error = Object.assign(new Error(), { code: 'WONT_CREATE', message: 'Volume is out of range' })
|
|
31
|
+
|
|
32
|
+
assert.deepEqual(of(new http.UnprocessableEntity(error)),
|
|
33
|
+
{ code: REFUSED, message: 'Volume is out of range', data: { code: 'WONT_CREATE' } })
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('should stand the code in for a message the operation did not declare', () => {
|
|
37
|
+
const error = Object.assign(new Error(), { code: 'WONT_CREATE' })
|
|
38
|
+
|
|
39
|
+
assert.deepEqual(of(new http.UnprocessableEntity(error)),
|
|
40
|
+
{ code: REFUSED, message: 'WONT_CREATE', data: { code: 'WONT_CREATE' } })
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should say what any other client error was refused with', () => {
|
|
44
|
+
assert.deepEqual(of(new http.Conflict()),
|
|
45
|
+
{ code: REFUSED, message: 'Refused', data: { status: 409 } })
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should say nothing of what it did not mean to answer', () => {
|
|
49
|
+
assert.deepEqual(of(new Error('the connection dropped')),
|
|
50
|
+
{ code: INTERNAL, message: 'Internal error' })
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as http from '../HTTP/index.js'
|
|
2
|
+
import { VERSION, type Failure, type Response } from './types.js'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* The five the specification fixes (JSON-RPC 2.0 §5.1). A client reads these the same
|
|
6
|
+
* whoever answers.
|
|
7
|
+
*/
|
|
8
|
+
export const PARSE = -32700
|
|
9
|
+
export const INVALID_REQUEST = -32600
|
|
10
|
+
export const METHOD_NOT_FOUND = -32601
|
|
11
|
+
export const INVALID_PARAMS = -32602
|
|
12
|
+
export const INTERNAL = -32603
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Ours. The specification reserves -32000 to -32099 for implementation-defined server
|
|
16
|
+
* errors and defines nothing in it, so these mean nothing outside Toa — which is why
|
|
17
|
+
* `REFUSED` carries the operation's own code in `data`.
|
|
18
|
+
*/
|
|
19
|
+
export const FORBIDDEN = -32000
|
|
20
|
+
export const REFUSED = -32001
|
|
21
|
+
export const BATCH_TOO_LARGE = -32002
|
|
22
|
+
|
|
23
|
+
export function failure (code: number, message: string, data?: unknown): Failure {
|
|
24
|
+
const value: Failure = { code, message }
|
|
25
|
+
|
|
26
|
+
if (data !== undefined)
|
|
27
|
+
value.data = data
|
|
28
|
+
|
|
29
|
+
return value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function response (id: string | number | null, error: Failure): Response {
|
|
33
|
+
return { jsonrpc: VERSION, id, error }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* What an exception says as a JSON-RPC error.
|
|
38
|
+
*
|
|
39
|
+
* The readable text is `body`, never `message`: `http.Exception` calls `super()` with no
|
|
40
|
+
* argument, so every one of them carries an empty `message`.
|
|
41
|
+
*/
|
|
42
|
+
export function of (exception: unknown): Failure {
|
|
43
|
+
if (exception instanceof http.UnprocessableEntity)
|
|
44
|
+
return refusal(exception)
|
|
45
|
+
|
|
46
|
+
if (exception instanceof http.NotFound || exception instanceof http.MethodNotAllowed)
|
|
47
|
+
return failure(METHOD_NOT_FOUND, text(exception, 'Method not found'))
|
|
48
|
+
|
|
49
|
+
if (exception instanceof http.Forbidden)
|
|
50
|
+
return failure(FORBIDDEN, text(exception, 'Forbidden'))
|
|
51
|
+
|
|
52
|
+
if (exception instanceof http.BadRequest)
|
|
53
|
+
return failure(INVALID_PARAMS, text(exception, 'Invalid params'))
|
|
54
|
+
|
|
55
|
+
// a conflict, a precondition, a throttle: the call was refused, and by what is worth saying
|
|
56
|
+
if (exception instanceof http.ClientError)
|
|
57
|
+
return failure(REFUSED, text(exception, 'Refused'), { status: exception.status })
|
|
58
|
+
|
|
59
|
+
return failure(INTERNAL, 'Internal error')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* An operation that declares its errors answers with one rather than throwing, and the
|
|
64
|
+
* reply contract states `{ code, message? }` — the message optional. The number says the
|
|
65
|
+
* operation refused; `data.code` says what it refused with, and is what a caller branches on.
|
|
66
|
+
*/
|
|
67
|
+
function refusal (exception: http.UnprocessableEntity): Failure {
|
|
68
|
+
const body = exception.body
|
|
69
|
+
|
|
70
|
+
if (typeof body !== 'object' || body === null || typeof body.code !== 'string')
|
|
71
|
+
return failure(REFUSED, text(exception, 'Refused'))
|
|
72
|
+
|
|
73
|
+
const code = body.code as string
|
|
74
|
+
const message = typeof body.message === 'string' && body.message !== '' ? body.message : code
|
|
75
|
+
|
|
76
|
+
return failure(REFUSED, message, { code })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function text (exception: http.Exception, fallback: string): string {
|
|
80
|
+
return typeof exception.body === 'string' && exception.body !== ''
|
|
81
|
+
? exception.body
|
|
82
|
+
: fallback
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Dispatcher } from './Dispatcher.js'
|