Skip to content

Commit

Permalink
fix: remaining problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Feb 10, 2023
1 parent c3b68b4 commit 0e1880a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
4 changes: 0 additions & 4 deletions packages/interface/src/capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,6 @@ export interface ParsedCapability<
nb: C
}

export type InferCaveats<C> = Optionalize<{
[K in keyof C]: C[K] extends Reader<infer T, unknown, infer _> ? T : never
}>

export interface Descriptor<
A extends Ability,
R extends URI,
Expand Down
6 changes: 3 additions & 3 deletions 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, ParsedCapability } from '@ucanto/interface'
import { CanIssue, ParsedCapability } from '@ucanto/interface'

export * from '@ucanto/interface'

Expand All @@ -23,8 +23,8 @@ export interface ProviderContext<
R extends API.URI = API.URI,
C extends API.Caveats = API.Caveats
> {
capability: API.ParsedCapability<A, R, API.InferCaveats<C>>
invocation: API.Invocation<API.Capability<A, R, API.InferCaveats<C>>>
capability: API.ParsedCapability<A, R, C>
invocation: API.Invocation<API.Capability<A, R, C>>

context: API.InvocationContext
}
Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { access } from '@ucanto/validator'
* @template {API.URI} R
* @template {API.Caveats} C
* @template {unknown} U
* @param {API.CapabilityParser<API.Match<API.ParsedCapability<A, R, API.InferCaveats<C>>>>} capability
* @param {(input:API.ProviderInput<API.ParsedCapability<A, R, API.InferCaveats<C>>>) => API.Await<U>} handler
* @returns {API.ServiceMethod<API.Capability<A, R, API.InferCaveats<C>>, Exclude<U, {error:true}>, Exclude<U, Exclude<U, {error:true}>>>}
* @param {API.CapabilityParser<API.Match<API.ParsedCapability<A, R, C>>>} capability
* @param {(input:API.ProviderInput<API.ParsedCapability<A, R, C>>) => API.Await<U>} handler
* @returns {API.ServiceMethod<API.Capability<A, R, C>, Exclude<U, {error:true}>, Exclude<U, Exclude<U, {error:true}>>>}
*/

export const provide =
(capability, handler) =>
/**
* @param {API.Invocation<API.Capability<A, R, API.InferCaveats<C>>>} invocation
* @param {API.Invocation<API.Capability<A, R, C>>} invocation
* @param {API.InvocationContext} options
*/
async (invocation, options) => {
Expand Down
9 changes: 5 additions & 4 deletions packages/server/test/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import * as CBOR from '@ucanto/transport/cbor'
import { alice, bob, mallory, service as w3 } from './fixtures.js'
import * as Service from '../../client/test/service.js'
import { test, assert } from './test.js'
import { Schema } from '@ucanto/validator'

const storeAdd = Server.capability({
can: 'store/add',
with: Server.URI.match({ protocol: 'did:' }),
nb: {
nb: Schema.struct({
link: Server.Link.match().optional(),
},
}),
derives: (claimed, delegated) => {
if (claimed.with !== delegated.with) {
return new Server.Failure(
Expand All @@ -34,9 +35,9 @@ const storeAdd = Server.capability({
const storeRemove = Server.capability({
can: 'store/remove',
with: Server.URI.match({ protocol: 'did:' }),
nb: {
nb: Schema.struct({
link: Server.Link.match().optional(),
},
}),
derives: (claimed, delegated) => {
if (claimed.with !== delegated.with) {
return new Server.Failure(
Expand Down
9 changes: 5 additions & 4 deletions packages/server/test/service/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { provide } from '../../src/handler.js'
import * as API from './api.js'
import * as Access from './access.js'
import { service as issuer } from '../fixtures.js'
import { Schema } from '@ucanto/validator/src/lib.js'

const addCapability = Server.capability({
can: 'store/add',
with: Server.URI.match({ protocol: 'did:' }),
nb: {
nb: Schema.struct({
link: Server.Link.match().optional(),
},
}),
derives: (claimed, delegated) => {
if (claimed.with !== delegated.with) {
return new Server.Failure(
Expand All @@ -34,9 +35,9 @@ const addCapability = Server.capability({
const removeCapability = Server.capability({
can: 'store/remove',
with: Server.URI.match({ protocol: 'did:' }),
nb: {
nb: Schema.struct({
link: Server.Link.match().optional(),
},
}),
derives: (claimed, delegated) => {
if (claimed.with !== delegated.with) {
return new Server.Failure(
Expand Down

0 comments on commit 0e1880a

Please sign in to comment.