-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alan Shaw
committed
Dec 8, 2023
1 parent
e340d25
commit 4c51c6a
Showing
17 changed files
with
511 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package storeadd | ||
|
||
import ( | ||
"github.com/ipld/go-ipld-prime" | ||
"github.com/ipld/go-ipld-prime/datamodel" | ||
"github.com/ipld/go-ipld-prime/node/basicnode" | ||
"github.com/web3-storage/go-ucanto/did" | ||
"github.com/web3-storage/go-ucanto/ucan" | ||
) | ||
|
||
const Ability = "store/add" | ||
|
||
type Caveat struct { | ||
Link ipld.Link | ||
Size uint64 | ||
Origin *ipld.Link | ||
} | ||
|
||
var _ ucan.MapBuilder = (*Caveat)(nil) | ||
|
||
func (c *Caveat) Build() (map[string]datamodel.Node, error) { | ||
data := map[string]datamodel.Node{} | ||
|
||
b := basicnode.Prototype.Link.NewBuilder() | ||
err := b.AssignLink(c.Link) | ||
if err != nil { | ||
return nil, err | ||
} | ||
data["link"] = b.Build() | ||
|
||
b = basicnode.Prototype.Int.NewBuilder() | ||
err = b.AssignInt(int64(c.Size)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
data["size"] = b.Build() | ||
|
||
if c.Origin != nil { | ||
b = basicnode.Prototype.Link.NewBuilder() | ||
err = b.AssignLink(c.Link) | ||
if err != nil { | ||
return nil, err | ||
} | ||
data["origin"] = b.Build() | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
func NewCapability(space did.DID, nb *Caveat) ucan.Capability[ucan.MapBuilder] { | ||
return ucan.NewCapability(Ability, space.String(), ucan.MapBuilder(nb)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package storeadd | ||
|
||
import "github.com/web3-storage/go-ucanto/core/receipt" | ||
|
||
func NewReceiptReader() (receipt.ReceiptReader[*Success, *Failure], error) { | ||
return receipt.NewReceiptReader[*Success, *Failure](ResultSchema) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package storeadd | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/ipld/go-ipld-prime" | ||
) | ||
|
||
//go:embed result.ipldsch | ||
var ResultSchema []byte | ||
|
||
type Success struct { | ||
Status string | ||
With string | ||
Link ipld.Link | ||
Url *string | ||
Headers *Headers | ||
} | ||
|
||
type Headers struct { | ||
Keys []string | ||
Values map[string]string | ||
} | ||
|
||
type Failure struct { | ||
Name *string | ||
Message string | ||
Stack *string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
type Result union { | ||
| Success "ok" | ||
| Failure "error" | ||
} representation keyed | ||
|
||
type Success struct { | ||
status String | ||
with DID | ||
link Link | ||
url optional URL | ||
headers optional {String: String} | ||
} | ||
|
||
# type Success union { | ||
# | SuccessUpload "upload" | ||
# | SuccessDone "done" | ||
# } representation inline { | ||
# discriminantKey "status" | ||
# } | ||
|
||
# type SuccessUpload struct { | ||
# with DID | ||
# link Link | ||
# url URL | ||
# headers {String: String} | ||
# } | ||
|
||
# type SuccessDone struct { | ||
# with DID | ||
# link Link | ||
# } | ||
|
||
type DID string | ||
type URL string | ||
|
||
type Failure struct { | ||
name optional String | ||
message String | ||
stack optional String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package uploadadd | ||
|
||
import ( | ||
"github.com/ipld/go-ipld-prime" | ||
"github.com/ipld/go-ipld-prime/datamodel" | ||
"github.com/ipld/go-ipld-prime/node/basicnode" | ||
"github.com/web3-storage/go-ucanto/did" | ||
"github.com/web3-storage/go-ucanto/ucan" | ||
) | ||
|
||
const Ability = "upload/add" | ||
|
||
type Caveat struct { | ||
Root ipld.Link | ||
Shards []ipld.Link | ||
} | ||
|
||
var _ ucan.MapBuilder = (*Caveat)(nil) | ||
|
||
func (c *Caveat) Build() (map[string]datamodel.Node, error) { | ||
data := map[string]datamodel.Node{} | ||
|
||
b := basicnode.Prototype.Link.NewBuilder() | ||
err := b.AssignLink(c.Root) | ||
if err != nil { | ||
return nil, err | ||
} | ||
data["root"] = b.Build() | ||
|
||
if c.Shards != nil { | ||
b := basicnode.Prototype.Any.NewBuilder() | ||
la, err := b.BeginList(int64(len(c.Shards))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, s := range c.Shards { | ||
err := la.AssembleValue().AssignLink(s) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
la.Finish() | ||
data["shards"] = b.Build() | ||
} | ||
return data, nil | ||
} | ||
|
||
func NewCapability(space did.DID, nb *Caveat) ucan.Capability[ucan.MapBuilder] { | ||
return ucan.NewCapability(Ability, space.String(), ucan.MapBuilder(nb)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package uploadadd | ||
|
||
import "github.com/web3-storage/go-ucanto/core/receipt" | ||
|
||
func NewReceiptReader() (receipt.ReceiptReader[*Success, *Failure], error) { | ||
return receipt.NewReceiptReader[*Success, *Failure](ResultSchema) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package uploadadd | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/ipld/go-ipld-prime" | ||
) | ||
|
||
//go:embed result.ipldsch | ||
var ResultSchema []byte | ||
|
||
type Success struct { | ||
Root ipld.Link | ||
Shards []ipld.Link | ||
} | ||
|
||
type Failure struct { | ||
Name *string | ||
Message string | ||
Stack *string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type Result union { | ||
| Success "ok" | ||
| Failure "error" | ||
} representation keyed | ||
|
||
type Success struct { | ||
root Link | ||
shards optional [Link] | ||
} | ||
|
||
type Failure struct { | ||
name optional String | ||
message String | ||
stack optional String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package uploadlist | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/ipld/go-ipld-prime" | ||
) | ||
|
||
//go:embed result.ipldsch | ||
var ResultSchema []byte | ||
|
||
type Success struct { | ||
Results []Item | ||
Before *string | ||
After *string | ||
Cursor *string | ||
Size uint64 | ||
} | ||
|
||
type Item struct { | ||
Root ipld.Link | ||
Shards []ipld.Link | ||
InsertedAt string | ||
UpdatedAt string | ||
} | ||
|
||
type Failure struct { | ||
Name *string | ||
Message string | ||
Stack *string | ||
} |
12 changes: 6 additions & 6 deletions
12
capability/uploadlist/upload.ipldsch → capability/uploadlist/result.ipldsch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.