@homaiohq/napi-quickfix 0.1.0 → 0.2.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 (141) hide show
  1. package/CMakeLists.txt +5 -1
  2. package/README.md +235 -18
  3. package/cpp/acceptor_wrap.cpp +253 -19
  4. package/cpp/acceptor_wrap.h +60 -1
  5. package/cpp/addon.cpp +10 -6
  6. package/cpp/application_bridge.cpp +114 -30
  7. package/cpp/application_bridge.h +57 -4
  8. package/cpp/data_dictionary_wrap.cpp +89 -3
  9. package/cpp/data_dictionary_wrap.h +27 -5
  10. package/cpp/engine_common.h +108 -0
  11. package/cpp/engine_workers.h +99 -18
  12. package/cpp/field_map_ops.h +492 -0
  13. package/cpp/group_wrap.cpp +221 -0
  14. package/cpp/group_wrap.h +76 -0
  15. package/cpp/initiator_wrap.cpp +262 -25
  16. package/cpp/initiator_wrap.h +37 -2
  17. package/cpp/message_wrap.cpp +171 -78
  18. package/cpp/message_wrap.h +47 -5
  19. package/cpp/session_op_gate.h +201 -0
  20. package/cpp/session_static.cpp +139 -12
  21. package/cpp/session_wrap.cpp +438 -0
  22. package/cpp/session_wrap.h +144 -0
  23. package/dist/cjs/acceptor.d.ts +0 -1
  24. package/dist/cjs/acceptor.js +0 -1
  25. package/dist/cjs/application.d.ts +0 -1
  26. package/dist/cjs/application.js +0 -1
  27. package/dist/cjs/data-dictionary.d.ts +21 -3
  28. package/dist/cjs/data-dictionary.js +32 -4
  29. package/dist/cjs/engine.d.ts +42 -4
  30. package/dist/cjs/engine.js +50 -5
  31. package/dist/cjs/enums.d.ts +48 -14
  32. package/dist/cjs/enums.js +20 -25
  33. package/dist/cjs/field-value.d.ts +12 -0
  34. package/dist/cjs/field-value.js +40 -0
  35. package/dist/cjs/generated/fields.d.ts +0 -1
  36. package/dist/cjs/generated/fields.js +0 -1
  37. package/dist/cjs/generated/values.d.ts +8548 -0
  38. package/dist/cjs/generated/values.js +8580 -0
  39. package/dist/cjs/group.d.ts +126 -0
  40. package/dist/cjs/group.js +185 -0
  41. package/dist/cjs/index.d.ts +26 -5
  42. package/dist/cjs/index.js +28 -28
  43. package/dist/cjs/initiator.d.ts +0 -1
  44. package/dist/cjs/initiator.js +0 -1
  45. package/dist/cjs/message.d.ts +129 -5
  46. package/dist/cjs/message.js +146 -9
  47. package/dist/cjs/native.d.ts +179 -17
  48. package/dist/cjs/native.js +0 -1
  49. package/dist/cjs/session-id.d.ts +12 -1
  50. package/dist/cjs/session-id.js +21 -1
  51. package/dist/cjs/session-settings.d.ts +0 -1
  52. package/dist/cjs/session-settings.js +0 -1
  53. package/dist/cjs/session.d.ts +213 -0
  54. package/dist/cjs/session.js +337 -0
  55. package/dist/esm/acceptor.d.ts +0 -1
  56. package/dist/esm/acceptor.js +0 -1
  57. package/dist/esm/application.d.ts +0 -1
  58. package/dist/esm/application.js +0 -1
  59. package/dist/esm/data-dictionary.d.ts +21 -3
  60. package/dist/esm/data-dictionary.js +32 -4
  61. package/dist/esm/engine.d.ts +42 -4
  62. package/dist/esm/engine.js +51 -6
  63. package/dist/esm/enums.d.ts +48 -14
  64. package/dist/esm/enums.js +14 -24
  65. package/dist/esm/field-value.d.ts +12 -0
  66. package/dist/esm/field-value.js +37 -0
  67. package/dist/esm/generated/fields.d.ts +0 -1
  68. package/dist/esm/generated/fields.js +0 -1
  69. package/dist/esm/generated/values.d.ts +8548 -0
  70. package/dist/esm/generated/values.js +8564 -0
  71. package/dist/esm/group.d.ts +126 -0
  72. package/dist/esm/group.js +181 -0
  73. package/dist/esm/index.d.ts +26 -5
  74. package/dist/esm/index.js +17 -26
  75. package/dist/esm/initiator.d.ts +0 -1
  76. package/dist/esm/initiator.js +0 -1
  77. package/dist/esm/message.d.ts +129 -5
  78. package/dist/esm/message.js +146 -9
  79. package/dist/esm/native.d.ts +179 -17
  80. package/dist/esm/native.js +0 -1
  81. package/dist/esm/session-id.d.ts +12 -1
  82. package/dist/esm/session-id.js +20 -1
  83. package/dist/esm/session-settings.d.ts +0 -1
  84. package/dist/esm/session-settings.js +0 -1
  85. package/dist/esm/session.d.ts +213 -0
  86. package/dist/esm/session.js +329 -0
  87. package/package.json +13 -1
  88. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  89. package/prebuilds/darwin-x64/node.napi.node +0 -0
  90. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  91. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  92. package/prebuilds/win32-x64/node.napi.node +0 -0
  93. package/cpp/enums.cpp +0 -66
  94. package/dist/cjs/acceptor.d.ts.map +0 -1
  95. package/dist/cjs/acceptor.js.map +0 -1
  96. package/dist/cjs/application.d.ts.map +0 -1
  97. package/dist/cjs/application.js.map +0 -1
  98. package/dist/cjs/data-dictionary.d.ts.map +0 -1
  99. package/dist/cjs/data-dictionary.js.map +0 -1
  100. package/dist/cjs/engine.d.ts.map +0 -1
  101. package/dist/cjs/engine.js.map +0 -1
  102. package/dist/cjs/enums.d.ts.map +0 -1
  103. package/dist/cjs/enums.js.map +0 -1
  104. package/dist/cjs/generated/fields.d.ts.map +0 -1
  105. package/dist/cjs/generated/fields.js.map +0 -1
  106. package/dist/cjs/index.d.ts.map +0 -1
  107. package/dist/cjs/index.js.map +0 -1
  108. package/dist/cjs/initiator.d.ts.map +0 -1
  109. package/dist/cjs/initiator.js.map +0 -1
  110. package/dist/cjs/message.d.ts.map +0 -1
  111. package/dist/cjs/message.js.map +0 -1
  112. package/dist/cjs/native.d.ts.map +0 -1
  113. package/dist/cjs/native.js.map +0 -1
  114. package/dist/cjs/session-id.d.ts.map +0 -1
  115. package/dist/cjs/session-id.js.map +0 -1
  116. package/dist/cjs/session-settings.d.ts.map +0 -1
  117. package/dist/cjs/session-settings.js.map +0 -1
  118. package/dist/esm/acceptor.d.ts.map +0 -1
  119. package/dist/esm/acceptor.js.map +0 -1
  120. package/dist/esm/application.d.ts.map +0 -1
  121. package/dist/esm/application.js.map +0 -1
  122. package/dist/esm/data-dictionary.d.ts.map +0 -1
  123. package/dist/esm/data-dictionary.js.map +0 -1
  124. package/dist/esm/engine.d.ts.map +0 -1
  125. package/dist/esm/engine.js.map +0 -1
  126. package/dist/esm/enums.d.ts.map +0 -1
  127. package/dist/esm/enums.js.map +0 -1
  128. package/dist/esm/generated/fields.d.ts.map +0 -1
  129. package/dist/esm/generated/fields.js.map +0 -1
  130. package/dist/esm/index.d.ts.map +0 -1
  131. package/dist/esm/index.js.map +0 -1
  132. package/dist/esm/initiator.d.ts.map +0 -1
  133. package/dist/esm/initiator.js.map +0 -1
  134. package/dist/esm/message.d.ts.map +0 -1
  135. package/dist/esm/message.js.map +0 -1
  136. package/dist/esm/native.d.ts.map +0 -1
  137. package/dist/esm/native.js.map +0 -1
  138. package/dist/esm/session-id.d.ts.map +0 -1
  139. package/dist/esm/session-id.js.map +0 -1
  140. package/dist/esm/session-settings.d.ts.map +0 -1
  141. package/dist/esm/session-settings.js.map +0 -1
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Ergonomic wrapper around the native `FIX::Group`: one entry of a repeating
3
+ * group.
4
+ */
5
+ import { type NativeGroup } from './native.js';
6
+ /**
7
+ * One entry of a FIX repeating group.
8
+ *
9
+ * A group is identified by its **count tag** (`field`, e.g. `453 NoPartyIDs`)
10
+ * and its **delimiter** (`delim`, the first tag of every entry, e.g.
11
+ * `448 PartyID`). Build an entry, fill its fields, then
12
+ * {@link Message.addGroup} it; QuickFIX maintains the count field for you.
13
+ *
14
+ * Field values are accepted as `string | number` on input (numbers are written
15
+ * without exponent notation) and always returned as `string`, exactly as on
16
+ * {@link Message}. Groups nest: an entry can carry its own repeating groups
17
+ * through the same `addGroup` / `getGroup` API.
18
+ *
19
+ * Entries read back with `getGroup` are **snapshot copies**: mutating one does
20
+ * not change the message it came from. Write it back with
21
+ * {@link Message.replaceGroup}.
22
+ *
23
+ * Group indices are **1-based**, as in QuickFIX.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { Group, Message, FIELD } from '@homaiohq/napi-quickfix';
28
+ *
29
+ * const party = new Group(FIELD.NoPartyIDs, FIELD.PartyID)
30
+ * .setField(FIELD.PartyID, 'TRADER-1')
31
+ * .setField(FIELD.PartyIDSource, 'D')
32
+ * .setField(FIELD.PartyRole, 11);
33
+ * order.addGroup(party);
34
+ *
35
+ * order.groupCount(FIELD.NoPartyIDs); // 1
36
+ * order.getGroup(1, FIELD.NoPartyIDs).getField(FIELD.PartyID); // 'TRADER-1'
37
+ * ```
38
+ */
39
+ export declare class Group {
40
+ #private;
41
+ /**
42
+ * Create an empty group entry.
43
+ *
44
+ * @param field The group's count tag (e.g. `FIELD.NoPartyIDs`), or an
45
+ * existing native handle to adopt (internal).
46
+ * @param delim The delimiter: the first tag of every entry (e.g.
47
+ * `FIELD.PartyID`).
48
+ * @param order Optional complete field order of an entry, delimiter first
49
+ * (e.g. `[448, 447, 452]`). Fields not listed sort after the listed ones by
50
+ * tag number. Without it, fields sort delimiter-first then by tag number,
51
+ * which already matches the standard dictionaries for most groups.
52
+ */
53
+ constructor(field: number | NativeGroup, delim?: number, order?: readonly number[]);
54
+ /** @internal Wrap an existing native group handle. */
55
+ static fromNative(handle: NativeGroup): Group;
56
+ /** @internal The native handle backing this group. */
57
+ get nativeHandle(): NativeGroup;
58
+ /** The group's count tag (e.g. `453` for `NoPartyIDs`). */
59
+ get field(): number;
60
+ /** The delimiter: the first tag of every entry (e.g. `448` for `PartyID`). */
61
+ get delim(): number;
62
+ /**
63
+ * Read a field by tag.
64
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) if absent.
65
+ */
66
+ getField(tag: number): string;
67
+ /** Set a field. Returns `this` for chaining. */
68
+ setField(tag: number, value: string | number): this;
69
+ /** Whether a field is present. */
70
+ isSetField(tag: number): boolean;
71
+ /** Remove a field (no-op if absent). Returns `this` for chaining. */
72
+ removeField(tag: number): this;
73
+ /** Read a field by tag, or `undefined` if absent. */
74
+ getFieldIfSet(tag: number): string | undefined;
75
+ /** The number of fields, including every field of every nested group entry. */
76
+ totalFields(): number;
77
+ /** Whether the entry has no fields of its own. */
78
+ isEmpty(): boolean;
79
+ /** Remove every field and nested group. Returns `this` for chaining. */
80
+ clear(): this;
81
+ /** The entry's own fields, in wire order, as `[tag, value]` pairs. */
82
+ fields(): [number, string][];
83
+ /** Iterates the entry's own fields as `[tag, value]` pairs (see {@link Group.fields}). */
84
+ [Symbol.iterator](): IterableIterator<[number, string]>;
85
+ /**
86
+ * Append a nested group entry under its own count tag (a copy is stored; the
87
+ * count field is updated). Returns `this` for chaining.
88
+ * @throws `TypeError` when `group.delim` differs from the delimiter of the
89
+ * entries already stored under `group.field`.
90
+ */
91
+ addGroup(group: Group): this;
92
+ /**
93
+ * A snapshot copy of the `index`-th entry (1-based) of the nested group `tag`.
94
+ * Mutations do not affect this entry; write them back with
95
+ * {@link Group.replaceGroup}.
96
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) when the tag
97
+ * has no entries or `index` is out of range.
98
+ */
99
+ getGroup(index: number, tag: number): Group;
100
+ /**
101
+ * Overwrite the `index`-th entry (1-based) under `group.field` with a copy of
102
+ * `group`. Returns `this` for chaining.
103
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) when that
104
+ * entry does not exist.
105
+ * @throws `TypeError` when `group.delim` differs from the stored entry's
106
+ * delimiter.
107
+ */
108
+ replaceGroup(index: number, group: Group): this;
109
+ /**
110
+ * Remove every entry of the nested group `tag` (and its count field), or
111
+ * only the `index`-th entry (1-based). Returns `this`.
112
+ *
113
+ * Removing every entry of a tag that has none is a no-op.
114
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) when the
115
+ * `index`-th entry does not exist.
116
+ */
117
+ removeGroup(tag: number): this;
118
+ removeGroup(index: number, tag: number): this;
119
+ /** Whether the nested group `tag` has any entry, or has an `index`-th entry (1-based). */
120
+ hasGroup(tag: number): boolean;
121
+ hasGroup(index: number, tag: number): boolean;
122
+ /** The number of entries of the nested group `tag` (0 if none). */
123
+ groupCount(tag: number): number;
124
+ /** The entry's fields (and nested groups) as a SOH-delimited string, in wire order. */
125
+ toString(): string;
126
+ }
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Group = void 0;
4
+ /**
5
+ * Ergonomic wrapper around the native `FIX::Group`: one entry of a repeating
6
+ * group.
7
+ */
8
+ const native_js_1 = require("./native.js");
9
+ const field_value_js_1 = require("./field-value.js");
10
+ /**
11
+ * One entry of a FIX repeating group.
12
+ *
13
+ * A group is identified by its **count tag** (`field`, e.g. `453 NoPartyIDs`)
14
+ * and its **delimiter** (`delim`, the first tag of every entry, e.g.
15
+ * `448 PartyID`). Build an entry, fill its fields, then
16
+ * {@link Message.addGroup} it; QuickFIX maintains the count field for you.
17
+ *
18
+ * Field values are accepted as `string | number` on input (numbers are written
19
+ * without exponent notation) and always returned as `string`, exactly as on
20
+ * {@link Message}. Groups nest: an entry can carry its own repeating groups
21
+ * through the same `addGroup` / `getGroup` API.
22
+ *
23
+ * Entries read back with `getGroup` are **snapshot copies**: mutating one does
24
+ * not change the message it came from. Write it back with
25
+ * {@link Message.replaceGroup}.
26
+ *
27
+ * Group indices are **1-based**, as in QuickFIX.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { Group, Message, FIELD } from '@homaiohq/napi-quickfix';
32
+ *
33
+ * const party = new Group(FIELD.NoPartyIDs, FIELD.PartyID)
34
+ * .setField(FIELD.PartyID, 'TRADER-1')
35
+ * .setField(FIELD.PartyIDSource, 'D')
36
+ * .setField(FIELD.PartyRole, 11);
37
+ * order.addGroup(party);
38
+ *
39
+ * order.groupCount(FIELD.NoPartyIDs); // 1
40
+ * order.getGroup(1, FIELD.NoPartyIDs).getField(FIELD.PartyID); // 'TRADER-1'
41
+ * ```
42
+ */
43
+ class Group {
44
+ /** @internal Underlying native handle. */
45
+ #native;
46
+ /**
47
+ * Create an empty group entry.
48
+ *
49
+ * @param field The group's count tag (e.g. `FIELD.NoPartyIDs`), or an
50
+ * existing native handle to adopt (internal).
51
+ * @param delim The delimiter: the first tag of every entry (e.g.
52
+ * `FIELD.PartyID`).
53
+ * @param order Optional complete field order of an entry, delimiter first
54
+ * (e.g. `[448, 447, 452]`). Fields not listed sort after the listed ones by
55
+ * tag number. Without it, fields sort delimiter-first then by tag number,
56
+ * which already matches the standard dictionaries for most groups.
57
+ */
58
+ constructor(field, delim, order) {
59
+ if (typeof field !== 'number') {
60
+ // Adopt an existing native handle (getGroup path).
61
+ this.#native = field;
62
+ }
63
+ else {
64
+ if (typeof delim !== 'number') {
65
+ throw new TypeError('new Group(field: number, delim: number, order?: number[])');
66
+ }
67
+ this.#native = new native_js_1.native.GroupWrap(field, delim, order);
68
+ }
69
+ }
70
+ /** @internal Wrap an existing native group handle. */
71
+ static fromNative(handle) {
72
+ return new Group(handle);
73
+ }
74
+ /** @internal The native handle backing this group. */
75
+ get nativeHandle() {
76
+ return this.#native;
77
+ }
78
+ /** The group's count tag (e.g. `453` for `NoPartyIDs`). */
79
+ get field() {
80
+ return this.#native.field();
81
+ }
82
+ /** The delimiter: the first tag of every entry (e.g. `448` for `PartyID`). */
83
+ get delim() {
84
+ return this.#native.delim();
85
+ }
86
+ /**
87
+ * Read a field by tag.
88
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) if absent.
89
+ */
90
+ getField(tag) {
91
+ return this.#native.getField(tag);
92
+ }
93
+ /** Set a field. Returns `this` for chaining. */
94
+ setField(tag, value) {
95
+ this.#native.setField(tag, (0, field_value_js_1.formatFieldValue)(value));
96
+ return this;
97
+ }
98
+ /** Whether a field is present. */
99
+ isSetField(tag) {
100
+ return this.#native.isSetField(tag);
101
+ }
102
+ /** Remove a field (no-op if absent). Returns `this` for chaining. */
103
+ removeField(tag) {
104
+ this.#native.removeField(tag);
105
+ return this;
106
+ }
107
+ /** Read a field by tag, or `undefined` if absent. */
108
+ getFieldIfSet(tag) {
109
+ return this.#native.getFieldIfSet(tag);
110
+ }
111
+ /** The number of fields, including every field of every nested group entry. */
112
+ totalFields() {
113
+ return this.#native.totalFields();
114
+ }
115
+ /** Whether the entry has no fields of its own. */
116
+ isEmpty() {
117
+ return this.#native.isEmpty();
118
+ }
119
+ /** Remove every field and nested group. Returns `this` for chaining. */
120
+ clear() {
121
+ this.#native.clear();
122
+ return this;
123
+ }
124
+ /** The entry's own fields, in wire order, as `[tag, value]` pairs. */
125
+ fields() {
126
+ return this.#native.fields();
127
+ }
128
+ /** Iterates the entry's own fields as `[tag, value]` pairs (see {@link Group.fields}). */
129
+ [Symbol.iterator]() {
130
+ return this.fields()[Symbol.iterator]();
131
+ }
132
+ /**
133
+ * Append a nested group entry under its own count tag (a copy is stored; the
134
+ * count field is updated). Returns `this` for chaining.
135
+ * @throws `TypeError` when `group.delim` differs from the delimiter of the
136
+ * entries already stored under `group.field`.
137
+ */
138
+ addGroup(group) {
139
+ this.#native.addGroup(group.nativeHandle);
140
+ return this;
141
+ }
142
+ /**
143
+ * A snapshot copy of the `index`-th entry (1-based) of the nested group `tag`.
144
+ * Mutations do not affect this entry; write them back with
145
+ * {@link Group.replaceGroup}.
146
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) when the tag
147
+ * has no entries or `index` is out of range.
148
+ */
149
+ getGroup(index, tag) {
150
+ return Group.fromNative(this.#native.getGroup(index, tag));
151
+ }
152
+ /**
153
+ * Overwrite the `index`-th entry (1-based) under `group.field` with a copy of
154
+ * `group`. Returns `this` for chaining.
155
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) when that
156
+ * entry does not exist.
157
+ * @throws `TypeError` when `group.delim` differs from the stored entry's
158
+ * delimiter.
159
+ */
160
+ replaceGroup(index, group) {
161
+ this.#native.replaceGroup(index, group.nativeHandle);
162
+ return this;
163
+ }
164
+ removeGroup(a, b) {
165
+ if (b === undefined) {
166
+ this.#native.removeGroup(a);
167
+ }
168
+ else {
169
+ this.#native.removeGroup(a, b);
170
+ }
171
+ return this;
172
+ }
173
+ hasGroup(a, b) {
174
+ return b === undefined ? this.#native.hasGroup(a) : this.#native.hasGroup(a, b);
175
+ }
176
+ /** The number of entries of the nested group `tag` (0 if none). */
177
+ groupCount(tag) {
178
+ return this.#native.groupCount(tag);
179
+ }
180
+ /** The entry's fields (and nested groups) as a SOH-delimited string, in wire order. */
181
+ toString() {
182
+ return this.#native.toString();
183
+ }
184
+ }
185
+ exports.Group = Group;
@@ -1,7 +1,8 @@
1
1
  import type { Message } from './message.js';
2
- import type { SessionID } from './session-id.js';
2
+ import { type SessionID } from './session-id.js';
3
3
  export { Message, createMessage, parseMessage } from './message.js';
4
4
  export type { MessageParseOptions, MessageJSON } from './message.js';
5
+ export { Group } from './group.js';
5
6
  export { SessionID } from './session-id.js';
6
7
  export { SessionSettings } from './session-settings.js';
7
8
  export { DataDictionary } from './data-dictionary.js';
@@ -9,11 +10,12 @@ export { Initiator } from './initiator.js';
9
10
  export { Acceptor } from './acceptor.js';
10
11
  export { Engine } from './engine.js';
11
12
  export type { EngineOptions, EngineEvents } from './engine.js';
13
+ export { Session, lookupSession, doesSessionExist, getSessions, numSessions } from './session.js';
12
14
  export { FixReject, fixReject } from './application.js';
13
15
  export type { ApplicationHandlers, FixRejectKind } from './application.js';
14
16
  export type { QuickFixError } from './native.js';
15
- export { enums, FIELD, MsgType, Side } from './enums.js';
16
- export type { Enums, EnumGroup, FieldName } from './enums.js';
17
+ export { enums, FIELD, VALUES, MsgType, Side, OrdType, TimeInForce } from './enums.js';
18
+ export type { Enums, EnumGroup, FieldName, ValueGroups, ValueGroupName } from './enums.js';
17
19
  /**
18
20
  * Send a message to the target session identified by `sessionID`.
19
21
  *
@@ -23,11 +25,17 @@ export type { Enums, EnumGroup, FieldName } from './enums.js';
23
25
  * Runs off the main thread and resolves once the engine has accepted (or
24
26
  * rejected) the message, so the event loop stays free for callbacks. On a
25
27
  * missing session the returned Promise rejects with a
26
- * {@link QuickFixError} (`fixErrorName: 'SessionNotFound'`).
28
+ * {@link QuickFixError} (`fixErrorName: 'SessionNotFound'`). The send is
29
+ * bound to the engine that owns the session when it is called: if that
30
+ * engine is stopped before the send reaches its session, the Promise rejects
31
+ * with `SessionNotFound` rather than running through an engine created later
32
+ * with the same id.
27
33
  *
28
34
  * @param message The message to send.
29
35
  * @param sessionID The destination session.
30
36
  * @returns A Promise resolving to `true` if the message was accepted for sending.
37
+ * @throws {TypeError} synchronously if `sessionID` is neither a {@link SessionID}
38
+ * nor a qualifier string (it is not routed by the header instead).
31
39
  *
32
40
  * @example
33
41
  * ```ts
@@ -37,6 +45,20 @@ export type { Enums, EnumGroup, FieldName } from './enums.js';
37
45
  * ```
38
46
  */
39
47
  export declare function sendToTarget(message: Message, sessionID: SessionID): Promise<boolean>;
48
+ /**
49
+ * Send a message to the session identified by the message's **own header**
50
+ * (`BeginString`, `SenderCompID`, `TargetCompID`) plus an optional session
51
+ * qualifier.
52
+ *
53
+ * Wraps the `FIX::Session::sendToTarget(message, qualifier)` overload. Same
54
+ * threading and error behaviour as the SessionID form; a message whose header
55
+ * does not identify an existing session rejects with
56
+ * `fixErrorName: 'SessionNotFound'`.
57
+ *
58
+ * @param message The message to send; its header must carry tags 8, 49 and 56.
59
+ * @param qualifier Optional session qualifier (`SessionQualifier` in the settings).
60
+ */
61
+ export declare function sendToTarget(message: Message, qualifier?: string): Promise<boolean>;
40
62
  /** The QuickFIX engine / addon version string. */
41
63
  export declare const version: () => string;
42
64
  /**
@@ -44,4 +66,3 @@ export declare const version: () => string;
44
66
  * prefer {@link Message.parse} + {@link Message.getMsgType} for general use.
45
67
  */
46
68
  export declare const quickfixParseMsgType: (raw: string) => string;
47
- //# sourceMappingURL=index.d.ts.map
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.quickfixParseMsgType = exports.version = exports.Side = exports.MsgType = exports.FIELD = exports.enums = exports.fixReject = exports.FixReject = exports.Engine = exports.Acceptor = exports.Initiator = exports.DataDictionary = exports.SessionSettings = exports.SessionID = exports.parseMessage = exports.createMessage = exports.Message = void 0;
3
+ exports.quickfixParseMsgType = exports.version = exports.TimeInForce = exports.OrdType = exports.Side = exports.MsgType = exports.VALUES = exports.FIELD = exports.enums = exports.fixReject = exports.FixReject = exports.numSessions = exports.getSessions = exports.doesSessionExist = exports.lookupSession = exports.Session = exports.Engine = exports.Acceptor = exports.Initiator = exports.DataDictionary = exports.SessionSettings = exports.SessionID = exports.Group = exports.parseMessage = exports.createMessage = exports.Message = void 0;
4
4
  exports.sendToTarget = sendToTarget;
5
5
  /**
6
6
  * `@homaiohq/napi-quickfix` — a modern Node-API binding for the QuickFIX C++
@@ -9,13 +9,16 @@ exports.sendToTarget = sendToTarget;
9
9
  * @packageDocumentation
10
10
  */
11
11
  const native_js_1 = require("./native.js");
12
+ const session_id_js_1 = require("./session-id.js");
12
13
  // --- Pure layer -----------------------------------------------------------
13
14
  var message_js_1 = require("./message.js");
14
15
  Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_js_1.Message; } });
