Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Repository maintenance #74

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package-lock=false
legacy-peer-deps=true
4 changes: 4 additions & 0 deletions lib/children-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(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');
Expand Down
24 changes: 16 additions & 8 deletions lib/partials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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');

Expand All @@ -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
Expand Down Expand Up @@ -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<Array<string | undefined>>
>(
(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<string[], string | undefined>(collection, first),
map(collection, last),
],
(list) => take(list, index + 1),
).concat(accumulator),
[] as Array<Array<string | undefined>>,
[],
);

return (products as Array<Array<string | undefined>>)
Expand Down
2 changes: 1 addition & 1 deletion lib/types/cuetypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint @typescript-eslint/no-empty-interface: 0 */

Check warning on line 1 in lib/types/cuetypes.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

This rule requires the `strictNullChecks` compiler option to be turned on to function correctly

Check warning on line 1 in lib/types/cuetypes.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

This rule requires the `strictNullChecks` compiler option to be turned on to function correctly

Check warning on line 1 in lib/types/cuetypes.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

This rule requires the `strictNullChecks` compiler option to be turned on to function correctly

Check warning on line 1 in lib/types/cuetypes.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

This rule requires the `strictNullChecks` compiler option to be turned on to function correctly

Check warning on line 1 in lib/types/cuetypes.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

This rule requires the `strictNullChecks` compiler option to be turned on to function correctly
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
Expand All @@ -12,7 +12,7 @@
type?: 'meta.blueprint';
layout?: components['schemas']['BlueprintLayout'];
skeleton?: { [key: string]: any };
} & { [key: string]: any };
};
BlueprintLayout: { [key: string]: any };
Contract: {
type: string;
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export const setUnion = <T>(set1: Set<T>, set2: Set<T>): Set<T> => {
* console.log(element)
* > 'foo'
*/
export const setFirst = <T>(set1: Set<T>): T => set1.values().next().value;
export const setFirst = <T>(set1: Set<T>): T | undefined =>
set1.values().next().value;

/**
* @summary Map a set using an iteratee function
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
"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"
},
"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"
},
Expand All @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading