Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for range selectors #184

Merged
merged 3 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
89 changes: 89 additions & 0 deletions specs/selectors/fixtures/selector-fixtures-adl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Selector Fixtures (ADL)
=======================

This file contains a set of selectors that can be used to test the ADL capabilities of selectors (InterpretAs and Slice).


### What's the fixture format?

Same as described in [selector-fixtures-1](../selector-fixtures-1/#whats-the-fixture-format).

---


Fixtures
--------

### A slice of a unixfs file.

#### data
The combination of these five data objects is replicated in `selector-fixtures-adl.car`.

[testmark]:# (adl-interpreted/root)
```json
{
"Data":{
"/":{"bytes":"CAIYgIBAIICAECCAgBAggIAQIICAEA"}
},
"Links":[
{"Hash":{"/":"baguqeera2pkvbqv2slrvh3dswozj6ozoob53idll3rkh3zh5tqsdqjvpzu7q"},"Name":"","Tsize":14},
{"Hash":{"/":"baguqeerasc2dhjjhbg6h3rt7rqbgpzlwzng5to3zwxcxtmdajfqt6tdyxscq"},"Name":"","Tsize":14},
{"Hash":{"/":"baguqeera7d7gvq7y7rugmmzh3u2552ckh6hyqno3tptbceutb5s3c4vixsua"},"Name":"","Tsize":14},
{"Hash":{"/":"baguqeeraxvm7dmqutnagoxxhq2iyghr5qidbjovdi7iqdptw527gifajqlgq"},"Name":"","Tsize":14}
]
}
```

the leaves are dag-json encodings of "file chunk a\r\n" through "file chunk d\r\n".

[testmark]:# (adl-interpreted/baguqeera2pkvbqv2slrvh3dswozj6ozoob53idll3rkh3zh5tqsdqjvpzu7q)
```json
{
"/":{"bytes":"ZmlsZSBjaHVuayBhCgo"}
}
```
[testmark]:# (adl-interpreted/baguqeerasc2dhjjhbg6h3rt7rqbgpzlwzng5to3zwxcxtmdajfqt6tdyxscq)
```json
{
"/":{"bytes":"ZmlsZSBjaHVuayBiCgo"}
}
```
[testmark]:# (adl-interpreted/baguqeera7d7gvq7y7rugmmzh3u2552ckh6hyqno3tptbceutb5s3c4vixsua)
```json
{
"/":{"bytes":"ZmlsZSBjaHVuayBjCgo"}
}
```
[testmark]:# (adl-interpreted/baguqeeraxvm7dmqutnagoxxhq2iyghr5qidbjovdi7iqdptw527gifajqlgq)
```json
{
"/":{"bytes":"ZmlsZSBjaHVuayBkCgo"}
}
```
#### selector

[testmark]:# (adl-interpreted/selector)
```json
{
"~": {
"as": "unixfs",
">": {
".": {
"subset": {
"[": 14,
"]": 42
}
}
}
}
}
```

#### expected visit events

the visit will be to the synthetic node containing the contents: "file chunk b\r\nfile chunk c\r\n"

[testmark]:# (adl-interpreted/expect-visit)
```text
{"path": "", "node": {"bytes": {"/":{"bytes":"ZmlsZSBjaHVuayBiCgpmaWxlIGNodW5rIGMKCg"}}}, "matched": true}
warpfork marked this conversation as resolved.
Show resolved Hide resolved
```
10 changes: 10 additions & 0 deletions specs/selectors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ type InterpretAs struct {
next Selector (rename ">")
}

## Slice is a predicate that selects only a subset of node.
## This is applicable primarily in the context of reified nodes based on the
## InterpetAs clause above, where the primitive (bytes or string) node is actually
## composed from multiple underlying substrate nodes.
type Slice struct {
from Int (rename "[")
to Int (rename "]")
}

## Matcher marks a node to be included in the "result" set.
## (All nodes traversed by a selector are in the "covered" set (which is a.k.a.
## "the merkle proof"); the "result" set is a subset of the "covered" set.)
Expand All @@ -213,6 +222,7 @@ type InterpretAs struct {
type Matcher struct {
onlyIf optional Condition # match is true based on position alone if this is not set.
label optional String # labels can be used to match multiple different structures in one selection.
subset optional Slice # if set, only the subset of the node specified by the slice is matched.
}

## Condition is expresses a predicate with a boolean result.
Expand Down