@apollo-annotation/shared 0.3.12 → 1.0.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.
Files changed (170) hide show
  1. package/dist/Changes/{DeleteFeatureChange.d.ts → AddAndDeleteFeatureChanges.d.ts} +26 -11
  2. package/dist/Changes/AddAndDeleteFeatureChanges.d.ts.map +1 -0
  3. package/dist/Changes/AddAndDeleteFeatureChanges.js +117 -0
  4. package/dist/Changes/AddAndDeleteFeatureChanges.js.map +1 -0
  5. package/dist/Changes/AddAssemblyAliasesChange.d.ts +1 -4
  6. package/dist/Changes/AddAssemblyAliasesChange.d.ts.map +1 -1
  7. package/dist/Changes/AddAssemblyAliasesChange.js +0 -27
  8. package/dist/Changes/AddAssemblyAliasesChange.js.map +1 -1
  9. package/dist/Changes/AddAssemblyAndFeaturesFromFileChange.d.ts +2 -11
  10. package/dist/Changes/AddAssemblyAndFeaturesFromFileChange.d.ts.map +1 -1
  11. package/dist/Changes/AddAssemblyAndFeaturesFromFileChange.js +2 -82
  12. package/dist/Changes/AddAssemblyAndFeaturesFromFileChange.js.map +1 -1
  13. package/dist/Changes/AddAssemblyFromExternalChange.d.ts +1 -9
  14. package/dist/Changes/AddAssemblyFromExternalChange.d.ts.map +1 -1
  15. package/dist/Changes/AddAssemblyFromExternalChange.js +0 -72
  16. package/dist/Changes/AddAssemblyFromExternalChange.js.map +1 -1
  17. package/dist/Changes/AddAssemblyFromFileChange.d.ts +2 -17
  18. package/dist/Changes/AddAssemblyFromFileChange.d.ts.map +1 -1
  19. package/dist/Changes/AddAssemblyFromFileChange.js +2 -119
  20. package/dist/Changes/AddAssemblyFromFileChange.js.map +1 -1
  21. package/dist/Changes/AddFeaturesFromFileChange.d.ts +2 -11
  22. package/dist/Changes/AddFeaturesFromFileChange.d.ts.map +1 -1
  23. package/dist/Changes/AddFeaturesFromFileChange.js +2 -66
  24. package/dist/Changes/AddFeaturesFromFileChange.js.map +1 -1
  25. package/dist/Changes/AddRefSeqAliasesChange.d.ts +1 -4
  26. package/dist/Changes/AddRefSeqAliasesChange.d.ts.map +1 -1
  27. package/dist/Changes/AddRefSeqAliasesChange.js +0 -34
  28. package/dist/Changes/AddRefSeqAliasesChange.js.map +1 -1
  29. package/dist/Changes/DeleteAssemblyChange.d.ts +1 -9
  30. package/dist/Changes/DeleteAssemblyChange.d.ts.map +1 -1
  31. package/dist/Changes/DeleteAssemblyChange.js +0 -53
  32. package/dist/Changes/DeleteAssemblyChange.js.map +1 -1
  33. package/dist/Changes/DeleteUserChange.d.ts +1 -4
  34. package/dist/Changes/DeleteUserChange.d.ts.map +1 -1
  35. package/dist/Changes/DeleteUserChange.js +0 -19
  36. package/dist/Changes/DeleteUserChange.js.map +1 -1
  37. package/dist/Changes/FeatureAttributeChange.d.ts +1 -9
  38. package/dist/Changes/FeatureAttributeChange.d.ts.map +1 -1
  39. package/dist/Changes/FeatureAttributeChange.js +0 -82
  40. package/dist/Changes/FeatureAttributeChange.js.map +1 -1
  41. package/dist/Changes/ImportJBrowseConfigChange.d.ts +1 -4
  42. package/dist/Changes/ImportJBrowseConfigChange.d.ts.map +1 -1
  43. package/dist/Changes/ImportJBrowseConfigChange.js +1 -18
  44. package/dist/Changes/ImportJBrowseConfigChange.js.map +1 -1
  45. package/dist/Changes/LocationEndChange.d.ts +1 -9
  46. package/dist/Changes/LocationEndChange.d.ts.map +1 -1
  47. package/dist/Changes/LocationEndChange.js +0 -90
  48. package/dist/Changes/LocationEndChange.js.map +1 -1
  49. package/dist/Changes/LocationStartChange.d.ts +1 -9
  50. package/dist/Changes/LocationStartChange.d.ts.map +1 -1
  51. package/dist/Changes/LocationStartChange.js +0 -90
  52. package/dist/Changes/LocationStartChange.js.map +1 -1
  53. package/dist/Changes/MergeAndUndoMergeExonsChanges.d.ts +46 -0
  54. package/dist/Changes/MergeAndUndoMergeExonsChanges.d.ts.map +1 -0
  55. package/dist/Changes/MergeAndUndoMergeExonsChanges.js +83 -0
  56. package/dist/Changes/MergeAndUndoMergeExonsChanges.js.map +1 -0
  57. package/dist/Changes/{MergeTranscriptsChange.d.ts → MergeAndUndoMergeTranscriptsChanges.d.ts} +22 -6
  58. package/dist/Changes/MergeAndUndoMergeTranscriptsChanges.d.ts.map +1 -0
  59. package/dist/Changes/{MergeTranscriptsChange.js → MergeAndUndoMergeTranscriptsChanges.js} +40 -50
  60. package/dist/Changes/MergeAndUndoMergeTranscriptsChanges.js.map +1 -0
  61. package/dist/Changes/SplitAndUndoSplitExonChanges.d.ts +55 -0
  62. package/dist/Changes/SplitAndUndoSplitExonChanges.d.ts.map +1 -0
  63. package/dist/Changes/SplitAndUndoSplitExonChanges.js +115 -0
  64. package/dist/Changes/SplitAndUndoSplitExonChanges.js.map +1 -0
  65. package/dist/Changes/StrandChange.d.ts +1 -9
  66. package/dist/Changes/StrandChange.d.ts.map +1 -1
  67. package/dist/Changes/StrandChange.js +0 -77
  68. package/dist/Changes/StrandChange.js.map +1 -1
  69. package/dist/Changes/TypeChange.d.ts +1 -9
  70. package/dist/Changes/TypeChange.d.ts.map +1 -1
  71. package/dist/Changes/TypeChange.js +0 -77
  72. package/dist/Changes/TypeChange.js.map +1 -1
  73. package/dist/Changes/UserChange.d.ts +1 -4
  74. package/dist/Changes/UserChange.d.ts.map +1 -1
  75. package/dist/Changes/UserChange.js +0 -23
  76. package/dist/Changes/UserChange.js.map +1 -1
  77. package/dist/Changes/index.d.ts +29 -22
  78. package/dist/Changes/index.d.ts.map +1 -1
  79. package/dist/Changes/index.js +19 -24
  80. package/dist/Changes/index.js.map +1 -1
  81. package/dist/Validations/Validation.d.ts +2 -2
  82. package/dist/Validations/Validation.d.ts.map +1 -1
  83. package/dist/Validations/Validation.js +1 -1
  84. package/dist/Validations/Validation.js.map +1 -1
  85. package/dist/Validations/ValidationSet.d.ts +2 -2
  86. package/dist/Validations/ValidationSet.d.ts.map +1 -1
  87. package/dist/Validations/ValidationSet.js +2 -2
  88. package/dist/Validations/ValidationSet.js.map +1 -1
  89. package/dist/index.d.ts +0 -1
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +0 -1
  92. package/dist/index.js.map +1 -1
  93. package/dist/tsconfig.tsbuildinfo +1 -1
  94. package/package.json +9 -4
  95. package/src/Changes/{DeleteFeatureChange.ts → AddAndDeleteFeatureChanges.ts} +77 -107
  96. package/src/Changes/AddAssemblyAliasesChange.ts +0 -35
  97. package/src/Changes/AddAssemblyAndFeaturesFromFileChange.ts +5 -108
  98. package/src/Changes/AddAssemblyFromExternalChange.ts +0 -87
  99. package/src/Changes/AddAssemblyFromFileChange.ts +5 -169
  100. package/src/Changes/AddFeaturesFromFileChange.ts +5 -86
  101. package/src/Changes/AddRefSeqAliasesChange.ts +0 -44
  102. package/src/Changes/DeleteAssemblyChange.ts +0 -72
  103. package/src/Changes/DeleteUserChange.ts +0 -25
  104. package/src/Changes/FeatureAttributeChange.ts +0 -104
  105. package/src/Changes/ImportJBrowseConfigChange.ts +1 -27
  106. package/src/Changes/LocationEndChange.ts +0 -100
  107. package/src/Changes/LocationStartChange.ts +0 -100
  108. package/src/Changes/{MergeExonsChange.ts → MergeAndUndoMergeExonsChanges.ts} +70 -90
  109. package/src/Changes/{MergeTranscriptsChange.ts → MergeAndUndoMergeTranscriptsChanges.ts} +74 -66
  110. package/src/Changes/{SplitExonChange.ts → SplitAndUndoSplitExonChanges.ts} +95 -122
  111. package/src/Changes/StrandChange.ts +0 -94
  112. package/src/Changes/TypeChange.ts +0 -94
  113. package/src/Changes/UserChange.ts +0 -30
  114. package/src/Changes/index.ts +32 -24
  115. package/src/Validations/Validation.ts +2 -5
  116. package/src/Validations/ValidationSet.ts +3 -6
  117. package/src/index.ts +0 -1
  118. package/dist/Changes/AddFeatureChange.d.ts +0 -37
  119. package/dist/Changes/AddFeatureChange.d.ts.map +0 -1
  120. package/dist/Changes/AddFeatureChange.js +0 -169
  121. package/dist/Changes/AddFeatureChange.js.map +0 -1
  122. package/dist/Changes/DeleteFeatureChange.d.ts.map +0 -1
  123. package/dist/Changes/DeleteFeatureChange.js +0 -161
  124. package/dist/Changes/DeleteFeatureChange.js.map +0 -1
  125. package/dist/Changes/FromFileBaseChange.d.ts +0 -12
  126. package/dist/Changes/FromFileBaseChange.d.ts.map +0 -1
  127. package/dist/Changes/FromFileBaseChange.js +0 -196
  128. package/dist/Changes/FromFileBaseChange.js.map +0 -1
  129. package/dist/Changes/MergeExonsChange.d.ts +0 -30
  130. package/dist/Changes/MergeExonsChange.d.ts.map +0 -1
  131. package/dist/Changes/MergeExonsChange.js +0 -110
  132. package/dist/Changes/MergeExonsChange.js.map +0 -1
  133. package/dist/Changes/MergeTranscriptsChange.d.ts.map +0 -1
  134. package/dist/Changes/MergeTranscriptsChange.js.map +0 -1
  135. package/dist/Changes/SplitExonChange.d.ts +0 -34
  136. package/dist/Changes/SplitExonChange.d.ts.map +0 -1
  137. package/dist/Changes/SplitExonChange.js +0 -138
  138. package/dist/Changes/SplitExonChange.js.map +0 -1
  139. package/dist/Changes/UndoMergeExonsChange.d.ts +0 -28
  140. package/dist/Changes/UndoMergeExonsChange.d.ts.map +0 -1
  141. package/dist/Changes/UndoMergeExonsChange.js +0 -100
  142. package/dist/Changes/UndoMergeExonsChange.js.map +0 -1
  143. package/dist/Changes/UndoMergeTranscriptsChange.d.ts +0 -28
  144. package/dist/Changes/UndoMergeTranscriptsChange.d.ts.map +0 -1
  145. package/dist/Changes/UndoMergeTranscriptsChange.js +0 -100
  146. package/dist/Changes/UndoMergeTranscriptsChange.js.map +0 -1
  147. package/dist/Changes/UndoSplitExonChange.d.ts +0 -33
  148. package/dist/Changes/UndoSplitExonChange.d.ts.map +0 -1
  149. package/dist/Changes/UndoSplitExonChange.js +0 -107
  150. package/dist/Changes/UndoSplitExonChange.js.map +0 -1
  151. package/dist/Operations/GetAssembliesOperation.d.ts +0 -12
  152. package/dist/Operations/GetAssembliesOperation.d.ts.map +0 -1
  153. package/dist/Operations/GetAssembliesOperation.js +0 -16
  154. package/dist/Operations/GetAssembliesOperation.js.map +0 -1
  155. package/dist/Operations/GetFeaturesOperation.d.ts +0 -27
  156. package/dist/Operations/GetFeaturesOperation.d.ts.map +0 -1
  157. package/dist/Operations/GetFeaturesOperation.js +0 -38
  158. package/dist/Operations/GetFeaturesOperation.js.map +0 -1
  159. package/dist/Operations/index.d.ts +0 -9
  160. package/dist/Operations/index.d.ts.map +0 -1
  161. package/dist/Operations/index.js +0 -6
  162. package/dist/Operations/index.js.map +0 -1
  163. package/src/Changes/AddFeatureChange.ts +0 -236
  164. package/src/Changes/FromFileBaseChange.ts +0 -231
  165. package/src/Changes/UndoMergeExonsChange.ts +0 -149
  166. package/src/Changes/UndoMergeTranscriptsChange.ts +0 -153
  167. package/src/Changes/UndoSplitExonChange.ts +0 -174
  168. package/src/Operations/GetAssembliesOperation.ts +0 -28
  169. package/src/Operations/GetFeaturesOperation.ts +0 -58
  170. package/src/Operations/index.ts +0 -6
