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 Aug 27, 2023
1 parent 7b87951 commit 06e033e
Show file tree
Hide file tree
Showing 43 changed files with 435 additions and 415 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
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
19 changes: 12 additions & 7 deletions lib/backend/postgres/jsonschema2sql/sql-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,9 +1166,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 +1199,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 +1226,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
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
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
7 changes: 3 additions & 4 deletions lib/types/contracts/authentication-oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export interface AuthenticationOauthData {
[k: string]: unknown;
}

export interface AuthenticationOauthContractDefinition
extends ContractDefinition<AuthenticationOauthData> {}
export type AuthenticationOauthContractDefinition =
ContractDefinition<AuthenticationOauthData>;

export interface AuthenticationOauthContract
extends Contract<AuthenticationOauthData> {}
export type AuthenticationOauthContract = Contract<AuthenticationOauthData>;
8 changes: 4 additions & 4 deletions lib/types/contracts/authentication-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export interface AuthenticationPasswordData {
[k: string]: unknown;
}

export interface AuthenticationPasswordContractDefinition
extends ContractDefinition<AuthenticationPasswordData> {}
export type AuthenticationPasswordContractDefinition =
ContractDefinition<AuthenticationPasswordData>;

export interface AuthenticationPasswordContract
extends Contract<AuthenticationPasswordData> {}
export type AuthenticationPasswordContract =
Contract<AuthenticationPasswordData>;
4 changes: 2 additions & 2 deletions lib/types/contracts/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export interface CardData {
[k: string]: unknown;
}

export interface CardContractDefinition extends ContractDefinition<CardData> {}
export type CardContractDefinition = ContractDefinition<CardData>;

export interface CardContract extends Contract<CardData> {}
export type CardContract = Contract<CardData>;
5 changes: 2 additions & 3 deletions lib/types/contracts/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface ErrorData {
[k: string]: unknown;
}

export interface ErrorContractDefinition
extends ContractDefinition<ErrorData> {}
export type ErrorContractDefinition = ContractDefinition<ErrorData>;

export interface ErrorContract extends Contract<ErrorData> {}
export type ErrorContract = Contract<ErrorData>;
5 changes: 2 additions & 3 deletions lib/types/contracts/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface EventData {
[k: string]: unknown;
}

export interface EventContractDefinition
extends ContractDefinition<EventData> {}
export type EventContractDefinition = ContractDefinition<EventData>;

export interface EventContract extends Contract<EventData> {}
export type EventContract = Contract<EventData>;
Loading

0 comments on commit 06e033e

Please sign in to comment.