jspurefix 5.2.0 → 5.5.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 (92) hide show
  1. package/BACKPORT_PLAN.md +135 -39
  2. package/dist/config/js-fix-config.d.ts +2 -0
  3. package/dist/config/js-fix-config.js.map +1 -1
  4. package/dist/dictionary/parser/quickfix/dictionary-validator.d.ts +39 -0
  5. package/dist/dictionary/parser/quickfix/dictionary-validator.js +321 -0
  6. package/dist/dictionary/parser/quickfix/dictionary-validator.js.map +1 -0
  7. package/dist/dictionary/parser/quickfix/index-visitor.d.ts +10 -0
  8. package/dist/dictionary/parser/quickfix/index-visitor.js +68 -0
  9. package/dist/dictionary/parser/quickfix/index-visitor.js.map +1 -0
  10. package/dist/dictionary/parser/quickfix/index.d.ts +7 -0
  11. package/dist/dictionary/parser/quickfix/index.js +7 -0
  12. package/dist/dictionary/parser/quickfix/index.js.map +1 -1
  13. package/dist/dictionary/parser/quickfix/quick-fix-graph-file-parser.d.ts +13 -0
  14. package/dist/dictionary/parser/quickfix/quick-fix-graph-file-parser.js +65 -0
  15. package/dist/dictionary/parser/quickfix/quick-fix-graph-file-parser.js.map +1 -0
  16. package/dist/dictionary/parser/quickfix/quick-fix-graph-parser.d.ts +73 -0
  17. package/dist/dictionary/parser/quickfix/quick-fix-graph-parser.js +363 -0
  18. package/dist/dictionary/parser/quickfix/quick-fix-graph-parser.js.map +1 -0
  19. package/dist/dictionary/parser/quickfix/sax-tree-builder.d.ts +5 -0
  20. package/dist/dictionary/parser/quickfix/sax-tree-builder.js +103 -0
  21. package/dist/dictionary/parser/quickfix/sax-tree-builder.js.map +1 -0
  22. package/dist/dictionary/parser/quickfix/validation-error.d.ts +17 -0
  23. package/dist/dictionary/parser/quickfix/validation-error.js +32 -0
  24. package/dist/dictionary/parser/quickfix/validation-error.js.map +1 -0
  25. package/dist/dictionary/parser/quickfix/x-element.d.ts +26 -0
  26. package/dist/dictionary/parser/quickfix/x-element.js +82 -0
  27. package/dist/dictionary/parser/quickfix/x-element.js.map +1 -0
  28. package/dist/store/file-session-store.d.ts +42 -0
  29. package/dist/store/file-session-store.js +256 -0
  30. package/dist/store/file-session-store.js.map +1 -0
  31. package/dist/store/file-session-stream-provider.d.ts +25 -0
  32. package/dist/store/file-session-stream-provider.js +162 -0
  33. package/dist/store/file-session-stream-provider.js.map +1 -0
  34. package/dist/store/fix-msg-ascii-store-resend.js +6 -0
  35. package/dist/store/fix-msg-ascii-store-resend.js.map +1 -1
  36. package/dist/store/fix-session-store-factory.d.ts +13 -0
  37. package/dist/store/fix-session-store-factory.js +21 -0
  38. package/dist/store/fix-session-store-factory.js.map +1 -0
  39. package/dist/store/fix-session-store.d.ts +19 -0
  40. package/dist/store/fix-session-store.js +3 -0
  41. package/dist/store/fix-session-store.js.map +1 -0
  42. package/dist/store/index.d.ts +9 -0
  43. package/dist/store/index.js +9 -0
  44. package/dist/store/index.js.map +1 -1
  45. package/dist/store/memory-session-store.d.ts +27 -0
  46. package/dist/store/memory-session-store.js +104 -0
  47. package/dist/store/memory-session-store.js.map +1 -0
  48. package/dist/store/memory-session-stream-provider.d.ts +26 -0
  49. package/dist/store/memory-session-stream-provider.js +103 -0
  50. package/dist/store/memory-session-stream-provider.js.map +1 -0
  51. package/dist/store/session-id.d.ts +9 -0
  52. package/dist/store/session-id.js +55 -0
  53. package/dist/store/session-id.js.map +1 -0
  54. package/dist/store/session-stream-provider.d.ts +15 -0
  55. package/dist/store/session-stream-provider.js +3 -0
  56. package/dist/store/session-stream-provider.js.map +1 -0
  57. package/dist/store/store-config.d.ts +5 -0
  58. package/dist/store/store-config.js +3 -0
  59. package/dist/store/store-config.js.map +1 -0
  60. package/dist/transport/ascii/ascii-session.d.ts +6 -1
  61. package/dist/transport/ascii/ascii-session.js +37 -5
  62. package/dist/transport/ascii/ascii-session.js.map +1 -1
  63. package/dist/transport/session/session-description.d.ts +2 -0
  64. package/dist/transport/session/session-description.js.map +1 -1
  65. package/dist/util/definition-factory.js +1 -1
  66. package/dist/util/definition-factory.js.map +1 -1
  67. package/jsfix.test_client.txt +67 -67
  68. package/jsfix.test_server.txt +64 -64
  69. package/package.json +6 -6
  70. package/src/config/js-fix-config.ts +2 -0
  71. package/src/dictionary/parser/quickfix/dictionary-validator.ts +473 -0
  72. package/src/dictionary/parser/quickfix/index-visitor.ts +100 -0
  73. package/src/dictionary/parser/quickfix/index.ts +7 -0
  74. package/src/dictionary/parser/quickfix/quick-fix-graph-file-parser.ts +63 -0
  75. package/src/dictionary/parser/quickfix/quick-fix-graph-parser.ts +450 -0
  76. package/src/dictionary/parser/quickfix/sax-tree-builder.ts +112 -0
  77. package/src/dictionary/parser/quickfix/validation-error.ts +34 -0
  78. package/src/dictionary/parser/quickfix/x-element.ts +115 -0
  79. package/src/store/file-session-store.ts +294 -0
  80. package/src/store/file-session-stream-provider.ts +123 -0
  81. package/src/store/fix-msg-ascii-store-resend.ts +8 -0
  82. package/src/store/fix-session-store-factory.ts +31 -0
  83. package/src/store/fix-session-store.ts +37 -0
  84. package/src/store/index.ts +9 -0
  85. package/src/store/memory-session-store.ts +102 -0
  86. package/src/store/memory-session-stream-provider.ts +97 -0
  87. package/src/store/session-id.ts +32 -0
  88. package/src/store/session-stream-provider.ts +74 -0
  89. package/src/store/store-config.ts +16 -0
  90. package/src/transport/ascii/ascii-session.ts +57 -6
  91. package/src/transport/session/session-description.ts +2 -0
  92. package/src/util/definition-factory.ts +2 -2
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XDocument = exports.XNode = void 0;
4
+ class XNode {
5
+ constructor(element) {
6
+ this.element = element;
7
+ }
8
+ attribute(name) {
9
+ return this.element.attributes[name];
10
+ }
11
+ elements(name) {
12
+ const children = name
13
+ ? this.element.children.filter(c => c.name === name)
14
+ : this.element.children;
15
+ return children.map(c => new XNode(c));
16
+ }
17
+ firstElement(name) {
18
+ const child = this.element.children.find(c => c.name === name);
19
+ return child ? new XNode(child) : undefined;
20
+ }
21
+ descendants(name) {
22
+ const result = [];
23
+ this.collectDescendants(this.element, name, result);
24
+ return result;
25
+ }
26
+ firstDescendant(name) {
27
+ return this.findDescendant(this.element, name);
28
+ }
29
+ requiredAttribute(name) {
30
+ var _a;
31
+ const val = this.element.attributes[name];
32
+ if (val === undefined) {
33
+ throw new Error(`missing required attribute '${name}' on <${this.element.name}> at line ${(_a = this.element.line) !== null && _a !== void 0 ? _a : '?'}`);
34
+ }
35
+ return val;
36
+ }
37
+ get name() {
38
+ return this.element.name;
39
+ }
40
+ get line() {
41
+ return this.element.line;
42
+ }
43
+ collectDescendants(el, name, result) {
44
+ for (const child of el.children) {
45
+ if (child.name === name) {
46
+ result.push(new XNode(child));
47
+ }
48
+ this.collectDescendants(child, name, result);
49
+ }
50
+ }
51
+ findDescendant(el, name) {
52
+ for (const child of el.children) {
53
+ if (child.name === name) {
54
+ return new XNode(child);
55
+ }
56
+ const found = this.findDescendant(child, name);
57
+ if (found)
58
+ return found;
59
+ }
60
+ return undefined;
61
+ }
62
+ }
63
+ exports.XNode = XNode;
64
+ class XDocument {
65
+ constructor(rootElement) {
66
+ this.root = new XNode(rootElement);
67
+ }
68
+ descendants(name) {
69
+ const result = [];
70
+ if (this.root.name === name)
71
+ result.push(this.root);
72
+ result.push(...this.root.descendants(name));
73
+ return result;
74
+ }
75
+ firstDescendant(name) {
76
+ if (this.root.name === name)
77
+ return this.root;
78
+ return this.root.firstDescendant(name);
79
+ }
80
+ }
81
+ exports.XDocument = XDocument;
82
+ //# sourceMappingURL=x-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x-element.js","sourceRoot":"","sources":["../../../../src/dictionary/parser/quickfix/x-element.ts"],"names":[],"mappings":";;;AAgBA,MAAa,KAAK;IAChB,YAA6B,OAAiB;QAAjB,YAAO,GAAP,OAAO,CAAU;IAAG,CAAC;IAGlD,SAAS,CAAE,IAAY;QACrB,OAAO,IAAI,CAAC,OAAO,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;YAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACnD,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAA;QAC3C,OAAO,MAAM,CAAA;IACf,CAAC;IAGD,eAAe,CAAE,IAAY;QAC3B,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,IAAI,CAAA;QAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC;CACF;AApBD,8BAoBC","sourcesContent":["/**\n * Lightweight in-memory XML element tree — provides DOM-like random access\n * over XML parsed by SAX. Mirrors the C# XDocument/XElement API surface\n * used by QuickFixXmlFileParser and DictionaryValidator.\n */\nexport interface XElement {\n readonly name: string\n readonly attributes: Record<string, string>\n readonly children: XElement[]\n readonly line?: number\n}\n\n/**\n * Query helper wrapping an XElement tree with C#-style traversal methods.\n * Mirrors XDocument/XElement LINQ-to-XML API used in cspurefix.\n */\nexport class XNode {\n constructor (public readonly element: XElement) {}\n\n /** Attribute value by name, or undefined if not present. */\n attribute (name: string): string | undefined {\n return this.element.attributes[name]\n }\n\n /** Direct children with the given tag name. */\n elements (name?: string): XNode[] {\n const children = name\n ? this.element.children.filter(c => c.name === name)\n : this.element.children\n return children.map(c => new XNode(c))\n }\n\n /** First direct child with the given tag name, or undefined. */\n firstElement (name: string): XNode | undefined {\n const child = this.element.children.find(c => c.name === name)\n return child ? new XNode(child) : undefined\n }\n\n /** All descendants (recursive) with the given tag name. */\n descendants (name: string): XNode[] {\n const result: XNode[] = []\n this.collectDescendants(this.element, name, result)\n return result\n }\n\n /** First descendant with the given tag name, or undefined. */\n firstDescendant (name: string): XNode | undefined {\n return this.findDescendant(this.element, name)\n }\n\n /** Shorthand: attribute value, throwing if missing. */\n requiredAttribute (name: string): string {\n const val = this.element.attributes[name]\n if (val === undefined) {\n throw new Error(`missing required attribute '${name}' on <${this.element.name}> at line ${this.element.line ?? '?'}`)\n }\n return val\n }\n\n /** The element's tag name. */\n get name (): string {\n return this.element.name\n }\n\n /** The element's source line number, if available. */\n get line (): number | undefined {\n return this.element.line\n }\n\n private collectDescendants (el: XElement, name: string, result: XNode[]): void {\n for (const child of el.children) {\n if (child.name === name) {\n result.push(new XNode(child))\n }\n this.collectDescendants(child, name, result)\n }\n }\n\n private findDescendant (el: XElement, name: string): XNode | undefined {\n for (const child of el.children) {\n if (child.name === name) {\n return new XNode(child)\n }\n const found = this.findDescendant(child, name)\n if (found) return found\n }\n return undefined\n }\n}\n\n/**\n * Parsed XML document — wraps the root element with query methods.\n * Equivalent to C# XDocument.\n */\nexport class XDocument {\n public readonly root: XNode\n\n constructor (rootElement: XElement) {\n this.root = new XNode(rootElement)\n }\n\n /** All descendants of the root with the given tag name (including the root itself if it matches). */\n descendants (name: string): XNode[] {\n const result: XNode[] = []\n if (this.root.name === name) result.push(this.root)\n result.push(...this.root.descendants(name))\n return result\n }\n\n /** First descendant of the root with the given tag name (including the root itself if it matches). */\n firstDescendant (name: string): XNode | undefined {\n if (this.root.name === name) return this.root\n return this.root.firstDescendant(name)\n }\n}\n"]}
@@ -0,0 +1,42 @@
1
+ import { IFixSessionStore } from './fix-session-store';
2
+ import { SessionId } from './session-id';
3
+ import { IFixMsgStoreRecord } from './fix-msg-store-record';
4
+ import { ISessionStreamProvider } from './session-stream-provider';
5
+ export declare class FileSessionStore implements IFixSessionStore {
6
+ readonly sessionId: SessionId;
7
+ private readonly streamProvider;
8
+ private readonly ownsProvider;
9
+ private senderSeqNumValue;
10
+ private targetSeqNumValue;
11
+ private creationTimeValue;
12
+ private readonly headerIndex;
13
+ static createWithFiles(sessionId: SessionId, directory: string): FileSessionStore;
14
+ constructor(sessionId: SessionId, streamProvider: ISessionStreamProvider, ownsProvider?: boolean);
15
+ getStreamProvider(): ISessionStreamProvider;
16
+ get senderSeqNum(): number;
17
+ set senderSeqNum(value: number);
18
+ get targetSeqNum(): number;
19
+ set targetSeqNum(value: number);
20
+ setSenderSeqNum(value: number): Promise<void>;
21
+ setTargetSeqNum(value: number): Promise<void>;
22
+ nextSenderSeqNum(): Promise<number>;
23
+ nextTargetSeqNum(): Promise<number>;
24
+ get creationTime(): Date;
25
+ reset(): Promise<void>;
26
+ put(record: IFixMsgStoreRecord): Promise<void>;
27
+ get(seqNum: number): Promise<IFixMsgStoreRecord | null>;
28
+ getRange(fromSeqNum: number, toSeqNum: number): Promise<IFixMsgStoreRecord[]>;
29
+ initialize(): Promise<void>;
30
+ flush(): Promise<void>;
31
+ dispose(): Promise<void>;
32
+ private persistSeqNums;
33
+ private loadSeqNums;
34
+ private persistSessionTime;
35
+ private loadSessionTime;
36
+ private loadHeaderIndex;
37
+ private readMessage;
38
+ static extractTag(message: string, tag: string): string | null;
39
+ private static findDelimiter;
40
+ static formatSessionTime(date: Date): string;
41
+ static parseSessionTime(str: string): Date | null;
42
+ }
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FileSessionStore = void 0;
13
+ const fix_msg_store_record_1 = require("./fix-msg-store-record");
14
+ const file_session_stream_provider_1 = require("./file-session-stream-provider");
15
+ class FileSessionStore {
16
+ static createWithFiles(sessionId, directory) {
17
+ return new FileSessionStore(sessionId, new file_session_stream_provider_1.FileSessionStreamProvider(sessionId, directory), true);
18
+ }
19
+ constructor(sessionId, streamProvider, ownsProvider = false) {
20
+ this.sessionId = sessionId;
21
+ this.senderSeqNumValue = 1;
22
+ this.targetSeqNumValue = 1;
23
+ this.creationTimeValue = new Date();
24
+ this.headerIndex = new Map();
25
+ this.streamProvider = streamProvider;
26
+ this.ownsProvider = ownsProvider;
27
+ }
28
+ getStreamProvider() {
29
+ return this.streamProvider;
30
+ }
31
+ get senderSeqNum() {
32
+ return this.senderSeqNumValue;
33
+ }
34
+ set senderSeqNum(value) {
35
+ this.senderSeqNumValue = value;
36
+ }
37
+ get targetSeqNum() {
38
+ return this.targetSeqNumValue;
39
+ }
40
+ set targetSeqNum(value) {
41
+ this.targetSeqNumValue = value;
42
+ }
43
+ setSenderSeqNum(value) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ this.senderSeqNumValue = value;
46
+ yield this.persistSeqNums();
47
+ });
48
+ }
49
+ setTargetSeqNum(value) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ this.targetSeqNumValue = value;
52
+ yield this.persistSeqNums();
53
+ });
54
+ }
55
+ nextSenderSeqNum() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const next = ++this.senderSeqNumValue;
58
+ yield this.persistSeqNums();
59
+ return next;
60
+ });
61
+ }
62
+ nextTargetSeqNum() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const next = ++this.targetSeqNumValue;
65
+ yield this.persistSeqNums();
66
+ return next;
67
+ });
68
+ }
69
+ get creationTime() {
70
+ return this.creationTimeValue;
71
+ }
72
+ reset() {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ this.senderSeqNumValue = 1;
75
+ this.targetSeqNumValue = 1;
76
+ this.creationTimeValue = new Date();
77
+ this.headerIndex.clear();
78
+ yield this.streamProvider.reset();
79
+ yield this.persistSeqNums();
80
+ yield this.persistSessionTime();
81
+ this.streamProvider.openBody();
82
+ });
83
+ }
84
+ put(record) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ if (record.encoded == null) {
87
+ throw new Error('Record must have encoded content');
88
+ }
89
+ const bytes = Buffer.from(record.encoded, 'utf8');
90
+ const length = bytes.length;
91
+ const offset = yield this.streamProvider.appendBody(bytes);
92
+ this.headerIndex.set(record.seqNum, { offset, length });
93
+ yield this.streamProvider.appendHeaderLine(`${record.seqNum},${offset},${length}`);
94
+ });
95
+ }
96
+ get(seqNum) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ const entry = this.headerIndex.get(seqNum);
99
+ if (!entry)
100
+ return null;
101
+ return yield this.readMessage(seqNum, entry.offset, entry.length);
102
+ });
103
+ }
104
+ getRange(fromSeqNum, toSeqNum) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const results = [];
107
+ for (let seq = fromSeqNum; seq <= toSeqNum; seq++) {
108
+ const record = yield this.get(seq);
109
+ if (record) {
110
+ results.push(record);
111
+ }
112
+ }
113
+ return results;
114
+ });
115
+ }
116
+ initialize() {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ yield this.loadSeqNums();
119
+ yield this.loadSessionTime();
120
+ yield this.loadHeaderIndex();
121
+ this.streamProvider.openBody();
122
+ });
123
+ }
124
+ flush() {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ yield this.streamProvider.flush();
127
+ });
128
+ }
129
+ dispose() {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ yield this.streamProvider.flush();
132
+ if (this.ownsProvider) {
133
+ yield this.streamProvider.dispose();
134
+ }
135
+ });
136
+ }
137
+ persistSeqNums() {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ const sender = this.senderSeqNumValue.toString().padStart(20, ' ');
140
+ const target = this.targetSeqNumValue.toString().padStart(20, ' ');
141
+ yield this.streamProvider.writeSeqNums(`${sender} : ${target}`);
142
+ });
143
+ }
144
+ loadSeqNums() {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ const content = yield this.streamProvider.readSeqNums();
147
+ if (content == null) {
148
+ this.senderSeqNumValue = 1;
149
+ this.targetSeqNumValue = 1;
150
+ return;
151
+ }
152
+ const parts = content.split(':');
153
+ if (parts.length === 2) {
154
+ this.senderSeqNumValue = parseInt(parts[0].trim(), 10) || 1;
155
+ this.targetSeqNumValue = parseInt(parts[1].trim(), 10) || 1;
156
+ }
157
+ });
158
+ }
159
+ persistSessionTime() {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ yield this.streamProvider.writeSessionTime(FileSessionStore.formatSessionTime(this.creationTimeValue));
162
+ });
163
+ }
164
+ loadSessionTime() {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ const content = yield this.streamProvider.readSessionTime();
167
+ if (content == null) {
168
+ this.creationTimeValue = new Date();
169
+ yield this.persistSessionTime();
170
+ return;
171
+ }
172
+ const parsed = FileSessionStore.parseSessionTime(content.trim());
173
+ this.creationTimeValue = parsed !== null && parsed !== void 0 ? parsed : new Date();
174
+ });
175
+ }
176
+ loadHeaderIndex() {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ const lines = yield this.streamProvider.readHeaderLines();
179
+ for (const line of lines) {
180
+ if (!line.trim())
181
+ continue;
182
+ const parts = line.split(',');
183
+ if (parts.length === 3) {
184
+ const seqNum = parseInt(parts[0], 10);
185
+ const offset = parseInt(parts[1], 10);
186
+ const length = parseInt(parts[2], 10);
187
+ if (!isNaN(seqNum) && !isNaN(offset) && !isNaN(length)) {
188
+ this.headerIndex.set(seqNum, { offset, length });
189
+ }
190
+ }
191
+ }
192
+ });
193
+ }
194
+ readMessage(seqNum, offset, length) {
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ const buffer = yield this.streamProvider.readBody(offset, length);
197
+ if (buffer.length !== length)
198
+ return null;
199
+ const encoded = buffer.toString('utf8');
200
+ const msgType = FileSessionStore.extractTag(encoded, '35');
201
+ const sendingTimeStr = FileSessionStore.extractTag(encoded, '52');
202
+ let timestamp = new Date(0);
203
+ if (sendingTimeStr) {
204
+ const parsed = FileSessionStore.parseSessionTime(sendingTimeStr);
205
+ if (parsed)
206
+ timestamp = parsed;
207
+ }
208
+ return new fix_msg_store_record_1.FixMsgStoreRecord(msgType !== null && msgType !== void 0 ? msgType : '', timestamp, seqNum, undefined, encoded);
209
+ });
210
+ }
211
+ static extractTag(message, tag) {
212
+ const tagPrefix = `${tag}=`;
213
+ if (message.startsWith(tagPrefix)) {
214
+ const endIndex = FileSessionStore.findDelimiter(message, tagPrefix.length);
215
+ return message.substring(tagPrefix.length, endIndex);
216
+ }
217
+ for (const delim of ['\x01', '|']) {
218
+ const search = `${delim}${tagPrefix}`;
219
+ const idx = message.indexOf(search);
220
+ if (idx >= 0) {
221
+ const startIndex = idx + search.length;
222
+ const endIndex = FileSessionStore.findDelimiter(message, startIndex);
223
+ return message.substring(startIndex, endIndex);
224
+ }
225
+ }
226
+ return null;
227
+ }
228
+ static findDelimiter(message, fromIndex) {
229
+ for (let i = fromIndex; i < message.length; i++) {
230
+ const ch = message.charAt(i);
231
+ if (ch === '\x01' || ch === '|')
232
+ return i;
233
+ }
234
+ return message.length;
235
+ }
236
+ static formatSessionTime(date) {
237
+ const y = date.getUTCFullYear();
238
+ const M = (date.getUTCMonth() + 1).toString().padStart(2, '0');
239
+ const d = date.getUTCDate().toString().padStart(2, '0');
240
+ const h = date.getUTCHours().toString().padStart(2, '0');
241
+ const m = date.getUTCMinutes().toString().padStart(2, '0');
242
+ const s = date.getUTCSeconds().toString().padStart(2, '0');
243
+ const ms = date.getUTCMilliseconds().toString().padStart(3, '0');
244
+ return `${y}${M}${d}-${h}:${m}:${s}.${ms}000`;
245
+ }
246
+ static parseSessionTime(str) {
247
+ const match = str.match(/^(\d{4})(\d{2})(\d{2})-(\d{2}):(\d{2}):(\d{2})\.(\d{3,6})$/);
248
+ if (!match)
249
+ return null;
250
+ const [, y, M, d, h, m, s, frac] = match;
251
+ const ms = parseInt(frac.substring(0, 3), 10);
252
+ return new Date(Date.UTC(parseInt(y), parseInt(M) - 1, parseInt(d), parseInt(h), parseInt(m), parseInt(s), ms));
253
+ }
254
+ }
255
+ exports.FileSessionStore = FileSessionStore;
256
+ //# sourceMappingURL=file-session-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-session-store.js","sourceRoot":"","sources":["../../src/store/file-session-store.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,iEAA8E;AAE9E,iFAA0E;AAW1E,MAAa,gBAAgB;IAc3B,MAAM,CAAC,eAAe,CAAE,SAAoB,EAAE,SAAiB;QAC7D,OAAO,IAAI,gBAAgB,CAAC,SAAS,EAAE,IAAI,wDAAyB,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,CAAA;IACnG,CAAC;IAMD,YACkB,SAAoB,EACpC,cAAsC,EACtC,eAAwB,KAAK;QAFb,cAAS,GAAT,SAAS,CAAW;QAnB9B,sBAAiB,GAAW,CAAC,CAAA;QAC7B,sBAAiB,GAAW,CAAC,CAAA;QAC7B,sBAAiB,GAAS,IAAI,IAAI,EAAE,CAAA;QAG3B,gBAAW,GAAoD,IAAI,GAAG,EAAE,CAAA;QAkBvF,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAKD,iBAAiB;QACf,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;IAID,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,iBAAiB,CAAA;IAC/B,CAAC;IAED,IAAI,YAAY,CAAE,KAAa;QAC7B,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAA;IAChC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,iBAAiB,CAAA;IAC/B,CAAC;IAED,IAAI,YAAY,CAAE,KAAa;QAC7B,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAA;IAChC,CAAC;IAEK,eAAe,CAAE,KAAa;;YAClC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAA;YAC9B,MAAM,IAAI,CAAC,cAAc,EAAE,CAAA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C,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;IACjH,CAAC;CACF;AAtRD,4CAsRC","sourcesContent":["import { IFixSessionStore } from './fix-session-store'\nimport { SessionId } from './session-id'\nimport { IFixMsgStoreRecord, FixMsgStoreRecord } from './fix-msg-store-record'\nimport { ISessionStreamProvider } from './session-stream-provider'\nimport { FileSessionStreamProvider } from './file-session-stream-provider'\n\n/**\n * QuickFix-compatible file-based session store.\n *\n * File format:\n * - .seqnums: \"SSSSSSSSSSSSSSSSSSSS : TTTTTTTTTTTTTTTTTTTT\" (20-char right-justified sender : target)\n * - .session: \"YYYYMMDD-HH:MM:SS.ffffff\" (session creation time)\n * - .header: \"seqnum,offset,length\" per line (index into body)\n * - .body: concatenated raw FIX messages (no delimiters)\n */\nexport class FileSessionStore implements IFixSessionStore {\n private readonly streamProvider: ISessionStreamProvider\n private readonly ownsProvider: boolean\n\n private senderSeqNumValue: number = 1\n private targetSeqNumValue: number = 1\n private creationTimeValue: Date = new Date()\n\n // In-memory index: seqnum -> { offset, length }\n private readonly headerIndex: Map<number, { offset: number, length: number }> = new Map()\n\n /**\n * Creates a FileSessionStore with the default file-based stream provider.\n */\n static createWithFiles (sessionId: SessionId, directory: string): FileSessionStore {\n return new FileSessionStore(sessionId, new FileSessionStreamProvider(sessionId, directory), true)\n }\n\n /**\n * Creates a FileSessionStore with a custom stream provider.\n * Useful for testing with in-memory streams.\n */\n constructor (\n public readonly sessionId: SessionId,\n streamProvider: ISessionStreamProvider,\n ownsProvider: boolean = false\n ) {\n this.streamProvider = streamProvider\n this.ownsProvider = ownsProvider\n }\n\n /**\n * Gets the stream provider for direct access (useful for testing).\n */\n getStreamProvider (): ISessionStreamProvider {\n return this.streamProvider\n }\n\n // Sequence Numbers\n\n get senderSeqNum (): number {\n return this.senderSeqNumValue\n }\n\n set senderSeqNum (value: number) {\n this.senderSeqNumValue = value\n }\n\n get targetSeqNum (): number {\n return this.targetSeqNumValue\n }\n\n set targetSeqNum (value: number) {\n this.targetSeqNumValue = value\n }\n\n async setSenderSeqNum (value: number): Promise<void> {\n this.senderSeqNumValue = value\n await this.persistSeqNums()\n }\n\n async setTargetSeqNum (value: number): Promise<void> {\n this.targetSeqNumValue = value\n await this.persistSeqNums()\n }\n\n async nextSenderSeqNum (): Promise<number> {\n const next = ++this.senderSeqNumValue\n await this.persistSeqNums()\n return next\n }\n\n async nextTargetSeqNum (): Promise<number> {\n const next = ++this.targetSeqNumValue\n await this.persistSeqNums()\n return next\n }\n\n // Session\n\n get creationTime (): Date {\n return this.creationTimeValue\n }\n\n async reset (): Promise<void> {\n this.senderSeqNumValue = 1\n this.targetSeqNumValue = 1\n this.creationTimeValue = new Date()\n this.headerIndex.clear()\n\n await this.streamProvider.reset()\n await this.persistSeqNums()\n await this.persistSessionTime()\n this.streamProvider.openBody()\n }\n\n // Message Operations\n\n async put (record: IFixMsgStoreRecord): Promise<void> {\n if (record.encoded == null) {\n throw new Error('Record must have encoded content')\n }\n\n const bytes = Buffer.from(record.encoded, 'utf8')\n const length = bytes.length\n const offset = await this.streamProvider.appendBody(bytes)\n this.headerIndex.set(record.seqNum, { offset, length })\n await this.streamProvider.appendHeaderLine(`${record.seqNum},${offset},${length}`)\n }\n\n async get (seqNum: number): Promise<IFixMsgStoreRecord | null> {\n const entry = this.headerIndex.get(seqNum)\n if (!entry) return null\n return await this.readMessage(seqNum, entry.offset, entry.length)\n }\n\n async getRange (fromSeqNum: number, toSeqNum: number): Promise<IFixMsgStoreRecord[]> {\n const results: IFixMsgStoreRecord[] = []\n for (let seq = fromSeqNum; seq <= toSeqNum; seq++) {\n const record = await this.get(seq)\n if (record) {\n results.push(record)\n }\n }\n return results\n }\n\n // Lifecycle\n\n async initialize (): Promise<void> {\n await this.loadSeqNums()\n await this.loadSessionTime()\n await this.loadHeaderIndex()\n this.streamProvider.openBody()\n }\n\n async flush (): Promise<void> {\n await this.streamProvider.flush()\n }\n\n async dispose (): Promise<void> {\n await this.streamProvider.flush()\n if (this.ownsProvider) {\n await this.streamProvider.dispose()\n }\n }\n\n // Private - persistence\n\n private async persistSeqNums (): Promise<void> {\n const sender = this.senderSeqNumValue.toString().padStart(20, ' ')\n const target = this.targetSeqNumValue.toString().padStart(20, ' ')\n await this.streamProvider.writeSeqNums(`${sender} : ${target}`)\n }\n\n private async loadSeqNums (): Promise<void> {\n const content = await this.streamProvider.readSeqNums()\n if (content == null) {\n this.senderSeqNumValue = 1\n this.targetSeqNumValue = 1\n return\n }\n const parts = content.split(':')\n if (parts.length === 2) {\n this.senderSeqNumValue = parseInt(parts[0].trim(), 10) || 1\n this.targetSeqNumValue = parseInt(parts[1].trim(), 10) || 1\n }\n }\n\n private async persistSessionTime (): Promise<void> {\n await this.streamProvider.writeSessionTime(FileSessionStore.formatSessionTime(this.creationTimeValue))\n }\n\n private async loadSessionTime (): Promise<void> {\n const content = await this.streamProvider.readSessionTime()\n if (content == null) {\n this.creationTimeValue = new Date()\n await this.persistSessionTime()\n return\n }\n const parsed = FileSessionStore.parseSessionTime(content.trim())\n this.creationTimeValue = parsed ?? new Date()\n }\n\n private async loadHeaderIndex (): Promise<void> {\n const lines = await this.streamProvider.readHeaderLines()\n for (const line of lines) {\n if (!line.trim()) continue\n const parts = line.split(',')\n if (parts.length === 3) {\n const seqNum = parseInt(parts[0], 10)\n const offset = parseInt(parts[1], 10)\n const length = parseInt(parts[2], 10)\n if (!isNaN(seqNum) && !isNaN(offset) && !isNaN(length)) {\n this.headerIndex.set(seqNum, { offset, length })\n }\n }\n }\n }\n\n // Private - message reading\n\n private async readMessage (seqNum: number, offset: number, length: number): Promise<IFixMsgStoreRecord | null> {\n const buffer = await this.streamProvider.readBody(offset, length)\n if (buffer.length !== length) return null\n\n const encoded = buffer.toString('utf8')\n const msgType = FileSessionStore.extractTag(encoded, '35')\n const sendingTimeStr = FileSessionStore.extractTag(encoded, '52')\n let timestamp = new Date(0)\n if (sendingTimeStr) {\n const parsed = FileSessionStore.parseSessionTime(sendingTimeStr)\n if (parsed) timestamp = parsed\n }\n\n return new FixMsgStoreRecord(msgType ?? '', timestamp, seqNum, undefined, encoded)\n }\n\n /**\n * Extract a FIX tag value from a raw message string.\n * Tags are delimited by SOH (0x01) or pipe (|).\n */\n static extractTag (message: string, tag: string): string | null {\n const tagPrefix = `${tag}=`\n\n // Check if tag is at the start\n if (message.startsWith(tagPrefix)) {\n const endIndex = FileSessionStore.findDelimiter(message, tagPrefix.length)\n return message.substring(tagPrefix.length, endIndex)\n }\n\n // Search for SOH + tag= or | + tag=\n for (const delim of ['\\x01', '|']) {\n const search = `${delim}${tagPrefix}`\n const idx = message.indexOf(search)\n if (idx >= 0) {\n const startIndex = idx + search.length\n const endIndex = FileSessionStore.findDelimiter(message, startIndex)\n return message.substring(startIndex, endIndex)\n }\n }\n\n return null\n }\n\n private static findDelimiter (message: string, fromIndex: number): number {\n for (let i = fromIndex; i < message.length; i++) {\n const ch = message.charAt(i)\n if (ch === '\\x01' || ch === '|') return i\n }\n return message.length\n }\n\n /**\n * Format a date as QuickFix session time: YYYYMMDD-HH:MM:SS.ffffff\n */\n static formatSessionTime (date: Date): string {\n const y = date.getUTCFullYear()\n const M = (date.getUTCMonth() + 1).toString().padStart(2, '0')\n const d = date.getUTCDate().toString().padStart(2, '0')\n const h = date.getUTCHours().toString().padStart(2, '0')\n const m = date.getUTCMinutes().toString().padStart(2, '0')\n const s = date.getUTCSeconds().toString().padStart(2, '0')\n const ms = date.getUTCMilliseconds().toString().padStart(3, '0')\n return `${y}${M}${d}-${h}:${m}:${s}.${ms}000`\n }\n\n /**\n * Parse a QuickFix session time string: YYYYMMDD-HH:MM:SS.fff[fff]\n */\n static parseSessionTime (str: string): Date | null {\n // Format: YYYYMMDD-HH:MM:SS.ffffff\n const match = str.match(/^(\\d{4})(\\d{2})(\\d{2})-(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3,6})$/)\n if (!match) return null\n const [, y, M, d, h, m, s, frac] = match\n const ms = parseInt(frac.substring(0, 3), 10)\n return new Date(Date.UTC(parseInt(y), parseInt(M) - 1, parseInt(d), parseInt(h), parseInt(m), parseInt(s), ms))\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import { ISessionStreamProvider } from './session-stream-provider';
2
+ import { SessionId } from './session-id';
3
+ export declare class FileSessionStreamProvider implements ISessionStreamProvider {
4
+ private readonly bodyPath;
5
+ private readonly headerPath;
6
+ private readonly seqNumsPath;
7
+ private readonly sessionPath;
8
+ private bodyFd;
9
+ private bodySize;
10
+ constructor(sessionId: SessionId, directory: string);
11
+ openBody(): void;
12
+ appendBody(data: Buffer): Promise<number>;
13
+ readBody(offset: number, length: number): Promise<Buffer>;
14
+ getBodySize(): number;
15
+ appendHeaderLine(line: string): Promise<void>;
16
+ readHeaderLines(): Promise<string[]>;
17
+ readSeqNums(): Promise<string | null>;
18
+ writeSeqNums(content: string): Promise<void>;
19
+ readSessionTime(): Promise<string | null>;
20
+ writeSessionTime(content: string): Promise<void>;
21
+ reset(): Promise<void>;
22
+ flush(): Promise<void>;
23
+ dispose(): Promise<void>;
24
+ private deleteIfExists;
25
+ }
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.FileSessionStreamProvider = void 0;
46
+ const fs = __importStar(require("fs"));
47
+ class FileSessionStreamProvider {
48
+ constructor(sessionId, directory) {
49
+ this.bodyFd = null;
50
+ this.bodySize = 0;
51
+ fs.mkdirSync(directory, { recursive: true });
52
+ this.bodyPath = sessionId.getFilePath(directory, 'body');
53
+ this.headerPath = sessionId.getFilePath(directory, 'header');
54
+ this.seqNumsPath = sessionId.getFilePath(directory, 'seqnums');
55
+ this.sessionPath = sessionId.getFilePath(directory, 'session');
56
+ }
57
+ openBody() {
58
+ if (this.bodyFd !== null)
59
+ return;
60
+ this.bodyFd = fs.openSync(this.bodyPath, 'a+');
61
+ const stat = fs.fstatSync(this.bodyFd);
62
+ this.bodySize = stat.size;
63
+ }
64
+ appendBody(data) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ if (this.bodyFd === null) {
67
+ this.openBody();
68
+ }
69
+ const offset = this.bodySize;
70
+ fs.writeSync(this.bodyFd, data, 0, data.length, offset);
71
+ this.bodySize += data.length;
72
+ return offset;
73
+ });
74
+ }
75
+ readBody(offset, length) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (this.bodyFd === null) {
78
+ this.openBody();
79
+ }
80
+ const buf = Buffer.alloc(length);
81
+ fs.readSync(this.bodyFd, buf, 0, length, offset);
82
+ return buf;
83
+ });
84
+ }
85
+ getBodySize() {
86
+ return this.bodySize;
87
+ }
88
+ appendHeaderLine(line) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ yield fs.promises.appendFile(this.headerPath, line + '\n', 'utf8');
91
+ });
92
+ }
93
+ readHeaderLines() {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ if (!fs.existsSync(this.headerPath))
96
+ return [];
97
+ const content = yield fs.promises.readFile(this.headerPath, 'utf8');
98
+ if (!content.trim())
99
+ return [];
100
+ return content.split('\n').filter(l => l.trim().length > 0);
101
+ });
102
+ }
103
+ readSeqNums() {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ if (!fs.existsSync(this.seqNumsPath))
106
+ return null;
107
+ return yield fs.promises.readFile(this.seqNumsPath, 'utf8');
108
+ });
109
+ }
110
+ writeSeqNums(content) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ yield fs.promises.writeFile(this.seqNumsPath, content, 'utf8');
113
+ });
114
+ }
115
+ readSessionTime() {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ if (!fs.existsSync(this.sessionPath))
118
+ return null;
119
+ return yield fs.promises.readFile(this.sessionPath, 'utf8');
120
+ });
121
+ }
122
+ writeSessionTime(content) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ yield fs.promises.writeFile(this.sessionPath, content, 'utf8');
125
+ });
126
+ }
127
+ reset() {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ if (this.bodyFd !== null) {
130
+ fs.closeSync(this.bodyFd);
131
+ this.bodyFd = null;
132
+ }
133
+ this.bodySize = 0;
134
+ this.deleteIfExists(this.bodyPath);
135
+ this.deleteIfExists(this.headerPath);
136
+ this.deleteIfExists(this.seqNumsPath);
137
+ this.deleteIfExists(this.sessionPath);
138
+ });
139
+ }
140
+ flush() {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ if (this.bodyFd !== null) {
143
+ fs.fsyncSync(this.bodyFd);
144
+ }
145
+ });
146
+ }
147
+ dispose() {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ if (this.bodyFd !== null) {
150
+ fs.closeSync(this.bodyFd);
151
+ this.bodyFd = null;
152
+ }
153
+ });
154
+ }
155
+ deleteIfExists(filePath) {
156
+ if (fs.existsSync(filePath)) {
157
+ fs.unlinkSync(filePath);
158
+ }
159
+ }
160
+ }
161
+ exports.FileSessionStreamProvider = FileSessionStreamProvider;
162
+ //# sourceMappingURL=file-session-stream-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-session-stream-provider.js","sourceRoot":"","sources":["../../src/store/file-session-stream-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAwB;AAcxB,MAAa,yBAAyB;IAQpC,YACE,SAAoB,EACpB,SAAiB;QALX,WAAM,GAAkB,IAAI,CAAA;QAC5B,aAAQ,GAAW,CAAC,CAAA;QAM1B,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAC5C,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QACxD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,WAAW,CAAC,SAA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C;CACF;AA5GD,8DA4GC","sourcesContent":["import * as fs from 'fs'\nimport { ISessionStreamProvider } from './session-stream-provider'\nimport { SessionId } from './session-id'\n\n/**\n * File-based implementation of ISessionStreamProvider.\n * Creates QuickFix-compatible files in the specified directory.\n *\n * Files created:\n * - {prefix}.body — concatenated raw FIX messages\n * - {prefix}.header — index lines: \"seqnum,offset,length\"\n * - {prefix}.seqnums — sender/target sequence numbers\n * - {prefix}.session — session creation time\n */\nexport class FileSessionStreamProvider implements ISessionStreamProvider {\n private readonly bodyPath: string\n private readonly headerPath: string\n private readonly seqNumsPath: string\n private readonly sessionPath: string\n private bodyFd: number | null = null\n private bodySize: number = 0\n\n constructor (\n sessionId: SessionId,\n directory: string\n ) {\n fs.mkdirSync(directory, { recursive: true })\n this.bodyPath = sessionId.getFilePath(directory, 'body')\n this.headerPath = sessionId.getFilePath(directory, 'header')\n this.seqNumsPath = sessionId.getFilePath(directory, 'seqnums')\n this.sessionPath = sessionId.getFilePath(directory, 'session')\n }\n\n openBody (): void {\n if (this.bodyFd !== null) return\n this.bodyFd = fs.openSync(this.bodyPath, 'a+')\n const stat = fs.fstatSync(this.bodyFd)\n this.bodySize = stat.size\n }\n\n async appendBody (data: Buffer): Promise<number> {\n if (this.bodyFd === null) {\n this.openBody()\n }\n const offset = this.bodySize\n fs.writeSync(this.bodyFd!, data, 0, data.length, offset)\n this.bodySize += data.length\n return offset\n }\n\n async readBody (offset: number, length: number): Promise<Buffer> {\n if (this.bodyFd === null) {\n this.openBody()\n }\n const buf = Buffer.alloc(length)\n fs.readSync(this.bodyFd!, buf, 0, length, offset)\n return buf\n }\n\n getBodySize (): number {\n return this.bodySize\n }\n\n async appendHeaderLine (line: string): Promise<void> {\n await fs.promises.appendFile(this.headerPath, line + '\\n', 'utf8')\n }\n\n async readHeaderLines (): Promise<string[]> {\n if (!fs.existsSync(this.headerPath)) return []\n const content = await fs.promises.readFile(this.headerPath, 'utf8')\n if (!content.trim()) return []\n return content.split('\\n').filter(l => l.trim().length > 0)\n }\n\n async readSeqNums (): Promise<string | null> {\n if (!fs.existsSync(this.seqNumsPath)) return null\n return await fs.promises.readFile(this.seqNumsPath, 'utf8')\n }\n\n async writeSeqNums (content: string): Promise<void> {\n await fs.promises.writeFile(this.seqNumsPath, content, 'utf8')\n }\n\n async readSessionTime (): Promise<string | null> {\n if (!fs.existsSync(this.sessionPath)) return null\n return await fs.promises.readFile(this.sessionPath, 'utf8')\n }\n\n async writeSessionTime (content: string): Promise<void> {\n await fs.promises.writeFile(this.sessionPath, content, 'utf8')\n }\n\n async reset (): Promise<void> {\n if (this.bodyFd !== null) {\n fs.closeSync(this.bodyFd)\n this.bodyFd = null\n }\n this.bodySize = 0\n this.deleteIfExists(this.bodyPath)\n this.deleteIfExists(this.headerPath)\n this.deleteIfExists(this.seqNumsPath)\n this.deleteIfExists(this.sessionPath)\n }\n\n async flush (): Promise<void> {\n if (this.bodyFd !== null) {\n fs.fsyncSync(this.bodyFd)\n }\n }\n\n async dispose (): Promise<void> {\n if (this.bodyFd !== null) {\n fs.closeSync(this.bodyFd)\n this.bodyFd = null\n }\n }\n\n private deleteIfExists (filePath: string): void {\n if (fs.existsSync(filePath)) {\n fs.unlinkSync(filePath)\n }\n }\n}\n"]}
@@ -22,6 +22,12 @@ class FixMsgAsciiStoreResend {
22
22
  }
23
23
  getResendRequest(startSeq, endSeq) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
+ var _a;
26
+ if (((_a = this.config.description.store) === null || _a === void 0 ? void 0 : _a.resendGapFillOnly) === true) {
27
+ const gapFillOnly = [];
28
+ this.gap(startSeq, endSeq + 1, gapFillOnly);
29
+ return gapFillOnly;
30
+ }
25
31
  return yield new Promise((resolve, reject) => {
26
32
  this.store.getSeqNumRange(startSeq, endSeq).then(res => {
27
33
  resolve(this.inflateRange(startSeq, endSeq, res));