@web3-storage/capabilities
Advanced tools
Comparing version 13.3.1 to 14.0.0
@@ -10,7 +10,3 @@ /** | ||
export const blob: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"blob/*", `did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; /** | ||
* Capability can only be delegated (but not invoked) allowing audience to | ||
* derived any `blob/` prefixed capability for the (memory) space identified | ||
* by DID in the `with` field. | ||
*/ | ||
protocol: "did:"; | ||
}>, any>>; | ||
@@ -33,7 +29,3 @@ /** | ||
export const add: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"blob/add", `did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; /** | ||
* Capability can only be delegated (but not invoked) allowing audience to | ||
* derived any `blob/` prefixed capability for the (memory) space identified | ||
* by DID in the `with` field. | ||
*/ | ||
protocol: "did:"; | ||
}>, Schema.InferStruct<{ | ||
@@ -47,4 +39,25 @@ blob: Schema.StructSchema<{ | ||
}>>>; | ||
/** | ||
* Capability can be used to remove the stored Blob from the (memory) | ||
* space identified by `with` field. | ||
*/ | ||
export const remove: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"blob/remove", `did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, Schema.InferStruct<{ | ||
digest: Schema.Schema<Uint8Array, unknown>; | ||
}>>>; | ||
/** | ||
* Capability can be invoked to request a list of stored Blobs in the | ||
* (memory) space identified by `with` field. | ||
*/ | ||
export const list: import("@ucanto/interface").TheCapabilityParser<import("@ucanto/interface").CapabilityMatch<"blob/list", `did:key:${string}` & `did:${string}` & import("@ucanto/interface").Phantom<{ | ||
protocol: "did:"; | ||
}>, Schema.InferStruct<{ | ||
cursor: Schema.Schema<string | undefined, unknown>; | ||
size: Schema.Schema<(number & import("@ucanto/interface").Phantom<{ | ||
typeof: "integer"; | ||
}>) | undefined, unknown>; | ||
}>>>; | ||
export { Schema }; | ||
import { Schema } from '@ucanto/validator'; | ||
//# sourceMappingURL=blob.d.ts.map |
@@ -347,2 +347,4 @@ import type { TupleToUnion } from 'type-fest'; | ||
export type BlobAdd = InferInvokedCapability<typeof BlobCaps.add>; | ||
export type BlobRemove = InferInvokedCapability<typeof BlobCaps.remove>; | ||
export type BlobList = InferInvokedCapability<typeof BlobCaps.list>; | ||
export type ServiceBlob = InferInvokedCapability<typeof W3sBlobCaps.blob>; | ||
@@ -370,2 +372,9 @@ export type BlobAllocate = InferInvokedCapability<typeof W3sBlobCaps.allocate>; | ||
} | ||
export interface BlobRemoveSuccess { | ||
size: number; | ||
} | ||
export type BlobRemoveFailure = Ucanto.Failure; | ||
export interface BlobListSuccess extends ListResponse<BlobListItem> { | ||
} | ||
export type BlobListFailure = Ucanto.Failure; | ||
export interface BlobAllocateSuccess { | ||
@@ -608,2 +617,4 @@ size: number; | ||
BlobAdd['can'], | ||
BlobRemove['can'], | ||
BlobList['can'], | ||
ServiceBlob['can'], | ||
@@ -610,0 +621,0 @@ BlobAllocate['can'], |
{ | ||
"name": "@web3-storage/capabilities", | ||
"version": "13.3.1", | ||
"version": "14.0.0", | ||
"description": "UCAN Capabilities provided by web3.storage", | ||
@@ -5,0 +5,0 @@ "homepage": "https://web3.storage", |
@@ -14,3 +14,4 @@ /** | ||
*/ | ||
import { capability, Schema } from '@ucanto/validator' | ||
import { equals } from 'uint8arrays/equals' | ||
import { capability, Schema, fail, ok } from '@ucanto/validator' | ||
import { equalBlob, equalWith, SpaceDID } from './utils.js' | ||
@@ -74,4 +75,70 @@ | ||
/** | ||
* Capability can be used to remove the stored Blob from the (memory) | ||
* space identified by `with` field. | ||
*/ | ||
export const remove = capability({ | ||
can: 'blob/remove', | ||
/** | ||
* DID of the (memory) space where Blob is stored. | ||
*/ | ||
with: SpaceDID, | ||
nb: Schema.struct({ | ||
/** | ||
* A multihash digest of the blob payload bytes, uniquely identifying blob. | ||
*/ | ||
digest: Schema.bytes(), | ||
}), | ||
derives: (claimed, delegated) => { | ||
if (claimed.with !== delegated.with) { | ||
return fail( | ||
`Expected 'with: "${delegated.with}"' instead got '${claimed.with}'` | ||
) | ||
} else if ( | ||
delegated.nb.digest && | ||
!equals(delegated.nb.digest, claimed.nb.digest) | ||
) { | ||
return fail( | ||
`Link ${ | ||
claimed.nb.digest ? `${claimed.nb.digest}` : '' | ||
} violates imposed ${delegated.nb.digest} constraint.` | ||
) | ||
} | ||
return ok({}) | ||
}, | ||
}) | ||
/** | ||
* Capability can be invoked to request a list of stored Blobs in the | ||
* (memory) space identified by `with` field. | ||
*/ | ||
export const list = capability({ | ||
can: 'blob/list', | ||
/** | ||
* DID of the (memory) space where Blobs to be listed are stored. | ||
*/ | ||
with: SpaceDID, | ||
nb: Schema.struct({ | ||
/** | ||
* A pointer that can be moved back and forth on the list. | ||
* It can be used to paginate a list for instance. | ||
*/ | ||
cursor: Schema.string().optional(), | ||
/** | ||
* Maximum number of items per page. | ||
*/ | ||
size: Schema.integer().optional(), | ||
}), | ||
derives: (claimed, delegated) => { | ||
if (claimed.with !== delegated.with) { | ||
return fail( | ||
`Expected 'with: "${delegated.with}"' instead got '${claimed.with}'` | ||
) | ||
} | ||
return ok({}) | ||
}, | ||
}) | ||
// ⚠️ We export imports here so they are not omitted in generated typedefs | ||
// @see https://github.com/microsoft/TypeScript/issues/51548 | ||
export { Schema } |
@@ -98,2 +98,4 @@ import * as Provider from './provider.js' | ||
Blob.add.can, | ||
Blob.remove.can, | ||
Blob.list.can, | ||
W3sBlob.blob.can, | ||
@@ -100,0 +102,0 @@ W3sBlob.allocate.can, |
@@ -455,2 +455,4 @@ import type { TupleToUnion } from 'type-fest' | ||
export type BlobAdd = InferInvokedCapability<typeof BlobCaps.add> | ||
export type BlobRemove = InferInvokedCapability<typeof BlobCaps.remove> | ||
export type BlobList = InferInvokedCapability<typeof BlobCaps.list> | ||
export type ServiceBlob = InferInvokedCapability<typeof W3sBlobCaps.blob> | ||
@@ -491,2 +493,16 @@ export type BlobAllocate = InferInvokedCapability<typeof W3sBlobCaps.allocate> | ||
// Blob remove | ||
export interface BlobRemoveSuccess { | ||
size: number | ||
} | ||
// TODO: make types more specific | ||
export type BlobRemoveFailure = Ucanto.Failure | ||
// Blob list | ||
export interface BlobListSuccess extends ListResponse<BlobListItem> {} | ||
// TODO: make types more specific | ||
export type BlobListFailure = Ucanto.Failure | ||
// Blob allocate | ||
@@ -825,2 +841,4 @@ export interface BlobAllocateSuccess { | ||
BlobAdd['can'], | ||
BlobRemove['can'], | ||
BlobList['can'], | ||
ServiceBlob['can'], | ||
@@ -827,0 +845,0 @@ BlobAllocate['can'], |
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
184429
4356