feat: Convert all app files to JS

This commit is contained in:
Faruk AYDIN
2024-01-05 17:44:21 +01:00
parent b95478b635
commit 43dba351c3
1030 changed files with 5114 additions and 6436 deletions

View File

@@ -1,11 +1,7 @@
import { IJSONArray } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import getClient from '../../common/postgres-client';
import setParams from '../../common/set-run-time-parameters';
import whereClauseOperators from '../../common/where-clause-operators';
type TWhereClauseEntry = { columnName: string, value: string, operator: string };
type TWhereClauseEntries = TWhereClauseEntry[];
import defineAction from '../../../../helpers/define-action.js';
import getClient from '../../common/postgres-client.js';
import setParams from '../../common/set-run-time-parameters.js';
import whereClauseOperators from '../../common/where-clause-operators.js';
export default defineAction({
name: 'Delete',
@@ -15,7 +11,7 @@ export default defineAction({
{
label: 'Schema name',
key: 'schema',
type: 'string' as const,
type: 'string',
value: 'public',
required: true,
variables: true,
@@ -23,73 +19,73 @@ export default defineAction({
{
label: 'Table name',
key: 'table',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Where clause entries',
key: 'whereClauseEntries',
type: 'dynamic' as const,
type: 'dynamic',
required: true,
fields: [
{
label: 'Column name',
key: 'columnName',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Operator',
key: 'operator',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
variables: true,
options: whereClauseOperators
options: whereClauseOperators,
},
{
label: 'Value',
key: 'value',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
}
]
},
],
},
{
label: 'Run-time parameters',
key: 'params',
type: 'dynamic' as const,
type: 'dynamic',
required: false,
description: 'Change run-time configuration parameters with SET command',
fields: [
{
label: 'Parameter name',
key: 'parameter',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Value',
key: 'value',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
}
},
],
}
},
],
async run($) {
const client = getClient($);
await setParams(client, $.step.parameters.params);
const whereClauseEntries = $.step.parameters.whereClauseEntries as TWhereClauseEntries;
const whereClauseEntries = $.step.parameters.whereClauseEntries;
const response = await client($.step.parameters.table as string)
.withSchema($.step.parameters.schema as string)
const response = await client($.step.parameters.table)
.withSchema($.step.parameters.schema)
.returning('*')
.where((builder) => {
for (const whereClauseEntry of whereClauseEntries) {
@@ -100,14 +96,14 @@ export default defineAction({
}
}
})
.del() as IJSONArray;
.del();
client.destroy();
$.setActionItem({
raw: {
rows: response
}
rows: response,
},
});
},
});

View File

@@ -0,0 +1,6 @@
import insertAction from './insert/index.js';
import updateAction from './update/index.js';
import deleteAction from './delete/index.js';
import SQLQuery from './sql-query/index.js';
export default [insertAction, updateAction, deleteAction, SQLQuery];

View File

@@ -1,6 +0,0 @@
import insertAction from './insert';
import updateAction from './update';
import deleteAction from './delete';
import SQLQuery from './sql-query'
export default [insertAction, updateAction, deleteAction, SQLQuery];

View File

