@apollo-annotation/common 0.3.6 → 0.3.7

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/common",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/GMOD/Apollo3.git",
@@ -11,13 +11,13 @@
11
11
  "build": "tsc"
12
12
  },
13
13
  "dependencies": {
14
- "@apollo-annotation/schemas": "^0.3.6",
14
+ "@apollo-annotation/schemas": "^0.3.7",
15
15
  "@jbrowse/core": "^3.0.1",
16
16
  "bson-objectid": "^2.0.4",
17
17
  "tslib": "^2.3.1"
18
18
  },
19
19
  "devDependencies": {
20
- "@apollo-annotation/mst": "^0.3.6",
20
+ "@apollo-annotation/mst": "^0.3.7",
21
21
  "@nestjs/common": "^10.1.0",
22
22
  "@nestjs/core": "^10.1.0",
23
23
  "@types/node": "^18.14.2",
@@ -116,4 +116,69 @@ export abstract class FeatureChange extends AssemblySpecificChange {
116
116
  _id: newId,
117
117
  }
118
118
  }
119
+
120
+ addChild(parentFeature: Feature, child: AnnotationFeatureSnapshot) {
121
+ if (!parentFeature.attributes?._id) {
122
+ let { attributes } = parentFeature
123
+ if (!attributes) {
124
+ attributes = {}
125
+ }
126
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
127
+ attributes = {
128
+ _id: [parentFeature._id.toString()],
129
+ // eslint-disable-next-line unicorn/prefer-structured-clone
130
+ ...JSON.parse(JSON.stringify(attributes)),
131
+ }
132
+ parentFeature.attributes = attributes
133
+ }
134
+ const { _id } = child
135
+ if (!parentFeature.children) {
136
+ parentFeature.children = new Map()
137
+ }
138
+ parentFeature.children.set(_id, {
139
+ allIds: [],
140
+ ...child,
141
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
142
+ // @ts-expect-error
143
+ _id,
144
+ })
145
+ // Child features should be sorted for click and drag of gene glyphs to work properly
146
+ parentFeature.children = new Map(
147
+ [...parentFeature.children.entries()].sort((a, b) => a[1].min - b[1].min),
148
+ )
149
+ }
150
+
151
+ /**
152
+ * Delete feature's subfeatures that match an ID and return the IDs of any
153
+ * sub-subfeatures that were deleted
154
+ * @param feature -
155
+ * @param featureIdToDelete -
156
+ * @returns - list of deleted feature IDs
157
+ */
158
+ findAndDeleteChildFeature(
159
+ feature: Feature,
160
+ featureIdToDelete: string,
161
+ ): string[] {
162
+ if (!feature.children) {
163
+ throw new Error(`Feature ${feature._id.toHexString()} has no children`)
164
+ }
165
+ const { _id, children } = feature
166
+ const child = children.get(featureIdToDelete)
167
+ if (child) {
168
+ const deletedIds = this.getChildFeatureIds(child)
169
+ children.delete(featureIdToDelete)
170
+ return deletedIds
171
+ }
172
+ for (const [, childFeature] of children) {
173
+ try {
174
+ return this.findAndDeleteChildFeature(childFeature, featureIdToDelete)
175
+ } catch {
176
+ // pass
177
+ }
178
+ }
179
+
180
+ throw new Error(
181
+ `Feature "${featureIdToDelete}" not found in ${_id.toHexString()}`,
182
+ )
183
+ }
119
184
  }