-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcold_api_deep_dive.html
More file actions
781 lines (781 loc) · 29.8 KB
/
cold_api_deep_dive.html
File metadata and controls
781 lines (781 loc) · 29.8 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
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>cold</title>
<link rel="stylesheet" href="https://caltechlibrary.github.io/css/site.css">
<link rel="stylesheet" href="https://media.library.caltech.edu/cl-webcomponents/css/code-blocks.css">
<script type="module" src="https://media.library.caltech.edu/cl-webcomponents/copyToClipboard.js"></script>
<script type="module" src="https://media.library.caltech.edu/cl-webcomponents/footer-global.js"></script>
</head>
<body>
<header>
<a href="https://library.caltech.edu"><img src="https://media.library.caltech.edu/assets/caltechlibrary-logo.png" alt="Caltech Library logo"></a>
</header>
<a href="#main-content" class="visually-hidden">skip to main content</a>
<nav>
<ul>
<li><a href="/">All Library Apps</a></li>
<li><a href="index.html">Home</a></li>
<li><a href="LICENSE">LICENSE</a></li>
<li><a href="INSTALL.html">INSTALL</a></li>
<li><a href="user_manual.html">User Manual</a></li>
<li><a href="about.html">About</a></li>
<!-- <li><a href="search.html">Search</a></li> -->
<li><a href="https://github.com/caltechlibrary/cold">Code Repository</a></li>
</ul>
</nav>
<section id="main-content">
<h1 id="cold_api.yaml-deep-dive">cold_api.yaml Deep Dive</h1>
<p><code>cold_api.yaml</code> is the configuration file for
<code>datasetd</code>, the JSON API backend that COLD builds on. It is
not read by any TypeScript code — it is consumed entirely by the
<code>datasetd</code> binary. Everything the middleware and browser can
access about stored objects is ultimately controlled by what this file
declares.</p>
<p>Reference documentation for the <code>datasetd</code> configuration
format: - <a
href="https://caltechlibrary.github.io/dataset/datasetd.1.html"
class="uri">https://caltechlibrary.github.io/dataset/datasetd.1.html</a>
- <a href="https://caltechlibrary.github.io/dataset/datasetd_api.5.html"
class="uri">https://caltechlibrary.github.io/dataset/datasetd_api.5.html</a></p>
<hr />
<h2 id="top-level-fields">Top-level fields</h2>
<div class="sourceCode" id="cb1"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">host</span><span class="kw">:</span><span class="at"> localhost:8112</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">collections</span><span class="kw">:</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> ...</span></span></code></pre></div>
<table>
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr>
<th scope="col">Field</th>
<th scope="col">Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>host</code></td>
<td>The TCP address <code>datasetd</code> listens on. The middleware
(<code>cold.ts</code>) defaults its <code>--apiUrl</code> to
<code>http://localhost:8112</code>. They must match.</td>
</tr>
<tr>
<td><code>collections</code></td>
<td>List of dataset collection configurations. Each entry exposes one
<code>.ds</code> directory as a REST resource.</td>
</tr>
</tbody>
</table>
<hr />
<h2 id="collection-block-structure">Collection block structure</h2>
<p>Each item under <code>collections</code> has this shape:</p>
<div class="sourceCode" id="cb2"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">-</span><span class="at"> </span><span class="fu">dataset</span><span class="kw">:</span><span class="at"> <name>.ds</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">query</span><span class="kw">:</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="fu"> <query_name></span><span class="kw">: </span><span class="ch">|</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <SQL></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">keys</span><span class="kw">:</span><span class="at"> true|false</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">create</span><span class="kw">:</span><span class="at"> true|false</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">read</span><span class="kw">:</span><span class="at"> true|false</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">update</span><span class="kw">:</span><span class="at"> true|false</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">versions</span><span class="kw">:</span><span class="at"> true|false</span></span></code></pre></div>
<h3 id="dataset">dataset</h3>
<p>The path to the dataset collection directory, relative to the working
directory where <code>datasetd</code> is started. The collection name
(without <code>.ds</code>) becomes the first segment of every URL path
for that collection: <code>/api/<name>/...</code>.</p>
<h3 id="query">query</h3>
<p>A map of named SQL queries. Each query is a SQLite statement that
operates on the collection’s internal <code>src</code> column, which
holds the JSON object for each record. Results are returned as a JSON
array.</p>
<p>Named queries are exposed at:</p>
<pre><code>GET /api/<collection_name>/_query/<query_name></code></pre>
<p>Parameterized queries use <code>?</code> placeholders. Parameters are
passed as a JSON body or as query-string key-value pairs, depending on
how the caller constructs the request. The middleware’s
<code>browser_api.ts</code> builds query-string calls; internal
TypeScript handlers use the <code>Dataset</code> client from
<code>deps.ts</code>.</p>
<h3 id="crud-permissions">CRUD permissions</h3>
<table>
<thead>
<tr>
<th scope="col">Field</th>
<th scope="col">HTTP method enabled</th>
<th scope="col">datasetd endpoint</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>keys: true</code></td>
<td>GET</td>
<td><code>/api/<name>/keys</code></td>
</tr>
<tr>
<td><code>create: true</code></td>
<td>POST</td>
<td><code>/api/<name>/</code></td>
</tr>
<tr>
<td><code>read: true</code></td>
<td>GET</td>
<td><code>/api/<name>/<key></code></td>
</tr>
<tr>
<td><code>update: true</code></td>
<td>PUT</td>
<td><code>/api/<name>/<key></code></td>
</tr>
</tbody>
</table>
<p>There is no <code>delete</code> permission declared in COLD’s
configuration. Records are never deleted through the API — they are
either versioned or left in place.</p>
<h3 id="versions">versions</h3>
<p>When <code>versions: true</code>, <code>datasetd</code> keeps
previous copies of each object whenever it is updated. This is COLD’s
audit trail. All collections enable versioning.</p>
<hr />
<h2 id="collections-reference">Collections reference</h2>
<h3 id="people.ds">people.ds</h3>
<p>Stores person objects. Each object is keyed by <code>clpid</code>
(Caltech Library People ID).</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
<th scope="col">Used by</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>people_vocabulary</code></td>
<td>none</td>
<td>List of objects shaped for the authors vocabulary:
<code>clpid</code>, <code>family_name</code>, <code>given_name</code>,
<code>identifiers</code> (ORCID if present), <code>affiliations</code>
(Caltech ROR if present)</td>
<td><code>people_vocabulary.ts</code>,
<code>run_people_vocabulary.bash</code></td>
</tr>
<tr>
<td><code>people_names</code></td>
<td>none</td>
<td>Compact list: <code>clpid</code>, <code>family_name</code>,
<code>given_name</code>, <code>orcid</code>, <code>thesis_id</code>,
<code>directory_id</code></td>
<td><code>client_api.ts getPeopleList()</code></td>
</tr>
<tr>
<td><code>missing_bios</code></td>
<td>none</td>
<td>People with a <code>directory_user_id</code> but an empty
<code>bio</code> field</td>
<td>Administrative/debugging</td>
</tr>
<tr>
<td><code>directory_people</code></td>
<td>none</td>
<td>People with a <code>directory_user_id</code> (i.e., current Caltech
directory members)</td>
<td><code>directory_sync.ts</code></td>
</tr>
<tr>
<td><code>people_csv</code></td>
<td>none</td>
<td>Full people export for the CSV report</td>
<td><code>run_people_csv.bash</code> (via
<code>cold_reports</code>)</td>
</tr>
<tr>
<td><code>division_people</code></td>
<td>none</td>
<td>Per-person <code>division</code>, <code>clpid</code>,
<code>orcid</code>, <code>family_name</code>,
<code>given_name</code></td>
<td><code>run_division_people.bash</code></td>
</tr>
<tr>
<td><code>people_membership</code></td>
<td>none</td>
<td>Flattened list: one row per person-per-group membership</td>
<td><code>run_people_membership.bash</code></td>
</tr>
<tr>
<td><code>get_all_clpid</code></td>
<td>none</td>
<td>Ordered list of all <code>clpid</code> strings (for
autocomplete)</td>
<td>Browser UI</td>
</tr>
<tr>
<td><code>validate_clpid</code></td>
<td><code>?</code> (clpid value)</td>
<td>Single-element list <code>{clpid}</code> if found, empty if not</td>
<td>Input validation</td>
</tr>
<tr>
<td><code>lookup_clgid</code></td>
<td><code>?</code> (clgid value)</td>
<td>People who belong to the group with that <code>clgid</code></td>
<td><code>client_api.ts lookupGroupMembership()</code>,
<code>browser_api.ts</code></td>
</tr>
</tbody>
</table>
<p><strong>Notes on <code>people_vocabulary</code>:</strong> The query
uses a <code>CASE</code> expression to include an ORCID identifier only
when <code>length(src->>'orcid') > 1</code>, which guards
against empty strings. Caltech affiliation is included only when the
<code>ror</code> field equals the Caltech ROR
(<code>https://ror.org/05dxps055</code>). These business rules live in
the SQL, not in TypeScript.</p>
<p><strong>Notes on <code>lookup_clgid</code>:</strong> This query uses
a correlated subquery against <code>json_each(src, '$.groups')</code> to
find all people whose <code>groups</code> array contains the requested
<code>clgid</code>. The <code>?</code> placeholder is bound by the
caller.</p>
<hr />
<h3 id="groups.ds">groups.ds</h3>
<p>Stores group objects. Each object is keyed by <code>clgid</code>
(Caltech Library Group ID).</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
<th scope="col">Used by</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>group_vocabulary</code></td>
<td>none</td>
<td>List of <code>{clgid, group_name}</code> sorted by name</td>
<td><code>group_vocabulary.ts</code>,
<code>run_group_vocabulary.bash</code></td>
</tr>
<tr>
<td><code>group_names</code></td>
<td>none</td>
<td>Same shape as <code>group_vocabulary</code> (duplicate, retained for
compatibility)</td>
<td><code>client_api.ts getGroupsList()</code></td>
</tr>
<tr>
<td><code>lookup_name</code></td>
<td><code>?</code> (name pattern)</td>
<td>Groups whose <code>name</code> or any <code>alternative</code> name
matches the LIKE pattern</td>
<td><code>client_api.ts lookupGroupName()</code></td>
</tr>
<tr>
<td><code>lookup_name_or_clgid</code></td>
<td><code>?</code>, <code>?</code>, <code>?</code> (name, clgid,
alternative)</td>
<td>Groups matching any of: name, clgid, alternative names</td>
<td><code>utils.ts lookupGroupInfo()</code></td>
</tr>
<tr>
<td><code>get_all_clgid</code></td>
<td>none</td>
<td>Ordered list of all <code>clgid</code> strings (for
autocomplete)</td>
<td>Browser UI</td>
</tr>
</tbody>
</table>
<p><strong>Notes on <code>lookup_name</code> and
<code>lookup_name_or_clgid</code>:</strong> Both use
<code>EXISTS(SELECT true FROM json_each(src->'alternative') WHERE ...)</code>
to search inside the JSON array of alternative names. LIKE patterns
(e.g., <code>%LIGO%</code>) are supplied by callers.
<code>lookup_name_or_clgid</code> takes three <code>?</code> parameters
that are all typically set to the same search string.</p>
<hr />
<h3 id="funders.ds">funders.ds</h3>
<p>Stores funder objects. Each object is keyed by <code>clfid</code>
(Caltech Library Funder ID).</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
<th scope="col">Used by</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>funder_names</code></td>
<td>none</td>
<td>List of <code>{clfid, name, ror}</code> sorted by name</td>
<td>Funder autocomplete</td>
</tr>
</tbody>
</table>
<hr />
<h3 id="subjects.ds">subjects.ds</h3>
<p>Stores subject classification objects. Each object is keyed by
<code>clsid</code>.</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
<th scope="col">Used by</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>subject_names</code></td>
<td>none</td>
<td>List of <code>{clsid, name}</code> sorted by name</td>
<td>Subject autocomplete</td>
</tr>
</tbody>
</table>
<hr />
<h3 id="thesis_options.ds">thesis_options.ds</h3>
<p>Stores thesis option objects (degree program options). Each object is
keyed by <code>option_id</code>.</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
<th scope="col">Used by</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>thesis_option_names</code></td>
<td>none</td>
<td>List of <code>{option_id, name, division}</code> sorted by name</td>
<td><code>thesis_option_vocabulary.ts</code>, thesis autocomplete</td>
</tr>
</tbody>
</table>
<hr />
<h3 id="journals.ds">journals.ds</h3>
<p>Stores journal metadata. Each object is keyed by ISSN.</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
<th scope="col">Used by</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>journal_names</code></td>
<td>none</td>
<td>List of <code>{issn, name}</code> sorted by name</td>
<td><code>journal_vocabulary.ts</code>, journal autocomplete</td>
</tr>
</tbody>
</table>
<hr />
<h3 id="doi_prefix.ds">doi_prefix.ds</h3>
<p>Stores DOI prefix records. Each object is keyed by DOI prefix
string.</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
<th scope="col">Used by</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>doi_prefix_names</code></td>
<td>none</td>
<td>List of <code>{doi_prefix, name}</code> sorted by name</td>
<td>DOI prefix autocomplete</td>
</tr>
</tbody>
</table>
<hr />
<h3 id="reports.ds">reports.ds</h3>
<p>This collection is the report request queue — the integration point
between the middleware and the <code>cold_reports</code> service.
Objects are keyed by a UUID v5 generated from the report request content
plus a timestamp.</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
<th scope="col">Used by</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>report_list</code></td>
<td>none</td>
<td>All report requests ordered by <code>updated</code> descending
(stack view)</td>
<td><code>cold_reports.ts handleReportsList()</code> → renders the
<code>/reports</code> page</td>
</tr>
<tr>
<td><code>next_request</code></td>
<td>none</td>
<td>Oldest report request with <code>status = 'requested'</code> (FIFO
queue)</td>
<td><code>cold_reports.ts servicing_requests()</code></td>
</tr>
</tbody>
</table>
<p><strong><code>report_list</code></strong> omits the
<code>inputs</code> field — it is a summary view for display.
<strong><code>next_request</code></strong> includes <code>inputs</code>
so the runner has the parameter values needed to execute the
command.</p>
<p><strong>Status lifecycle:</strong></p>
<pre><code>"requested" → "processing" → "completed"
→ "error"
→ "aborting, unknown report"</code></pre>
<p>The transition from <code>"requested"</code> to
<code>"processing"</code> is written by <code>cold_reports</code> before
executing the command; the final status is written after the command
returns.</p>
<hr />
<h3 id="ror.ds">ror.ds</h3>
<p>Stores Research Organization Registry (ROR) records imported from a
ROR data dump. Each object is keyed by the ROR identifier suffix (the
part after <code>https://ror.org/</code>).</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
<th scope="col">Used by</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>get_ror</code></td>
<td><code>?</code> (ror key)</td>
<td>Full ROR record for the key</td>
<td><code>client_api.ts getROR()</code></td>
</tr>
<tr>
<td><code>lookup_by_name_or_acronym</code></td>
<td><code>?</code>, <code>?</code> (name pattern, acronym pattern)</td>
<td>List of <code>{ror, name, country, acronyms}</code></td>
<td><code>client_api.ts</code></td>
</tr>
<tr>
<td><code>lookup_by_name</code></td>
<td><code>?</code> (name pattern)</td>
<td>List of <code>{ror, name, country, acronyms}</code></td>
<td>ROR name lookup</td>
</tr>
<tr>
<td><code>lookup_by_acronym</code></td>
<td><code>?</code> (acronym pattern)</td>
<td>List of <code>{ror, name, country, acronyms}</code></td>
<td>ROR acronym lookup</td>
</tr>
<tr>
<td><code>clear_ror_data</code></td>
<td>none</td>
<td>Deletes all ROR records (<code>DELETE FROM ror</code>)</td>
<td><code>ror_import.ts</code> before re-import</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> <code>clear_ror_data</code> is a
<code>DELETE</code> statement. In <code>datasetd</code> this is exposed
as a query endpoint, not a DELETE HTTP method. The
<code>ror_import.ts</code> tool calls it before loading a fresh ROR data
dump.</p>
<hr />
<h3 id="rdm_review_queue.ds">rdm_review_queue.ds</h3>
<p>Stores records from the RDM (Research Data Management) submission
review queue. Records are deposited here from the InvenioRDM system for
curator review.</p>
<p><strong>Named queries:</strong></p>
<table>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr>
<th scope="col">Query</th>
<th scope="col">Parameters</th>
<th scope="col">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>browse</code></td>
<td>none</td>
<td>All records ordered by <code>updated</code> descending</td>
</tr>
<tr>
<td><code>search</code></td>
<td><code>?</code> (text pattern)</td>
<td>Records where the JSON source matches the pattern</td>
</tr>
<tr>
<td><code>by_name</code></td>
<td><code>?</code> (name pattern)</td>
<td>Records where any creator’s <code>person_or_org.name</code>
matches</td>
</tr>
<tr>
<td><code>review_queue_by_name</code></td>
<td><code>?</code> (name pattern)</td>
<td>Same as <code>by_name</code> but filtered to
<code>status = 'submitted'</code></td>
</tr>
<tr>
<td><code>by_clpid</code></td>
<td><code>?</code> (clpid)</td>
<td>Records where any creator has a <code>clpid</code> identifier
matching the value</td>
</tr>
<tr>
<td><code>review_queue_by_clpid</code></td>
<td><code>?</code> (clpid)</td>
<td>Same as <code>by_clpid</code> but filtered to
<code>status = 'submitted'</code></td>
</tr>
<tr>
<td><code>by_orcid</code></td>
<td><code>?</code> (orcid)</td>
<td>Records where any creator has an <code>orcid</code> identifier
matching the value</td>
</tr>
<tr>
<td><code>review_queue_by_orcid</code></td>
<td><code>?</code> (orcid)</td>
<td>Same as <code>by_orcid</code> but filtered to
<code>status = 'submitted'</code></td>
</tr>
<tr>
<td><code>by_clgid</code></td>
<td><code>?</code> (clgid)</td>
<td>Records where <code>custom_fields."caltech:groups"</code> contains
the clgid</td>
</tr>
<tr>
<td><code>review_queue_by_clgid</code></td>
<td><code>?</code> (clgid)</td>
<td>Same as <code>by_clgid</code> but filtered to
<code>status = 'submitted'</code></td>
</tr>
<tr>
<td><code>review_queue_mentions</code></td>
<td><code>?</code> (text pattern)</td>
<td>Submitted records with comments containing the pattern</td>
</tr>
</tbody>
</table>
<p>These queries make heavy use of <code>json_each</code> to search
inside nested JSON arrays (creators, identifiers, groups). The
<code>JOIN</code> between two <code>json_each</code> calls in the
<code>by_clpid</code>/<code>by_orcid</code> family is the pattern to
follow when adding new identifier-based queries.</p>
<hr />
<h2 id="how-the-middleware-consumes-cold_api.yaml">How the middleware
consumes cold_api.yaml</h2>
<h3 id="browser_api.ts-the-read-only-browser-api">browser_api.ts — the
read-only browser API</h3>
<p><code>handleBrowserAPI</code> (called for <code>GET /api/...</code>)
parses the URL path using <code>apiPathParse()</code>:</p>
<pre><code>/api/<c_name>/<query_name>[?key=value&...]</code></pre>
<p>It constructs a <code>DatasetApiClient</code> for the named
collection and calls <code>.query(query_name, paramList, body)</code>.
The result is returned as JSON to the browser. This is how browser-side
TypeScript modules (<code>client_api.ts</code>,
<code>validator.ts</code>, <code>collaborator_report.ts</code>) access
named queries.</p>
<p><strong>Important:</strong> <code>browser_api.ts</code> only handles
<code>GET</code>. All browser queries are read-only. Mutation goes
through the dedicated collection handlers (<code>people.ts</code>,
<code>groups.ts</code>, etc.) which call <code>datasetd</code>’s CRUD
endpoints directly, not through named queries.</p>
<h3 id="collection-handlers-people.ts-groups.ts-etc.">Collection
handlers (people.ts, groups.ts, etc.)</h3>
<p>Each collection has a handler module that uses the
<code>Dataset</code> class from <code>deps.ts</code> to call
<code>datasetd</code>’s CRUD endpoints:</p>
<ul>
<li><code>ds.keys()</code> →
<code>GET /api/<name>/keys</code></li>
<li><code>ds.read(key)</code> →
<code>GET /api/<name>/<key></code></li>
<li><code>ds.create(key, obj)</code> →
<code>POST /api/<name>/</code></li>
<li><code>ds.update(key, obj)</code> →
<code>PUT /api/<name>/<key></code></li>
<li><code>ds.query(name, params, body)</code> →
<code>GET /api/<name>/_query/<name></code></li>
</ul>
<p>These are available only because the corresponding <code>keys</code>,
<code>read</code>, <code>create</code>, <code>update</code> flags are
set to <code>true</code> in <code>cold_api.yaml</code>.</p>
<hr />
<h2 id="debugging-tips">Debugging tips</h2>
<p><strong>Query returns unexpected results:</strong> Run the SQL
directly against the SQLite database inside the <code>.ds</code>
directory:</p>
<div class="sourceCode" id="cb6"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="ex">sqlite3</span> people.ds/collection.db <span class="st">"SELECT json_object(...) FROM people ..."</span></span></code></pre></div>
<p>The <code>src</code> column holds the raw JSON. The table name is the
collection name without <code>.ds</code>.</p>
<p><strong><code>datasetd</code> rejects a request:</strong> Check that
the corresponding permission flag (<code>create</code>,
<code>read</code>, <code>update</code>, <code>keys</code>) is set to
<code>true</code> in <code>cold_api.yaml</code> for that collection.</p>
<p><strong>A new query is not accessible:</strong> After editing
<code>cold_api.yaml</code>, restart <code>datasetd</code>. It reads the
file at startup only.</p>
<p><strong>Parameter mismatch:</strong> If a query uses <code>?</code>
placeholders, the caller must supply exactly the right number of
parameters in the correct order. Mismatch causes a SQLite error that
appears in the <code>datasetd</code> log.</p>
<p><strong>Port conflict:</strong> If the middleware’s
<code>--apiUrl</code> does not match <code>cold_api.yaml</code>’s
<code>host</code>, all API calls will fail with a connection error.
Default is <code>localhost:8112</code> on both sides.</p>
<hr />
<h2 id="adding-a-new-query">Adding a new query</h2>
<ol type="1">
<li>Edit <code>cold_api.yaml</code>. Under the relevant collection’s
<code>query:</code> block, add:</li>
</ol>
<div class="sourceCode" id="cb7"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">my_new_query</span><span class="kw">: </span><span class="ch">|</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> SELECT json_object('field', src->'field') AS src</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> FROM <collection_name></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> WHERE src->>'some_field' = ?</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> ORDER BY src->>'field'</span></code></pre></div>
<ol start="2" type="1">
<li><p>Restart <code>datasetd</code>.</p></li>
<li><p>Test directly:</p></li>
</ol>
<div class="sourceCode" id="cb8"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="ex">curl</span> <span class="st">"http://localhost:8112/api/<collection_name>/_query/my_new_query"</span> <span class="dt">\</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="at">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="dt">\</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="at">-d</span> <span class="st">'{"param": "value"}'</span></span></code></pre></div>
<ol start="4" type="1">
<li>Call it from TypeScript via <code>browser_api.ts</code> at
<code>GET /api/<collection_name>/my_new_query?q=value</code>, or
from a server-side handler via
<code>ds.query("my_new_query", ["param"], {param: "value"})</code>.</li>
</ol>
<hr />
<h2 id="adding-a-new-collection">Adding a new collection</h2>
<ol type="1">
<li>Initialize the dataset collection:</li>
</ol>
<div class="sourceCode" id="cb9"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="ex">dataset</span> init newcollection.ds <span class="st">'sqlite://collection.db'</span></span></code></pre></div>
<ol start="2" type="1">
<li>Add a block to <code>cold_api.yaml</code>:</li>
</ol>
<div class="sourceCode" id="cb10"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="kw">-</span><span class="at"> </span><span class="fu">dataset</span><span class="kw">:</span><span class="at"> newcollection.ds</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">query</span><span class="kw">:</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="fu"> list_all</span><span class="kw">: </span><span class="ch">|</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> SELECT src FROM newcollection ORDER BY src->>'name'</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">keys</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">create</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">read</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">update</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">versions</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span></code></pre></div>
<ol start="3" type="1">
<li><p>Restart <code>datasetd</code>.</p></li>
<li><p>Add a corresponding handler module (e.g.,
<code>newcollection.ts</code>) following the pattern in
<code>people.ts</code> or <code>groups.ts</code>, and wire it into
<code>cold.ts</code>’s <code>ColdReadWriteHandler</code>.</p></li>
</ol>
</section>
<footer-global></footer-global>
</body>
</html>