Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some typescript errors #346

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
"postbuild": "tsc",
"preperf": "npm run build",
"perf": "TZ=America/Los_Angeles tape 'perf/**/*-perf.js'",
"perf-windows": "SET TZ=America/Los_Angeles && tape perf/**/*-perf.js",
"lint": "eslint src test --ext .js",
"test": "TZ=America/Los_Angeles tape 'test/**/*-test.js' --require esm",
"test-windows": "SET TZ=America/Los_Angeles && tape test/**/*-test.js --require esm",
"prepublishOnly": "npm test && npm run lint && npm run build"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/arrow/arrow-column.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const isListType = type => isList(type) || isFixedSizeList(type);

/**
* Create an Arquero column that proxies access to an Arrow column.
* @param {object} arrow An Apache Arrow column.
* @param {object} vector An Apache Arrow column.
* @return {import('../table/column').ColumnType} An Arquero-compatible column.
*/
export default function arrowColumn(vector, nested) {
Expand Down
3 changes: 2 additions & 1 deletion src/arrow/encode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import isFunction from '../../util/is-function';
* @property {number} [limit=Infinity] The maximum number of rows to include.
* @property {number} [offset=0] The row offset indicating how many initial
* rows to skip.
* @property {string[]|(data: object) => string[]} [columns] Ordered list of
* @property {string[]|((data: object) => string[])} [columns] Ordered list of
* column names to include. If function-valued, the function should accept
* a dataset as input and return an array of column name strings.
* @property {object} [types] The Arrow data types to use. If specified,
Expand Down Expand Up @@ -45,6 +45,7 @@ export default function(data, options = {}) {
cols[name] = col;
});
const T = table();
// @ts-ignore
return new T(cols);
}

