Skip to content

Commit

Permalink
fix(ucanto): capability provider inference (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala authored Jun 23, 2022
1 parent 9b0e8e4 commit 4fa6876
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
9 changes: 8 additions & 1 deletion packages/server/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as API from '@ucanto/interface'
import { InferCaveats, CanIssue } from '@ucanto/interface'
import { InferCaveats, CanIssue, ParsedCapability } from '@ucanto/interface'

export * from '@ucanto/interface'

Expand Down Expand Up @@ -28,3 +28,10 @@ export interface ProviderContext<

context: API.InvocationContext
}

export interface ProviderInput<T extends ParsedCapability> {
capability: T
invocation: API.Invocation<API.Capability<T['can'], T['with']> & T['caveats']>

context: API.InvocationContext
}
13 changes: 4 additions & 9 deletions packages/server/src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@ import * as API from './api.js'
import { access } from '@ucanto/validator'

/**
* @template {API.Ability} A
* @template {API.Caveats} C
* @template {API.URI} R
* @template {API.ParsedCapability} T
* @template {unknown} U
* @template {API.Match} Z
* @template {API.ParsedCapability<A, R, API.InferCaveats<C>>} T
* @param {API.CapabilityParser<API.Match<T, Z>>} capability
* @param {(input:API.ProviderContext<A, R, C>) => API.Await<U>} handler
* @returns {API.ServiceMethod<API.Capability<A, R['href']> & API.InferCaveats<C>, Exclude<U, {error:true}>, Exclude<U, Exclude<U, {error:true}>>>}
* @param {API.CapabilityParser<API.Match<T>>} capability
* @param {(input:API.ProviderInput<T>) => API.Await<U>} handler
* @returns {API.ServiceMethod<API.Capability<T['can'], T['with']> & T['caveats'], Exclude<U, {error:true}>, Exclude<U, Exclude<U, {error:true}>>>}
*/

export const provide =
(capability, handler) =>
/**
* @param {API.Invocation<API.Capability<T['can'], T['with']> & T['caveats']>} invocation
* @param {API.InvocationContext} options
* @return {Promise<API.Result<Exclude<U, {error:true}>, Exclude<U, Exclude<U, {error:true}>>|API.InvocationError>>}
*/
async (invocation, options) => {
const authorization = await access(invocation, {
Expand Down

0 comments on commit 4fa6876

Please sign in to comment.