diff --git a/lib/authorization/utils.ts b/lib/authorization/utils.ts index 4cea13580..2df68fdee 100644 --- a/lib/authorization/utils.ts +++ b/lib/authorization/utils.ts @@ -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; } diff --git a/lib/backend/postgres/cards.ts b/lib/backend/postgres/cards.ts index 9602a7add..7187f7120 100644 --- a/lib/backend/postgres/cards.ts +++ b/lib/backend/postgres/cards.ts @@ -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'; @@ -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 && diff --git a/lib/backend/postgres/index.ts b/lib/backend/postgres/index.ts index 9ae9eca53..f5e838045 100644 --- a/lib/backend/postgres/index.ts +++ b/lib/backend/postgres/index.ts @@ -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'; @@ -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'; @@ -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); } } } diff --git a/lib/backend/postgres/jsonschema2sql/array-contains-filter.ts b/lib/backend/postgres/jsonschema2sql/array-contains-filter.ts index 57366d3dc..84fe82d85 100644 --- a/lib/backend/postgres/jsonschema2sql/array-contains-filter.ts +++ b/lib/backend/postgres/jsonschema2sql/array-contains-filter.ts @@ -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(); diff --git a/lib/backend/postgres/jsonschema2sql/builder-context.ts b/lib/backend/postgres/jsonschema2sql/builder-context.ts index fe7d3f77b..f7bdc3f28 100644 --- a/lib/backend/postgres/jsonschema2sql/builder-context.ts +++ b/lib/backend/postgres/jsonschema2sql/builder-context.ts @@ -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); diff --git a/lib/backend/postgres/jsonschema2sql/equals-filter.ts b/lib/backend/postgres/jsonschema2sql/equals-filter.ts index ee8c5e26b..c60c8ea0f 100644 --- a/lib/backend/postgres/jsonschema2sql/equals-filter.ts +++ b/lib/backend/postgres/jsonschema2sql/equals-filter.ts @@ -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(); @@ -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; diff --git a/lib/backend/postgres/jsonschema2sql/is-null-filter.ts b/lib/backend/postgres/jsonschema2sql/is-null-filter.ts index 210b0ba23..a836ff689 100644 --- a/lib/backend/postgres/jsonschema2sql/is-null-filter.ts +++ b/lib/backend/postgres/jsonschema2sql/is-null-filter.ts @@ -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(); diff --git a/lib/backend/postgres/jsonschema2sql/is-of-json-types-filter.ts b/lib/backend/postgres/jsonschema2sql/is-of-json-types-filter.ts index 68454d042..53b11ac98 100644 --- a/lib/backend/postgres/jsonschema2sql/is-of-json-types-filter.ts +++ b/lib/backend/postgres/jsonschema2sql/is-of-json-types-filter.ts @@ -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(); diff --git a/lib/backend/postgres/jsonschema2sql/link-filter.ts b/lib/backend/postgres/jsonschema2sql/link-filter.ts index 505477597..636c745a7 100644 --- a/lib/backend/postgres/jsonschema2sql/link-filter.ts +++ b/lib/backend/postgres/jsonschema2sql/link-filter.ts @@ -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; diff --git a/lib/backend/postgres/jsonschema2sql/multiple-of-filter.ts b/lib/backend/postgres/jsonschema2sql/multiple-of-filter.ts index 29b859e22..d0fd938dd 100644 --- a/lib/backend/postgres/jsonschema2sql/multiple-of-filter.ts +++ b/lib/backend/postgres/jsonschema2sql/multiple-of-filter.ts @@ -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(); diff --git a/lib/backend/postgres/jsonschema2sql/regexes.ts b/lib/backend/postgres/jsonschema2sql/regexes.ts index 28706f9c8..ec36fefe6 100644 --- a/lib/backend/postgres/jsonschema2sql/regexes.ts +++ b/lib/backend/postgres/jsonschema2sql/regexes.ts @@ -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(), @@ -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*$', }; diff --git a/lib/backend/postgres/jsonschema2sql/select-map.ts b/lib/backend/postgres/jsonschema2sql/select-map.ts index 1f2484f72..a8801e68a 100644 --- a/lib/backend/postgres/jsonschema2sql/select-map.ts +++ b/lib/backend/postgres/jsonschema2sql/select-map.ts @@ -346,7 +346,10 @@ class BranchMap { filter: ExpressionFilter; seen: Set; - 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 diff --git a/lib/backend/postgres/jsonschema2sql/sql-filter.ts b/lib/backend/postgres/jsonschema2sql/sql-filter.ts index da8bb5e95..8260db17b 100644 --- a/lib/backend/postgres/jsonschema2sql/sql-filter.ts +++ b/lib/backend/postgres/jsonschema2sql/sql-filter.ts @@ -39,7 +39,7 @@ 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) {} /** @@ -47,6 +47,7 @@ export class SqlFilter { * * @param {SqlFragmentBuilder} _builder - Builder for the final SQL string. */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars toSqlInto(_builder: any) { throw new Error(); } diff --git a/lib/backend/postgres/jsonschema2sql/sql-query.ts b/lib/backend/postgres/jsonschema2sql/sql-query.ts index bbd59efa0..9b01f2384 100644 --- a/lib/backend/postgres/jsonschema2sql/sql-query.ts +++ b/lib/backend/postgres/jsonschema2sql/sql-query.ts @@ -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)) @@ -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; } @@ -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; } @@ -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; } diff --git a/lib/backend/postgres/links.ts b/lib/backend/postgres/links.ts index 86c84c555..538dd0873 100644 --- a/lib/backend/postgres/links.ts +++ b/lib/backend/postgres/links.ts @@ -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'; diff --git a/lib/backend/postgres/streams.ts b/lib/backend/postgres/streams.ts index 04463f4a2..58e817698 100644 --- a/lib/backend/postgres/streams.ts +++ b/lib/backend/postgres/streams.ts @@ -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); } @@ -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) { diff --git a/lib/backend/postgres/utils.ts b/lib/backend/postgres/utils.ts index 805f30a19..e870a8201 100644 --- a/lib/backend/postgres/utils.ts +++ b/lib/backend/postgres/utils.ts @@ -40,7 +40,6 @@ export const parseVersion = (version: string) => { latest: true, }; } - // eslint-disable-next-line max-len const versionPattern = /(?\d+)(\.(?\d+))?(\.(?\d+))?(-(?[0-9A-Za-z-]+))?(\+(?[0-9A-Za-z-]+))?|(?latest)/; diff --git a/lib/cli/generate-contract-interfaces.ts b/lib/cli/generate-contract-interfaces.ts index f2a77af2a..fb027b3c4 100644 --- a/lib/cli/generate-contract-interfaces.ts +++ b/lib/cli/generate-contract-interfaces.ts @@ -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; @@ -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 diff --git a/lib/cli/index.ts b/lib/cli/index.ts index 74372f493..ee97fe63d 100644 --- a/lib/cli/index.ts +++ b/lib/cli/index.ts @@ -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'; diff --git a/lib/context.ts b/lib/context.ts index 3bc6922f5..7336b146f 100644 --- a/lib/context.ts +++ b/lib/context.ts @@ -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); @@ -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 { diff --git a/lib/contracts/card.ts b/lib/contracts/card.ts index 1a7805ca8..92c9fe614 100644 --- a/lib/contracts/card.ts +++ b/lib/contracts/card.ts @@ -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-]+)*))?$', }, diff --git a/lib/contracts/mixins/index.ts b/lib/contracts/mixins/index.ts index 03124e168..3cfca5672 100644 --- a/lib/contracts/mixins/index.ts +++ b/lib/contracts/mixins/index.ts @@ -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) => { diff --git a/lib/types/contract.ts b/lib/types/contract.ts index a65dadaf8..acd8f7ccd 100644 --- a/lib/types/contract.ts +++ b/lib/types/contract.ts @@ -89,11 +89,12 @@ export interface Contract< /** * A summary of a contract, containing just the key fields. */ -export interface ContractSummary - extends Pick, 'id' | 'slug' | 'version' | 'type'> {} +export type ContractSummary = Pick< + Contract, + 'id' | 'slug' | 'version' | 'type' +>; -interface OptionalContract - extends Partial> {} +export type OptionalContract = Partial>; /** * Contracts are defined with certain required properties and various other optional properties. diff --git a/lib/types/contracts/authentication-oauth.ts b/lib/types/contracts/authentication-oauth.ts index 33dab6fce..00e75955c 100644 --- a/lib/types/contracts/authentication-oauth.ts +++ b/lib/types/contracts/authentication-oauth.ts @@ -19,8 +19,7 @@ export interface AuthenticationOauthData { [k: string]: unknown; } -export interface AuthenticationOauthContractDefinition - extends ContractDefinition {} +export type AuthenticationOauthContractDefinition = + ContractDefinition; -export interface AuthenticationOauthContract - extends Contract {} +export type AuthenticationOauthContract = Contract; diff --git a/lib/types/contracts/authentication-password.ts b/lib/types/contracts/authentication-password.ts index 69d08d6d3..43a0e76aa 100644 --- a/lib/types/contracts/authentication-password.ts +++ b/lib/types/contracts/authentication-password.ts @@ -14,8 +14,8 @@ export interface AuthenticationPasswordData { [k: string]: unknown; } -export interface AuthenticationPasswordContractDefinition - extends ContractDefinition {} +export type AuthenticationPasswordContractDefinition = + ContractDefinition; -export interface AuthenticationPasswordContract - extends Contract {} +export type AuthenticationPasswordContract = + Contract; diff --git a/lib/types/contracts/card.ts b/lib/types/contracts/card.ts index d82f17311..df7ac2227 100644 --- a/lib/types/contracts/card.ts +++ b/lib/types/contracts/card.ts @@ -12,6 +12,6 @@ export interface CardData { [k: string]: unknown; } -export interface CardContractDefinition extends ContractDefinition {} +export type CardContractDefinition = ContractDefinition; -export interface CardContract extends Contract {} +export type CardContract = Contract; diff --git a/lib/types/contracts/error.ts b/lib/types/contracts/error.ts index 885b7c01d..756caecf6 100644 --- a/lib/types/contracts/error.ts +++ b/lib/types/contracts/error.ts @@ -18,7 +18,6 @@ export interface ErrorData { [k: string]: unknown; } -export interface ErrorContractDefinition - extends ContractDefinition {} +export type ErrorContractDefinition = ContractDefinition; -export interface ErrorContract extends Contract {} +export type ErrorContract = Contract; diff --git a/lib/types/contracts/event.ts b/lib/types/contracts/event.ts index 7d00fdfd0..0312070d9 100644 --- a/lib/types/contracts/event.ts +++ b/lib/types/contracts/event.ts @@ -18,7 +18,6 @@ export interface EventData { [k: string]: unknown; } -export interface EventContractDefinition - extends ContractDefinition {} +export type EventContractDefinition = ContractDefinition; -export interface EventContract extends Contract {} +export type EventContract = Contract; diff --git a/lib/types/contracts/link.ts b/lib/types/contracts/link.ts index 9729fa8bc..64238afc2 100644 --- a/lib/types/contracts/link.ts +++ b/lib/types/contracts/link.ts @@ -25,6 +25,6 @@ export interface LinkData { [k: string]: unknown; } -export interface LinkContractDefinition extends ContractDefinition {} +export type LinkContractDefinition = ContractDefinition; -export interface LinkContract extends Contract {} +export type LinkContract = Contract; diff --git a/lib/types/contracts/loop.ts b/lib/types/contracts/loop.ts index 624ed2dd5..b7d4a792e 100644 --- a/lib/types/contracts/loop.ts +++ b/lib/types/contracts/loop.ts @@ -12,6 +12,6 @@ export interface LoopData { [k: string]: unknown; } -export interface LoopContractDefinition extends ContractDefinition {} +export type LoopContractDefinition = ContractDefinition; -export interface LoopContract extends Contract {} +export type LoopContract = Contract; diff --git a/lib/types/contracts/org.ts b/lib/types/contracts/org.ts index 0bd438be5..ab1a0dce3 100644 --- a/lib/types/contracts/org.ts +++ b/lib/types/contracts/org.ts @@ -16,6 +16,6 @@ export interface OrgData { [k: string]: unknown; } -export interface OrgContractDefinition extends ContractDefinition {} +export type OrgContractDefinition = ContractDefinition; -export interface OrgContract extends Contract {} +export type OrgContract = Contract; diff --git a/lib/types/contracts/relationship.ts b/lib/types/contracts/relationship.ts index f86217448..b12b8d123 100644 --- a/lib/types/contracts/relationship.ts +++ b/lib/types/contracts/relationship.ts @@ -23,7 +23,7 @@ export interface RelationshipData { [k: string]: unknown; } -export interface RelationshipContractDefinition - extends ContractDefinition {} +export type RelationshipContractDefinition = + ContractDefinition; -export interface RelationshipContract extends Contract {} +export type RelationshipContract = Contract; diff --git a/lib/types/contracts/role.ts b/lib/types/contracts/role.ts index 115d4af5d..4bbb9a65c 100644 --- a/lib/types/contracts/role.ts +++ b/lib/types/contracts/role.ts @@ -15,6 +15,6 @@ export interface RoleData { [k: string]: unknown; } -export interface RoleContractDefinition extends ContractDefinition {} +export type RoleContractDefinition = ContractDefinition; -export interface RoleContract extends Contract {} +export type RoleContract = Contract; diff --git a/lib/types/contracts/session.ts b/lib/types/contracts/session.ts index 61b19cbd4..f0b72f8cc 100644 --- a/lib/types/contracts/session.ts +++ b/lib/types/contracts/session.ts @@ -21,7 +21,6 @@ export interface SessionData { [k: string]: unknown; } -export interface SessionContractDefinition - extends ContractDefinition {} +export type SessionContractDefinition = ContractDefinition; -export interface SessionContract extends Contract {} +export type SessionContract = Contract; diff --git a/lib/types/contracts/type.ts b/lib/types/contracts/type.ts index cb4ae350b..9495bf551 100644 --- a/lib/types/contracts/type.ts +++ b/lib/types/contracts/type.ts @@ -23,6 +23,6 @@ export interface TypeData { [k: string]: unknown; } -export interface TypeContractDefinition extends ContractDefinition {} +export type TypeContractDefinition = ContractDefinition; -export interface TypeContract extends Contract {} +export type TypeContract = Contract; diff --git a/lib/types/contracts/user-settings.ts b/lib/types/contracts/user-settings.ts index 6f9125d60..a4474cbe6 100644 --- a/lib/types/contracts/user-settings.ts +++ b/lib/types/contracts/user-settings.ts @@ -49,7 +49,7 @@ export interface UserSettingsData { [k: string]: unknown; } -export interface UserSettingsContractDefinition - extends ContractDefinition {} +export type UserSettingsContractDefinition = + ContractDefinition; -export interface UserSettingsContract extends Contract {} +export type UserSettingsContract = Contract; diff --git a/lib/types/contracts/user.ts b/lib/types/contracts/user.ts index 152c7a809..8dc08822c 100644 --- a/lib/types/contracts/user.ts +++ b/lib/types/contracts/user.ts @@ -124,6 +124,6 @@ export interface InAMeeting { [k: string]: unknown; } -export interface UserContractDefinition extends ContractDefinition {} +export type UserContractDefinition = ContractDefinition; -export interface UserContract extends Contract {} +export type UserContract = Contract; diff --git a/lib/types/contracts/view.ts b/lib/types/contracts/view.ts index 2fdba60f2..bcdda963f 100644 --- a/lib/types/contracts/view.ts +++ b/lib/types/contracts/view.ts @@ -14,20 +14,20 @@ export interface ViewData { schema?: { [k: string]: unknown; }; - anyOf?: { + anyOf?: Array<{ name: string; schema: { type: 'object'; [k: string]: unknown; }; - }[]; - allOf?: { + }>; + allOf?: Array<{ name: string; schema: { type: 'object'; [k: string]: unknown; }; - }[]; + }>; /** * A list of data types this view can return */ @@ -35,6 +35,6 @@ export interface ViewData { [k: string]: unknown; } -export interface ViewContractDefinition extends ContractDefinition {} +export type ViewContractDefinition = ContractDefinition; -export interface ViewContract extends Contract {} +export type ViewContract = Contract; diff --git a/lib/types/json-schema.ts b/lib/types/json-schema.ts index 35867cdb5..72edf21d0 100644 --- a/lib/types/json-schema.ts +++ b/lib/types/json-schema.ts @@ -64,14 +64,6 @@ export type JsonSchema = [key: string]: JsonSchema; }; additionalProperties?: JsonSchema; - // These are not supported currently - /*patternProperties?: { - [key: string]: JsonSchema; - };*/ - /*dependencies?: { - [key: string]: JSONSchema | string[]; - };*/ - // propertyNames?: JsonSchema; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6 @@ -100,14 +92,6 @@ export type JsonSchema = // contentMediaType?: string; // contentEncoding?: string; - /** - * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9 - */ - // This is not supported currently - /*definitions?: { - [key: string]: JsonSchema; - };*/ - /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10 */ diff --git a/package.json b/package.json index 36b22b603..65b915f64 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "scripts": { "clean": "rimraf build", "build": "npm run clean && tsc -p tsconfig.build.json", - "lint": "npm run types && balena-lint lib test && deplint && prettier --check **/*.json **/*.yml", + "lint": "balena-lint lib test && deplint && prettier --check **/*.json **/*.yml", "lint:fix": "balena-lint --fix lib test && prettier -w **/*.json **/*.yml", "test": "npm run lint && npm run test:unit", "test:unit": "jest test/unit", @@ -77,7 +77,7 @@ "uuid-v4-regex": "^1.0.2" }, "devDependencies": { - "@balena/lint": "^6.2.2", + "@balena/lint": "^7.0.2", "@json-schema-org/tests": "^2.0.0", "@types/bluebird": "^3.5.38", "@types/jest": "^29.5.0", @@ -97,7 +97,7 @@ "simple-git-hooks": "^2.9.0", "ts-jest": "^29.0.5", "ts-node": "^10.9.1", - "typescript": "^5.0.3" + "typescript": "^5.2.2" }, "simple-git-hooks": { "pre-commit": "npx lint-staged" diff --git a/test/integration/backend/index.spec.ts b/test/integration/backend/index.spec.ts index 6c20ee31b..0d9009abc 100644 --- a/test/integration/backend/index.spec.ts +++ b/test/integration/backend/index.spec.ts @@ -1109,19 +1109,19 @@ describe('backend', () => { const expected = [ { indexname: `${typeContract.slug}__name__idx`, - indexdef: `CREATE INDEX \"${typeContract.slug}__name__idx\" ON public.${CONTRACTS_TABLE} USING btree (name) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, + indexdef: `CREATE INDEX "${typeContract.slug}__name__idx" ON public.${CONTRACTS_TABLE} USING btree (name) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, }, { indexname: `${typeContract.slug}__data_payload_message__idx`, - indexdef: `CREATE INDEX \"${typeContract.slug}__data_payload_message__idx\" ON public.${CONTRACTS_TABLE} USING btree (((data #>> '{payload,message}'::text[]))) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, + indexdef: `CREATE INDEX "${typeContract.slug}__data_payload_message__idx" ON public.${CONTRACTS_TABLE} USING btree (((data #>> '{payload,message}'::text[]))) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, }, { indexname: `${typeContract.slug}__data_payload_mentionsUser__idx`, - indexdef: `CREATE INDEX \"${typeContract.slug}__data_payload_mentionsUser__idx\" ON public.${CONTRACTS_TABLE} USING gin (((data #> '{payload,mentionsUser}'::text[]))) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, + indexdef: `CREATE INDEX "${typeContract.slug}__data_payload_mentionsUser__idx" ON public.${CONTRACTS_TABLE} USING gin (((data #> '{payload,mentionsUser}'::text[]))) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, }, { indexname: `${typeContract.slug}__data_from_id__name__data_to_id__idx`, - indexdef: `CREATE INDEX \"test-link__data_from_id__name__data_to_id__idx\" ON public.${CONTRACTS_TABLE} USING btree (((data #>> '{from,id}'::text[])), name, ((data #>> '{to,id}'::text[]))) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, + indexdef: `CREATE INDEX "test-link__data_from_id__name__data_to_id__idx" ON public.${CONTRACTS_TABLE} USING btree (((data #>> '{from,id}'::text[])), name, ((data #>> '{to,id}'::text[]))) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, }, ]; @@ -1194,11 +1194,11 @@ describe('backend', () => { const expected = [ { indexname: `${typeContract.slug}__name__search_idx`, - indexdef: `CREATE INDEX \"${typeContract.slug}__name__search_idx\" ON public.${CONTRACTS_TABLE} USING gin (to_tsvector('english'::regconfig, name)) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, + indexdef: `CREATE INDEX "${typeContract.slug}__name__search_idx" ON public.${CONTRACTS_TABLE} USING gin (to_tsvector('english'::regconfig, name)) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, }, { indexname: `${typeContract.slug}__data_payload_message__search_idx`, - indexdef: `CREATE INDEX \"${typeContract.slug}__data_payload_message__search_idx\" ON public.${CONTRACTS_TABLE} USING gin (jsonb_to_tsvector('english'::regconfig, (data #> '{payload,message}'::text[]), '["string"]'::jsonb)) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, + indexdef: `CREATE INDEX "${typeContract.slug}__data_payload_message__search_idx" ON public.${CONTRACTS_TABLE} USING gin (jsonb_to_tsvector('english'::regconfig, (data #> '{payload,message}'::text[]), '["string"]'::jsonb)) WHERE (type = '${typeContract.slug}@${typeContract.version}'::text)`, }, ]; @@ -4738,14 +4738,14 @@ describe('backend', () => { }, ); - const result = await new Promise(async (resolve, reject) => { + const result = await new Promise((resolve, reject) => { emitter.on('data', (change) => { resolve(change); }); emitter.on('error', reject); - Bluebird.all([ + Promise.all([ ctx.backend.insertElement(ctx.context, { type: 'foo@1.0.0', version: '1.0.0', @@ -4782,7 +4782,9 @@ describe('backend', () => { test: randString, }, }), - ]); + ]).catch((err) => { + throw err; + }); }); expect(result.type).toBe('insert'); @@ -4871,7 +4873,7 @@ describe('backend', () => { }, }); - const result = await new Promise(async (resolve, reject) => { + const result = await new Promise((resolve, reject) => { emitter.on('data', (change) => { if (change.type === 'insert') { return; @@ -4882,42 +4884,50 @@ describe('backend', () => { emitter.on('error', reject); - await ctx.backend.upsertElement(ctx.context, { - slug: slug1, - version: '1.0.0', - tags: [], - loop: null, - links: {}, - markers: [], - requires: [], - capabilities: [], - created_at: new Date().toISOString(), - updated_at: null, - linked_at: {}, - active: true, - type: 'foo@1.0.0', - data: { - test: 2, - }, - }); - await ctx.backend.upsertElement(ctx.context, { - slug: slug2, - active: true, - version: '1.0.0', - links: {}, - tags: [], - loop: null, - markers: [], - requires: [], - capabilities: [], - created_at: new Date().toISOString(), - updated_at: null, - linked_at: {}, - type: 'bar@1.0.0', - data: { - test: 2, - }, - }); + ctx.backend + .upsertElement(ctx.context, { + slug: slug1, + version: '1.0.0', + tags: [], + loop: null, + links: {}, + markers: [], + requires: [], + capabilities: [], + created_at: new Date().toISOString(), + updated_at: null, + linked_at: {}, + active: true, + type: 'foo@1.0.0', + data: { + test: 2, + }, + }) + .catch((err) => { + throw err; + }); + ctx.backend + .upsertElement(ctx.context, { + slug: slug2, + active: true, + version: '1.0.0', + links: {}, + tags: [], + loop: null, + markers: [], + requires: [], + capabilities: [], + created_at: new Date().toISOString(), + updated_at: null, + linked_at: {}, + type: 'bar@1.0.0', + data: { + test: 2, + }, + }) + .catch((err) => { + throw err; + }); }); expect(result.type).toBe('update'); @@ -4987,7 +4997,7 @@ describe('backend', () => { }, }); - const result = await new Promise(async (resolve, reject) => { + const result = await new Promise((resolve, reject) => { emitter.on('data', (change) => { // Livefeeds are asynchronous and can pick up a change a // moment after the insertion, so there exist the @@ -5004,24 +5014,28 @@ describe('backend', () => { emitter.on('error', reject); - await ctx.backend.upsertElement(ctx.context, { - slug, - active: true, - version: '1.0.0', - links: {}, - tags: [], - loop: null, - markers: [], - requires: [], - capabilities: [], - linked_at: {}, - created_at: new Date().toISOString(), - updated_at: null, - type: 'foo@1.0.0', - data: { - test: new Array(5000).join('bazbuzz'), - }, - }); + ctx.backend + .upsertElement(ctx.context, { + slug, + active: true, + version: '1.0.0', + links: {}, + tags: [], + loop: null, + markers: [], + requires: [], + capabilities: [], + linked_at: {}, + created_at: new Date().toISOString(), + updated_at: null, + type: 'foo@1.0.0', + data: { + test: new Array(5000).join('bazbuzz'), + }, + }) + .catch((err) => { + throw err; + }); }); expect(result.type).toBe('update'); @@ -5056,6 +5070,9 @@ describe('backend', () => { emitter.on('error', done); emitter.on('closed', done); emitter.close(); + }) + .catch((err) => { + throw err; }); }); @@ -5112,7 +5129,7 @@ describe('backend', () => { }, }); - const result = await new Promise(async (resolve, reject) => { + const result = await new Promise((resolve, reject) => { emitter.on('data', (change) => { resolve(change); emitter.close(); @@ -5120,24 +5137,28 @@ describe('backend', () => { emitter.on('error', reject); - await ctx.backend.upsertElement(ctx.context, { - slug, - active: true, - links: {}, - version: '1.0.0', - tags: [], - loop: null, - markers: [], - requires: [], - capabilities: [], - linked_at: {}, - created_at: new Date().toISOString(), - updated_at: null, - type: 'foo@1.0.0', - data: { - test: 1, - }, - }); + ctx.backend + .upsertElement(ctx.context, { + slug, + active: true, + links: {}, + version: '1.0.0', + tags: [], + loop: null, + markers: [], + requires: [], + capabilities: [], + linked_at: {}, + created_at: new Date().toISOString(), + updated_at: null, + type: 'foo@1.0.0', + data: { + test: 1, + }, + }) + .catch((err) => { + throw err; + }); }); expect(result.after).toEqual({ @@ -5206,7 +5227,7 @@ describe('backend', () => { }, }); - const result = await new Promise(async (resolve, reject) => { + const result = await new Promise((resolve, reject) => { emitter.on('data', (change) => { // Livefeeds are asynchronous and can pick up a change a // moment after the insertion, so there exist the @@ -5223,25 +5244,29 @@ describe('backend', () => { emitter.on('error', reject); - await ctx.backend.upsertElement(ctx.context, { - slug, - version: '1.0.0', - tags: [], - loop: null, - links: {}, - markers: [], - requires: [], - capabilities: [], - created_at: new Date().toISOString(), - linked_at: {}, - updated_at: null, - active: true, - type: 'foo@1.0.0', - data: { - test: 2, - extra: true, - }, - }); + ctx.backend + .upsertElement(ctx.context, { + slug, + version: '1.0.0', + tags: [], + loop: null, + links: {}, + markers: [], + requires: [], + capabilities: [], + created_at: new Date().toISOString(), + linked_at: {}, + updated_at: null, + active: true, + type: 'foo@1.0.0', + data: { + test: 2, + extra: true, + }, + }) + .catch((err) => { + throw err; + }); }); expect(result).toEqual({ diff --git a/test/integration/backend/postgres/jsonschema2sql/index.spec.ts b/test/integration/backend/postgres/jsonschema2sql/index.spec.ts index 806e9f8f3..8823bdff7 100644 --- a/test/integration/backend/postgres/jsonschema2sql/index.spec.ts +++ b/test/integration/backend/postgres/jsonschema2sql/index.spec.ts @@ -1886,59 +1886,53 @@ describe('jsonschema2sql: Postgres specific', () => { for (const [name, testCases] of Object.entries(reqoptTestCases)) { for (const [idx, testCase] of testCases.cases.entries()) { - testFn( - `schema ${name} - ${testCase.required.desc}`, - /* eslint-disable no-loop-func */ - async () => { - const table = ['reqopt', name, idx] - .join('_') - .replace(/ /g, '_') - .replace(/`/g, ''); - - const schema: JsonSchema = { - properties: { - data: { - properties: {}, - }, - }, - }; - const required = testCase.required.value; - if (required.length > 0) { - // TS-TODO: Its weird that `data` has to be cast to "any" here - (schema.properties!.data as any).required = required; - } - if ('actor' in testCases) { - (schema.properties!.data as any).properties.actor = - testCases.actor; - } - if ('other' in testCases) { - (schema.properties!.data as any).properties.other = - testCases.other; - } + testFn(`schema ${name} - ${testCase.required.desc}`, async () => { + const table = ['reqopt', name, idx] + .join('_') + .replace(/ /g, '_') + .replace(/`/g, ''); - const elements = [ - { - slug: 'test-1', - type: 'contract', - data: { - actor: actorContents, - }, + const schema: JsonSchema = { + properties: { + data: { + properties: {}, }, - ]; + }, + }; + const required = testCase.required.value; + if (required.length > 0) { + // TS-TODO: Its weird that `data` has to be cast to "any" here + (schema.properties!.data as any).required = required; + } + if ('actor' in testCases) { + (schema.properties!.data as any).properties.actor = testCases.actor; + } + if ('other' in testCases) { + (schema.properties!.data as any).properties.other = testCases.other; + } - const results = await runner({ - context: ctx.context, - backend: ctx.backend, - database: ctx.database, - table, - elements, - schema, - }); + const elements = [ + { + slug: 'test-1', + type: 'contract', + data: { + actor: actorContents, + }, + }, + ]; + + const results = await runner({ + context: ctx.context, + backend: ctx.backend, + database: ctx.database, + table, + elements, + schema, + }); - // TODO: This check is vulnerable to errors where the results length is greater than 1 - expect(results.length === 1).toBe(testCase.valid); - }, - ); + // TODO: This check is vulnerable to errors where the results length is greater than 1 + expect(results.length === 1).toBe(testCase.valid); + }); } } diff --git a/test/integration/backend/postgres/streams/index.spec.ts b/test/integration/backend/postgres/streams/index.spec.ts index 2ec062bc3..1b8a8d8c2 100644 --- a/test/integration/backend/postgres/streams/index.spec.ts +++ b/test/integration/backend/postgres/streams/index.spec.ts @@ -164,33 +164,4 @@ describe('streams', () => { })(), ).resolves.not.toThrow(); }); - - // TODO: this is not done in the stream code anymore - /*it('should automatically reconnect on disconnect', async () => { - // Set up backend, which comes with its own stream client - const testBackend = new PostgresBackend( - null, - { - user: environment.postgres.user, - database: ctx.database, - password: environment.postgres.password, - host: environment.postgres.host, - port: environment.postgres.port, - }, - ); - - await testBackend.connect(ctx.context); - - // Disconnect client from database without using streams.disconnect(), - // simulating an unexpected client end event. - await testBackend.streamClient!.connection!.done(true); - - // Use the stream client to query database, after giving a little time to reconnect. - await Bluebird.delay(backend.connectRetryDelay); - const result = await testBackend.streamClient!.connection!.client.query( - `SELECT id FROM ${ctx.table} LIMIT 1`, - ); - - expect(result).toBeTruthy(); - });*/ }); diff --git a/test/integration/context.spec.ts b/test/integration/context.spec.ts index 228979ea0..8684d9d6a 100644 --- a/test/integration/context.spec.ts +++ b/test/integration/context.spec.ts @@ -104,11 +104,6 @@ describe('Context', () => { ).toEqual([{ id: id1 }]); }); - it.skip('should be able to perform a serialized transaction', async () => { - // TODO: not sure how to reliably force a serialization error with - // the `Context`'s interface - }); - it('should rollback if an exception is thrown inside the callback', async () => { const id = randomUUID(); try { @@ -122,7 +117,7 @@ describe('Context', () => { `, [id], ); - throw 0; + throw new Error('Dummy error for test'); }, ); } catch { @@ -187,25 +182,18 @@ describe('Context', () => { await context.withTransaction( TransactionIsolation.Snapshot, async (transactionContext1: Context) => { - await transactionContext1.runQuery( - ` - INSERT INTO test - VALUES ($1) - `, - [id1], - ); + await transactionContext1.runQuery('INSERT INTO test VALUES ($1)', [ + id1, + ]); try { await transactionContext1.withTransaction( TransactionIsolation.Snapshot, async (transactionContext2: Context) => { await transactionContext2.runQuery( - ` - INSERT INTO test - VALUES ($1) - `, + 'INSERT INTO test VALUES ($1)', [id2], ); - throw 0; + throw new Error('Test error'); }, ); } catch { @@ -215,51 +203,10 @@ describe('Context', () => { ); expect( - await context.query( - ` - SELECT id - FROM test - WHERE id IN ($1, $2) - `, - [id1, id2], - ), - ).toEqual([{ id: id1 }]); - }); - - it.skip('should serialize unawaited queries', async () => { - const id1 = randomUUID(); - const id2 = randomUUID(); - context.runQuery( - ` - INSERT INTO test - VALUES ($1) - `, - [id1], - ); - context.runQuery( - ` - INSERT INTO test - VALUES ($1) - `, - [id2], - ); - await context.runQuery( - ` - DELETE FROM test - WHERE id = $1 - `, - [id2], - ); - - expect( - await context.query( - ` - SELECT id - FROM test - WHERE id IN ($1, $2) - `, - [id1, id2], - ), + await context.query('SELECT id FROM test WHERE id IN ($1, $2)', [ + id1, + id2, + ]), ).toEqual([{ id: id1 }]); }); }); diff --git a/test/integration/kernel.link.spec.ts b/test/integration/kernel.link.spec.ts index be2189747..59a7abf0c 100644 --- a/test/integration/kernel.link.spec.ts +++ b/test/integration/kernel.link.spec.ts @@ -1,5 +1,4 @@ import { strict as assert } from 'assert'; -import * as _ from 'lodash'; import { randomUUID } from 'node:crypto'; import { errors, testUtils } from '../../lib'; import { createRelationships } from './create-relationships'; diff --git a/test/integration/kernel.spec.ts b/test/integration/kernel.spec.ts index 491dc56db..5faede566 100644 --- a/test/integration/kernel.spec.ts +++ b/test/integration/kernel.spec.ts @@ -1,4 +1,3 @@ -/* tslint:disable no-floating-promises */ import { strict as assert } from 'assert'; import * as _ from 'lodash'; import { randomUUID } from 'node:crypto'; @@ -4141,7 +4140,7 @@ describe('Kernel', () => { type: 'card@1.0.0', tags: ['foo'], data: { - number: 1, + bar: 1, }, }, ); @@ -4152,7 +4151,7 @@ describe('Kernel', () => { { type: 'card@1.0.0', data: { - number: 1, + bar: 1, }, }, ); @@ -4172,12 +4171,12 @@ describe('Kernel', () => { data: { type: 'object', properties: { - number: { + bar: { type: 'number', const: 1, }, }, - required: ['number'], + required: ['bar'], }, }, required: ['data'], @@ -4212,7 +4211,7 @@ describe('Kernel', () => { { tags: ['foo'], data: { - number: 1, + bar: 1, }, }, ]); @@ -4226,7 +4225,7 @@ describe('Kernel', () => { type: 'card@1.0.0', data: { thread: true, - number: 1, + bar: 1, }, }, ); @@ -4337,7 +4336,7 @@ describe('Kernel', () => { type: 'card@1.0.0', data: { thread: true, - number: 1, + bar: 1, }, }, ); @@ -4349,7 +4348,7 @@ describe('Kernel', () => { type: 'card@1.0.0', data: { thread: true, - number: 2, + bar: 2, }, }, ); @@ -4505,7 +4504,7 @@ describe('Kernel', () => { type: 'card@1.0.0', data: { thread: true, - number: 1, + bar: 1, }, }, ); @@ -4517,7 +4516,7 @@ describe('Kernel', () => { type: 'card@1.0.0', data: { thread: true, - number: 2, + bar: 2, }, }, ); @@ -4529,7 +4528,7 @@ describe('Kernel', () => { type: 'card@1.0.0', data: { thread: true, - number: 3, + bar: 3, }, }, ); diff --git a/test/integration/kernel.stream.spec.ts b/test/integration/kernel.stream.spec.ts index 15b960542..e12dc6891 100644 --- a/test/integration/kernel.stream.spec.ts +++ b/test/integration/kernel.stream.spec.ts @@ -81,17 +81,20 @@ describe('Kernel', () => { emitter.close(); }); - ctx.kernel.insertContract( - ctx.logContext, - ctx.kernel.adminSession()!, - { + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { slug, type: 'card@1.0.0', data: { test: 1, }, - }, - ); + }) + .catch((err) => { + throw err; + }); + }) + .catch((err) => { + throw err; }); }); @@ -152,29 +155,32 @@ describe('Kernel', () => { emitter.on('error', done); emitter.on('closed', done); - ctx.kernel.insertContract( - ctx.logContext, - ctx.kernel.adminSession()!, - { + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { slug, type: 'card@1.0.0', version: '1.0.0', data: { test: 1, }, - }, - ); + }) + .catch((err) => { + throw err; + }); - ctx.kernel.insertContract( - ctx.logContext, - ctx.kernel.adminSession()!, - { + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { type: 'card@1.0.0', data: { test: 2, }, - }, - ); + }) + .catch((err) => { + throw err; + }); + }) + .catch((err) => { + throw err; }); }); @@ -299,7 +305,7 @@ describe('Kernel', () => { }, ); - const result = await new Promise(async (resolve, reject) => { + const result = await new Promise((resolve, reject) => { emitter.on('data', (change) => { emitter.close(); resolve(change); @@ -307,19 +313,27 @@ describe('Kernel', () => { emitter.on('error', reject); - ctx.kernel.insertContract(ctx.logContext, ctx.kernel.adminSession()!, { - type: 'card@1.0.0', - data: { - test: 1, - }, - }); - ctx.kernel.insertContract(ctx.logContext, ctx.kernel.adminSession()!, { - slug, - type: 'card@1.0.0', - data: { - email: 'johndoe@example.com', - }, - }); + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { + type: 'card@1.0.0', + data: { + test: 1, + }, + }) + .catch((err) => { + throw err; + }); + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { + slug, + type: 'card@1.0.0', + data: { + email: 'johndoe@example.com', + }, + }) + .catch((err) => { + throw err; + }); }); expect(result.after).toEqual({ @@ -439,6 +453,9 @@ describe('Kernel', () => { emitter.on('error', done); emitter.on('closed', done); emitter.close(); + }) + .catch((err) => { + throw err; }); }); @@ -475,18 +492,21 @@ describe('Kernel', () => { emitter.on('error', done); emitter.on('closed', done); - ctx.kernel.insertContract( - ctx.logContext, - ctx.kernel.adminSession()!, - { + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { slug, active: false, type: 'card@1.0.0', data: { test: 2, }, - }, - ); + }) + .catch((err) => { + throw err; + }); + }) + .catch((err) => { + throw err; }); }); @@ -569,7 +589,7 @@ describe('Kernel', () => { }, ); - const result = await new Promise(async (resolve, reject) => { + const result = await new Promise((resolve, reject) => { emitter.on('data', (change) => { emitter.close(); resolve(change); @@ -577,18 +597,22 @@ describe('Kernel', () => { emitter.on('error', reject); - await ctx.kernel.patchContractBySlug( - ctx.logContext, - ctx.kernel.adminSession()!, - `${contract1.slug}@${contract1.version}`, - [ - { - op: 'replace', - path: '/data/test', - value: 3, - }, - ], - ); + ctx.kernel + .patchContractBySlug( + ctx.logContext, + ctx.kernel.adminSession()!, + `${contract1.slug}@${contract1.version}`, + [ + { + op: 'replace', + path: '/data/test', + value: 3, + }, + ], + ) + .catch((err) => { + throw err; + }); }); expect(result.after).toEqual({ @@ -670,22 +694,26 @@ describe('Kernel', () => { emitter.on('error', reject); - ctx.kernel.insertContract(ctx.logContext, ctx.kernel.adminSession()!, { - slug: `link-${contract1.slug}-is-attached-to-${contract2.slug}`, - type: 'link@1.0.0', - name: 'is attached to', - data: { - inverseName: 'has attached element', - from: { - id: contract1.id, - type: contract1.type, - }, - to: { - id: contract2.id, - type: contract2.type, + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { + slug: `link-${contract1.slug}-is-attached-to-${contract2.slug}`, + type: 'link@1.0.0', + name: 'is attached to', + data: { + inverseName: 'has attached element', + from: { + id: contract1.id, + type: contract1.type, + }, + to: { + id: contract2.id, + type: contract2.type, + }, }, - }, - }); + }) + .catch((err) => { + throw err; + }); }); expect(result.after).toEqual({ @@ -814,7 +842,7 @@ describe('Kernel', () => { }, ); - const result = await new Promise(async (resolve, reject) => { + const result = await new Promise((resolve, reject) => { emitter.on('data', (change) => { resolve(change.after); }); @@ -822,21 +850,25 @@ describe('Kernel', () => { emitter.on('error', reject); // Insert a second link between contract 1 and contract 3 - this should trigger a stream update - ctx.kernel.insertContract(ctx.logContext, ctx.kernel.adminSession()!, { - type: 'link@1.0.0', - name: 'is attached to', - data: { - inverseName: 'has attached element', - from: { - id: contract1.id, - type: contract1.type, - }, - to: { - id: contract3.id, - type: contract3.type, + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { + type: 'link@1.0.0', + name: 'is attached to', + data: { + inverseName: 'has attached element', + from: { + id: contract1.id, + type: contract1.type, + }, + to: { + id: contract3.id, + type: contract3.type, + }, }, - }, - }); + }) + .catch((err) => { + throw err; + }); }); // Link data can come in an indeterminate sort order, so we sort it here for convenience @@ -959,18 +991,25 @@ describe('Kernel', () => { emitter.on('error', done); emitter.on('closed', done); - ctx.kernel.patchContractBySlug( - ctx.logContext, - ctx.kernel.adminSession()!, - `${contract2.slug}@${contract1.version}`, - [ - { - op: 'replace', - path: '/data/test', - value: 3, - }, - ], - ); + ctx.kernel + .patchContractBySlug( + ctx.logContext, + ctx.kernel.adminSession()!, + `${contract2.slug}@${contract1.version}`, + [ + { + op: 'replace', + path: '/data/test', + value: 3, + }, + ], + ) + .catch((err) => { + throw err; + }); + }) + .catch((err) => { + throw err; }); }); @@ -1273,25 +1312,29 @@ describe('Kernel', () => { }, ); - const result: any = await new Promise(async (resolve, reject) => { + const result: any = await new Promise((resolve, reject) => { stream.on('data', (change) => { resolve(change); }); stream.on('error', reject); - ctx.kernel.patchContractBySlug( - ctx.logContext, - ctx.kernel.adminSession()!, - `${contract2.slug}@${contract2.version}`, - [ - { - op: 'replace', - path: '/data/test', - value: 3, - }, - ], - ); + ctx.kernel + .patchContractBySlug( + ctx.logContext, + ctx.kernel.adminSession()!, + `${contract2.slug}@${contract2.version}`, + [ + { + op: 'replace', + path: '/data/test', + value: 3, + }, + ], + ) + .catch((err) => { + throw err; + }); }); expect(result.id).toEqual(contract1.id); @@ -1339,26 +1382,34 @@ describe('Kernel', () => { }, ); - ctx.kernel.insertContract(ctx.logContext, ctx.kernel.adminSession()!, { - slug, - type: 'card@1.0.0', - version: '1.0.0', - data: { - test: 1, - }, - }); + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { + slug, + type: 'card@1.0.0', + version: '1.0.0', + data: { + test: 1, + }, + }) + .catch((err) => { + throw err; + }); - ctx.kernel.insertContract(ctx.logContext, ctx.kernel.adminSession()!, { - type: 'card@1.0.0', - data: { - test: 2, - }, - }); + ctx.kernel + .insertContract(ctx.logContext, ctx.kernel.adminSession()!, { + type: 'card@1.0.0', + data: { + test: 2, + }, + }) + .catch((err) => { + throw err; + }); await delay(1); await ctx.kernel.disconnect(ctx.logContext); - await emitter.close(); + emitter.close(); }); }); });