Skip to content

Commit

Permalink
fix: error inference of provide (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala authored Apr 25, 2023
1 parent b6dd279 commit 5ed3651
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions packages/server/src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { access, Schema, Failure } from '@ucanto/validator'
* @template {API.Ability} A
* @template {API.URI} R
* @template {API.Caveats} C
* @template {API.Result<{}, {}>} Result
* @template {{}} O
* @template {API.Failure} X
* @template {API.Result<O, X>} Result
* @param {API.CapabilityParser<API.Match<API.ParsedCapability<A, R, C>>>} capability
* @param {(input:API.ProviderInput<API.ParsedCapability<A, R, C>>) => API.Await<Result>} handler
* @returns {API.ServiceMethod<API.Capability<A, R, C>, Result['ok'] & {}, Result['error'] & {}>}
* @returns {API.ServiceMethod<API.Capability<A, R, C>, O & Result['ok'], X & Result['error']>}
*/

export const provide = (capability, handler) =>
Expand All @@ -31,12 +33,13 @@ export const provide = (capability, handler) =>
* @template {API.URI} R
* @template {API.Caveats} C
* @template {{}} O
* @template {{}} X
* @template {API.Failure} X
* @template {API.Result<O, X>} Result
* @param {object} input
* @param {API.Reader<API.DID>} [input.audience]
* @param {API.CapabilityParser<API.Match<API.ParsedCapability<A, R, C>>>} input.capability
* @param {(input:API.ProviderInput<API.ParsedCapability<A, R, C>>) => API.Await<API.Result<O, X>>} input.handler
* @returns {API.ServiceMethod<API.Capability<A, R, C>, O, X>}
* @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']>}
*/

export const provideAdvanced =
Expand Down
8 changes: 4 additions & 4 deletions packages/server/test/handler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ test('test access/claim provider', async () => {
/**
* @type {Client.ConnectionView<{
* access: {
* claim: API.ServiceMethod<API.InferInvokedCapability<typeof Access.claimCapability>, never[], {}>
* claim: API.ServiceMethod<API.InferInvokedCapability<typeof Access.claimCapability>, never[], API.Failure>
* }
* }>}
*/
Expand Down Expand Up @@ -350,19 +350,19 @@ test('union result', () => {
})

/**
* @type {API.ServiceMethod<API.InferInvokedCapability<typeof add>, ({status: 'done'}|{status:'pending', progress: number}), {}>}
* @type {API.ServiceMethod<API.InferInvokedCapability<typeof add>, ({status: 'done'}|{status:'pending', progress: number}), API.Failure>}
*/
const provider = Provider.provide(add, async ({ capability }) => {
if (capability.nb.key === 'done') {
return {
ok: {
status: /** @type {const} */ ('done'),
status: 'done',
},
}
} else {
return {
ok: {
status: /** @type {const} */ ('pending'),
status: 'pending',
progress: 5,
},
}
Expand Down

0 comments on commit 5ed3651

Please sign in to comment.