Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class ArgumentNullError extends Error {
this.name = "ArgumentNullError";
}

name: string;
override name: string;
}

export class GeneratorError extends Error {
Expand All @@ -15,7 +15,7 @@ export class GeneratorError extends Error {
this.name = "GeneratorError";
}

name: string;
override name: string;
}

export class ParserError extends Error {
Expand All @@ -24,7 +24,7 @@ export class ParserError extends Error {
this.name = "ParserError";
}

name: string;
override name: string;
}

export class QuerySyntaxError extends Error {
Expand All @@ -33,5 +33,5 @@ export class QuerySyntaxError extends Error {
this.name = "QuerySyntaxError";
}

name: string;
override name: string;
}
2 changes: 1 addition & 1 deletion src/X12FatInterchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class X12FatInterchange extends Array<X12Interchange> {
* @param {X12SerializationOptions} [options] - Options to override serializing back to EDI.
* @returns {string} This fat interchange converted to EDI string.
*/
toString(options?: X12SerializationOptions): string {
override toString(options?: X12SerializationOptions): string {
options = options !== undefined
? defaultSerializationOptions(options)
: this.options;
Expand Down
4 changes: 2 additions & 2 deletions src/X12Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ export class X12Parser extends Transform {
* @description Flush method for Node API Transform stream.
* @param {Function} callback - Callback to execute when finished.
*/
public _flush(callback: Function): void {
public override _flush(callback: Function): void {
this._flushing = true;
this._consumeChunk(this._dataCache);
this._flushing = false;
Expand All @@ -657,7 +657,7 @@ export class X12Parser extends Transform {
* @param {string} encoding - Chunk enoding.
* @param {Function} callback - Callback signalling chunk is processed and instance is ready for next chunk.
*/
public _transform(chunk: any, _encoding: string, callback: Function): void {
public override _transform(chunk: any, _encoding: string, callback: Function): void {
this._consumeChunk(this._decoder.write(chunk));

callback();
Expand Down
4 changes: 2 additions & 2 deletions src/X12QueryEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export class X12QueryEngine {
}

const hlPathMatch = reference.match(/HL\+(\w\+?)+[+-]/g); // ex. HL+O+P+I
const segPathMatch = reference.match(/((?<!\+)[A-Z0-9]{2,3}-)+/g); // ex. PO1-N9-
const elmRefMatch = reference.match(/[A-Z0-9]{2,3}[0-9]{2}[^[]?/g); // ex. REF02; need to remove trailing ":" if exists
const segPathMatch = reference.match(/((?<!\+)[A-Z0-9]{2,3}(?:!\d{2}\[)-)+/g); // ex. PO1-N9-
const elmRefMatch = reference.match(/[A-Z][A-Z0-9]{1,2}[0-9]{2}[^[]?/g); // ex. REF02; need to remove trailing ":" if exists
const qualMatch = reference.match(
/:[A-Z0-9]{2,3}[0-9]{2,}\[["'][^[\]"']+["']\]/g,
); // ex. :REF01["PO"]
Expand Down
6 changes: 4 additions & 2 deletions src/X12TransactionMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ export class X12TransactionMap {
newArray.push(this.helper(key, result.value, query, callback));
}
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
throw new QuerySyntaxError(
`${err.message}; bad query in ${map[key]}`,
`${message}; bad query in ${map[key]}`,
);
}
});
Expand Down Expand Up @@ -259,8 +260,9 @@ export class X12TransactionMap {
clone[key] = this.helper(key, result.value, map[key], callback);
}
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
throw new QuerySyntaxError(
`${err.message}; bad query in ${map[key]}`,
`${message}; bad query in ${map[key]}`,
);
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/X12ValidationEngine/X12ValidationRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class X12InterchangeRule extends X12ValidationRule {
header: X12SegmentRule;
trailer: X12SegmentRule;

assert?(interchange: X12Interchange): true | ValidationReport {
override assert?(interchange: X12Interchange): true | ValidationReport {
const report: ValidationReport = {};
const headerResult = this.header.assert?.(interchange.header);
let pass = true;
Expand Down Expand Up @@ -222,7 +222,7 @@ export class X12GroupRule extends X12ValidationRule {
header: X12SegmentRule;
trailer: X12SegmentRule;

assert?(
override assert?(
group: X12FunctionalGroup,
controlNumber: number,
): true | ValidationReport {
Expand Down Expand Up @@ -336,7 +336,7 @@ export class X12TransactionRule extends X12ValidationRule {
header: X12SegmentRule;
trailer: X12SegmentRule;

assert?(
override assert?(
transaction: X12Transaction,
controlNumber: number,
): true | ValidationReport {
Expand Down Expand Up @@ -504,7 +504,7 @@ export class X12SegmentRule extends X12ValidationRule {
loopEnd?: boolean;
mandatory?: boolean;

assert?(segment: X12Segment, position = 1): true | ValidationReport {
override assert?(segment: X12Segment, position = 1): true | ValidationReport {
const errors: ValidationError[] = [];
const elements: ValidationError[] = [];

Expand Down Expand Up @@ -587,7 +587,7 @@ export class X12ElementRule extends X12ValidationRule {
| "gs01"
| "st01";

assert?(element: X12Element, position?: number): true | ValidationReport {
override assert?(element: X12Element, position?: number): true | ValidationReport {
if (this.skip) return true;
if (typeof element === "undefined") {
return { elements: [errorLookup(this.ruleType, "2", position, "")] };
Expand Down
4 changes: 2 additions & 2 deletions test/GeneratorSuite_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("X12Generator", () => {
try {
t.setHeader([...fileEdi[2].split("*").slice(1), "N"]);
} catch (err) {
error = err.message;
error = (err as Error).message;
}

if (
Expand Down Expand Up @@ -166,7 +166,7 @@ describe("X12Generator", () => {
const generator = new X12Generator(JSON.parse(json), options);
generator.toString();
} catch (err) {
error = err.message;
error = (err as Error).message;
}

if (
Expand Down
6 changes: 3 additions & 3 deletions test/ParserSuite_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("X12Parser", () => {
error = err;
}

if (error.name !== "ArgumentNullError") {
if ((error as Error).name !== "ArgumentNullError") {
throw new Error(
"ArgumentNullError expected when first argument to X12Parser.parse() is undefined.",
);
Expand All @@ -110,7 +110,7 @@ describe("X12Parser", () => {
error = err;
}

if (error.name !== "ParserError") {
if ((error as Error).name !== "ParserError") {
throw new Error(
"ParserError expected when document length is too short and parser is strict.",
);
Expand All @@ -128,7 +128,7 @@ describe("X12Parser", () => {
error = err;
}

if (error.name !== "ParserError") {
if ((error as Error).name !== "ParserError") {
throw new Error(
"ParserError expected when elementDelimiter in document does not match and parser is strict.",
);
Expand Down
13 changes: 13 additions & 0 deletions test/QuerySuite_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ describe("X12QueryEngine", () => {
}
});

it("should handle hyphenated qualifiers values", () => {
const edi = Deno.readTextFileSync("test/test-data/850.edi");
const parser = new X12Parser(true);
const engine = new X12QueryEngine(parser);
const results = engine.query(edi, 'PO102:PO107["065374-118"]');

console.log(results.length);

if (results.length !== 1) {
throw new Error('Expected one matching elements for PO102:PO107["065374-118"].');
}
});

it("should handle HL path element references", () => {
const edi = Deno.readTextFileSync("test/test-data/856.edi");
const parser = new X12Parser(true);
Expand Down
2 changes: 1 addition & 1 deletion test/ValidationSuite_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("X12ValidationEngine", () => {
try {
validator.assert(interchange, rule);
} catch (error) {
const { report } = error;
const { report } = error as Error & { report: any };

assert.strictEqual(typeof report, "object");
}
Expand Down
Loading