@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,18 +1,8 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-call */
2
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
3
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
4
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
5
- /* eslint-disable @typescript-eslint/require-await */
6
- import type {
7
- ChangeOptions,
8
- ClientDataStore,
9
- LocalGFF3DataStore,
10
- SerializedAssemblySpecificChange,
11
- ServerDataStore,
1
+ import {
2
+ AssemblySpecificChange,
3
+ type ChangeOptions,
4
+ type SerializedAssemblySpecificChange,
12
5
  } from '@apollo-annotation/common'
13
- import { BgzipIndexedFasta } from '@gmod/indexedfasta'
14
-
15
- import { FromFileBaseChange } from './FromFileBaseChange.js'
16
6
 
17
7
  export interface SerializedAddAssemblyFromFileChangeBase
18
8
  extends SerializedAssemblySpecificChange {
@@ -37,7 +27,7 @@ export type SerializedAddAssemblyFromFileChange =
37
27
  | SerializedAddAssemblyFromFileChangeSingle
38
28
  | SerializedAddAssemblyFromFileChangeMultiple
39
29
 
40
- export class AddAssemblyFromFileChange extends FromFileBaseChange {
30
+ export class AddAssemblyFromFileChange extends AssemblySpecificChange {
41
31
  typeName = 'AddAssemblyFromFileChange' as const
42
32
  changes: AddAssemblyFromFileChangeDetails[]
43
33
 
@@ -62,160 +52,6 @@ export class AddAssemblyFromFileChange extends FromFileBaseChange {
62
52
  return { typeName, assembly, changes }
63
53
  }
64
54
 
65
- /**
66
- * Applies the required change to database
67
- * @param backend - parameters from backend
68
- * @returns
69
- */
70
- async executeOnServer(backend: ServerDataStore) {
71
- const { changes } = this
72
- for (const change of changes) {
73
- const { assemblyName, fileIds } = change
74
- await ('gzi' in fileIds
75
- ? this.executeOnServerIndexed(backend, assemblyName, fileIds)
76
- : this.executeOnServerFasta(backend, assemblyName, fileIds.fa))
77
- }
78
- }
79
-
80
- async executeOnServerIndexed(
81
- backend: ServerDataStore,
82
- assemblyName: string,
83
- fileIds: { fa: string; fai: string; gzi: string },
84
- ) {
85
- const { CHUNK_SIZE } = process.env
86
- const customChunkSize = CHUNK_SIZE && Number(CHUNK_SIZE)
87
-
88
- const { FILE_UPLOAD_FOLDER } = process.env
89
- if (!FILE_UPLOAD_FOLDER) {
90
- throw new Error('No FILE_UPLOAD_FOLDER found in .env file')
91
- }
92
-
93
- const { fa: faId, fai: faiId, gzi: gziId } = fileIds
94
- const {
95
- assemblyModel,
96
- checkModel,
97
- fileModel,
98
- filesService,
99
- refSeqModel,
100
- user,
101
- } = backend
102
-
103
- const faDoc = await fileModel.findById(faId)
104
- const faChecksum = faDoc?.checksum
105
- if (!faChecksum) {
106
- throw new Error(`No checksum for file document ${faDoc?.id}`)
107
- }
108
-
109
- const faiDoc = await fileModel.findById(faiId)
110
- const faiChecksum = faiDoc?.checksum
111
- if (!faiChecksum) {
112
- throw new Error(`No checksum for file document ${faiDoc?.id}`)
113
- }
114
-
115
- const gziDoc = await fileModel.findById(gziId)
116
- const gziChecksum = gziDoc?.checksum
117
- if (!gziChecksum) {
118
- throw new Error(`No checksum for file document ${gziDoc?.id}`)
119
- }
120
-
121
- const fasta = filesService.getFileHandle(faDoc)
122
- const fai = filesService.getFileHandle(faiDoc)
123
- const gzi = filesService.getFileHandle(gziDoc)
124
- const sequenceAdapter = new BgzipIndexedFasta({ fasta, fai, gzi })
125
- const allSequenceSizes = await sequenceAdapter.getSequenceSizes()
126
- await Promise.all([fasta.close(), fai.close(), gzi.close()])
127
-
128
- const assemblyDoc = await assemblyModel
129
- .findOne({ name: assemblyName })
130
- .exec()
131
- if (assemblyDoc) {
132
- throw new Error(`Assembly "${assemblyName}" already exists`)
133
- }
134
- const checkDocs = await checkModel.find({ isDefault: true }).exec()
135
- const checks = checkDocs.map((checkDoc) => checkDoc._id.toHexString())
136
- const [newAssemblyDoc] = await assemblyModel.create([
137
- {
138
- _id: this.assembly,
139
- name: assemblyName,
140
- user,
141
- status: -1,
142
- fileIds,
143
- checks,
144
- },
145
- ])
146
- this.logger.debug?.(
147
- `Added new assembly "${assemblyName}", docId "${newAssemblyDoc._id}"`,
148
- )
149
-
150
- for (const sequenceName in allSequenceSizes) {
151
- const [newRefSeqDoc] = await refSeqModel.create([
152
- {
153
- name: sequenceName,
154
- assembly: newAssemblyDoc._id,
155
- length: allSequenceSizes[sequenceName],
156
- ...(customChunkSize ? { chunkSize: customChunkSize } : null),
157
- user,
158
- status: -1,
159
- },
160
- ])
161
- this.logger.debug?.(
162
- `Added new refSeq "${sequenceName}", docId "${newRefSeqDoc._id}"`,
163
- )
164
- }
165
- }
166
-
167
- async executeOnServerFasta(
168
- backend: ServerDataStore,
169
- assemblyName: string,
170
- fileId: string,
171
- ) {
172
- const { assemblyModel, checkModel, fileModel, user } = backend
173
- // Get file checksum
174
- const fileDoc = await fileModel.findById(fileId).exec()
175
- if (!fileDoc) {
176
- throw new Error(`File "${fileId}" not found in Mongo`)
177
- }
178
- this.logger.debug?.(`FileId "${fileId}", checksum "${fileDoc.checksum}"`)
179
-
180
- // Check and add new assembly
181
- const assemblyDoc = await assemblyModel
182
- .findOne({ name: assemblyName })
183
- .exec()
184
- if (assemblyDoc) {
185
- throw new Error(`Assembly "${assemblyName}" already exists`)
186
- }
187
- const checkDocs = await checkModel.find({ default: true }).exec()
188
- const checks = checkDocs.map((checkDoc) => checkDoc._id.toHexString())
189
- // Add assembly
190
- const [newAssemblyDoc] = await assemblyModel.create([
191
- {
192
- _id: this.assembly,
193
- name: assemblyName,
194
- user,
195
- status: -1,
196
- fileIds: { fa: fileId },
197
- checks,
198
- },
199
- ])
200
- this.logger.debug?.(
201
- `Added new assembly "${assemblyName}", docId "${newAssemblyDoc._id}"`,
202
- )
203
- this.logger.debug?.(
204
- `File type: "${fileDoc.type}", assemblyId: "${newAssemblyDoc._id}"`,
205
- )
206
-
207
- // Add refSeqs
208
- // We cannot use Mongo 'session' / transaction here because Mongo has 16 MB limit for transaction
209
- await this.addRefSeqIntoDb(fileDoc, newAssemblyDoc._id.toString(), backend)
210
- }
211
-
212
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
213
- throw new Error('executeOnLocalGFF3 not implemented')
214
- }
215
-
216
- // eslint-disable-next-line @typescript-eslint/no-empty-function
217
- async executeOnClient(_dataStore: ClientDataStore) {}
218
-
219
55
  getInverse() {
220
56
  const { assembly, changes, logger, typeName } = this
221
57
  return new AddAssemblyFromFileChange(
@@ -1,14 +1,9 @@
1
- /* eslint-disable @typescript-eslint/require-await */
2
- import type {
3
- ChangeOptions,
4
- ClientDataStore,
5
- LocalGFF3DataStore,
6
- SerializedAssemblySpecificChange,
7
- ServerDataStore,
1
+ import {
2
+ AssemblySpecificChange,
3
+ type ChangeOptions,
4
+ type SerializedAssemblySpecificChange,
8
5
  } from '@apollo-annotation/common'
9
6
 
10
- import { FromFileBaseChange } from './FromFileBaseChange.js'
11
-
12
7
  export interface SerializedAddFeaturesFromFileChangeBase
13
8
  extends SerializedAssemblySpecificChange {
14
9
  typeName: 'AddFeaturesFromFileChange'
@@ -33,7 +28,7 @@ export type SerializedAddFeaturesFromFileChange =
33
28
  | SerializedAddFeaturesFromFileChangeSingle
34
29
  | SerializedAddFeaturesFromFileChangeMultiple
35
30
 
36
- export class AddFeaturesFromFileChange extends FromFileBaseChange {
31
+ export class AddFeaturesFromFileChange extends AssemblySpecificChange {
37
32
  typeName = 'AddFeaturesFromFileChange' as const
38
33
  changes: AddFeaturesFromFileChangeDetails[]
39
34
  deleteExistingFeatures = false
@@ -61,82 +56,6 @@ export class AddFeaturesFromFileChange extends FromFileBaseChange {
61
56
  return { typeName, assembly, changes, deleteExistingFeatures }
62
57
  }
63
58
 
64
- /**
65
- * Applies the required change to database
66
- * @param backend - parameters from backend
67
- * @returns
68
- */
69
- async executeOnServer(backend: ServerDataStore) {
70
- const { fileModel, filesService } = backend
71
- const { changes, deleteExistingFeatures, logger } = this
72
-
73
- if (deleteExistingFeatures) {
74
- await this.removeExistingFeatures(backend)
75
- }
76
-
77
- for (const change of changes) {
78
- const { fileId, parseOptions } = change
79
-
80
- const { FILE_UPLOAD_FOLDER } = process.env
81
- if (!FILE_UPLOAD_FOLDER) {
82
- throw new Error('No FILE_UPLOAD_FOLDER found in .env file')
83
- }
84
- // Get file checksum
85
- const fileDoc = await fileModel.findById(fileId).exec()
86
- if (!fileDoc) {
87
- throw new Error(`File "${fileId}" not found in Mongo`)
88
- }
89
- logger.debug?.(`FileId "${fileId}", checksum "${fileDoc.checksum}"`)
90
-
91
- let errorCount = 0
92
- // eslint-disable-next-line unicorn/consistent-function-scoping
93
- const errorLogger = (error: unknown) => {
94
- if (errorCount <= 99) {
95
- logger.warn('Error parsing or adding feature')
96
- logger.warn(error)
97
- if (errorCount === 99) {
98
- logger.warn(
99
- 'Reached 100 feature errors, omitting further warnings from log',
100
- )
101
- }
102
- }
103
- errorCount++
104
- }
105
-
106
- // Read data from compressed file and parse the content
107
- const { bufferSize = 10_000, strict = true } = parseOptions ?? {}
108
- const featureStream = filesService.parseGFF3(
109
- filesService.getFileStream(fileDoc),
110
- { bufferSize, errorCallback: strict ? undefined : errorLogger },
111
- )
112
- let featureCount = 0
113
- for await (const gff3Feature of featureStream) {
114
- // Add new feature into database
115
- try {
116
- await this.addFeatureIntoDb(gff3Feature, backend)
117
- } catch (error) {
118
- // if the first feature is an error, assume the file isn't valid and throw
119
- if (strict || featureCount === 0) {
120
- throw error
121
- }
122
- errorLogger(error)
123
- }
124
- featureCount++
125
- if (featureCount % 1000 === 0) {
126
- logger.debug?.(`Processed ${featureCount} features`)
127
- }
128
- }
129
- }
130
- logger.debug?.('New features added into database!')
131
- }
132
-
133
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
134
- throw new Error('executeOnLocalGFF3 not implemented')
135
- }
136
-
137
- // eslint-disable-next-line @typescript-eslint/no-empty-function
138
- async executeOnClient(_dataStore: ClientDataStore) {}
139
-
140
59
  getInverse() {
141
60
  const { assembly, changes, logger, typeName } = this
142
61
  return new AddFeaturesFromFileChange(
@@ -1,16 +1,9 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
- /* eslint-disable @typescript-eslint/no-unsafe-call */
3
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
1
  import {
5
2
  AssemblySpecificChange,
6
3
  type Change,
7
4
  type ChangeOptions,
8
- type ClientDataStore,
9
- type LocalGFF3DataStore,
10
5
  type SerializedAssemblySpecificChange,
11
- type ServerDataStore,
12
6
  } from '@apollo-annotation/common'
13
- import { getSession } from '@jbrowse/core/util'
14
7
 
15
8
  export interface SerializedRefSeqAliases {
16
9
  refName: string
@@ -32,24 +25,6 @@ export class AddRefSeqAliasesChange extends AssemblySpecificChange {
32
25
  this.refSeqAliases = json.refSeqAliases
33
26
  }
34
27
 
35
- executeOnClient(clientDataStore: ClientDataStore) {
36
- const { assemblyManager } = getSession(clientDataStore)
37
- const assembly = assemblyManager.get(this.assembly)
38
- if (!assembly) {
39
- throw new Error(`assembly ${this.assembly} not found`)
40
- }
41
- const sessionAliases = assembly.refNameAliases ?? {}
42
-
43
- for (const refSeqAlias of this.refSeqAliases) {
44
- const { aliases, refName } = refSeqAlias
45
- for (const alias of aliases) {
46
- sessionAliases[alias] = refName
47
- }
48
- }
49
- assembly.setRefNameAliases(sessionAliases)
50
- return Promise.resolve()
51
- }
52
-
53
28
  getInverse(): Change {
54
29
  throw new Error('Method not implemented.')
55
30
  }
@@ -59,25 +34,6 @@ export class AddRefSeqAliasesChange extends AssemblySpecificChange {
59
34
  return { assembly, typeName, refSeqAliases }
60
35
  }
61
36
 
62
- async executeOnServer(backend: ServerDataStore) {
63
- const { refSeqModel, session } = backend
64
- const { assembly, logger, refSeqAliases } = this
65
-
66
- for (const refSeqAlias of refSeqAliases) {
67
- logger.debug?.(
68
- `Updating Refname alias for assembly: ${assembly}, refSeqAlias: ${JSON.stringify(refSeqAlias)}`,
69
- )
70
- const { aliases, refName } = refSeqAlias
71
- await refSeqModel
72
- .updateOne({ assembly, name: refName }, { $set: { aliases } })
73
- .session(session)
74
- }
75
- }
76
-
77
- executeOnLocalGFF3(_backend: LocalGFF3DataStore): Promise<unknown> {
78
- throw new Error('Method not implemented.')
79
- }
80
-
81
37
  // eslint-disable-next-line @typescript-eslint/class-literal-property-style
82
38
  get notification(): string {
83
39
  return 'RefSeq aliases have been added.'
@@ -1,16 +1,7 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
- /* eslint-disable @typescript-eslint/no-unsafe-return */
3
- /* eslint-disable @typescript-eslint/require-await */
4
- /* eslint-disable @typescript-eslint/no-unnecessary-condition */
5
- /* eslint-disable @typescript-eslint/no-unsafe-call */
6
1
  import {
7
2
  AssemblySpecificChange,
8
- type ClientDataStore,
9
- type LocalGFF3DataStore,
10
3
  type SerializedAssemblySpecificChange,
11
- type ServerDataStore,
12
4
  } from '@apollo-annotation/common'
13
- import { getSession } from '@jbrowse/core/util'
14
5
 
15
6
  export interface SerializedDeleteAssemblyChange
16
7
  extends SerializedAssemblySpecificChange {
@@ -28,69 +19,6 @@ export class DeleteAssemblyChange extends AssemblySpecificChange {
28
19
  return { typeName, assembly }
29
20
  }
30
21
 
31
- /**
32
- * Applies the required change to database
33
- * @param backend - parameters from backend
34
- * @returns
35
- */
36
- async executeOnServer(backend: ServerDataStore) {
37
- const {
38
- assemblyModel,
39
- featureModel,
40
- refSeqChunkModel,
41
- refSeqModel,
42
- session,
43
- } = backend
44
- const { assembly, logger } = this
45
-
46
- const assemblyDoc = await assemblyModel
47
- .findById(assembly)
48
- .session(session)
49
- .exec()
50
- if (!assemblyDoc) {
51
- const errMsg = `*** ERROR: Assembly with id "${assembly}" not found`
52
- logger.error(errMsg)
53
- throw new Error(errMsg)
54
- }
55
-
56
- // We cannot use Mongo 'session' / transaction here because Mongo has 16 MB limit for transaction
57
-
58
- // Get RefSeqs
59
- const refSeqs = await refSeqModel.find({ assembly }).exec()
60
- const refSeqIds = refSeqs.map((refSeq) => refSeq._id)
61
-
62
- // Get and delete RefSeqChunks
63
- await refSeqChunkModel.deleteMany({ refSeq: refSeqIds }).exec()
64
-
65
- // Get and delete Features
66
- await featureModel.deleteMany({ refSeq: refSeqIds }).exec()
67
-
68
- // Delete RefSeqs and Assembly
69
- await refSeqModel.deleteMany({ assembly }).exec()
70
- await assemblyModel.findByIdAndDelete(assembly).exec()
71
-
72
- logger.debug?.(`Assembly "${assembly}" deleted from database.`)
73
- }
74
-
75
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
76
- throw new Error('executeOnLocalGFF3 not implemented')
77
- }
78
-
79
- async executeOnClient(dataStore: ClientDataStore) {
80
- const { assembly } = this
81
- if (!dataStore) {
82
- throw new Error('No data store')
83
- }
84
- const session = getSession(dataStore)
85
- // If assemblyId is not present in client data store
86
- if (dataStore.assemblies.has(assembly)) {
87
- dataStore.deleteAssembly(assembly)
88
- }
89
- await session.removeAssembly?.(assembly)
90
- // @ts-expect-error this isn't on the AbstractSessionModel
91
- await session.removeSessionAssembly?.(assembly)
92
- }
93
-
94
22
  getInverse() {
95
23
  const { assembly, logger } = this
96
24
  return new DeleteAssemblyChange(
@@ -1,11 +1,7 @@
1
- /* eslint-disable @typescript-eslint/require-await */
2
1
  import {
3
2
  Change,
4
3
  type ChangeOptions,
5
- type ClientDataStore,
6
- type LocalGFF3DataStore,
7
4
  type SerializedChange,
8
- type ServerDataStore,
9
5
  } from '@apollo-annotation/common'
10
6
 
11
7
  export interface SerializedDeleteUserChangeBase extends SerializedChange {
@@ -45,27 +41,6 @@ export class DeleteUserChange extends Change {
45
41
  return { typeName, userId }
46
42
  }
47
43
 
48
- async executeOnServer(backend: ServerDataStore) {
49
- const { session, userModel } = backend
50
- const { logger, userId } = this
51
- const user = await userModel
52
- .findOneAndDelete({ _id: userId })
53
- .session(session)
54
- .exec()
55
- if (!user) {
56
- const errMsg = `*** ERROR: User with id "${userId}" not found`
57
- logger.error(errMsg)
58
- throw new Error(errMsg)
59
- }
60
- }
61
-
62
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
63
- throw new Error('executeOnLocalGFF3 not implemented')
64
- }
65
-
66
- // eslint-disable-next-line @typescript-eslint/no-empty-function
67
- async executeOnClient(_dataStore: ClientDataStore) {}
68
-
69
44
  getInverse() {
70
45
  const { logger, typeName, userId } = this
71
46
  return new DeleteUserChange({ typeName, userId }, { logger })
@@ -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 SerializedFeatureAttributeChangeBase extends SerializedFeatureChange {
15
9
  typeName: 'FeatureAttributeChange'
@@ -59,104 +53,6 @@ export class FeatureAttributeChange extends FeatureChange {
59
53
  return { typeName, changedIds, assembly, changes }
60
54
  }
61
55
 
62
- /**
63
- * Applies the required change to database
64
- * @param backend - parameters from backend
65
- * @returns
66
- */
67
- async executeOnServer(backend: ServerDataStore) {
68
- const { featureModel, session } = backend
69
- const { changes, logger } = this
70
-
71
- const featuresForChanges: {
72
- feature: Feature
73
- topLevelFeature: FeatureDocument
74
- }[] = []
75
- // Loop the changes and check that all features are found
76
- for (const change of changes) {
77
- const { featureId } = change
78
-
79
- // Search correct feature
80
- const topLevelFeature = await featureModel
81
- .findOne({ allIds: featureId })
82
- .session(session)
83
- .exec()
84
-
85
- if (!topLevelFeature) {
86
- const errMsg = `*** ERROR: The following featureId was not found in database ='${featureId}'`
87
- logger.error(errMsg)
88
- throw new Error(errMsg)
89
- // throw new NotFoundException(errMsg) -- This is causing runtime error because Exception comes from @nestjs/common!!!
90
- }
91
- logger.debug?.(`*** Feature found: ${JSON.stringify(topLevelFeature)}`)
92
-
93
- const foundFeature = this.getFeatureFromId(topLevelFeature, featureId)
94
- if (!foundFeature) {
95
- const errMsg = 'ERROR when searching feature by featureId'
96
- logger.error(errMsg)
97
- throw new Error(errMsg)
98
- }
99
- logger.debug?.(`*** Found feature: ${JSON.stringify(foundFeature)}`)
100
- featuresForChanges.push({ feature: foundFeature, topLevelFeature })
101
- }
102
-
103
- const { INDEXED_IDS } = process.env
104
- let idsToIndex: string[] | undefined
105
- if (INDEXED_IDS) {
106
- idsToIndex = INDEXED_IDS.split(',')
107
- }
108
- // Let's update objects
109
- for (const [idx, change] of changes.entries()) {
110
- const { newAttributes } = change
111
- const { feature, topLevelFeature } = featuresForChanges[idx]
112
- const indexedIdsChanged = idsToIndex?.some(
113
- (id) => id in newAttributes || id in (feature?.attributes ?? {}),
114
- )
115
- feature.attributes = newAttributes
116
- if (indexedIdsChanged) {
117
- const indexedIds = this.getIndexedIds(topLevelFeature, idsToIndex)
118
- topLevelFeature.indexedIds = indexedIds
119
- topLevelFeature.markModified('indexedIds')
120
- }
121
- if (topLevelFeature._id.equals(feature._id)) {
122
- topLevelFeature.markModified('attributes') // Mark as modified. Without this save() -method is not updating data in database
123
- } else {
124
- topLevelFeature.markModified('children') // Mark as modified. Without this save() -method is not updating data in database
125
- }
126
-
127
- try {
128
- await topLevelFeature.save()
129
- } catch (error) {
130
- logger.debug?.(`*** FAILED: ${error}`)
131
- throw error
132
- }
133
- logger.debug?.(
134
- `*** Feature attributes modified (added, edited or deleted), docId: ${JSON.stringify(
135
- topLevelFeature,
136
- )}`,
137
- )
138
- }
139
- }
140
-
141
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
142
- throw new Error('applyToLocalGFF3 not implemented')
143
- }
144
-
145
- async executeOnClient(dataStore: ClientDataStore) {
146
- if (!dataStore) {
147
- throw new Error('No data store')
148
- }
149
- for (const [idx, changedId] of this.changedIds.entries()) {
150
- const feature = dataStore.getFeature(changedId)
151
- if (!feature) {
152
- throw new Error(`Could not find feature with identifier "${changedId}"`)
153
- }
154
- feature.setAttributes(
155
- new Map(Object.entries(this.changes[idx].newAttributes)),
156
- )
157
- }
158
- }
159
-
160
56
  getInverse() {
161
57
  const { assembly, changedIds, changes, logger } = this
162
58
  const inverseChangedIds = [...changedIds].reverse()
@@ -1,11 +1,4 @@
1
- /* eslint-disable @typescript-eslint/require-await */
2
- import {
3
- Change,
4
- type ChangeOptions,
5
- type ClientDataStore,
6
- type LocalGFF3DataStore,
7
- type ServerDataStore,
8
- } from '@apollo-annotation/common'
1
+ import { Change, type ChangeOptions } from '@apollo-annotation/common'
9
2
 
10
3
  interface JBrowseAssembly {
11
4
  sequence: { adapter: { type: string } }
@@ -99,25 +92,6 @@ export class ImportJBrowseConfigChange extends Change {
99
92
  return { typeName, oldJBrowseConfig, newJBrowseConfig }
100
93
  }
101
94
 
102
- async executeOnServer(backend: ServerDataStore) {
103
- const { jbrowseConfigModel } = backend
104
- const { logger, newJBrowseConfig } = this
105
- await jbrowseConfigModel.deleteMany()
106
- if (!newJBrowseConfig) {
107
- return
108
- }
109
- const filteredConfig = filterJBrowseConfig(newJBrowseConfig)
110
- await jbrowseConfigModel.create(filteredConfig)
111
- logger.debug?.('Stored new JBrowse Config')
112
- }
113
-
114
- async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
115
- throw new Error('executeOnLocalGFF3 not implemented')
116
- }
117
-
118
- // eslint-disable-next-line @typescript-eslint/no-empty-function
119
- async executeOnClient(_dataStore: ClientDataStore) {}
120
-
121
95
  getInverse() {
122
96
  const { logger, newJBrowseConfig, oldJBrowseConfig } = this
123
97
  return new ImportJBrowseConfigChange(