@web3-storage/capabilities
Advanced tools
Comparing version 4.0.1 to 5.0.0
@@ -114,3 +114,3 @@ export { top } from "./top.js"; | ||
import { Schema } from "@ucanto/validator/src/lib.js"; | ||
import { Link } from "@ucanto/validator/src/schema.js"; | ||
import { Link } from "@ucanto/core/schema.js"; | ||
//# sourceMappingURL=access.d.ts.map |
@@ -10,4 +10,7 @@ /** @type {import('./types.js').AbilitiesArray} */ | ||
import * as Voucher from "./voucher.js"; | ||
import * as Consumer from "./consumer.js"; | ||
import * as Customer from "./customer.js"; | ||
import * as Console from "./console.js"; | ||
import * as Utils from "./utils.js"; | ||
export { Access, Provider, Space, Top, Store, Upload, Voucher, Utils }; | ||
export { Access, Provider, Space, Top, Store, Upload, Voucher, Consumer, Customer, Console, Utils }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,5 +0,5 @@ | ||
export const Provider: import("@ucanto/validator/src/schema.js").Schema<`did:web:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
export const Provider: import("@ucanto/core/schema.js").Schema<`did:web:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, any>; | ||
export const AccountDID: import("@ucanto/validator/src/schema.js").Schema<`did:mailto:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
export const AccountDID: import("@ucanto/core/schema.js").Schema<`did:mailto:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
@@ -12,7 +12,7 @@ }>, any>; | ||
protocol: "did:"; | ||
}>, import("@ucanto/validator/src/lib.js").InferStruct<{ | ||
provider: import("@ucanto/validator/src/schema.js").Schema<`did:web:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
}>, import("@ucanto/core/schema/type.js").InferStruct<{ | ||
provider: import("@ucanto/core/schema.js").Schema<`did:web:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, any>; | ||
consumer: import("@ucanto/validator/src/schema.js").Schema<`did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
consumer: import("@ucanto/core/schema.js").Schema<`did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
@@ -19,0 +19,0 @@ }>, any>; |
export { top } from "./top.js"; | ||
export { Store }; | ||
export const space: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"space/*", import("@ucanto/interface").URI<"did:">, any>>; | ||
export const SpaceDID: Store.Schema.Schema<`did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, any>; | ||
export const space: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"space/*", `did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, any>>; | ||
/** | ||
@@ -9,3 +14,5 @@ * `space/info` can be derived from any of the `store/*` | ||
*/ | ||
export const info: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").DerivedMatch<import("@ucanto/interface").ParsedCapability<"space/info", import("@ucanto/interface").URI<"did:">, {}>, import("@ucanto/interface").CapabilityMatch<"store/add", import("@ucanto/interface").URI<"did:">, Store.Schema.InferStruct<{ | ||
export const info: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").DerivedMatch<import("@ucanto/interface").ParsedCapability<"space/info", `did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, {}>, import("@ucanto/interface").CapabilityMatch<"store/add", import("@ucanto/interface").URI<"did:">, Store.Schema.InferStruct<{ | ||
link: typeof Store.Schema.Link; | ||
@@ -26,3 +33,3 @@ size: Store.Schema.NumberSchema<number & import("@ucanto/interface").Phantom<{ | ||
root: typeof Store.Schema.Link; | ||
shards: Store.Schema.Schema<import("@ucanto/interface").Link<unknown, 514, number, 1>[] | undefined, any>; | ||
shards: Store.Schema.Schema<import("@ucanto/interface").Link<unknown, import("@ucanto/interface").MulticodecCode<514, "CAR">, number, 1>[] | undefined, any>; | ||
}>> | import("@ucanto/interface").CapabilityMatch<"upload/remove", import("@ucanto/interface").URI<"did:">, Store.Schema.InferStruct<{ | ||
@@ -37,9 +44,20 @@ root: typeof Store.Schema.Link; | ||
}>>>>; | ||
export const recoverValidation: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"space/recover-validation", import("@ucanto/interface").URI<"did:">, Store.Schema.InferStruct<{ | ||
export const recoverValidation: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"space/recover-validation", `did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, Store.Schema.InferStruct<{ | ||
identity: Store.Schema.Schema<import("@ucanto/interface").URI<"mailto:">, unknown>; | ||
}>>>; | ||
export const recover: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"space/recover", import("@ucanto/interface").URI<"did:">, Store.Schema.InferStruct<{ | ||
export const recover: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"space/recover", `did:${string}:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, Store.Schema.InferStruct<{ | ||
identity: Store.Schema.Schema<import("@ucanto/interface").URI<"mailto:">, unknown>; | ||
}>>>; | ||
export const allocate: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"space/allocate", `did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, Store.Schema.InferStruct<{ | ||
size: Store.Schema.NumberSchema<number & import("@ucanto/interface").Phantom<{ | ||
typeof: "integer"; | ||
}>, unknown>; | ||
}>>>; | ||
import * as Store from "./store.js"; | ||
//# sourceMappingURL=space.d.ts.map |
@@ -55,4 +55,4 @@ /** | ||
import { Schema } from "@ucanto/validator/src/lib.js"; | ||
import { Link } from "@ucanto/validator/src/schema.js"; | ||
import { Link } from "@ucanto/core/schema.js"; | ||
export { Schema, Link }; | ||
//# sourceMappingURL=store.d.ts.map |
import type { TupleToUnion } from 'type-fest'; | ||
import * as Ucanto from '@ucanto/interface'; | ||
import { InferInvokedCapability } from '@ucanto/interface'; | ||
import { InferInvokedCapability, Unit } from '@ucanto/interface'; | ||
import { space, info, recover, recoverValidation } from './space.js'; | ||
@@ -11,4 +11,3 @@ import * as provider from './provider.js'; | ||
import * as AccessCaps from './access.js'; | ||
export interface Unit { | ||
} | ||
export type { Unit }; | ||
/** | ||
@@ -18,3 +17,2 @@ * failure due to a resource not having enough storage capacity. | ||
export interface InsufficientStorage { | ||
error: true; | ||
name: 'InsufficientStorage'; | ||
@@ -31,3 +29,4 @@ message: string; | ||
export interface AccessClaimFailure { | ||
error: true; | ||
name: 'AccessClaimFailure'; | ||
message: string; | ||
} | ||
@@ -40,6 +39,7 @@ export interface AccessConfirmSuccess { | ||
export type AccessDelegate = InferInvokedCapability<typeof AccessCaps.delegate>; | ||
export type AccessDelegateSuccess = unknown; | ||
export type AccessDelegateFailure = { | ||
error: true; | ||
} | InsufficientStorage; | ||
export type AccessDelegateSuccess = Unit; | ||
export type AccessDelegateFailure = InsufficientStorage | DelegationNotFound; | ||
export interface DelegationNotFound extends Ucanto.Failure { | ||
name: 'DelegationNotFound'; | ||
} | ||
export type AccessSession = InferInvokedCapability<typeof AccessCaps.session>; | ||
@@ -46,0 +46,0 @@ export type AccessConfirm = InferInvokedCapability<typeof AccessCaps.confirm>; |
@@ -28,3 +28,3 @@ /** | ||
root: typeof Link; | ||
shards: Schema.Schema<import("@ucanto/interface").Link<unknown, 514, number, 1>[] | undefined, any>; | ||
shards: Schema.Schema<import("@ucanto/interface").Link<unknown, import("@ucanto/interface").MulticodecCode<514, "CAR">, number, 1>[] | undefined, any>; | ||
}>>>; | ||
@@ -52,3 +52,3 @@ /** | ||
root: typeof Link; | ||
shards: Schema.Schema<import("@ucanto/interface").Link<unknown, 514, number, 1>[] | undefined, any>; | ||
shards: Schema.Schema<import("@ucanto/interface").Link<unknown, import("@ucanto/interface").MulticodecCode<514, "CAR">, number, 1>[] | undefined, any>; | ||
}>> | import("@ucanto/interface").CapabilityMatch<"upload/remove", import("@ucanto/interface").URI<"did:">, Schema.InferStruct<{ | ||
@@ -64,4 +64,4 @@ root: typeof Link; | ||
import { Schema } from "@ucanto/validator/src/lib.js"; | ||
import { Link } from "@ucanto/validator/src/schema.js"; | ||
import { Link } from "@ucanto/core/schema.js"; | ||
export { Link, Schema }; | ||
//# sourceMappingURL=upload.d.ts.map |
@@ -7,3 +7,9 @@ /** | ||
*/ | ||
export function canDelegateURI(child?: string | undefined, parent?: string | undefined): true | Failure; | ||
export function canDelegateURI(child?: string | undefined, parent?: string | undefined): { | ||
ok: {}; | ||
value?: undefined; | ||
} | { | ||
error: Types.Failure; | ||
ok?: undefined; | ||
}; | ||
/** | ||
@@ -16,3 +22,9 @@ * Checks that `with` on claimed capability is the same as `with` | ||
*/ | ||
export function equalWith(child: Types.ParsedCapability, parent: Types.ParsedCapability): true | Failure; | ||
export function equalWith(child: Types.ParsedCapability, parent: Types.ParsedCapability): { | ||
error: Types.Failure; | ||
ok?: undefined; | ||
} | { | ||
ok: {}; | ||
value?: undefined; | ||
}; | ||
/** | ||
@@ -23,8 +35,10 @@ * @param {unknown} child | ||
*/ | ||
export function equal(child: unknown, parent: unknown, constraint: string): true | Failure; | ||
export function equal(child: unknown, parent: unknown, constraint: string): { | ||
error: Types.Failure; | ||
ok?: undefined; | ||
} | { | ||
ok: {}; | ||
value?: undefined; | ||
}; | ||
/** | ||
* @param {Types.Failure | true} value | ||
*/ | ||
export function fail(value: Types.Failure | true): Types.Failure | undefined; | ||
/** | ||
* | ||
@@ -39,5 +53,9 @@ * TODO: needs to account for caps derived from different namespaces like 'account/info' can be derived from 'store/add' | ||
link?: Types.Link<unknown, number, number, 0 | 1> | undefined; | ||
}>>(claimed: T, delegated: T): Types.Result<true, Types.Failure>; | ||
import { Failure } from "@ucanto/validator/src/lib"; | ||
}>>(claimed: T, delegated: T): Types.Result<{}, Types.Failure>; | ||
export function and<T>(result: Types.Result<T, Types.Failure>): { | ||
error: Types.Failure; | ||
ok?: undefined; | ||
} | undefined; | ||
import * as Types from "@ucanto/interface"; | ||
import { ok } from "@ucanto/validator/src/lib"; | ||
//# sourceMappingURL=utils.d.ts.map |
export { top } from "./top.js"; | ||
export const SpaceDID: Schema.Schema<`did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, any>; | ||
/** | ||
@@ -3,0 +6,0 @@ * Products are identified by the CID of the DAG that describes them. |
{ | ||
"name": "@web3-storage/capabilities", | ||
"version": "4.0.1", | ||
"version": "5.0.0", | ||
"description": "Capabilities provided by web3.storage", | ||
@@ -57,7 +57,7 @@ "homepage": "https://github.com/web3-storage/w3protocol/tree/main/packages/capabilities", | ||
"dependencies": { | ||
"@ucanto/core": "^5.2.0", | ||
"@ucanto/interface": "^6.2.0", | ||
"@ucanto/principal": "^5.1.0", | ||
"@ucanto/transport": "^5.1.1", | ||
"@ucanto/validator": "^6.1.0" | ||
"@ucanto/core": "^7.0.1", | ||
"@ucanto/interface": "^7.0.1", | ||
"@ucanto/principal": "^7.0.0", | ||
"@ucanto/transport": "^7.0.3", | ||
"@ucanto/validator": "^7.0.0" | ||
}, | ||
@@ -64,0 +64,0 @@ "devDependencies": { |
@@ -11,5 +11,5 @@ /** | ||
*/ | ||
import { capability, URI, DID, Link, Schema, Failure } from '@ucanto/validator' | ||
import { capability, URI, DID, Link, Schema, fail, ok } from '@ucanto/validator' | ||
import * as Types from '@ucanto/interface' | ||
import { equalWith, fail, equal } from './utils.js' | ||
import { equalWith, equal, and } from './utils.js' | ||
export { top } from './top.js' | ||
@@ -69,6 +69,6 @@ | ||
return ( | ||
fail(equalWith(child, parent)) || | ||
fail(equal(child.nb.iss, parent.nb.iss, 'iss')) || | ||
fail(subsetCapabilities(child.nb.att, parent.nb.att)) || | ||
true | ||
and(equalWith(child, parent)) || | ||
and(equal(child.nb.iss, parent.nb.iss, 'iss')) || | ||
and(subsetCapabilities(child.nb.att, parent.nb.att)) || | ||
ok({}) | ||
) | ||
@@ -94,7 +94,7 @@ }, | ||
return ( | ||
fail(equalWith(claim, proof)) || | ||
fail(equal(claim.nb.iss, proof.nb.iss, 'iss')) || | ||
fail(equal(claim.nb.aud, proof.nb.aud, 'aud')) || | ||
fail(subsetCapabilities(claim.nb.att, proof.nb.att)) || | ||
true | ||
and(equalWith(claim, proof)) || | ||
and(equal(claim.nb.iss, proof.nb.iss, 'iss')) || | ||
and(equal(claim.nb.aud, proof.nb.aud, 'aud')) || | ||
and(subsetCapabilities(claim.nb.att, proof.nb.att)) || | ||
ok({}) | ||
) | ||
@@ -164,5 +164,5 @@ }, | ||
return ( | ||
fail(equalWith(claim, proof)) || | ||
fail(subsetsNbDelegations(claim, proof)) || | ||
true | ||
and(equalWith(claim, proof)) || | ||
and(subsetsNbDelegations(claim, proof)) || | ||
ok({}) | ||
) | ||
@@ -200,7 +200,5 @@ }, | ||
if (missingProofs.size > 0) { | ||
return new Failure( | ||
`unauthorized nb.delegations ${[...missingProofs].join(', ')}` | ||
) | ||
return fail(`unauthorized nb.delegations ${[...missingProofs].join(', ')}`) | ||
} | ||
return true | ||
return ok({}) | ||
} | ||
@@ -224,3 +222,3 @@ | ||
if (allowed.has('*')) { | ||
return true | ||
return ok({}) | ||
} | ||
@@ -235,6 +233,6 @@ | ||
if (escalated.size > 0) { | ||
return new Failure(`unauthorized nb.att.can ${[...escalated].join(', ')}`) | ||
return fail(`unauthorized nb.att.can ${[...escalated].join(', ')}`) | ||
} | ||
return true | ||
return ok({}) | ||
} | ||
@@ -241,0 +239,0 @@ |
@@ -9,4 +9,19 @@ import * as Provider from './provider.js' | ||
import * as Utils from './utils.js' | ||
import * as Consumer from './consumer.js' | ||
import * as Customer from './customer.js' | ||
import * as Console from './console.js' | ||
export { Access, Provider, Space, Top, Store, Upload, Voucher, Utils } | ||
export { | ||
Access, | ||
Provider, | ||
Space, | ||
Top, | ||
Store, | ||
Upload, | ||
Voucher, | ||
Consumer, | ||
Customer, | ||
Console, | ||
Utils, | ||
} | ||
@@ -13,0 +28,0 @@ /** @type {import('./types.js').AbilitiesArray} */ |
@@ -11,4 +11,4 @@ /** | ||
*/ | ||
import { capability, DID, struct } from '@ucanto/validator' | ||
import { equalWith, fail, equal } from './utils.js' | ||
import { capability, DID, struct, ok } from '@ucanto/validator' | ||
import { equalWith, and, equal } from './utils.js' | ||
@@ -32,8 +32,8 @@ // e.g. did:web:web3.storage or did:web:staging.web3.storage | ||
return ( | ||
fail(equalWith(child, parent)) || | ||
fail(equal(child.nb.provider, parent.nb.provider, 'provider')) || | ||
fail(equal(child.nb.consumer, parent.nb.consumer, 'consumer')) || | ||
true | ||
and(equalWith(child, parent)) || | ||
and(equal(child.nb.provider, parent.nb.provider, 'provider')) || | ||
and(equal(child.nb.consumer, parent.nb.consumer, 'consumer')) || | ||
ok({}) | ||
) | ||
}, | ||
}) |
@@ -13,4 +13,4 @@ /** | ||
import * as Store from './store.js' | ||
import { capability, URI, Schema } from '@ucanto/validator' | ||
import { canDelegateURI, equalWith, fail } from './utils.js' | ||
import { capability, URI, Schema, ok, fail } from '@ucanto/validator' | ||
import { canDelegateURI, equalWith, and } from './utils.js' | ||
import * as Upload from './upload.js' | ||
@@ -23,5 +23,6 @@ export { top } from './top.js' | ||
export const SpaceDID = Schema.did({ method: 'key' }) | ||
export const space = capability({ | ||
can: 'space/*', | ||
with: URI.match({ protocol: 'did:' }), | ||
with: SpaceDID, | ||
derives: equalWith, | ||
@@ -44,3 +45,3 @@ }) | ||
can: 'space/info', | ||
with: URI.match({ protocol: 'did:' }), | ||
with: SpaceDID, | ||
}), | ||
@@ -52,3 +53,3 @@ derives: equalWith, | ||
can: 'space/recover-validation', | ||
with: URI.match({ protocol: 'did:' }), | ||
with: SpaceDID, | ||
nb: Schema.struct({ | ||
@@ -61,3 +62,3 @@ identity: URI.match({ protocol: 'mailto:' }), | ||
can: 'space/recover', | ||
with: URI.match({ protocol: 'did:' }), | ||
with: Schema.did(), | ||
nb: Schema.struct({ | ||
@@ -68,7 +69,27 @@ identity: URI.match({ protocol: 'mailto:' }), | ||
return ( | ||
fail(equalWith(child, parent)) || | ||
fail(canDelegateURI(child.nb.identity, parent.nb.identity)) || | ||
true | ||
and(equalWith(child, parent)) || | ||
and(canDelegateURI(child.nb.identity, parent.nb.identity)) || | ||
ok({}) | ||
) | ||
}, | ||
}) | ||
export const allocate = capability({ | ||
can: 'space/allocate', | ||
with: SpaceDID, | ||
nb: Schema.struct({ | ||
size: Schema.integer(), | ||
}), | ||
derives: (child, parent) => { | ||
const result = equalWith(child, parent) | ||
if (result.ok) { | ||
return child.nb.size <= parent.nb.size | ||
? ok({}) | ||
: fail( | ||
`Claimed size ${child.nb.size} escalates delegated size ${parent.nb.size}` | ||
) | ||
} else { | ||
return result | ||
} | ||
}, | ||
}) |
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
import { capability, Failure, Link, URI, Schema } from '@ucanto/validator' | ||
import { capability, Link, URI, Schema, ok, fail } from '@ucanto/validator' | ||
import { equalLink, equalWith } from './utils.js' | ||
@@ -73,8 +73,6 @@ | ||
return claim.nb.size > from.nb.size | ||
? new Failure( | ||
`Size constraint violation: ${claim.nb.size} > ${from.nb.size}` | ||
) | ||
: true | ||
? fail(`Size constraint violation: ${claim.nb.size} > ${from.nb.size}`) | ||
: ok({}) | ||
} else { | ||
return true | ||
return ok({}) | ||
} | ||
@@ -132,7 +130,7 @@ }, | ||
if (claimed.with !== delegated.with) { | ||
return new Failure( | ||
return fail( | ||
`Expected 'with: "${delegated.with}"' instead got '${claimed.with}'` | ||
) | ||
} | ||
return true | ||
return ok({}) | ||
}, | ||
@@ -139,0 +137,0 @@ }) |
import type { TupleToUnion } from 'type-fest' | ||
import * as Ucanto from '@ucanto/interface' | ||
import { InferInvokedCapability } from '@ucanto/interface' | ||
import { InferInvokedCapability, Unit } from '@ucanto/interface' | ||
import { space, info, recover, recoverValidation } from './space.js' | ||
@@ -12,4 +12,3 @@ import * as provider from './provider.js' | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface Unit {} | ||
export type { Unit } | ||
/** | ||
@@ -19,3 +18,2 @@ * failure due to a resource not having enough storage capacity. | ||
export interface InsufficientStorage { | ||
error: true | ||
name: 'InsufficientStorage' | ||
@@ -38,3 +36,4 @@ message: string | ||
export interface AccessClaimFailure { | ||
error: true | ||
name: 'AccessClaimFailure' | ||
message: string | ||
} | ||
@@ -48,5 +47,9 @@ | ||
export type AccessDelegate = InferInvokedCapability<typeof AccessCaps.delegate> | ||
export type AccessDelegateSuccess = unknown | ||
export type AccessDelegateFailure = { error: true } | InsufficientStorage | ||
export type AccessDelegateSuccess = Unit | ||
export type AccessDelegateFailure = InsufficientStorage | DelegationNotFound | ||
export interface DelegationNotFound extends Ucanto.Failure { | ||
name: 'DelegationNotFound' | ||
} | ||
export type AccessSession = InferInvokedCapability<typeof AccessCaps.session> | ||
@@ -53,0 +56,0 @@ export type AccessConfirm = InferInvokedCapability<typeof AccessCaps.confirm> |
@@ -11,5 +11,5 @@ /** | ||
*/ | ||
import { capability, Link, URI, Schema } from '@ucanto/validator' | ||
import { capability, Link, URI, Schema, ok } from '@ucanto/validator' | ||
import { codec as CAR } from '@ucanto/transport/car' | ||
import { equalWith, fail, equal } from './utils.js' | ||
import { equalWith, and, equal } from './utils.js' | ||
@@ -73,6 +73,6 @@ /** | ||
return ( | ||
fail(equalWith(self, from)) || | ||
fail(equal(self.nb.root, from.nb.root, 'root')) || | ||
fail(equal(self.nb.shards, from.nb.shards, 'shards')) || | ||
true | ||
and(equalWith(self, from)) || | ||
and(equal(self.nb.root, from.nb.root, 'root')) || | ||
and(equal(self.nb.shards, from.nb.shards, 'shards')) || | ||
ok({}) | ||
) | ||
@@ -101,5 +101,5 @@ }, | ||
return ( | ||
fail(equalWith(self, from)) || | ||
fail(equal(self.nb.root, from.nb.root, 'root')) || | ||
true | ||
and(equalWith(self, from)) || | ||
and(equal(self.nb.root, from.nb.root, 'root')) || | ||
ok({}) | ||
) | ||
@@ -106,0 +106,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import { Failure } from '@ucanto/validator' | ||
import { fail, ok } from '@ucanto/validator' | ||
// eslint-disable-next-line no-unused-vars | ||
@@ -13,13 +13,13 @@ import * as Types from '@ucanto/interface' | ||
if (parent === undefined) { | ||
return true | ||
return ok({}) | ||
} | ||
if (child !== undefined && parent.endsWith('*')) { | ||
return child.startsWith(parent.slice(0, -1)) | ||
? true | ||
: new Failure(`${child} does not match ${parent}`) | ||
? ok({}) | ||
: fail(`${child} does not match ${parent}`) | ||
} | ||
return child === parent | ||
? true | ||
: new Failure(`${child} is different from ${parent}`) | ||
? ok({}) | ||
: fail(`${child} is different from ${parent}`) | ||
} | ||
@@ -35,8 +35,5 @@ | ||
export function equalWith(child, parent) { | ||
return ( | ||
child.with === parent.with || | ||
new Failure( | ||
`Can not derive ${child.can} with ${child.with} from ${parent.with}` | ||
) | ||
) | ||
return child.with === parent.with | ||
? ok({}) | ||
: fail(`Can not derive ${child.can} with ${child.with} from ${parent.with}`) | ||
} | ||
@@ -52,7 +49,7 @@ | ||
if (parent === undefined || parent === '*') { | ||
return true | ||
return ok({}) | ||
} else if (String(child) === String(parent)) { | ||
return true | ||
return ok({}) | ||
} else { | ||
return new Failure( | ||
return fail( | ||
`Constrain violation: ${child} violates imposed ${constraint} constraint ${parent}` | ||
@@ -67,7 +64,7 @@ ) | ||
* @param {T} delegated | ||
* @returns {Types.Result<true, Types.Failure>} | ||
* @returns {Types.Result<{}, Types.Failure>} | ||
*/ | ||
export const equalLink = (claimed, delegated) => { | ||
if (claimed.with !== delegated.with) { | ||
return new Failure( | ||
return fail( | ||
`Expected 'with: "${delegated.with}"' instead got '${claimed.with}'` | ||
@@ -79,3 +76,3 @@ ) | ||
) { | ||
return new Failure( | ||
return fail( | ||
`Link ${claimed.nb.link ? `${claimed.nb.link}` : ''} violates imposed ${ | ||
@@ -86,3 +83,3 @@ delegated.nb.link | ||
} else { | ||
return true | ||
return ok({}) | ||
} | ||
@@ -92,7 +89,7 @@ } | ||
/** | ||
* @param {Types.Failure | true} value | ||
* @template T | ||
* @param {Types.Result<T , Types.Failure>} result | ||
* @returns {{error: Types.Failure, ok?:undefined}|undefined} | ||
*/ | ||
export function fail(value) { | ||
return value === true ? undefined : value | ||
} | ||
export const and = (result) => (result.error ? result : undefined) | ||
@@ -99,0 +96,0 @@ /** |
@@ -11,6 +11,8 @@ /** | ||
*/ | ||
import { capability, URI, DID, Schema } from '@ucanto/validator' | ||
import { equalWith, fail, equal } from './utils.js' | ||
import { capability, URI, DID, Schema, ok } from '@ucanto/validator' | ||
import { equalWith, and, equal } from './utils.js' | ||
export { top } from './top.js' | ||
export const SpaceDID = DID.match({ method: 'key' }) | ||
/** | ||
@@ -74,7 +76,7 @@ * Products are identified by the CID of the DAG that describes them. | ||
return ( | ||
fail(equalWith(child, parent)) || | ||
fail(equal(child.nb.product, parent.nb.product, 'product')) || | ||
fail(equal(child.nb.identity, parent.nb.identity, 'identity')) || | ||
fail(equal(child.nb.service, parent.nb.service, 'service')) || | ||
true | ||
and(equalWith(child, parent)) || | ||
and(equal(child.nb.product, parent.nb.product, 'product')) || | ||
and(equal(child.nb.identity, parent.nb.identity, 'identity')) || | ||
and(equal(child.nb.service, parent.nb.service, 'service')) || | ||
ok({}) | ||
) | ||
@@ -107,9 +109,9 @@ }, | ||
return ( | ||
fail(equalWith(child, parent)) || | ||
fail(equal(child.nb.product, parent.nb.product, 'product')) || | ||
fail(equal(child.nb.identity, parent.nb.identity, 'identity')) || | ||
fail(equal(child.nb.space, parent.nb.space, 'account')) || | ||
true | ||
and(equalWith(child, parent)) || | ||
and(equal(child.nb.product, parent.nb.product, 'product')) || | ||
and(equal(child.nb.identity, parent.nb.identity, 'identity')) || | ||
and(equal(child.nb.space, parent.nb.space, 'account')) || | ||
ok({}) | ||
) | ||
}, | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
77166
41
1660
+ Added@ucanto/core@7.1.1(transitive)
+ Added@ucanto/interface@7.1.0(transitive)
+ Added@ucanto/principal@7.0.0(transitive)
+ Added@ucanto/transport@7.0.3(transitive)
+ Added@ucanto/validator@7.0.0(transitive)
- Removed@ucanto/core@5.2.0(transitive)
- Removed@ucanto/interface@6.2.0(transitive)
- Removed@ucanto/principal@5.1.0(transitive)
- Removed@ucanto/transport@5.1.1(transitive)
- Removed@ucanto/validator@6.1.0(transitive)
Updated@ucanto/core@^7.0.1
Updated@ucanto/interface@^7.0.1
Updated@ucanto/principal@^7.0.0
Updated@ucanto/transport@^7.0.3
Updated@ucanto/validator@^7.0.0