@pbkware/fielded-text-web 0.1.0 → 0.2.1

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 (202) hide show
  1. package/README.md +68 -0
  2. package/dist/api/ft-reader.js +1 -1
  3. package/dist/api/ft-reader.js.map +1 -1
  4. package/dist/api/ft-serialization.js +4 -4
  5. package/dist/api/ft-serialization.js.map +1 -1
  6. package/dist/factory/ft-field-factory.js +1 -1
  7. package/dist/factory/ft-field-factory.js.map +1 -1
  8. package/dist/factory/ft-sequence-redirect-factory.js +3 -3
  9. package/dist/factory/ft-sequence-redirect-factory.js.map +1 -1
  10. package/dist/fields/definitions/ft-boolean-field-definition.js +1 -1
  11. package/dist/fields/definitions/ft-boolean-field-definition.js.map +1 -1
  12. package/dist/fields/definitions/ft-date-time-field-definition.js +1 -1
  13. package/dist/fields/definitions/ft-date-time-field-definition.js.map +1 -1
  14. package/dist/fields/definitions/ft-decimal-field-definition.js +1 -1
  15. package/dist/fields/definitions/ft-decimal-field-definition.js.map +1 -1
  16. package/dist/fields/definitions/ft-field-definition.js +1 -1
  17. package/dist/fields/definitions/ft-field-definition.js.map +1 -1
  18. package/dist/fields/definitions/ft-float-field-definition.js +1 -1
  19. package/dist/fields/definitions/ft-float-field-definition.js.map +1 -1
  20. package/dist/fields/definitions/ft-integer-field-definition.js +1 -1
  21. package/dist/fields/definitions/ft-integer-field-definition.js.map +1 -1
  22. package/dist/fields/definitions/ft-string-field-definition.js +1 -1
  23. package/dist/fields/definitions/ft-string-field-definition.js.map +1 -1
  24. package/dist/fields/instances/errors/ft-field-null-error.js +11 -0
  25. package/dist/fields/instances/errors/ft-field-null-error.js.map +1 -0
  26. package/dist/fields/instances/errors/ft-field-type-error.js +11 -0
  27. package/dist/fields/instances/errors/ft-field-type-error.js.map +1 -0
  28. package/dist/fields/instances/ft-boolean-field.js +14 -6
  29. package/dist/fields/instances/ft-boolean-field.js.map +1 -1
  30. package/dist/fields/instances/ft-date-time-field.js +26 -8
  31. package/dist/fields/instances/ft-date-time-field.js.map +1 -1
  32. package/dist/fields/instances/ft-decimal-field.js +14 -6
  33. package/dist/fields/instances/ft-decimal-field.js.map +1 -1
  34. package/dist/fields/instances/ft-field.js +315 -123
  35. package/dist/fields/instances/ft-field.js.map +1 -1
  36. package/dist/fields/instances/ft-float-field.js +14 -6
  37. package/dist/fields/instances/ft-float-field.js.map +1 -1
  38. package/dist/fields/instances/ft-generic-field.js +29 -67
  39. package/dist/fields/instances/ft-generic-field.js.map +1 -1
  40. package/dist/fields/instances/ft-integer-field.js +24 -8
  41. package/dist/fields/instances/ft-integer-field.js.map +1 -1
  42. package/dist/fields/instances/ft-string-field.js +13 -13
  43. package/dist/fields/instances/ft-string-field.js.map +1 -1
  44. package/dist/index.d.ts +616 -288
  45. package/dist/index.js +12 -3
  46. package/dist/index.js.map +1 -1
  47. package/dist/meta/sequences/core/ft-meta-sequence-list.js +4 -2
  48. package/dist/meta/sequences/core/ft-meta-sequence-list.js.map +1 -1
  49. package/dist/meta/sequences/redirects/ft-meta-sequence-redirect-list.js +1 -1
  50. package/dist/meta/sequences/redirects/ft-meta-sequence-redirect-list.js.map +1 -1
  51. package/dist/meta-serialization/format/ft-xml-meta-serialization.js +4 -6
  52. package/dist/meta-serialization/format/ft-xml-meta-serialization.js.map +1 -1
  53. package/dist/meta-serialization/styles/ft-number-styles-meta-serialization.js +1 -1
  54. package/dist/meta-serialization/styles/ft-number-styles-meta-serialization.js.map +1 -1
  55. package/dist/meta-serialization/types/date-time-meta-serialization.js +1 -1
  56. package/dist/meta-serialization/types/date-time-meta-serialization.js.map +1 -1
  57. package/dist/meta-serialization/types/enums/sequence-redirect-type-meta-serialisation.js +1 -1
  58. package/dist/meta-serialization/types/enums/sequence-redirect-type-meta-serialisation.js.map +1 -1
  59. package/dist/meta-serialization/types/float-meta-serialization.js +2 -2
  60. package/dist/meta-serialization/types/float-meta-serialization.js.map +1 -1
  61. package/dist/meta-serialization/types/integer-float-meta-serialization.js +2 -2
  62. package/dist/meta-serialization/types/integer-float-meta-serialization.js.map +1 -1
  63. package/dist/meta-serialization/utils/implicit-explicit-index-sorter.js +4 -10
  64. package/dist/meta-serialization/utils/implicit-explicit-index-sorter.js.map +1 -1
  65. package/dist/meta-serialization/utils/meta-serialization-sequence-name-resolver.js +25 -2
  66. package/dist/meta-serialization/utils/meta-serialization-sequence-name-resolver.js.map +1 -1
  67. package/dist/meta-serialization/utils/sequence-item-field-indices.js +2 -2
  68. package/dist/meta-serialization/utils/sequence-item-field-indices.js.map +1 -1
  69. package/dist/sequences/redirects/ft-case-insensitive-string-sequence-redirect.js +3 -1
  70. package/dist/sequences/redirects/ft-case-insensitive-string-sequence-redirect.js.map +1 -1
  71. package/dist/serialization/char-reader.js +2 -2
  72. package/dist/serialization/char-reader.js.map +1 -1
  73. package/dist/serialization/declaration-parser.js +1 -1
  74. package/dist/serialization/declaration-parser.js.map +1 -1
  75. package/dist/serialization/delimited-field-parser.js.map +1 -1
  76. package/dist/serialization/events/ft-field-heading-ready-event-args.js.map +1 -0
  77. package/dist/serialization/events/ft-field-value-ready-event-args.js.map +1 -0
  78. package/dist/serialization/events/ft-heading-line-finished-event-args.js.map +1 -0
  79. package/dist/serialization/events/ft-heading-line-started-event-args.js.map +1 -0
  80. package/dist/serialization/events/ft-record-finished-event-args.js.map +1 -0
  81. package/dist/serialization/events/ft-record-started-event-args.js.map +1 -0
  82. package/dist/serialization/events/ft-sequence-redirected-event-args.js.map +1 -0
  83. package/dist/serialization/fixed-width-field-parser.js +1 -1
  84. package/dist/serialization/fixed-width-field-parser.js.map +1 -1
  85. package/dist/serialization/ft-declared-parameters.js +9 -8
  86. package/dist/serialization/ft-declared-parameters.js.map +1 -1
  87. package/dist/serialization/{serialization-core.js → ft-serialization-core.js} +114 -11
  88. package/dist/serialization/ft-serialization-core.js.map +1 -0
  89. package/dist/{types/errors/ft-serialization-error.js → serialization/ft-serialization-error-code.js} +2 -2
  90. package/dist/serialization/ft-serialization-error-code.js.map +1 -0
  91. package/dist/{types/errors/ft-serialization-exception.js → serialization/ft-serialization-error.js} +7 -7
  92. package/dist/serialization/ft-serialization-error.js.map +1 -0
  93. package/dist/serialization/ft-serialization-reader.js +19 -47
  94. package/dist/serialization/ft-serialization-reader.js.map +1 -1
  95. package/dist/serialization/ft-serialization-writer.js +86 -49
  96. package/dist/serialization/ft-serialization-writer.js.map +1 -1
  97. package/dist/serialization/heading-line-record-parser.js +7 -7
  98. package/dist/serialization/heading-line-record-parser.js.map +1 -1
  99. package/dist/serialization/line-parser.js +1 -1
  100. package/dist/serialization/line-parser.js.map +1 -1
  101. package/dist/serialization/{ft-text-reader.js → text-reader/ft-string-reader.js} +1 -13
  102. package/dist/serialization/text-reader/ft-string-reader.js.map +1 -0
  103. package/dist/serialization/text-reader/ft-text-reader.js +13 -0
  104. package/dist/serialization/text-reader/ft-text-reader.js.map +1 -0
  105. package/dist/tsdoc-metadata.json +1 -1
  106. package/dist/types/enums/ft-heading-constraint.js +5 -0
  107. package/dist/types/enums/ft-heading-constraint.js.map +1 -1
  108. package/dist/utils/ft-comma-text.js +247 -0
  109. package/dist/utils/ft-comma-text.js.map +1 -0
  110. package/dist/utils/ft-internal-error.js +129 -0
  111. package/dist/utils/ft-internal-error.js.map +1 -0
  112. package/dist/utils/ft-result.js +2 -0
  113. package/dist/utils/ft-result.js.map +1 -0
  114. package/dist/utils/number-parse.js +33 -0
  115. package/dist/utils/number-parse.js.map +1 -0
  116. package/dist/utils/string-builder.js +40 -0
  117. package/dist/utils/string-builder.js.map +1 -0
  118. package/package.json +27 -25
  119. package/src/api/ft-reader.ts +2 -1
  120. package/src/api/ft-serialization.ts +13 -13
  121. package/src/factory/ft-field-factory.ts +1 -1
  122. package/src/factory/ft-sequence-redirect-factory.ts +4 -4
  123. package/src/fields/definitions/ft-boolean-field-definition.ts +1 -1
  124. package/src/fields/definitions/ft-date-time-field-definition.ts +1 -1
  125. package/src/fields/definitions/ft-decimal-field-definition.ts +1 -1
  126. package/src/fields/definitions/ft-field-definition.ts +1 -1
  127. package/src/fields/definitions/ft-float-field-definition.ts +1 -1
  128. package/src/fields/definitions/ft-generic-field-definition.ts +1 -1
  129. package/src/fields/definitions/ft-integer-field-definition.ts +1 -1
  130. package/src/fields/definitions/ft-string-field-definition.ts +1 -1
  131. package/src/fields/instances/errors/ft-field-null-error.ts +10 -0
  132. package/src/fields/instances/errors/ft-field-type-error.ts +10 -0
  133. package/src/fields/instances/ft-boolean-field.ts +17 -6
  134. package/src/fields/instances/ft-date-time-field.ts +28 -7
  135. package/src/fields/instances/ft-decimal-field.ts +17 -6
  136. package/src/fields/instances/ft-field.ts +329 -145
  137. package/src/fields/instances/ft-float-field.ts +17 -6
  138. package/src/fields/instances/ft-generic-field.ts +32 -88
  139. package/src/fields/instances/ft-integer-field.ts +29 -7
  140. package/src/fields/instances/ft-string-field.ts +15 -12
  141. package/src/index.ts +21 -12
  142. package/src/meta/sequences/core/ft-meta-sequence-list.ts +4 -3
  143. package/src/meta/sequences/redirects/ft-meta-sequence-redirect-list.ts +1 -1
  144. package/src/meta-serialization/format/ft-xml-meta-serialization.ts +4 -7
  145. package/src/meta-serialization/styles/ft-number-styles-meta-serialization.ts +1 -1
  146. package/src/meta-serialization/types/date-time-meta-serialization.ts +1 -1
  147. package/src/meta-serialization/types/enums/meta-element-type-meta-serialization.ts +4 -4
  148. package/src/meta-serialization/types/enums/sequence-redirect-type-meta-serialisation.ts +1 -1
  149. package/src/meta-serialization/types/float-meta-serialization.ts +2 -2
  150. package/src/meta-serialization/types/integer-float-meta-serialization.ts +2 -2
  151. package/src/meta-serialization/utils/implicit-explicit-index-sorter.ts +18 -12
  152. package/src/meta-serialization/utils/meta-serialization-sequence-name-resolver.ts +25 -2
  153. package/src/meta-serialization/utils/sequence-item-field-indices.ts +2 -2
  154. package/src/sequences/redirects/ft-case-insensitive-string-sequence-redirect.ts +3 -1
  155. package/src/serialization/char-reader.ts +2 -2
  156. package/src/serialization/declaration-parser.ts +1 -1
  157. package/src/serialization/delimited-field-parser.ts +3 -3
  158. package/src/serialization/fixed-width-field-parser.ts +4 -4
  159. package/src/serialization/ft-declared-parameters.ts +12 -11
  160. package/src/serialization/{serialization-core.ts → ft-serialization-core.ts} +133 -17
  161. package/src/{types/errors/ft-serialization-error.ts → serialization/ft-serialization-error-code.ts} +2 -2
  162. package/src/{types/errors/ft-serialization-exception.ts → serialization/ft-serialization-error.ts} +14 -9
  163. package/src/serialization/ft-serialization-reader.ts +21 -54
  164. package/src/serialization/ft-serialization-writer.ts +97 -64
  165. package/src/serialization/heading-line-record-parser.ts +10 -10
  166. package/src/serialization/line-parser.ts +1 -1
  167. package/src/serialization/{ft-text-reader.ts → text-reader/ft-string-reader.ts} +1 -24
  168. package/src/serialization/text-reader/ft-text-reader.ts +24 -0
  169. package/src/types/enums/ft-heading-constraint.ts +5 -0
  170. package/src/utils/ft-comma-text.ts +285 -0
  171. package/src/utils/ft-internal-error.ts +143 -0
  172. package/src/utils/ft-result.ts +1 -0
  173. package/src/utils/number-parse.ts +35 -0
  174. package/src/utils/string-builder.ts +47 -0
  175. package/dist/serialization/ft-text-reader.js.map +0 -1
  176. package/dist/serialization/serialization-core.js.map +0 -1
  177. package/dist/types/errors/ft-internal-error.js +0 -14
  178. package/dist/types/errors/ft-internal-error.js.map +0 -1
  179. package/dist/types/errors/ft-serialization-error.js.map +0 -1
  180. package/dist/types/errors/ft-serialization-exception.js.map +0 -1
  181. package/dist/types/events/ft-field-heading-ready-event-args.js.map +0 -1
  182. package/dist/types/events/ft-field-value-ready-event-args.js.map +0 -1
  183. package/dist/types/events/ft-heading-line-finished-event-args.js.map +0 -1
  184. package/dist/types/events/ft-heading-line-started-event-args.js.map +0 -1
  185. package/dist/types/events/ft-record-finished-event-args.js.map +0 -1
  186. package/dist/types/events/ft-record-started-event-args.js.map +0 -1
  187. package/dist/types/events/ft-sequence-redirected-event-args.js.map +0 -1
  188. package/src/types/errors/ft-internal-error.ts +0 -15
  189. /package/dist/{types → serialization}/events/ft-field-heading-ready-event-args.js +0 -0
  190. /package/dist/{types → serialization}/events/ft-field-value-ready-event-args.js +0 -0
  191. /package/dist/{types → serialization}/events/ft-heading-line-finished-event-args.js +0 -0
  192. /package/dist/{types → serialization}/events/ft-heading-line-started-event-args.js +0 -0
  193. /package/dist/{types → serialization}/events/ft-record-finished-event-args.js +0 -0
  194. /package/dist/{types → serialization}/events/ft-record-started-event-args.js +0 -0
  195. /package/dist/{types → serialization}/events/ft-sequence-redirected-event-args.js +0 -0
  196. /package/src/{types → serialization}/events/ft-field-heading-ready-event-args.ts +0 -0
  197. /package/src/{types → serialization}/events/ft-field-value-ready-event-args.ts +0 -0
  198. /package/src/{types → serialization}/events/ft-heading-line-finished-event-args.ts +0 -0
  199. /package/src/{types → serialization}/events/ft-heading-line-started-event-args.ts +0 -0
  200. /package/src/{types → serialization}/events/ft-record-finished-event-args.ts +0 -0
  201. /package/src/{types → serialization}/events/ft-record-started-event-args.ts +0 -0
  202. /package/src/{types → serialization}/events/ft-sequence-redirected-event-args.ts +0 -0
