@larsgw/formica 0.1.1 → 0.2.0

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.
File without changes
@@ -44,6 +44,7 @@ var Work = /** @class */ (function (_super) {
44
44
  license: { required: false, multiple: true, format: value_1.FORMATS.LICENSE },
45
45
  key_type: { required: true, multiple: true, format: value_1.FORMATS.KEY_TYPE },
46
46
  taxon: { required: true, multiple: true },
47
+ taxon_scope: { required: false, multiple: true },
47
48
  scope: { required: false, multiple: true },
48
49
  region: { required: true, multiple: true },
49
50
  complete: { required: false, multiple: false, format: value_1.FORMATS.COMPLETE },
@@ -362,6 +362,14 @@ function parseResource(resource) {
362
362
  var line = (content.slice(0, offset).match(/\n/g) || []).length + 1;
363
363
  throw new SyntaxError("Too much indentation at ".concat(line, ":0\n").concat(content.slice(offset).split('\n', 1), "\n^"));
364
364
  }
365
+ // Check for missing leaf taxa
366
+ var missingLeafTaxa = new RegExp("^( ){0,".concat(config.levels.length - 2, "}(?![+=>] ).*\\n(?!\\1 )"), 'm');
367
+ var missingLeafTaxaMatch = content.match(missingLeafTaxa);
368
+ if (missingLeafTaxaMatch !== null) {
369
+ var offset = missingLeafTaxaMatch.index;
370
+ var line = (content.slice(0, offset).match(/\n/g) || []).length + 1;
371
+ throw new SyntaxError("Missing leaf taxon at ".concat(line, ":0\n").concat(content.slice(offset).split('\n', 1), "\n^"));
372
+ }
365
373
  return [config, content];
366
374
  }
367
375
  function parseResourceContent(content, resource, oldIds) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@larsgw/formica",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "SDK and tools for data from the Library of Identification Resources",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -11,6 +11,7 @@
11
11
  "loir-resources-index": "./lib/bin/process-resources-index.js"
12
12
  },
13
13
  "scripts": {
14
+ "test": "node --test --test-reporter spec",
14
15
  "lint": "eslint src",
15
16
  "build": "tsc -d",
16
17
  "preversion": "npm run lint",
@@ -26,6 +26,7 @@ export class Work extends Entity {
26
26
  license: { required: false, multiple: true, format: FORMATS.LICENSE },
27
27
  key_type: { required: true, multiple: true, format: FORMATS.KEY_TYPE },
28
28
  taxon: { required: true, multiple: true },
29
+ taxon_scope: { required: false, multiple: true },
29
30
  scope: { required: false, multiple: true },
30
31
  region: { required: true, multiple: true },
31
32
  complete: { required: false, multiple: false, format: FORMATS.COMPLETE },
@@ -376,6 +376,17 @@ ${content.slice(offset).split('\n', 1)}
376
376
  ^`)
377
377
  }
378
378
 
379
+ // Check for missing leaf taxa
380
+ const missingLeafTaxa = new RegExp(`^( ){0,${config.levels.length - 2}}(?![+=>] ).*\\n(?!\\1 )`, 'm')
381
+ const missingLeafTaxaMatch = content.match(missingLeafTaxa)
382
+ if (missingLeafTaxaMatch !== null) {
383
+ const offset = missingLeafTaxaMatch.index
384
+ const line = (content.slice(0, offset).match(/\n/g) || []).length + 1
385
+ throw new SyntaxError(`Missing leaf taxon at ${line}:0
386
+ ${content.slice(offset).split('\n', 1)}
387
+ ^`)
388
+ }
389
+
379
390
  return [config, content]
380
391
  }
381
392
 
@@ -0,0 +1,19 @@
1
+ const test = require('node:test')
2
+ const assert = require('assert')
3
+
4
+ const { resources } = require('../lib')
5
+
6
+ test('resources', async (t) => {
7
+ await t.test('missing leaf taxa', (t) => {
8
+ assert.throws(() => {
9
+ resources.parseTextFile(`---
10
+ levels: [family, genus, species]
11
+ ---
12
+
13
+ Cydnidae
14
+ Cydnidae
15
+ Legnotus
16
+ limbosus`, 'T1')
17
+ })
18
+ })
19
+ })
package/lib/types.d.ts DELETED
@@ -1,62 +0,0 @@
1
- type Value = string[] | string;
2
- type SingleValue = string;
3
- interface FieldError {
4
- field: string;
5
- error: string;
6
- }
7
- interface WorkError extends FieldError {
8
- entity: WorkId;
9
- }
10
- type Rank = string;
11
- type DwcRank = Rank;
12
- type TaxonStatus = string;
13
- type TaxonId = string;
14
- type ResourceId = string;
15
- type WorkId = string;
16
- interface WorkingTaxon {
17
- scientificNameID?: TaxonId;
18
- scientificName?: string;
19
- scientificNameAuthorship?: string;
20
- genericName?: string;
21
- infragenericEpithet?: string;
22
- specificEpithet?: string;
23
- intraspecificEpithet?: string;
24
- taxonRank?: Rank;
25
- taxonRemarks?: string;
26
- collectionCode?: ResourceId;
27
- taxonomicStatus?: TaxonStatus;
28
- acceptedNameUsageID?: TaxonId;
29
- acceptedNameUsage?: string;
30
- parentNameUsageID?: TaxonId;
31
- parentNameUsage?: string;
32
- kingdom?: string;
33
- phylum?: string;
34
- class?: string;
35
- order?: string;
36
- family?: string;
37
- subfamily?: string;
38
- genus?: string;
39
- subgenus?: string;
40
- higherClassification?: string;
41
- scientificNameOnly?: string;
42
- incorrect?: WorkingTaxon;
43
- }
44
- interface Taxon extends WorkingTaxon {
45
- scientificNameID: TaxonId;
46
- scientificName: string;
47
- taxonRank: Rank;
48
- collectionCode: ResourceId;
49
- taxonomicStatus: string;
50
- }
51
- interface ResourceMetadata {
52
- levels: Rank[];
53
- scope: string[];
54
- catalog?: object;
55
- }
56
- interface Resource {
57
- id: string;
58
- file: string;
59
- workId: string;
60
- metadata: ResourceMetadata;
61
- taxa: Record<TaxonId, Taxon>;
62
- }
package/lib/types.js DELETED
File without changes