-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.bs
1928 lines (1703 loc) · 58.1 KB
/
index.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class="metadata">
Title: Shape Trees Specification
Shortname: shapetrees-spec
Level: 1
Max ToC Depth: 2
Status: w3c/ED
Group: w3c
URL: https://shapetrees.org/TR/specification/
Editor: Eric Prud'hommeaux
Editor: Justin Bingham
Markup Shorthands: markdown yes
Abstract:
Semantic Web Applications interoperate by sharing semantics of terms and
constellations of resource-oriented data structures. This specification
defines shape trees, a mechanism for declaring and operating over
constellations of resource-oriented data structures.
</pre>
<!-- For bikeshed style overrides -->
<style>
em.rfc2119 {
text-transform: lowercase;
font-variant: small-caps;
font-style: normal;
font-size: 18px;
color: #900;
}
figcaption {
text-align: left;
}
pre {
font-size: 12px;
}
a[href*=".ttl"] {
color: #339966;
border-bottom: 1px solid #339966;
}
a[href*=".shex"] {
color: #cc2900;
border-bottom: 1px solid #cc2900;
}
a[href*=".tree"] {
color: #e68a00;
border-bottom: 1px solid #e68a00;
}
a[data-link-type=dfn] {
color: #000000;
}
table.tree thead tr {
font-size: 14px;
}
table.tree tbody tr:nth-child(even) {
background-color: lightgray;
font-size: 14px;
}
table.tree tbody td {
font-size: 12px;
}
table.operation {
border-collapse: separate;
border: 3px solid #808080;
margin-bottom: .5em;
}
table.operation thead tr {
font-size: 14px;
}
table.operation thead th {
background-color: #005A9C;
color: #FFF;
}
table.operation th[colspan] {
text-align: left;
}
table.operation td[colspan] {
text-align: left;
}
table.operation tbody td {
font-size: 13px;
text-align: left;
}
table.operation code {
background-color: #DCDCDC;
color: #000;
font-size: 13px;
padding-left: .2em;
padding-right: .2em;
padding-top: .05em;
padding-bottom: .05em;
}
.opdetails code {
background-color: #DCDCDC;
color: #000;
font-weight: bold;
font-size: 13px;
padding-left: .2em;
padding-right: .2em;
padding-top: .05em;
padding-bottom: .05em;
}
.opdetails code.vocab {
color: #339966;
background-color: #FFFFFF;
}
.opdetails ol {
margin-left: 0;
padding-left: 1em;
}
code.container {
color: #005555;
}
code.notes {
color: #770033;
}
code.citation {
color: #330077;
}
code.image {
color: #337700;
}
code.vocab {
color: #339966;
}
</style>
<div boilerplate="copyright">
<a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2020
<a href="https://www.w3.org/">W3C</a>®
(<a href="https://www.csail.mit.edu/">MIT</a>,
<a href="https://www.ercim.eu/">ERCIM</a>,
<a href="https://www.keio.ac.jp/">Keio</a>,
<a href="https://ev.buaa.edu.cn/">Beihang</a>).
W3C
<a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and
<a href="https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document">permissive document license</a>
rules apply.
</div>
Introduction {#introduction}
=====================
*This section is non-normative.*
Realizing the value proposition of the Semantic Web lies in building useful and
robust applications that can interoperate over linked data. Protocols such as
[[LDP]] and [[Solid]] organize linked data graphs into resource hierarchies,
providing a foundation upon which these robust and interoperable applications
can be created.
Application interoperability depends on applications sharing semantics for
relationships and data structures. Existing technologies fulfill portions
of those dependencies:
* [[RDF]]'s foundation in unambiguous identifiers provides an infrastructure
that allows for interoperability, but does not specifically encourage or enforce it.
* [=Shape=] languages (e.g. [[ShEx]] and [[SHACL]]) provide machine-readable,
enforceable data structure definitions on single resources.
For applications that operate on more complex and interconnected resources,
<i>[=Shape Trees=]</i> express the layout of those resources and associate them
with their respective [=shapes=].
[=Shape trees=] marry [[RDF]] vocabularies, shapes, and resources into
"little trees" that provide machine to machine interoperability, combining them
into concepts that humans can easily comprehend, such as medical records, notes,
notebooks, calendars, and financial records.
This allows one to treat a set of related resources as a single grouping, and
apply that to a range of operations including access control, data organization,
data validation, and data migration.
While [=shape trees=] are intended to adapt to different technology platforms
that support the notion of [=containers=] and [=resources=], examples in this
specification will reflect usage in an [[LDP]] environment.
[=Shape trees=] are defined as an [=RDF=] graph structure that expresses a set
of expected behaviors by agents that work with them. This provides a sort of
type-safety of resource hierarchies called <dfn>shape tree consistency</dfn>.
These semantics CAN be implemented by a [=server-side agent=], or by a
[=client-side agent=] that implements [=shape tree=] operations as primitive
requests to a server.
[=Shape tree=] support by a [=server-side agent=] ensures [=shape tree
consistency=] by managing all manipulations of data within a resource hierarchy
(see [=managed resource=]).
## ShapeTree Support From Proxy or Client-side Library
If a server does not support [=shape trees=], some [=shape tree consistency=]
can be achieved by implementing [=shape tree=] support in the client, typically
in a library than can enforce consistency for any clients using the
library. Primitive operations by other clients not using the library may leave the
resource hierarchy in an inconsistent state.
For client-side shape tree libraries that operate by intercepting HTTP
operations, this specification serves as an API for those client
interactions. (Additionally, if [=shape tree=] support is later added to the
server, the client's execution of [=shape tree=] operations does not change.) In
the remainder of this document, [=shape tree=] operations are described in terms
of a [=client-side agent=] performing operations on a [=server-side agent=] with
support for [=shape trees=].
A proxy performing [=shape tree=] operations would be indistinguishable from
server support except that clients performing primitive operations directly on
the server (bypassing the proxy) may leave the server in an inconsistent state.
Shape Tree {#tree}
=====================
A <dfn>shape tree</dfn> is a machine-readable template describing the
expected layout of a tree of resources in a [=container=]-based [=ecosystem=].
A [=shape tree=] expresses a tree hierarchy by containing
other [=shape trees=]. The terms used to express a [=shape tree=] are described
using an [[RDF]] [vocabulary](shapetrees.ttl).
A <dfn>managed instance</dfn> is a resource assigned to
and in conformance with one or more [=shape trees=] via
a [=shape tree manager=]. The primary resource in a
[=managed instance=] is called a <dfn>managed resource</dfn>.
Every [=managed resource=] has an associated [=shape tree manager=].
A [=shape tree manager=] identifies the [=shape tree=] associated
with a [=managed resource=], and additional information needed to navigate
nested hierarchies of managed resources. A resource becomes a
[=managed resource=] when a [=shape tree manager=] is associated with it
through the [[#plant-shapetree]] operation.
The <code class="vocab">st:expectsType</code> property of a [=shape tree=]
specifies that the described [=managed resource=] be one of these three types:
<table class="data" align="left">
<colgroup></colgroup>
<colgroup></colgroup>
<tbody>
<tr>
<td><code class="vocab">st:Resource</code></td>
<td>Regular RDF resource that is not a container</td>
</tr>
<tr>
<td><code class="vocab">st:Container</code></td>
<td>RDF resource that uses server-managed metadata to
enumerate nested resources</td>
</tr>
<tr>
<td><code class="vocab">st:NonRDFResource</code></td>
<td>Non-RDF resource such as binaries or images</td>
</tr>
</tbody>
</table>
The <code class="vocab">st:shape</code> property specifies that the
described [=managed resource=] conforms to the stated [[ShEx]] or [[SHACL]]
shape.
[=Shape trees=] prescribe physical hierarchies and can reference other
shape trees to form virtual hierarchies.
For physical hierarchies, the <code class="vocab">st:contains</code>
property asserts that a [=managed resource=] is a [=container=] that
explicitly contains another [=managed resource=].
If [=shape tree=] `S1` <code class="vocab">st:contains</code> [=shape tree=]
`S2`, `S1` describes a [=container=] that contains another [=managed resource=]
described by `S2`. For example, in [[LDP]], `S1` describes
an [[LDP]] [=container=] which <code class="vocab">ldp:contains</code> nested
resources described by `S2`. [=Shape tree=] `S2` and the nested resources
associated with it are considered to be <dfn>in-scope</dfn> of the containing
[=shape tree=] `S1`.
<figure id="shapetree-physical">
<figcaption>Shape tree validation of a physical hierarchy</figcaption>
<table class="data tree" align="left">
<col>
<col>
<thead>
<tr>
<th>Managed Resource</th>
<th>Associated Shape Tree</th>
</tr>
</thead>
<tbody>
<tr>
<td>`/project-1/`</td>
<td>`ex:ProjectTree`</td>
</tr>
<tr>
<td>`-- /milestone-A/`</td>
<td>`ex:MilestoneTree`</td>
</tr>
<tr>
<td>`---- /task-43/`</td>
<td>`ex:TaskTree`</td>
</tr>
<tr>
<td>`---- /task-48/`</td>
<td>`ex:TaskTree`</td>
</tr>
<tr>
<td>`------ /attachment-aa89`</td>
<td>`st:NonRDFResourceTree`</td>
</tr>
<tr>
<td>`---- /task-61/`</td>
<td>`ex:TaskTree`</td>
</tr>
<tr>
<td>`---- /issue-22/`</td>
<td>`ex:IssueTree`</td>
</tr>
<tr>
<td>`------ /attachment-cd12`</td>
<td>`st:NonRDFResourceTree`</td>
</tr>
<tr>
<td>`------ /attachment-ef55`</td>
<td>`st:NonRDFResourceTree`</td>
</tr>
<tr>
<td>`---- /issue-31/`</td>
<td>`ex:IssueTree`</td>
</tr>
</tbody>
</table>
<pre class=include-code>
path: snippets/project-tree.ttl
highlight: turtle
show: 1-29
</pre>
</figure>
A virtual hierarchy is defined by [=shape tree references=] that link to
other [=shape trees=] by the <code class="vocab">st:references</code>
property.
A <dfn>shape tree reference</dfn>
identifies the [=shape tree=] to be referenced via
<code class="vocab">st:referencesShapeTree</code>, and the [=shape path=] through
which it is linked via either <code class="vocab">st:viaShapePath</code>, or
<code class="vocab">st:viaPredicate</code>.
A <dfn>shape path</dfn> is a string that defines a traversal
of a [=shape=] schema. [[SHEXPATH]]
<figure id="shapetree-virtual">
<figcaption>Shape tree validation of a virtual hierarchy</figcaption>
<table class="data tree" align="left">
<col>
<col>
<thead>
<tr>
<th>Managed Resource</th>
<th>Associated Shape Tree</th>
</tr>
</thead>
<tbody>
<tr>
<td>`/project-1`</td>
<td>`ex:VirtualProjectTree`</td>
</tr>
<tr>
<td>`/milestone-A`</td>
<td>`ex:VirtualMilestoneTree`</td>
</tr>
<tr>
<td>`/task-43`</td>
<td>`ex:VirtualTaskTree`</td>
</tr>
<tr>
<td>`/task-48`</td>
<td>`ex:VirtualTaskTree`</td>
</tr>
<tr>
<td>`/attachment-aa89`</td>
<td>`st:NonRDFResourceTree`</td>
</tr>
<tr>
<td>`/task-61`</td>
<td>`ex:VirtualTaskTree`</td>
</tr>
<tr>
<td>`/issue-22`</td>
<td>`ex:VirtualIssueTree`</td>
</tr>
<tr>
<td>`/attachment-cd12`</td>
<td>`st:NonRDFResourceTree`</td>
</tr>
<tr>
<td>`/attachment-ef55`</td>
<td>`st:NonRDFResourceTree`</td>
</tr>
<tr>
<td>`/issue-31`</td>
<td>`ex:VirtualIssueTree`</td>
</tr>
</tbody>
</table>
<pre class=include-code>
path: snippets/project-tree.ttl
highlight: turtle
show: 31-70
</pre>
</figure>
Let <code>ST</code> be a [=shape tree=].
Let <code>STI</code> be a corresponding [=managed instance=].
* An { `ST` <code class="vocab">st:expectsType</code> `T` } [=triple=] identifies
the resource type `T` of a corresponding [=managed resource=]
<code>R</code> in <code>STI</code>
where `T` <em class="rfc2119">MUST</em> be one of
<code class="vocab">st:Resource</code>,
<code class="vocab">st:Container</code>, or
<code class="vocab">st:NonRDFResource</code>.
* An { `ST` <code class="vocab">rdfs:label</code> `L` } [=triple=]
indicates that there is at most one corresponding [=managed resource=]
`R` in `STI` and it has the name `L`. `L` is a <dfn>static resource</dfn>.
* An { `ST` <code class="vocab">st:shape</code> `SH` }
[=triple=] indicates that [=managed resource=] `R` has
at most one node which conforms to [=shape=] `SH`.
* An { `ST` <code class="vocab">st:contains</code> `ST2` }
[=triple=] identifies a nested [=shape tree=] `ST2`.
* An { `ST` <code class="vocab">st:references</code> `STR` }
[=triple=] indicates that the [=shape tree=] identified in
[=shape tree reference=] `STR`, is referenced through the
instance data of `STI`.
* An { `STR` <code class="vocab">st:referencesShapeTree</code> `ST3` } [=triple=]
indicates a [=shape tree=] referenced through the instance data of `STI`
* An { `STR` <code class="vocab">st:viaShapePath</code> `PATH` }
[=triple=] identifies the [=shape path=] through which a
[=managed instance=] of `ST3` can be found via the instance data of
`STI`
* An { `STR` <code class="vocab">st:viaPredicate</code> `PRED` }
[=triple=] identifies the RDF predicate through which a
[=managed instance=] of `ST3` can be found via the instance data of
`STI`
## Shape Tree Schema ## {#st-schema}
<figure id="shapetree-shex">
<figcaption>ShEx Schema for a Shape Tree</figcaption>
<pre class=include-code>
path: shapetrees-schema.shex
highlight: turtle
show: 7-28
</pre>
</figure>
Assigning Shape Trees {#assigning}
=====================
## Shape Tree Manager ## {#manager}
A <dfn>shape tree manager</dfn> associates a [=managed resource=] with
one or more [=shape trees=]. No more than one [=shape tree manager=] may be
associated with a [=managed resource=].
A [=shape tree manager=] includes one or more [=shape tree assignments=].
The server MUST advertise the URI of the [=shape tree manager=] for a
given resource by responding to HTTP requests of that resource with an
included `HTTP Link` header with a `rel` value of
`http://www.w3.org/ns/shapetrees#managedBy` and the manager resource
as the link target.
Conversely, the server MUST advertise the URI of the resource managed
by a [=shape tree manager=] by responding to HTTP requests of the
manager resource with an included `HTTP Link` header with a `rel` value of
`http://www.w3.org/ns/shapetrees#manages` and the [=managed resource=]
as the link target.
<figure id="shapetree-manager-properties">
<figcaption>Shape Tree Manager properties</figcaption>
<table class="data" align="left">
<colgroup></colgroup>
<colgroup></colgroup>
<thead>
<tr>
<th>Property</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="vocab">st:hasAssignment</code></td>
<td>Links a [=shape tree assignment=] of the [=shape tree manager=]</td>
</tr>
</tbody>
</table>
</figure>
## Shape Tree Assignment ## {#assignment}
A <dfn>shape tree assignment</dfn> is used to associate a given [=shape tree=]
with a [=managed resource=].
[=Shape tree assignments=] identify key contextual points in a physical
hierarchy. A <dfn>root shape tree assignment</dfn> is set by the
[Plant Operation](#plant-shapetree), and any subsequent assignment applied
within that managed hierarchy reference it via `st:hasRootAssignment`.
If there is more than one [=shape tree assignment=] in a [=shape tree manager=],
they must all apply to the same [=managed resource=] associated with the
[=shape tree manager=].
<figure id="shapetree-assignment-properties">
<figcaption>Shape Tree Assignment properties</figcaption>
<table class="data" align="left">
<colgroup></colgroup>
<colgroup></colgroup>
<thead>
<tr>
<th>Property</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="vocab">st:assigns</code></td>
<td>Identifies the [=shape tree=] to be associated with
the [=managed resource=]</td>
</tr>
<tr>
<td><code class="vocab">st:manages</code></td>
<td>Identifies the [=managed resource=] associated with the [=shape tree assignment=]</td>
</tr>
<tr>
<td><code class="vocab">st:hasRootAssignment</code></td>
<td>Identifies the [=root shape tree assignment=]</td>
</tr>
<tr>
<td><code class="vocab">st:focusNode</code></td>
<td>Identifies the focus node for [=shape=] validation
in the associated [=managed resource=], and is only valid when the
corresponding [=shape tree=] includes
<code class="vocab">st:shape</code></td>
</tr>
<tr>
<td><code class="vocab">st:shape</code></td>
<td>Identifies the [=shape=] to which <code class="vocab">st:focusNode</code>
must conform, and must be equivalent to <code class="vocab">st:shape</code>
in the corresponding [=shape tree=]</td>
</tr>
</tbody>
</table>
</figure>
A [=root shape tree=], and its corresponding [=managed resource=] can
be planted within an existing managed hierarchy, alongside or within other
[=root shape trees=] and [=managed resources=].
[=Shape tree assignments=]
in a given [=shape tree manager=] may have different
focus nodes.
<figure id="shapetree-navigation">
<figcaption>Navigating a physical shape tree hierarchy</figcaption>
<table class="data tree" align="left">
<colgroup>
<colgroup>
<col>
<col>
<col>
<thead>
<tr>
<th>Managed Resource</th>
<th>Shape Tree</th>
<th>Root Shape Tree</th>
<th>Root Managed Resource</th>
</tr>
</thead>
<tbody>
<tr>
<td>`/data/`</td>
<td>`ex:DataTree`</td>
<td>`ex:DataTree`</td>
<td>`/data/`</td>
</tr>
<tr>
<td>`-- /projects/`</td>
<td>`ex:DataCollectionTree`<br/>
`ex:ProjectCollectionTree`</td>
<td>`ex:DataTree`<br/>
`ex:ProjectCollectionTree`</td>
<td>`/data/`<br/>
`/data/projects/`</td>
</tr>
<tr>
<td>`---- /project-1/`</td>
<td>`ex:ProjectTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
<tr>
<td>`------ /milestone-A/`</td>
<td>`ex:MilestoneTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
<tr>
<td>`-------- /task-43/`</td>
<td>`ex:TaskTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
<tr>
<td>`-------- /task-48/`</td>
<td>`ex:TaskTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
<tr>
<td>`---------- /attachment-aa89`</td>
<td>`ex:AttachmentTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
<tr>
<td>`-------- /task-61/`</td>
<td>`ex:TaskTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
<tr>
<td>`-------- /issue-22/`</td>
<td>`ex:IssueTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
<tr>
<td>`---------- /attachment-cd12`</td>
<td>`ex:AttachmentTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
<tr>
<td>`---------- /attachment-ef55`</td>
<td>`ex:AttachmentTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
<tr>
<td>`-------- /issue-31/`</td>
<td>`ex:IssueTree`</td>
<td>`ex:ProjectCollectionTree`</td>
<td>`/data/projects/`</td>
</tr>
</tbody>
</table>
</figure>
<figure id="manager-multiple-assignments">
<figcaption>[=Shape Tree Manager=] for /data/projects/ with multiple
[=shape tree assignments=] in a nested physical hierarchy</figcaption>
<pre class=include-code>
path: snippets/manager-multiple.ttl
highlight: turtle
show: 1-25
</pre>
</figure>
<figure id="manager-single">
<figcaption>[=Shape Tree Manager=] for
/data/projects/project-1/milestone-A/task-48 with a single
[=shape tree assignment=] in a nested physical hierarchy</figcaption>
<pre class=include-code>
path: snippets/manager-single.ttl
highlight: turtle
show: 1-20
</pre>
</figure>
## Shape Tree Manager Schema ## {#st-manager-schema}
<figure id="shapetree-manager-shex">
<figcaption>ShEx Schema for a Shape Tree Manager</figcaption>
<pre class=include-code>
path: shapetrees-schema.shex
highlight: turtle
show: 37-49
</pre>
</figure>
Shape Tree Operations {#operations}
=====================
Working with [=shape trees=] entails using several higher-level operations --
each of which may represent one or more HTTP requests and/or pieces of
processing logic.
In regular use, a [=client-side agent=] manipulates resources on a
[=resource server=] running a [=server-side agent=]. That [=server-side agent=]
applies logic for [=shape tree=] validation and navigation where applicable
when processing requests from [=client-side agents=].
The key operations used to manage [=shape trees=] are:
* [Discover Shape Tree](#discover) - determine the [=shape tree=] linked to some [=managed resource=].
* [Plant Shape Tree](#plant-shapetree) - declare that a resource will henceforth be managed by the provided [=shape tree=].
* [Unplant Shape Tree](#unplant-shapetree) - assert that a managed resource should no longer be managed by the provided [=shape tree=].
* [Create Managed Instance](#create-managed-instance) - add a resource to a managed resource hierarchy.
* [Update Managed Instance](#update-managed-instance) - modify a resource in a managed resource hierarchy.
* [Delete Managed Instance](#delete-managed-instance) - remove a resource in a managed resource hierarchy.
These operations make use of reusable, internal algorithms defined in
[Shape Tree Algorithms](#algorithms).
[=Shape tree=] logic can be applied by [=server-side agents=]
implementing different protocols such as [[LDP]] or [[Solid]]. The operations
defined herein defer to the implementing protocol as to the appropriate
status code and composition of HTTP responses.
Note: Server-side processing of changes to [=shape tree managers=]
can support the addition and removal of multiple [=shape tree assignments=]
at once. For simplicity, this specification provides discreet client-side
operations to plant or unplant one shape tree at a time. However, it
would not be inappropriate to provide client implementations that
support requests to plant and unplant multiple shape trees for a
given [=resource=] in a single request.
## Discover Shape Tree ## {#discover}
<table class="data operation" align="left">
<colgroup></colgroup>
<colgroup></colgroup>
<thead>
<tr><th colspan=2>Description</th></tr>
</thead>
<tbody>
<tr>
<td colspan=2>
This operation is used by a [=client-side agent=] to discover
any [=shape trees=] associated with a given [=resource=].
If `URI` is a [=managed resource=], the associated
[=Shape Tree Manager=] will be returned.
</td>
</tbody>
<thead>
<tr><th colspan=2>Inputs</th></tr>
</thead>
<tbody>
<tr>
<td>`RESOURCEURI`</td>
<td>The URI of the resource to discover shape trees for</td>
</tr>
</tbody>
<thead>
<tr><th colspan=2>Outputs</th></tr>
</thead>
<tbody>
<tr>
<td>`MANAGER`</td>
<td>[=Shape tree manager=] associated with the [=managed resource=]</td>
</tr>
</tbody>
</table>
<div class="opdetails">
1. Perform an HTTP HEAD or GET on the provided <code>RESOURCEURI</code>.
<pre highlight="http">
HEAD https://storage.example/data/projects/
</pre>
<pre highlight="http">
HTTP/1.1 200 OK
Link: <https://storage.example/meta/c560224b>; rel="http://www.w3.org/ns/shapetrees#managedBy"
Link: <http://www.w3.org/ns/ldp#Container>; rel="type"
...other HTTP response headers omitted...
</pre>
2. Let <code>MANAGERURI</code> be the URI of a [=shape tree manager=]
associated with `RESOURCEURI` with a Link relation type of
`http://www.w3.org/ns/shapetrees#managedBy`.
3. If `MANAGERURI` is missing, the resource at
`RESOURCEURI` is not a [=managed resource=], and no [=shape tree manager=]
will be returned.
4. Perform an HTTP GET on `MANAGERURI`
<pre highlight="http">
GET https://storage.example/data/projects/.shapetree
</pre>
<pre highlight="turtle">
...HTTP response headers omitted...
PREFIX st: <http://www.w3.org/ns/shapetrees#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ex: <http://www.example/ns/ex#>
<>
a st:Manager ;
st:hasAssignment <#assignment1> .
<#assignment1>
st:assigns ex:DataCollectionTree ;
st:manages <https://storage.example/data/projects/>
st:hasRootAssignment <https://storage.example/data/.shapetree#assignment1> ;
st:focusNode <https://storage.example/data/projects/#collection> ;
st:shape ex:DataCollectionShape .
</pre>
5. If a corresponding resource at `MANAGERURI` is not found, it
<em class="rfc2119">MUST</em> be considered
an [=unmanaged resource=].
<pre highlight="http">
GET https://storage.example/data/projects/.shapetree
</pre>
<pre highlight="http">
HTTP/1.1 404 Not Found
</pre>
5. If `MANAGERURI` contains a valid [=shape tree manager=],
the resource at `RESOURCEURI` <em class="rfc2119">MUST</em> be considered a
[=managed resource=].
</div>
## Plant Shape Tree ## {#plant-shapetree}
<table class="data operation" align="left">
<colgroup></colgroup>
<colgroup></colgroup>
<thead>
<tr><th colspan=2>Description</th></tr>
</thead>
<tbody>
<tr>
<td colspan=2>
This operation marks an existing [=resource=] as managed by
one or more shape trees, by creating or updating an associated
[=shape tree manager=].
If the
[=resource=] is already managed, the associated [=shape tree manager=]
will be updated with another [=shape tree assignment=] for the
planted [=shape tree=].
If the [=resource=] is a container that already contains existing
resources, this operation will perform a depth first traversal through
the containment hierarchy, validating and assigning as it works its
way back up to the target resource of this operation.
</td>
</tbody>
</table>
### [=Client-side Agent|Client-side=] ### {#plant-client}
<table class="data operation" align="left">
<thead>
<tr><th colspan=2>Inputs</th></tr>
</thead>
<tbody>
<tr>
<td>`TR`</td>
<td>The URI of the resource to plant on</td>
</tr>
<tr>
<td>`TST`</td>
<td>A URI representing the shape tree to plant for `TR`</td>
</tr>
<tr>
<td>`FN`</td>
<td>An <em class="rfc2119">OPTIONAL</em> URI representing the
subject within `TR` used as the focus node for shape validation</td>
</tr>
</tbody>
<thead>
<tr><th colspan=2>Outputs</th></tr>
</thead>
<tbody>
<tr>
<td>`RESPONSE`</td>
<td>A standard HTTP response</td>
</tr>
</tbody>
</table>
<div class="opdetails">
1. [Discover](#discover) if `TR` is a [=managed resource=].
* Let `MANAGERURI` be the URI of the [=Shape Tree Manager=] associated
with `TR`.
1. Perform an HTTP `PUT` or `PATCH` on `MANAGERURI` to create or update the
[=Shape Tree Manager=] for `TR`
* Add a new `st:Assignment ASN`
* Let `ASN assigns` be `TST`
* Let `ASN manages` be `TR`
* Let `ASN hasRootAssignment` be `ASN`
* If `TST` has an `st:shape`
* Let `ASN st:shape` be the object value of `TST st:shape`
* Let `ASN st:focusNode` be `FN`
</div>
<pre highlight="http">
PUT https://storage.example/data/projects/.shapetree
</pre>
<pre highlight="turtle">
PREFIX st: <http://www.w3.org/ns/shapetrees#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ex: <http://www.example/ns/ex#>
<>
a st:Manager ;
st:hasAssignment <#assignment1>, <#assignment2> .
<#assignment1>
st:assigns ex:DataCollectionTree ;
st:manages <https://storage.example/data/projects/>
st:hasRootAssignment <https://storage.example/data/.shapetree#assignment1> ;
st:focusNode <https://storage.example/data/projects/#collection> ;
st:shape ex:DataCollectionShape .
<#assignment2>
st:assigns ex:ProjectCollectionTree ;
st:manages <https://storage.example/data/projects/>
st:hasRootAssignment <https://storage.example/data/projects/.shapetree#assignment2> ;
st:focusNode <https://storage.example/data/projects/#collection> ;
st:shape ex:ProjectCollectionShape .
</pre>
<pre highlight="http">
HTTP/1.1 204 No Content
</pre>
### [=Server-side Agent|Server-side=] ### {#plant-server}
<table class="data operation" align="left">
<thead>
<tr><th colspan=2>Inputs</th></tr>
</thead>
<tbody>
<tr>
<td>`REQ`</td>
<td>An HTTP `PUT` or `PATCH` request on `MANAGERURI` from the
[[#plant-client|previous sequence]]</td>
</tr>
</tbody>
<thead>
<tr><th colspan=2>Outputs</th></tr>
</thead>
<tbody>
<tr>
<td>`RESPONSE`</td>
<td>A standard HTTP response</td>
</tr>
</tbody>
</table>
<div class="opdetails">
Note: The following sequence is invoked by the server in response
to the `HTTP PUT` or `HTTP PATCH` on `MANAGERURI` by the [=client-side agent=]
in the [[#plant-client|previous sequence]].
1. Let `MANAGER` be the [=shape tree manager=] target of `REQ`
1. Let `R` be the primary resource directly associated with `MANAGER`
1. Let `UMR` be the updated [=shape tree manager=] in the body of `REQ`
1. Let `EMR` be the existing [=shape tree manager=] resource on the server
1. Let `ADDED` be the set of [=shape tree assignments=] that have been added to `EMR` by `UMR`
1. Let `REMOVED` be the set of [=shape tree assignments=] that have been removed from `EMR` by `UMR`
1. If `REMOVED` is not empty, the server must [[#unplant-server|unplant]] the
[=shape tree assignments=] that have been removed.
1. For each [=shape tree assignment=] `ASN` in `ADDED`
1. Call [[#assign-resource]] with inputs: `UMR`, `ASN`, `ASN`, `R`, `NULL`
</div>