diff --git a/.npmrc b/.npmrc index 4fd15ed..43c97e7 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1 @@ package-lock=false -legacy-peer-deps=true diff --git a/lib/children-tree.ts b/lib/children-tree.ts index 0d0c899..274316d 100644 --- a/lib/children-tree.ts +++ b/lib/children-tree.ts @@ -36,6 +36,10 @@ export const build = (contract: Contract): object => { for (const type of contract.metadata.children.types) { if (contract.metadata.children.byType[type].size === 1) { const hash = setFirst(contract.metadata.children.byType[type]); + if (hash === undefined) { + throw new Error('Error retrieving child'); + } + const child = contract.getChildByHash(hash); if (child === undefined) { throw new Error('Error retrieving child'); diff --git a/lib/partials.ts b/lib/partials.ts index c3a8279..f8c3390 100644 --- a/lib/partials.ts +++ b/lib/partials.ts @@ -8,7 +8,7 @@ import Debug from 'debug'; import * as fs from 'fs'; import path from 'path'; import handlebars from 'handlebars'; -import asyncHelpers from 'handlebars-async-helpers'; +import promisedHandlebars from 'promised-handlebars'; import first from 'lodash/first'; import invokeMap from 'lodash/invokeMap'; import join from 'lodash/join'; @@ -30,7 +30,7 @@ import Contract from './contract'; import type { ContractObject } from './types/types'; import { cartesianProductWith, stripExtraBlankLines } from './utils'; -const hb = asyncHelpers(handlebars); +const hb = promisedHandlebars(handlebars); const debug = Debug('partials'); @@ -39,7 +39,7 @@ const debug = Debug('partials'); * @type {String} * @private */ -const REFERENCE_DELIMITER: string = '+'; +const REFERENCE_DELIMITER = '+'; /** * @summary Calculate the paths to search for a partial given a contract @@ -112,15 +112,23 @@ export const findPartial = ( range(options.structure.length, 1, -1), (accumulator, slice) => accumulator.concat(invokeMap(products, 'slice', 0, slice)), - [] as string[][], + [] as string[], ); - const fallbackPaths = combinations.reduce( + const fallbackPaths = combinations.reduce< + Array> + >( (accumulator, _, index, collection) => - map([map(collection, first), map(collection, last)], (list) => - take(list, index + 1), + map( + [ + // For some reason typescript does not infer correctly the return + // type of first + map(collection, first), + map(collection, last), + ], + (list) => take(list, index + 1), ).concat(accumulator), - [] as Array>, + [], ); return (products as Array>) diff --git a/lib/types/cuetypes.ts b/lib/types/cuetypes.ts index 76ea480..ad0af12 100644 --- a/lib/types/cuetypes.ts +++ b/lib/types/cuetypes.ts @@ -12,7 +12,7 @@ export interface components { type?: 'meta.blueprint'; layout?: components['schemas']['BlueprintLayout']; skeleton?: { [key: string]: any }; - } & { [key: string]: any }; + }; BlueprintLayout: { [key: string]: any }; Contract: { type: string; diff --git a/lib/utils.ts b/lib/utils.ts index 1237f4a..8cfe3af 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -82,7 +82,8 @@ export const setUnion = (set1: Set, set2: Set): Set => { * console.log(element) * > 'foo' */ -export const setFirst = (set1: Set): T => set1.values().next().value; +export const setFirst = (set1: Set): T | undefined => + set1.values().next().value; /** * @summary Map a set using an iteratee function diff --git a/package.json b/package.json index 9b61b3b..e25f9c2 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "doc": "typedoc --options ./typedoc.json", "lint": "balena-lint -t tsconfig.dev.json --typescript lib tests scripts", "lint-fix": "balena-lint -t tsconfig.dev.json --typescript --fix lib tests scripts", - "test:node": "mocha -r ts-node/register/transpile-only --reporter spec tests/**/*.spec.ts", + "test:node": "mocha -r ts-node/register/transpile-only --reporter spec \"tests/**/*.spec.ts\"", "test": "npm run build && npm run lint && npm run test:node", "test:fast": "npm run build && npm run test:node", "prepack": "npm run build" @@ -36,10 +36,10 @@ "dependencies": { "debug": "^3.2.6", "handlebars": "^4.7.8", - "handlebars-async-helpers": "^1.0.4", "js-combinatorics": "^0.5.5", "lodash": "^4.17.19", "object-hash": "^1.3.1", + "promised-handlebars": "^2.0.1", "semver": "^5.7.1", "skhema": "^5.3.2" }, @@ -63,12 +63,12 @@ "openapi-typescript": "^3.2.4", "rimraf": "^3.0.2", "ts-node": "^8.10.1", - "typedoc": "^0.23.28", - "typescript": "^4.9.5" + "typedoc": "^0.27.5", + "typescript": "^5.7.2" }, "engines": { - "node": "^20.0.0", - "npm": "^10.0.0" + "node": ">=20.0.0", + "npm": ">=10.0.0" }, "versionist": { "publishedAt": "2024-04-30T23:37:32.408Z" diff --git a/scripts/build-types.ts b/scripts/build-types.ts index 5b0fc8c..1ada3a6 100644 --- a/scripts/build-types.ts +++ b/scripts/build-types.ts @@ -32,4 +32,6 @@ const main = async () => { console.log(`Built types to ${output}`); }; -main().catch((err) => console.error(err)); +main().catch((err) => { + console.error(err); +}); diff --git a/typings/handlebars-async-helpers.d.ts b/typings/promised-handlebars.d.ts similarity index 72% rename from typings/handlebars-async-helpers.d.ts rename to typings/promised-handlebars.d.ts index b1d53c8..e2a100e 100644 --- a/typings/handlebars-async-helpers.d.ts +++ b/typings/promised-handlebars.d.ts @@ -1,4 +1,4 @@ -declare module 'handlebars-async-helpers' { +declare module 'promised-handlebars' { import type Handlebars from 'handlebars'; const fn: (hb: typeof Handlebars) => typeof Handlebars;