-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.html
More file actions
1612 lines (1354 loc) · 76.3 KB
/
tutorial.html
File metadata and controls
1612 lines (1354 loc) · 76.3 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tutorial — WREN</title>
<meta name="description" content="A hands-on guide to WREN: collections, versioning, labels, schemas, binary assets, trees, API keys, collaborators, permissions, and the CLI." />
<link rel="stylesheet" href="/styles.css" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="alternate icon" href="/favicon.ico" />
<link rel="manifest" href="/site.webmanifest" />
<meta name="theme-color" content="#4338ca" />
<style>
.tutorial-screenshot {
display: block;
width: 100%;
border-radius: 8px;
border: 1px solid #e2e8f0;
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
margin: 1.25rem 0 1.75rem;
}
.tutorial-layout {
display: grid;
grid-template-columns: 230px 1fr;
gap: 0;
max-width: var(--container-max);
margin: 0 auto;
padding: var(--nav-height) 24px 0;
min-height: calc(100vh - var(--nav-height));
}
.tutorial-toc {
position: sticky;
top: calc(var(--nav-height) + 24px);
align-self: start;
padding: 32px 24px 32px 0;
font-size: 14px;
max-height: calc(100vh - var(--nav-height) - 48px);
overflow-y: auto;
}
.tutorial-toc__title {
font-size: 11px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--color-muted);
margin-bottom: 12px;
}
.tutorial-toc__list {
list-style: none;
display: flex;
flex-direction: column;
gap: 2px;
}
.tutorial-toc__list a {
display: block;
padding: 5px 8px;
border-radius: var(--radius-sm);
color: var(--color-muted);
font-size: 13px;
transition: background 0.1s, color 0.1s;
}
.tutorial-toc__list a:hover {
background: var(--color-bg-subtle);
color: var(--color-text);
}
.tutorial-toc__sub {
padding-left: 14px;
}
.tutorial-body {
padding: 48px 0 80px 40px;
border-left: 1px solid var(--color-border);
min-width: 0;
}
.tutorial-body h1 {
font-size: 36px;
font-weight: 800;
line-height: 1.2;
margin-bottom: 12px;
}
.tutorial-body .lead {
font-size: 18px;
color: var(--color-muted);
margin-bottom: 48px;
max-width: 600px;
}
.tutorial-section {
margin-bottom: 56px;
}
.tutorial-section h2 {
font-size: 24px;
font-weight: 700;
margin-bottom: 8px;
padding-top: 8px;
color: var(--color-text);
display: flex;
align-items: center;
gap: 10px;
}
.step-badge {
display: inline-flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
border-radius: 50%;
background: var(--color-primary);
color: #fff;
font-size: 13px;
font-weight: 700;
flex-shrink: 0;
}
.tutorial-section h3 {
font-size: 16px;
font-weight: 600;
margin: 28px 0 8px;
color: var(--color-text);
}
.tutorial-section p {
color: var(--color-muted);
margin-bottom: 16px;
max-width: 680px;
line-height: 1.7;
}
.tutorial-section ul, .tutorial-section ol {
color: var(--color-muted);
margin: 0 0 16px 20px;
line-height: 1.8;
max-width: 680px;
}
.tutorial-section ul li code,
.tutorial-section ol li code,
.tutorial-section p code {
font-family: var(--font-mono);
font-size: 0.85em;
background: var(--color-bg-subtle);
border: 1px solid var(--color-border);
border-radius: 3px;
padding: 1px 5px;
color: var(--color-primary-dark);
}
.tutorial-divider {
border: none;
border-top: 1px solid var(--color-border);
margin: 48px 0;
}
/* paired UI + CLI layout */
.paired {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
margin: 16px 0 24px;
max-width: 840px;
}
.paired--wide {
grid-template-columns: 1fr;
max-width: 680px;
}
@media (max-width: 900px) {
.paired { grid-template-columns: 1fr; }
}
.code-block {
background: var(--color-code-bg);
border-radius: var(--radius-md);
overflow: hidden;
font-size: 13px;
}
.code-block__header {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 14px;
border-bottom: 1px solid rgba(255,255,255,0.07);
}
.code-block__lang {
font-family: var(--font-mono);
font-size: 11px;
color: rgba(255,255,255,0.4);
text-transform: uppercase;
letter-spacing: 0.06em;
}
.code-block__label {
font-size: 12px;
color: rgba(255,255,255,0.45);
margin-left: auto;
font-weight: 600;
}
.code-block pre {
padding: 14px 16px;
overflow-x: auto;
line-height: 1.65;
color: #e2e8f0;
margin: 0;
}
.callout {
border-radius: var(--radius-md);
padding: 14px 16px;
margin: 20px 0;
font-size: 14px;
max-width: 680px;
line-height: 1.6;
}
.callout--tip {
background: #eff6ff;
border-left: 3px solid var(--color-primary);
color: #1e40af;
}
.callout--info {
background: #f0fdf4;
border-left: 3px solid var(--color-success);
color: #065f46;
}
.callout--warn {
background: #fefce8;
border-left: 3px solid #eab308;
color: #713f12;
}
.callout strong { font-weight: 700; }
.callout code {
font-family: var(--font-mono);
font-size: 0.85em;
background: rgba(0,0,0,0.08);
border-radius: 3px;
padding: 1px 4px;
}
.ui-hint {
display: flex;
align-items: flex-start;
gap: 10px;
background: var(--color-bg-subtle);
border: 1px solid var(--color-border);
border-radius: var(--radius-md);
padding: 12px 16px;
margin: 12px 0 20px;
font-size: 13px;
color: var(--color-muted);
max-width: 680px;
line-height: 1.6;
}
.ui-hint strong { color: var(--color-text); }
.ui-hint__icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.steps-inline {
list-style: none;
margin: 0 0 20px;
padding: 0;
max-width: 680px;
display: flex;
flex-direction: column;
gap: 6px;
}
.steps-inline li {
display: flex;
align-items: baseline;
gap: 10px;
font-size: 14px;
color: var(--color-muted);
line-height: 1.6;
}
.steps-inline li .n {
display: inline-flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
border-radius: 50%;
background: var(--color-border);
color: var(--color-text);
font-size: 11px;
font-weight: 700;
flex-shrink: 0;
}
@media (max-width: 768px) {
.tutorial-layout { grid-template-columns: 1fr; overflow-x: hidden; padding-left: 16px; padding-right: 16px; }
.tutorial-toc { display: none; }
.tutorial-body { border-left: none; padding-left: 0; }
.tutorial-screenshot { width: 100%; height: auto; }
.paired { grid-template-columns: 1fr; }
pre { font-size: 12px; }
}
</style>
</head>
<body>
<nav class="nav">
<div class="nav__inner">
<a href="/" class="nav__logo"><img src="/wren-logo.svg" alt="WREN" class="nav__logo-img" />WREN</a>
<ul class="nav__links">
<li><a href="/tutorial" style="color:var(--color-primary);font-weight:600">Tutorial</a></li>
<li><a href="/docs">Docs</a></li>
<li><a href="/#clients">Libraries</a></li>
<li><a href="/#pricing">Pricing</a></li>
<li><a href="/projects">Projects</a></li>
<li><a href="/admin">Admin</a></li>
</ul><button class="nav__hamburger" onclick="document.querySelector('.nav__links').classList.toggle('open')" aria-label="Menu"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 12h18M3 6h18M3 18h18"/></svg></button>
</div>
</nav>
<div class="tutorial-layout">
<aside class="tutorial-toc">
<p class="tutorial-toc__title">On this page</p>
<ul class="tutorial-toc__list">
<li><a href="#getting-started">1. Getting started</a></li>
<li class="tutorial-toc__sub"><a href="#login">Login & account</a></li>
<li class="tutorial-toc__sub"><a href="#org">Organisations</a></li>
<li><a href="#building-blocks">2. Three building blocks</a></li>
<li class="tutorial-toc__sub"><a href="#bb-docs">Documents</a></li>
<li class="tutorial-toc__sub"><a href="#bb-versions">Versions</a></li>
<li class="tutorial-toc__sub"><a href="#bb-trees">Trees</a></li>
<li><a href="#collections">3. Collections & documents</a></li>
<li class="tutorial-toc__sub"><a href="#create-col">Create a collection</a></li>
<li class="tutorial-toc__sub"><a href="#create-doc">Create a document</a></li>
<li class="tutorial-toc__sub"><a href="#read-doc">Read & list</a></li>
<li class="tutorial-toc__sub"><a href="#update-doc">Update a document</a></li>
<li class="tutorial-toc__sub"><a href="#delete-doc">Delete a document</a></li>
<li class="tutorial-toc__sub"><a href="#natural-key">Natural keys & upsert</a></li>
<li><a href="#binary">4. Binary assets</a></li>
<li class="tutorial-toc__sub"><a href="#binary-upload">Upload</a></li>
<li class="tutorial-toc__sub"><a href="#binary-replace">Replace & download</a></li>
<li><a href="#versioning">5. Versioning</a></li>
<li class="tutorial-toc__sub"><a href="#history">View history</a></li>
<li class="tutorial-toc__sub"><a href="#diff">Diff versions</a></li>
<li class="tutorial-toc__sub"><a href="#rollback">Rollback</a></li>
<li><a href="#labels">6. Labels</a></li>
<li><a href="#schemas">7. JSON Schemas</a></li>
<li class="tutorial-toc__sub"><a href="#schema-set">Set a schema</a></li>
<li class="tutorial-toc__sub"><a href="#display-name">Display name rules</a></li>
<li class="tutorial-toc__sub"><a href="#schema-grandfathering">Changing a schema</a></li>
<li class="tutorial-toc__sub"><a href="#schema-validate">Dry-run validation</a></li>
<li><a href="#trees">8. Trees</a></li>
<li class="tutorial-toc__sub"><a href="#tree-browse">Browse a tree</a></li>
<li class="tutorial-toc__sub"><a href="#tree-assign">Assign documents</a></li>
<li class="tutorial-toc__sub"><a href="#tree-paths">Paths tab</a></li>
<li><a href="#apikeys">9. API keys</a></li>
<li><a href="#collab">10. Collaborators & orgs</a></li>
<li class="tutorial-toc__sub"><a href="#invite">Invite a collaborator</a></li>
<li class="tutorial-toc__sub"><a href="#accept">Accept an invite</a></li>
<li><a href="#permissions">11. Permissions</a></li>
<li><a href="#cli">12. CLI reference</a></li>
<li><a href="#clients">13. Client libraries</a></li>
<li class="tutorial-toc__sub"><a href="#clients-ts">TypeScript / Node / Bun</a></li>
<li class="tutorial-toc__sub"><a href="#clients-py">Python</a></li>
</ul>
</aside>
<main class="tutorial-body">
<h1>WREN Tutorial</h1>
<p class="lead">Three building blocks — documents, versions, and trees — and everything built on top of them: labels, schemas, binary assets, API keys, collaborators, and permissions. A complete walkthrough of the Admin UI and CLI.</p>
<div class="callout callout--tip">
<strong>Focused on trees?</strong> If you’re using WREN primarily as hierarchical storage — events, catalogues, taxonomies — the <a href="/tutorial/trees">tree tutorial</a> is a shorter tree-first walkthrough.
</div>
<!-- ─────────────────────────────────────────────────────────── -->
<section class="tutorial-section" id="getting-started">
<h2><span class="step-badge">1</span> Getting started</h2>
<p>WREN runs as a single Docker container backed by Postgres. Start everything with:</p>
<div class="code-block paired--wide">
<div class="code-block__header"><span class="code-block__lang">bash</span></div>
<pre>docker compose up -d
# Admin UI → http://localhost:4000/admin
# API docs → http://localhost:4000/docs</pre>
</div>
<h3 id="login">Login & account</h3>
<p>Open <code>http://localhost:4000/admin</code>. On first visit, sign up with an email and password. Every subsequent visit requires the same credentials. Your session persists across browser refreshes.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren auth login -e you@example.com -p yourpassword
wren auth whoami
wren auth logout</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>POST /api/auth/sign-in/email
{"email":"you@example.com","password":"…"}
GET /api/auth/get-session</pre>
</div>
</div>
<img src="/img/01-login.png" alt="WREN login screen" class="tutorial-screenshot">
<h3 id="org">Organisations</h3>
<p>When you sign up, WREN creates an organisation for you. Every collection, document, and tree belongs to an organisation — data is fully isolated between orgs. If you're a member of multiple orgs, a dropdown in the sidebar lets you switch the active one.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren org current
wren org switch <orgId></pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>GET /api/org
PUT /api/org {"orgId":"<id>"}</pre>
</div>
</div>
</section>
<hr class="tutorial-divider" />
<!-- ─────────────────────────────────────────────────────────── -->
<section class="tutorial-section" id="building-blocks">
<h2><span class="step-badge">2</span> Three building blocks</h2>
<p>Before you dive in, it helps to see the whole shape. WREN is built on three composable primitives. Each one is useful alone, and they all come together in the same API.</p>
<h3 id="bb-docs">Documents (in collections)</h3>
<p>A <strong>document</strong> is a JSON object. Documents live in named <strong>collections</strong> — schema-free by default, or validated by a JSON Schema when you’re ready. Binary assets (images, PDFs, videos) are first-class and live in collections too. Everything in WREN ultimately hangs off a document.</p>
<div class="code-block paired--wide">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>POST /api/v1/events
{ "name": "Masters 2026", "city": "Augusta" }
→ { "id": "abc", "version": 1, ... }</pre>
</div>
<p>Covered in <a href="#collections">section 3</a>, with binary assets in <a href="#binary">section 4</a>.</p>
<h3 id="bb-versions">Versions (and labels)</h3>
<p>Every mutation creates a new <strong>version</strong> — the old data is never overwritten. Roll back, diff any two versions, or pin a <strong>label</strong> like <code>published</code> or <code>draft</code> to serve a specific snapshot. Labels are how you build publish workflows without splitting your data across two collections.</p>
<div class="code-block paired--wide">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>PUT /api/v1/events/abc → version 2
POST /api/v1/events/abc/labels { "label": "published" }
GET /api/v1/events/abc?label=published → served at v2</pre>
</div>
<p>Covered in <a href="#versioning">section 5</a> and <a href="#labels">section 6</a>.</p>
<h3 id="bb-trees">Trees (paths pointing at documents)</h3>
<p>A <strong>tree</strong> is a named hierarchy of <strong>paths</strong>. Each path can point to a document in any collection, be an empty folder, or both. Trees give your data shape — a site map, an event calendar, a product catalogue — and let you fetch a whole branch in one request with <code>?full=true</code>. Combined with public permissions, a tree becomes a zero-config read API at <code>/orgs/{slug}/tree/…</code>.</p>
<div class="code-block paired--wide">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>PUT /api/v1/tree/site/2026/masters { "documentId": "abc" }
GET /api/v1/tree/site?full=true&label=published</pre>
</div>
<p>Covered in <a href="#trees">section 8</a>.</p>
<div class="callout callout--info">
<strong>How they fit together.</strong> Documents store the data, versions keep the history, trees give the structure. You can use any one without the others — a schema-free collection with no labels or trees is a valid WREN app. But when you need them, each layer composes cleanly with the rest.
</div>
</section>
<hr class="tutorial-divider" />
<!-- ─────────────────────────────────────────────────────────── -->
<section class="tutorial-section" id="collections">
<h2><span class="step-badge">3</span> Collections & documents</h2>
<p>A <strong>collection</strong> is a named bucket for JSON documents. Collections are listed in the sidebar with their document counts.</p>
<h3 id="create-col">Create a collection</h3>
<p>Click <strong>New collection</strong> on the Collections page, enter a name (lowercase, letters, numbers, hyphens, underscores), and click <strong>Create</strong>. A default open JSON Schema (<code>{"type":"object","additionalProperties":true}</code>) is created automatically so the collection appears in the schema tab immediately.</p>
<div class="ui-hint">
<span class="ui-hint__icon">💡</span>
You can also create a collection implicitly by posting the first document to it via the API — no schema will be set in that case.
</div>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre># Schema set implicitly on first doc
wren create pages '{"title":"Hello"}'
# Or set schema explicitly first
wren schema set pages '{
"type":"object",
"additionalProperties":true
}'</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>PUT /pages/_schema
{
"collectionType": "json",
"schema": {
"type": "object",
"additionalProperties": true
}
}</pre>
</div>
</div>
<img src="/img/02-collections.png" alt="Collections list in the admin UI" class="tutorial-screenshot">
<h3 id="create-doc">Create a document</h3>
<ol class="steps-inline">
<li><span class="n">1</span> Open a collection from the sidebar.</li>
<li><span class="n">2</span> Click <strong>New document</strong>.</li>
<li><span class="n">3</span> Optionally enter a custom ID (leave blank to auto-generate a UUID).</li>
<li><span class="n">4</span> Paste or type your JSON and click <strong>Create</strong>.</li>
</ol>
<div class="ui-hint">
<span class="ui-hint__icon">🛡️</span>
If the collection has a strict JSON Schema, invalid documents are rejected with a <code>422</code> and a list of field errors.
</div>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren create pages '{"title":"Hello World","published":false}'</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>POST /pages
{"title":"Hello World","published":false}
→ {"id":"abc123","version":1,"data":{…}}</pre>
</div>
</div>
<img src="/img/03-document-list.png" alt="Document list for the articles collection" class="tutorial-screenshot">
<h3 id="read-doc">Read & list</h3>
<p>The collection page shows all documents in a table. If a <strong>display name rule</strong> is set (e.g. <code>{title}</code>), the human-readable name appears in the first column instead of the raw ID. Click any row to open the document.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren collections
wren list pages
wren list pages --limit=5 --label=published
wren get pages abc123
wren get pages abc123 --label=published</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>GET /collections
GET /pages?limit=20&offset=0
GET /pages?label=published
GET /pages/abc123
GET /pages/abc123?label=published</pre>
</div>
</div>
<img src="/img/04-document-editor.png" alt="Document editor showing JSON content" class="tutorial-screenshot">
<h3 id="update-doc">Update a document</h3>
<p>Open a document and click the <strong>Document</strong> tab. Edit the JSON directly in the textarea and click <strong>Save</strong>. Every save creates a new immutable version — the old data is never overwritten.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren update pages abc123 '{"title":"Hello World","published":true}'</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>PUT /pages/abc123
{"title":"Hello World","published":true}</pre>
</div>
</div>
<h3 id="delete-doc">Delete a document</h3>
<p>Click the red <strong>Delete</strong> button on the document page. The button requires a confirmation click. Deletion is a soft-delete — the document is hidden but its versions remain in the database.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren delete pages abc123</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>DELETE /pages/abc123</pre>
</div>
</div>
<h3 id="natural-key">Natural keys and upsert-by-key</h3>
<p>Every document has a UUID, but most content also has a human-readable identifier — a <code>slug</code>, a <code>sku</code>, a <code>path</code>. WREN lets you declare one field as the collection’s <strong>natural key</strong> and then interact with documents by that value instead of the UUID.</p>
<p><strong>Step 1 — declare the key.</strong> Set <code>naturalKey</code> on the collection schema:</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren schema set pages \
'{"type":"object","required":["slug","title"],...}' \
--natural-key=slug</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>PUT /api/v1/pages/_schema
{
"naturalKey": "slug",
"schema": {"type":"object","required":["slug","title"],...}
}</pre>
</div>
</div>
<p><strong>Step 2 — upsert.</strong> <code>PUT /api/v1/pages/by-key/about</code> creates the document if it doesn’t exist, or updates it if it does — in a single transactional call. The 20-line list-then-find-then-put loop in every push script becomes one API call:</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre># First run → 201 (created)
wren upsert pages about \
'{"slug":"about","title":"About Us"}'
# Second run → 200 (updated, version 2)
wren upsert pages about \
'{"slug":"about","title":"About Us (updated)"}'</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>PUT /api/v1/pages/by-key/about
{"slug":"about","title":"About Us"}
→ 201 { "id": "abc", "version": 1, "naturalKey": "about", ... }
PUT /api/v1/pages/by-key/about
{"slug":"about","title":"About Us (updated)"}
→ 200 { "id": "abc", "version": 2, ... }</pre>
</div>
</div>
<p><strong>Step 3 — read and delete by key.</strong></p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren get-by-key pages about
wren delete-by-key pages about</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>GET /api/v1/pages/by-key/about
DELETE /api/v1/pages/by-key/about</pre>
</div>
</div>
<div class="callout callout--tip">
<strong>How keys auto-sync.</strong> The natural key is stored as a column on the document and updated on every write. If you rename <code>data.slug</code> from <code>"about"</code> to <code>"about-us"</code> via a regular PUT, the column moves too — the document is now addressable at <code>/by-key/about-us</code> and the old key is released.
</div>
<div class="callout callout--warn">
<strong>Uniqueness is enforced.</strong> Two documents in the same collection cannot share a key. WREN returns <code>409 Conflict</code> if a collision is detected. Deleted documents release their key slot (they’re excluded from the unique index), so you can recreate at the same key after deletion.
</div>
<p>Public reads also work via the org slug: <code>GET /api/v1/orgs/{slug}/pages/by-key/about</code> (or the short alias <code>/orgs/{slug}/pages/by-key/about</code>), gated by the usual <code>principal=*</code> read rule on the collection.</p>
</section>
<hr class="tutorial-divider" />
<!-- ─────────────────────────────────────────────────────────── -->
<section class="tutorial-section" id="binary">
<h2><span class="step-badge">4</span> Binary assets</h2>
<p>Collections can store binary files (images, videos, PDFs, etc.) instead of JSON. Set <strong>Collection type</strong> to <em>Binary assets</em> in the Schema tab to enable this mode.</p>
<h3 id="binary-upload">Upload a file</h3>
<ol class="steps-inline">
<li><span class="n">1</span> Open a binary collection.</li>
<li><span class="n">2</span> Click <strong>Upload file</strong>.</li>
<li><span class="n">3</span> Choose a file and click <strong>Upload</strong>. The filename, MIME type, and size are stored automatically.</li>
</ol>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren upload images ./photo.jpg</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>POST /images (multipart/form-data, field: file)
→ {"id":"xyz","version":1,"data":{
"filename":"photo.jpg",
"mimeType":"image/jpeg",
"size":204800
}}</pre>
</div>
</div>
<h3 id="binary-replace">Replace & download</h3>
<p>Open a binary asset to see a preview (images, video, audio, and PDFs render inline). Use the <strong>Download</strong> button to save the file, or scroll to <strong>Replace file</strong> to upload a new version while keeping the history.</p>
<p>A <strong>Metadata</strong> card below the file controls shows the document's JSON — system fields like <code>filename</code>, <code>mimeType</code>, and <code>size</code>, plus any custom fields you added. You can edit and save metadata independently of the file.</p>
<p>Every version of a binary asset is independently downloadable via the raw URL.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre># Download current version
wren download images xyz --out ./photo.jpg
# Download a specific version
wren download images xyz --version=2 --out ./photo-v2.jpg
# Upload a new version (replaces content, keeps history)
wren upload-version images xyz ./photo-v2.jpg</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>GET /images/xyz/raw
GET /images/xyz/raw?version=2
PUT /images/xyz (multipart/form-data, field: file)</pre>
</div>
</div>
</section>
<hr class="tutorial-divider" />
<!-- ─────────────────────────────────────────────────────────── -->
<section class="tutorial-section" id="versioning">
<h2><span class="step-badge">5</span> Versioning</h2>
<p>Every mutation — create, update, rollback — produces a new numbered version. Versions start at 1, increment by 1, and are immutable. Nothing is ever deleted from the version history.</p>
<h3 id="history">View history</h3>
<p>Open any document and click the <strong>History</strong> tab. A timeline shows every version, newest first. Click <strong>View</strong> on any entry to expand the raw data for that version.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren versions pages abc123</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>GET /pages/abc123/versions
GET /pages/abc123/versions/2</pre>
</div>
</div>
<img src="/img/05-version-history.png" alt="Version history timeline showing 3 versions" class="tutorial-screenshot">
<h3 id="diff">Diff versions</h3>
<p>In the History tab, click <strong>Compare versions</strong>, pick any two version numbers from the dropdowns, then click <strong>Show diff</strong>. The response shows what changed between them.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren diff pages abc123 --v1=1 --v2=3</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>GET /pages/abc123/diff?v1=1&v2=3</pre>
</div>
</div>
<img src="/img/06-diff.png" alt="Diff view comparing version 1 and version 3" class="tutorial-screenshot">
<h3 id="rollback">Rollback</h3>
<p>Rolling back doesn't erase versions — it creates a <em>new</em> version whose content matches the target. In the History tab, click <strong>Rollback here</strong> on any entry and confirm.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre># Creates v4 = copy of v1's data
wren rollback pages abc123 1</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>POST /pages/abc123/rollback/1</pre>
</div>
</div>
</section>
<hr class="tutorial-divider" />
<!-- ─────────────────────────────────────────────────────────── -->
<section class="tutorial-section" id="labels">
<h2><span class="step-badge">6</span> Labels</h2>
<p>A <strong>label</strong> is a named pointer to a specific version — like a Git tag. Moving a label never changes the underlying versions. Common labels: <code>published</code>, <code>stable</code>, <code>draft</code>.</p>
<img src="/img/07-labels.png" alt="Labels tab with label name field" class="tutorial-screenshot">
<div class="ui-hint">
<span class="ui-hint__icon">🏷️</span>
<div>Open a document → <strong>Labels</strong> tab → type a label name → optionally pick a version from the dropdown → click <strong>Set label</strong>. The label moves to that version; all other versions are untouched.</div>
</div>
<div class="callout callout--info">
<strong>Common pattern:</strong> write new versions freely (drafts, experiments). Only move the <code>published</code> label when you're ready. Readers always fetch by label, so they always get the approved version regardless of how many drafts exist.
</div>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre># Point "published" at the current version
wren label pages abc123 published
# Point "archive" at version 1 specifically
wren label pages abc123 archive --version=1
# Fetch whichever version "published" points to
wren get pages abc123 --label=published
# List documents filtered to a label
wren list pages --label=published</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>POST /pages/abc123/labels
{"label":"published"}
POST /pages/abc123/labels
{"label":"archive","version":1}
GET /pages/abc123?label=published
GET /pages?label=published</pre>
</div>
</div>
</section>
<hr class="tutorial-divider" />
<!-- ─────────────────────────────────────────────────────────── -->
<section class="tutorial-section" id="schemas">
<h2><span class="step-badge">7</span> JSON Schemas</h2>
<p>By default a new collection accepts any JSON object. Attach a <a href="https://json-schema.org/" target="_blank">JSON Schema</a> to enforce a strict shape — every write is validated and rejected with <code>422</code> if it fails.</p>
<h3 id="schema-set">Set a schema</h3>
<ol class="steps-inline">
<li><span class="n">1</span> Open a collection and click the <strong>Schema</strong> tab.</li>
<li><span class="n">2</span> Choose <em>Collection type</em>: <strong>JSON documents</strong> or <strong>Binary assets</strong>.</li>
<li><span class="n">3</span> For JSON collections, optionally set a <strong>Display name rule</strong> (e.g. <code>{title}</code>) and configure <strong>List columns</strong> — type a field name and click <strong>Add</strong>, then drag rows to reorder or click <strong>×</strong> to remove them.</li>
<li><span class="n">4</span> Edit the JSON Schema in the textarea.</li>
<li><span class="n">5</span> Click <strong>Save</strong>. Click <strong>Remove schema</strong> to disable validation entirely.</li>
</ol>
<div class="callout callout--tip">
<strong>Start permissive.</strong> The default open schema (<code>"additionalProperties": true</code>) accepts any object. Tighten it once your shape is stable.
</div>
<div class="code-block paired--wide" style="margin:16px 0 8px">
<div class="code-block__header"><span class="code-block__lang">json</span><span class="code-block__label">Example schema</span></div>
<pre>{
"type": "object",
"required": ["title"],
"properties": {
"title": { "type": "string", "minLength": 1 },
"published": { "type": "boolean" },
"body": { "type": "string" }
},
"additionalProperties": false
}</pre>
</div>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren schema get pages
wren schema set pages '{"type":"object","required":["title"],...}'
wren schema set pages --type=binary # binary collection
wren schema delete pages</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>GET /pages/_schema
PUT /pages/_schema
{"collectionType":"json","schema":{…},"displayName":"{title}"}
DELETE /pages/_schema</pre>
</div>
</div>
<img src="/img/08-schema.png" alt="JSON Schema editor for the articles collection" class="tutorial-screenshot">
<h3 id="display-name">Display name rules</h3>
<p>A <strong>display name rule</strong> is a template that extracts a human-readable name from document data. Set it in the <strong>Display name rule</strong> field on the Schema tab, for example <code>{title}</code> or <code>{first} {last}</code>. This name is shown in the documents list instead of the raw UUID.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre>wren schema set pages \
'{"type":"object","additionalProperties":true}' \
--display-name="{title}"</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre>PUT /pages/_schema
{
"collectionType": "json",
"displayName": "{title}",
"schema": {"type":"object","additionalProperties":true}
}</pre>
</div>
</div>
<h3 id="schema-grandfathering">Changing a schema on existing data</h3>
<p>WREN does not validate existing documents when you set or change a schema. The rules apply going forward:</p>
<ul>
<li><strong>POST a new document</strong> — validated against the current schema; rejected with <code>422</code> if it fails.</li>
<li><strong>PUT an update</strong> — same. Every write must satisfy the current schema.</li>
<li><strong>Existing documents</strong> — left untouched. If you tighten the schema, already-stored documents that no longer match are <em>grandfathered</em>: they keep working, but you cannot update them without also bringing them into compliance.</li>
<li><strong>Rollback</strong> — writes a new version containing the old data <em>without</em> running validation. This means you can roll a document back to a pre-schema version even after tightening the schema. The next PUT on that document, however, must satisfy the current rules.</li>
<li><strong>Reads</strong> — never validated. Clients always get whatever is stored.</li>
</ul>
<div class="callout callout--warn">
<strong>Migration is manual.</strong> There is no "run the new schema against every existing document" tool yet. If you need every doc to satisfy a stricter shape, you have to walk the collection yourself (list all, for each one: load, transform, PUT back) — and because PUT validates, any doc you miss will fail loudly the next time something tries to update it.
</div>
<div class="callout callout--tip">
<strong>Widen freely, tighten with care.</strong> Adding optional fields or removing <code>required</code> constraints is safe: existing docs still match. Adding new <code>required</code> fields, tightening types, or setting <code>additionalProperties: false</code> are the changes that strand existing data in "readable but not re-writable" purgatory. Test the new schema against a few real documents before shipping it.
</div>
<h3 id="schema-validate">Dry-run: validate existing docs against a schema</h3>
<p>Before tightening a schema, you can ask WREN to run it against every existing document in the collection and report which ones would fail — without actually changing anything. Useful as a pre-flight check, or as a CI gate for schema changes.</p>
<p>Hit <code>GET /api/v1/{collection}/_schema/validate</code> to run the <em>currently-stored</em> schema against every document (useful for spotting grandfathered docs from a previous tightening). Or <code>POST</code> with a schema in the body to dry-run a <em>proposed</em> schema before committing to it.</p>
<div class="paired">
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">bash</span><span class="code-block__label">CLI</span></div>
<pre># Validate against the currently-stored schema
wren schema validate pages
# Validate a proposed schema before saving it
wren schema validate pages '{
"type":"object",
"required":["title","author"],
"properties":{
"title":{"type":"string"},
"author":{"type":"string"}
}
}'
# --json for the raw response (good for piping to jq)
wren schema validate pages --json
# --max / --limit for very large collections
wren schema validate pages --max=50000 --limit=500</pre>
</div>
<div class="code-block">
<div class="code-block__header"><span class="code-block__lang">http</span><span class="code-block__label">REST</span></div>
<pre># Current schema against all existing docs
GET /api/v1/pages/_schema/validate?max=10000&limit=100
# Proposed schema (wrapper form)
POST /api/v1/pages/_schema/validate
{"schema":{"type":"object","required":["title"],...}}</pre>
</div>
</div>
<p>The response reports totals plus up to <code>limit</code> failing documents with their id, current version, and the exact ajv error messages:</p>
<div class="code-block paired--wide" style="margin:16px 0 8px">
<div class="code-block__header"><span class="code-block__lang">json</span><span class="code-block__label">Response</span></div>
<pre>{
"collection": "pages",
"schemaSource": "proposed",
"checked": 150,
"limitReached": false,
"valid": 147,
"invalid": 3,
"failures": [
{ "id": "abc", "version": 5, "errors": ["/author must be string"] },
{ "id": "def", "version": 2, "errors": ["/title must NOT have fewer than 1 characters"] },
{ "id": "ghi", "version": 1, "errors": ["/ must have required property 'author'"] }
],
"failuresTruncated": false
}</pre>
</div>
<div class="callout callout--info">
<strong>Exit codes gate deployments.</strong> <code>wren schema validate</code> exits with status 1 when any documents would fail. So <code>wren schema validate pages && wren schema set pages '…' && deploy.sh</code> is a safe pipeline: the schema only gets set, and the deploy only runs, if every existing document already passes.
</div>
<p>The endpoint is read-only. It requires <code>read</code> access to the collection (anyone who can read the data can dry-run a schema against it); schema <em>changes</em> still require <code>admin</code>. It caps at 50 000 documents per call — for larger collections, <code>limitReached: true</code> in the response tells you there's more to check.</p>
</section>