@larsgw/formica 0.6.0 → 0.6.2
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 +23 -0
- package/lib/bin/clean-links.d.ts +2 -0
- package/lib/bin/clean-links.js +170 -0
- package/lib/catalog/entities.js +1 -1
- package/lib/catalog/index.d.ts +2 -1
- package/lib/catalog/index.js +2 -1
- package/lib/resources/content/clavis.js +10 -0
- package/lib/resources/content/index.js +0 -0
- package/lib/resources/content/sdd.js +151 -0
- package/lib/resources/parse-text.js +2 -2
- package/lib/resources/sdd.js +78 -0
- package/package.json +3 -2
- package/src/bin/clean-links.ts +96 -0
- package/src/catalog/entities.ts +1 -1
- package/src/catalog/index.ts +1 -1
- package/src/resources/parse-text.ts +2 -2
- package/test/resources.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
## [0.6.2](https://github.com/identification-resources/formica/compare/v0.6.1...v0.6.2) (2024-04-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **catalog:** include all fields in tabular export ([c4e47bb](https://github.com/identification-resources/formica/commit/c4e47bbdf31c8f589e35c897c8207eb4dd979461))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **catalog:** add script to de-duplicate links ([b719348](https://github.com/identification-resources/formica/commit/b719348635e1b35ee80758c0cdd9938625d79ebf))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [0.6.1](https://github.com/identification-resources/formica/compare/v0.6.0...v0.6.1) (2024-03-20)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **resources:** allow two-part hybrid names ([8e3b836](https://github.com/identification-resources/formica/commit/8e3b8368985d1db35b62d306d833121150e91865))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
1
24
|
# [0.6.0](https://github.com/identification-resources/formica/compare/v0.5.2...v0.6.0) (2024-01-05)
|
|
2
25
|
|
|
3
26
|
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
+
function step(op) {
|
|
17
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
20
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
+
switch (op[0]) {
|
|
22
|
+
case 0: case 1: t = op; break;
|
|
23
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
+
default:
|
|
27
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
+
if (t[2]) _.ops.pop();
|
|
32
|
+
_.trys.pop(); continue;
|
|
33
|
+
}
|
|
34
|
+
op = body.call(thisArg, _);
|
|
35
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
var fs_1 = require("fs");
|
|
41
|
+
var path = require("path");
|
|
42
|
+
var util = require("util");
|
|
43
|
+
var index_1 = require("../index");
|
|
44
|
+
var LINKS = {
|
|
45
|
+
author: { sheet: 'authors', cleanField: 'main_full_name' },
|
|
46
|
+
publisher: { sheet: 'publishers', cleanField: 'full_name' },
|
|
47
|
+
};
|
|
48
|
+
function replaceLink(value, data, cleanField) {
|
|
49
|
+
var _a;
|
|
50
|
+
var entity = data.get(value);
|
|
51
|
+
return (_a = entity.get(cleanField)) !== null && _a !== void 0 ? _a : value;
|
|
52
|
+
}
|
|
53
|
+
function save(sheet, path) {
|
|
54
|
+
return fs_1.promises.writeFile(path, index_1.csv.formatCsv(sheet.toTable()));
|
|
55
|
+
}
|
|
56
|
+
function main() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var args, files, _i, _a, arg, filePath, file, sheet, _loop_1, _b, _c, _d, _e, field;
|
|
59
|
+
return __generator(this, function (_f) {
|
|
60
|
+
switch (_f.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
args = util.parseArgs({ allowPositionals: true });
|
|
63
|
+
files = {};
|
|
64
|
+
_i = 0, _a = args.positionals;
|
|
65
|
+
_f.label = 1;
|
|
66
|
+
case 1:
|
|
67
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
68
|
+
arg = _a[_i];
|
|
69
|
+
filePath = path.resolve(arg);
|
|
70
|
+
return [4 /*yield*/, fs_1.promises.readFile(filePath, 'utf8')];
|
|
71
|
+
case 2:
|
|
72
|
+
file = _f.sent();
|
|
73
|
+
sheet = path.basename(filePath, '.csv');
|
|
74
|
+
files[sheet] = {
|
|
75
|
+
path: filePath,
|
|
76
|
+
sheet: index_1.catalog.loadData(file, sheet),
|
|
77
|
+
};
|
|
78
|
+
_f.label = 3;
|
|
79
|
+
case 3:
|
|
80
|
+
_i++;
|
|
81
|
+
return [3 /*break*/, 1];
|
|
82
|
+
case 4:
|
|
83
|
+
if (!files.catalog) {
|
|
84
|
+
throw new Error('Catalog file must be provided');
|
|
85
|
+
}
|
|
86
|
+
_loop_1 = function (field) {
|
|
87
|
+
var _g, sheet, cleanField, indexField, used, _h, _j, work, value, entities, _k, _l, entity, oldKey, newKey;
|
|
88
|
+
return __generator(this, function (_m) {
|
|
89
|
+
switch (_m.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
_g = LINKS[field], sheet = _g.sheet, cleanField = _g.cleanField;
|
|
92
|
+
indexField = index_1.catalog.getTypeInfo(sheet)[1];
|
|
93
|
+
used = new Set();
|
|
94
|
+
if (!files[sheet]) {
|
|
95
|
+
return [2 /*return*/, "continue"];
|
|
96
|
+
}
|
|
97
|
+
// Update works
|
|
98
|
+
for (_h = 0, _j = files.catalog.sheet.entities; _h < _j.length; _h++) {
|
|
99
|
+
work = _j[_h];
|
|
100
|
+
value = work.get(field);
|
|
101
|
+
if (value === undefined) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
else if (Array.isArray(value)) {
|
|
105
|
+
work.fields[field] = value.map(function (value) {
|
|
106
|
+
value = replaceLink(value, files[sheet].sheet, cleanField);
|
|
107
|
+
used.add(value);
|
|
108
|
+
return value;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
work.fields[field] = replaceLink(value, files[sheet].sheet, cleanField);
|
|
113
|
+
used.add(work.fields[field]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
entities = [];
|
|
117
|
+
for (_k = 0, _l = files[sheet].sheet.entities; _k < _l.length; _k++) {
|
|
118
|
+
entity = _l[_k];
|
|
119
|
+
oldKey = entity.get(indexField);
|
|
120
|
+
if (entity.has(cleanField)) {
|
|
121
|
+
entity.fields[indexField] = entity.get(cleanField);
|
|
122
|
+
delete entity.fields[cleanField];
|
|
123
|
+
}
|
|
124
|
+
newKey = entity.get(indexField);
|
|
125
|
+
if (used.has(newKey) && (newKey === oldKey || !files[sheet].sheet.index[newKey])) {
|
|
126
|
+
entities.push(entity);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Save new file
|
|
130
|
+
return [4 /*yield*/, save(new index_1.catalog.Entities(entities, indexField), files[sheet].path)];
|
|
131
|
+
case 1:
|
|
132
|
+
// Save new file
|
|
133
|
+
_m.sent();
|
|
134
|
+
return [2 /*return*/];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
_b = LINKS;
|
|
139
|
+
_c = [];
|
|
140
|
+
for (_d in _b)
|
|
141
|
+
_c.push(_d);
|
|
142
|
+
_e = 0;
|
|
143
|
+
_f.label = 5;
|
|
144
|
+
case 5:
|
|
145
|
+
if (!(_e < _c.length)) return [3 /*break*/, 8];
|
|
146
|
+
_d = _c[_e];
|
|
147
|
+
if (!(_d in _b)) return [3 /*break*/, 7];
|
|
148
|
+
field = _d;
|
|
149
|
+
return [5 /*yield**/, _loop_1(field)];
|
|
150
|
+
case 6:
|
|
151
|
+
_f.sent();
|
|
152
|
+
_f.label = 7;
|
|
153
|
+
case 7:
|
|
154
|
+
_e++;
|
|
155
|
+
return [3 /*break*/, 5];
|
|
156
|
+
case 8:
|
|
157
|
+
// Save catalog
|
|
158
|
+
return [4 /*yield*/, save(files.catalog.sheet, files.catalog.path)];
|
|
159
|
+
case 9:
|
|
160
|
+
// Save catalog
|
|
161
|
+
_f.sent();
|
|
162
|
+
return [2 /*return*/];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
main().catch(function (error) {
|
|
168
|
+
console.error(error);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
});
|
package/lib/catalog/entities.js
CHANGED
|
@@ -97,7 +97,7 @@ var Entities = /** @class */ (function () {
|
|
|
97
97
|
if (this.entities.length === 0) {
|
|
98
98
|
return [[]];
|
|
99
99
|
}
|
|
100
|
-
var header = Object.keys(this.entities[0].
|
|
100
|
+
var header = Object.keys(this.entities[0].schema);
|
|
101
101
|
var table = this.entities.map(function (entity) {
|
|
102
102
|
return header.map(function (field) {
|
|
103
103
|
var value = entity.get(field) || '';
|
package/lib/catalog/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Entities } from './entities';
|
|
2
2
|
import { Entity } from './entity';
|
|
3
|
-
|
|
3
|
+
declare function getTypeInfo(type: string): [typeof Entity, string];
|
|
4
|
+
export { Entities, Entity, getTypeInfo };
|
|
4
5
|
export declare function loadData(file: string, type: string): Entities;
|
package/lib/catalog/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadData = exports.Entity = exports.Entities = void 0;
|
|
3
|
+
exports.loadData = exports.getTypeInfo = exports.Entity = exports.Entities = void 0;
|
|
4
4
|
var entities_1 = require("./entities");
|
|
5
5
|
Object.defineProperty(exports, "Entities", { enumerable: true, get: function () { return entities_1.Entities; } });
|
|
6
6
|
var entity_1 = require("./entity");
|
|
@@ -16,6 +16,7 @@ function getTypeInfo(type) {
|
|
|
16
16
|
default: throw new TypeError("Unknown type \"".concat(type, "\""));
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
exports.getTypeInfo = getTypeInfo;
|
|
19
20
|
function loadData(file, type) {
|
|
20
21
|
var _a = getTypeInfo(type), subClass = _a[0], indexField = _a[1];
|
|
21
22
|
var entities = [];
|
|
File without changes
|