linked-rolls 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.
- package/LICENSE +26 -0
- package/README.md +35 -0
- package/lib/Assumption.d.ts +7 -2
- package/lib/ConditionState.d.ts +8 -1
- package/lib/Edit.d.ts +4 -3
- package/lib/Edition.d.ts +65 -35
- package/lib/Edition.js +1 -1
- package/lib/Emulation.js +32 -10
- package/lib/Feature.d.ts +19 -4
- package/lib/Plan.js +2 -1
- package/lib/RollCopy.d.ts +58 -26
- package/lib/RollCopy.js +2 -2
- package/lib/Symbol.d.ts +37 -20
- package/lib/Symbol.js +12 -0
- package/lib/TrackerBar.d.ts +18 -0
- package/lib/TrackerBar.js +27 -0
- package/lib/Version.d.ts +12 -4
- package/lib/asJsonLd.js +16 -2
- package/lib/context.d.ts +2 -0
- package/lib/context.js +2 -0
- package/lib/importJsonLd.js +19 -5
- package/lib/migrate.d.ts +15 -0
- package/lib/migrate.js +77 -0
- package/lib/schema.json +322 -276
- package/lib/spec/context.json +201 -131
- package/lib/spec/welte-t100.context.json +10 -0
- package/lib/systems/welteT100.js +19 -17
- package/lib/validate.d.ts +26 -0
- package/lib/validate.js +46 -0
- package/package.json +2 -1
package/lib/migrate.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { conditions } from "./Feature";
|
|
2
|
+
import { rollConditions } from "./RollCopy";
|
|
3
|
+
import { systemOf, welteT100 } from "./TrackerBar";
|
|
4
|
+
import { versionTypes } from "./Version";
|
|
5
|
+
const versionTypeValues = new Set(versionTypes);
|
|
6
|
+
const conditionTypeValues = new Set([...rollConditions, ...Object.values(conditions).flat()]);
|
|
7
|
+
const renamedKeys = {
|
|
8
|
+
productionEvent: 'production',
|
|
9
|
+
annotates: 'depiction',
|
|
10
|
+
classification: 'editType'
|
|
11
|
+
};
|
|
12
|
+
const referenceKeys = ['alignedWith', 'pairedWith', 'basedOn'];
|
|
13
|
+
const named = (name) => ({ name, sameAs: [] });
|
|
14
|
+
const withRenamedKeys = (node) => Object.fromEntries(Object.entries(node).map(([key, value]) => [renamedKeys[key] ?? key, value]));
|
|
15
|
+
const withTypology = (node) => {
|
|
16
|
+
if (versionTypeValues.has(node['@type'])) {
|
|
17
|
+
return { ...node, '@type': 'Version', versionType: node['@type'] };
|
|
18
|
+
}
|
|
19
|
+
if (conditionTypeValues.has(node['@type'])) {
|
|
20
|
+
return { ...node, '@type': 'ConditionState', conditionType: node['@type'] };
|
|
21
|
+
}
|
|
22
|
+
return node;
|
|
23
|
+
};
|
|
24
|
+
const withReferences = (node) => referenceKeys.reduce((result, key) => {
|
|
25
|
+
const reference = result[key];
|
|
26
|
+
if (reference && typeof reference === 'object' && '@value' in reference) {
|
|
27
|
+
const { '@value': id, ...rest } = reference;
|
|
28
|
+
return { ...result, [key]: { '@id': id, ...rest } };
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}, node);
|
|
32
|
+
const withKeeper = (node) => {
|
|
33
|
+
if (typeof node.location !== 'string')
|
|
34
|
+
return node;
|
|
35
|
+
const { location, ...rest } = node;
|
|
36
|
+
return { ...rest, keeper: named(location) };
|
|
37
|
+
};
|
|
38
|
+
const withProductionNodes = (node) => {
|
|
39
|
+
const production = node.production;
|
|
40
|
+
if (!production || typeof production !== 'object')
|
|
41
|
+
return node;
|
|
42
|
+
const { company, paper, system, ...rest } = production;
|
|
43
|
+
return {
|
|
44
|
+
...node,
|
|
45
|
+
production: {
|
|
46
|
+
...rest,
|
|
47
|
+
...(typeof company === 'string' ? (company && { company: named(company) }) : { company }),
|
|
48
|
+
...(typeof paper === 'string' ? (paper && { paper: named(paper) }) : { paper }),
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const migrateNode = (node) => [withRenamedKeys, withTypology, withReferences, withKeeper, withProductionNodes]
|
|
53
|
+
.reduce((result, step) => step(result), node);
|
|
54
|
+
const walk = (value) => {
|
|
55
|
+
if (Array.isArray(value))
|
|
56
|
+
return value.map(walk);
|
|
57
|
+
if (value && typeof value === 'object') {
|
|
58
|
+
return Object.fromEntries(Object.entries(migrateNode(value)).map(([key, child]) => [key, walk(child)]));
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Every 0.1 edition was read with the T-100 tracker bar, so a roll
|
|
64
|
+
* without a system is a T-100 roll. The text a copy's production
|
|
65
|
+
* gave for the system is kept as the name.
|
|
66
|
+
*/
|
|
67
|
+
const withRollSystem = (edition) => {
|
|
68
|
+
if (!edition.roll || edition.roll.system)
|
|
69
|
+
return edition;
|
|
70
|
+
const stated = (edition.copies ?? [])
|
|
71
|
+
.map((copy) => copy.production?.system ?? copy.productionEvent?.system)
|
|
72
|
+
.find((system) => typeof system === 'string' && system !== '');
|
|
73
|
+
const { id, ...concept } = systemOf(welteT100);
|
|
74
|
+
const system = { '@id': id, ...concept, ...(stated && { name: stated }) };
|
|
75
|
+
return { ...edition, roll: { ...edition.roll, system } };
|
|
76
|
+
};
|
|
77
|
+
export const migrate = (edition) => walk(withRollSystem(edition));
|