Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Update typescript and balena-lint
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
joshbwlng committed Sep 2, 2023
1 parent dcad25f commit b78a382
Show file tree
Hide file tree
Showing 47 changed files with 485 additions and 488 deletions.
1 change: 0 additions & 1 deletion lib/authorization/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const evaluateSchemaWithContext = (

for (const key of Object.keys(schema)) {
// For performance reasons
// eslint-disable-next-line lodash/prefer-lodash-typecheck
if (typeof schema[key] !== 'object') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/backend/postgres/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as textSearch from './jsonschema2sql/text-search';
import type { SearchFieldDef } from './types';
import * as utils from './utils';

// tslint:disable-next-line: no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version: coreVersion } = require('../../../package.json');

const CARDS_TABLE = 'cards';
Expand Down Expand Up @@ -749,7 +749,7 @@ export const parseFullTextSearchFields = (
) => {
const fields: SearchFieldDef[] = [];
const combinators = ['anyOf', 'allOf', 'oneOf'];
traverse(schema).forEach(function (_node) {
traverse(schema).forEach(function () {
if (
this.key === 'fullTextSearch' &&
this.node === true &&
Expand Down
13 changes: 7 additions & 6 deletions lib/backend/postgres/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { strict as nativeAssert } from 'assert';
import * as Bluebird from 'bluebird';
import * as fastEquals from 'fast-equals';
import * as _ from 'lodash';
import { strict as nativeAssert } from 'node:assert';
import { setTimeout } from 'node:timers/promises';
import { performance } from 'perf_hooks';
import { Pool, PoolClient } from 'pg';
import * as semver from 'semver';
Expand Down Expand Up @@ -30,7 +31,7 @@ import type {
import * as utils from './utils';
export type { StreamChange } from './streams';

// tslint:disable-next-line: no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version: coreVersion } = require('../../../package.json');

export const INDEX_TABLE = 'jf_indexes';
Expand Down Expand Up @@ -284,17 +285,17 @@ export class PostgresBackend implements Database {
*/
async connect(context: Context) {
const ourContext = new Context(context.getLogContext(), this);
while (true) {
let connected = false;
while (connected === false) {
try {
await this.tryConnect(ourContext);

return;
connected = true;
} catch (error: unknown) {
context.warn(
`Connection to database failed. Retrying in ${this.connectRetryDelay} milliseconds`,
{ error },
);
await Bluebird.delay(this.connectRetryDelay);
await setTimeout(this.connectRetryDelay);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/backend/postgres/jsonschema2sql/array-contains-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export class ArrayContainsFilter extends SqlFilter {
* @param {SqlPath} path - Path to be tested.
* @param {SqlFilter} filter - Filter to test elements against.
*/
constructor(public path: SqlPath, public filter: SqlFilter) {
constructor(
public path: SqlPath,
public filter: SqlFilter,
) {
super();

this.path = path.cloned();
Expand Down
1 change: 1 addition & 0 deletions lib/backend/postgres/jsonschema2sql/builder-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class BuilderContext {
});

// The `require` is here to break load-time circular dependencies
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { SqlFragmentBuilder } = require('./fragment-builder');
const linkCountStart = (this as any).linkCount;
this.pushTable(joinAlias);
Expand Down
11 changes: 9 additions & 2 deletions lib/backend/postgres/jsonschema2sql/equals-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export class EqualsFilter extends SqlFilter {
* @param {SqlPath} path - Path to be tested.
* @param {Array} values - Array of values to test `path` against.
*/
constructor(public path: SqlPath, public values: any[]) {
constructor(
public path: SqlPath,
public values: any[],
) {
super();

this.path = path.cloned();
Expand Down Expand Up @@ -66,7 +69,11 @@ export class EqualsFilter extends SqlFilter {
}

class IsEqualFilter extends SqlFilter {
constructor(public path: SqlPath, public asText: boolean, public value: any) {
constructor(
public path: SqlPath,
public asText: boolean,
public value: any,
) {
super();

this.path = path;
Expand Down
5 changes: 4 additions & 1 deletion lib/backend/postgres/jsonschema2sql/is-null-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export class IsNullFilter extends SqlFilter {
* @param {Boolean} isNull - Whether `path` must be `NULL`, or must not be
* `NULL`.
*/
constructor(public path: SqlPath, public isNull: boolean) {
constructor(
public path: SqlPath,
public isNull: boolean,
) {
super();

this.path = path.cloned();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export class IsOfJsonTypesFilter extends SqlFilter {
* @param {SqlPath} path - Path to be tested.
* @param {Array} types - Array of accepted JSON types.
*/
constructor(public path: SqlPath, public types: string[]) {
constructor(
public path: SqlPath,
public types: string[],
) {
super();

this.path = path.cloned();
Expand Down
5 changes: 4 additions & 1 deletion lib/backend/postgres/jsonschema2sql/link-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export class LinkFilter extends SqlFilter {
* @param {String} linkType - The link type.
* @param {SqlFilter} filter - Filter for the link.
*/
constructor(public linkType: string, public filter: SqlFilter) {
constructor(
public linkType: string,
public filter: SqlFilter,
) {
super();

this.linkType = linkType;
Expand Down
5 changes: 4 additions & 1 deletion lib/backend/postgres/jsonschema2sql/multiple-of-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export class MultipleOfFilter extends SqlFilter {
* @param {SqlPath} path - Path to be tested.
* @param {Number} multiple - A constant that `path` must be a multiple of.
*/
constructor(public path: SqlPath, public multiple: number) {
constructor(
public path: SqlPath,
public multiple: number,
) {
super();

this.path = path.cloned();
Expand Down
3 changes: 0 additions & 3 deletions lib/backend/postgres/jsonschema2sql/regexes.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { regex } from 'uuid-v4-regex';

export const format = {
// eslint-disable-next-line max-len
'uri-template':
'^(?:(?:[^\\x00-\\x20"\\\'<>%\\^`{|}]|%[0-9a-f]{2})|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$',
'uri-reference':
'^(?:(?:[a-z][a-z0-9+-.]*:)?\\/?\\/)?(?:[^\\\\s#][^\\s#]*)?(?:#[^\\\\s]*)?$',
'json-pointer': '^(?:/(?:[^~/]|~0|~1)*)*$',
email: '^\\S+@\\S+\\.\\S+$',
// eslint-disable-next-line max-len
'date-time':
'^\\d\\d\\d\\d-[0-1]\\d-[0-3]\\d[tT\\s](?:[0-2]\\d:[0-5]\\d:[0-5]\\d|23:59:60)(?:\\.\\d+)?(?:[zZ]|[+-]\\d\\d(?::\\d\\d)?)$',
uuid: regex.toString(),
Expand All @@ -20,6 +18,5 @@ export const format = {
ipv4: '^(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$',

// Optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
// eslint-disable-next-line max-len
ipv6: '^\\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(?:%.+)?\\s*$',
};
5 changes: 4 additions & 1 deletion lib/backend/postgres/jsonschema2sql/select-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ class BranchMap {
filter: ExpressionFilter;
seen: Set<string>;

constructor(map: { [key: string]: any }, public parent: SelectMap) {
constructor(
map: { [key: string]: any },
public parent: SelectMap,
) {
// We need this for `this.newBranch()`
this.parent = parent;
// Defaults to true as per the JSON schema spec
Expand Down
3 changes: 2 additions & 1 deletion lib/backend/postgres/jsonschema2sql/sql-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ export class SqlFilter {
*
* @param {Array} _list - Array to be filled with links, if any.
*/
// tslint:disable-next-line:no-empty
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
scrapLinksInto(_list: any) {}

/**
* Format this filter by pushing string fragments into `_builder`.
*
* @param {SqlFragmentBuilder} _builder - Builder for the final SQL string.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toSqlInto(_builder: any) {
throw new Error();
}
Expand Down
20 changes: 12 additions & 8 deletions lib/backend/postgres/jsonschema2sql/sql-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,6 @@ export class SqlQuery {
filter = new ValueIsFilter(this.path, '@>', value);
} else if (keyCount === 2 && 'type' in schema) {
const type = schema.type;
// eslint-disable-next-line valid-typeof
if (
typeof value === type ||
(type === 'integer' && _.isNumber(value))
Expand Down Expand Up @@ -1166,9 +1165,10 @@ export class SqlQuery {
schema,
this.options,
);
// tslint:disable-next-line: prefer-for-of
for (const _item of suffix) {
this.parentState.jsonPath?.pop();
if (Array.isArray(suffix) && suffix.length) {
suffix.forEach(() => {
this.parentState.jsonPath?.pop();
});
}
return query;
}
Expand Down Expand Up @@ -1198,8 +1198,10 @@ export class SqlQuery {
path: parentPath,
},
);
for (const _item of suffix) {
this.parentState.jsonPath?.pop();
if (Array.isArray(suffix) && suffix.length) {
suffix.forEach(() => {
this.parentState.jsonPath?.pop();
});
}
return query;
}
Expand All @@ -1223,8 +1225,10 @@ export class SqlQuery {
jsonPath: this.parentState.jsonPath,
},
);
for (const _item of suffix) {
this.parentState.jsonPath?.pop();
if (Array.isArray(suffix) && suffix.length) {
suffix.forEach(() => {
this.parentState.jsonPath?.pop();
});
}
return query;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/backend/postgres/links.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as _ from 'lodash';
import type { PostgresBackend } from '.';
import { Context } from '../../context';
import type { Contract, LinkContract } from '../../types';

// tslint:disable-next-line: no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version: coreVersion } = require('../../../package.json');

const LINK_TABLE = 'links2';
Expand Down
8 changes: 6 additions & 2 deletions lib/backend/postgres/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ export class Streamer {
private streams: { [id: string]: Stream } = {};
private notificationHandler: DatabaseNotificationHandler | null = null;

constructor(private context: Context, public table: string) {
constructor(
private context: Context,
public table: string,
) {
this.channel = `stream-${table}`;
this.notificationListener = this.notificationListener.bind(this);
}
Expand Down Expand Up @@ -353,7 +356,8 @@ export class Stream extends EventEmitter {
);
this.schema = schema;
this.traversesLinks =
typeof schema !== 'boolean' && schema.hasOwnProperty('$$links');
typeof schema !== 'boolean' &&
Object.prototype.hasOwnProperty.call(schema, '$$links');
}

public async push(payload: EventPayload) {
Expand Down
1 change: 0 additions & 1 deletion lib/backend/postgres/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const parseVersion = (version: string) => {
latest: true,
};
}
// eslint-disable-next-line max-len
const versionPattern =
/(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(-(?<prerelease>[0-9A-Za-z-]+))?(\+(?<build>[0-9A-Za-z-]+))?|(?<latest>latest)/;

Expand Down
8 changes: 4 additions & 4 deletions lib/cli/generate-contract-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const requireFromString = (code: string, filename: string = '') => {
const m = new Module(filename, parent);
m.filename = filename;

// @ts-expect-error
// @ts-expect-error - We have to reference the private _nodeModulePaths here
const paths: string[] = Module._nodeModulePaths(path.dirname(filename));
m.paths = paths;

// @ts-expect-error
// @ts-expect-error - We have to reference the private _compile here
m._compile(code, filename);

return m.exports;
Expand Down Expand Up @@ -57,11 +57,11 @@ export async function generateContractInterfaces(

const baseContractImports = `
// tslint:disable: array-type
import type { Contract, ContractDefinition } from '${
packageJson && packageJson.name === 'autumndb' ? '../' : 'autumndb'
}';
`;

// Compile TypeScript and read in contract definitions
Expand Down
1 change: 0 additions & 1 deletion lib/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { Command } from 'commander';
import * as fs from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
import { generateContractInterfaces } from './generate-contract-interfaces';

Expand Down
6 changes: 4 additions & 2 deletions lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ export class Context {
const options = { drop: true };
const endListener = () => {
options.drop = false;
end();
end().catch((err) => {
this.exception('Error while ending database listender:', err);
});
};
connection.on('end', endListener);

Expand Down Expand Up @@ -515,7 +517,7 @@ export enum TransactionIsolation {
* other modules so this is interface is empty and only useful for type
* checking.
*/
// tslint:disable-next-line:no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface PreparedStatement {}

class PgPreparedStatement implements PreparedStatement {
Expand Down
1 change: 0 additions & 1 deletion lib/contracts/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const card = {
type: 'string',

// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
// eslint-disable-next-line max-len
pattern:
'^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$',
},
Expand Down
2 changes: 1 addition & 1 deletion lib/contracts/mixins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { baseUiSchema } from './with-ui-schema';

export { uiSchemaDef } from './ui-schema-defs';

// tslint:disable-next-line: no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const deref = require('json-schema-deref-sync');

export const mergeWithUniqConcatArrays = (objValue: any, srcValue: any) => {
Expand Down
9 changes: 5 additions & 4 deletions lib/types/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ export interface Contract<
/**
* A summary of a contract, containing just the key fields.
*/
export interface ContractSummary<TData = ContractData>
extends Pick<Contract<TData>, 'id' | 'slug' | 'version' | 'type'> {}
export type ContractSummary<TData = ContractData> = Pick<
Contract<TData>,
'id' | 'slug' | 'version' | 'type'
>;

interface OptionalContract<TData = ContractData>
extends Partial<Contract<TData>> {}
export type OptionalContract<TData = ContractData> = Partial<Contract<TData>>;

/**
* Contracts are defined with certain required properties and various other optional properties.
Expand Down
Loading

0 comments on commit b78a382

Please sign in to comment.