From 2a9a4d9043c86742cfd2e2316cac54e13daab20d Mon Sep 17 00:00:00 2001 From: Vitaliy Artemov Date: Sat, 24 Feb 2024 12:04:57 +0000 Subject: [PATCH] csv: add declarations --- package-lock.json | 4 ++-- package.json | 2 +- src/builtin/csv/Csv.d.ts | 38 ++++++++++++++++++++++++++++++++ src/builtin/csv/CsvOptions.d.ts | 21 ++++++++++++++++++ src/builtin/csv/CsvReadable.d.ts | 3 +++ src/builtin/csv/CsvWritable.d.ts | 3 +++ src/builtin/csv/index.d.ts | 3 +++ src/builtin/index.d.ts | 2 +- src/csv.d.ts | 1 + 9 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 src/builtin/csv/Csv.d.ts create mode 100644 src/builtin/csv/CsvOptions.d.ts create mode 100644 src/builtin/csv/CsvReadable.d.ts create mode 100644 src/builtin/csv/CsvWritable.d.ts create mode 100644 src/builtin/csv/index.d.ts create mode 100644 src/csv.d.ts diff --git a/package-lock.json b/package-lock.json index 30bea1d..91c2d06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tarantoolscript", - "version": "0.5.3", + "version": "0.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tarantoolscript", - "version": "0.5.3", + "version": "0.6.0", "license": "MIT", "dependencies": { "@typescript-to-lua/language-extensions": "^1.19.0", diff --git a/package.json b/package.json index c40673e..38d3d76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tarantoolscript", - "version": "0.5.3", + "version": "0.6.0", "author": "Vitaliy Artemov olivera507224@yandex.ru", "description": "TypeScript definitions for Tarantool Lua API.", "repository": { diff --git a/src/builtin/csv/Csv.d.ts b/src/builtin/csv/Csv.d.ts new file mode 100644 index 0000000..6517762 --- /dev/null +++ b/src/builtin/csv/Csv.d.ts @@ -0,0 +1,38 @@ +/** @noSelfInFile */ + +import { CsvOptions } from './CsvOptions'; +import { CsvReadable } from './CsvReadable'; +import { CsvWritable } from './CsvWritable'; + +/** + * Get CSV-formatted input from `readable` and return a table as output. + * Usually `readable` is either a string or a file opened for reading. + * Usually `options` is not specified. + * @param readable A string, or any object which has a `read()` method, formatted according to the CSV rules. + * @param options An options table. + * @returns Table - loaded value. + */ +export declare function load(readable: CsvReadable, options?: CsvOptions): unknown[]; + +/** + * Get table input from `csv-table` and return a CSV-formatted string as output. + * Or, get table input from `csv-table` and put the output in `writable`. + * Usually `options` is not specified. + * Usually `writable`, if specified, is a file opened for writing. + * `csv.dump()` is the reverse of `csv.load()`. + * @param csvTable A table which can be formatted according to the CSV rules. + * @param options An options table. + * @param writable Any object which has a `write()` method. + * @returns String, which is written to `writable` if specified. + */ +export declare function dump(csvTable: unknown[], options?: CsvOptions): string; +export declare function dump(csvTable: unknown[], options?: CsvOptions, writable: CsvWritable): void; + +/** + * Form a Lua iterator function for going through CSV records one field at a time. + * Use of an iterator is strongly recommended if the amount of data is large (ten or more megabytes). + * @param input A string, or any object which has a `read()` method, formatted according to che CSV rules. + * @param options An options table. + * @returns Lua iterator. + */ +export declare function iterate(input: CsvReadable, options?: CsvOptions): LuaIterable> diff --git a/src/builtin/csv/CsvOptions.d.ts b/src/builtin/csv/CsvOptions.d.ts new file mode 100644 index 0000000..0920de6 --- /dev/null +++ b/src/builtin/csv/CsvOptions.d.ts @@ -0,0 +1,21 @@ +export interface CsvOptions { + /** + * Single-byte character to designate end-of-field. + */ + delimiter?: string; + + /** + * Single-byte character to designate encloser of string. + */ + quote_char?: string; + + /** + * Number of characters to read at once (usually for file-IO efficiency). + */ + chunk_size?: number; + + /** + * Number of lines to skip at the start (usually for a header). + */ + skip_head_lines?: number; +} diff --git a/src/builtin/csv/CsvReadable.d.ts b/src/builtin/csv/CsvReadable.d.ts new file mode 100644 index 0000000..ac8561d --- /dev/null +++ b/src/builtin/csv/CsvReadable.d.ts @@ -0,0 +1,3 @@ +export type CsvReadable = + | string + | { read(): unknown } diff --git a/src/builtin/csv/CsvWritable.d.ts b/src/builtin/csv/CsvWritable.d.ts new file mode 100644 index 0000000..07aa0ab --- /dev/null +++ b/src/builtin/csv/CsvWritable.d.ts @@ -0,0 +1,3 @@ +export interface CsvWritable { + write(...args: unknown[]): unknown; +} diff --git a/src/builtin/csv/index.d.ts b/src/builtin/csv/index.d.ts new file mode 100644 index 0000000..c26c1d5 --- /dev/null +++ b/src/builtin/csv/index.d.ts @@ -0,0 +1,3 @@ +export * from './CsvOptions'; +export * from './CsvReadable'; +export * from './CsvWritable'; diff --git a/src/builtin/index.d.ts b/src/builtin/index.d.ts index de71356..0758860 100644 --- a/src/builtin/index.d.ts +++ b/src/builtin/index.d.ts @@ -4,7 +4,6 @@ /** @todo config https://www.tarantool.io/en/doc/latest/reference/reference_lua/config/ */ /** @todo console https://www.tarantool.io/en/doc/latest/reference/reference_lua/console/ */ /** @todo crypto https://www.tarantool.io/en/doc/latest/reference/reference_lua/crypto/ */ -/** @todo csv https://www.tarantool.io/en/doc/latest/reference/reference_lua/csv/ */ /** @todo datetime https://www.tarantool.io/en/doc/latest/reference/reference_lua/datetime/ */ /** @todo decimal https://www.tarantool.io/en/doc/latest/reference/reference_lua/decimal/ */ /** @todo digest https://www.tarantool.io/en/doc/latest/reference/reference_lua/digest/ */ @@ -39,6 +38,7 @@ export * from './box'; export * from './buffer'; +export * from './csv'; export * from './log'; export * from './msgpack'; export * from './package'; diff --git a/src/csv.d.ts b/src/csv.d.ts new file mode 100644 index 0000000..e4fdc58 --- /dev/null +++ b/src/csv.d.ts @@ -0,0 +1 @@ +export * from './builtin/csv/Csv';