adapt-authoring-tags 1.3.3 → 1.3.5
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/.github/workflows/releases.yml +9 -24
- package/migrations/1.4.0.js +45 -0
- package/package.json +4 -30
|
@@ -1,32 +1,17 @@
|
|
|
1
1
|
name: Release
|
|
2
|
+
|
|
2
3
|
on:
|
|
3
4
|
push:
|
|
4
5
|
branches:
|
|
5
6
|
- master
|
|
6
7
|
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
issues: write
|
|
11
|
+
pull-requests: write
|
|
12
|
+
id-token: write
|
|
13
|
+
packages: write
|
|
14
|
+
|
|
7
15
|
jobs:
|
|
8
16
|
release:
|
|
9
|
-
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
permissions:
|
|
12
|
-
contents: write # to be able to publish a GitHub release
|
|
13
|
-
issues: write # to be able to comment on released issues
|
|
14
|
-
pull-requests: write # to be able to comment on released pull requests
|
|
15
|
-
id-token: write # to enable use of OIDC for trusted publishing and npm provenance
|
|
16
|
-
steps:
|
|
17
|
-
- name: Checkout
|
|
18
|
-
uses: actions/checkout@v3
|
|
19
|
-
with:
|
|
20
|
-
fetch-depth: 0
|
|
21
|
-
- name: Setup Node.js
|
|
22
|
-
uses: actions/setup-node@v3
|
|
23
|
-
with:
|
|
24
|
-
node-version: 'lts/*'
|
|
25
|
-
- name: Update npm
|
|
26
|
-
run: npm install -g npm@latest
|
|
27
|
-
- name: Install dependencies
|
|
28
|
-
run: npm install
|
|
29
|
-
- name: Release
|
|
30
|
-
env:
|
|
31
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
32
|
-
run: npx semantic-release
|
|
17
|
+
uses: adaptlearning/semantic-release-config/.github/workflows/release.yml@master
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb'
|
|
2
|
+
|
|
3
|
+
const SKIP_COLLECTIONS = new Set(['migrations'])
|
|
4
|
+
|
|
5
|
+
export default function (migration) {
|
|
6
|
+
migration.describe('Normalise tag references to ObjectId form across all collections')
|
|
7
|
+
migration.runCommand(normaliseTags)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function normaliseTags (db, log) {
|
|
11
|
+
const collections = await db.listCollections({}, { nameOnly: true }).toArray()
|
|
12
|
+
for (const { name } of collections) {
|
|
13
|
+
if (SKIP_COLLECTIONS.has(name) || name.startsWith('system.')) continue
|
|
14
|
+
await normaliseCollection(db.collection(name), log)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function normaliseCollection (collection, log) {
|
|
19
|
+
const match = { tags: { $elemMatch: { $type: 'string' } } }
|
|
20
|
+
const docs = await collection.find(match, { projection: { _id: 1, tags: 1 } }).toArray()
|
|
21
|
+
if (!docs.length) return
|
|
22
|
+
|
|
23
|
+
const ops = []
|
|
24
|
+
let unconvertible = 0
|
|
25
|
+
for (const doc of docs) {
|
|
26
|
+
const next = []
|
|
27
|
+
for (const t of doc.tags) {
|
|
28
|
+
if (t instanceof ObjectId) {
|
|
29
|
+
next.push(t)
|
|
30
|
+
} else if (typeof t === 'string' && ObjectId.isValid(t)) {
|
|
31
|
+
next.push(new ObjectId(t))
|
|
32
|
+
} else {
|
|
33
|
+
next.push(t)
|
|
34
|
+
unconvertible++
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
ops.push({ updateOne: { filter: { _id: doc._id }, update: { $set: { tags: next } } } })
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < ops.length; i += 500) {
|
|
41
|
+
await collection.bulkWrite(ops.slice(i, i + 500), { ordered: false })
|
|
42
|
+
}
|
|
43
|
+
log('info', 'migrations', `${collection.collectionName}: normalised tag entries on ${docs.length} document(s)`)
|
|
44
|
+
if (unconvertible) log('warn', 'migrations', `${collection.collectionName}: ${unconvertible} tag entr(ies) could not be coerced to ObjectId and were left as-is`)
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-tags",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "Module for managing tags",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-tags",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -11,44 +11,18 @@
|
|
|
11
11
|
"test": "node --test 'tests/**/*.spec.js'"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
+
"@adaptlearning/semantic-release-config": "^1.0.0",
|
|
14
15
|
"adapt-authoring-server": "^2.1.0",
|
|
15
|
-
"@semantic-release/git": "^10.0.1",
|
|
16
|
-
"conventional-changelog-eslint": "^6.0.0",
|
|
17
|
-
"semantic-release": "^25.0.2",
|
|
18
16
|
"standard": "^17.1.0"
|
|
19
17
|
},
|
|
20
18
|
"release": {
|
|
21
|
-
"
|
|
22
|
-
[
|
|
23
|
-
"@semantic-release/commit-analyzer",
|
|
24
|
-
{
|
|
25
|
-
"preset": "eslint"
|
|
26
|
-
}
|
|
27
|
-
],
|
|
28
|
-
[
|
|
29
|
-
"@semantic-release/release-notes-generator",
|
|
30
|
-
{
|
|
31
|
-
"preset": "eslint"
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
"@semantic-release/npm",
|
|
35
|
-
"@semantic-release/github",
|
|
36
|
-
[
|
|
37
|
-
"@semantic-release/git",
|
|
38
|
-
{
|
|
39
|
-
"assets": [
|
|
40
|
-
"package.json"
|
|
41
|
-
],
|
|
42
|
-
"message": "Chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
]
|
|
19
|
+
"extends": "@adaptlearning/semantic-release-config"
|
|
46
20
|
},
|
|
47
21
|
"dependencies": {
|
|
48
22
|
"adapt-authoring-api": "^3.0.0"
|
|
49
23
|
},
|
|
50
24
|
"peerDependencies": {
|
|
51
|
-
"adapt-authoring-core": "^
|
|
25
|
+
"adapt-authoring-core": "^3.0.0",
|
|
52
26
|
"adapt-authoring-jsonschema": "^1.2.0",
|
|
53
27
|
"adapt-authoring-mongodb": "^3.0.0"
|
|
54
28
|
}
|