@@ -1,15 +1,9 @@
1
1
  import { FtWriterSettings } from '../api/ft-writer-settings.js';
2
2
  import { FtFieldDefinition } from '../fields/definitions/ft-field-definition.js';
3
- import { FtBooleanField } from '../fields/instances/ft-boolean-field.js';
4
- import { FtDateTimeField } from '../fields/instances/ft-date-time-field.js';
5
- import { FtDecimalField } from '../fields/instances/ft-decimal-field.js';
3
+ // eslint-disable-next-line import-x/no-cycle
6
4
  import { FtField } from '../fields/instances/ft-field.js';
7
- import { FtFloatField } from '../fields/instances/ft-float-field.js';
8
- import { FtIntegerField } from '../fields/instances/ft-integer-field.js';
9
- import { FtStringField } from '../fields/instances/ft-string-field.js';
10
5
  import { FtXmlMetaSerialization } from '../meta-serialization/format/ft-xml-meta-serialization.js';
11
6
  import { FtMeta } from '../meta/ft-meta.js';
12
- import { FtDataType } from '../types/enums/ft-data-type.js';
13
7
  import { FtEndOfLineAutoWriteType } from '../types/enums/ft-end-of-line-auto-write-type.js';
14
8
  import { FtEndOfLineType } from '../types/enums/ft-end-of-line-type.js';