15
16
  Object.defineProperty(exports, "createMessage", { enumerable: true, get: function () { return message_js_1.createMessage; } });
16
17
  Object.defineProperty(exports, "parseMessage", { enumerable: true, get: function () { return message_js_1.parseMessage; } });
17
- var session_id_js_1 = require("./session-id.js");
18
- Object.defineProperty(exports, "SessionID", { enumerable: true, get: function () { return session_id_js_1.SessionID; } });
18
+ var group_js_1 = require("./group.js");
19
+ Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return group_js_1.Group; } });
20
+ var session_id_js_2 = require("./session-id.js");
21
+ Object.defineProperty(exports, "SessionID", { enumerable: true, get: function () { return session_id_js_2.SessionID; } });
19
22
  var session_settings_js_1 = require("./session-settings.js");
20
23
  Object.defineProperty(exports, "SessionSettings", { enumerable: true, get: function () { return session_settings_js_1.SessionSettings; } });
21
24
  var data_dictionary_js_1 = require("./data-dictionary.js");
@@ -27,39 +30,37 @@ var acceptor_js_1 = require("./acceptor.js");
27
30
  Object.defineProperty(exports, "Acceptor", { enumerable: true, get: function () { return acceptor_js_1.Acceptor; } });
28
31
  var engine_js_1 = require("./engine.js");
