@pbkware/fielded-text-web 0.1.2 → 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.
- package/README.md +19 -41
- package/dist/api/ft-reader.js +1 -1
- package/dist/api/ft-reader.js.map +1 -1
- package/dist/api/ft-serialization.js +4 -4
- package/dist/api/ft-serialization.js.map +1 -1
- package/dist/factory/ft-field-factory.js +1 -1
- package/dist/factory/ft-field-factory.js.map +1 -1
- package/dist/factory/ft-sequence-redirect-factory.js +3 -3
- package/dist/factory/ft-sequence-redirect-factory.js.map +1 -1
- package/dist/fields/definitions/ft-boolean-field-definition.js +1 -1
- package/dist/fields/definitions/ft-boolean-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-date-time-field-definition.js +1 -1
- package/dist/fields/definitions/ft-date-time-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-decimal-field-definition.js +1 -1
- package/dist/fields/definitions/ft-decimal-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-field-definition.js +1 -1
- package/dist/fields/definitions/ft-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-float-field-definition.js +1 -1
- package/dist/fields/definitions/ft-float-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-integer-field-definition.js +1 -1
- package/dist/fields/definitions/ft-integer-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-string-field-definition.js +1 -1
- package/dist/fields/definitions/ft-string-field-definition.js.map +1 -1
- package/dist/fields/instances/errors/ft-field-null-error.js +11 -0
- package/dist/fields/instances/errors/ft-field-null-error.js.map +1 -0
- package/dist/fields/instances/errors/ft-field-type-error.js +11 -0
- package/dist/fields/instances/errors/ft-field-type-error.js.map +1 -0
- package/dist/fields/instances/ft-boolean-field.js +14 -6
- package/dist/fields/instances/ft-boolean-field.js.map +1 -1
- package/dist/fields/instances/ft-date-time-field.js +26 -8
- package/dist/fields/instances/ft-date-time-field.js.map +1 -1
- package/dist/fields/instances/ft-decimal-field.js +14 -6
- package/dist/fields/instances/ft-decimal-field.js.map +1 -1
- package/dist/fields/instances/ft-field.js +315 -123
- package/dist/fields/instances/ft-field.js.map +1 -1
- package/dist/fields/instances/ft-float-field.js +14 -6
- package/dist/fields/instances/ft-float-field.js.map +1 -1
- package/dist/fields/instances/ft-generic-field.js +29 -67
- package/dist/fields/instances/ft-generic-field.js.map +1 -1
- package/dist/fields/instances/ft-integer-field.js +24 -8
- package/dist/fields/instances/ft-integer-field.js.map +1 -1
- package/dist/fields/instances/ft-string-field.js +13 -13
- package/dist/fields/instances/ft-string-field.js.map +1 -1
- package/dist/index.d.ts +616 -288
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/meta/sequences/core/ft-meta-sequence-list.js +4 -2
- package/dist/meta/sequences/core/ft-meta-sequence-list.js.map +1 -1
- package/dist/meta/sequences/redirects/ft-meta-sequence-redirect-list.js +1 -1
- package/dist/meta/sequences/redirects/ft-meta-sequence-redirect-list.js.map +1 -1
- package/dist/meta-serialization/format/ft-xml-meta-serialization.js +4 -6
- package/dist/meta-serialization/format/ft-xml-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/styles/ft-number-styles-meta-serialization.js +1 -1
- package/dist/meta-serialization/styles/ft-number-styles-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/types/date-time-meta-serialization.js +1 -1
- package/dist/meta-serialization/types/date-time-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/types/enums/sequence-redirect-type-meta-serialisation.js +1 -1
- package/dist/meta-serialization/types/enums/sequence-redirect-type-meta-serialisation.js.map +1 -1
- package/dist/meta-serialization/types/float-meta-serialization.js +2 -2
- package/dist/meta-serialization/types/float-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/types/integer-float-meta-serialization.js +2 -2
- package/dist/meta-serialization/types/integer-float-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/utils/implicit-explicit-index-sorter.js +4 -10
- package/dist/meta-serialization/utils/implicit-explicit-index-sorter.js.map +1 -1
- package/dist/meta-serialization/utils/meta-serialization-sequence-name-resolver.js +25 -2
- package/dist/meta-serialization/utils/meta-serialization-sequence-name-resolver.js.map +1 -1
- package/dist/meta-serialization/utils/sequence-item-field-indices.js +2 -2
- package/dist/meta-serialization/utils/sequence-item-field-indices.js.map +1 -1
- package/dist/sequences/redirects/ft-case-insensitive-string-sequence-redirect.js +3 -1
- package/dist/sequences/redirects/ft-case-insensitive-string-sequence-redirect.js.map +1 -1
- package/dist/serialization/char-reader.js +2 -2
- package/dist/serialization/char-reader.js.map +1 -1
- package/dist/serialization/declaration-parser.js +1 -1
- package/dist/serialization/declaration-parser.js.map +1 -1
- package/dist/serialization/delimited-field-parser.js.map +1 -1
- package/dist/serialization/events/ft-field-heading-ready-event-args.js.map +1 -0
- package/dist/serialization/events/ft-field-value-ready-event-args.js.map +1 -0
- package/dist/serialization/events/ft-heading-line-finished-event-args.js.map +1 -0
- package/dist/serialization/events/ft-heading-line-started-event-args.js.map +1 -0
- package/dist/serialization/events/ft-record-finished-event-args.js.map +1 -0
- package/dist/serialization/events/ft-record-started-event-args.js.map +1 -0
- package/dist/serialization/events/ft-sequence-redirected-event-args.js.map +1 -0
- package/dist/serialization/fixed-width-field-parser.js +1 -1
- package/dist/serialization/fixed-width-field-parser.js.map +1 -1
- package/dist/serialization/ft-declared-parameters.js +9 -8
- package/dist/serialization/ft-declared-parameters.js.map +1 -1
- package/dist/serialization/{serialization-core.js → ft-serialization-core.js} +114 -11
- package/dist/serialization/ft-serialization-core.js.map +1 -0
- package/dist/{types/errors/ft-serialization-error.js → serialization/ft-serialization-error-code.js} +2 -2
- package/dist/serialization/ft-serialization-error-code.js.map +1 -0
- package/dist/{types/errors/ft-serialization-exception.js → serialization/ft-serialization-error.js} +7 -7
- package/dist/serialization/ft-serialization-error.js.map +1 -0
- package/dist/serialization/ft-serialization-reader.js +19 -47
- package/dist/serialization/ft-serialization-reader.js.map +1 -1
- package/dist/serialization/ft-serialization-writer.js +86 -49
- package/dist/serialization/ft-serialization-writer.js.map +1 -1
- package/dist/serialization/heading-line-record-parser.js +7 -7
- package/dist/serialization/heading-line-record-parser.js.map +1 -1
- package/dist/serialization/line-parser.js +1 -1
- package/dist/serialization/line-parser.js.map +1 -1
- package/dist/serialization/{ft-text-reader.js → text-reader/ft-string-reader.js} +1 -13
- package/dist/serialization/text-reader/ft-string-reader.js.map +1 -0
- package/dist/serialization/text-reader/ft-text-reader.js +13 -0
- package/dist/serialization/text-reader/ft-text-reader.js.map +1 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/enums/ft-heading-constraint.js +5 -0
- package/dist/types/enums/ft-heading-constraint.js.map +1 -1
- package/dist/utils/ft-comma-text.js +247 -0
- package/dist/utils/ft-comma-text.js.map +1 -0
- package/dist/utils/ft-internal-error.js +129 -0
- package/dist/utils/ft-internal-error.js.map +1 -0
- package/dist/utils/ft-result.js +2 -0
- package/dist/utils/ft-result.js.map +1 -0
- package/dist/utils/number-parse.js +33 -0
- package/dist/utils/number-parse.js.map +1 -0
- package/dist/utils/string-builder.js +40 -0
- package/dist/utils/string-builder.js.map +1 -0
- package/package.json +25 -27
- package/src/api/ft-reader.ts +2 -1
- package/src/api/ft-serialization.ts +13 -13
- package/src/factory/ft-field-factory.ts +1 -1
- package/src/factory/ft-sequence-redirect-factory.ts +4 -4
- package/src/fields/definitions/ft-boolean-field-definition.ts +1 -1
- package/src/fields/definitions/ft-date-time-field-definition.ts +1 -1
- package/src/fields/definitions/ft-decimal-field-definition.ts +1 -1
- package/src/fields/definitions/ft-field-definition.ts +1 -1
- package/src/fields/definitions/ft-float-field-definition.ts +1 -1
- package/src/fields/definitions/ft-generic-field-definition.ts +1 -1
- package/src/fields/definitions/ft-integer-field-definition.ts +1 -1
- package/src/fields/definitions/ft-string-field-definition.ts +1 -1
- package/src/fields/instances/errors/ft-field-null-error.ts +10 -0
- package/src/fields/instances/errors/ft-field-type-error.ts +10 -0
- package/src/fields/instances/ft-boolean-field.ts +17 -6
- package/src/fields/instances/ft-date-time-field.ts +28 -7
- package/src/fields/instances/ft-decimal-field.ts +17 -6
- package/src/fields/instances/ft-field.ts +329 -145
- package/src/fields/instances/ft-float-field.ts +17 -6
- package/src/fields/instances/ft-generic-field.ts +32 -88
- package/src/fields/instances/ft-integer-field.ts +29 -7
- package/src/fields/instances/ft-string-field.ts +15 -12
- package/src/index.ts +21 -12
- package/src/meta/sequences/core/ft-meta-sequence-list.ts +4 -3
- package/src/meta/sequences/redirects/ft-meta-sequence-redirect-list.ts +1 -1
- package/src/meta-serialization/format/ft-xml-meta-serialization.ts +4 -7
- package/src/meta-serialization/styles/ft-number-styles-meta-serialization.ts +1 -1
- package/src/meta-serialization/types/date-time-meta-serialization.ts +1 -1
- package/src/meta-serialization/types/enums/meta-element-type-meta-serialization.ts +4 -4
- package/src/meta-serialization/types/enums/sequence-redirect-type-meta-serialisation.ts +1 -1
- package/src/meta-serialization/types/float-meta-serialization.ts +2 -2
- package/src/meta-serialization/types/integer-float-meta-serialization.ts +2 -2
- package/src/meta-serialization/utils/implicit-explicit-index-sorter.ts +18 -12
- package/src/meta-serialization/utils/meta-serialization-sequence-name-resolver.ts +25 -2
- package/src/meta-serialization/utils/sequence-item-field-indices.ts +2 -2
- package/src/sequences/redirects/ft-case-insensitive-string-sequence-redirect.ts +3 -1
- package/src/serialization/char-reader.ts +2 -2
- package/src/serialization/declaration-parser.ts +1 -1
- package/src/serialization/delimited-field-parser.ts +3 -3
- package/src/serialization/fixed-width-field-parser.ts +4 -4
- package/src/serialization/ft-declared-parameters.ts +12 -11
- package/src/serialization/{serialization-core.ts → ft-serialization-core.ts} +133 -17
- package/src/{types/errors/ft-serialization-error.ts → serialization/ft-serialization-error-code.ts} +2 -2
- package/src/{types/errors/ft-serialization-exception.ts → serialization/ft-serialization-error.ts} +14 -9
- package/src/serialization/ft-serialization-reader.ts +21 -54
- package/src/serialization/ft-serialization-writer.ts +97 -64
- package/src/serialization/heading-line-record-parser.ts +10 -10
- package/src/serialization/line-parser.ts +1 -1
- package/src/serialization/{ft-text-reader.ts → text-reader/ft-string-reader.ts} +1 -24
- package/src/serialization/text-reader/ft-text-reader.ts +24 -0
- package/src/types/enums/ft-heading-constraint.ts +5 -0
- package/src/utils/ft-comma-text.ts +285 -0
- package/src/utils/ft-internal-error.ts +143 -0
- package/src/utils/ft-result.ts +1 -0
- package/src/utils/number-parse.ts +35 -0
- package/src/utils/string-builder.ts +47 -0
- package/LICENSE +0 -21
- package/dist/serialization/ft-text-reader.js.map +0 -1
- package/dist/serialization/serialization-core.js.map +0 -1
- package/dist/types/errors/ft-internal-error.js +0 -14
- package/dist/types/errors/ft-internal-error.js.map +0 -1
- package/dist/types/errors/ft-serialization-error.js.map +0 -1
- package/dist/types/errors/ft-serialization-exception.js.map +0 -1
- package/dist/types/events/ft-field-heading-ready-event-args.js.map +0 -1
- package/dist/types/events/ft-field-value-ready-event-args.js.map +0 -1
- package/dist/types/events/ft-heading-line-finished-event-args.js.map +0 -1
- package/dist/types/events/ft-heading-line-started-event-args.js.map +0 -1
- package/dist/types/events/ft-record-finished-event-args.js.map +0 -1
- package/dist/types/events/ft-record-started-event-args.js.map +0 -1
- package/dist/types/events/ft-sequence-redirected-event-args.js.map +0 -1
- package/src/types/errors/ft-internal-error.ts +0 -15
- /package/dist/{types → serialization}/events/ft-field-heading-ready-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-field-value-ready-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-heading-line-finished-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-heading-line-started-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-record-finished-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-record-started-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-sequence-redirected-event-args.js +0 -0
- /package/src/{types → serialization}/events/ft-field-heading-ready-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-field-value-ready-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-heading-line-finished-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-heading-line-started-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-record-finished-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-record-started-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-sequence-redirected-event-args.ts +0 -0
|
@@ -2,7 +2,9 @@ import { FtHeadingConstraint } from '../../types/enums/ft-heading-constraint.js'
|
|
|
2
2
|
import { FtQuotedType } from '../../types/enums/ft-quoted-type.js';
|
|
3
3
|
import { FtSequenceInvokationDelay } from '../../types/enums/ft-sequence-invokation-delay.js';
|
|
4
4
|
import { FtSequenceRedirectType } from '../../types/enums/ft-sequence-redirect-type.js';
|
|
5
|
-
import { FtUnreachableCaseError } from '../../
|
|
5
|
+
import { FtUnreachableCaseError } from '../../utils/ft-internal-error.js';
|
|
6
|
+
import { FtFieldNullError } from './errors/ft-field-null-error.js';
|
|
7
|
+
import { FtFieldTypeError } from './errors/ft-field-type-error.js';
|
|
6
8
|
/**
|
|
7
9
|
* Abstract base class for all field instances.
|
|
8
10
|
* Fields represent runtime field values during reading or writing.
|
|
@@ -12,7 +14,7 @@ export class FtField {
|
|
|
12
14
|
static NO_FIELDS_AFFECTED_INDEX = -1;
|
|
13
15
|
static IGNORED_SEQUENCE_INVOKATION_DELAY = FtSequenceInvokationDelay.AfterSequence;
|
|
14
16
|
sequenceRedirectEvent;
|
|
15
|
-
|
|
17
|
+
_valueAssigned = false;
|
|
16
18
|
quoted = false;
|
|
17
19
|
_index = 0;
|
|
18
20
|
_definition;
|
|
@@ -29,7 +31,7 @@ export class FtField {
|
|
|
29
31
|
_loadedLength = 0;
|
|
30
32
|
_loadedRawOffset = 0;
|
|
31
33
|
_loadedRawLength = 0;
|
|
32
|
-
|
|
34
|
+
_valueText = '';
|
|
33
35
|
constructor(sequenceInvokation, sequenceItem, valueTextNullTrimmable) {
|
|
34
36
|
if (!sequenceItem.fieldDefinition) {
|
|
35
37
|
throw new Error('SequenceItem must have a field definition');
|
|
@@ -86,11 +88,17 @@ export class FtField {
|
|
|
86
88
|
get headings() {
|
|
87
89
|
return this._headings;
|
|
88
90
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Indicates whether a value has been assigned to the field.
|
|
93
|
+
*/
|
|
94
|
+
get valueAssigned() {
|
|
95
|
+
return this._valueAssigned;
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
/**
|
|
98
|
+
* The formatted text of the field value as loaded from the data or via {@link loadValueText}.
|
|
99
|
+
*/
|
|
100
|
+
get valueText() {
|
|
101
|
+
return this._valueText;
|
|
94
102
|
}
|
|
95
103
|
// Properties delegating to definition
|
|
96
104
|
get dataType() {
|
|
@@ -100,7 +108,7 @@ export class FtField {
|
|
|
100
108
|
return this._definition.id;
|
|
101
109
|
}
|
|
102
110
|
get name() {
|
|
103
|
-
return this.
|
|
111
|
+
return this._name;
|
|
104
112
|
}
|
|
105
113
|
get metaHeadings() {
|
|
106
114
|
return this._definition.metaHeadings;
|
|
@@ -185,7 +193,7 @@ export class FtField {
|
|
|
185
193
|
}
|
|
186
194
|
/** @internal */
|
|
187
195
|
get asRedirectString() {
|
|
188
|
-
return this.
|
|
196
|
+
return this.formatValue();
|
|
189
197
|
}
|
|
190
198
|
/** @internal */
|
|
191
199
|
get asRedirectBoolean() {
|
|
@@ -207,64 +215,182 @@ export class FtField {
|
|
|
207
215
|
get asRedirectDecimal() {
|
|
208
216
|
return this.getAsRedirectDecimal();
|
|
209
217
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
get
|
|
218
|
-
|
|
218
|
+
/**
|
|
219
|
+
* The field value as an unspecified type.
|
|
220
|
+
*
|
|
221
|
+
* When setting the value, the actual type must be compatible with the field's expected type.
|
|
222
|
+
*
|
|
223
|
+
* @throws FtFieldNullError if the field is `null`.
|
|
224
|
+
*/
|
|
225
|
+
get value() {
|
|
226
|
+
if (this.isNull()) {
|
|
227
|
+
throw new FtFieldNullError(`Field value is null: ${this.name}`);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
return this.getValue();
|
|
231
|
+
}
|
|
219
232
|
}
|
|
220
|
-
set
|
|
221
|
-
this.
|
|
233
|
+
set value(value) {
|
|
234
|
+
this.setValue(value);
|
|
222
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* The field value as a string.
|
|
238
|
+
*
|
|
239
|
+
* @throws FtFieldTypeError if the field is not of data type `String`.
|
|
240
|
+
* @throws FtFieldNullError if the field is `null`.
|
|
241
|
+
*/
|
|
223
242
|
get asString() {
|
|
224
|
-
|
|
243
|
+
if (this.isNull()) {
|
|
244
|
+
throw new FtFieldNullError(`String field value is null: ${this.name}`);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
return this.getAsString();
|
|
248
|
+
}
|
|
225
249
|
}
|
|
226
250
|
set asString(value) {
|
|
227
251
|
this.setAsString(value);
|
|
228
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* The field value as a boolean.
|
|
255
|
+
*
|
|
256
|
+
* @throws FtFieldTypeError if the field is not of data type `Boolean`.
|
|
257
|
+
* @throws FtFieldNullError if the field is `null`.
|
|
258
|
+
*/
|
|
229
259
|
get asBoolean() {
|
|
230
|
-
|
|
260
|
+
if (this.isNull()) {
|
|
261
|
+
throw new FtFieldNullError(`Boolean field value is null: ${this.name}`);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
return this.getAsBoolean();
|
|
265
|
+
}
|
|
231
266
|
}
|
|
232
267
|
set asBoolean(value) {
|
|
233
268
|
this.setAsBoolean(value);
|
|
234
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* The field value as an integer.
|
|
272
|
+
|
|
273
|
+
* @throws FtFieldTypeError if the field is not of data type `Integer`.
|
|
274
|
+
* @throws FtFieldNullError if the field is `null`.
|
|
275
|
+
*/
|
|
235
276
|
get asInteger() {
|
|
236
|
-
|
|
277
|
+
if (this.isNull()) {
|
|
278
|
+
throw new FtFieldNullError(`Integer field value is null: ${this.name}`);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
return this.getAsInteger();
|
|
282
|
+
}
|
|
237
283
|
}
|
|
238
284
|
set asInteger(value) {
|
|
239
285
|
this.setAsInteger(value);
|
|
240
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* The field value as a bigint.
|
|
289
|
+
*
|
|
290
|
+
* @throws FtFieldTypeError if the field is not of data type `BigInt`.
|
|
291
|
+
* @throws FtFieldNullError if the field is `null`.
|
|
292
|
+
*/
|
|
241
293
|
get asBigInt() {
|
|
242
|
-
|
|
294
|
+
if (this.isNull()) {
|
|
295
|
+
throw new FtFieldNullError(`Integer field value is null: ${this.name}`);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
return this.getAsBigInt();
|
|
299
|
+
}
|
|
243
300
|
}
|
|
244
301
|
set asBigInt(value) {
|
|
245
302
|
this.setAsBigInt(value);
|
|
246
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* The field value as a float.
|
|
306
|
+
*
|
|
307
|
+
* @throws FtFieldTypeError if the field is not of data type `Float`.
|
|
308
|
+
* @throws FtFieldNullError if the field is `null`.
|
|
309
|
+
*/
|
|
247
310
|
get asFloat() {
|
|
248
|
-
|
|
311
|
+
if (this.isNull()) {
|
|
312
|
+
throw new FtFieldNullError(`Float field value is null: ${this.name}`);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
return this.getAsFloat();
|
|
316
|
+
}
|
|
249
317
|
}
|
|
250
318
|
set asFloat(value) {
|
|
251
319
|
this.setAsFloat(value);
|
|
252
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* The field value as a DateTime.
|
|
323
|
+
*
|
|
324
|
+
* @throws FtFieldTypeError if the field is not of data type `DateTime`.
|
|
325
|
+
* @throws FtFieldNullError if the field is `null`.
|
|
326
|
+
*/
|
|
253
327
|
get asDateTime() {
|
|
254
|
-
|
|
328
|
+
if (this.isNull()) {
|
|
329
|
+
throw new FtFieldNullError(`DateTime field value is null: ${this.name}`);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
return this.getAsDateTime();
|
|
333
|
+
}
|
|
255
334
|
}
|
|
256
335
|
set asDateTime(value) {
|
|
257
336
|
this.setAsDateTime(value);
|
|
258
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* The field value as a number (decimal).
|
|
340
|
+
*
|
|
341
|
+
* @throws FtFieldTypeError if the field is not of data type `Decimal`.
|
|
342
|
+
* @throws FtFieldNullError if the field is `null`.
|
|
343
|
+
*/
|
|
259
344
|
get asDecimal() {
|
|
260
|
-
|
|
345
|
+
if (this.isNull()) {
|
|
346
|
+
throw new FtFieldNullError(`Decimal field value is null: ${this.name}`);
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
return this.getAsDecimal();
|
|
350
|
+
}
|
|
261
351
|
}
|
|
262
352
|
set asDecimal(value) {
|
|
263
353
|
this.setAsDecimal(value);
|
|
264
354
|
}
|
|
265
|
-
|
|
355
|
+
/**
|
|
356
|
+
* The field value as an unspecified type or null.
|
|
357
|
+
|
|
358
|
+
* Use with caution, as this bypasses type safety. Ensure that the value being set is compatible with the field's expected type.
|
|
359
|
+
*/
|
|
360
|
+
get nullableValue() {
|
|
361
|
+
return this.isNull() ? null : this.getValue();
|
|
362
|
+
}
|
|
363
|
+
set nullableValue(value) {
|
|
364
|
+
if (value === null) {
|
|
365
|
+
this.setNull();
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
this.setValue(value);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The field value as a string or null.
|
|
373
|
+
*
|
|
374
|
+
* @throws FtFieldTypeError if the field is not of data type `String`.
|
|
375
|
+
*/
|
|
376
|
+
get asNullableString() {
|
|
377
|
+
return this.isNull() ? null : this.getAsString();
|
|
378
|
+
}
|
|
379
|
+
set asNullableString(value) {
|
|
380
|
+
if (value === null) {
|
|
381
|
+
this.setNull();
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
this.setAsString(value);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The field value as a boolean or null.
|
|
389
|
+
*
|
|
390
|
+
* @throws FtFieldTypeError if the field is not of data type `Boolean`.
|
|
391
|
+
*/
|
|
266
392
|
get asNullableBoolean() {
|
|
267
|
-
return this.isNull() ? null : this.
|
|
393
|
+
return this.isNull() ? null : this.getAsBoolean();
|
|
268
394
|
}
|
|
269
395
|
set asNullableBoolean(value) {
|
|
270
396
|
if (value === null) {
|
|
@@ -274,8 +400,13 @@ export class FtField {
|
|
|
274
400
|
this.setAsBoolean(value);
|
|
275
401
|
}
|
|
276
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* The field value as an integer or null.
|
|
405
|
+
*
|
|
406
|
+
* @throws FtFieldTypeError if the field is not of data type `BigInt`.
|
|
407
|
+
*/
|
|
277
408
|
get asNullableInteger() {
|
|
278
|
-
return this.isNull() ? null : this.
|
|
409
|
+
return this.isNull() ? null : this.getAsInteger();
|
|
279
410
|
}
|
|
280
411
|
set asNullableInteger(value) {
|
|
281
412
|
if (value === null) {
|
|
@@ -285,8 +416,13 @@ export class FtField {
|
|
|
285
416
|
this.setAsInteger(value);
|
|
286
417
|
}
|
|
287
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* The field value as a bigint or null.
|
|
421
|
+
*
|
|
422
|
+
* @throws FtFieldTypeError if the field is not of data type `BigInt`.
|
|
423
|
+
*/
|
|
288
424
|
get asNullableBigInt() {
|
|
289
|
-
return this.isNull() ? null : this.
|
|
425
|
+
return this.isNull() ? null : this.getAsBigInt();
|
|
290
426
|
}
|
|
291
427
|
set asNullableBigInt(value) {
|
|
292
428
|
if (value === null) {
|
|
@@ -296,8 +432,13 @@ export class FtField {
|
|
|
296
432
|
this.setAsBigInt(value);
|
|
297
433
|
}
|
|
298
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* The field value as a float or null.
|
|
437
|
+
*
|
|
438
|
+
* @throws FtFieldTypeError if the field is not of data type `Float`.
|
|
439
|
+
*/
|
|
299
440
|
get asNullableFloat() {
|
|
300
|
-
return this.isNull() ? null : this.
|
|
441
|
+
return this.isNull() ? null : this.getAsFloat();
|
|
301
442
|
}
|
|
302
443
|
set asNullableFloat(value) {
|
|
303
444
|
if (value === null) {
|
|
@@ -307,8 +448,13 @@ export class FtField {
|
|
|
307
448
|
this.setAsFloat(value);
|
|
308
449
|
}
|
|
309
450
|
}
|
|
451
|
+
/**
|
|
452
|
+
* The field value as a Date or null.
|
|
453
|
+
*
|
|
454
|
+
* @throws FtFieldTypeError if the field is not of data type `DateTime`.
|
|
455
|
+
*/
|
|
310
456
|
get asNullableDateTime() {
|
|
311
|
-
return this.isNull() ? null : this.
|
|
457
|
+
return this.isNull() ? null : this.getAsDateTime();
|
|
312
458
|
}
|
|
313
459
|
set asNullableDateTime(value) {
|
|
314
460
|
if (value === null) {
|
|
@@ -318,8 +464,13 @@ export class FtField {
|
|
|
318
464
|
this.setAsDateTime(value);
|
|
319
465
|
}
|
|
320
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* The field value as a number (decimal) or null.
|
|
469
|
+
*
|
|
470
|
+
* @throws FtFieldTypeError if the field is not of data type `Decimal`.
|
|
471
|
+
*/
|
|
321
472
|
get asNullableDecimal() {
|
|
322
|
-
return this.isNull() ? null : this.
|
|
473
|
+
return this.isNull() ? null : this.getAsDecimal();
|
|
323
474
|
}
|
|
324
475
|
set asNullableDecimal(value) {
|
|
325
476
|
if (value === null) {
|
|
@@ -329,69 +480,115 @@ export class FtField {
|
|
|
329
480
|
this.setAsDecimal(value);
|
|
330
481
|
}
|
|
331
482
|
}
|
|
332
|
-
|
|
483
|
+
/**
|
|
484
|
+
* Checks if the field value is null.
|
|
485
|
+
* @returns True if the field value is null, false otherwise.
|
|
486
|
+
*/
|
|
333
487
|
isNull() {
|
|
334
488
|
return this._valueIsNull;
|
|
335
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* Sets the field value to null.
|
|
492
|
+
*
|
|
493
|
+
* Checks for sequence redirects that may be triggered by setting the field to null.
|
|
494
|
+
*
|
|
495
|
+
* @returns If this setting of field to null caused a sequence redirect, returns the index of the first field affected by the redirect. If no redirect occurred, returns FtField.NO_FIELDS_AFFECTED_INDEX.
|
|
496
|
+
* @throws Error if the field is constant and cannot be set to null.
|
|
497
|
+
*/
|
|
336
498
|
setNull() {
|
|
337
499
|
if (this.constant) {
|
|
338
500
|
throw new Error(`Cannot set constant field "${this.name}" to null`);
|
|
339
501
|
}
|
|
340
502
|
else {
|
|
341
503
|
this._valueIsNull = true;
|
|
342
|
-
this.
|
|
504
|
+
this._valueAssigned = true;
|
|
343
505
|
return this.checkNullSequenceRedirect(); // returns fieldsAffectedFromIndex
|
|
344
506
|
}
|
|
345
507
|
}
|
|
508
|
+
/**
|
|
509
|
+
* Loads the field value from its formatted text representation.
|
|
510
|
+
* @param valueText - Formatted text representation of field value. Formatting only includes data type formatting and not text formatting such as quoting, padding, truncating etc.
|
|
511
|
+
*/
|
|
512
|
+
loadValueText(valueText) {
|
|
513
|
+
this._valueText = valueText;
|
|
514
|
+
this.loadValueFromText(valueText);
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Loads the field headings from an array of strings.
|
|
518
|
+
*
|
|
519
|
+
* The headings are loaded according to the field's heading constraint. See {@link loadHeading} for more information.
|
|
520
|
+
*
|
|
521
|
+
* @param value - An array of headings. The length of the array should be equal to {@link headingCount}. Extra headings are ignored and missing headings are set to empty strings.
|
|
522
|
+
*/
|
|
346
523
|
loadHeadings(value) {
|
|
347
|
-
|
|
524
|
+
const valueCount = value.length;
|
|
525
|
+
for (let i = 0; i < valueCount; i++) {
|
|
348
526
|
this.loadHeading(i, value[i]);
|
|
349
527
|
}
|
|
528
|
+
const headingCount = this._headings.length;
|
|
529
|
+
if (valueCount < headingCount) {
|
|
530
|
+
for (let i = valueCount; i < headingCount; i++) {
|
|
531
|
+
this.loadHeading(i, '');
|
|
532
|
+
}
|
|
533
|
+
}
|
|
350
534
|
}
|
|
535
|
+
/**
|
|
536
|
+
* Loads a heading into one of the field's heading lines.
|
|
537
|
+
*
|
|
538
|
+
* The heading is loaded according to the field's heading constraint.
|
|
539
|
+
*
|
|
540
|
+
* @param idx - Index of the heading to load.
|
|
541
|
+
* @param headingText - Text of the heading.
|
|
542
|
+
*/
|
|
351
543
|
loadHeading(idx, headingText) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
break;
|
|
356
|
-
case FtHeadingConstraint.AllConstant:
|
|
357
|
-
if (headingText !== this._headings[idx]) {
|
|
358
|
-
throw new Error(`Heading constraint violation: AllConstant at index ${idx} in field ${this.name}`);
|
|
359
|
-
}
|
|
360
|
-
break;
|
|
361
|
-
case FtHeadingConstraint.MainConstant:
|
|
362
|
-
if (idx !== this._definition.mainHeadingIndex) {
|
|
544
|
+
if (idx >= 0 && idx < this._headings.length) {
|
|
545
|
+
switch (this._definition.headingConstraint) {
|
|
546
|
+
case FtHeadingConstraint.None:
|
|
363
547
|
this._headings[idx] = headingText;
|
|
364
|
-
|
|
365
|
-
|
|
548
|
+
break;
|
|
549
|
+
case FtHeadingConstraint.AllConstant:
|
|
366
550
|
if (headingText !== this._headings[idx]) {
|
|
367
|
-
throw new Error(`Heading constraint violation:
|
|
551
|
+
throw new Error(`Heading constraint violation: AllConstant at index ${idx} in field ${this.name}`);
|
|
368
552
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (idx !== this._definition.mainHeadingIndex) {
|
|
373
|
-
this._headings[idx] = headingText;
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
if (headingText.toLowerCase() === this._definition.metaName.toLowerCase()) {
|
|
553
|
+
break;
|
|
554
|
+
case FtHeadingConstraint.MainConstant:
|
|
555
|
+
if (idx !== this._definition.mainHeadingIndex) {
|
|
377
556
|
this._headings[idx] = headingText;
|
|
378
557
|
}
|
|
379
558
|
else {
|
|
380
|
-
|
|
559
|
+
if (headingText !== this._headings[idx]) {
|
|
560
|
+
throw new Error(`Heading constraint violation: MainConstant in field ${this.name}`);
|
|
561
|
+
}
|
|
381
562
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
563
|
+
break;
|
|
564
|
+
case FtHeadingConstraint.NameConstant:
|
|
565
|
+
if (idx !== this._definition.mainHeadingIndex) {
|
|
566
|
+
this._headings[idx] = headingText;
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
if (headingText.toLowerCase() === this._definition.metaName.toLowerCase()) {
|
|
570
|
+
this._headings[idx] = headingText;
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
throw new Error(`Heading constraint violation: NameConstant in field ${this.name}`);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
break;
|
|
577
|
+
case FtHeadingConstraint.NameIsMain:
|
|
578
|
+
this._headings[idx] = headingText;
|
|
579
|
+
if (idx === this._definition.mainHeadingIndex) {
|
|
580
|
+
this._name = headingText;
|
|
581
|
+
}
|
|
582
|
+
break;
|
|
583
|
+
default:
|
|
584
|
+
throw new FtUnreachableCaseError('FLH30773', this._definition.headingConstraint);
|
|
585
|
+
}
|
|
392
586
|
}
|
|
393
587
|
}
|
|
394
|
-
/**
|
|
588
|
+
/**
|
|
589
|
+
* Checks if setting the field to null triggers a sequence redirect.
|
|
590
|
+
* @internal
|
|
591
|
+
*/
|
|
395
592
|
checkNullSequenceRedirect() {
|
|
396
593
|
if (this._sequenceRedirectList.count > 0 && !this._sidelined) {
|
|
397
594
|
let redirected = false;
|
|
@@ -417,7 +614,7 @@ export class FtField {
|
|
|
417
614
|
if (!this.constant) {
|
|
418
615
|
this._valueIsNull = true;
|
|
419
616
|
}
|
|
420
|
-
this.
|
|
617
|
+
this._valueAssigned = false;
|
|
421
618
|
}
|
|
422
619
|
// Loading methods (used by parsers)
|
|
423
620
|
/** @internal */
|
|
@@ -429,10 +626,10 @@ export class FtField {
|
|
|
429
626
|
}
|
|
430
627
|
/** @internal */
|
|
431
628
|
loadDelimitedValue(valueText, quoted) {
|
|
432
|
-
this.
|
|
629
|
+
this._valueText = valueText;
|
|
433
630
|
try {
|
|
434
631
|
if (quoted) {
|
|
435
|
-
this.
|
|
632
|
+
this.loadValueFromText(valueText);
|
|
436
633
|
}
|
|
437
634
|
else {
|
|
438
635
|
if (this._valueTextNullTrimmable) {
|
|
@@ -441,18 +638,18 @@ export class FtField {
|
|
|
441
638
|
this.loadNullValue();
|
|
442
639
|
}
|
|
443
640
|
else {
|
|
444
|
-
this.
|
|
641
|
+
this.loadValueFromText(valueText);
|
|
445
642
|
}
|
|
446
643
|
}
|
|
447
644
|
else {
|
|
448
645
|
if (valueText.length !== 0) {
|
|
449
|
-
this.
|
|
646
|
+
this.loadValueFromText(valueText);
|
|
450
647
|
}
|
|
451
648
|
else {
|
|
452
649
|
switch (this.valueQuotedType) {
|
|
453
650
|
case FtQuotedType.Never:
|
|
454
651
|
case FtQuotedType.Optional:
|
|
455
|
-
this.
|
|
652
|
+
this.loadValueFromText(valueText);
|
|
456
653
|
break;
|
|
457
654
|
case FtQuotedType.Always:
|
|
458
655
|
this.loadNullValue();
|
|
@@ -470,13 +667,13 @@ export class FtField {
|
|
|
470
667
|
}
|
|
471
668
|
/** @internal */
|
|
472
669
|
loadFixedWidthValue(valueText) {
|
|
473
|
-
this.
|
|
670
|
+
this._valueText = valueText;
|
|
474
671
|
if (valueText === this._definition.fixedWidthNullValueText) {
|
|
475
672
|
this.loadNullValue();
|
|
476
673
|
}
|
|
477
674
|
else {
|
|
478
675
|
try {
|
|
479
|
-
this.
|
|
676
|
+
this.loadValueFromText(valueText);
|
|
480
677
|
}
|
|
481
678
|
catch (e) {
|
|
482
679
|
throw new Error(`Error loading fixed-width value for field ${this.name}: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
@@ -487,7 +684,7 @@ export class FtField {
|
|
|
487
684
|
loadNullValue() {
|
|
488
685
|
if (!this.constant) {
|
|
489
686
|
this._valueIsNull = true;
|
|
490
|
-
this.
|
|
687
|
+
this._valueAssigned = true;
|
|
491
688
|
this.checkNullSequenceRedirect();
|
|
492
689
|
}
|
|
493
690
|
else {
|
|
@@ -496,20 +693,6 @@ export class FtField {
|
|
|
496
693
|
}
|
|
497
694
|
}
|
|
498
695
|
}
|
|
499
|
-
/**
|
|
500
|
-
* Get the field value as text (for writing). Public accessor for protected method.
|
|
501
|
-
* @internal
|
|
502
|
-
*/
|
|
503
|
-
getValueText() {
|
|
504
|
-
return this.getAsNonNullValueText();
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* Check if the field value has been assigned. Public accessor for protected property.
|
|
508
|
-
* @internal
|
|
509
|
-
*/
|
|
510
|
-
isValueAssigned() {
|
|
511
|
-
return this.valueAssigned;
|
|
512
|
-
}
|
|
513
696
|
// get dataTypeName(): string {
|
|
514
697
|
// return this._definition.dataTypeName;
|
|
515
698
|
// }
|
|
@@ -524,38 +707,47 @@ export class FtField {
|
|
|
524
707
|
clearNonConstantNull() {
|
|
525
708
|
this._valueIsNull = false;
|
|
526
709
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
this.loadNonNullValue(newValue);
|
|
530
|
-
}
|
|
531
|
-
catch (error) {
|
|
532
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
533
|
-
throw new Error(`Failed to set field "${this.name}" value: ${message}`, { cause: error });
|
|
534
|
-
}
|
|
710
|
+
getAsString() {
|
|
711
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsString`);
|
|
535
712
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
this.setNull();
|
|
539
|
-
}
|
|
540
|
-
else {
|
|
541
|
-
this.setAsNonNullValueText(newValue);
|
|
542
|
-
}
|
|
713
|
+
getAsBoolean() {
|
|
714
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsBoolean`);
|
|
543
715
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
this.setNull();
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
this.setAsNonNullObject(newValue);
|
|
550
|
-
}
|
|
716
|
+
getAsInteger() {
|
|
717
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsInteger`);
|
|
551
718
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
719
|
+
getAsBigInt() {
|
|
720
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsBigInt`);
|
|
721
|
+
}
|
|
722
|
+
getAsFloat() {
|
|
723
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsFloat`);
|
|
724
|
+
}
|
|
725
|
+
getAsDateTime() {
|
|
726
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsDateTime`);
|
|
727
|
+
}
|
|
728
|
+
getAsDecimal() {
|
|
729
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsDecimal`);
|
|
730
|
+
}
|
|
731
|
+
setAsString(_newValue) {
|
|
732
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsString`);
|
|
733
|
+
}
|
|
734
|
+
setAsBoolean(_newValue) {
|
|
735
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsBoolean`);
|
|
736
|
+
}
|
|
737
|
+
setAsInteger(_newValue) {
|
|
738
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsInteger`);
|
|
739
|
+
}
|
|
740
|
+
setAsBigInt(_newValue) {
|
|
741
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsBigInt`);
|
|
742
|
+
}
|
|
743
|
+
setAsFloat(_newValue) {
|
|
744
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsFloat`);
|
|
745
|
+
}
|
|
746
|
+
setAsDateTime(_newValue) {
|
|
747
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsDateTime`);
|
|
748
|
+
}
|
|
749
|
+
setAsDecimal(_newValue) {
|
|
750
|
+
throw new FtFieldTypeError(`Field ${this.name} does not support AsDecimal`);
|
|
559
751
|
}
|
|
560
752
|
}
|
|
561
753
|
//# sourceMappingURL=ft-field.js.map
|