@ucanto/interface
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -51,6 +51,25 @@ import { Ability, Capability, DID, Link, Resource } from '@ipld/dag-ucan'; | ||
to: TheCapabilityParser<DirectMatch<T>>; | ||
derives: Derives<T, M['value']>; | ||
derives: Derives<ToDeriveClaim<T>, ToDeriveProof<M['value']>>; | ||
} | ||
export interface Derives<T, U = T> { | ||
(self: T, from: U): Result<true, Failure>; | ||
/** | ||
* Utility type is used to infer the type of the capability passed into | ||
* `derives` handler. It simply makes all `nb` fileds optional because | ||
* in delegation all `nb` fields could be left out implying no restrictions. | ||
*/ | ||
export declare type ToDeriveClaim<T extends ParsedCapability> = T | ParsedCapability<T['can'], T['with'], Partial<T['nb']>>; | ||
/** | ||
* Utility type is used to infer type of the second argument of `derives` | ||
* handler (in the `cap.derive({ to, derives: (claim, proof) => true })`) | ||
* which could be either capability or set of capabilities. It simply makes | ||
* all `nb` fields optional, because in delegation all `nb` fields could be | ||
* left out implying no restrictions. | ||
*/ | ||
export declare type ToDeriveProof<T> = T extends ParsedCapability ? ToDeriveClaim<T> : ToDeriveProofs<T>; | ||
/** | ||
* Another helper type which is equivalent of `ToDeriveClaim` except it works | ||
* on tuple of capabilities. | ||
*/ | ||
declare type ToDeriveProofs<T> = T extends [infer U, ...infer E] ? [ToDeriveClaim<U & ParsedCapability>, ...ToDeriveProofs<E>] : T extends never[] ? [] : never; | ||
export interface Derives<T extends ParsedCapability, U = T> { | ||
(claim: T, proof: U): Result<true, Failure>; | ||
} | ||
@@ -110,3 +129,3 @@ export interface View<M extends Match> extends Matcher<M>, Selector<M> { | ||
*/ | ||
delegate(options: InferDelegationOptions<M['value']['with'], M['value']['nb']>): Promise<Delegation<[M['value']]>>; | ||
delegate(options: InferDelegationOptions<M['value']['with'], M['value']['nb']>): Promise<Delegation<[ToDeriveClaim<M['value']>]>>; | ||
} | ||
@@ -224,3 +243,3 @@ export declare type InferCreateOptions<R extends Resource, C extends {} | undefined> = keyof C extends never ? { | ||
nb?: C; | ||
derives?: Derives<ParsedCapability<A, R, InferCaveats<C>>, ParsedCapability<A, R, InferCaveats<C>>>; | ||
derives?: Derives<ToDeriveClaim<ParsedCapability<A, R, InferCaveats<C>>>, ToDeriveClaim<ParsedCapability<A, R, InferCaveats<C>>>>; | ||
} | ||
@@ -227,0 +246,0 @@ export interface CapabilityMatch<A extends Ability, R extends URI, C extends Caveats> extends DirectMatch<ParsedCapability<A, R, InferCaveats<C>>> { |
{ | ||
"name": "@ucanto/interface", | ||
"description": "interface definitions for ucanto", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"types": "./dist/src/lib.d.ts", | ||
@@ -23,3 +23,3 @@ "main": "./src/lib.js", | ||
"@ipld/dag-ucan": "^2.0.0", | ||
"multiformats": "^10.0.0" | ||
"multiformats": "^10.0.2" | ||
}, | ||
@@ -26,0 +26,0 @@ "devDependencies": { |
@@ -81,7 +81,39 @@ import { Ability, Capability, DID, Link, Resource } from '@ipld/dag-ucan' | ||
to: TheCapabilityParser<DirectMatch<T>> | ||
derives: Derives<T, M['value']> | ||
derives: Derives<ToDeriveClaim<T>, ToDeriveProof<M['value']>> | ||
} | ||
export interface Derives<T, U = T> { | ||
(self: T, from: U): Result<true, Failure> | ||
/** | ||
* Utility type is used to infer the type of the capability passed into | ||
* `derives` handler. It simply makes all `nb` fileds optional because | ||
* in delegation all `nb` fields could be left out implying no restrictions. | ||
*/ | ||
export type ToDeriveClaim<T extends ParsedCapability> = | ||
| T | ||
| ParsedCapability<T['can'], T['with'], Partial<T['nb']>> | ||
/** | ||
* Utility type is used to infer type of the second argument of `derives` | ||
* handler (in the `cap.derive({ to, derives: (claim, proof) => true })`) | ||
* which could be either capability or set of capabilities. It simply makes | ||
* all `nb` fields optional, because in delegation all `nb` fields could be | ||
* left out implying no restrictions. | ||
*/ | ||
export type ToDeriveProof<T> = T extends ParsedCapability | ||
? // If it a capability we just make `nb` partial | ||
ToDeriveClaim<T> | ||
: // otherwise we need to map tuple | ||
ToDeriveProofs<T> | ||
/** | ||
* Another helper type which is equivalent of `ToDeriveClaim` except it works | ||
* on tuple of capabilities. | ||
*/ | ||
type ToDeriveProofs<T> = T extends [infer U, ...infer E] | ||
? [ToDeriveClaim<U & ParsedCapability>, ...ToDeriveProofs<E>] | ||
: T extends never[] | ||
? [] | ||
: never | ||
export interface Derives<T extends ParsedCapability, U = T> { | ||
(claim: T, proof: U): Result<true, Failure> | ||
} | ||
@@ -157,3 +189,3 @@ | ||
options: InferDelegationOptions<M['value']['with'], M['value']['nb']> | ||
): Promise<Delegation<[M['value']]>> | ||
): Promise<Delegation<[ToDeriveClaim<M['value']>]>> | ||
} | ||
@@ -304,4 +336,4 @@ | ||
derives?: Derives< | ||
ParsedCapability<A, R, InferCaveats<C>>, | ||
ParsedCapability<A, R, InferCaveats<C>> | ||
ToDeriveClaim<ParsedCapability<A, R, InferCaveats<C>>>, | ||
ToDeriveClaim<ParsedCapability<A, R, InferCaveats<C>>> | ||
> | ||
@@ -308,0 +340,0 @@ } |
Sorry, the diff of this file is not supported yet
87858
1666
Updatedmultiformats@^10.0.2