29
32
  Object.defineProperty(exports, "Engine", { enumerable: true, get: function () { return engine_js_1.Engine; } });
33
+ var session_js_1 = require("./session.js");
34
+ Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return session_js_1.Session; } });
35
+ Object.defineProperty(exports, "lookupSession", { enumerable: true, get: function () { return session_js_1.lookupSession; } });
36
+ Object.defineProperty(exports, "doesSessionExist", { enumerable: true, get: function () { return session_js_1.doesSessionExist; } });
37
+ Object.defineProperty(exports, "getSessions", { enumerable: true, get: function () { return session_js_1.getSessions; } });
38
+ Object.defineProperty(exports, "numSessions", { enumerable: true, get: function () { return session_js_1.numSessions; } });
30
39
  var application_js_1 = require("./application.js");
31
40
  Object.defineProperty(exports, "FixReject", { enumerable: true, get: function () { return application_js_1.FixReject; } });
32
41
  Object.defineProperty(exports, "fixReject", { enumerable: true, get: function () { return application_js_1.fixReject; } });
33
42
  // --- Enums / constants ----------------------------------------------------
43
+ // Every other value group (ExecType, OrdStatus, SecurityType, ...) is reachable
44
+ // as `enums.<Field>` / `VALUES.<Field>`, or by name from the
45
+ // `@homaiohq/napi-quickfix/values` subpath, which keeps this namespace small.
34
46
  var enums_js_1 = require("./enums.js");