15
9
  import { FtLastLineEndedType } from '../types/enums/ft-last-line-ended-type.js';
@@ -18,19 +12,19 @@ import { FtPadAlignment } from '../types/enums/ft-pad-alignment.js';
18
12
  import { FtPadCharType } from '../types/enums/ft-pad-char-type.js';
19
13
  import { FtQuotedType } from '../types/enums/ft-quoted-type.js';
20
14
  import { FtTruncateType } from '../types/enums/ft-truncate-type.js';
21
- import { FtUnreachableCaseError } from '../types/errors/ft-internal-error.js';
22
- import { FtSerializationError } from '../types/errors/ft-serialization-error.js';
23
- import { FtSerializationException } from '../types/errors/ft-serialization-exception.js';
15
+ import { FtUnreachableCaseError } from '../utils/ft-internal-error.js';
24
16
  import { FtDeclaredParametersFormatter } from './formatting/ft-declared-parameters-formatter.js';
25
17
  import { FtDeclaredParameters } from './ft-declared-parameters.js';
18
+ import { FtSerializationCore } from './ft-serialization-core.js';
19
+ import { FtSerializationErrorCode } from './ft-serialization-error-code.js';
20
+ import { FtSerializationError } from './ft-serialization-error.js';
26
21
  import { FtTextWriter } from './ft-text-writer.js';
