@ucanto/server
Advanced tools
Comparing version 7.0.2 to 8.0.0
export * from './api.js' | ||
export * from '@ucanto/core' | ||
export * from './server.js' | ||
@@ -9,4 +10,5 @@ export { | ||
URI, | ||
ok, | ||
error, | ||
} from './server.js' | ||
export * from '@ucanto/core' | ||
export { | ||
@@ -13,0 +15,0 @@ invoke, |
export function provide<A extends API.Ability, R extends API.URI<`${string}:`>, C extends API.Caveats, O extends {}, X extends API.Failure, Result extends API.Result<O, X>>(capability: API.CapabilityParser<API.Match<API.ParsedCapability<A, R, C>, API.UnknownMatch>>, handler: (input: API.ProviderInput<API.ParsedCapability<A, R, C>>) => API.Await<Result>): API.ServiceMethod<API.Capability<A, R, C>, O & Result["ok"], X & Result["error"]>; | ||
export function provideAdvanced<A extends API.Ability, R extends API.URI<`${string}:`>, C extends API.Caveats, O extends {}, X extends API.Failure, Result extends API.Result<O, X>>({ capability, handler, audience }: { | ||
export function provideAdvanced<A extends API.Ability, R extends API.URI<`${string}:`>, C extends API.Caveats, O extends {}, X extends API.Failure, Result extends API.Transaction<O, X>>({ capability, handler, audience }: { | ||
audience?: API.Reader<`did:${string}:${string}`, any, API.Failure> | undefined; | ||
capability: API.CapabilityParser<API.Match<API.ParsedCapability<A, R, C>, API.UnknownMatch>>; | ||
handler: (input: API.ProviderInput<API.ParsedCapability<A, R, C>>) => API.Await<Result>; | ||
}): API.ServiceMethod<API.Capability<A, R, C>, O & Result["ok"], X & Result["error"]>; | ||
}): API.ServiceMethod<API.Capability<A, R, C>, O & API.InferTransaction<Result>["ok"], X & API.InferTransaction<Result>["error"]>; | ||
export function ok<T extends {}, X extends API.Failure>(value: T): API.OkBuilder<T, X>; | ||
export function error<T extends {}, X extends API.Failure>(error: X): API.ErrorBuilder<T, X>; | ||
import * as API from "./api.js"; | ||
//# sourceMappingURL=handler.d.ts.map |
export * from "./api.js"; | ||
export * from "@ucanto/core"; | ||
export * from "./server.js"; | ||
export * from "@ucanto/core"; | ||
export * from "./handler.js"; | ||
export * as API from "./api.js"; | ||
export { Failure, MalformedCapability, HandlerNotFound, Link, URI } from "./server.js"; | ||
export { Failure, MalformedCapability, HandlerNotFound, Link, URI, ok, error } from "./server.js"; | ||
export { invoke, Invocation, Receipt, Delegation, DID, Signature } from "@ucanto/core"; | ||
export { access, claim, Schema } from "@ucanto/validator"; | ||
//# sourceMappingURL=lib.d.ts.map |
@@ -0,1 +1,2 @@ | ||
export { fail }; | ||
export function create<Service extends Record<string, any>>(options: API.Server<Service>): API.ServerView<Service>; | ||
@@ -46,4 +47,3 @@ export function handle<S extends Record<string, any>, I extends API.Transport.Tuple<API.ServiceInvocation<API.Capability<API.Ability, `${string}:${string}`, any>, S>>>(server: API.ServerView<S>, request: API.HTTPRequest<API.AgentMessage<{ | ||
} | ||
import { ok } from "@ucanto/core/result"; | ||
import { fail } from "@ucanto/core/result"; | ||
import { fail } from "@ucanto/core/result.js"; | ||
import * as API from "@ucanto/interface"; | ||
@@ -89,4 +89,4 @@ /** | ||
import { Receipt } from "@ucanto/core"; | ||
export { ok, fail }; | ||
export { capability, URI, Link, Failure, MalformedCapability } from "@ucanto/validator"; | ||
export { ok, error } from "./handler.js"; | ||
//# sourceMappingURL=server.d.ts.map |
{ | ||
"name": "@ucanto/server", | ||
"description": "UCAN RPC Server", | ||
"version": "7.0.2", | ||
"version": "8.0.0", | ||
"types": "./dist/src/lib.d.ts", | ||
@@ -23,4 +23,4 @@ "main": "./src/lib.js", | ||
"dependencies": { | ||
"@ucanto/core": "^7.0.1", | ||
"@ucanto/interface": "^7.0.1", | ||
"@ucanto/core": "^8.0.0", | ||
"@ucanto/interface": "^8.0.0", | ||
"@ucanto/validator": "^7.0.0" | ||
@@ -43,3 +43,3 @@ }, | ||
"@ucanto/principal": "^7.0.0", | ||
"@ucanto/transport": "^7.0.2" | ||
"@ucanto/transport": "^7.0.3" | ||
}, | ||
@@ -46,0 +46,0 @@ "exports": { |
@@ -37,3 +37,3 @@ import * as API from './api.js' | ||
* @template {API.Failure} X | ||
* @template {API.Result<O, X>} Result | ||
* @template {API.Transaction<O, X>} Result | ||
* @param {object} input | ||
@@ -43,3 +43,3 @@ * @param {API.Reader<API.DID>} [input.audience] | ||
* @param {(input:API.ProviderInput<API.ParsedCapability<A, R, C>>) => API.Await<Result>} input.handler | ||
* @returns {API.ServiceMethod<API.Capability<A, R, C>, O & Result['ok'], X & Result['error']>} | ||
* @returns {API.ServiceMethod<API.Capability<A, R, C>, O & API.InferTransaction<Result>['ok'], X & API.InferTransaction<Result>['error']>} | ||
*/ | ||
@@ -97,1 +97,174 @@ | ||
} | ||
/** | ||
* @template {unknown} T | ||
* @template {{}} X | ||
* @implements {API.OkBuilder<T, X>} | ||
*/ | ||
class Ok { | ||
/** | ||
* @param {T} ok | ||
*/ | ||
constructor(ok) { | ||
this.ok = ok | ||
} | ||
get result() { | ||
return { ok: this.ok } | ||
} | ||
get effects() { | ||
return { fork: [] } | ||
} | ||
/** | ||
* @param {API.Run} run | ||
* @returns {API.ForkBuilder<T, X>} | ||
*/ | ||
fork(run) { | ||
return new Fork({ | ||
out: this.result, | ||
fx: { | ||
fork: [run], | ||
}, | ||
}) | ||
} | ||
/** | ||
* @param {API.Run} run | ||
* @returns {API.JoinBuilder<T, X>} | ||
*/ | ||
join(run) { | ||
return new Join({ | ||
out: this.result, | ||
fx: { | ||
fork: [], | ||
join: run, | ||
}, | ||
}) | ||
} | ||
} | ||
/** | ||
* @template {unknown} T | ||
* @template {{}} X | ||
* @implements {API.ErrorBuilder<T, X>} | ||
*/ | ||
class Error { | ||
/** | ||
* @param {X} error | ||
*/ | ||
constructor(error) { | ||
this.error = error | ||
} | ||
get result() { | ||
return { error: this.error } | ||
} | ||
get effects() { | ||
return { fork: [] } | ||
} | ||
/** | ||
* @param {API.Run} run | ||
* @returns {API.ForkBuilder<T, X>} | ||
*/ | ||
fork(run) { | ||
return new Fork({ | ||
out: this.result, | ||
fx: { | ||
fork: [run], | ||
}, | ||
}) | ||
} | ||
/** | ||
* @param {API.Run} run | ||
* @returns {API.JoinBuilder<T, X>} | ||
*/ | ||
join(run) { | ||
return new Join({ | ||
out: this.result, | ||
fx: { | ||
fork: [], | ||
join: run, | ||
}, | ||
}) | ||
} | ||
} | ||
/** | ||
* @template {unknown} T | ||
* @template {{}} X | ||
* @implements {API.JoinBuilder<T, X>} | ||
*/ | ||
class Join { | ||
/** | ||
* @param {API.Do<T, X>} model | ||
*/ | ||
constructor(model) { | ||
this.do = model | ||
} | ||
get result() { | ||
return this.do.out | ||
} | ||
get effects() { | ||
return this.do.fx | ||
} | ||
/** | ||
* @param {API.Run} run | ||
* @returns {API.JoinBuilder<T, X>} | ||
*/ | ||
fork(run) { | ||
const { out, fx } = this.do | ||
return new Join({ | ||
out, | ||
fx: { | ||
...fx, | ||
fork: [...fx.fork, run], | ||
}, | ||
}) | ||
} | ||
} | ||
/** | ||
* @template {unknown} T | ||
* @template {{}} X | ||
* @extends {Join<T, X>} | ||
* @implements {API.ForkBuilder<T, X>} | ||
*/ | ||
class Fork extends Join { | ||
/** | ||
* @param {API.Run} run | ||
* @returns {API.JoinBuilder<T, X>} | ||
*/ | ||
join(run) { | ||
const { out, fx } = this.do | ||
return new Join({ | ||
out, | ||
fx: { ...fx, join: run }, | ||
}) | ||
} | ||
/** | ||
* @param {API.Run} run | ||
* @returns {API.ForkBuilder<T, X>} | ||
*/ | ||
fork(run) { | ||
const { out, fx } = this.do | ||
return new Fork({ | ||
out, | ||
fx: { ...fx, fork: [...fx.fork, run] }, | ||
}) | ||
} | ||
} | ||
/** | ||
* @template {{}} T | ||
* @template {API.Failure} X | ||
* @param {T} value | ||
* @returns {API.OkBuilder<T, X>} | ||
*/ | ||
export const ok = value => new Ok(value) | ||
/** | ||
* @template {{}} T | ||
* @template {API.Failure} X | ||
* @param {X} error | ||
* @returns {API.ErrorBuilder<T, X>} | ||
*/ | ||
export const error = error => new Error(error) |
export * from './api.js' | ||
export * from '@ucanto/core' | ||
export * from './server.js' | ||
@@ -9,4 +10,5 @@ export { | ||
URI, | ||
ok, | ||
error, | ||
} from './server.js' | ||
export * from '@ucanto/core' | ||
export { | ||
@@ -13,0 +15,0 @@ invoke, |
@@ -10,5 +10,5 @@ import * as API from '@ucanto/interface' | ||
} from '@ucanto/validator' | ||
import { Receipt, ok, fail, Message, Failure } from '@ucanto/core' | ||
export { ok, fail } | ||
import { Receipt, Message, Failure, fail } from '@ucanto/core' | ||
export { ok, error } from './handler.js' | ||
export { fail } | ||
/** | ||
@@ -140,3 +140,6 @@ * Creates a connection to a service. | ||
try { | ||
const result = await handler[method](invocation, server.context) | ||
const outcome = await handler[method](invocation, server.context) | ||
const result = outcome.do ? outcome.do.out : outcome | ||
const fx = outcome.do ? outcome.do.fx : undefined | ||
return await Receipt.issue({ | ||
@@ -146,2 +149,3 @@ issuer: server.id, | ||
result, | ||
fx, | ||
}) | ||
@@ -269,2 +273,3 @@ } catch (cause) { | ||
* @param {string[]} path | ||
* @returns {null|Record<string, API.ServiceMethod<API.Capability, {}, API.Failure>>} | ||
*/ | ||
@@ -271,0 +276,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
26191
717
+ Added@ucanto/core@8.2.0(transitive)
+ Added@ucanto/interface@8.1.0(transitive)
Updated@ucanto/core@^8.0.0
Updated@ucanto/interface@^8.0.0