@apollo-annotation/shared 0.3.10 → 0.3.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo-annotation/shared",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "main": "./dist/index.js",
5
5
  "scripts": {
6
6
  "build": "yarn clean && tsc --build",
@@ -10,9 +10,9 @@
10
10
  "test:ci": "NODE_V8_COVERAGE=./coverage glob -c \"tsx --test --test-reporter spec --experimental-test-coverage \" \"**/*.test.ts\""
11
11
  },
12
12
  "dependencies": {
13
- "@apollo-annotation/common": "^0.3.10",
14
- "@apollo-annotation/mst": "^0.3.10",
15
- "@apollo-annotation/schemas": "^0.3.10",
13
+ "@apollo-annotation/common": "^0.3.11",
14
+ "@apollo-annotation/mst": "^0.3.11",
15
+ "@apollo-annotation/schemas": "^0.3.11",
16
16
  "@gmod/gff": "^2.0.0",
17
17
  "@gmod/indexedfasta": "^2.0.4",
18
18
  "@jbrowse/core": "^3.6.5",
@@ -123,6 +123,7 @@ export class AddFeatureChange extends FeatureChange {
123
123
  )
124
124
  featureCnt++
125
125
  } else {
126
+ const indexedIds = this.getIndexedIds(addedFeature, idsToIndex)
126
127
  // Adding new child feature
127
128
  if (parentFeatureId) {
128
129
  const topLevelFeature = await featureModel
@@ -146,11 +147,14 @@ export class AddFeatureChange extends FeatureChange {
146
147
  this.addChild(parentFeature, addedFeature)
147
148
  const childIds = this.getChildFeatureIds(addedFeature)
148
149
  topLevelFeature.allIds.push(_id, ...childIds)
150
+ if (indexedIds.length > 0 && !topLevelFeature.indexedIds) {
151
+ topLevelFeature.indexedIds = []
152
+ }
153
+ topLevelFeature.indexedIds?.push(...indexedIds)
149
154
  await topLevelFeature.save()
150
155
  } else {
151
156
  const childIds = this.getChildFeatureIds(addedFeature)
152
157
  const allIdsV2 = [_id, ...childIds]
153
- const indexedIds = this.getIndexedIds(addedFeature, idsToIndex)
154
158
  const [newFeatureDoc] = await featureModel.create(
155
159
  [{ allIds: allIdsV2, indexedIds, status: 0, ...addedFeature }],
156
160
  { session },
@@ -67,6 +67,12 @@ export class DeleteFeatureChange extends FeatureChange {
67
67
  const { featureModel, session } = backend
68
68
  const { changes, logger } = this
69
69
 
70
+ const { INDEXED_IDS } = process.env
71
+ let idsToIndex: string[] | undefined
72
+ if (INDEXED_IDS) {
73
+ idsToIndex = INDEXED_IDS.split(',')
74
+ }
75
+
70
76
  // Loop the changes
71
77
  for (const change of changes) {
72
78
  const { deletedFeature, parentFeatureId } = change
@@ -105,6 +111,18 @@ export class DeleteFeatureChange extends FeatureChange {
105
111
  featureDoc.allIds = featureDoc.allIds.filter(
106
112
  (id) => !deletedIds.includes(id),
107
113
  )
114
+ const indexedIds = this.getIndexedIds(featureDoc, idsToIndex)
115
+ if (featureDoc.indexedIds) {
116
+ if (indexedIds.length > 0) {
117
+ featureDoc.indexedIds = indexedIds
118
+ } else {
119
+ delete featureDoc.indexedIds
120
+ }
121
+ } else {
122
+ if (indexedIds.length > 0) {
123
+ featureDoc.indexedIds = indexedIds
124
+ }
125
+ }
108
126
  // Save updated document in Mongo
109
127
  featureDoc.markModified('children') // Mark as modified. Without this save() -method is not updating data in database
110
128
  try {
@@ -100,11 +100,24 @@ export class FeatureAttributeChange extends FeatureChange {
100
100
  featuresForChanges.push({ feature: foundFeature, topLevelFeature })
101
101
  }
102
102
 
103
+ const { INDEXED_IDS } = process.env
104
+ let idsToIndex: string[] | undefined
105
+ if (INDEXED_IDS) {
106
+ idsToIndex = INDEXED_IDS.split(',')
107
+ }
103
108
  // Let's update objects
104
109
  for (const [idx, change] of changes.entries()) {
105
110
  const { newAttributes } = change
106
111
  const { feature, topLevelFeature } = featuresForChanges[idx]
112
+ const indexedIdsChanged = idsToIndex?.some(
113
+ (id) => id in newAttributes || id in (feature?.attributes ?? {}),
114
+ )
107
115
  feature.attributes = newAttributes
116
+ if (indexedIdsChanged) {
117
+ const indexedIds = this.getIndexedIds(topLevelFeature, idsToIndex)
118
+ topLevelFeature.indexedIds = indexedIds
119
+ topLevelFeature.markModified('indexedIds')
120
+ }
108
121
  if (topLevelFeature._id.equals(feature._id)) {
109
122
  topLevelFeature.markModified('attributes') // Mark as modified. Without this save() -method is not updating data in database
110
123
  } else {