@@ -1,15 +1,9 @@
1
- /* eslint-disable @typescript-eslint/restrict-template-expressions */
2
- /* eslint-disable @typescript-eslint/require-await */
3
1
  /* eslint-disable @typescript-eslint/no-unnecessary-condition */
4
2
  import {
5
3
  type ChangeOptions,
6
- type ClientDataStore,
7
4
  FeatureChange,
8
- type LocalGFF3DataStore,
9
5
  type SerializedFeatureChange,
10
- type ServerDataStore,
11
6
  } from '@apollo-annotation/common'
12
- import type { Feature, FeatureDocument } from '@apollo-annotation/schemas'
13
7
 
14
8
  interface SerializedLocationEndChangeBase extends SerializedFeatureChange {
15
9
  typeName: 'LocationEndChange'
@@ -52,100 +46,6 @@ export class LocationEndChange extends FeatureChange {
52
46
  return { typeName, changedIds, assembly, changes }
53
47
  }
54
48
 
55
- /**
56
- * Applies the required change to database
57
- * @param backend - parameters from backend
58
- * @returns
59
- */
60
- async executeOnServer(backend: ServerDataStore) {
61
- const { featureModel, session } = backend
62
- const { changes, logger } = this
63
- // Let's first check that all features are found and those old values match with expected ones. We do this just to be sure that all changes can be done.
64
- const topLevelFeatures: FeatureDocument[] = []
65
- for (const change of changes) {
66
- const { featureId, oldEnd, newEnd } = change
67
-
68
- // See if we already have top-level feature for this feature
69
- let topLevelFeature: FeatureDocument | undefined | null
70
- let feature: Feature | undefined | null
71
- for (const tlv of topLevelFeatures) {
72
- const childFeature = this.getFeatureFromId(tlv, featureId)
73
- if (childFeature) {
74
- topLevelFeature = tlv
75
- feature = childFeature
76
- break
77
- }
78
- }
79
- if (!topLevelFeature) {
80
- // Don't already have top-level feature, so let's query it
81
- topLevelFeature = await featureModel
82
- .findOne({ allIds: featureId })
83
- .session(session)
84
- .exec()
85
- if (topLevelFeature) {
86
- topLevelFeatures.push(topLevelFeature)
87
- }
88
- }
89
-
90
- if (!topLevelFeature) {
91
- const errMsg = `*** ERROR: The following featureId was not found in database ='${featureId}'`
92
- logger.error(errMsg)
93
- throw new Error(errMsg)
94
- // throw new NotFoundException(errMsg) -- This is causing runtime error because Exception comes from @nestjs/common!!!
95
- }
96
- logger.debug?.(
97
- `*** TOP level feature found: ${JSON.stringify(topLevelFeature)}`,
98
- )
99
-
100
- if (!feature) {
101
- feature = this.getFeatureFromId(topLevelFeature, featureId)
102
- }
103
- if (!feature) {
104
- const errMsg = 'ERROR when searching feature by featureId'
105
- logger.error(errMsg)
106
- throw new Error(errMsg)
107
- }
108
- logger.debug?.(`*** Found feature: ${JSON.stringify(feature)}`)
109
- if (feature.max !== oldEnd) {
110
- const errMsg = 'Expected previous max does not match'
111
- logger.error(errMsg)
112
- throw new Error(errMsg)
113
- }
114
- feature.max = newEnd
115
- if (topLevelFeature._id.equals(feature._id)) {
116
- topLevelFeature.markModified('end') // Mark as modified. Without this save() -method is not updating data in database
117
- } else {
118
- topLevelFeature.markModified('children') // Mark as modified. Without this save() -method is not updating data in database
119
- }
120
- }
121
- for (const tlv of topLevelFeatures) {
122
- try {
123
- await tlv.save()
124
- } catch (error) {
125
- logger.debug?.(`*** FAILED: ${error}`)
126
- throw error
127
- }
128
- }
129
- }
130
-
131
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
132
- throw new Error('executeOnLocalGFF3 not implemented')
133
- }
134
-
135
- async executeOnClient(dataStore: ClientDataStore) {
136
- if (!dataStore) {
137
- throw new Error('No data store')
138
- }
139
- for (const change of this.changes) {
140
- const { featureId, newEnd } = change
141
- const feature = dataStore.getFeature(featureId)
142
- if (!feature) {
143
- throw new Error(`Could not find feature with identifier "${featureId}"`)
144
- }
145
- feature.setMax(newEnd)
146
- }
147
- }
148
-
149
49
  getInverse() {
150
50
  const { assembly, changedIds, changes, logger, typeName } = this
151
51
  const inverseChangedIds = [...changedIds].reverse()
@@ -1,15 +1,9 @@
1
- /* eslint-disable @typescript-eslint/restrict-template-expressions */
2
- /* eslint-disable @typescript-eslint/require-await */
3
1
  /* eslint-disable @typescript-eslint/no-unnecessary-condition */
4
2
  import {
5
3
  type ChangeOptions,
6
- type ClientDataStore,
7
4
  FeatureChange,
8
- type LocalGFF3DataStore,
9
5
  type SerializedFeatureChange,
10
- type ServerDataStore,
11
6
  } from '@apollo-annotation/common'
12
- import type { Feature, FeatureDocument } from '@apollo-annotation/schemas'
13
7
 
14
8
  interface SerializedLocationStartChangeBase extends SerializedFeatureChange {
15
9
  typeName: 'LocationStartChange'
@@ -52,100 +46,6 @@ export class LocationStartChange extends FeatureChange {
52
46
  return { typeName, changedIds, assembly, changes }
53
47
  }
54
48
 
55
- /**
56
- * Applies the required change to database
57
- * @param backend - parameters from backend
58
- * @returns
59
- */
60
- async executeOnServer(backend: ServerDataStore) {
61
- const { featureModel, session } = backend
62
- const { changes, logger } = this
63
- // Let's first check that all features are found and those old values match with expected ones. We do this just to be sure that all changes can be done.
64
- const topLevelFeatures: FeatureDocument[] = []
65
- for (const change of changes) {
66
- const { featureId, oldStart, newStart } = change
67
-
68
- // See if we already have top-level feature for this feature
69
- let topLevelFeature: FeatureDocument | undefined | null
70
- let feature: Feature | undefined | null
71
- for (const tlv of topLevelFeatures) {
72
- const childFeature = this.getFeatureFromId(tlv, featureId)
73
- if (childFeature) {
74
- topLevelFeature = tlv
75
- feature = childFeature
76
- break
77
- }
78
- }
79
- if (!topLevelFeature) {
80
- // Don't already have top-level feature, so let's query it
81
- topLevelFeature = await featureModel
82
- .findOne({ allIds: featureId })
83
- .session(session)
84
- .exec()
85
- if (topLevelFeature) {
86
- topLevelFeatures.push(topLevelFeature)
87
- }
88
- }
89
-
90
- if (!topLevelFeature) {
91
- const errMsg = `*** ERROR: The following featureId was not found in database ='${featureId}'`
92
- logger.error(errMsg)
93
- throw new Error(errMsg)
94
- // throw new NotFoundException(errMsg) -- This is causing runtime error because Exception comes from @nestjs/common!!!
95
- }
96
- logger.debug?.(
97
- `*** TOP level feature found: ${JSON.stringify(topLevelFeature)}`,
98
- )
99
-
100
- if (!feature) {
101
- feature = this.getFeatureFromId(topLevelFeature, featureId)
102
- }
103
- if (!feature) {
104
- const errMsg = 'ERROR when searching feature by featureId'
105
- logger.error(errMsg)
106
- throw new Error(errMsg)
107
- }
108
- logger.debug?.(`*** Found feature: ${JSON.stringify(feature)}`)
109
- if (feature.min !== oldStart) {
110
- const errMsg = 'Expected previous max does not match'
111
- logger.error(errMsg)
112
- throw new Error(errMsg)
113
- }
114
- feature.min = newStart
115
- if (topLevelFeature._id.equals(feature._id)) {
116
- topLevelFeature.markModified('start') // Mark as modified. Without this save() -method is not updating data in database
117
- } else {
118
- topLevelFeature.markModified('children') // Mark as modified. Without this save() -method is not updating data in database
119
- }
120
- }
121
- for (const tlv of topLevelFeatures) {
122
- try {
123
- await tlv.save()
124
- } catch (error) {
125
- logger.debug?.(`*** FAILED: ${error}`)
126
- throw error
127
- }
128
- }
129
- }
130
-
131
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
132
- throw new Error('executeOnLocalGFF3 not implemented')
133
- }
134
-
135
- async executeOnClient(dataStore: ClientDataStore) {
136
- if (!dataStore) {
137
- throw new Error('No data store')
138
- }
139
- for (const change of this.changes) {
140
- const { featureId, newStart } = change
141
- const feature = dataStore.getFeature(featureId)
142
- if (!feature) {
143
- throw new Error(`Could not find feature with identifier "${featureId}"`)
144
- }
145
- feature.setMin(newStart)
146
- }
147
- }
148
-
149
49
  getInverse() {
150
50
  const { assembly, changedIds, changes, logger, typeName } = this
151
51
  const inverseChangedIds = [...changedIds].reverse()
@@ -1,22 +1,10 @@
1
- /* eslint-disable unicorn/prefer-structured-clone */
2
- /* eslint-disable @typescript-eslint/require-await */
3
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
-
5
1
  import {
6
2
  type ChangeOptions,
7
- type ClientDataStore,
8
3
  FeatureChange,
9
- type LocalGFF3DataStore,
10
4
  type SerializedFeatureChange,
11
- type ServerDataStore,
12
5
  } from '@apollo-annotation/common'
13
6
  import type { AnnotationFeatureSnapshot } from '@apollo-annotation/mst'
14
7
 
15
- import { attributesToRecords, stringifyAttributes } from '../util.js'
16
-
17
- import { findAndDeleteChildFeature } from './DeleteFeatureChange.js'
18
- import { UndoMergeExonsChange } from './UndoMergeExonsChange.js'
19
-
20
8
  interface SerializedMergeExonsChangeBase extends SerializedFeatureChange {
21
9
  typeName: 'MergeExonsChange'
22
10
  }
@@ -40,6 +28,28 @@ export type SerializedMergeExonsChange =
40
28
  | SerializedMergeExonsChangeSingle
41
29
  | SerializedMergeExonsChangeMultiple
42
30
 
31
+ interface SerializedUndoMergeExonsChangeBase extends SerializedFeatureChange {
32
+ typeName: 'UndoMergeExonsChange'
33
+ }
34
+
35
+ export interface UndoMergeExonsChangeDetails {
36
+ exonsToRestore: AnnotationFeatureSnapshot[]
37
+ parentFeatureId: string
38
+ }
39
+
40
+ interface SerializedUndoMergeExonsChangeSingle
41
+ extends SerializedUndoMergeExonsChangeBase,
42
+ UndoMergeExonsChangeDetails {}
43
+
44
+ interface SerializedUndoMergeExonsChangeMultiple
45
+ extends SerializedUndoMergeExonsChangeBase {
46
+ changes: UndoMergeExonsChangeDetails[]
47
+ }
48
+
49
+ export type SerializedUndoMergeExonsChange =
50
+ | SerializedUndoMergeExonsChangeSingle
51
+ | SerializedUndoMergeExonsChangeMultiple
52
+
43
53
  export class MergeExonsChange extends FeatureChange {
44
54
  typeName = 'MergeExonsChange' as const
45
55
  changes: MergeExonsChangeDetails[]
@@ -70,84 +80,6 @@ export class MergeExonsChange extends FeatureChange {
70
80
  return { typeName, changedIds, assembly, changes }
71
81
  }
72
82
 
73
- async executeOnServer(backend: ServerDataStore) {
74
- const { featureModel, session } = backend
75
- const { changes, logger } = this
76
- for (const change of changes) {
77
- const { firstExon, secondExon } = change
78
- const topLevelFeature = await featureModel
79
- .findOne({ allIds: firstExon._id })
80
- .session(session)
81
- .exec()
82
- if (!topLevelFeature) {
83
- const errMsg = `*** ERROR: The following featureId was not found in database ='${firstExon._id}'`
84
- logger.error(errMsg)
85
- throw new Error(errMsg)
86
- }
87
- const mergedExon = this.getFeatureFromId(topLevelFeature, firstExon._id)
88
- if (!mergedExon) {
89
- const errMsg = 'ERROR when searching feature by featureId'
90
- logger.error(errMsg)
91
- throw new Error(errMsg)
92
- }
93
- mergedExon.min = Math.min(firstExon.min, secondExon.min)
94
- mergedExon.max = Math.max(firstExon.max, secondExon.max)
95
-
96
- const mergedAttributes: Record<string, string[]> = mergedExon.attributes
97
- ? JSON.parse(JSON.stringify(mergedExon.attributes))
98
- : {}
99
- mergedAttributes.merged_with = [
100
- stringifyAttributes(attributesToRecords(secondExon.attributes)),
101
- ]
102
- mergedExon.attributes = mergedAttributes
103
-
104
- const deletedIds = findAndDeleteChildFeature(
105
- topLevelFeature,
106
- secondExon._id,
107
- this,
108
- )
109
- deletedIds.push(secondExon._id)
110
- topLevelFeature.allIds = topLevelFeature.allIds.filter(
111
- (id) => !deletedIds.includes(id),
112
- )
113
- await topLevelFeature.save()
114
- }
115
- }
116
-
117
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
118
- throw new Error('executeOnLocalGFF3 not implemented')
119
- }
120
-
121
- async executeOnClient(dataStore: ClientDataStore) {
122
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
123
- if (!dataStore) {
124
- throw new Error('No data store')
125
- }
126
-
127
- for (const change of this.changes) {
128
- const { firstExon, secondExon } = change
129
- const mergedExon = dataStore.getFeature(firstExon._id)
130
- if (!mergedExon) {
131
- throw new Error(
132
- `Could not find feature with identifier "${firstExon._id}"`,
133
- )
134
- }
135
- mergedExon.setMin(Math.min(firstExon.min, secondExon.min))
136
- mergedExon.setMax(Math.max(firstExon.max, secondExon.max))
137
-
138
- const mrg = mergedExon.attributes.get('merged_with')?.slice() ?? []
139
- const mergedWith = stringifyAttributes(
140
- attributesToRecords(secondExon.attributes),
141
- )
142
- if (!mrg.includes(mergedWith)) {
143
- mrg.push(mergedWith)
144
- }
145
- mergedExon.setAttribute('merged_with', mrg)
146
-
147
- mergedExon.parent?.deleteChild(secondExon._id)
148
- }
149
- }
150
-
151
83
  getInverse() {
152
84
  const { assembly, changedIds, changes, logger } = this
153
85
  const inverseChangedIds = [...changedIds].reverse()
@@ -199,3 +131,51 @@ export class MergeExonsChange extends FeatureChange {
199
131
  // return mergedAttrs
200
132
  // }
201
133
  }
134
+
135
+ export class UndoMergeExonsChange extends FeatureChange {
136
+ typeName = 'UndoMergeExonsChange' as const
137
+ changes: UndoMergeExonsChangeDetails[]
138
+
139
+ constructor(json: SerializedUndoMergeExonsChange, options?: ChangeOptions) {
140
+ super(json, options)
141
+ this.changes = 'changes' in json ? json.changes : [json]
142
+ }
143
+
144
+ toJSON(): SerializedUndoMergeExonsChange {
145
+ const { assembly, changedIds, changes, typeName } = this
146
+ if (changes.length === 1) {
147
+ const [{ exonsToRestore, parentFeatureId }] = changes
148
+
149
+ return {
150
+ typeName,
151
+ changedIds,
152
+ assembly,
153
+ exonsToRestore,
154
+ parentFeatureId,
155
+ }
156
+ }
157
+ return { typeName, changedIds, assembly, changes }
158
+ }
159
+
160
+ getInverse() {
161
+ const { assembly, changedIds, changes, logger } = this
162
+ const inverseChangedIds = [...changedIds].reverse()
163
+ const inverseChanges = [...changes]
164
+ .reverse()
165
+ .map((undoMergeExonsChange) => ({
166
+ firstExon: undoMergeExonsChange.exonsToRestore[0],
167
+ secondExon: undoMergeExonsChange.exonsToRestore[1],
168
+ parentFeatureId: undoMergeExonsChange.parentFeatureId,
169
+ }))
170
+
171
+ return new MergeExonsChange(
172
+ {
173
+ changedIds: inverseChangedIds,
174
+ typeName: 'MergeExonsChange',
175
+ changes: inverseChanges,
176
+ assembly,
177
+ },
178
+ { logger },
179
+ )
180
+ }
181
+ }
@@ -1,14 +1,10 @@
1
1
  /* eslint-disable unicorn/prefer-structured-clone */
2
- /* eslint-disable @typescript-eslint/require-await */
3
2
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
3
 
5
4
  import {
6
5
  type ChangeOptions,
7
- type ClientDataStore,
8
6
  FeatureChange,
9
- type LocalGFF3DataStore,
10
7
  type SerializedFeatureChange,
11
- type ServerDataStore,
12
8
  } from '@apollo-annotation/common'
13
9
  import type {
14
10
  AnnotationFeature,
@@ -20,9 +16,6 @@ import { getSnapshot } from '@jbrowse/mobx-state-tree'
20
16
 
21
17
  import { attributesToRecords, stringifyAttributes } from '../util.js'
22
18
 
23
- import { findAndDeleteChildFeature } from './DeleteFeatureChange.js'
24
- import { UndoMergeTranscriptsChange } from './UndoMergeTranscriptsChange.js'
25
-
26
19
  interface SerializedMergeTranscriptsChangeBase extends SerializedFeatureChange {
27
20
  typeName: 'MergeTranscriptsChange'
28
21
  }
@@ -46,6 +39,29 @@ export type SerializedMergeTranscriptsChange =
46
39
  | SerializedMergeTranscriptsChangeSingle
47
40
  | SerializedMergeTranscriptsChangeMultiple
48
41
 
42
+ interface SerializedUndoMergeTranscriptsChangeBase
43
+ extends SerializedFeatureChange {
44
+ typeName: 'UndoMergeTranscriptsChange'
45
+ }
46
+
47
+ export interface UndoMergeTranscriptsChangeDetails {
48
+ transcriptsToRestore: AnnotationFeatureSnapshot[]
49
+ parentFeatureId: string
50
+ }
51
+
52
+ interface SerializedUndoMergeTranscriptsChangeSingle
53
+ extends SerializedUndoMergeTranscriptsChangeBase,
54
+ UndoMergeTranscriptsChangeDetails {}
55
+
56
+ interface SerializedUndoMergeTranscriptsChangeMultiple
57
+ extends SerializedUndoMergeTranscriptsChangeBase {
58
+ changes: UndoMergeTranscriptsChangeDetails[]
59
+ }
60
+
61
+ export type SerializedUndoMergeTranscriptsChange =
62
+ | SerializedUndoMergeTranscriptsChangeSingle
63
+ | SerializedUndoMergeTranscriptsChangeMultiple
64
+
49
65
  export class MergeTranscriptsChange extends FeatureChange {
50
66
  typeName = 'MergeTranscriptsChange' as const
51
67
  changes: MergeTranscriptsChangeDetails[]
@@ -76,43 +92,6 @@ export class MergeTranscriptsChange extends FeatureChange {
76
92
  return { typeName, changedIds, assembly, changes }
77
93
  }
78
94
 
79
- async executeOnServer(backend: ServerDataStore) {
80
- const { featureModel, session } = backend
81
- const { changes, logger } = this
82
- for (const change of changes) {
83
- const { firstTranscript, secondTranscript } = change
84
- const topLevelFeature = await featureModel
85
- .findOne({ allIds: firstTranscript._id })
86
- .session(session)
87
- .exec()
88
- if (!topLevelFeature) {
89
- const errMsg = `*** ERROR: The following featureId was not found in database ='${firstTranscript._id}'`
90
- logger.error(errMsg)
91
- throw new Error(errMsg)
92
- }
93
- const mergedTranscript = this.getFeatureFromId(
94
- topLevelFeature,
95
- firstTranscript._id,
96
- )
97
- if (!mergedTranscript) {
98
- const errMsg = 'ERROR when searching feature by featureId'
99
- logger.error(errMsg)
100
- throw new Error(errMsg)
101
- }
102
- this.mergeTranscriptsOnServer(mergedTranscript, secondTranscript)
103
- const deletedIds = findAndDeleteChildFeature(
104
- topLevelFeature,
105
- secondTranscript._id,
106
- this,
107
- )
108
- deletedIds.push(secondTranscript._id)
109
- topLevelFeature.allIds = topLevelFeature.allIds.filter(
110
- (id) => !deletedIds.includes(id),
111
- )
112
- await topLevelFeature.save()
113
- }
114
- }
115
-
116
95
  mergeTranscriptsOnServer(
117
96
  firstTranscript: Feature,
118
97
  secondTranscript: AnnotationFeatureSnapshot,
@@ -243,24 +222,6 @@ export class MergeTranscriptsChange extends FeatureChange {
243
222
  }
244
223
  }
245
224
 
246
- /* --------------------------------- */
247
-
248
- async executeOnClient(dataStore: ClientDataStore) {
249
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
250
- if (!dataStore) {
251
- throw new Error('No data store')
252
- }
253
- for (const [idx, changedId] of this.changedIds.entries()) {
254
- const { firstTranscript, secondTranscript } = this.changes[idx]
255
- const mergedTranscript = dataStore.getFeature(firstTranscript._id)
256
- if (!mergedTranscript) {
257
- throw new Error(`Could not find feature with identifier "${changedId}"`)
258
- }
259
- this.mergeTranscriptsOnClient(mergedTranscript, secondTranscript)
260
- mergedTranscript.parent?.deleteChild(secondTranscript._id)
261
- }
262
- }
263
-
264
225
  mergeTranscriptsOnClient(
265
226
  firstTranscript: AnnotationFeature,
266
227
  secondTranscript: AnnotationFeatureSnapshot,
@@ -364,10 +325,6 @@ export class MergeTranscriptsChange extends FeatureChange {
364
325
  }
365
326
  }
366
327
 
367
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
368
- throw new Error('executeOnLocalGFF3 not implemented')
369
- }
370
-
371
328
  getInverse() {
372
329
  const { assembly, changedIds, changes, logger } = this
373
330
  const inverseChangedIds = [...changedIds].reverse()
@@ -392,3 +349,54 @@ export class MergeTranscriptsChange extends FeatureChange {
392
349
  )
393
350
  }
394
351
  }
352
+
353
+ export class UndoMergeTranscriptsChange extends FeatureChange {
354
+ typeName = 'UndoMergeTranscriptsChange' as const
355
+ changes: UndoMergeTranscriptsChangeDetails[]
356
+
357
+ constructor(
358
+ json: SerializedUndoMergeTranscriptsChange,
359
+ options?: ChangeOptions,
360
+ ) {
361
+ super(json, options)
362
+ this.changes = 'changes' in json ? json.changes : [json]
363
+ }
364
+
365
+ toJSON(): SerializedUndoMergeTranscriptsChange {
366
+ const { assembly, changedIds, changes, typeName } = this
367
+ if (changes.length === 1) {
368
+ const [{ transcriptsToRestore, parentFeatureId }] = changes
369
+
370
+ return {
371
+ typeName,
372
+ changedIds,
373
+ assembly,
374
+ transcriptsToRestore,
375
+ parentFeatureId,
376
+ }
377
+ }
378
+ return { typeName, changedIds, assembly, changes }
379
+ }
380
+
381
+ getInverse() {
382
+ const { assembly, changedIds, changes, logger } = this
383
+ const inverseChangedIds = [...changedIds].reverse()
384
+ const inverseChanges = [...changes]
385
+ .reverse()
386
+ .map((undoMergeTranscriptsChange) => ({
387
+ firstTranscript: undoMergeTranscriptsChange.transcriptsToRestore[0],
388
+ secondTranscript: undoMergeTranscriptsChange.transcriptsToRestore[1],
389
+ parentFeatureId: undoMergeTranscriptsChange.parentFeatureId,
390
+ }))
391
+
392
+ return new MergeTranscriptsChange(
393
+ {
394
+ changedIds: inverseChangedIds,
395
+ typeName: 'MergeTranscriptsChange',
396
+ changes: inverseChanges,
397
+ assembly,
398
+ },
399
+ { logger },
400
+ )
401
+ }
402
+ }