From 890bf8d950c18a05cab5e35a461d0847d9425156 Mon Sep 17 00:00:00 2001 From: David Worms Date: Thu, 21 Oct 2021 23:39:14 +0200 Subject: [PATCH] feat: export ts types in sync --- packages/csv-generate/dist/cjs/index.d.ts | 14 --- packages/csv-generate/dist/cjs/sync.d.ts | 3 +- packages/csv-generate/dist/esm/index.d.ts | 14 --- packages/csv-generate/dist/esm/sync.d.ts | 3 +- packages/csv-generate/lib/index.d.ts | 14 --- packages/csv-generate/lib/sync.d.ts | 3 +- packages/csv-generate/test/api.types.sync.ts | 38 ++++++++ packages/csv-generate/test/api.types.ts | 16 ---- packages/csv-parse/dist/cjs/index.d.ts | 1 - packages/csv-parse/dist/cjs/sync.d.ts | 6 +- packages/csv-parse/dist/esm/index.d.ts | 1 - packages/csv-parse/dist/esm/sync.d.ts | 6 +- packages/csv-parse/lib/index.d.ts | 1 - packages/csv-parse/lib/sync.d.ts | 6 +- packages/csv-parse/test/api.types.sync.ts | 92 +++++++++++++++++++ packages/csv-stringify/dist/cjs/sync.d.ts | 5 + packages/csv-stringify/dist/esm/sync.d.ts | 5 + packages/csv-stringify/lib/sync.d.ts | 5 + packages/csv-stringify/test/api.types.sync.ts | 41 +++++++++ packages/csv/dist/cjs/index.d.ts | 7 +- packages/csv/dist/cjs/sync.cjs | 2 +- packages/csv/dist/cjs/sync.d.ts | 15 ++- packages/csv/dist/esm/index.d.ts | 7 +- packages/csv/dist/esm/sync.d.ts | 15 ++- packages/csv/dist/esm/sync.js | 2 +- packages/csv/dist/iife/sync.js | 2 +- packages/csv/dist/umd/sync.js | 2 +- packages/csv/lib/index.d.ts | 7 +- packages/csv/lib/sync.d.ts | 15 ++- packages/csv/test/api.types.sync.ts | 56 +++++++++++ packages/csv/test/api.types.ts | 2 +- packages/stream-transform/dist/cjs/sync.d.ts | 5 +- packages/stream-transform/dist/esm/sync.d.ts | 5 +- packages/stream-transform/lib/sync.d.ts | 5 +- .../stream-transform/test/api.types.sync.ts | 24 +++++ packages/stream-transform/test/api.types.ts | 9 -- 36 files changed, 346 insertions(+), 108 deletions(-) create mode 100644 packages/csv-generate/test/api.types.sync.ts create mode 100644 packages/csv-parse/test/api.types.sync.ts create mode 100644 packages/csv-stringify/test/api.types.sync.ts create mode 100644 packages/csv/test/api.types.sync.ts create mode 100644 packages/stream-transform/test/api.types.sync.ts diff --git a/packages/csv-generate/dist/cjs/index.d.ts b/packages/csv-generate/dist/cjs/index.d.ts index 6d3de7d39..62b9d560d 100644 --- a/packages/csv-generate/dist/cjs/index.d.ts +++ b/packages/csv-generate/dist/cjs/index.d.ts @@ -12,76 +12,62 @@ export class Generator extends stream.Readable { } export interface Options { - /** * Define the number of generated fields and the generation method. */ columns?: number | string[]; - /** * Set the field delimiter. */ delimiter?: string; - /** * Period to run in milliseconds. */ duration?: number; - /** * If specified, then buffers will be decoded to strings using the specified encoding. */ encoding?: string; - /** * When to stop the generation. */ end?: number | Date; - /** * One or multiple characters to print at the end of the file; only apply when objectMode is disabled. */ eof?: boolean | string; - /** * Generate buffers equals length as defined by the `highWaterMark` option. */ fixed_size?: boolean; fixedSize?: boolean; - /** * The maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource. */ high_water_mark?: number; highWaterMark?: number; - /** * Number of lines or records to generate. */ length?: number; - /** * Maximum number of characters per word. */ max_word_length?: number; maxWordLength?: number; - /** * Whether this stream should behave as a stream of objects. */ object_mode?: boolean objectMode?: boolean; - /** * One or multiple characters used to delimit records. */ row_delimiter?: string; - /** * Generate idempotent random characters if a number provided. */ seed?: boolean | number; - /** * The time to wait between the generation of each records */ diff --git a/packages/csv-generate/dist/cjs/sync.d.ts b/packages/csv-generate/dist/cjs/sync.d.ts index 66583b6ac..bc57dc568 100644 --- a/packages/csv-generate/dist/cjs/sync.d.ts +++ b/packages/csv-generate/dist/cjs/sync.d.ts @@ -2,6 +2,5 @@ import { Options } from './index'; declare function generate(options: number | Options): string & Array; - // export default generate; -export { generate }; +export { generate, Options }; diff --git a/packages/csv-generate/dist/esm/index.d.ts b/packages/csv-generate/dist/esm/index.d.ts index 6d3de7d39..62b9d560d 100644 --- a/packages/csv-generate/dist/esm/index.d.ts +++ b/packages/csv-generate/dist/esm/index.d.ts @@ -12,76 +12,62 @@ export class Generator extends stream.Readable { } export interface Options { - /** * Define the number of generated fields and the generation method. */ columns?: number | string[]; - /** * Set the field delimiter. */ delimiter?: string; - /** * Period to run in milliseconds. */ duration?: number; - /** * If specified, then buffers will be decoded to strings using the specified encoding. */ encoding?: string; - /** * When to stop the generation. */ end?: number | Date; - /** * One or multiple characters to print at the end of the file; only apply when objectMode is disabled. */ eof?: boolean | string; - /** * Generate buffers equals length as defined by the `highWaterMark` option. */ fixed_size?: boolean; fixedSize?: boolean; - /** * The maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource. */ high_water_mark?: number; highWaterMark?: number; - /** * Number of lines or records to generate. */ length?: number; - /** * Maximum number of characters per word. */ max_word_length?: number; maxWordLength?: number; - /** * Whether this stream should behave as a stream of objects. */ object_mode?: boolean objectMode?: boolean; - /** * One or multiple characters used to delimit records. */ row_delimiter?: string; - /** * Generate idempotent random characters if a number provided. */ seed?: boolean | number; - /** * The time to wait between the generation of each records */ diff --git a/packages/csv-generate/dist/esm/sync.d.ts b/packages/csv-generate/dist/esm/sync.d.ts index 66583b6ac..bc57dc568 100644 --- a/packages/csv-generate/dist/esm/sync.d.ts +++ b/packages/csv-generate/dist/esm/sync.d.ts @@ -2,6 +2,5 @@ import { Options } from './index'; declare function generate(options: number | Options): string & Array; - // export default generate; -export { generate }; +export { generate, Options }; diff --git a/packages/csv-generate/lib/index.d.ts b/packages/csv-generate/lib/index.d.ts index 6d3de7d39..62b9d560d 100644 --- a/packages/csv-generate/lib/index.d.ts +++ b/packages/csv-generate/lib/index.d.ts @@ -12,76 +12,62 @@ export class Generator extends stream.Readable { } export interface Options { - /** * Define the number of generated fields and the generation method. */ columns?: number | string[]; - /** * Set the field delimiter. */ delimiter?: string; - /** * Period to run in milliseconds. */ duration?: number; - /** * If specified, then buffers will be decoded to strings using the specified encoding. */ encoding?: string; - /** * When to stop the generation. */ end?: number | Date; - /** * One or multiple characters to print at the end of the file; only apply when objectMode is disabled. */ eof?: boolean | string; - /** * Generate buffers equals length as defined by the `highWaterMark` option. */ fixed_size?: boolean; fixedSize?: boolean; - /** * The maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource. */ high_water_mark?: number; highWaterMark?: number; - /** * Number of lines or records to generate. */ length?: number; - /** * Maximum number of characters per word. */ max_word_length?: number; maxWordLength?: number; - /** * Whether this stream should behave as a stream of objects. */ object_mode?: boolean objectMode?: boolean; - /** * One or multiple characters used to delimit records. */ row_delimiter?: string; - /** * Generate idempotent random characters if a number provided. */ seed?: boolean | number; - /** * The time to wait between the generation of each records */ diff --git a/packages/csv-generate/lib/sync.d.ts b/packages/csv-generate/lib/sync.d.ts index 66583b6ac..bc57dc568 100644 --- a/packages/csv-generate/lib/sync.d.ts +++ b/packages/csv-generate/lib/sync.d.ts @@ -2,6 +2,5 @@ import { Options } from './index'; declare function generate(options: number | Options): string & Array; - // export default generate; -export { generate }; +export { generate, Options }; diff --git a/packages/csv-generate/test/api.types.sync.ts b/packages/csv-generate/test/api.types.sync.ts new file mode 100644 index 000000000..48129049e --- /dev/null +++ b/packages/csv-generate/test/api.types.sync.ts @@ -0,0 +1,38 @@ + +import 'should' +import { generate, Options } from '../lib/sync.js' + +describe('API Types', () => { + + describe('usage', () => { + + it('sync with options as number', () => { + const generator: string = generateSync(1) + generator.should.be.a.String() + }) + + it('sync with options in string mode', () => { + const generator: string = generateSync({length: 1}) + generator.should.be.a.String() + }) + + it('sync with options in object mode', () => { + const generator: Array> = generateSync({length: 1, objectMode: true}) + generator.should.be.an.Array() + }) + }) + + describe('types', () => { + it('generate', () => { + const generator: string = generateSync(1) + return generator; + }) + it('Options', () => { + const options: Options = { + columns: 1 + } + return options; + }) + }) + +}) diff --git a/packages/csv-generate/test/api.types.ts b/packages/csv-generate/test/api.types.ts index 145184d5e..a78e8096b 100644 --- a/packages/csv-generate/test/api.types.ts +++ b/packages/csv-generate/test/api.types.ts @@ -1,7 +1,6 @@ import 'should' import { generate, Options, Generator } from '../lib/index.js' -import { generate as generateSync } from '../lib/sync.js' describe('API Types', () => { @@ -18,21 +17,6 @@ describe('API Types', () => { generate( {length: 1}, (err, records) => err || records ) }) - it('sync with options as number', () => { - const generator: string = generateSync(1) - generator.should.be.a.String() - }) - - it('sync with options in string mode', () => { - const generator: string = generateSync({length: 1}) - generator.should.be.a.String() - }) - - it('sync with options in object mode', () => { - const generator: Array> = generateSync({length: 1, objectMode: true}) - generator.should.be.an.Array() - }) - }) describe('Generator', () => { diff --git a/packages/csv-parse/dist/cjs/index.d.ts b/packages/csv-parse/dist/cjs/index.d.ts index c484d4511..e307d57c6 100644 --- a/packages/csv-parse/dist/cjs/index.d.ts +++ b/packages/csv-parse/dist/cjs/index.d.ts @@ -230,7 +230,6 @@ export interface Info { readonly invalid_field_length: number; } - export type CsvErrorCode = 'CSV_INVALID_OPTION_BOM' | 'CSV_INVALID_OPTION_CAST' diff --git a/packages/csv-parse/dist/cjs/sync.d.ts b/packages/csv-parse/dist/cjs/sync.d.ts index 5ff7490ba..c55842ced 100644 --- a/packages/csv-parse/dist/cjs/sync.d.ts +++ b/packages/csv-parse/dist/cjs/sync.d.ts @@ -2,6 +2,10 @@ import { Options } from './index'; declare function parse(input: Buffer | string, options?: Options): any; - // export default parse; export { parse }; + +export { + CastingContext, CastingFunction, CastingDateFunction, + ColumnOption, Options, Info, CsvErrorCode, CsvError +} from './index'; diff --git a/packages/csv-parse/dist/esm/index.d.ts b/packages/csv-parse/dist/esm/index.d.ts index c484d4511..e307d57c6 100644 --- a/packages/csv-parse/dist/esm/index.d.ts +++ b/packages/csv-parse/dist/esm/index.d.ts @@ -230,7 +230,6 @@ export interface Info { readonly invalid_field_length: number; } - export type CsvErrorCode = 'CSV_INVALID_OPTION_BOM' | 'CSV_INVALID_OPTION_CAST' diff --git a/packages/csv-parse/dist/esm/sync.d.ts b/packages/csv-parse/dist/esm/sync.d.ts index 5ff7490ba..c55842ced 100644 --- a/packages/csv-parse/dist/esm/sync.d.ts +++ b/packages/csv-parse/dist/esm/sync.d.ts @@ -2,6 +2,10 @@ import { Options } from './index'; declare function parse(input: Buffer | string, options?: Options): any; - // export default parse; export { parse }; + +export { + CastingContext, CastingFunction, CastingDateFunction, + ColumnOption, Options, Info, CsvErrorCode, CsvError +} from './index'; diff --git a/packages/csv-parse/lib/index.d.ts b/packages/csv-parse/lib/index.d.ts index c484d4511..e307d57c6 100644 --- a/packages/csv-parse/lib/index.d.ts +++ b/packages/csv-parse/lib/index.d.ts @@ -230,7 +230,6 @@ export interface Info { readonly invalid_field_length: number; } - export type CsvErrorCode = 'CSV_INVALID_OPTION_BOM' | 'CSV_INVALID_OPTION_CAST' diff --git a/packages/csv-parse/lib/sync.d.ts b/packages/csv-parse/lib/sync.d.ts index 5ff7490ba..c55842ced 100644 --- a/packages/csv-parse/lib/sync.d.ts +++ b/packages/csv-parse/lib/sync.d.ts @@ -2,6 +2,10 @@ import { Options } from './index'; declare function parse(input: Buffer | string, options?: Options): any; - // export default parse; export { parse }; + +export { + CastingContext, CastingFunction, CastingDateFunction, + ColumnOption, Options, Info, CsvErrorCode, CsvError +} from './index'; diff --git a/packages/csv-parse/test/api.types.sync.ts b/packages/csv-parse/test/api.types.sync.ts new file mode 100644 index 000000000..9a991969f --- /dev/null +++ b/packages/csv-parse/test/api.types.sync.ts @@ -0,0 +1,92 @@ + +import 'should' +import { + parse, + CastingContext, CastingFunction, CastingDateFunction, + ColumnOption, Options, Info, CsvErrorCode, CsvError +} from '../lib/sync.js' + +describe('API Types', () => { + + it('respect parse signature', () => { + // No argument + parse("") + parse("", {}) + parse(Buffer.from("")) + parse(Buffer.from(""), {}) + }) + + it('return records', () => { + try { + const data: object = parse("") + typeof data + }catch (err){ + if (err instanceof CsvError){ + err.message + } + } + }) + + it('Options', () => { + (options: Options) => { + const bom: boolean | undefined = options.bom; + return [bom] + } + }) + + it('CastingContext', () => { + const options: Options = { + cast: (value: string, context: CastingContext) => { + return `${value} ${context.index}` + } + } + return options; + }) + + it('CastingDateFunction', () => { + const castDate: CastingDateFunction = (value: string, context: CastingContext) => { + return new Date(`${value} ${context.index}`) + } + const options: Options = { + cast_date: castDate + } + return options; + }) + + it('CastingFunction', () => { + const cast: CastingFunction = (value: string, context: CastingContext) => { + return `${value} ${context.index}` + }; + const options: Options = { + cast: cast + }; + return options; + }) + + it('ColumnOption', () => { + const column: ColumnOption = {name: 'sth'}; + const options: Options = { + columns: [column] + } + return options; + }) + + it('CsvErrorCode', () => { + const err = new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', 'error'); + const code: CsvErrorCode = err.code; + return code; + }) + + it('Info', () => { + const info: Info = { + comment_lines: 1, + empty_lines: 1, + lines: 1, + records: 1, + bytes: 1, + invalid_field_length: 1, + }; + return info; + }) + +}) diff --git a/packages/csv-stringify/dist/cjs/sync.d.ts b/packages/csv-stringify/dist/cjs/sync.d.ts index 984b7b60e..3914a2928 100644 --- a/packages/csv-stringify/dist/cjs/sync.d.ts +++ b/packages/csv-stringify/dist/cjs/sync.d.ts @@ -5,3 +5,8 @@ declare function stringify(input: Input, options?: Options): string // export default stringify; export { stringify }; + +export { + RecordDelimiter, Cast, PlainObject, Input, ColumnOption, CastingContext, + Options +} from './index'; diff --git a/packages/csv-stringify/dist/esm/sync.d.ts b/packages/csv-stringify/dist/esm/sync.d.ts index 984b7b60e..3914a2928 100644 --- a/packages/csv-stringify/dist/esm/sync.d.ts +++ b/packages/csv-stringify/dist/esm/sync.d.ts @@ -5,3 +5,8 @@ declare function stringify(input: Input, options?: Options): string // export default stringify; export { stringify }; + +export { + RecordDelimiter, Cast, PlainObject, Input, ColumnOption, CastingContext, + Options +} from './index'; diff --git a/packages/csv-stringify/lib/sync.d.ts b/packages/csv-stringify/lib/sync.d.ts index 984b7b60e..3914a2928 100644 --- a/packages/csv-stringify/lib/sync.d.ts +++ b/packages/csv-stringify/lib/sync.d.ts @@ -5,3 +5,8 @@ declare function stringify(input: Input, options?: Options): string // export default stringify; export { stringify }; + +export { + RecordDelimiter, Cast, PlainObject, Input, ColumnOption, CastingContext, + Options +} from './index'; diff --git a/packages/csv-stringify/test/api.types.sync.ts b/packages/csv-stringify/test/api.types.sync.ts new file mode 100644 index 000000000..5d1593213 --- /dev/null +++ b/packages/csv-stringify/test/api.types.sync.ts @@ -0,0 +1,41 @@ + +import 'should' +import { + stringify, + RecordDelimiter, Cast, PlainObject, Input, + ColumnOption, CastingContext, +Options +} from '../lib/sync.js' + +describe('API Types', () => { + + it('stringify return string', () => { + const input: Input = [[1,2,3]]; + const stringifier: string = stringify(input) + stringifier + }) + + it('Options', () => { + (options: Options) => { + const rd: RecordDelimiter | undefined = options.record_delimiter + const cast = options.cast + const castBoolean : Cast | undefined = cast?.boolean + const columns: string[] | PlainObject | ColumnOption[] | undefined = options.columns + return [ + rd, castBoolean, columns + ] + } + }) + + it('CastingContext', () => { + const options: Options = { + cast: { + boolean: (value: boolean, context: CastingContext) => { + return `${value} ${context.index}` + } + } + } + return options + }) + +}) diff --git a/packages/csv/dist/cjs/index.d.ts b/packages/csv/dist/cjs/index.d.ts index dcf571e51..c9770f8df 100644 --- a/packages/csv/dist/cjs/index.d.ts +++ b/packages/csv/dist/cjs/index.d.ts @@ -6,4 +6,9 @@ import { parse } from 'csv-parse'; import { transform } from 'stream-transform'; import { stringify } from 'csv-stringify'; -export { generate, parse, transform, stringify } +export { generate, parse, transform, stringify }; + +export * as generator from 'csv-generate'; +export * as parser from 'csv-parse'; +export * as transformer from 'stream-transform'; +export * as stringifier from 'csv-stringify'; diff --git a/packages/csv/dist/cjs/sync.cjs b/packages/csv/dist/cjs/sync.cjs index f39bfef60..d0ae74a06 100644 --- a/packages/csv/dist/cjs/sync.cjs +++ b/packages/csv/dist/cjs/sync.cjs @@ -7075,7 +7075,7 @@ const stringify = function(records, options={}){ stringifier.write(record); } stringifier.end(); - stringifier.off('data', onData); + stringifier.removeListener('data', onData); return data.join(''); }; diff --git a/packages/csv/dist/cjs/sync.d.ts b/packages/csv/dist/cjs/sync.d.ts index 041d111e8..b1812592d 100644 --- a/packages/csv/dist/cjs/sync.d.ts +++ b/packages/csv/dist/cjs/sync.d.ts @@ -1,9 +1,14 @@ // Alias to the modules exposing the sync APIs -import { generate } from 'csv-generate/lib/sync' -import { parse } from 'csv-parse/lib/sync'; -import { transform } from 'stream-transform/lib/sync'; -import { stringify } from 'csv-stringify/lib/sync'; +import { generate } from 'csv-generate/sync' +import { parse } from 'csv-parse/sync'; +import { transform } from 'stream-transform/sync'; +import { stringify } from 'csv-stringify/sync'; -export {generate, parse, transform, stringify} +export { generate, parse, transform, stringify } + +export * as generator from 'csv-generate/sync'; +export * as parser from 'csv-parse/sync'; +export * as transformer from 'stream-transform/sync'; +export * as stringifier from 'csv-stringify/sync'; diff --git a/packages/csv/dist/esm/index.d.ts b/packages/csv/dist/esm/index.d.ts index dcf571e51..c9770f8df 100644 --- a/packages/csv/dist/esm/index.d.ts +++ b/packages/csv/dist/esm/index.d.ts @@ -6,4 +6,9 @@ import { parse } from 'csv-parse'; import { transform } from 'stream-transform'; import { stringify } from 'csv-stringify'; -export { generate, parse, transform, stringify } +export { generate, parse, transform, stringify }; + +export * as generator from 'csv-generate'; +export * as parser from 'csv-parse'; +export * as transformer from 'stream-transform'; +export * as stringifier from 'csv-stringify'; diff --git a/packages/csv/dist/esm/sync.d.ts b/packages/csv/dist/esm/sync.d.ts index 041d111e8..b1812592d 100644 --- a/packages/csv/dist/esm/sync.d.ts +++ b/packages/csv/dist/esm/sync.d.ts @@ -1,9 +1,14 @@ // Alias to the modules exposing the sync APIs -import { generate } from 'csv-generate/lib/sync' -import { parse } from 'csv-parse/lib/sync'; -import { transform } from 'stream-transform/lib/sync'; -import { stringify } from 'csv-stringify/lib/sync'; +import { generate } from 'csv-generate/sync' +import { parse } from 'csv-parse/sync'; +import { transform } from 'stream-transform/sync'; +import { stringify } from 'csv-stringify/sync'; -export {generate, parse, transform, stringify} +export { generate, parse, transform, stringify } + +export * as generator from 'csv-generate/sync'; +export * as parser from 'csv-parse/sync'; +export * as transformer from 'stream-transform/sync'; +export * as stringifier from 'csv-stringify/sync'; diff --git a/packages/csv/dist/esm/sync.js b/packages/csv/dist/esm/sync.js index 6910bbea6..d6732f08c 100644 --- a/packages/csv/dist/esm/sync.js +++ b/packages/csv/dist/esm/sync.js @@ -7071,7 +7071,7 @@ const stringify = function(records, options={}){ stringifier.write(record); } stringifier.end(); - stringifier.off('data', onData); + stringifier.removeListener('data', onData); return data.join(''); }; diff --git a/packages/csv/dist/iife/sync.js b/packages/csv/dist/iife/sync.js index 8404ffd57..781f3038c 100644 --- a/packages/csv/dist/iife/sync.js +++ b/packages/csv/dist/iife/sync.js @@ -7074,7 +7074,7 @@ var csv = (function (exports) { stringifier.write(record); } stringifier.end(); - stringifier.off('data', onData); + stringifier.removeListener('data', onData); return data.join(''); }; diff --git a/packages/csv/dist/umd/sync.js b/packages/csv/dist/umd/sync.js index 8ca0de95f..2a43d22ee 100644 --- a/packages/csv/dist/umd/sync.js +++ b/packages/csv/dist/umd/sync.js @@ -7077,7 +7077,7 @@ stringifier.write(record); } stringifier.end(); - stringifier.off('data', onData); + stringifier.removeListener('data', onData); return data.join(''); }; diff --git a/packages/csv/lib/index.d.ts b/packages/csv/lib/index.d.ts index dcf571e51..c9770f8df 100644 --- a/packages/csv/lib/index.d.ts +++ b/packages/csv/lib/index.d.ts @@ -6,4 +6,9 @@ import { parse } from 'csv-parse'; import { transform } from 'stream-transform'; import { stringify } from 'csv-stringify'; -export { generate, parse, transform, stringify } +export { generate, parse, transform, stringify }; + +export * as generator from 'csv-generate'; +export * as parser from 'csv-parse'; +export * as transformer from 'stream-transform'; +export * as stringifier from 'csv-stringify'; diff --git a/packages/csv/lib/sync.d.ts b/packages/csv/lib/sync.d.ts index 041d111e8..b1812592d 100644 --- a/packages/csv/lib/sync.d.ts +++ b/packages/csv/lib/sync.d.ts @@ -1,9 +1,14 @@ // Alias to the modules exposing the sync APIs -import { generate } from 'csv-generate/lib/sync' -import { parse } from 'csv-parse/lib/sync'; -import { transform } from 'stream-transform/lib/sync'; -import { stringify } from 'csv-stringify/lib/sync'; +import { generate } from 'csv-generate/sync' +import { parse } from 'csv-parse/sync'; +import { transform } from 'stream-transform/sync'; +import { stringify } from 'csv-stringify/sync'; -export {generate, parse, transform, stringify} +export { generate, parse, transform, stringify } + +export * as generator from 'csv-generate/sync'; +export * as parser from 'csv-parse/sync'; +export * as transformer from 'stream-transform/sync'; +export * as stringifier from 'csv-stringify/sync'; diff --git a/packages/csv/test/api.types.sync.ts b/packages/csv/test/api.types.sync.ts new file mode 100644 index 000000000..66aefcd4d --- /dev/null +++ b/packages/csv/test/api.types.sync.ts @@ -0,0 +1,56 @@ + +import 'should' +import csv, {generate, parse, stringify, transform} from '../lib/sync.js' + +describe('API Types', () => { + + describe('usage', () => { + + it('generate', () => { + // with options + handler + const output: string = generate(1); + return output; + }) + + it('parse', () => { + const output: string = parse(''); + return output; + }) + + it('stringify', () => { + const output: string = stringify([]); + return output; + }) + + it('transform', () => { + const output: any = transform([], () => {}); + return output; + }) + + }) + + describe('usage', () => { + + it('csv.generate', () => { + const options: csv.generator.Options = {} + return options; + }) + + it('csv.parse', () => { + const options: csv.parser.Options = {} + return options; + }) + + it('csv.stringifier', () => { + const options: csv.stringifier.Options = {} + return options; + }) + + it('csv.transform', () => { + const options: csv.transformer.Options = {} + return options; + }) + + }) + +}) diff --git a/packages/csv/test/api.types.ts b/packages/csv/test/api.types.ts index 7bf9243ff..cc7582ec9 100644 --- a/packages/csv/test/api.types.ts +++ b/packages/csv/test/api.types.ts @@ -1,6 +1,6 @@ import 'should' -import {generate, parse, stringify, transform} from '../lib/index.js' +import {generate, parse, parser, stringify, transform} from '../lib/index.js' describe('API Types', () => { diff --git a/packages/stream-transform/dist/cjs/sync.d.ts b/packages/stream-transform/dist/cjs/sync.d.ts index 38c64d86a..8d46042f9 100644 --- a/packages/stream-transform/dist/cjs/sync.d.ts +++ b/packages/stream-transform/dist/cjs/sync.d.ts @@ -1,9 +1,10 @@ /// -import {Options} from './index'; +import { Options } from './index'; export type Handler = (record: T) => U +// export default transform; export function transform(records: Array, handler: Handler): Array export function transform(records: Array, options: Options, handler: Handler): Array -export default transform; +export { Options }; diff --git a/packages/stream-transform/dist/esm/sync.d.ts b/packages/stream-transform/dist/esm/sync.d.ts index 38c64d86a..8d46042f9 100644 --- a/packages/stream-transform/dist/esm/sync.d.ts +++ b/packages/stream-transform/dist/esm/sync.d.ts @@ -1,9 +1,10 @@ /// -import {Options} from './index'; +import { Options } from './index'; export type Handler = (record: T) => U +// export default transform; export function transform(records: Array, handler: Handler): Array export function transform(records: Array, options: Options, handler: Handler): Array -export default transform; +export { Options }; diff --git a/packages/stream-transform/lib/sync.d.ts b/packages/stream-transform/lib/sync.d.ts index 38c64d86a..8d46042f9 100644 --- a/packages/stream-transform/lib/sync.d.ts +++ b/packages/stream-transform/lib/sync.d.ts @@ -1,9 +1,10 @@ /// -import {Options} from './index'; +import { Options } from './index'; export type Handler = (record: T) => U +// export default transform; export function transform(records: Array, handler: Handler): Array export function transform(records: Array, options: Options, handler: Handler): Array -export default transform; +export { Options }; diff --git a/packages/stream-transform/test/api.types.sync.ts b/packages/stream-transform/test/api.types.sync.ts new file mode 100644 index 000000000..8395c13f3 --- /dev/null +++ b/packages/stream-transform/test/api.types.sync.ts @@ -0,0 +1,24 @@ + +import 'should' +import { transform, Options } from '../lib/sync.js' + +describe('api.types', () => { + + it('sync', () => { + // With records + handler + const transformer: Array = transform( ['record'], record => record ) + transformer.should.be.an.Array() + // With records + options + handler + transform( ['record'], {consume: true}, record => record ) + }) + + it('Options', () => { + (options: Options) => { + const consume: boolean | undefined = options.consume; + const parallel: number | undefined = options.parallel + const params: number = options.params + return {consume, parallel, params} + } + }) + +}) diff --git a/packages/stream-transform/test/api.types.ts b/packages/stream-transform/test/api.types.ts index 76a8a44dd..6703617eb 100644 --- a/packages/stream-transform/test/api.types.ts +++ b/packages/stream-transform/test/api.types.ts @@ -1,7 +1,6 @@ import 'should' import { transform, Options, Transformer } from '../lib/index.js' -import { transform as transformSync } from '../lib/sync.js' describe('api.types', () => { @@ -22,14 +21,6 @@ describe('api.types', () => { // With records + options + handler + callback transform( ['record'], {consume: true}, record => record, (err, records) => err || records ) }) - - it('sync', () => { - // With records + handler - const transformer: Array = transformSync( ['record'], record => record ) - transformer.should.be.an.Array() - // With records + options + handler - transformSync( ['record'], {consume: true}, record => record ) - }) })