@@ -1,9 +1,6 @@
import { IJSONObject } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import getClient from '../../common/postgres-client';
import setParams from '../../common/set-run-time-parameters';
type TColumnValueEntries = { columnName: string, value: string }[];
import defineAction from '../../../../helpers/define-action.js';
import getClient from '../../common/postgres-client.js';
import setParams from '../../common/set-run-time-parameters.js';
export default defineAction({
name: 'Insert',
@@ -13,7 +10,7 @@ export default defineAction({
{
label: 'Schema name',
key: 'schema',
type: 'string' as const,
type: 'string',
value: 'public',
required: true,
variables: true,
@@ -21,75 +18,78 @@ export default defineAction({
{
label: 'Table name',
key: 'table',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Column - value entries',
key: 'columnValueEntries',
type: 'dynamic' as const,
type: 'dynamic',
required: true,
description: 'Table columns with values',
fields: [
{
label: 'Column name',
key: 'columnName',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Value',
key: 'value',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
}
},
],
},
{
label: 'Run-time parameters',
key: 'params',
type: 'dynamic' as const,
type: 'dynamic',
required: true,
description: 'Change run-time configuration parameters with SET command',
fields: [
{
label: 'Parameter name',
key: 'parameter',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Value',
key: 'value',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
}
},
],
}
},
],
async run($) {
const client = getClient($);
await setParams(client, $.step.parameters.params);
const fields = $.step.parameters.columnValueEntries as TColumnValueEntries;
const data = fields.reduce((result, { columnName, value }) => ({
...result,
[columnName]: value,
}), {});
const fields = $.step.parameters.columnValueEntries;
const data = fields.reduce(
(result, { columnName, value }) => ({
...result,
[columnName]: value,
}),
{}
);
const response = await client($.step.parameters.table as string)
.withSchema($.step.parameters.schema as string)
const response = await client($.step.parameters.table)
.withSchema($.step.parameters.schema)
.returning('*')
.insert(data) as IJSONObject;
.insert(data);
client.destroy();
$.setActionItem({ raw: response[0] as IJSONObject });
$.setActionItem({ raw: response[0] });
},
});

View File

@@ -1,6 +1,6 @@
import defineAction from '../../../../helpers/define-action';
import getClient from '../../common/postgres-client';
import setParams from '../../common/set-run-time-parameters';
import defineAction from '../../../../helpers/define-action.js';
import getClient from '../../common/postgres-client.js';
import setParams from '../../common/set-run-time-parameters.js';
export default defineAction({
name: 'SQL query',
@@ -10,7 +10,7 @@ export default defineAction({
{
label: 'SQL statement',
key: 'queryStatement',
type: 'string' as const,
type: 'string',
value: 'public',
required: true,
variables: true,
@@ -18,26 +18,26 @@ export default defineAction({
{
label: 'Run-time parameters',
key: 'params',
type: 'dynamic' as const,
type: 'dynamic',
required: false,
description: 'Change run-time configuration parameters with SET command',
fields: [
{
label: 'Parameter name',
key: 'parameter',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Value',
key: 'value',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
}
},
],
}
},
],
async run($) {
@@ -50,8 +50,8 @@ export default defineAction({
$.setActionItem({
raw: {
rows
}
rows,
},
});
},
});

View File

@@ -1,12 +1,7 @@
import { IJSONArray } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import getClient from '../../common/postgres-client';
import setParams from '../../common/set-run-time-parameters';
import whereClauseOperators from '../../common/where-clause-operators';
type TColumnValueEntries = { columnName: string, value: string }[];
type TWhereClauseEntry = { columnName: string, value: string, operator: string };
type TWhereClauseEntries = TWhereClauseEntry[];
import defineAction from '../../../../helpers/define-action.js';
import getClient from '../../common/postgres-client.js';
import setParams from '../../common/set-run-time-parameters.js';
import whereClauseOperators from '../../common/where-clause-operators.js';
export default defineAction({
name: 'Update',
@@ -16,7 +11,7 @@ export default defineAction({
{
label: 'Schema name',
key: 'schema',
type: 'string' as const,
type: 'string',
value: 'public',
required: true,
variables: true,
@@ -24,102 +19,105 @@ export default defineAction({
{
label: 'Table name',
key: 'table',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Where clause entries',
key: 'whereClauseEntries',
type: 'dynamic' as const,
type: 'dynamic',
required: true,
fields: [
{
label: 'Column name',
key: 'columnName',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Operator',
key: 'operator',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
variables: true,
options: whereClauseOperators
options: whereClauseOperators,
},
{
label: 'Value',
key: 'value',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
}
]
},
],
},
{
label: 'Column - value entries',
key: 'columnValueEntries',
type: 'dynamic' as const,
type: 'dynamic',
required: true,
description: 'Table columns with values',
fields: [
{
label: 'Column name',
key: 'columnName',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Value',
key: 'value',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
}
},
],
},
{
label: 'Run-time parameters',
key: 'params',
type: 'dynamic' as const,
type: 'dynamic',
required: false,
description: 'Change run-time configuration parameters with SET command',
fields: [
{
label: 'Parameter name',
key: 'parameter',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},
{
label: 'Value',
key: 'value',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
}
},
],
}
},
],
async run($) {
const client = getClient($);
await setParams(client, $.step.parameters.params);
const whereClauseEntries = $.step.parameters.whereClauseEntries as TWhereClauseEntries;
const whereClauseEntries = $.step.parameters.whereClauseEntries;
const fields = $.step.parameters.columnValueEntries as TColumnValueEntries;
const data: Record<string, unknown> = fields.reduce((result, { columnName, value }) => ({
...result,
[columnName]: value,
}), {});
const fields = $.step.parameters.columnValueEntries;
const data = fields.reduce(
(result, { columnName, value }) => ({
...result,
[columnName]: value,
}),
{}
);
const response = await client($.step.parameters.table as string)
.withSchema($.step.parameters.schema as string)
const response = await client($.step.parameters.table)
.withSchema($.step.parameters.schema)
.returning('*')
.where((builder) => {
for (const whereClauseEntry of whereClauseEntries) {
@@ -130,14 +128,14 @@ export default defineAction({
}
}
})
.update(data) as IJSONArray;
.update(data);
client.destroy();
$.setActionItem({
raw: {
rows: response
}
rows: response,
},
});
},
});

View File

@@ -1,12 +1,12 @@
import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified';
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';
export default {
fields: [
{
key: 'version',
label: 'PostgreSQL version',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,
@@ -18,7 +18,7 @@ export default {
{
key: 'host',
label: 'Host',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: '127.0.0.1',
@@ -29,7 +29,7 @@ export default {
{
key: 'port',
label: 'Port',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: '5432',
@@ -40,7 +40,7 @@ export default {
{
key: 'enableSsl',
label: 'Enable SSL',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
readOnly: false,
value: 'false',
@@ -61,7 +61,7 @@ export default {
{
key: 'database',
label: 'Database name',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,
@@ -72,7 +72,7 @@ export default {
{
key: 'user',
label: 'Database username',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,
@@ -83,7 +83,7 @@ export default {
{
key: 'password',
label: 'Password',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,

View File

@@ -0,0 +1,9 @@
import verifyCredentials from './verify-credentials.js';
const isStillVerified = async ($) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -1,10 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import verifyCredentials from './verify-credentials';
const isStillVerified = async ($: IGlobalVariable) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -1,8 +1,7 @@
import { IGlobalVariable } from '@automatisch/types';
import logger from '../../../helpers/logger';
import getClient from '../common/postgres-client';
import logger from '../../../helpers/logger.js';
import getClient from '../common/postgres-client.js';
const verifyCredentials = async ($: IGlobalVariable) => {
const verifyCredentials = async ($) => {
const client = getClient($);
const checkConnection = await client.raw('SELECT 1');
client.destroy();

View File

@@ -0,0 +1,20 @@
import knex from 'knex';
const getClient = ($) => {
const client = knex({
client: 'pg',
version: $.auth.data.version,
connection: {
host: $.auth.data.host,
port: Number($.auth.data.port),
ssl: $.auth.data.enableSsl === 'true' || $.auth.data.enableSsl === true,
user: $.auth.data.user,
password: $.auth.data.password,
database: $.auth.data.database,
},
});
return client;
};
export default getClient;

View File

@@ -1,22 +0,0 @@
import knex, { Knex } from 'knex';
import { IGlobalVariable } from '@automatisch/types';
const getClient = ($: IGlobalVariable): Knex<any, unknown[]> => {
const client = knex({
client: 'pg',
version: $.auth.data.version as string,
connection: {
host: $.auth.data.host as string,
port: Number($.auth.data.port),
ssl: ($.auth.data.enableSsl === 'true' ||
$.auth.data.enableSsl === true) as boolean,
user: $.auth.data.user as string,
password: $.auth.data.password as string,
database: $.auth.data.database as string,
},
});
return client;
};
export default getClient;

View File

@@ -0,0 +1,14 @@
const setParams = async (client, params) => {
for (const { parameter, value } of params) {
if (parameter) {
const bindings = {
parameter,
value,
};
await client.raw('SET :parameter: = :value:', bindings);
}
}
};
export default setParams;

View File

@@ -1,19 +0,0 @@
import { Knex } from 'knex';
import { type IJSONValue } from '@automatisch/types';
type TParams = { parameter: string; value: string; }[];
const setParams = async (client: Knex<any, unknown[]>, params: IJSONValue = []): Promise<void> => {
for (const { parameter, value } of (params as TParams)) {
if (parameter) {
const bindings = {
parameter,
value,
};
await client.raw('SET :parameter: = :value:', bindings);
}
}
};
export default setParams;

View File

@@ -1,6 +1,6 @@
import defineApp from '../../helpers/define-app';
import auth from './auth';
import actions from './actions';
import defineApp from '../../helpers/define-app.js';
import auth from './auth/index.js';
import actions from './actions/index.js';
export default defineApp({
name: 'PostgreSQL',