Expand Down
7 changes: 4 additions & 3 deletions src/arrow/encode/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ function infer(p) {
return Type.Float64;
}
else if (p.bigints === valid) {
const v = -p.min > p.max ? -p.min - 1n : p.max;
// eslint-disable-next-line no-undef
const v = -p.min > p.max ? BigInt(-p.min) - 1n : p.max;
return p.min < 0
? v < 2 ** 63 ? Type.Int64
? v < 2n ** 63n ? Type.Int64
: error(`BigInt exceeds 64 bits: ${v}`)
: p.max < 2 ** 64 ? Type.Uint64
: p.max < 2n ** 64n ? Type.Uint64
: error(`BigInt exceeds 64 bits: ${p.max}`);
}
else if (p.bools === valid) {
Expand Down
7 changes: 5 additions & 2 deletions src/engine/reduce/field-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ export default function(oplist, stream) {
const { ops, output } = expand(oplist, stream);
const fields = oplist[0].fields;
const n = fields.length;

if (n > 2 ) {
error('Unsupported field count: ' + n);
}
const cls = n === 0 ? FieldReducer
: n === 1 ? Field1Reducer
: n === 2 ? Field2Reducer
: error('Unsupported field count: ' + n);
: Field2Reducer;
return new cls(fields, ops, output, stream);
}

Expand Down
2 changes: 2 additions & 0 deletions src/engine/window/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const peersValue = op => !!op.peers;
function windowOp(spec) {
const { id, name, fields = [], params = [] } = spec;
const op = getWindow(name).create(...params);
// @ts-ignore
if (fields.length) op.get = fields[0];
// @ts-ignore
op.id = id;
return op;
}
Expand Down
9 changes: 8 additions & 1 deletion src/expression/parse-expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import isArray from '../util/is-array';
import isNumber from '../util/is-number';
import toString from '../util/to-string';

const PARSER_OPT = { ecmaVersion: 11 };
const PARSER_OPT = {
/**
* @type {import('acorn').ecmaVersion}
*/
ecmaVersion: 11
};
const DEFAULT_PARAM_ID = '$';
const DEFAULT_TUPLE_ID = 'd';
const DEFAULT_TUPLE_ID1 = 'd1';
Expand Down Expand Up @@ -93,8 +98,10 @@ function parseAST(expr) {
const code = expr.field ? fieldRef(expr)
: isArray(expr) ? toString(expr)
: expr;
// @ts-ignore
return parse(`expr=(${code})`, PARSER_OPT).body[0].expression.right;
} catch (err) {
// @ts-ignore
error(`Expression parse error: ${expr+''}`, err);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/expression/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function(input, opt = {}) {

// return expression asts if requested
if (opt.ast) {
return { names, exprs };
return { names, exprs, ops: [] };
}

// compile input field accessors
Expand Down
2 changes: 1 addition & 1 deletion src/expression/rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const dictOps = {
* @param {object} col The actual table column instance.
* @param {object} op Parent AST node operating on the column reference.
*/
export default function(ref, name, index = 0, col, op) {
export default function(ref, name, index = 0, col = 0, op = 0) {
ref.type = Column;
ref.name = name;
ref.table = index;
Expand Down
2 changes: 1 addition & 1 deletion src/format/from-arrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ColumnTable from '../table/column-table';
* @param {ArrowOptions} options Options for Arrow import.
* @return {ColumnTable} A new table containing the imported values.
*/
export default function(arrow, options = {}) {
export default function(arrow, options = {columns: undefined}) {
if (arrow && !arrow.batches) {
arrow = fromIPC()(arrow);
}
Expand Down
2 changes: 1 addition & 1 deletion src/format/from-fixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function(text, options = {}) {
);
}

function positions({ positions, widths }) {
function positions({ positions = undefined, widths = undefined }) {
if (!positions && !widths) {
error('Fixed width files require a "positions" or "widths" option');
}
Expand Down
2 changes: 1 addition & 1 deletion src/format/from-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import isString from '../util/is-string';
* The data payload can also be provided as the "data" property of an
* enclosing object, with an optional "schema" property containing table
* metadata such as a "fields" array of ordered column information.
* @param {string|object} data A string in JSON format, or pre-parsed object.
* @param {string|object} json A string in JSON format, or pre-parsed object.
* @param {JSONParseOptions} options The formatting options.
* @return {ColumnTable} A new table containing the parsed values.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/format/parse/parse-delimited.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import error from '../../util/error';
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

export default function(text, { delimiter = ',', skip, comment }) {
export default function(text, { delimiter = ',', skip = undefined, comment = undefined }) {
if (delimiter.length !== 1) {
error(`Text "delimiter" should be a single character, found "${delimiter}"`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/format/parse/parse-lines.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NEWLINE, RETURN } from './constants';
import filter from './text-filter';

export default function(text, { skip, comment }) {
export default function(text, { skip = undefined, comment = undefined }) {
let N = text.length;
let I = 0; // current character index

Expand Down
2 changes: 1 addition & 1 deletion src/format/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import isFunction from '../util/is-function';
* Column format options. The object keys should be column names.
* The object values should be formatting functions or objects.
* If specified, these override any automatically inferred options.
* @typedef {Object.<string, import('./value').ValueFormatOptions} ColumnFormatOptions
* @typedef {Object.<string, import('./value').ValueFormatOptions>} ColumnFormatOptions
*/

/**
Expand Down
4 changes: 4 additions & 0 deletions src/format/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,29 @@ import isTypedArray from '../util/is-typed-array';
*/
export default function(v, options = {}) {
if (isFunction(options)) {
// @ts-ignore
return options(v) + '';
}

const type = typeof v;

if (type === 'object') {
if (isDate(v)) {
// @ts-ignore
return options.utc ? formatUTCDate(v) : formatDate(v);
} else {
const s = JSON.stringify(
v,
(k, v) => isTypedArray(v) ? Array.from(v) : v
);
// @ts-ignore
const maxlen = options.maxlen || 30;
return s.length > maxlen
? s.slice(0, 28) + '\u2026' + (s[0] === '[' ? ']' : '}')
: s;
}
} else if (type === 'number') {
// @ts-ignore
const digits = options.digits || 0;
let a;
return v !== 0 && ((a = Math.abs(v)) >= 1e18 || a < Math.pow(10, -digits))
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export function range(start, end) {
export function matches(pattern) {
if (isString(pattern)) pattern = RegExp(escapeRegExp(pattern));
return decorate(
// @ts-ignore
table => table.columnNames(name => pattern.test(name)),
// @ts-ignore
() => ({ matches: [pattern.source, pattern.flags] })
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const internal = {
};

// export public API
import pkg from '../package.json';
import * as pkg from '../package.json';
export const version = pkg.version;
export { seed } from './util/random';
export { default as fromArrow } from './format/from-arrow';
Expand Down
12 changes: 6 additions & 6 deletions src/op/functions/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const t = d => (
* @param {number} [minutes=0] The minute within the hour.
* @param {number} [seconds=0] The second within the minute.
* @param {number} [milliseconds=0] The milliseconds within the second.
* @return {date} The resuting Date value.
* @return {Date} The resuting Date value.
*/
function datetime(year, month, date, hours, minutes, seconds, milliseconds) {
return !arguments.length
Expand All @@ -48,7 +48,7 @@ function datetime(year, month, date, hours, minutes, seconds, milliseconds) {
* @param {number} [minutes=0] The minute within the hour.
* @param {number} [seconds=0] The second within the minute.
* @param {number} [milliseconds=0] The milliseconds within the second.
* @return {date} The resuting Date value.
* @return {Date} The resuting Date value.
*/
function utcdatetime(year, month, date, hours, minutes, seconds, milliseconds) {
return !arguments.length
Expand All @@ -71,14 +71,14 @@ function dayofyear(date) {
t0.setMonth(0);
t0.setDate(1);
const tz = (t1.getTimezoneOffset() - t0.getTimezoneOffset()) * msMinute;
return Math.floor(1 + ((t1 - t0) - tz) / msDay);
return Math.floor(1 + ((t1.valueOf() - t0.valueOf()) - tz) / msDay);
}

function utcdayofyear(date) {
t1.setTime(+date);
t1.setUTCHours(0, 0, 0, 0);
const t0 = Date.UTC(t1.getUTCFullYear(), 0, 1);
return Math.floor(1 + (t1 - t0) / msDay);
return Math.floor(1 + (t1.valueOf() - t0) / msDay);
}

function week(date, firstday) {
Expand All @@ -92,7 +92,7 @@ function week(date, firstday) {
t0.setDate(1 - (t0.getDay() + 7 - i) % 7);
t0.setHours(0, 0, 0, 0);
const tz = (t1.getTimezoneOffset() - t0.getTimezoneOffset()) * msMinute;
return Math.floor((1 + (t1 - t0) - tz) / msWeek);
return Math.floor((1 + (t1.valueOf() - t0.valueOf()) - tz) / msWeek);
}

function utcweek(date, firstday) {
Expand All @@ -105,7 +105,7 @@ function utcweek(date, firstday) {
t0.setUTCDate(1);
t0.setUTCDate(1 - (t0.getUTCDay() + 7 - i) % 7);
t0.setUTCHours(0, 0, 0, 0);
return Math.floor((1 + (t1 - t0)) / msWeek);
return Math.floor((1 + (t1.valueOf() - t0.valueOf())) / msWeek);
}

export default {
Expand Down
4 changes: 2 additions & 2 deletions src/op/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function hasWindow(name) {
/**
* Get an aggregate function definition.
* @param {string} name The name of the aggregate function.
* @return {AggregateDef} The aggregate function definition,
* @return {import('./aggregate-functions').AggregateDef} The aggregate function definition,
* or undefined if not found.
*/
export function getAggregate(name) {
Expand All @@ -49,7 +49,7 @@ export function getAggregate(name) {
/**
* Get a window function definition.
* @param {string} name The name of the window function.
* @return {WindowDef} The window function definition,
* @return {import('./window-functions').WindowDef} The window function definition,
* or undefined if not found.
*/
export function getWindow(name) {
Expand Down
1 change: 1 addition & 0 deletions src/op/op-api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import functions from './functions';
import op from './op';

Expand Down
Loading