-
Notifications
You must be signed in to change notification settings - Fork 6
/
sequence-adaptation.ts
70 lines (59 loc) · 2.75 KB
/
sequence-adaptation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { derived, get, writable, type Writable } from 'svelte/store';
import type { GlobalType } from '../types/global-type';
import type { ISequenceAdaptation, SequenceAdaptation } from '../types/sequencing';
import gql from '../utilities/gql';
import { seqJsonToSequence } from '../utilities/sequence-editor/from-seq-json';
import { sequenceAutoIndent } from '../utilities/sequence-editor/sequence-autoindent';
import { sequenceCompletion } from '../utilities/sequence-editor/sequence-completion';
import { sequenceToSeqJson } from '../utilities/sequence-editor/to-seq-json';
import { gqlSubscribable } from './subscribable';
const defaultAdaptation: ISequenceAdaptation = {
argDelegator: undefined,
autoComplete: sequenceCompletion,
autoIndent: sequenceAutoIndent,
globals: [],
inputFormat: {
linter: undefined,
name: 'SeqN',
toInputFormat: seqJsonToSequence,
},
modifyOutput: undefined,
modifyOutputParse: undefined,
outputFormat: [
{
fileExtension: 'json',
name: 'Seq JSON',
toOutputFormat: sequenceToSeqJson,
},
],
};
/* Writeable */
export const sequenceAdaptation: Writable<ISequenceAdaptation> = writable(defaultAdaptation);
/* Subscriptions. */
export const sequenceAdaptations = gqlSubscribable<SequenceAdaptation[]>(gql.SUB_SEQUENCE_ADAPTATIONS, {}, [], null);
/* Derived */
export const inputFormat = derived([sequenceAdaptation], ([$sequenceAdaptation]) => $sequenceAdaptation?.inputFormat);
export const outputFormat = derived(
[sequenceAdaptation],
([$sequenceAdaptation]) => $sequenceAdaptation?.outputFormat ?? [],
);
/* Helpers */
export function getGlobals(): GlobalType[] {
return get(sequenceAdaptation).globals ?? [];
}
export function setSequenceAdaptation(newSequenceAdaptation: Partial<ISequenceAdaptation> | undefined): void {
sequenceAdaptation.set({
argDelegator: newSequenceAdaptation?.argDelegator ?? defaultAdaptation.argDelegator,
autoComplete: newSequenceAdaptation?.autoComplete ?? defaultAdaptation.autoComplete,
autoIndent: newSequenceAdaptation?.autoIndent ?? defaultAdaptation.autoIndent,
globals: newSequenceAdaptation?.globals ?? defaultAdaptation.globals,
inputFormat: {
linter: newSequenceAdaptation?.inputFormat?.linter ?? defaultAdaptation.inputFormat.linter,
name: newSequenceAdaptation?.inputFormat?.name ?? defaultAdaptation.inputFormat.name,
toInputFormat: newSequenceAdaptation?.inputFormat?.toInputFormat ?? defaultAdaptation.inputFormat.toInputFormat,
},
modifyOutput: newSequenceAdaptation?.modifyOutput ?? defaultAdaptation.modifyOutput,
modifyOutputParse: newSequenceAdaptation?.modifyOutputParse ?? defaultAdaptation.modifyOutputParse,
outputFormat: newSequenceAdaptation?.outputFormat ?? defaultAdaptation.outputFormat,
});
}