Skip to content

Commit

Permalink
refactor: refactor all code (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
clement-berard authored Jan 10, 2025
1 parent 35b4b98 commit d17e11c
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ jobs:

- name: Lint
run: pnpm lint:check

- name: Build
run: pnpm build
2 changes: 1 addition & 1 deletion build-readme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'node:fs';
import { alphabetical, title } from 'radash';
import { list } from './src/common/list';
import { list } from './src/lib/client-side/list';

const sortByKey = (obj) => {
return Object.fromEntries(Object.entries(obj).sort((a, b) => a[0].localeCompare(b[0])));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@formkit/tempo": "^0.1.2",
"@keload/node-red-dxp": "1.19.0",
"@keload/node-red-dxp": "1.20.0",
"@release-it/conventional-changelog": "9.0.4",
"@types/jquery": "3.5.32",
"@types/jqueryui": "1.12.23",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions src/lib/client-side/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { alphabetical, title } from 'radash';
import { list } from './list';

export const getCategories = alphabetical(Object.keys(list), (f) => f);

export function getFunctionsFromCategory(category: string) {
const all = Object.keys(list[category])
.map((v) => {
const fn = list[category][v];
return {
key: v,
label: fn.label || title(v),
enabled: fn?.enabled ?? true,
};
})
.filter((v) => v.enabled);

return alphabetical(all, (f) => f.label);
}

export function getFunctionDetails(category: string, fn: string) {
const foundFn = list?.[category]?.[fn];
return {
...foundFn,
nodeDocs: `
${foundFn?.description || ''}
<br><br>
${foundFn?.docs || ''}
`.trim(),
};
}
30 changes: 2 additions & 28 deletions src/common/list.ts → src/lib/client-side/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { alphabetical, title } from 'radash';
import * as docsHelper from './docs';
import type { UtilityList } from './types';
import type { UtilityList } from '../../types/UtilityList';
import * as docsHelper from '../../utils/docs';

export const list: UtilityList = {
array_utilities: {
Expand Down Expand Up @@ -219,28 +218,3 @@ export const list: UtilityList = {
},
},
};

export const getCategories = alphabetical(Object.keys(list), (f) => f);

export function getFunctionsFromCategory(category: string) {
const all = Object.keys(list[category]).map((v) => {
return {
key: v,
label: list[category][v].label || title(v),
};
});

return alphabetical(all, (f) => f.label);
}

export function getFunctionDetails(category: string, fn: string) {
const foundFn = list?.[category]?.[fn];
return {
...foundFn,
nodeDocs: `
${foundFn?.description || ''}
<br><br>
${foundFn?.docs || ''}
`.trim(),
};
}
File renamed without changes.
8 changes: 8 additions & 0 deletions src/lib/server-side/fns/async-utilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { sleep } from 'radash';

export const asyncUtilities = {
delay: (_, inputProp: unknown) => {
const realProp = inputProp as number;
return sleep(realProp);
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { date, format } from '@formkit/tempo';
import type { NodeMainProps } from '../../nodes/main/types';
import type { NodeMainProps } from '../../../types/NodeMainProps';
function getCurrentTimezone() {
const timezoneDefault = Intl.DateTimeFormat().resolvedOptions().timeZone;
// @ts-ignore
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/lib/server-side/fns/object-utilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { keys } from 'radash';

export const objectUtilities = {
getKeys: keys,
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 10 additions & 17 deletions src/common/list-functions.ts → src/lib/server-side/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import { takeRight } from 'es-toolkit';
import { keys, sleep } from 'radash';
import { arrayUtilities } from './fns/array-utilities';
import { asyncUtilities } from './fns/async-utilities';
import { dateUtilities } from './fns/date-utilities';
import { mathUtilities } from './fns/math-utilities';
import { networkUtilities } from './fns/network-utilities';
import { objectUtilities } from './fns/object-utilities';
import { predicates } from './fns/predicates';
import { stringUtilities } from './fns/string-utilities';
import { utilityFunctions } from './fns/utilityFunctions';
import { utilityFunctions } from './fns/utility-functions';

export const listFunctions = {
utility_functions: utilityFunctions,
string_utilities: stringUtilities,
date_utilities: dateUtilities,
predicates,
object_utilities: {
getKeys: keys,
},
array_utilities: arrayUtilities,
network_utilities: networkUtilities,
async_utilities: asyncUtilities,
date_utilities: dateUtilities,
math_utilities: mathUtilities,
async_utilities: {
delay: (_, inputProp: unknown) => {
const realProp = inputProp as number;
return sleep(realProp);
},
},
network_utilities: networkUtilities,
object_utilities: objectUtilities,
predicates,
string_utilities: stringUtilities,
utility_functions: utilityFunctions,
};
8 changes: 4 additions & 4 deletions src/nodes/main/controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { NodeControllerConfig, NodeControllerInst } from '@keload/node-red-dxp/editor';
import { splitBooleanOutputs } from '@keload/node-red-dxp/utils/controller';
import { tryit } from 'radash';
import { getFunctionDetails } from '../../common/list';
import { listFunctions } from '../../common/list-functions';
import { splitBooleanOutputs } from './helpers/outputs';
import type { NodeMainProps } from './types';
import { getFunctionDetails } from '../../lib/client-side';
import { listFunctions } from '../../lib/server-side';
import type { NodeMainProps } from '../../types/NodeMainProps';

// Main Node-RED node controller
// Handles the node's initialization and message processing
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/main/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
watchInput,
} from '@keload/node-red-dxp/editor/dom-helper';
import { title } from 'radash';
import { getCategories, getFunctionDetails, getFunctionsFromCategory } from '../../../common/list';
import type { NodeMainProps } from '../types';
import { getCategories, getFunctionDetails, getFunctionsFromCategory } from '../../../lib/client-side';
import type { NodeMainProps } from '../../../types/NodeMainProps';

const Main: NodeEditorDefinition<NodeMainProps> = {
category: 'toolkit',
Expand Down
12 changes: 0 additions & 12 deletions src/nodes/main/helpers/outputs.ts

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions src/common/types.ts → src/types/UtilityList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type UtilityItem = {
label?: string;
};
label?: string;
enabled?: boolean;
revealClasses?: string[];
configArgs?: string;
};
Expand Down
File renamed without changes.

0 comments on commit d17e11c

Please sign in to comment.