@hippo-digital/hippocampus 2.9.0 → 2.9.1
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 +16 -0
- package/docs/source-model.md +1 -1
- package/lib/schema-version.js +36 -8
- package/package.json +1 -1
- package/scripts/import-design-actions.js +3 -1
- package/scripts/migrate-knowledge.js +22 -7
- package/scripts/promote-research-draft.js +5 -0
- package/scripts/validate-knowledge.js +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.9.1
|
|
4
|
+
|
|
5
|
+
- **Every route that can add a newer feature records the version it needs.**
|
|
6
|
+
In 2.9.0 only `draft promote` wrote `requiresPackage` into `_meta.json`, so
|
|
7
|
+
an expert review promoted with `promote research` left it out, and anyone
|
|
8
|
+
still on 2.8.1 got a schema error about an unknown method instead of being
|
|
9
|
+
told to upgrade. `promote research` and `import design-actions` now record
|
|
10
|
+
it too.
|
|
11
|
+
- **`validate` warns when the knowledge base needs more than `_meta.json`
|
|
12
|
+
says.** Records added by hand skip every command that records the level.
|
|
13
|
+
The warning names the features and the version, and fails `--strict`.
|
|
14
|
+
- **`migrate` records the level** even when the schema needs no migration, so
|
|
15
|
+
the warning has a one-command fix. Run `npx hippocampus validate` after
|
|
16
|
+
upgrading; if it warns, run `npx hippocampus migrate` and commit
|
|
17
|
+
`hippocampus/source/_meta.json`.
|
|
18
|
+
|
|
3
19
|
## 2.9.0
|
|
4
20
|
|
|
5
21
|
Release 1 of the traceability work: the knowledge base can say who decided,
|
package/docs/source-model.md
CHANGED
|
@@ -364,7 +364,7 @@ A relationship may carry a `note` saying why. Validation checks the From and To
|
|
|
364
364
|
|
|
365
365
|
### Which version a knowledge base needs
|
|
366
366
|
|
|
367
|
-
`hippocampus/source/_meta.json` holds the `schemaVersion` and, once a knowledge base uses something an older package cannot read, `requiresPackage`: the lowest version of Hippocampus that understands everything in it. `draft promote`
|
|
367
|
+
`hippocampus/source/_meta.json` holds the `schemaVersion` and, once a knowledge base uses something an older package cannot read, `requiresPackage`: the lowest version of Hippocampus that understands everything in it. `draft promote`, `promote research` and `import design-actions` write it when they add a newer link type or method, and never lower it. Records added by hand skip those commands, so `validate` warns when the knowledge base uses something `_meta.json` does not record, and `npx hippocampus migrate` records it. An older package refuses the knowledge base and says which version to upgrade to, rather than reading it partially. The `rests-on` and `challenged-by` links and the `expert-review` method need 2.9.0.
|
|
368
368
|
|
|
369
369
|
Project context stays outside the graph: it is briefing material, and organisational requirements are where its rules become checkable.
|
|
370
370
|
|
package/lib/schema-version.js
CHANGED
|
@@ -20,8 +20,10 @@ const META_FILENAME = '_meta.json'
|
|
|
20
20
|
// would reject, and list what needs it in FEATURES_NEEDING.
|
|
21
21
|
const FEATURE_LEVEL = '2.9.0'
|
|
22
22
|
|
|
23
|
-
// What, in a knowledge base, needs which level. Checked
|
|
24
|
-
//
|
|
23
|
+
// What, in a knowledge base, needs which level. Checked by every command that
|
|
24
|
+
// writes records (draft promote, promote research, import design-actions), so
|
|
25
|
+
// the level is written only once something actually needs it. validate warns
|
|
26
|
+
// when a hand edit has added one without it, and migrate records it.
|
|
25
27
|
const FEATURES_NEEDING = {
|
|
26
28
|
'2.9.0': {
|
|
27
29
|
relationshipTypes: ['rests-on', 'challenged-by'],
|
|
@@ -75,19 +77,43 @@ function compareVersions (a, b) {
|
|
|
75
77
|
return 0
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
// Each versioned feature this knowledge uses, with the level it needs.
|
|
81
|
+
function featuresUsed (knowledge) {
|
|
82
|
+
const linkTypes = new Set((knowledge.relationships || []).map((r) => r.type))
|
|
83
|
+
const methods = new Set((knowledge.researchRounds || []).flatMap((r) => r.methods || []))
|
|
84
|
+
const used = []
|
|
85
|
+
for (const [level, uses] of Object.entries(FEATURES_NEEDING)) {
|
|
86
|
+
for (const type of uses.relationshipTypes || []) if (linkTypes.has(type)) used.push({ level, feature: `${type} links` })
|
|
87
|
+
for (const method of uses.researchMethods || []) if (methods.has(method)) used.push({ level, feature: `the ${method} method` })
|
|
88
|
+
}
|
|
89
|
+
return used
|
|
90
|
+
}
|
|
91
|
+
|
|
78
92
|
// The lowest level that can read this knowledge, from what it actually uses.
|
|
79
93
|
function levelNeeded (knowledge) {
|
|
80
94
|
let needed = null
|
|
81
|
-
for (const
|
|
82
|
-
|
|
83
|
-
const methods = new Set((knowledge.researchRounds || []).flatMap((r) => r.methods || []))
|
|
84
|
-
const used = (uses.relationshipTypes || []).some((t) => linkTypes.has(t)) ||
|
|
85
|
-
(uses.researchMethods || []).some((m) => methods.has(m))
|
|
86
|
-
if (used && (!needed || compareVersions(level, needed) > 0)) needed = level
|
|
95
|
+
for (const { level } of featuresUsed(knowledge)) {
|
|
96
|
+
if (!needed || compareVersions(level, needed) > 0) needed = level
|
|
87
97
|
}
|
|
88
98
|
return needed
|
|
89
99
|
}
|
|
90
100
|
|
|
101
|
+
// What the knowledge needs and _meta.json does not yet say: { level, features }
|
|
102
|
+
// or null. Records added by hand, or by a command older than this check, are
|
|
103
|
+
// the usual cause, and an older package then fails on them with a schema error
|
|
104
|
+
// instead of asking for an upgrade.
|
|
105
|
+
function unrecordedLevel (knowledgeSourceDir, knowledge) {
|
|
106
|
+
const needed = levelNeeded(knowledge)
|
|
107
|
+
if (!needed) return null
|
|
108
|
+
const metaPath = path.join(knowledgeSourceDir, META_FILENAME)
|
|
109
|
+
const recorded = fs.existsSync(metaPath) ? JSON.parse(fs.readFileSync(metaPath, 'utf8')).requiresPackage : null
|
|
110
|
+
if (recorded && compareVersions(recorded, needed) >= 0) return null
|
|
111
|
+
const features = featuresUsed(knowledge)
|
|
112
|
+
.filter(({ level }) => !recorded || compareVersions(level, recorded) > 0)
|
|
113
|
+
.map(({ feature }) => feature)
|
|
114
|
+
return { level: needed, features }
|
|
115
|
+
}
|
|
116
|
+
|
|
91
117
|
// Writes requiresPackage into _meta.json when the knowledge now needs a higher
|
|
92
118
|
// level than it records. Never lowers it: removing the last use of a feature
|
|
93
119
|
// is not worth a write, and an over-cautious level costs an upgrade at most.
|
|
@@ -160,7 +186,9 @@ module.exports = {
|
|
|
160
186
|
FEATURE_LEVEL,
|
|
161
187
|
FEATURES_NEEDING,
|
|
162
188
|
compareVersions,
|
|
189
|
+
featuresUsed,
|
|
163
190
|
levelNeeded,
|
|
191
|
+
unrecordedLevel,
|
|
164
192
|
recordLevelNeeded,
|
|
165
193
|
migrations,
|
|
166
194
|
readMeta,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hippo-digital/hippocampus",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.1",
|
|
4
4
|
"description": "A design-knowledge base for NHS Prototype Kit projects: research, insights, needs, journeys and screens, traceable end to end.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -21,7 +21,7 @@ const fs = require('fs')
|
|
|
21
21
|
const path = require('path')
|
|
22
22
|
const { openWorkbook, readSheetGrid } = require('./lib/xlsx-grid')
|
|
23
23
|
const { KnowledgeSchema } = require('../lib/schema')
|
|
24
|
-
const { readMeta, migrateInMemory } = require('../lib/schema-version')
|
|
24
|
+
const { readMeta, migrateInMemory, recordLevelNeeded } = require('../lib/schema-version')
|
|
25
25
|
const { createContextOrExit } = require('../lib/context')
|
|
26
26
|
const ctx = createContextOrExit()
|
|
27
27
|
const { knowledgeSourceDir } = ctx.paths
|
|
@@ -195,6 +195,8 @@ function main () {
|
|
|
195
195
|
for (const [file, data] of Object.entries(proposed)) {
|
|
196
196
|
fs.writeFileSync(path.join(knowledgeSourceDir, file), `${JSON.stringify(data, null, 2)}\n`)
|
|
197
197
|
}
|
|
198
|
+
const level = recordLevelNeeded(knowledgeSourceDir, migrated)
|
|
199
|
+
if (level) console.log(`This knowledge base now needs Hippocampus ${level} or later. Recorded in _meta.json.`)
|
|
198
200
|
console.log(`\nImported from ${path.relative(ctx.root, path.resolve(args.workbook))}. Run npx hippocampus validate to confirm.`)
|
|
199
201
|
}
|
|
200
202
|
|
|
@@ -6,7 +6,9 @@ const {
|
|
|
6
6
|
META_FILENAME,
|
|
7
7
|
readMeta,
|
|
8
8
|
migrateInMemory,
|
|
9
|
-
writeMeta
|
|
9
|
+
writeMeta,
|
|
10
|
+
unrecordedLevel,
|
|
11
|
+
recordLevelNeeded
|
|
10
12
|
} = require('../lib/schema-version')
|
|
11
13
|
|
|
12
14
|
// The loader migrates in memory and warns on every read. This is the command
|
|
@@ -41,18 +43,30 @@ function main () {
|
|
|
41
43
|
const sourceDir = path.join(project.dir, 'source')
|
|
42
44
|
const meta = readMeta(sourceDir)
|
|
43
45
|
|
|
44
|
-
if (meta.schemaVersion === CURRENT_SCHEMA_VERSION && !meta.implicit) {
|
|
45
|
-
console.log(`${project.name}: already at schemaVersion ${CURRENT_SCHEMA_VERSION}`)
|
|
46
|
-
continue
|
|
47
|
-
}
|
|
48
|
-
|
|
49
46
|
const raw = {}
|
|
50
47
|
for (const [key, filename] of Object.entries(collectionFiles)) {
|
|
51
48
|
const filePath = path.join(sourceDir, filename)
|
|
52
49
|
raw[key] = fs.existsSync(filePath) ? JSON.parse(fs.readFileSync(filePath, 'utf8')) : []
|
|
53
50
|
}
|
|
51
|
+
|
|
52
|
+
if (meta.schemaVersion === CURRENT_SCHEMA_VERSION && !meta.implicit) {
|
|
53
|
+
// Nothing to migrate, but records added by hand may need a package level
|
|
54
|
+
// that _meta.json does not record yet. validate points here for that.
|
|
55
|
+
const unrecorded = unrecordedLevel(sourceDir, raw)
|
|
56
|
+
if (!unrecorded) {
|
|
57
|
+
console.log(`${project.name}: already at schemaVersion ${CURRENT_SCHEMA_VERSION}`)
|
|
58
|
+
} else if (dryRun) {
|
|
59
|
+
console.log(`${project.name}: would record that it needs Hippocampus ${unrecorded.level} (uses ${unrecorded.features.join(', ')})`)
|
|
60
|
+
} else {
|
|
61
|
+
recordLevelNeeded(sourceDir, raw)
|
|
62
|
+
console.log(`${project.name}: recorded that it needs Hippocampus ${unrecorded.level} (uses ${unrecorded.features.join(', ')})`)
|
|
63
|
+
}
|
|
64
|
+
continue
|
|
65
|
+
}
|
|
66
|
+
|
|
54
67
|
raw.project = JSON.parse(fs.readFileSync(path.join(sourceDir, 'project.json'), 'utf8'))
|
|
55
|
-
|
|
68
|
+
const contextPath = path.join(sourceDir, 'project-context.json')
|
|
69
|
+
raw.projectContext = JSON.parse(fs.readFileSync(contextPath, 'utf8'))
|
|
56
70
|
|
|
57
71
|
const { data, version } = migrateInMemory(raw, meta)
|
|
58
72
|
|
|
@@ -69,6 +83,7 @@ function main () {
|
|
|
69
83
|
fs.writeFileSync(filePath, JSON.stringify(data[key], null, 2) + '\n')
|
|
70
84
|
}
|
|
71
85
|
writeMeta(sourceDir, { generator: 'hippocampus migrate:knowledge' })
|
|
86
|
+
recordLevelNeeded(sourceDir, data)
|
|
72
87
|
console.log(`${project.name}: migrated ${meta.schemaVersion} -> ${version}, ${META_FILENAME} stamped`)
|
|
73
88
|
}
|
|
74
89
|
}
|
|
@@ -4,6 +4,7 @@ const { spawnSync } = require('child_process')
|
|
|
4
4
|
const { ResearchImportDraftSchema } = require('../lib/schema')
|
|
5
5
|
const { readAllRecordIds } = require('../lib/collections')
|
|
6
6
|
const { createContextOrExit } = require('../lib/context')
|
|
7
|
+
const { recordLevelNeeded } = require('../lib/schema-version')
|
|
7
8
|
const ctx = createContextOrExit()
|
|
8
9
|
const { knowledgeSourceDir, researchImportsDir, researchManifestPath } = ctx.paths
|
|
9
10
|
|
|
@@ -52,6 +53,10 @@ function main () {
|
|
|
52
53
|
for (const [key, filename] of Object.entries(collections)) {
|
|
53
54
|
writeJson(path.join(dataDir, filename), proposed[key])
|
|
54
55
|
}
|
|
56
|
+
// Before validation, so a package that predates what this draft uses
|
|
57
|
+
// refuses the knowledge base with an upgrade message, not a schema error.
|
|
58
|
+
const level = recordLevelNeeded(dataDir, proposed)
|
|
59
|
+
if (level) console.log(`This knowledge base now needs Hippocampus ${level} or later. Recorded in _meta.json.`)
|
|
55
60
|
|
|
56
61
|
// Run the sibling script directly rather than `npm run <script>`. Those npm
|
|
57
62
|
// scripts exist in this repo and in the demo, and in no host that installs the
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const { createContextOrExit } = require('../lib/context')
|
|
2
|
+
const path = require('path')
|
|
2
3
|
const { lintKnowledge } = require('../lib/lint-knowledge')
|
|
4
|
+
const { unrecordedLevel } = require('../lib/schema-version')
|
|
3
5
|
|
|
4
6
|
const ctx = createContextOrExit()
|
|
5
7
|
const strict = process.argv.includes('--strict')
|
|
@@ -28,6 +30,14 @@ function main () {
|
|
|
28
30
|
console.log(`${project.name}: knowledge data is valid`)
|
|
29
31
|
|
|
30
32
|
for (const warning of warnings) console.warn(` warning ${warning.message}`)
|
|
33
|
+
|
|
34
|
+
// Records added by hand bypass the commands that record the level, and an
|
|
35
|
+
// older package then fails on them with a schema error, not an upgrade.
|
|
36
|
+
const unrecorded = unrecordedLevel(path.join(project.dir, 'source'), knowledge)
|
|
37
|
+
if (unrecorded) {
|
|
38
|
+
console.warn(` warning uses ${unrecorded.features.join(', ')}, which need Hippocampus ${unrecorded.level}, but _meta.json does not say so. Older versions will fail on it instead of asking for an upgrade. Run \`npx hippocampus migrate\` to record it.`)
|
|
39
|
+
if (strict) failed = true
|
|
40
|
+
}
|
|
31
41
|
if (!quiet) {
|
|
32
42
|
for (const info of infos) console.log(` info ${info.message}`)
|
|
33
43
|
}
|