From 7b55f050df327939efcb65d4e76d27f98c89d925 Mon Sep 17 00:00:00 2001 From: David Worms Date: Sun, 7 Nov 2021 00:52:57 +0100 Subject: [PATCH] refactor(csv-parse)!: rename RECORD_INCONSISTENT_FIELDS_LENGTH --- packages/csv-parse/ROADMAP.md | 1 - packages/csv-parse/dist/cjs/index.cjs | 4 +--- packages/csv-parse/dist/cjs/index.d.ts | 2 +- packages/csv-parse/dist/cjs/sync.cjs | 4 +--- packages/csv-parse/dist/esm/index.d.ts | 2 +- packages/csv-parse/dist/esm/index.js | 4 +--- packages/csv-parse/dist/esm/sync.js | 4 +--- packages/csv-parse/dist/iife/index.js | 4 +--- packages/csv-parse/dist/iife/sync.js | 4 +--- packages/csv-parse/dist/umd/index.js | 4 +--- packages/csv-parse/dist/umd/sync.js | 4 +--- packages/csv-parse/lib/index.d.ts | 2 +- packages/csv-parse/lib/index.js | 4 +--- ...elax_column_count.record_inconsistent_length.js | 2 +- packages/csv-parse/test/api.types.sync.ts | 2 +- packages/csv-parse/test/api.types.ts | 14 +++++++------- .../test/option.relax_column_count.coffee | 10 +++++----- .../test/option.skip_records_with_error.coffee | 4 ++-- 18 files changed, 28 insertions(+), 47 deletions(-) diff --git a/packages/csv-parse/ROADMAP.md b/packages/csv-parse/ROADMAP.md index 7cdc3903a..fd7a00115 100644 --- a/packages/csv-parse/ROADMAP.md +++ b/packages/csv-parse/ROADMAP.md @@ -9,6 +9,5 @@ We invite you to join and contribute but create an issue before engaging any wor * errors: finish normalisation of all errors (easy) * encoding: new encoding_input and encoding_output options (medium) * `columns_duplicates_to_array`: this is just too long but I don't have much insipiration for a better name -* `relax_column_count`: rename INCONSISTENT_RECORD_LENGTH to RECORD_INCONSISTENT_FIELDS_LENGTH (easy) * `info`: remove the `parser.info` object and move its properties to `state` * `info`: rename the `info` related properties and functions to `context` diff --git a/packages/csv-parse/dist/cjs/index.cjs b/packages/csv-parse/dist/cjs/index.cjs index d10aa4e0d..68ea1de24 100644 --- a/packages/csv-parse/dist/cjs/index.cjs +++ b/packages/csv-parse/dist/cjs/index.cjs @@ -5879,9 +5879,7 @@ class Parser extends Transform { } if(recordLength !== this.state.expectedRecordLength){ const err = columns === false ? - // Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to - // CSV_RECORD_INCONSISTENT_FIELDS_LENGTH - new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [ + new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [ 'Invalid Record Length:', `expect ${this.state.expectedRecordLength},`, `got ${recordLength} on line ${this.info.lines}`, diff --git a/packages/csv-parse/dist/cjs/index.d.ts b/packages/csv-parse/dist/cjs/index.d.ts index 5ada1bcb4..78114f792 100644 --- a/packages/csv-parse/dist/cjs/index.d.ts +++ b/packages/csv-parse/dist/cjs/index.d.ts @@ -253,7 +253,7 @@ export type CsvErrorCode = | 'CSV_MAX_RECORD_SIZE' | 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE' | 'CSV_QUOTE_NOT_CLOSED' - | 'CSV_INCONSISTENT_RECORD_LENGTH' + | 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' | 'CSV_RECORD_INCONSISTENT_COLUMNS' | 'CSV_OPTION_COLUMNS_MISSING_NAME' diff --git a/packages/csv-parse/dist/cjs/sync.cjs b/packages/csv-parse/dist/cjs/sync.cjs index 1f90c88b9..ba56de82f 100644 --- a/packages/csv-parse/dist/cjs/sync.cjs +++ b/packages/csv-parse/dist/cjs/sync.cjs @@ -5879,9 +5879,7 @@ class Parser extends Transform { } if(recordLength !== this.state.expectedRecordLength){ const err = columns === false ? - // Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to - // CSV_RECORD_INCONSISTENT_FIELDS_LENGTH - new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [ + new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [ 'Invalid Record Length:', `expect ${this.state.expectedRecordLength},`, `got ${recordLength} on line ${this.info.lines}`, diff --git a/packages/csv-parse/dist/esm/index.d.ts b/packages/csv-parse/dist/esm/index.d.ts index 5ada1bcb4..78114f792 100644 --- a/packages/csv-parse/dist/esm/index.d.ts +++ b/packages/csv-parse/dist/esm/index.d.ts @@ -253,7 +253,7 @@ export type CsvErrorCode = | 'CSV_MAX_RECORD_SIZE' | 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE' | 'CSV_QUOTE_NOT_CLOSED' - | 'CSV_INCONSISTENT_RECORD_LENGTH' + | 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' | 'CSV_RECORD_INCONSISTENT_COLUMNS' | 'CSV_OPTION_COLUMNS_MISSING_NAME' diff --git a/packages/csv-parse/dist/esm/index.js b/packages/csv-parse/dist/esm/index.js index 7cc22df32..526b69edd 100644 --- a/packages/csv-parse/dist/esm/index.js +++ b/packages/csv-parse/dist/esm/index.js @@ -5875,9 +5875,7 @@ class Parser extends Transform { } if(recordLength !== this.state.expectedRecordLength){ const err = columns === false ? - // Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to - // CSV_RECORD_INCONSISTENT_FIELDS_LENGTH - new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [ + new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [ 'Invalid Record Length:', `expect ${this.state.expectedRecordLength},`, `got ${recordLength} on line ${this.info.lines}`, diff --git a/packages/csv-parse/dist/esm/sync.js b/packages/csv-parse/dist/esm/sync.js index fb01234d1..c164f5cb0 100644 --- a/packages/csv-parse/dist/esm/sync.js +++ b/packages/csv-parse/dist/esm/sync.js @@ -5875,9 +5875,7 @@ class Parser extends Transform { } if(recordLength !== this.state.expectedRecordLength){ const err = columns === false ? - // Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to - // CSV_RECORD_INCONSISTENT_FIELDS_LENGTH - new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [ + new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [ 'Invalid Record Length:', `expect ${this.state.expectedRecordLength},`, `got ${recordLength} on line ${this.info.lines}`, diff --git a/packages/csv-parse/dist/iife/index.js b/packages/csv-parse/dist/iife/index.js index 811eeef13..421f0e132 100644 --- a/packages/csv-parse/dist/iife/index.js +++ b/packages/csv-parse/dist/iife/index.js @@ -5878,9 +5878,7 @@ var csv_parse = (function (exports) { } if(recordLength !== this.state.expectedRecordLength){ const err = columns === false ? - // Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to - // CSV_RECORD_INCONSISTENT_FIELDS_LENGTH - new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [ + new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [ 'Invalid Record Length:', `expect ${this.state.expectedRecordLength},`, `got ${recordLength} on line ${this.info.lines}`, diff --git a/packages/csv-parse/dist/iife/sync.js b/packages/csv-parse/dist/iife/sync.js index c4c4a14f2..14cbfc1ad 100644 --- a/packages/csv-parse/dist/iife/sync.js +++ b/packages/csv-parse/dist/iife/sync.js @@ -5878,9 +5878,7 @@ var csv_parse_sync = (function (exports) { } if(recordLength !== this.state.expectedRecordLength){ const err = columns === false ? - // Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to - // CSV_RECORD_INCONSISTENT_FIELDS_LENGTH - new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [ + new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [ 'Invalid Record Length:', `expect ${this.state.expectedRecordLength},`, `got ${recordLength} on line ${this.info.lines}`, diff --git a/packages/csv-parse/dist/umd/index.js b/packages/csv-parse/dist/umd/index.js index 91e8a022b..9901a1805 100644 --- a/packages/csv-parse/dist/umd/index.js +++ b/packages/csv-parse/dist/umd/index.js @@ -5881,9 +5881,7 @@ } if(recordLength !== this.state.expectedRecordLength){ const err = columns === false ? - // Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to - // CSV_RECORD_INCONSISTENT_FIELDS_LENGTH - new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [ + new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [ 'Invalid Record Length:', `expect ${this.state.expectedRecordLength},`, `got ${recordLength} on line ${this.info.lines}`, diff --git a/packages/csv-parse/dist/umd/sync.js b/packages/csv-parse/dist/umd/sync.js index 32d3edbd7..87a0c9b9b 100644 --- a/packages/csv-parse/dist/umd/sync.js +++ b/packages/csv-parse/dist/umd/sync.js @@ -5881,9 +5881,7 @@ } if(recordLength !== this.state.expectedRecordLength){ const err = columns === false ? - // Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to - // CSV_RECORD_INCONSISTENT_FIELDS_LENGTH - new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [ + new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [ 'Invalid Record Length:', `expect ${this.state.expectedRecordLength},`, `got ${recordLength} on line ${this.info.lines}`, diff --git a/packages/csv-parse/lib/index.d.ts b/packages/csv-parse/lib/index.d.ts index 5ada1bcb4..78114f792 100644 --- a/packages/csv-parse/lib/index.d.ts +++ b/packages/csv-parse/lib/index.d.ts @@ -253,7 +253,7 @@ export type CsvErrorCode = | 'CSV_MAX_RECORD_SIZE' | 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE' | 'CSV_QUOTE_NOT_CLOSED' - | 'CSV_INCONSISTENT_RECORD_LENGTH' + | 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' | 'CSV_RECORD_INCONSISTENT_COLUMNS' | 'CSV_OPTION_COLUMNS_MISSING_NAME' diff --git a/packages/csv-parse/lib/index.js b/packages/csv-parse/lib/index.js index fa7a6e1ac..1057bc49e 100644 --- a/packages/csv-parse/lib/index.js +++ b/packages/csv-parse/lib/index.js @@ -879,9 +879,7 @@ class Parser extends Transform { } if(recordLength !== this.state.expectedRecordLength){ const err = columns === false ? - // Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to - // CSV_RECORD_INCONSISTENT_FIELDS_LENGTH - new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [ + new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [ 'Invalid Record Length:', `expect ${this.state.expectedRecordLength},`, `got ${recordLength} on line ${this.info.lines}`, diff --git a/packages/csv-parse/samples/option.relax_column_count.record_inconsistent_length.js b/packages/csv-parse/samples/option.relax_column_count.record_inconsistent_length.js index c311c45d6..a6619188c 100644 --- a/packages/csv-parse/samples/option.relax_column_count.record_inconsistent_length.js +++ b/packages/csv-parse/samples/option.relax_column_count.record_inconsistent_length.js @@ -6,7 +6,7 @@ const records = parse('1,2\nin:va:lid\n3,4', { relax_column_count: true, raw: true, on_record: ({raw, record}, {error}) => { - if(error && error.code === 'CSV_INCONSISTENT_RECORD_LENGTH'){ + if(error && error.code === 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'){ return raw.trim().split(':'); } else { return record; diff --git a/packages/csv-parse/test/api.types.sync.ts b/packages/csv-parse/test/api.types.sync.ts index 8506a7219..05804166a 100644 --- a/packages/csv-parse/test/api.types.sync.ts +++ b/packages/csv-parse/test/api.types.sync.ts @@ -72,7 +72,7 @@ describe('API Types', () => { }) it('CsvErrorCode', () => { - const err = new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', 'error'); + const err = new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', 'error'); const code: CsvErrorCode = err.code; return code; }) diff --git a/packages/csv-parse/test/api.types.ts b/packages/csv-parse/test/api.types.ts index 2c243dc14..3a1a2f229 100644 --- a/packages/csv-parse/test/api.types.ts +++ b/packages/csv-parse/test/api.types.ts @@ -340,23 +340,23 @@ describe('API Types', () => { describe('CsvError', () => { describe('Typescript definition is accurate', () => { it('Minimum', () => { - const error = new CsvError("CSV_INCONSISTENT_RECORD_LENGTH", "MESSAGE"); + const error = new CsvError("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH", "MESSAGE"); - error.code.should.eql("CSV_INCONSISTENT_RECORD_LENGTH") + error.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH") error.message.should.eql("MESSAGE") }) it('Multiple messages', () => { - const error = new CsvError("CSV_INCONSISTENT_RECORD_LENGTH", ["MESSAGE1", "MESSAGE2"]) + const error = new CsvError("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH", ["MESSAGE1", "MESSAGE2"]) - error.code.should.eql("CSV_INCONSISTENT_RECORD_LENGTH") + error.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH") error.message.should.eql("MESSAGE1 MESSAGE2") }) it('Supports contexts', () => { - const error = new CsvError("CSV_INCONSISTENT_RECORD_LENGTH", "MESSAGE", {}, { testContext: { testProp: "testValue" } }) + const error = new CsvError("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH", "MESSAGE", {}, { testContext: { testProp: "testValue" } }) - error.code.should.eql("CSV_INCONSISTENT_RECORD_LENGTH") + error.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH") error.message.should.eql("MESSAGE") error.should.have.key("testContext").and.eql({ testProp: "testValue" }) }) @@ -366,7 +366,7 @@ describe('API Types', () => { parse(`a,b\nc`, function (e: Error|undefined) { const isCsvError = e instanceof CsvError; isCsvError.should.be.true(); - (e as CsvError).code.should.eql('CSV_INCONSISTENT_RECORD_LENGTH'); + (e as CsvError).code.should.eql('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'); }) }) }) diff --git a/packages/csv-parse/test/option.relax_column_count.coffee b/packages/csv-parse/test/option.relax_column_count.coffee index 8c013b22d..7b2fbfc16 100644 --- a/packages/csv-parse/test/option.relax_column_count.coffee +++ b/packages/csv-parse/test/option.relax_column_count.coffee @@ -22,7 +22,7 @@ describe 'Option `relax_column_count`', -> 4,5 """, (err) -> assert_error err, - code: 'CSV_INCONSISTENT_RECORD_LENGTH' + code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' message: 'Invalid Record Length: expect 3, got 2 on line 2' record: ['4', '5'] next() @@ -36,7 +36,7 @@ describe 'Option `relax_column_count`', -> """ , (err) -> assert_error err, - code: 'CSV_INCONSISTENT_RECORD_LENGTH' + code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' message: 'Invalid Record Length: expect 2, got 1 on line 2' record: ['1'] next() @@ -106,7 +106,7 @@ describe 'Option `relax_column_count`', -> a,b """, relax_column_count_more: true, (err) -> assert_error err, - code: 'CSV_INCONSISTENT_RECORD_LENGTH' + code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' message: 'Invalid Record Length: expect 3, got 2 on line 2' record: ['a', 'b'] next() @@ -130,7 +130,7 @@ describe 'Option `relax_column_count`', -> a,b,c,d """, relax_column_count_less: true, (err) -> assert_error err, - code: 'CSV_INCONSISTENT_RECORD_LENGTH' + code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' message: 'Invalid Record Length: expect 3, got 4 on line 2' record: ['a', 'b', 'c', 'd'] next() @@ -146,7 +146,7 @@ describe 'Option `relax_column_count`', -> relax_column_count: true, raw: true, on_record: ({raw, record}, {error}) -> - if error?.code is 'CSV_INCONSISTENT_RECORD_LENGTH' + if error?.code is 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' raw.trim().split ':' else record diff --git a/packages/csv-parse/test/option.skip_records_with_error.coffee b/packages/csv-parse/test/option.skip_records_with_error.coffee index bc08b9c1c..41f7cfe22 100644 --- a/packages/csv-parse/test/option.skip_records_with_error.coffee +++ b/packages/csv-parse/test/option.skip_records_with_error.coffee @@ -108,7 +108,7 @@ describe 'Option `skip_records_with_error`', -> parser.end() - it 'handle "CSV_INCONSISTENT_RECORD_LENGTH"', (next) -> + it 'handle "CSV_RECORD_INCONSISTENT_FIELDS_LENGTH"', (next) -> errors = 0 parser = parse skip_records_with_error: true, (err, records) -> records.should.eql [ @@ -120,7 +120,7 @@ describe 'Option `skip_records_with_error`', -> parser.on 'skip', (err) -> assert_error err, message: 'Invalid Record Length: expect 4, got 3 on line 2' - code: 'CSV_INCONSISTENT_RECORD_LENGTH' + code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' record: ['1', '2', '3'] errors++ parser.write '''