From 678d45ee9e26bae8ba95d56b7c00d839f8bb72b8 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Tue, 1 Mar 2022 19:13:55 +0100 Subject: [PATCH 1/3] Proposal for range selectors --- .../fixtures/selector-fixtures-adl.md | 98 +++++++++++++++++++ specs/selectors/index.md | 10 ++ 2 files changed, 108 insertions(+) create mode 100644 specs/selectors/fixtures/selector-fixtures-adl.md diff --git a/specs/selectors/fixtures/selector-fixtures-adl.md b/specs/selectors/fixtures/selector-fixtures-adl.md new file mode 100644 index 00000000..520d9d60 --- /dev/null +++ b/specs/selectors/fixtures/selector-fixtures-adl.md @@ -0,0 +1,98 @@ +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 + +[testmark]:# (adl-interpreted/root) +```json +{ + "Links": [ + { + "Name": "", + "Hash": "shard-a", + "Size": 256 + }, + { + "Name": "", + "Hash": "shard-b", + "Size": 256 + }, + { + "Name": "", + "Hash": "shard-c", + "Size": 256 + }, + { + "Name": "", + "Hash": "shard-d", + "Size": 256 + } + ], + "Data": {"/": ""} +} +``` +[testmark]:# (adl-interpreted/shard-a) +```json +{ + "/": {"Bytes": "..."} +} +``` +[testmark]:# (adl-interpreted/shard-b) +```json +{ + "/": {"Bytes": "..."} +} +``` +[testmark]:# (adl-interpreted/shard-c) +```json +{ + "/": {"Bytes": "..."} +} +``` +[testmark]:# (adl-interpreted/shard-d) +```json +{ + "/": {"Bytes": "..."} +} +``` +#### selector + +[testmark]:# (adl-interpreted/selector) +```json +{ + "~": { + "as": "unixfs", + ">": { + ".": { + "subset": { + "[": 256, + "]": 768 + } + } + } + } +} +``` + +#### expected visit events + +[testmark]:# (adl-interpreted/expect-visit) +```text +{"path": "shard-b", "node": {"list": null}, "matched": true} +{"path": "shard-c", "node": {"list": null}, "matched": true} +``` diff --git a/specs/selectors/index.md b/specs/selectors/index.md index 32ab8ecd..42604650 100644 --- a/specs/selectors/index.md +++ b/specs/selectors/index.md @@ -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.) @@ -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. From b435d45c2f70db12290d308356cca0facabc1df8 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Sun, 6 Mar 2022 18:05:33 +0100 Subject: [PATCH 2/3] Fill in spec fixture with behavior --- .../fixtures/selector-fixtures-adl.car | Bin 0 -> 1147 bytes .../fixtures/selector-fixtures-adl.md | 56 +++++++----------- 2 files changed, 21 insertions(+), 35 deletions(-) create mode 100644 specs/selectors/fixtures/selector-fixtures-adl.car diff --git a/specs/selectors/fixtures/selector-fixtures-adl.car b/specs/selectors/fixtures/selector-fixtures-adl.car new file mode 100644 index 0000000000000000000000000000000000000000..94976f30f6a0d3a21d53ec188780a8e4ba219678 GIT binary patch literal 1147 zcmd;Dm|m7zRGgWg$HagJjG_D_W(Z>{l(t@!T9lt(Qrvh$D?*KdaV3+GLd&ror@Gd- zq{kiUiqUpsTC5we_R#*WbBoPwe^QQUMdIi;6 zc(d<>)IRw;N5w*I{aO2JC4D8UYNe#glGI`)E2XI1oZ_fpr>sPeu+qdzrwr%xe5Kl2 zh*1-^7%x@l+*5n3zK1FOY1wJto4YHw9C={tFyCXx|3si zx~F3xnC}P-KOH5X%)D%1_(oSNc_bERKuu6eN=z>;Oie9HG%Cn0ODZfgD$Xe?%P>wU zF3+#ZGRv>Z&rdQn&P>V4F)qr^Fs{llEh#KcDas46utR0107mzbLhj5Q@4rI6yx zDj?I)q*e!q9mUB;DH&N=8A<788OB8==0$}`=>=6e%0VxC@BXkKYvRGOZfTa{s4YGi6^l$@PmmQh)lmv3BBP?D6KT3V81 zT5OzbQkGd!T$)I#KPt*{%~NsT(=*c&vkG(4arz^+wvmGonB|0^`47a_0OAu+KB3H(0nz{jgtA6EL>U92#3~Cl Rk5I0)ftp7sA6F^H literal 0 HcmV?d00001 diff --git a/specs/selectors/fixtures/selector-fixtures-adl.md b/specs/selectors/fixtures/selector-fixtures-adl.md index 520d9d60..4655d653 100644 --- a/specs/selectors/fixtures/selector-fixtures-adl.md +++ b/specs/selectors/fixtures/selector-fixtures-adl.md @@ -17,57 +17,44 @@ 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 { - "Links": [ - { - "Name": "", - "Hash": "shard-a", - "Size": 256 - }, - { - "Name": "", - "Hash": "shard-b", - "Size": 256 - }, - { - "Name": "", - "Hash": "shard-c", - "Size": 256 - }, - { - "Name": "", - "Hash": "shard-d", - "Size": 256 - } - ], - "Data": {"/": ""} + "Data":{ + "/":{"bytes":"CAIYgIBAIICAECCAgBAggIAQIICAEA"} + }, + "Links":[ + {"Hash":{"/":"baguqeera2pkvbqv2slrvh3dswozj6ozoob53idll3rkh3zh5tqsdqjvpzu7q"},"Name":"","Tsize":14}, + {"Hash":{"/":"baguqeerasc2dhjjhbg6h3rt7rqbgpzlwzng5to3zwxcxtmdajfqt6tdyxscq"},"Name":"","Tsize":14}, + {"Hash":{"/":"baguqeera7d7gvq7y7rugmmzh3u2552ckh6hyqno3tptbceutb5s3c4vixsua"},"Name":"","Tsize":14}, + {"Hash":{"/":"baguqeeraxvm7dmqutnagoxxhq2iyghr5qidbjovdi7iqdptw527gifajqlgq"},"Name":"","Tsize":14} + ] } ``` -[testmark]:# (adl-interpreted/shard-a) +[testmark]:# (adl-interpreted/baguqeera2pkvbqv2slrvh3dswozj6ozoob53idll3rkh3zh5tqsdqjvpzu7q) ```json { - "/": {"Bytes": "..."} + "/":{"bytes":"ZmlsZSBjaHVuayBhCgo"} } ``` -[testmark]:# (adl-interpreted/shard-b) +[testmark]:# (adl-interpreted/baguqeerasc2dhjjhbg6h3rt7rqbgpzlwzng5to3zwxcxtmdajfqt6tdyxscq) ```json { - "/": {"Bytes": "..."} + "/":{"bytes":"ZmlsZSBjaHVuayBiCgo"} } ``` -[testmark]:# (adl-interpreted/shard-c) +[testmark]:# (adl-interpreted/baguqeera7d7gvq7y7rugmmzh3u2552ckh6hyqno3tptbceutb5s3c4vixsua) ```json { - "/": {"Bytes": "..."} + "/":{"bytes":"ZmlsZSBjaHVuayBjCgo"} } ``` -[testmark]:# (adl-interpreted/shard-d) +[testmark]:# (adl-interpreted/baguqeeraxvm7dmqutnagoxxhq2iyghr5qidbjovdi7iqdptw527gifajqlgq) ```json { - "/": {"Bytes": "..."} + "/": {"bytes": "ZmlsZSBjaHVuayBkCgo"} } ``` #### selector @@ -80,8 +67,8 @@ Fixtures ">": { ".": { "subset": { - "[": 256, - "]": 768 + "[": 14, + "]": 42 } } } @@ -93,6 +80,5 @@ Fixtures [testmark]:# (adl-interpreted/expect-visit) ```text -{"path": "shard-b", "node": {"list": null}, "matched": true} -{"path": "shard-c", "node": {"list": null}, "matched": true} +{"path": "", "node": {"bytes": {"/":{"bytes":"ZmlsZSBjaHVuayBiCgpmaWxlIGNodW5rIGMKCg"}}}, "matched": true} ``` From 8b19ac91320c02f01699efc906382b803c6136aa Mon Sep 17 00:00:00 2001 From: Will Scott Date: Sun, 6 Mar 2022 18:55:11 +0100 Subject: [PATCH 3/3] add additional explanitory text --- specs/selectors/fixtures/selector-fixtures-adl.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/specs/selectors/fixtures/selector-fixtures-adl.md b/specs/selectors/fixtures/selector-fixtures-adl.md index 4655d653..8b1eaf0e 100644 --- a/specs/selectors/fixtures/selector-fixtures-adl.md +++ b/specs/selectors/fixtures/selector-fixtures-adl.md @@ -33,6 +33,9 @@ The combination of these five data objects is replicated in `selector-fixtures-a ] } ``` + +the leaves are dag-json encodings of "file chunk a\r\n" through "file chunk d\r\n". + [testmark]:# (adl-interpreted/baguqeera2pkvbqv2slrvh3dswozj6ozoob53idll3rkh3zh5tqsdqjvpzu7q) ```json { @@ -54,7 +57,7 @@ The combination of these five data objects is replicated in `selector-fixtures-a [testmark]:# (adl-interpreted/baguqeeraxvm7dmqutnagoxxhq2iyghr5qidbjovdi7iqdptw527gifajqlgq) ```json { - "/": {"bytes": "ZmlsZSBjaHVuayBkCgo"} + "/":{"bytes":"ZmlsZSBjaHVuayBkCgo"} } ``` #### selector @@ -78,6 +81,8 @@ The combination of these five data objects is replicated in `selector-fixtures-a #### 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}