@@ -21,6 +21,9 @@ import {
21
21
import { space , info } from './space.js'
22
22
import * as provider from './provider.js'
23
23
import { top } from './top.js'
24
+ import * as BlobCaps from './blob.js'
25
+ import * as W3sBlobCaps from './web3.storage/blob.js'
26
+ import * as HTTPCaps from './http.js'
24
27
import * as StoreCaps from './store.js'
25
28
import * as UploadCaps from './upload.js'
26
29
import * as AccessCaps from './access.js'
@@ -41,6 +44,10 @@ export type ISO8601Date = string
41
44
42
45
export type { Unit , PieceLink }
43
46
47
+ export interface UCANAwait < Selector extends string = string , Task = unknown > {
48
+ 'ucan/await' : [ Selector , Link < Task > ]
49
+ }
50
+
44
51
/**
45
52
* An IPLD Link that has the CAR codec code.
46
53
*/
@@ -439,6 +446,95 @@ export interface UploadNotFound extends Ucanto.Failure {
439
446
440
447
export type UploadGetFailure = UploadNotFound | Ucanto . Failure
441
448
449
+ // HTTP
450
+ export type HTTPPut = InferInvokedCapability < typeof HTTPCaps . put >
451
+
452
+ // Blob
453
+ export type Blob = InferInvokedCapability < typeof BlobCaps . blob >
454
+ export type BlobAdd = InferInvokedCapability < typeof BlobCaps . add >
455
+ export type ServiceBlob = InferInvokedCapability < typeof W3sBlobCaps . blob >
456
+ export type BlobAllocate = InferInvokedCapability < typeof W3sBlobCaps . allocate >
457
+ export type BlobAccept = InferInvokedCapability < typeof W3sBlobCaps . accept >
458
+
459
+ export type BlobMultihash = Uint8Array
460
+ export interface BlobModel {
461
+ digest : BlobMultihash
462
+ size : number
463
+ }
464
+
465
+ // Blob add
466
+ export interface BlobAddSuccess {
467
+ site : UCANAwait < '.out.ok.site' >
468
+ }
469
+
470
+ export interface BlobSizeOutsideOfSupportedRange extends Ucanto . Failure {
471
+ name : 'BlobSizeOutsideOfSupportedRange'
472
+ }
473
+
474
+ export interface AwaitError extends Ucanto . Failure {
475
+ name : 'AwaitError'
476
+ }
477
+
478
+ // TODO: We need Ucanto.Failure because provideAdvanced can't handle errors without it
479
+ export type BlobAddFailure =
480
+ | BlobSizeOutsideOfSupportedRange
481
+ | AwaitError
482
+ | StorageGetError
483
+ | Ucanto . Failure
484
+
485
+ export interface BlobListItem {
486
+ blob : BlobModel
487
+ insertedAt : ISO8601Date
488
+ }
489
+
490
+ // Blob allocate
491
+ export interface BlobAllocateSuccess {
492
+ size : number
493
+ address ?: BlobAddress
494
+ }
495
+
496
+ export interface BlobAddress {
497
+ url : ToString < URL >
498
+ headers : Record < string , string >
499
+ expiresAt : ISO8601Date
500
+ }
501
+
502
+ // If user space has not enough space to allocate the blob.
503
+ export interface NotEnoughStorageCapacity extends Ucanto . Failure {
504
+ name : 'NotEnoughStorageCapacity'
505
+ }
506
+
507
+ export type BlobAllocateFailure = NotEnoughStorageCapacity | Ucanto . Failure
508
+
509
+ // Blob accept
510
+ export interface BlobAcceptSuccess {
511
+ // A Link for a delegation with site commiment for the added blob.
512
+ site : Link
513
+ }
514
+
515
+ export interface AllocatedMemoryHadNotBeenWrittenTo extends Ucanto . Failure {
516
+ name : 'AllocatedMemoryHadNotBeenWrittenTo'
517
+ }
518
+
519
+ // TODO: We should type the store errors and add them here, instead of Ucanto.Failure
520
+ export type BlobAcceptFailure =
521
+ | AllocatedMemoryHadNotBeenWrittenTo
522
+ | Ucanto . Failure
523
+
524
+ // Storage errors
525
+ export type StoragePutError = StorageOperationError
526
+ export type StorageGetError = StorageOperationError | RecordNotFound
527
+
528
+ // Operation on a storage failed with unexpected error
529
+ export interface StorageOperationError extends Error {
530
+ name : 'StorageOperationFailed'
531
+ }
532
+
533
+ // Record requested not found in the storage
534
+ export interface RecordNotFound extends Error {
535
+ name : 'RecordNotFound'
536
+ }
537
+
442
538
// Store
443
539
export type Store = InferInvokedCapability < typeof StoreCaps . store >
444
540
export type StoreAdd = InferInvokedCapability < typeof StoreCaps . add >
@@ -530,6 +626,7 @@ export interface UploadListSuccess extends ListResponse<UploadListItem> {}
530
626
531
627
export type UCANRevoke = InferInvokedCapability < typeof UCANCaps . revoke >
532
628
export type UCANAttest = InferInvokedCapability < typeof UCANCaps . attest >
629
+ export type UCANConclude = InferInvokedCapability < typeof UCANCaps . conclude >
533
630
534
631
export interface Timestamp {
535
632
/**
@@ -540,6 +637,8 @@ export interface Timestamp {
540
637
541
638
export type UCANRevokeSuccess = Timestamp
542
639
640
+ export type UCANConcludeSuccess = Timestamp
641
+
543
642
/**
544
643
* Error is raised when `UCAN` being revoked is not supplied or it's proof chain
545
644
* leading to supplied `scope` is not supplied.
@@ -578,6 +677,15 @@ export type UCANRevokeFailure =
578
677
| UnauthorizedRevocation
579
678
| RevocationsStoreFailure
580
679
680
+ /**
681
+ * Error is raised when receipt is received for unknown invocation
682
+ */
683
+ export interface ReferencedInvocationNotFound extends Ucanto . Failure {
684
+ name : 'ReferencedInvocationNotFound'
685
+ }
686
+
687
+ export type UCANConcludeFailure = ReferencedInvocationNotFound | Ucanto . Failure
688
+
581
689
// Admin
582
690
export type Admin = InferInvokedCapability < typeof AdminCaps . admin >
583
691
export type AdminUploadInspect = InferInvokedCapability <
@@ -686,6 +794,7 @@ export type ServiceAbilityArray = [
686
794
Access [ 'can' ] ,
687
795
AccessAuthorize [ 'can' ] ,
688
796
UCANAttest [ 'can' ] ,
797
+ UCANConclude [ 'can' ] ,
689
798
CustomerGet [ 'can' ] ,
690
799
ConsumerHas [ 'can' ] ,
691
800
ConsumerGet [ 'can' ] ,
@@ -708,7 +817,13 @@ export type ServiceAbilityArray = [
708
817
AdminStoreInspect [ 'can' ] ,
709
818
PlanGet [ 'can' ] ,
710
819
Usage [ 'can' ] ,
711
- UsageReport [ 'can' ]
820
+ UsageReport [ 'can' ] ,
821
+ Blob [ 'can' ] ,
822
+ BlobAdd [ 'can' ] ,
823
+ ServiceBlob [ 'can' ] ,
824
+ BlobAllocate [ 'can' ] ,
825
+ BlobAccept [ 'can' ] ,
826
+ HTTPPut [ 'can' ]
712
827
]
713
828
714
829
/**
0 commit comments