35
47
  Object.defineProperty(exports, "enums", { enumerable: true, get: function () { return enums_js_1.enums; } });
36
48
  Object.defineProperty(exports, "FIELD", { enumerable: true, get: function () { return enums_js_1.FIELD; } });
49
+ Object.defineProperty(exports, "VALUES", { enumerable: true, get: function () { return enums_js_1.VALUES; } });
37
50
  Object.defineProperty(exports, "MsgType", { enumerable: true, get: function () { return enums_js_1.MsgType; } });
38
51
  Object.defineProperty(exports, "Side", { enumerable: true, get: function () { return enums_js_1.Side; } });
39
- /**
40
- * Send a message to the target session identified by `sessionID`.
41
- *
42
- * Wraps `FIX::Session::sendToTarget`. The session must exist and be logged on
43
- * for delivery; otherwise the engine queues or drops per its configuration.
44
- *
45
- * Runs off the main thread and resolves once the engine has accepted (or
46
- * rejected) the message, so the event loop stays free for callbacks. On a
47
- * missing session the returned Promise rejects with a
48
- * {@link QuickFixError} (`fixErrorName: 'SessionNotFound'`).
49
- *
50
- * @param message The message to send.
51
- * @param sessionID The destination session.
52
- * @returns A Promise resolving to `true` if the message was accepted for sending.
53
- *
54
- * @example
55
- * ```ts
56
- * import { sendToTarget, createMessage, SessionID, FIELD, MsgType } from '@homaiohq/napi-quickfix';
57
- * const order = createMessage({ [FIELD.MsgType]: MsgType.NewOrderSingle });
58
- * await sendToTarget(order, new SessionID('FIX.4.4', 'CLIENT', 'BROKER'));
59
- * ```
60
- */
61
- function sendToTarget(message, sessionID) {
62
- return native_js_1.native.sendToTarget(message.nativeHandle, sessionID.nativeHandle);
52
+ Object.defineProperty(exports, "OrdType", { enumerable: true, get: function () { return enums_js_1.OrdType; } });
53
+ Object.defineProperty(exports, "TimeInForce", { enumerable: true, get: function () { return enums_js_1.TimeInForce; } });
54
+ function sendToTarget(message, sessionIDOrQualifier) {
55
+ // Dispatch on the primitive, not `instanceof SessionID`: this package ships
56
+ // ESM and CJS builds, and a SessionID created by the other build is a
57
+ // different class with the same shape (see toNativeSessionID). Anything
58
+ // else is a TypeError here rather than an `undefined` target the native
59
+ // layer would read as "route by the message header".
60
+ const target = typeof sessionIDOrQualifier === 'string' || sessionIDOrQualifier === undefined
61
+ ? sessionIDOrQualifier
62
+ : (0, session_id_js_1.toNativeSessionID)(sessionIDOrQualifier, 'sessionID');
63
+ return native_js_1.native.sendToTarget(message.nativeHandle, target);
63
64
  }
64
65
  /** The QuickFIX engine / addon version string. */
65
66
  const version = () => native_js_1.native.version();
@@ -70,4 +71,3 @@ exports.version = version;
70
71
  */
71
72
  const quickfixParseMsgType = (raw) => native_js_1.native.quickfixParseMsgType(raw);
72
73
  exports.quickfixParseMsgType = quickfixParseMsgType;
73
- //# sourceMappingURL=index.js.map
@@ -27,4 +27,3 @@ export declare class Initiator extends Engine {
27
27
  /** @param options Engine options. */
28
28
  constructor(options: EngineOptions);
29
29
  }
30
- //# sourceMappingURL=initiator.d.ts.map
@@ -36,4 +36,3 @@ class Initiator extends engine_js_1.Engine {
36
36
  }
37
37
  }
