@ucanto/server
Advanced tools
Comparing version 0.6.4 to 0.7.0
{ | ||
"name": "@ucanto/server", | ||
"description": "UCAN RPC Server", | ||
"version": "0.6.4", | ||
"version": "0.7.0", | ||
"types": "./dist/src/lib.d.ts", | ||
@@ -23,23 +23,23 @@ "main": "./src/lib.js", | ||
"dependencies": { | ||
"@ucanto/interface": "^0.6.2", | ||
"@ucanto/core": "^0.5.4", | ||
"@ucanto/validator": "^0.5.5" | ||
"@ucanto/core": "^0.6.0", | ||
"@ucanto/interface": "^0.7.0", | ||
"@ucanto/validator": "^0.6.0" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^9.1.0", | ||
"@types/chai": "^4.3.0", | ||
"@types/chai-subset": "^1.3.3", | ||
"mocha": "^9.2.2", | ||
"chai": "^4.3.6", | ||
"chai-subset": "^1.6.0", | ||
"playwright-test": "^7.3.0", | ||
"@types/mocha": "^9.1.0", | ||
"@ucanto/authority": "^0.5.0", | ||
"@ucanto/client": "^0.6.0", | ||
"@ucanto/transport": "^0.7.0", | ||
"@web-std/fetch": "^4.1.0", | ||
"@web-std/file": "^3.0.2", | ||
"c8": "^7.11.0", | ||
"chai": "^4.3.6", | ||
"chai-subset": "^1.6.0", | ||
"mocha": "^9.2.2", | ||
"multiformats": "^9.6.4", | ||
"nyc": "^15.1.0", | ||
"typescript": "^4.7.2", | ||
"@ucanto/client": "^0.5.4", | ||
"@ucanto/transport": "^0.6.3", | ||
"@ucanto/authority": "^0.4.5", | ||
"multiformats": "^9.6.4" | ||
"playwright-test": "^7.3.0", | ||
"typescript": "^4.7.4" | ||
}, | ||
@@ -62,3 +62,3 @@ "exports": { | ||
"test": "npm run test:node", | ||
"coverage": "c8 --reporter=html mocha test/test-*.js && npm_config_yes=true npx st -d coverage -p 8080", | ||
"coverage": "c8 --reporter=html mocha test/**/*.spec.js && npm_config_yes=true npx st -d coverage -p 8080", | ||
"typecheck": "tsc --build", | ||
@@ -65,0 +65,0 @@ "build": "tsc --build" |
@@ -34,2 +34,3 @@ import * as API from '@ucanto/interface' | ||
decoder, | ||
catch: fail, | ||
authority = Authority, | ||
@@ -44,2 +45,3 @@ canIssue = (capability, issuer) => | ||
this.decoder = decoder | ||
this.catch = fail || (() => {}) | ||
} | ||
@@ -65,10 +67,10 @@ get id() { | ||
* @template {API.Tuple<API.ServiceInvocation<C, T>>} I | ||
* @param {API.ServerView<T>} handler | ||
* @param {API.ServerView<T>} server | ||
* @param {API.HTTPRequest<I>} request | ||
* @returns {Promise<API.HTTPResponse<API.InferServiceInvocations<I, T>>>} | ||
*/ | ||
export const handle = async (handler, request) => { | ||
const invocations = await handler.decoder.decode(request) | ||
const result = await execute(invocations, handler) | ||
return handler.encoder.encode(result) | ||
export const handle = async (server, request) => { | ||
const invocations = await server.decoder.decode(request) | ||
const result = await execute(invocations, server) | ||
return server.encoder.encode(result) | ||
} | ||
@@ -107,5 +109,14 @@ | ||
if (invocation.audience.did() !== server.id.did()) { | ||
return /** @type {any} */ (new InvalidAudience(server.id, invocation)) | ||
return /** @type {API.Result<any, API.InvalidAudience>} */ ( | ||
new InvalidAudience(server.id, invocation) | ||
) | ||
} | ||
// Invocation needs to have one single capability | ||
if (invocation.capabilities.length !== 1) { | ||
return /** @type {API.Result<any, InvocationCapabilityError>} */ ( | ||
new InvocationCapabilityError(invocation.capabilities) | ||
) | ||
} | ||
const [capability] = invocation.capabilities | ||
@@ -124,9 +135,10 @@ | ||
} catch (error) { | ||
return /** @type {API.Result<any, API.HandlerExecutionError>} */ ( | ||
new HandlerExecutionError( | ||
/** @type {API.Result<any, API.HandlerNotFound>} */ | ||
capability, | ||
/** @type {Error} */ (error) | ||
) | ||
const err = new HandlerExecutionError( | ||
capability, | ||
/** @type {Error} */ (error) | ||
) | ||
server.catch(err) | ||
return /** @type {API.Result<any, API.HandlerExecutionError>} */ (err) | ||
} | ||
@@ -179,4 +191,7 @@ } | ||
this.cause = cause | ||
/** @type { true } */ | ||
this.error = true | ||
} | ||
/** @type {'HandlerExecutionError'} */ | ||
get name() { | ||
@@ -208,2 +223,28 @@ return 'HandlerExecutionError' | ||
class InvocationCapabilityError extends Error { | ||
/** | ||
* @param {any} caps | ||
*/ | ||
constructor(caps) { | ||
super() | ||
/** @type {true} */ | ||
this.error = true | ||
this.caps = caps | ||
} | ||
get name() { | ||
return 'InvocationCapabilityError' | ||
} | ||
get message() { | ||
return `Invocation is required to have a single capability.` | ||
} | ||
toJSON() { | ||
return { | ||
name: this.name, | ||
error: this.error, | ||
message: this.message, | ||
capabilities: this.caps, | ||
} | ||
} | ||
} | ||
/** | ||
@@ -210,0 +251,0 @@ * @param {Record<string, any>} service |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17731
14
404
1
+ Added@ucanto/core@0.6.0(transitive)
+ Added@ucanto/interface@0.7.0(transitive)
+ Added@ucanto/validator@0.6.0(transitive)
- Removed@ucanto/core@0.5.4(transitive)
- Removed@ucanto/interface@0.6.2(transitive)
- Removed@ucanto/validator@0.5.5(transitive)
Updated@ucanto/core@^0.6.0
Updated@ucanto/interface@^0.7.0
Updated@ucanto/validator@^0.6.0