27
- import { SerializationCore } from './serialization-core.js';
28
22
 
29
23
  /**
30
24
  * Writer for fielded text streams. Coordinates all writing logic.
31
25
  * @public
32
26
  */
33
- export class FtSerializationWriter extends SerializationCore {
27
+ export class FtSerializationWriter extends FtSerializationCore {
34
28
  private static readonly DECLARATION_LINE2_BEFORE_COMMENT_CHARS = ' ';
35
29
  private static readonly EMBEDDED_META_BEFORE_COMMENT_CHARS = ' ';
36
30
 
@@ -100,7 +94,7 @@ export class FtSerializationWriter extends SerializationCore {
100
94
  */
101
95
  writeHeader(): void {
102
96
  if (this._headerWritten) {
103
- throw new FtSerializationException(FtSerializationError.HeaderAlreadyWritten, 'Header already written');
97
+ throw new FtSerializationError(FtSerializationErrorCode.HeaderAlreadyWritten, 'Header already written');
104
98
  }
105
99
 
106
100
  if (this._settings?.declared) {
@@ -142,106 +136,145 @@ export class FtSerializationWriter extends SerializationCore {
142
136
  }
143
137
 
144
138
  /**
145
- * Set a field value by index.
139
+ * Set a field value by index. Accepts `null` to set the field to null.
140
+ *
141
+ * @param idx - The 0-based index of the field to set.
142
+ * @param value - The value to set for the field. Can be `null` to set the field to null.
143
+ *
144
+ * @throws FtTypeError if the value being set is not of the field's expected type.
146
145
  */
147
- setFieldValue(idx: number, value: unknown): void {
148
- this.fieldList.get(idx).asObject = value;
146
+ setFieldValue(idx: number, value: FtField.Value | null): void {
147
+ this.fieldList.get(idx).nullableValue = value;
149
148
  }
150
149
 
151
150
  /**
152
151
  * Set a field value by name.
152
+ *
153
+ * @param name - The name of the field to set.
154
+ * @param value - The value to set for the field. Can be `null` to set the field to null.
155
+ *
156
+ * @throws FtTypeError if the value being set is not of the field's expected type.
153
157
  */
154
- setFieldValueByName(name: string, value: unknown): void {
158
+ setFieldValueByName(name: string, value: FtField.Value | null): void {
155
159
  const field = this.fieldList.getByName(name);
156
160
  if (!field) {
157
161
  throw new Error(`Field not found: ${name}`);
158
162
  }
159
- field.asObject = value;
163
+ field.nullableValue = value;
160
164
  }
161
165
 
162
166
  /**
163
167
  * Set a field to null.
168
+ *
169
+ * @param idx - The 0-based index of the field to set.
164
170
  */
165
171
  setNull(idx: number): void {
166
172
  this.fieldList.get(idx).setNull();
167
173
  }
168
174
 
175
+ /**
176
+ * Set a field to null.
177
+ *
178
+ * @param name - The name of the field to set.
179
+ */
180
+ setNullByName(name: string): void {
181
+ const field = this.fieldList.getByName(name);
182
+ if (!field) {
183
+ throw new Error(`Field not found: ${name}`);
184
+ }
185
+ field.setNull();
186
+ }
187
+
169
188
  /**
170
189
  * Set a boolean field.
190
+ *
191
+ * @param idx - The 0-based index of the field to set.
192
+ * @param value - The value to set for the field. Can be `null` to set the field to null.
171
193
  */
172
- setBoolean(idx: number, value: boolean): void {
194
+ setBoolean(idx: number, value: boolean | null): void {
173
195
  const field = this.fieldList.get(idx);
174
- if (field.dataType !== FtDataType.Boolean) {
175
- throw new Error(`Invalid cast: field ${idx} is not boolean`);
176
- }
177
- (field as FtBooleanField).value = value;
196
+ field.asNullableBoolean = value;
178
197
  }
179
198
 
180
199
  /**
181
- * Set a date/time field.
200
+ * Set a DateTime field's value.
201
+ *
202
+ * @param idx - The 0-based index of the field to set.
203
+ * @param value - The value to set for the field. Can be `null` to set the field to null.
182
204
  */
183
- setDateTime(idx: number, value: Date): void {
205
+ setDateTime(idx: number, value: Date | null): void {
184
206
  const field = this.fieldList.get(idx);
185
- if (field.dataType !== FtDataType.DateTime) {
186
- throw new Error(`Invalid cast: field ${idx} is not datetime`);
187
- }
188
- (field as FtDateTimeField).value = value;
207
+ field.asNullableDateTime = value;
189
208
  }
190
209
 
191
210
  /**
192
211
  * Set a decimal field.
212
+ *
213
+ * @param idx - The 0-based index of the field to set.
214
+ * @param value - The value to set for the field. Can be `null` to set the field to null.
193
215
  */
194
- setDecimal(idx: number, value: number): void {
216
+ setDecimal(idx: number, value: number | null): void {
195
217
  const field = this.fieldList.get(idx);
196
- if (field.dataType !== FtDataType.Decimal) {
197
- throw new Error(`Invalid cast: field ${idx} is not decimal`);
198
- }
199
- (field as FtDecimalField).value = value;
218
+ field.asNullableDecimal = value;
200
219
  }
201
220
 
202
221
  /**
203
222
  * Set a float field.
223
+ *
224
+ * @param idx - The 0-based index of the field to set.
225
+ * @param value - The value to set for the field. Can be `null` to set the field to null.
204
226
  */
205
- setFloat(idx: number, value: number): void {
227
+ setFloat(idx: number, value: number | null): void {
206
228
  const field = this.fieldList.get(idx);
207
- if (field.dataType !== FtDataType.Float) {
208
- throw new Error(`Invalid cast: field ${idx} is not float`);
209
- }
210
- (field as FtFloatField).value = value;
229
+ field.asNullableFloat = value;
211
230
  }
212
231
 
213
232
  /**
214
233
  * Set an integer field.
234
+ *
235
+ * @param idx - The 0-based index of the field to set.
236
+ * @param value - The value to set for the field. Can be `null` to set the field to null.
215
237
  */
216
- setInteger(idx: number, value: number | bigint): void {
238
+ setInteger(idx: number, value: number | bigint | null): void {
217
239
  const field = this.fieldList.get(idx);
218
- if (field.dataType !== FtDataType.Integer) {
219
- throw new Error(`Invalid cast: field ${idx} is not integer`);
240
+ switch (typeof value) {
241
+ case 'bigint':
242
+ field.asBigInt = value;
243
+ break;
244
+ case 'number':
245
+ field.asInteger = value;
246
+ break;
247
+ default:
248
+ field.setNull();
249
+ break;
220
250
  }
221
- (field as FtIntegerField).value = typeof value === 'bigint' ? value : BigInt(value);
222
251
  }
223
252
 
224
253
  /**
225
254
  * Set a string field.
255
+ *
256
+ * @param idx - The 0-based index of the field to set.
257
+ * @param value - The value to set for the field. Can be `null` to set the field to null.
226
258
  */
227
- setString(idx: number, value: string): void {
259
+ setString(idx: number, value: string | null): void {
228
260
  const field = this.fieldList.get(idx);
229
- if (field.dataType !== FtDataType.String) {
230
- throw new Error(`Invalid cast: field ${idx} is not string`);
231
- }
232
- (field as FtStringField).value = value;
261
+ field.asNullableString = value;
233
262
  }
234
263
 
235
264
  /**
236
265
  * Set multiple field values.
266
+ *
267
+ * @param values - An array of values to set for the fields. The length of the array must not exceed the number of fields. Array elements can be null to set the corresponding field to null.
268
+ *
269
+ * @throws FtTypeError if any of the values being set is not of the corresponding field's expected type.
237
270
  */
238
- setValues(values: unknown[]): void {
271
+ setValues(values: (FtField.Value | null)[]): void {
239
272
  if (values.length > this.fieldCount) {
240
273
  throw new Error(`Values length ${values.length} exceeds field count ${this.fieldCount}`);
241
274
  }
242
275
 
243
276
  for (let i = 0; i < values.length; i++) {
244
- this.fieldList.get(i).asObject = values[i];
277
+ this.fieldList.get(i).nullableValue = values[i];
245
278
  }
246
279
  }
247
280
 
@@ -322,15 +355,15 @@ export class FtSerializationWriter extends SerializationCore {
322
355
  case FtEndOfLineType.Char:
323
356
  return this.endOfLineChar;
324
357
  case FtEndOfLineType.CrLf:
325
- return SerializationCore.CarriageReturnLineFeedString;
358
+ return FtSerializationCore.CarriageReturnLineFeedString;
326
359
  case FtEndOfLineType.Auto:
327
360
  switch (this.endOfLineAutoWriteType) {
328
361
  case FtEndOfLineAutoWriteType.CrLf:
329
- return SerializationCore.CarriageReturnLineFeedString;
362
+ return FtSerializationCore.CarriageReturnLineFeedString;
330
363
  case FtEndOfLineAutoWriteType.Cr:
331
- return SerializationCore.CarriageReturnChar;
364
+ return FtSerializationCore.CarriageReturnChar;
332
365
  case FtEndOfLineAutoWriteType.Lf:
333
- return SerializationCore.LineFeedChar;
366
+ return FtSerializationCore.LineFeedChar;
334
367
  case FtEndOfLineAutoWriteType.Local:
335
368
  return '\n'; // Use platform default
336
369
  default:
@@ -373,8 +406,8 @@ export class FtSerializationWriter extends SerializationCore {
373
406
  switch (this.endOfLineType) {
374
407
  case FtEndOfLineType.Auto:
375
408
  case FtEndOfLineType.CrLf:
376
- searchChars.push(SerializationCore.CarriageReturnChar);
377
- searchChars.push(SerializationCore.LineFeedChar);
409
+ searchChars.push(FtSerializationCore.CarriageReturnChar);
410
+ searchChars.push(FtSerializationCore.LineFeedChar);
378
411
  break;
379
412
  case FtEndOfLineType.Char:
380
413
  searchChars.push(this.endOfLineChar);
@@ -413,12 +446,12 @@ export class FtSerializationWriter extends SerializationCore {
413
446
  }
414
447
 
415
448
  const parameters = new FtDeclaredParameters();
416
- parameters.setVersion(SerializationCore.VersionMajor, SerializationCore.VersionMinor);
449
+ parameters.setVersion(FtSerializationCore.VersionMajor, FtSerializationCore.VersionMinor);
417
450
  const metaReferenceType = this._settings.metaReferenceType ?? FtWriterSettings.DEFAULT_META_REFERENCE_TYPE;
418
451
  const metaReference = this._settings.metaReference ?? FtWriterSettings.DEFAULT_META_REFERENCE;
419
452
  parameters.setMetaReference(metaReferenceType, metaReference);
420
453
 
421
- this.writeComment(SerializationCore.Signature + ' ' + FtDeclaredParametersFormatter.toSignatureLineText(parameters), '');
454
+ this.writeComment(FtSerializationCore.Signature + ' ' + FtDeclaredParametersFormatter.toSignatureLineText(parameters), '');
422
455
  this.writeComment(FtDeclaredParametersFormatter.toLine2Text(parameters), FtSerializationWriter.DECLARATION_LINE2_BEFORE_COMMENT_CHARS);
423
456
  }
424
457
 
@@ -481,7 +514,7 @@ export class FtSerializationWriter extends SerializationCore {
481
514
  }
482
515
 
483
516
  if (field.headingWritePrefixSpace) {
484
- this._writer?.write(SerializationCore.PrefixSpaceChar);
517
+ this._writer?.write(FtSerializationCore.PrefixSpaceChar);
485
518
  }
486
519
 
487
520
  if (fieldQuoted) {
@@ -532,7 +565,7 @@ export class FtSerializationWriter extends SerializationCore {
532
565
  if (field.isNull()) {
533
566
  this._writer?.write(field.definition.fixedWidthNullValueText);
534
567
  } else {
535
- const valueText = field.getValueText();
568
+ const valueText = field.formatValue();
536
569
  const rawText = this.encodeFixedWidthValueText(valueText, field);
537
570
  this._writer?.write(rawText);
538
571
  }
@@ -540,7 +573,7 @@ export class FtSerializationWriter extends SerializationCore {
540
573
  if (field.isNull()) {
541
574
  this._writer?.write('');
542
575
  } else {
543
- const valueText = field.getValueText();
576
+ const valueText = field.formatValue();
544
577
 
545
578
  let fieldQuoted: boolean;
546
579
  switch (field.valueQuotedType) {
@@ -562,7 +595,7 @@ export class FtSerializationWriter extends SerializationCore {
562
595
  }
563
596
 
564
597
  if (field.valueWritePrefixSpace) {
565
- this._writer?.write(SerializationCore.PrefixSpaceChar);
598
+ this._writer?.write(FtSerializationCore.PrefixSpaceChar);
566
599
  }
567
600
 
568
601
  if (fieldQuoted) {
@@ -578,7 +611,7 @@ export class FtSerializationWriter extends SerializationCore {
578
611
  }
579
612
  }
580
613
 
581
- if (!field.constant && !field.isValueAssigned()) {
614
+ if (!field.constant && !field.valueAssigned) {
582
615
  // Field was not assigned a value, check null sequence redirects
583
616
  if (!field.isNull()) {
584
617
  throw new Error('Field value not assigned');
@@ -752,7 +785,7 @@ export class FtSerializationWriter extends SerializationCore {
752
785
  case FtTruncateType.NullChar:
753
786
  return nullChar.repeat(definition.width);
754
787
  case FtTruncateType.Exception:
755
- throw new FtSerializationException(FtSerializationError.FieldTruncated, `Text truncation: ${text}`);
788
+ throw new FtSerializationError(FtSerializationErrorCode.FieldTruncated, `Text truncation: ${text}`);
756
789
  default:
757
790
  throw new FtUnreachableCaseError('SWCTTT22117', truncateType);
758
791
  }
@@ -1,11 +1,11 @@
1
1
  import { FtField } from '../fields/instances/ft-field.js';
2
- import { FtAssertError, FtUnreachableCaseError } from '../types/errors/ft-internal-error.js';
3
- import { FtSerializationError } from '../types/errors/ft-serialization-error.js';
4
- import { FtSerializationException } from '../types/errors/ft-serialization-exception.js';
2
+ import { FtAssertError, FtUnreachableCaseError } from '../utils/ft-internal-error.js';
5
3
  import { CharReader } from './char-reader.js';
6
4
  import { DelimitedFieldParser } from './delimited-field-parser.js';
7
5
  import { FixedWidthFieldParser } from './fixed-width-field-parser.js';
8
- import { SerializationCore } from './serialization-core.js';
6
+ import { FtSerializationCore } from './ft-serialization-core.js';
7
+ import { FtSerializationErrorCode } from './ft-serialization-error-code.js';
8
+ import { FtSerializationError } from './ft-serialization-error.js';
9
9
 
10
10
  const State = {
11
11
  Out: 'Out',
@@ -23,7 +23,7 @@ type State = (typeof State)[keyof typeof State];
23
23
  * @internal
24
24
  */
25
25
  export class HeadingLineRecordParser {
26
- private readonly _core: SerializationCore;
26
+ private readonly _core: FtSerializationCore;
27
27
  private readonly _charReader: CharReader;
28
28
  private readonly _headingLines: boolean;
29
29
 
@@ -38,7 +38,7 @@ export class HeadingLineRecordParser {
38
38
  private _startPosition = -1;
39
39
  private _ignoreExtraCharsStartPosition = -1;
40
40
 
41
- constructor(core: SerializationCore, charReader: CharReader, forHeadingLines: boolean) {
41
+ constructor(core: FtSerializationCore, charReader: CharReader, forHeadingLines: boolean) {
42
42
  this._core = core;
43
43
  this._charReader = charReader;
44
44
  this._headingLines = forHeadingLines;
@@ -109,11 +109,11 @@ export class HeadingLineRecordParser {
109
109
  if (this._fieldCount < this._core.fieldList.count) {
110
110
  this.enterField(this._core.fieldList.get(this._fieldCount));
111
111
  } else {
112
- const error = this._headingLines ? FtSerializationError.HeadingLineTooManyFields : FtSerializationError.RecordTooManyFields;
112
+ const error = this._headingLines ? FtSerializationErrorCode.HeadingLineTooManyFields : FtSerializationErrorCode.RecordTooManyFields;
113
113
  const message = this._headingLines
114
114
  ? `Heading line has too many fields. Expected ${this._core.fieldList.count}`
115
115
  : `Record has too many fields. Expected ${this._core.fieldList.count}`;
116
- throw new FtSerializationException(error, message);
116
+ throw new FtSerializationError(error, message);
117
117
  }
118
118
  this.parseChar(aChar);
119
119
  break;
@@ -206,11 +206,11 @@ export class HeadingLineRecordParser {
206
206
 
207
207
  if (this._fieldCount < this._core.fieldList.count) {
208
208
  if (!this._core.allowIncompleteRecords) {
209
- const error = this._headingLines ? FtSerializationError.HeadingLineNotEnoughFields : FtSerializationError.RecordNotEnoughFields;
209
+ const error = this._headingLines ? FtSerializationErrorCode.HeadingLineNotEnoughFields : FtSerializationErrorCode.RecordNotEnoughFields;
210
210
  const message = this._headingLines
211
211
  ? `Heading line has not enough fields. Got ${this._fieldCount}, expected ${this._core.fieldList.count}`
212
212
  : `Record has not enough fields. Got ${this._fieldCount}, expected ${this._core.fieldList.count}`;
213
- throw new FtSerializationException(error, message);
213
+ throw new FtSerializationError(error, message);
214
214
  } else {
215
215
  for (let i = this._fieldCount; i < this._core.fieldList.count; i++) {
216
216
  const field = this._core.fieldList.get(i);
@@ -1,5 +1,5 @@
1
1
  import { FtEndOfLineType } from '../types/enums/ft-end-of-line-type.js';
2
- import { FtAssertError, FtUnreachableCaseError } from '../types/errors/ft-internal-error.js';
2
+ import { FtAssertError, FtUnreachableCaseError } from '../utils/ft-internal-error.js';
3
3
  import { CharReader } from './char-reader.js';
4
4
 
5
5
  const FtLineState = {
@@ -1,27 +1,4 @@
1
- /**
2
- * Interface for reading characters from a text source.
3
- * Mirrors .NET's TextReader for compatibility with C# implementation.
4
- * @public
5
- */
6
- export interface FtTextReader {
7
- /**
8
- * Reads the next character from the text reader and advances the character position by one character.
9
- * @returns The character read as a number (charCode), or -1 if the end of the text has been reached.
10
- */
11
- read(): number;
12
- }
13
-
14
- /**
15
- * Namespace merged with TextReader interface to provide static constants.
16
- * @public
17
- */
18
- export namespace FtTextReader {
19
- /**
20
- * Value returned by read() when the end of the text reader has been reached.
21
- * Matches .NET's TextReader behavior.
22
- */
23
- export const EofReadResult = -1;
24
- }
1
+ import type { FtTextReader } from './ft-text-reader.js';
25
2
 
26
3
  /**
27
4
  * A TextReader implementation that reads from a string.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Interface for reading characters from a text source.
3
+ * Mirrors .NET's TextReader for compatibility with C# implementation.
4
+ * @public
5
+ */
6
+ export interface FtTextReader {
7
+ /**
8
+ * Reads the next character from the text reader and advances the character position by one character.
9
+ * @returns The character read as a number (charCode), or -1 if the end of the text has been reached.
10
+ */
11
+ read(): number;
12
+ }
13
+
14
+ /**
15
+ * Namespace merged with TextReader interface to provide static constants.
16
+ * @public
17
+ */
18
+ export namespace FtTextReader {
19
+ /**
20
+ * Value returned by read() when the end of the text reader has been reached.
21
+ * Matches .NET's TextReader behavior.
22
+ */
23
+ export const EofReadResult = -1;
24
+ }
@@ -2,10 +2,15 @@
2
2
  * @public
3
3
  */
4
4
  export const FtHeadingConstraint = {
5
+ /** No constraings on headings */
5
6
  None: 'None',
7
+ /** All headings in the data must match the headings specified in the Meta */
6
8
  AllConstant: 'AllConstant',
9
+ /** The heading in the main heading line in the data must match the corresponding heading specified in the Meta */
7
10
  MainConstant: 'MainConstant',
11
+ /** The heading in the main heading line in the data must case-insensitively match the field's name */
8
12
  NameConstant: 'NameConstant',
13
+ /** The field's name is set to the heading in the main heading line in the data */
9
14
  NameIsMain: 'NameIsMain',
10
15
  } as const;
11
16