38
38
  exports.Initiator = Initiator;
39
- //# sourceMappingURL=initiator.js.map
@@ -2,6 +2,8 @@
2
2
  * Ergonomic wrapper around the native `FIX::Message`.
3
3
  */
4
4
  import { type NativeMessage } from './native.js';
5
+ import { Group } from './group.js';
6
+ import type { DataDictionary } from './data-dictionary.js';
5
7
  /** Options controlling how a raw FIX string is parsed into a {@link Message}. */
6
8
  export interface MessageParseOptions {
7
9
  /**
@@ -11,6 +13,26 @@ export interface MessageParseOptions {
11
13
  * {@link DataDictionary} instead.
12
14
  */
13
15
  validate?: boolean;
16
+ /**
17
+ * Parse with this dictionary as both the session and application dictionary
18
+ * (the usual choice for FIX 4.x). With a dictionary, repeating groups are
19
+ * parsed into nested {@link Group} entries readable with
20
+ * {@link Message.getGroup}; without one the parse is **flat** and group
21
+ * fields are left as plain repeated body fields.
22
+ */
23
+ dictionary?: DataDictionary;
24
+ /**
25
+ * The session (transport) dictionary, e.g. `FIXT11.xml`. Governs header,
26
+ * trailer and admin messages. Overrides {@link MessageParseOptions.dictionary}
27
+ * for that role.
28
+ */
29
+ sessionDictionary?: DataDictionary;
30
+ /**
31
+ * The application dictionary, e.g. `FIX50SP2.xml`. Governs the body of
32
+ * application messages. Overrides {@link MessageParseOptions.dictionary} for
33
+ * that role.
34
+ */
35
+ applicationDictionary?: DataDictionary;
14
36
  }
