@larsgw/formica 0.6.5 → 0.6.6

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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.6.6](https://github.com/identification-resources/formica/compare/v0.6.5...v0.6.6) (2025-02-16)
2
+
3
+
4
+ ### Features
5
+
6
+ * **resources:** allow other resources in version_of ([85947b0](https://github.com/identification-resources/formica/commit/85947b0dcfbdb4bfd6537c628b34087a6e6326f7))
7
+
8
+
9
+
1
10
  ## [0.6.5](https://github.com/identification-resources/formica/compare/v0.6.4...v0.6.5) (2024-12-20)
2
11
 
3
12
 
@@ -13,7 +13,7 @@ var __assign = (this && this.__assign) || function () {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.parseFileHeader = exports.parseFile = void 0;
15
15
  var yaml = require("js-yaml");
16
- var work_1 = require("../catalog/tables/work");
16
+ var resource_1 = require("./resource");
17
17
  var diff_resource_1 = require("./diff-resource");
18
18
  var RANKS = [
19
19
  'phylum',
@@ -370,6 +370,9 @@ function parseHeader(header) {
370
370
  var metadata = { levels: levels };
371
371
  if ('catalog' in config && typeof config.catalog === 'object' && config.catalog !== null) {
372
372
  var catalog = {};
373
+ if ('id' in config.catalog) {
374
+ throw new SyntaxError('"catalog" should not contain id');
375
+ }
373
376
  for (var key in config.catalog) {
374
377
  var value = config.catalog[key];
375
378
  if (typeof value === 'number') {
@@ -382,7 +385,7 @@ function parseHeader(header) {
382
385
  throw new SyntaxError("\"catalog\" should contain only strings (\"".concat(key, "\")"));
383
386
  }
384
387
  }
385
- var work = new work_1.Work(catalog);
388
+ var work = new resource_1.WorkResource(catalog);
386
389
  var errors = work.validate().filter(function (_a) {
387
390
  var error = _a.error;
388
391
  return error !== 'Value(s) required but missing';
@@ -0,0 +1,4 @@
1
+ import { Work } from '../catalog/tables/work';
2
+ export declare class WorkResource extends Work {
3
+ constructor(values: Record<string, string>);
4
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.WorkResource = void 0;
19
+ var work_1 = require("../catalog/tables/work");
20
+ var WorkResource = /** @class */ (function (_super) {
21
+ __extends(WorkResource, _super);
22
+ function WorkResource(values) {
23
+ var _this = _super.call(this, values) || this;
24
+ _this.schema.version_of.format = /^B[1-9]\d*:[1-9]\d*$/;
25
+ _this.schema.duplicate_of.format = /^B[1-9]\d*:[1-9]\d*$/;
26
+ return _this;
27
+ }
28
+ return WorkResource;
29
+ }(work_1.Work));
30
+ exports.WorkResource = WorkResource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@larsgw/formica",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
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",
@@ -16,7 +16,7 @@
16
16
  "lint": "eslint src",
17
17
  "build": "tsc -d",
18
18
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
19
- "preversion": "npm run lint",
19
+ "preversion": "npm run lint && npm test",
20
20
  "version": "npm run changelog && git add CHANGELOG.md",
21
21
  "prepublishOnly": "npm run build"
22
22
  },
@@ -1,5 +1,5 @@
1
1
  import * as yaml from 'js-yaml'
2
- import { Work } from '../catalog/tables/work'
2
+ import { WorkResource } from './resource'
3
3
  import { createDiff, ResourceDiffType } from './diff-resource'
4
4
 
5
5
  const RANKS: Rank[] = [
@@ -394,6 +394,9 @@ function parseHeader (header: string): ResourceMetadata {
394
394
 
395
395
  if ('catalog' in config && typeof config.catalog === 'object' && config.catalog !== null) {
396
396
  const catalog: Record<string, string> = {}
397
+ if ('id' in config.catalog) {
398
+ throw new SyntaxError('"catalog" should not contain id')
399
+ }
397
400
  for (const key in config.catalog) {
398
401
  const value = config.catalog[key as keyof object]
399
402
  if (typeof value === 'number') {
@@ -404,7 +407,7 @@ function parseHeader (header: string): ResourceMetadata {
404
407
  throw new SyntaxError(`"catalog" should contain only strings ("${key}")`)
405
408
  }
406
409
  }
407
- const work = new Work(catalog)
410
+ const work = new WorkResource(catalog)
408
411
  const errors = work.validate().filter(({ error }) => error !== 'Value(s) required but missing')
409
412
  if (errors.length > 0) {
410
413
  throw new SyntaxError(`"catalog" contains errors: ${errors.map(({ field, error }) => `[${field}] ${error}`).join('; ')}`)
@@ -0,0 +1,10 @@
1
+ import { Work } from '../catalog/tables/work'
2
+
3
+ export class WorkResource extends Work {
4
+ constructor (values: Record<string, string>) {
5
+ super(values)
6
+
7
+ this.schema.version_of.format = /^B[1-9]\d*:[1-9]\d*$/
8
+ this.schema.duplicate_of.format = /^B[1-9]\d*:[1-9]\d*$/
9
+ }
10
+ }