forked from shapetrees/specification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.bs
1983 lines (1719 loc) · 70.3 KB
/
spec.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/spec
Editor: Eric Prud'hommeaux
Editor: Justin Bingham
Editor: Josh Collins
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;
}
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.algorithmparams {
width: 70%;
align: center;
}
table.algorithmparams tbody td {
}
table.algorithmparams tbody tr:nth-child(even) {
background-color: lightgray;
}
table.algorithmparams thead td {
}
table.operationdetails {
width: 100%;
margin-bottom: 25px;
}
table.operationdetails tbody tr:nth-child(even) {
background-color: lightgray;
}
table.operationdetails thead td {
border: 1px solid #999999;
}
table.operationdetails tbody td {
border: 1px solid #999999;
}
code.container {
color: #005555;
}
code.notes {
color: #770033;
}
code.citation {
color: #330077;
}
code.image {
color: #337700;
}
code.vocab {
color: #339966;
}
</style>
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.
[=Shape trees=] are defined as an [=RDF=] graph structure that expresses a set
of expected behaviors by agents that work with them. These semantics CAN be
implemented by a server, or a client-side library that pre-processes requests
to a server.
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.
Structure {#structure}
=====================
A <dfn>shape tree</dfn> is a machine-readable template describing the expected
layout of a tree of resources in a [=container=]-based ecosystem.
The terms used to express a [=shape tree=] are described using an [=RDF=]
[vocabulary](shapetree.ttl).
The realization of a [=shape tree=] is a <dfn>planted shape tree</dfn>.
The upper-most Container of that tree is the <dfn>instance root</dfn>.
Let <code>ST</code> be a [=shape tree=];
Let <code>T</code> be a corresponding instance tree.
For any [=shape tree=] <code>S</code> linked in <code>ST</code>:
* The <code class="vocab">st:expectsType</code> arc identifies the type of a
corresponding resource <code>R</code> in <code>T</code> where validate
values <em class="rfc2119">MUST</em> be one of
<code class="vocab">st:ShapeTreeResource</code>,
<code class="vocab">st:ShapeTreeContainer</code>, or
<code class="vocab">st:ShapeTreeNonRDFResource</code>.
* An { <code>S</code> <code class="vocab">rdfs:label</code> <code>L</code> } arc
indicates that there is exactly one corresponding resource <code>R</code>
and it has the name <code>L</code>.
* An { <code>S</code> <code class="vocab">st:matchesUriTemplate</code>
<code>L</code> } arc indicates that there <em class="rfc2119">MAY</em>
be an arbitrary number of corresponding resources <code>R</code>
and each will have a name that matches the URI template
[[RFC6570]] <code>L</code>.
* An { <code>S</code> <code class="vocab">st:validatedBy</code> <code>Sh</code> }
arc indicates that <code>R</code> <em class="rfc2119">MUST</em>
have exactly one node which conforms to shape <code>Sh</code>.
* Any { <code>S</code> <code class="vocab">st:contains</code> <code>S2</code> }
arcs indicate there is a nested [=shape tree=] and corresponding nested
resource <code>R2</code>.
* An { <code>S</code> <code class="vocab">st:references</code> <code>S3</code> }
arc indicates that [=shape tree=] <code>S3</code> is referenced through the
instance data for <code>S</code>.
* An { <code>S</code> <code class="vocab">st:supports</code> <code>S4</code> }
arc indicates that <code>S</code> provides a different representation of
<code>S4</code> for aggregation purposes.
A { <code class="vocab">st:hasShapeTreeDecoratorIndex</code> <code>Si</code> }
arc indicates the location of an index of SKOS hierarchies that describe
<code>ST</code>.
<figure id="shapetree-shex">
<figcaption>ShEx validation of a Shape Tree</figcaption>
<pre highlight="turtle">
prefix st: <http://www.w3.org/ns/st#>.
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
<#ShapeTree> {
a st:ShapeTree ;
(
st:expectsType [st:ShapeTreeContainer] ;
st:contains @<#ShapeTree> +
) ;
(rdfs:label xsd:string | st:matchesUriTemplate xsd:string) ;
st:references @<#ReferencedShapeTree> * ;
st:validatedBy IRI ? ;
st:contains IRI ? ;
st:supports IRI ? ;
}
<#ReferencedShapeTree> {
st:hasShapeTree IRI ;
st:traverseViaShapePath xsd:string
}
</pre>
</figure>
Ecosystems {#ecosystems}
=====================
[=Shape trees=] are meant to be used in context of a broader [=ecosystem=].
[=Ecosystems=] have the ability to react to (and in some cases influence)
[=shape tree=] operations.
[=Ecosystems=] define the compatibility requirements for participating
applications and agents to be interoperable.
[=Shape trees=] are used by [=ecosystems=] to become aware of the planting of
[=shape trees=] and changes to instances of those trees.
A [=Shape tree=] client library <em class="rfc2119">MUST</em> be initialized
with a reference to the the target [=ecosystem=] it would operate within.
For purposes of this specification, an [=ecosystem=]
<em class="rfc2119">SHOULD</em> be considered a software interface, expecting
the [below operations](#ecosystem-operations) to be implemented.
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.
The key operations used to manage [=shape trees=] are:
* [Discover Shape Tree](#discover)
* [Plant Shape Tree](#plant-shapetree)
* [Create Data Instance](#create-data-instance)
* [Update Data Instance](#update-data-instance)
* [Delete Data Instance](#delete-data-instance)
* [Unplant Shape Tree](#unplant-shapetree)
These operations make use of reusable, internal algorithms defined in
[Shape Tree Algorithms](#algorithms).
## Discover Shape Tree ## {#discover}
The <b>discover shape tree</b> operation entails discovering what, if any,
shape trees are managing a given container.
### Inputs ### {#discover-inputs}
* Let <code>uri</code> be the URI of the resource to discover shape trees for
### Outputs ### {#discover-outputs}
* Collection of <code class="vocab">st:ShapeTreeLocator</code> subjects
### Operation Summary ### {#discover-summary}
<table class="data operationdetails" align="left">
<thead>
<tr>
<th>#</th>
<th>Step</th>
<th colspan="2">Interaction</th>
</tr>
</thead>
<tbody>
<tr>
<td>[1](#discovery-details-head)</td>
<td>Perform a HEAD on <code>uri</code> to discover Shape Tree metadata URI</td>
<td>[Request](#fig-discover-head-request)</td>
<td>
[Response](#fig-discover-head-response)
</td>
</tr>
<tr>
<td>[2](#discovery-details-get)</td>
<td>Perform a GET on the discovered Shape Tree metadata resource</td>
<td>[Request](#fig-discover-get-metadata)</td>
<td>
[Managed Response](#fig-discover-head-response-managed)<br/>
[Unmanaged Response](#fig-discover-head-response-unmanaged)
</td>
</tr>
<tr>
<td>[3](#discovery-details-collect)</td>
<td>Collect any navigable shape trees</td>
<td colspan="2">N/A - Logic only</td>
</tr>
</tbody>
</table>
### Operation Details ### {#discovery-details}
#### Perform a HEAD on the provided <code>uri</code> to discover Shape Tree metadata URI #### {#discovery-details-head}
Note: This step <em class="rfc2119">SHOULD</em> be performed by a
client-side agent.
<figure id="fig-discover-head-request">
<figcaption><code>uri</code> = <code>/data/CommonNotes/</code></figcaption>
<pre highlight="http">
HEAD /data/CommonNotes/
</pre>
</figure>
<figure id="fig-discover-head-response">
<figcaption>Discover Container Shape Tree Metadata - HEAD container -
Response</figcaption>
<pre highlight="http">
HTTP/1.1 200 OK
Link: </data/CommonNotes/meta/UUID>; rel="http://shapetrees.org/#ShapeTree"
Link: <http://www.w3.org/ns/ldp#Container>; rel="type"
...other headers omitted...
</pre>
</figure>
Discovering shape trees only applies to URIs of containers. A status code of
400 <em class="rfc2119">MUST</em> be returned if no Link headers with a
relation type which maps to the implementation's notion of a [=container=]
(e.g. `http://www.w3.org/ns/ldp#Container` in an LDP context) exists.
Let <code>metauri</code> be the URI of the shape tree metadata resource
pertaining to <code>uri</code> through the Link header with relation
`http://shapetrees.org/#ShapeTree`.
#### Perform a GET on the discovered Shape Tree metadata resource (<code>metauri</code>) #### {#discovery-details-get}
Note: This step <em class="rfc2119">SHOULD</em> performed by a
client-side agent.
<figure id="fig-discover-get-metadata">
<figcaption>Discover Container Shape Tree Metadata -
Get Shape Tree metadata - Request</figcaption>
<pre highlight="http">
GET /data/CommonNotes/meta/UUID
</pre>
</figure>
<figure id="fig-discover-head-response-managed">
<figcaption>Discover Container Shape Tree Metadata -
GET Shape Tree metadata - Managed Container Response</figcaption>
<pre highlight="turtle">
prefix st: <http://www.w3.org/ns/st#>.
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
<#shapetree>
st:hasShapeTreeLocator <#bc1b490a-537d-4749-b778-cd7d6da3ac56> .
<#bc1b490a-537d-4749-b778-cd7d6da3ac56>
a st:ShapeTreeLocator ;
st:hasRootShapeTree <http://commonnote.example/commonnote#container-tree> ;
st:hasShapeTree <http://commonnote.example/commonnote#container-tree> ;
st:hasShapeTreeInstanceRoot </data/CommonNotes/> .
</pre>
</figure>
<figure id="fig-discover-head-response-unmanaged">
<figcaption>Discover Container Shape Tree Metadata -
GET Shape Tree metadata - Unmanaged Container Response</figcaption>
<pre highlight="http">
HTTP/1.1 404 NOT FOUND
</pre>
</figure>
A 404 status code indicates that no [=shape trees=] manage this
[=container=], and so it <em class="rfc2119">MUST</em> be considered
an [=Unmanaged Container=].
#### Collect any navigable shape trees #### {#discovery-details-collect}
Note: This step <em class="rfc2119">SHOULD</em> performed by a
client-side agent.
If the ```<#shapetree>``` subject has one or more
<code class="vocab">st:hasShapeTreeLocator</code> predicates it means this
container <em class="rfc2119">MUST</em> be considered a [=Managed Container=].
Let <code>mc</code> be this [=managed container=].
The <code class="vocab">st:hasShapeTree</code> of each
<code class="vocab">st:ShapeTreeLocator</code> subject specifies what
[=shape tree=] manages <code>mc</code>.
The IRI of each <code class="vocab">st:ShapeTreeLocator</code> describing a
[=shape tree=] managing <code>mc</code> <em class="rfc2119">SHOULD</em>
be returned.
## Plant Shape Tree ## {#plant-shapetree}
Note: A plant operation <em class="rfc2119">MAY</em>
be performed by either a client or server side agent.
The <b>plant</b> operation marks a container (new or existing) as being
managed by one or more shape trees.
### Inputs ### {#plant-inputs}
* Let <code>req</code> be a POST or PUT HTTP request with the following
characteristics:
* Let <code>linkst</code> be one or more Link headers with the relation of
"http://shapetrees.org/#ShapeTree". This represents one or more
[=shape trees=] to be planted by the plant operation.
* A Link header with the relation "type" and a value of a compatible
[=container=] (e.g. <http://www.w3.org/ns/ldp#BasicContainer>)
* Let <code>linkfn</code> be an <em class="rfc2119">optional</em> Link
header with the relation of
"http://shapetrees.org/#FocusNode". This represents the
target subject within the request body (used for ShEx validation, etc.)
* Let <code>linktst</code> be an <em class="rfc2119">OPTIONAL</em>
Link header with the relation of "http://shapetrees.org/#TargetShapeTree"
* Let <code>slug</code> be a Slug header, <em class="rfc2119">REQUIRED</em>
when <code>req</code> is a POST and no <code>linktst</code> is provided
* Let <code>name</code> be the portion of the URI that represents the name of
the resource; will only be present with <code>req</code> is a PUT
### Outputs ### {#plant-outputs}
* An HTTP response containing a Location header with the URI of the container
that the requested shape trees (<code>linkst</code>) are planted in
### Key Terms for Planting ### {#plant-keyterms}
* Let <code>tc</code> be the <dfn>Target Container</dfn> - The container that
will contain instances of the planted shape tree.
This container may or may not already exist.
* Let <code>pc</code> be the <dfn>Parent Container</dfn> - The container that
will contain the new or existing [=target container=] representing the
planted shape tree. When <code>req</code> is a POST, this will be the
location URL. For PUT, this will be the parent of the PUT container.
### Operation Summary ### {#plant-summary}
<table class="data operationdetails" align="left">
<thead>
<tr>
<th>#</th>
<th>Step</th>
<th colspan="2">Interaction</th>
</tr>
</thead>
<tbody>
<tr>
<td>[1](#plant-details-callhook-beforeplantshapetree)</td>
<td>Call Ecosystem Hook - Before Plant Shape Tree</td>
<td colspan="2">See [Before Plant Shape Tree](#ecosystem-beforeplantshapetree)</td>
</tr>
<tr>
<td>[2](#plant-details-preconditions)</td>
<td>Preconditions:
* Discover Shape Tree(s) for Parent Container (<code>pc</code>)
* Discover Shape Tree(s) for Target Container (<code>tc</code>)
</td>
<td colspan="2">See [Discovery](#discover)</td>
</tr>
<tr>
<td>[3](#plant-static-validation)</td>
<td>Static Validation of Shape Trees for Conflicts</td>
<td colspan="2">N/A - Logic only</td>
</tr>
<tr>
<td>[4](#plant-graphbody-validation)</td>
<td>Validate Graph Body</td>
<td colspan="2">N/A - Logic only</td>
</tr>
<tr>
<td>[5](#plant-parent-validation)</td>
<td>Validate against Parent Container (pc)</td>
<td colspan="2">
See [Validate Proposed Resource](#validate-proposed-resource)
</td>
</tr>
<tr>
<td>[6](#plant-create-container)</td>
<td>Create Target Container (<code>tc</code>), if necessary</td>
<td>[Request](#fig-plant-create-target-request)</td>
<td>[Response](#fig-plant-create-target-response)</td>
</tr>
<tr>
<td>[7](#plant-update-container-metadata)</td>
<td>Update Shape Tree Meta Data for Target Container (<code>tc</code>)</td>
<td colspan="2">
See [Update Container Metadata](#update-container-metadata)
</td>
</tr>
<tr>
<td>[8](#plant-initialize-statics)</td>
<td>Initialize Static Content</td>
<td colspan="2">See [Initialize Static Content](#initialize-statics)</td>
</tr>
<tr>
<td>[9](#plant-details-callhook-indexshapetree)</td>
<td>Call Ecosystem Hook - Index Shape Tree</td>
<td colspan="2">See [Index Shape Tree](#ecosystem-indexshapetree)</td>
</tr>
</tbody>
</table>
### Operation Details ### {#plant-details}
#### Call Ecosystem Hook - Before Plant Shape Tree #### {#plant-details-callhook-beforeplantshapetree}
Note: This step <em class="rfc2119">SHOULD</em> be performed by
a client-side agent.
Call the provided [=ecosystem=]'s [Before Plant Shape Tree operation](#ecosystem-beforeplantshapetree) with parameters:
<table class="data algorithmparams" align="left">
<thead>
<tr>
<td><b>Parameter</b></td>
<td><b>Value</b></td>
<td><b>Notes</b></td>
</tr>
</thead>
<tbody>
<tr>
<td><code>targetContainer</code></td>
<td><code>tc</code></td>
<td>
The [=target container=] that will contain instance data of the
[=shape tree=]
</td>
</tr>
<tr>
<td><code>bodyGraph</code></td>
<td>
[=Body Graph=] of <code>req</code>
</td>
<td>RDF body graph from request</td>
</tr>
<tr>
<td><code>shapeTreesToPlant</code></td>
<td><code>linkst</code></td>
<td>
Link header with the relation of
"http://shapetrees.org/#TargetShapeTree"
</td>
</tr>
<tr>
<td><code>linkHeaders</code></td>
<td>Link headers of <code>req</code></td>
<td>All link headers from request</td>
</tr>
</table>
#### Preconditions #### {#plant-details-preconditions}
Note: This step <em class="rfc2119">SHOULD</em> be performed by a
client-side agent.
1. Ensure the [=Parent Container=] (<code>pc</code>) exists. If not, this
operation <em class="rfc2119">MUST</em> return a 404 status code.
1. [Discover](#discover) any planted [=shape tree=] IRIs managing <code>pc</code>.
1. Let <code>parentst</code> be the collection of dereferenced shape tree
IRIs discovered for <code>pc</code>
1. If the [=Target Container=] (<code>tc</code>) already exists,
[discover](#discover) any previously planted shape tree IRIs.
1. Collect any existing shape tree IRIs and combine with the IRIs of the
<code>linkst</code> provided via the request Link header to represent
the full collection of existing and proposed shape trees for <code>tc</code>.
1. Let <code>allst</code> be the collection of dereferenced shape tree IRIs
representing both existing and <code>linkst</code> IRIs
#### Static Validation of Shape Trees for Conflicts #### {#plant-static-validation}
Note: This step <em class="rfc2119">MAY</em> be performed by either a
client or server side agent.
1. Iterate <code>allst</code> to validate that none of the following conditions
are met:
* any shape tree has a <code class="vocab">st:expectsResourceType</code>
with a value other than <code class="vocab">st:ShapeTreeContainer</code>
* more than one shape tree has a <code class="vocab">st:validatedBy</code> value
* more than one shape tree has a <code class="vocab">st:contains</code> value
If any of the above static validations fail, this operation
<em class="rfc2119">MUST</em> return a 400 status code.
#### Validate graph body #### {#plant-graphbody-validation}
Note: This step <em class="rfc2119">MAY</em> be performed by either a
client or server side agent.
Issue: Must detail how to differentiate between ShEx and SHACL validation
1. Let <code>vst</code> be the validating shape tree that is identified by the
only [=shape tree=] in <code>allst</code> having a
<code class="vocab">st:validatedBy</code> value
1. If <code>vst</code> is present and the plant operation (<code>req</code>)
includes an RDF graph body and ShEx validation is used and a [=Focus Node=]
(<code>linkfn</code>) is not present, this operation
<em class="rfc2119">MUST</em> return a 422 status code
1. Perform a validation of the RDF graph body of <code>req</code> using the
<code>vst</code> <code class="vocab">st:validatedBy</code> shape,
targeting the graph's <code>linkfn</code>. If validation fails, this
operation <em class="rfc2119">MUST</em> return a 422 status code
#### Validate against parent container #### {#plant-parent-validation}
Note: This step <em class="rfc2119">MAY</em> be performed by either a
client or server side agent.
1. Determine if the [=Parent Container=] (<code>pc</code>) is a
[=Managed Container=] by evaluating if <code>parentst</code> is not empty
2. If <code>pc</code> is a [=Managed Container=] call the
[validate proposed resource](#validate-proposed-resource) algorithm with
parameters:
<table class="data algorithmparams" align="left">
<thead>
<tr>
<td><b>Parameter</b></td>
<td><b>Value</b></td>
<td><b>Notes</b></td>
</tr>
</thead>
<tbody>
<tr>
<td><code>uri</code></td>
<td><code>pc</code></td>
<td>
The [=parent container=] that will contain the [=target container=]
</td>
</tr>
<tr>
<td><code>rn</code></td>
<td>
If <code>req</code> is a POST then <code>slug</code><br/>
If <code>req</code> is a PUT then <code>name</code>
</td>
<td>The name of the resource</td>
</tr>
<tr>
<td><code>sth</code></td>
<td><code>linktst</code></td>
<td>
Link header with the relation of
"http://shapetrees.org/#TargetShapeTree"
</td>
</tr>
<tr>
<td><code>rt</code></td>
<td><code class="vocab">st:ShapeTreeContainer</code></td>
<td>The resource type being created/modified</td>
</tr>
</table>
#### Create Target Container (<code>tc</code>), if necessary #### {#plant-create-container}
Note: This step <em class="rfc2119">MAY</em> be performed by either a
client or server side agent.
1. If <code>tc</code> does not exist, create it.
<figure id="fig-plant-create-target-request">
<figcaption>Create Target Container - Request</figcaption>
<pre highlight="http">
POST /<b><i><pc></b></i>/
Slug: <b><i><tc></b></i>;
Link: <http://www.w3.org/ns/ldp#BasicContainer>; rel="type"
</pre>
</figure>
<figure id="fig-plant-create-target-response">
<figcaption>Create Target Container - Response</figcaption>
<pre highlight="http">
HTTP 201 CREATED
Location: http://pod.example/<b><i><pc></b></i>/<b><i><tc></b></i>/
Content-type: text/turtle; charset=utf-8
Content-length: 396
</pre>
</figure>
#### Update Shape Tree Meta Data for Target Container (<code>tc</code>) #### {#plant-update-container-metadata}
Note: This step <em class="rfc2119">MAY</em> be performed by either a
client or server side agent.
1. Update Target Container <code>tc</code> Metadata (<code>metauri</code>)
1. Iterate the collection of shape trees to be planted (<code>linkst</code>),
let <code>linksti</code> be the current shape tree in context.
1. Call algorithm [Update Container Metadata](#update-container-metadata) with
parameters:
<table class="data algorithmparams" align="left">
<thead>
<tr>
<td><b>Parameter</b></td>
<td><b>Value</b></td>
<td><b>Notes</td>
</tr>
</thead>
<tbody>
<tr>
<td><code>tc</code></td>
<td><code>tc</code></td>
<td>
The [=target container=] to that will contain instance data of the
[=shape tree=]
</td>
</tr>
<tr>
<td><code>rootst</code></td>
<td><code>linksti</code></td>
<td>The root [=shape tree=] at the top of the hierarchy</td>
</tr>
<tr>
<td><code>st</code></td>
<td><code>linksti</code></td>
<td>The [=shape tree=] managing the [=target container=]</td>
</tr>
<tr>
<td><code>rootpath</code></td>
<td><code>tc</code></td>
<td>
The [=target container=] to that will contain instance data of the
[=shape tree=]
</td>
</tr>
</table>
#### Initialize Static Content #### {#plant-initialize-statics}
Note: This step <em class="rfc2119">MAY</em> be performed by either
a client or server side agent.
1. Let <code>cst</code> be the shape tree having a
<code class="vocab">st:contains</code> value (if one exists) from the
list of shape trees that were planted <code>linkst</code>
1. Iterate any <code class="vocab">st:contains</code> IRIs within
<code>cst</code>, letting <code>csti</code> be the current IRI in context
1. Let <code>cstist</code> be the shape tree resulting in dereferencing IRI
<code>csti</code>
1. If <code>cstist</code> has a <code class="vocab">rdfs:label</code> value,
let <code>label</code> be the value of rdfs:label for <code>cstist</code>,
and call algorithm
[Initialize Statics](#initialize-statics) with parameters:
<table class="data algorithmparams" align="left">
<thead>
<tr>
<td><b>Parameter</b></td>
<td><b>Value</b></td>
<td><b>Notes</td>
</tr>
</thead>
<tbody>
<tr>
<td><code>pc</code></td>
<td><code>tc</code></td>
<td>
The [=target container=] to that will contain instance data of the
[=shape tree=]
</td>
</tr>
<tr>
<td><code>sst</code></td>
<td><code>cstist</code></td>
<td>The matching contained [=shape tree=]</td>
</tr>
<tr>
<td><code>rst</code></td>
<td><code>cst</code></td>
<td>The [=shape tree=] containing a <code class="vocab">st:container</code>
</tr>
<tr>
<td><code>rc</code></td>
<td><code>tc</code></td>
<td>
The [=target container=] to that will contain instance data of the
[=shape tree=]
</td>
</tr>
</table>
#### Call Ecosystem Hook - Index Shape Tree #### {#plant-details-callhook-indexshapetree}
Note: This step <em class="rfc2119">SHOULD</em> be performed by a
client-side agent.
1. Iterate the collection of shape trees that were planted (<code>linkst</code>),
letting <code>linksti</code> be the current IRI in context
1. Call the provided [=ecosystem=]'s
[Index Shape Tree operation](#ecosystem-indexshapetree) with parameters:
<table class="data algorithmparams" align="left">
<thead>
<tr>
<td><b>Parameter</b></td>
<td><b>Value</b></td>
<td><b>Notes</td>
</tr>
</thead>
<tbody>
<tr>
<td><code>parentContainer</code></td>
<td><code>pc</code></td>
<td>
The [=parent container=] that will contain the [=target container=]
</td>
</tr>
<tr>
<td><code>shapeTree</code></td>
<td><code>linksti</code></td>
<td>The [=shape tree=] managing the [=target container=]</td>
</tr>
<tr>
<td><code>targetContainer</code></td>
<td><code>tc</code></td>
<td>
The [=target container=] that will contain instance data of the
[=shape tree=]
</td>
</tr>
</table>
## Create Data Instance ## {#create-data-instance}
The <b>create data instance</b> operation creates an instance of a shape
tree within a managed container.
### Inputs ### {#create-data-instance-inputs}
* Let <code>req</code> be a POST or PUT HTTP request with the following
characteristics:
* Let <code>linkfn</code> be an <em class="rfc2119">OPTIONAL</em>
Link header with the relation of "http://shapetrees.org/#FocusNode".
This represents the target subject within the request body
(used for ShEx validation, etc.)
* Let <code>linktst</code> be an <em class="rfc2119">OPTIONAL</em> Link
header with the relation of "http://shapetrees.org/#TargetShapeTree"
* Let <code>slug</code> be a Slug header, <em class="rfc2119">REQUIRED</em>
when <code>req</code> is a POST and no <code>linktst</code> is provided
* Let <code>name</code> be a portion of the URI that represents the name of
the resource. This will only be present when <code>req</code> is a PUT
### Outputs ### {#create-data-instance-outputs}
* Standard HTTP response
### Key Terms for Creating Data Instances ### {#create-data-instance-terms}
* Let <code>pc</code> be the [=Parent Container=]
### Operation Summary ### {#create-data-instance-summary}
<table class="data operationdetails" align="left">
<thead>
<tr>
<th>#</th>
<th>Step</th>
<th colspan="2">Interaction</th>
</tr>
</thead>
<tbody>
<tr>
<td>[1](#create-data-instance-details-preconditions)</td>
<td>Discover Shape Tree(s) for Target Container (<code>tc</code>)
</td>
<td colspan="2">See [Discovery](#discover)</td>
</tr>
<tr>
<td>[2](#create-data-instance-details-parent-validation)</td>
<td>Validate against parent container</td>
<td colspan="2">
See [Validate Proposed Resource](#validate-proposed-resource)
</td>
</tr>
<tr>
<td>[3](#create-data-instance-details-create-resource)</td>
<td>Create Proposed Resource</td>
<td colspan="2"></td>
</tr>
<tr>
<td>[4](#create-data-instance-details-initialize-statics)</td>
<td>Initialize Static Content</td>
<td colspan="2">See [Initialize Static Content](#initialize-statics)</td>
</tr>
<tr>
<td>
[5](#create-data-instance-details-callhook-indexshapetreedatainstance)
</td>
<td>Call Ecosystem Hook - Index Shape Tree Data Instance</td>
<td colspan="2">
See [Index Shape Tree Data Instance](#ecosystem-indexshapetreedatainstance)
</td>
</tr>
</tbody>
</table>
### Operation Details ### {#create-data-instance-details}
#### Preconditions #### {#create-data-instance-details-preconditions}
Note: This step <em class="rfc2119">SHOULD</em> be performed by a
client-side agent.
1. Ensure the [=Parent Container=] (<code>pc</code>) exists. If not, return
this operation <em class="rfc2119">MUST</em> return a 404 status code.
1. [Discover](#discover) any planted shape tree IRIs managing <code>pc</code>.
1. Let <code>parentst</code> be the collection of dereferenced shape tree IRIs
discovered for <code>pc</code>
#### Validate against parent container #### {#create-data-instance-details-parent-validation}
Note: This step <em class="rfc2119">MAY</em> be performed by either a
client or server side agent.
1. Determine if the [=Parent Container=] (<code>pc</code>) is a
[=Managed Container=] by evaluating if <code>parentst</code> is not empty
2. If <code>pc</code> is a [=Managed Container=] call the
[validate proposed resource](#validate-proposed-resource) algorithm
with parameters:
<table class="data algorithmparams" align="left">
<thead>
<tr>
<td><b>Parameter</b></td>
<td><b>Value</b></td>
<td><b>Notes</b></td>
</tr>
</thead>
<tbody>
<tr>
<td><code>uri</code></td>
<td><code>pc</code></td>
<td>
The [=parent container=] to that will contain the [=target container=]
</td>
</tr>
<tr>
<td><code>rn</code></td>
<td>
If <code>req</code> is a POST then <code>slug</code><br/>
If <code>req</code> is a PUT then <code>name</code>
</td>
<td>The name of the resource</td>
</tr>
<tr>
<td><code>sth</code></td>
<td><code>linktst</code></td>
<td>The [=shape tree=] managing the [=target container=]</td>
</tr>
<tr>
<td><code>rt</code></td>
<td>
<code class="vocab">st:ShapeTreeContainer</code> or
<code class="vocab">st:ShapeTreeResource</code> or
<code class="vocab">st:ShapeTreeNonRDFResource</code>
</td>
<td>The resource type being created</td>
</tr>
</table>
#### Create Resource #### {#create-data-instance-details-create-resource}
Note: This step <em class="rfc2119">MAY</em> be performed by either a
client or server side agent.
#### Initialize Static Content #### {#create-data-instance-details-initialize-statics}
Note: This step <em class="rfc2119">MAY</em> be performed by either a
client or server side agent.
1. Iterate any <code class="vocab">st:contains</code> IRIs within
<code>mcst</code>, letting <code>csti</code> be the current IRI in context
1. Let <code>cstist</code> be the [=shape tree=] resulting in dereferencing IRI
<code>csti</code>
1. If <code>cstist</code> has a <code class="vocab">rdfs:label</code> value,
let <code>label</code> be the value of
<code class="vocab">rdfs:label</code> for <code>cstist</code>, and
call algorithm [Initialize Statics](#initialize-statics) with parameters:
<table class="data algorithmparams" align="left">
<thead>
<tr>
<td><b>Parameter</b></td>
<td><b>Value</b></td>
<td><b>Note</b></td>
</tr>
</thead>
<tbody>
<tr>
<td><code>pc</code></td>
<td><code>tc</code></td>