@extantape/payload-plugin-onephylogeny 0.0.0-stage → 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +75 -0
- package/README.md +90 -2
- package/dist/index.d.ts +334 -0
- package/dist/index.js +810 -0
- package/package.json +56 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Required Notice: Copyright 2026 EXTANT APE (https://github.com/ExtantApe)
|
|
2
|
+
|
|
3
|
+
# PolyForm Noncommercial License 1.0.0
|
|
4
|
+
|
|
5
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
14
|
+
|
|
15
|
+
## Distribution License
|
|
16
|
+
|
|
17
|
+
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
18
|
+
|
|
19
|
+
## Notices
|
|
20
|
+
|
|
21
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
22
|
+
|
|
23
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
24
|
+
|
|
25
|
+
## Changes and New Works License
|
|
26
|
+
|
|
27
|
+
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
28
|
+
|
|
29
|
+
## Patent License
|
|
30
|
+
|
|
31
|
+
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
32
|
+
|
|
33
|
+
## Noncommercial Purposes
|
|
34
|
+
|
|
35
|
+
Any noncommercial purpose is a permitted purpose.
|
|
36
|
+
|
|
37
|
+
## Personal Uses
|
|
38
|
+
|
|
39
|
+
Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
|
|
40
|
+
|
|
41
|
+
## Noncommercial Organizations
|
|
42
|
+
|
|
43
|
+
Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
|
|
44
|
+
|
|
45
|
+
## Fair Use
|
|
46
|
+
|
|
47
|
+
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
48
|
+
|
|
49
|
+
## No Other Rights
|
|
50
|
+
|
|
51
|
+
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
52
|
+
|
|
53
|
+
## Patent Defense
|
|
54
|
+
|
|
55
|
+
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
56
|
+
|
|
57
|
+
## Violations
|
|
58
|
+
|
|
59
|
+
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
60
|
+
|
|
61
|
+
## No Liability
|
|
62
|
+
|
|
63
|
+
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
64
|
+
|
|
65
|
+
## Definitions
|
|
66
|
+
|
|
67
|
+
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
68
|
+
|
|
69
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
70
|
+
|
|
71
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
72
|
+
|
|
73
|
+
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
74
|
+
|
|
75
|
+
**Use** means anything you do with the software requiring one of your licenses.
|
package/README.md
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @extantape/payload-plugin-onephylogeny
|
|
2
|
+
|
|
3
|
+
OnePhylogeny for Payload: immutable reference panels and released results on your own collections, with server-enforced review, safe endpoints and no coordinates.
|
|
4
|
+
|
|
5
|
+
See the [repository](https://github.com/ExtantApe/OnePhylogeny) for documentation.
|
|
6
|
+
|
|
7
|
+
## Samples and sequences
|
|
8
|
+
|
|
9
|
+
Pass `records` to add `samples` and `sequences`. A lab's file becomes one of each through one call:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { registerSequence } from '@extantape/payload-plugin-onephylogeny'
|
|
13
|
+
|
|
14
|
+
const { sample, sequence, created } = await registerSequence(payload, {
|
|
15
|
+
tenant, animal, kit, lab, file, // your own record IDs; taxon is read from the animal if you leave it out
|
|
16
|
+
sha256, // computed by your server from the stored bytes
|
|
17
|
+
text, // the file's contents, which must hash to sha256
|
|
18
|
+
marker: 'cytb',
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
It refuses, in plain words, a file whose text doesn't match its SHA-256, a file with more or fewer than one sequence, characters that aren't DNA bases, a sequence outside the lengths set for its marker, and an animal with no species. Sending the same file for the same kit again changes nothing (`created: false`). It writes with full access, so check first that the caller may submit results for that kit.
|
|
23
|
+
|
|
24
|
+
A Sanger chromatogram goes in the same way, with its bytes instead of text:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { registerTrace } from '@extantape/payload-plugin-onephylogeny'
|
|
28
|
+
|
|
29
|
+
const { sequence } = await registerTrace(payload, { tenant, animal, kit, lab, file, sha256, bytes, fileName: 'K0001-F.ab1', marker: 'cytb' })
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The read is trimmed by quality and bases below Q20 become N (OnePhylogeny's `assessRead`, with its stated defaults). The kept bases are stored and tested like any sequence. The sequence's `trace` field records how the read was judged: status, kept range, raw length, mean quality, masked bases and mixed-peak count. Nothing else from the file is stored. A file that isn't a chromatogram, doesn't match its SHA-256, or holds a failed or too-short read (under 100 good bases) is refused, and nothing is stored. Joining a forward and a reverse read isn't offered here yet; send the better read.
|
|
33
|
+
|
|
34
|
+
`assignWaiting(payload, { evaluate })` is the sweep. It tests each waiting sequence against the panel for its marker and species, using the `evaluate` function you pass (OnePhylogeny's `testSample` in a Node job), and records a result pending review. A sequence with no panel stays waiting, and one the panel's checks refuse is marked `not-assessable`, with the reason. Results reach readers only after a reviewer approves them.
|
|
35
|
+
|
|
36
|
+
On a multi-site host, set `tenantField` if the site field isn't called `tenant`. A result, sample or sequence keeps the site it was made for, so nobody can move it to another site's readers.
|
|
37
|
+
|
|
38
|
+
## External samples
|
|
39
|
+
|
|
40
|
+
A sample is `internal` (the host's own material, from a kit, an upload or a historic record) or `external` (a record from a paper, a public database, a validated panel or an institution). `origin` is set once. Internal samples have `source`, and may have a kit and consent. External samples have none of those, and instead fill the `external` group:
|
|
41
|
+
|
|
42
|
+
| Field | What it holds |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `sourceType` | `paper`, `public-database`, `validated-panel` or `institution`. Required. |
|
|
45
|
+
| `accession`, `database` | The source's own identifier and the database it belongs to. Unique together where both are set, without regard to case or spacing: `GenBank AB000001` and ` genbank ab000001` are one record. A hidden `sourceKey` holds the normalized pair under a sparse unique index, so two writes in the same instant can't both land. |
|
|
46
|
+
| `voucher.institution`, `voucher.catalogNumber` | The specimen, as a collection names it. |
|
|
47
|
+
| `collector`, `permit` | Restricted: read and changed only by the check you pass as `external.restrictedAccess`. Default nobody. |
|
|
48
|
+
| `collectionDatePrecision` | `day`, `month`, `year` or `unknown`, for the sample's `collectedAt`. |
|
|
49
|
+
| `dataLicense` | `cc0`, `cc-by`, `cc-by-nc`, `insdc`, `other` or `unknown`. Left out, it is `unknown`. `other` and `unknown` both allow nothing. |
|
|
50
|
+
| `dataLicenseNote`, `citation`, `doi` | The terms as written, and the paper or dataset. |
|
|
51
|
+
| `url` | The source's own page. Readable only by the check you pass as `external.urlAccess`. Default nobody. |
|
|
52
|
+
| `sourceRelease`, `importRun` | Relations to your own collections, added when you name them in `external.relations`. |
|
|
53
|
+
|
|
54
|
+
The plugin knows no roles. Pass your own checks:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
records: {
|
|
58
|
+
external: {
|
|
59
|
+
restrictedAccess: ({ req }) => req.user?.role === 'super-admin', // collector and permit
|
|
60
|
+
urlAccess: ({ req }) => Boolean(req.user?.role), // the source link
|
|
61
|
+
relations: { sourceReleases: 'source-releases', importRuns: 'import-runs' },
|
|
62
|
+
},
|
|
63
|
+
ecoregions: { land: { dataset: 'RESOLVE Ecoregions', version: '2017' } },
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**The data license fails closed.** `unknown` means the record is a pointer to the source: no copy of its reads may be kept and nothing may be passed on, until a curator sets a real license. `other` gets the same answer: its terms are in `dataLicenseNote`, which only a person can read, and a check that can't decide says no. Once someone has read them, move the record to a real license. `licenseTerms(license)` gives the same answers to your own code (`keepCopy`, `redistribute`, `commercial`, `pointerOnly`).
|
|
68
|
+
|
|
69
|
+
The accession check works on MongoDB and Postgres. Its tests against Postgres skip unless asked: run `pnpm test:postgres` in `packages/payload` (needs Docker; it starts one throwaway Postgres 17 container, pinned by image digest, on 127.0.0.1 and removes it; a run killed part way leaves the container for you to remove) or set `ONEPHYLOGENY_TEST_POSTGRES_URL` to an empty throwaway database. The tests push their schema into that database, so one that already holds a table is refused. The Postgres adapter is a dev dependency only.
|
|
70
|
+
|
|
71
|
+
`rawReads[]` holds pointers to raw reads (an SRA run, a URL, your storage key), each with its SHA-256 and a `tier`: `external` (the source holds it), `cache` (a copy that may be cleared), `hot` or `deep-archive` (your own reads). An external sample's reads are `external`, or `cache` once its license allows a copy. An internal sample's reads are `hot` or `deep-archive`. The reads themselves are never stored here.
|
|
72
|
+
|
|
73
|
+
`ecoregion` is the most any page may show of where a sample came from, in three realms: `land`, `marine` and `freshwater`. Each value carries the dataset and version it came from, and a realm you pin in `ecoregions` refuses any other set. Precise localities never enter the plugin: a sample with a coordinate anywhere in it is refused, whether as a field named for one (`lat`, `lon`, `coordinates` and the like) or as text that reads like one in any field (`4.61 N 74.08 W`, `4°36'35"N`, `4.6097, -74.0817`). The refusal names the field. `looksLikeCoordinates(text)` is the same check, for your own code. Keep localities in your own collection, with your own audit.
|
|
74
|
+
|
|
75
|
+
### Importing GenBank records
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { importGenBank } from '@extantape/payload-plugin-onephylogeny'
|
|
79
|
+
|
|
80
|
+
const report = await importGenBank(payload, genBankText, { subject: referenceSubjectId, req })
|
|
81
|
+
// { created: [{ accession, id }], duplicates: [{ accession, id }], failed: [{ accession, reason }] }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Each record becomes an external sample: `public-database`, `GenBank`, the accession without its version, the voucher, collector and date precision where the record gives them, its citation, a link to the record in `url` (so your `urlAccess` rule governs it), and a `rawReads` pointer that names the versioned accession (`PQ562694.1`), checked by the sequence's SHA-256. GenBank states no license, so `dataLicense` is `unknown` and only a pointer is kept; `tier: 'cache'` is refused. `subject` is yours, an id or a function of the record: the plugin doesn't decide what a reference record is.
|
|
85
|
+
|
|
86
|
+
**Access.** Pass `req` (the request of the person importing) and every read and write runs as that user, under your access rules: a user who may not create samples gets each record back under `failed`, and `duplicates` names only samples they may read. Without `req` the import runs with full access, like any Local API job, so it belongs only in trusted server code that has already checked who is asking. Never wire it to an upload or a request without `req`.
|
|
87
|
+
|
|
88
|
+
**Place.** The importer never reads `lat_lon`, `geo_loc_name` or `country`, so no place qualifier reaches a sample. A reference title or citation keeps the words its authors wrote, which may name a country. A voucher or citation whose text reads like a coordinate is refused, like any other sample, and lands under `failed`. When a record's only reference is its direct submission, the citation is the authors and title alone, because the JOURNAL line there is the submitter's postal address.
|
|
89
|
+
|
|
90
|
+
Running it twice makes nothing new and lists the accessions already held. `genBankToExternalSample(record)` does the mapping alone. The test fixture is five real public records in `fixtures/external/`.
|
|
2
91
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { FieldAccess, Access, PayloadRequest, Payload, Where, Plugin } from 'payload';
|
|
2
|
+
import { Result, GenBankRecord } from '@extantape/onephylogeny-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Settings for samples that came from outside the host: a paper, a public database, a validated panel or an institution.
|
|
6
|
+
* The plugin knows no roles. Every rule about who sees what is a function the host passes, and each defaults to nobody.
|
|
7
|
+
*/
|
|
8
|
+
type ExternalOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Who may read and change a source's collector name and permit reference. They name people, so the default is nobody:
|
|
11
|
+
* only scripts that bypass access see them. Hosts pass their strictest check here.
|
|
12
|
+
*/
|
|
13
|
+
restrictedAccess?: FieldAccess;
|
|
14
|
+
/** Who may read the source's own page for a record (`external.url`). Default: nobody. Hosts usually pass their admin check. */
|
|
15
|
+
urlAccess?: FieldAccess;
|
|
16
|
+
/** Host collections for the release an import came from and the run that created the sample. Left out, the field isn't added. */
|
|
17
|
+
relations?: {
|
|
18
|
+
sourceReleases?: string;
|
|
19
|
+
importRuns?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/** One ecoregion set, fixed by version so a stored name can always be traced to the dataset that gave it. */
|
|
23
|
+
type EcoregionPin = {
|
|
24
|
+
dataset: string;
|
|
25
|
+
version: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The ecoregion sets a host uses, one per realm. A pinned realm refuses any value from another dataset or version. An
|
|
29
|
+
* unpinned realm still needs every value to carry its dataset and version.
|
|
30
|
+
*/
|
|
31
|
+
type EcoregionOptions = {
|
|
32
|
+
land?: EcoregionPin;
|
|
33
|
+
marine?: EcoregionPin;
|
|
34
|
+
freshwater?: EcoregionPin;
|
|
35
|
+
};
|
|
36
|
+
declare const SOURCE_TYPES: readonly ["paper", "public-database", "validated-panel", "institution"];
|
|
37
|
+
declare const DATA_LICENSES: readonly ["cc0", "cc-by", "cc-by-nc", "insdc", "other", "unknown"];
|
|
38
|
+
declare const READ_TIERS: readonly ["external", "cache", "hot", "deep-archive"];
|
|
39
|
+
type DataLicense = (typeof DATA_LICENSES)[number];
|
|
40
|
+
/**
|
|
41
|
+
* What a data license lets a host do with a sequence, read so a license the plugin can't decide on allows nothing: the
|
|
42
|
+
* record is a pointer to the source, with no copy kept and nothing passed on, until a curator sets a real license. That
|
|
43
|
+
* covers `unknown`, nothing at all, and `other`: its terms are written in `dataLicenseNote`, which only a person can read,
|
|
44
|
+
* so the plugin answers no. A host that has read them moves the record to a real license.
|
|
45
|
+
*/
|
|
46
|
+
declare function licenseTerms(license: string | null | undefined): {
|
|
47
|
+
keepCopy: boolean;
|
|
48
|
+
redistribute: boolean;
|
|
49
|
+
commercial: boolean;
|
|
50
|
+
pointerOnly: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The key the unique index holds for a source record: `database:accession`, both normalized. Accessions are folded to
|
|
54
|
+
* lower case because GenBank, ENA and BOLD read them without regard to case. Undefined when either part is missing, so
|
|
55
|
+
* the sparse index skips samples with no public record.
|
|
56
|
+
*/
|
|
57
|
+
declare const sourceKeyOf: (database: unknown, accession: unknown) => string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* True when free text reads like a coordinate: a decimal or degree-minute pair with hemisphere letters, or a plain
|
|
60
|
+
* decimal pair in the range of a latitude and longitude. A catalog number, a date, a page range or a checksum is not one.
|
|
61
|
+
* Tight on purpose: it refuses what is plainly a position, so a sample's text can't carry a locality past the field
|
|
62
|
+
* names, and leaves ordinary numbers alone.
|
|
63
|
+
*/
|
|
64
|
+
declare const looksLikeCoordinates: (text: string) => boolean;
|
|
65
|
+
|
|
66
|
+
/** Settings for the optional `samples` and `sequences` collections. */
|
|
67
|
+
type RecordsOptions = {
|
|
68
|
+
slugs?: {
|
|
69
|
+
samples?: string;
|
|
70
|
+
sequences?: string;
|
|
71
|
+
};
|
|
72
|
+
/** Host collections for the kit a sample came in and the lab that read it. Left out, the field isn't added. */
|
|
73
|
+
relations?: {
|
|
74
|
+
kit?: string;
|
|
75
|
+
lab?: string;
|
|
76
|
+
};
|
|
77
|
+
/** Who may read samples and sequences, besides managers. Default: managers only. */
|
|
78
|
+
readAccess?: Access;
|
|
79
|
+
/** The markers a sequence may be for, with the lengths accepted. Default: any marker, 100 to 50,000 bases. */
|
|
80
|
+
markers?: Record<string, {
|
|
81
|
+
minLength?: number;
|
|
82
|
+
maxLength?: number;
|
|
83
|
+
}>;
|
|
84
|
+
/** The host's tenant field, filled from `registerSequence`'s `tenant` and copied onto results. Default `tenant`. */
|
|
85
|
+
tenantField?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Samples from outside the host (papers, public databases, validated panels, institutions). The fields are always
|
|
88
|
+
* added; this sets who may read the restricted ones, which default to nobody, and which host collections they relate to.
|
|
89
|
+
*/
|
|
90
|
+
external?: ExternalOptions;
|
|
91
|
+
/** The ecoregion sets this host uses, one per realm, each pinned by version. Default: none pinned. */
|
|
92
|
+
ecoregions?: EcoregionOptions;
|
|
93
|
+
};
|
|
94
|
+
/** Reads one FASTA file as one sequence, or says in plain words why it can't. */
|
|
95
|
+
declare function readSingleSequence(text: string, marker: string, markers?: RecordsOptions['markers']): {
|
|
96
|
+
recordId: string;
|
|
97
|
+
residues: string;
|
|
98
|
+
};
|
|
99
|
+
/** How a chromatogram read was judged, as stored on its sequence. Never coordinates or anything else from the file. */
|
|
100
|
+
type TraceSummary = {
|
|
101
|
+
status: 'usable';
|
|
102
|
+
keptStart: number;
|
|
103
|
+
keptEnd: number;
|
|
104
|
+
rawLength: number;
|
|
105
|
+
meanQuality: number | null;
|
|
106
|
+
maskedBases: number;
|
|
107
|
+
mixedPeaks: number | null;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Reads one Sanger chromatogram (.ab1) as one sequence: trimmed by quality, with weak bases as N (`assessRead`'s stated
|
|
111
|
+
* defaults). Refuses, in plain words, a file that isn't a readable chromatogram and a read that failed or is too short.
|
|
112
|
+
*/
|
|
113
|
+
declare function readTrace(bytes: Uint8Array, marker: string, markers?: RecordsOptions['markers']): {
|
|
114
|
+
recordId: string | null;
|
|
115
|
+
residues: string;
|
|
116
|
+
trace: TraceSummary;
|
|
117
|
+
};
|
|
118
|
+
type RegisterBase = {
|
|
119
|
+
/** The host's tenant (site), written to the tenant field. */
|
|
120
|
+
tenant?: string | number;
|
|
121
|
+
animal: string | number;
|
|
122
|
+
/** Taken from the animal's `taxon` field when left out. */
|
|
123
|
+
taxon?: string | number;
|
|
124
|
+
kit?: string | number;
|
|
125
|
+
lab?: string | number;
|
|
126
|
+
/** The host's file record holding the bytes the lab sent. */
|
|
127
|
+
file?: string | number;
|
|
128
|
+
/** SHA-256 of the file, as the host computed it from the stored bytes. */
|
|
129
|
+
sha256: string;
|
|
130
|
+
marker: string;
|
|
131
|
+
source?: 'kit' | 'upload' | 'historic';
|
|
132
|
+
collectedAt?: string;
|
|
133
|
+
req?: PayloadRequest;
|
|
134
|
+
};
|
|
135
|
+
type RegisterSequenceInput = RegisterBase & {
|
|
136
|
+
/** The file's text. It must hash to `sha256`. */
|
|
137
|
+
text: string;
|
|
138
|
+
};
|
|
139
|
+
type RegisterTraceInput = RegisterBase & {
|
|
140
|
+
/** The chromatogram's bytes. They must hash to `sha256`. */
|
|
141
|
+
bytes: Uint8Array;
|
|
142
|
+
/** Used as the sequence's record ID when the file carries no sample name. */
|
|
143
|
+
fileName?: string;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Records one lab file as a sample and a sequence. It writes with full access, so the caller must already have checked
|
|
147
|
+
* that this person may submit results for this kit. Calling it again with the same kit and file changes nothing.
|
|
148
|
+
*/
|
|
149
|
+
declare function registerSequence(payload: Payload, input: RegisterSequenceInput): Promise<Registered>;
|
|
150
|
+
/**
|
|
151
|
+
* Records one Sanger chromatogram (.ab1) as a sample and a sequence, like `registerSequence`. The read is trimmed by
|
|
152
|
+
* quality and its weak bases become N; the kept bases are stored with how the read was judged (`trace`). A file that
|
|
153
|
+
* isn't a chromatogram, or a read that failed or is too short, is refused and nothing is stored. The same access rule
|
|
154
|
+
* applies: check first that the caller may submit results for this kit.
|
|
155
|
+
*/
|
|
156
|
+
declare function registerTrace(payload: Payload, input: RegisterTraceInput): Promise<Registered>;
|
|
157
|
+
type Registered = {
|
|
158
|
+
sample: Record<string, unknown>;
|
|
159
|
+
sequence: Record<string, unknown>;
|
|
160
|
+
created: boolean;
|
|
161
|
+
};
|
|
162
|
+
/** What `assignWaiting` asks the host to compute for one sequence against one panel. */
|
|
163
|
+
/**
|
|
164
|
+
* Tests one sequence. `{ skip }` means the panel itself can't be used right now (for example its examples no longer give
|
|
165
|
+
* the answers they gave when it was built): the sequence stays waiting, and the skip is reported, never held against it.
|
|
166
|
+
*/
|
|
167
|
+
type Evaluate = (args: {
|
|
168
|
+
residues: string;
|
|
169
|
+
queryId: string;
|
|
170
|
+
panel: Record<string, unknown>;
|
|
171
|
+
}) => Promise<{
|
|
172
|
+
result: Result | null;
|
|
173
|
+
problems: string[];
|
|
174
|
+
} | {
|
|
175
|
+
skip: string;
|
|
176
|
+
}>;
|
|
177
|
+
/** A short, plain summary of a result, naming the groups it is consistent with. */
|
|
178
|
+
declare function summarize(result: Result, panel: {
|
|
179
|
+
groups?: {
|
|
180
|
+
groupId: string;
|
|
181
|
+
label: string;
|
|
182
|
+
}[];
|
|
183
|
+
}): string;
|
|
184
|
+
/**
|
|
185
|
+
* The sweep: tests each sequence still `received` against the panel for its marker and species, and records a result
|
|
186
|
+
* waiting for review. A sequence with no panel stays waiting; one the checks refuse is marked not assessable, with why. A
|
|
187
|
+
* panel `evaluate` skips leaves its sequences waiting, and is listed in `skippedPanels` so the run can say so.
|
|
188
|
+
*/
|
|
189
|
+
declare function assignWaiting(payload: Payload, args: {
|
|
190
|
+
evaluate: Evaluate;
|
|
191
|
+
limit?: number;
|
|
192
|
+
req?: PayloadRequest;
|
|
193
|
+
}): Promise<{
|
|
194
|
+
checked: number;
|
|
195
|
+
skippedPanels: {
|
|
196
|
+
panel: string;
|
|
197
|
+
key: string;
|
|
198
|
+
version: string;
|
|
199
|
+
reason: string;
|
|
200
|
+
}[];
|
|
201
|
+
assigned: number;
|
|
202
|
+
notAssessable: number;
|
|
203
|
+
noPanel: number;
|
|
204
|
+
skipped: number;
|
|
205
|
+
}>;
|
|
206
|
+
|
|
207
|
+
type Granted = boolean | Where;
|
|
208
|
+
/**
|
|
209
|
+
* Joins access results with "or". A rule may grant everything (`true`), nothing, or only matching records (a query), and
|
|
210
|
+
* a query is never read as everything: a reviewer of one site sees that site's records, not all of them.
|
|
211
|
+
*/
|
|
212
|
+
declare function either(...grants: (Granted | null | undefined)[]): Granted;
|
|
213
|
+
/** Access that allows what any of the given rules allows. */
|
|
214
|
+
declare const anyOf: (...rules: (Access | undefined)[]) => Access;
|
|
215
|
+
|
|
216
|
+
type Doc = Record<string, unknown>;
|
|
217
|
+
/**
|
|
218
|
+
* How much of a GenBank `collection_date` to trust, from its shape alone: `2019`, `Mar-2019` or `2019-03`, `15-Mar-2019`
|
|
219
|
+
* or `2019-03-15`, with a trailing time or range ignored. The date itself isn't kept. Anything else is `unknown`.
|
|
220
|
+
*/
|
|
221
|
+
declare function datePrecision(value: string | undefined): 'day' | 'month' | 'year' | 'unknown';
|
|
222
|
+
type GenBankImportOptions = {
|
|
223
|
+
/**
|
|
224
|
+
* The host's subject (the `samples.subject` relation) for a record. The plugin requires one, and what a reference
|
|
225
|
+
* record stands for is the host's call, so the import never makes one up. A plain id is used for every record.
|
|
226
|
+
*/
|
|
227
|
+
subject: string | number | ((record: GenBankRecord) => string | number | Promise<string | number>);
|
|
228
|
+
/** Anything else the host's `samples` needs, such as its tenant field. Merged over the mapped fields. */
|
|
229
|
+
extra?: (record: GenBankRecord) => Doc;
|
|
230
|
+
/**
|
|
231
|
+
* Where a copy of the sequence may be kept: `external` (the default) points at GenBank and keeps nothing, `cache` keeps
|
|
232
|
+
* a copy. GenBank states no license, so the record is `unknown`, and the plugin refuses `cache` for it.
|
|
233
|
+
*/
|
|
234
|
+
tier?: 'external' | 'cache';
|
|
235
|
+
/** The collection's slug. Default `samples`. */
|
|
236
|
+
samples?: string;
|
|
237
|
+
/**
|
|
238
|
+
* The request of the person running the import. With it, every read and write runs as that user, under the host's
|
|
239
|
+
* access rules (`overrideAccess: false`): a user who may not create samples gets every record back under `failed`,
|
|
240
|
+
* and `duplicates` names only samples they may read (one they may not read comes back under `failed`, in the plugin's
|
|
241
|
+
* own words for a duplicate, with no id). Without it, the import runs with full access, as a trusted server-side job,
|
|
242
|
+
* so the host must have checked the caller first.
|
|
243
|
+
*/
|
|
244
|
+
req?: PayloadRequest;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Turns one parsed GenBank record into the input for an external sample: GenBank as a public database, the accession
|
|
248
|
+
* without its version (so a new version of the record is the same sample), the voucher, collector and the precision of
|
|
249
|
+
* the collection date where the record gives them, the first reference that isn't the direct submission as the
|
|
250
|
+
* citation, a link to the record as `url`, and a `rawReads` pointer naming the versioned accession (`PQ562694.1`)
|
|
251
|
+
* checked by the sequence's own SHA-256. The link lives in `url` alone, so the host's `urlAccess` rule governs it.
|
|
252
|
+
*
|
|
253
|
+
* The record states no data license, so it is `unknown`: pointer only. The mapper never reads `lat_lon`, `geo_loc_name`
|
|
254
|
+
* or `country`, so no place qualifier reaches the sample. A title or citation keeps the words its authors wrote. When a
|
|
255
|
+
* record's only reference is the direct submission, the citation is its authors and title alone, because the JOURNAL
|
|
256
|
+
* line of a direct submission is the submitter's postal address. The plugin itself refuses a sample with a coordinate
|
|
257
|
+
* anywhere in it, as a field or as text. Pure: it makes no request and touches no database.
|
|
258
|
+
*/
|
|
259
|
+
declare function genBankToExternalSample(rec: GenBankRecord, o?: {
|
|
260
|
+
tier?: 'external' | 'cache';
|
|
261
|
+
}): Doc;
|
|
262
|
+
type GenBankImportReport = {
|
|
263
|
+
/** Accessions saved, with the new sample's id. */
|
|
264
|
+
created: {
|
|
265
|
+
accession: string;
|
|
266
|
+
id: string | number;
|
|
267
|
+
}[];
|
|
268
|
+
/** Accessions a sample already holds, so nothing was added. */
|
|
269
|
+
duplicates: {
|
|
270
|
+
accession: string;
|
|
271
|
+
id: string | number;
|
|
272
|
+
}[];
|
|
273
|
+
/** Records the plugin refused, in its words. */
|
|
274
|
+
failed: {
|
|
275
|
+
accession: string;
|
|
276
|
+
reason: string;
|
|
277
|
+
}[];
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Imports a GenBank flat file as external samples through the Local API, so every rule of the plugin applies. Safe to
|
|
281
|
+
* run twice: an accession a sample already holds is reported as a duplicate. One refused record doesn't stop the rest.
|
|
282
|
+
*
|
|
283
|
+
* Access: pass `req` to run as the person importing, under the host's access rules. Without `req` the import runs with
|
|
284
|
+
* full access, the way Payload's Local API does for any server job, so it belongs only in trusted server code that has
|
|
285
|
+
* already checked who is asking. Never wire it to a request without `req`.
|
|
286
|
+
*/
|
|
287
|
+
declare function importGenBank(payload: Payload, text: string, o: GenBankImportOptions): Promise<GenBankImportReport>;
|
|
288
|
+
|
|
289
|
+
type OnePhylogenyPluginOptions = {
|
|
290
|
+
/** Slugs of the collections this plugin adds. */
|
|
291
|
+
slugs?: {
|
|
292
|
+
panels?: string;
|
|
293
|
+
assignments?: string;
|
|
294
|
+
};
|
|
295
|
+
/** Host collections to relate to. Leave one out and its field isn't added, so the plugin works in any site. */
|
|
296
|
+
relations?: {
|
|
297
|
+
subject?: string;
|
|
298
|
+
sequence?: string;
|
|
299
|
+
taxa?: string;
|
|
300
|
+
files?: string;
|
|
301
|
+
importRuns?: string;
|
|
302
|
+
};
|
|
303
|
+
/** Who may create panels and results, and activate panels. Default: nobody but trusted local scripts. Activating also needs a signed-in user, who is recorded. */
|
|
304
|
+
manageAccess?: Access;
|
|
305
|
+
/** Who may approve or reject results. Default: same as manageAccess. */
|
|
306
|
+
reviewAccess?: Access;
|
|
307
|
+
/** Extra rule for reading released results, such as the host's own animal permissions. Default: signed-in users. */
|
|
308
|
+
readReleasedAccess?: Access;
|
|
309
|
+
/** Field added to assignments for multi-tenant hosts' isolation plugins to find. */
|
|
310
|
+
group?: string;
|
|
311
|
+
/**
|
|
312
|
+
* Which panels results may be made against. `activeOrShown` also allows a `candidate` a maintainer ticked "shown as
|
|
313
|
+
* exploratory", and lets readers see such candidates. Default: `active`.
|
|
314
|
+
*/
|
|
315
|
+
resultsAgainst?: 'active' | 'activeOrShown';
|
|
316
|
+
/**
|
|
317
|
+
* Adds `samples` and `sequences`, with `registerSequence` to record a lab's file and `assignWaiting` to test waiting
|
|
318
|
+
* sequences. Left out, neither collection is added. Results then relate to these sequences.
|
|
319
|
+
*/
|
|
320
|
+
records?: RecordsOptions;
|
|
321
|
+
/**
|
|
322
|
+
* The host's tenant (site) field on results, if it has one, such as a multi-tenant plugin adds. A result's site is set
|
|
323
|
+
* when it is made and can't change, so a reviewer can't move it to a site whose people would then see it. Default `tenant`.
|
|
324
|
+
*/
|
|
325
|
+
tenantField?: string;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* OnePhylogeny for Payload. Adds immutable panels and reviewed results, relating to whatever collections a site already
|
|
330
|
+
* has. It holds no species knowledge. Compute happens elsewhere: this stores what was computed and controls release.
|
|
331
|
+
*/
|
|
332
|
+
declare const onePhylogeny: (options?: OnePhylogenyPluginOptions) => Plugin;
|
|
333
|
+
|
|
334
|
+
export { DATA_LICENSES, type DataLicense, type EcoregionOptions, type EcoregionPin, type Evaluate, type ExternalOptions, type GenBankImportOptions, type GenBankImportReport, type OnePhylogenyPluginOptions, READ_TIERS, type RecordsOptions, type RegisterSequenceInput, type RegisterTraceInput, SOURCE_TYPES, type TraceSummary, anyOf, assignWaiting, datePrecision, either, genBankToExternalSample, importGenBank, licenseTerms, looksLikeCoordinates, onePhylogeny, readSingleSequence, readTrace, registerSequence, registerTrace, sourceKeyOf, summarize };
|