15
37
  /** A structured, best-effort view of a parsed message returned by {@link Message.toJSON}. */
16
38
  export interface MessageJSON {
@@ -23,7 +45,9 @@ export interface MessageJSON {
23
45
  * A FIX message.
24
46
  *
25
47
  * Field values are accepted as `string | number` on input (numbers are
26
- * stringified, since FIX is string-on-the-wire) and always returned as `string`.
48
+ * stringified, since FIX is string-on-the-wire, without exponent notation:
49
+ * `1e-7` is written `0.0000001`) and always returned as `string`. `NaN` and
50
+ * `±Infinity` throw a `RangeError`.
27
51
  *
28
52
  * @example
29
53
  * ```ts
@@ -36,6 +60,12 @@ export interface MessageJSON {
36
60
  *
37
61
  * const parsed = Message.parse(msg.toString());
38
62
  * console.log(parsed.getMsgType());
63
+ *
64
+ * // Repeating groups: build entries with Group, read them back by 1-based index.
65
+ * msg.addGroup(new Group(FIELD.NoPartyIDs, FIELD.PartyID).setField(FIELD.PartyID, 'TRADER-1'));
66
+ * const dd = DataDictionary.fromFile('FIX44.xml');
67
+ * const withGroups = Message.parse(msg.toString(), { dictionary: dd });
68
+ * withGroups.getGroup(1, FIELD.NoPartyIDs).getField(FIELD.PartyID); // 'TRADER-1'
39
69
  * ```
40
70
  */
41
71
  export declare class Message {
@@ -55,8 +85,18 @@ export declare class Message {
55
85
  /**
56
86
  * Parse a raw FIX wire string into a {@link Message}.
57
87
  *
88
+ * Pass a `dictionary` to parse repeating groups structurally; without one
89
+ * the parse is flat (see {@link MessageParseOptions}).
90
+ *
58
91
  * @param raw Raw FIX wire string (SOH-delimited).
59
92
  * @param opts Optional parse options.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * const dd = DataDictionary.fromFile('./spec/FIX44.xml');
97
+ * const msg = Message.parse(raw, { dictionary: dd });
98
+ * msg.getGroup(1, FIELD.NoPartyIDs).getField(FIELD.PartyID);
99
+ * ```
60
100
  */
61
101
  static parse(raw: string, opts?: MessageParseOptions): Message;
62
102
  /** @internal Wrap an existing native message handle (used by the engine bridge). */
@@ -64,12 +104,97 @@ export declare class Message {
64
104
  /** @internal The native handle backing this message (for the engine / sendToTarget / validation). */
65
105
  get nativeHandle(): NativeMessage;
66
106
  /**
67
- * Read a body field by tag.
68
- * @throws A `QuickFixError` (`fixError: 'FieldNotFound'`) if absent.
107
+ * Read a field by tag. Standard header/trailer tags (`MsgType`,
108
+ * `SenderCompID`, `CheckSum`, ...) are read from their section, and so are
109
+ * the header/trailer fields of the session dictionary the message was
110
+ * parsed with (`sessionDictionary` / `dictionary`) or delivered with (a
111
+ * message handed to an engine handler). Any other tag is read from the body,
112
+ * or from the header or trailer if that is where it is.
113
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) if absent.
69
114
  */
70
115
  getField(tag: number): string;
71
- /** Set a body field. Returns `this` for chaining. */
116
+ /**
117
+ * Set a field. Standard header/trailer tags and the session dictionary's
118
+ * header/trailer fields auto-route to their section (see
119
+ * {@link Message.getField}). Any other tag is updated in place if the header
120
+ * or trailer already holds it; otherwise it goes to the body. On a message
121
+ * without a session dictionary (built with `new Message()`), put a new
122
+ * custom header field in the header with {@link Message.setHeaderField}.
123
+ * Returns `this` for chaining.
124
+ */
72
125
  setField(tag: number, value: string | number): this;
126
+ /** Whether a field is present (same auto-routing as {@link Message.getField}). */
127
+ isSetField(tag: number): boolean;
128
+ /** Remove a field (no-op if absent; same auto-routing). Returns `this` for chaining. */
129
+ removeField(tag: number): this;
130
+ /** Read a field by tag, or `undefined` if absent (same auto-routing). */
131
+ getFieldIfSet(tag: number): string | undefined;
132
+ /** Whether the header, body and trailer have no fields of their own. */
133
+ isEmpty(): boolean;
134
+ /** The number of body fields, including every field of every group entry. */
135
+ totalFields(): number;
136
+ /** Remove every header, body and trailer field and group. Returns `this` for chaining. */
137
+ clear(): this;
138
+ /** The body's own fields, in wire order, as `[tag, value]` pairs (group entries excluded). */
139
+ fields(): [number, string][];
140
+ /** The header fields, in wire order, as `[tag, value]` pairs. */
141
+ headerFields(): [number, string][];
142
+ /** The trailer fields, in wire order, as `[tag, value]` pairs. */
143
+ trailerFields(): [number, string][];
144
+ /** Iterates the body's own fields as `[tag, value]` pairs (see {@link Message.fields}). */
145
+ [Symbol.iterator](): IterableIterator<[number, string]>;
146
+ /**
147
+ * Append a repeating-group entry under its count tag (`group.field`). A copy
148
+ * is stored and the count field is updated. Header groups (e.g. `NoHops`)
149
+ * auto-route to the header. Returns `this` for chaining.
150
+ *
151
+ * @throws `TypeError` when `group.delim` differs from the delimiter of the
152
+ * entries already stored under `group.field`.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * order.addGroup(new Group(FIELD.NoPartyIDs, FIELD.PartyID).setField(FIELD.PartyID, 'X'));
157
+ * ```
158
+ */
159
+ addGroup(group: Group): this;
160
+ /**
161
+ * A **snapshot copy** of the `index`-th entry (1-based) of the repeating
162
+ * group `tag`. Mutating the returned {@link Group} does not change this
163
+ * message; write it back with {@link Message.replaceGroup}.
164
+ *
165
+ * Groups exist only on messages built with {@link Message.addGroup} or
166
+ * parsed with a dictionary, which includes every message the engine hands
167
+ * to your handlers when the session has `UseDataDictionary=Y` (the
168
+ * default); a flat parse, or `UseDataDictionary=N`, leaves none.
169
+ *
170
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) when the tag
171
+ * has no entries or `index` is out of range.
172
+ */
173
+ getGroup(index: number, tag: number): Group;
174
+ /**
175
+ * Overwrite the `index`-th entry (1-based) under `group.field` with a copy of
176
+ * `group`. Returns `this` for chaining.
177
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) when that
178
+ * entry does not exist.
179
+ * @throws `TypeError` when `group.delim` differs from the stored entry's
180
+ * delimiter.
181
+ */
182
+ replaceGroup(index: number, group: Group): this;
183
+ /**
184
+ * Remove every entry of the repeating group `tag` (and its count field), or
185
+ * only the `index`-th entry (1-based). Returns `this`.
186
+ *
187
+ * Removing every entry of a tag that has none is a no-op.
188
+ * @throws A `QuickFixError` (`fixErrorName: 'FieldNotFound'`) when the
189
+ * `index`-th entry does not exist.
190
+ */
191
+ removeGroup(tag: number): this;
192
+ removeGroup(index: number, tag: number): this;
193
+ /** Whether the repeating group `tag` has any entry, or has an `index`-th entry (1-based). */
194
+ hasGroup(tag: number): boolean;
195
+ hasGroup(index: number, tag: number): boolean;
196
+ /** The number of entries of the repeating group `tag` (0 if none). */
197
+ groupCount(tag: number): number;
73
198
  /**
74
199
  * Read a header field by tag.
75
200
  * @throws A `QuickFixError` (`fixError: 'FieldNotFound'`) if absent.
@@ -111,4 +236,3 @@ export declare function createMessage(fields?: Record<number, string | number>):
111
236
  * Parse a raw FIX wire string into a {@link Message}. Alias of {@link Message.parse}.
112
237
  */
113
238
  export declare function parseMessage(raw: string, opts?: MessageParseOptions): Message;
114
- //# sourceMappingURL=message.d.ts.map