diff --git a/packages/backend/package.json b/packages/backend/package.json index 5893599b..8a5e671d 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -18,6 +18,7 @@ "dependencies": { "@automatisch/web": "0.1.0", "@octokit/oauth-methods": "^1.2.6", + "ajv-formats": "^2.1.1", "axios": "0.24.0", "bcrypt": "^5.0.1", "cors": "^2.8.5", diff --git a/packages/backend/src/db/migrations/20211005151457_create_users.ts b/packages/backend/src/db/migrations/20211005151457_create_users.ts index d74dc3a5..aab544fe 100644 --- a/packages/backend/src/db/migrations/20211005151457_create_users.ts +++ b/packages/backend/src/db/migrations/20211005151457_create_users.ts @@ -2,7 +2,7 @@ import { Knex } from "knex"; export async function up(knex: Knex): Promise { return knex.schema.createTable('users', (table) => { - table.increments('id'); + table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()')); table.string('email').unique().notNullable(); table.string('password').notNullable(); diff --git a/packages/backend/src/db/migrations/20211011120732_create_credentials.ts b/packages/backend/src/db/migrations/20211011120732_create_credentials.ts index 580d2c6d..35a93b18 100644 --- a/packages/backend/src/db/migrations/20211011120732_create_credentials.ts +++ b/packages/backend/src/db/migrations/20211011120732_create_credentials.ts @@ -2,11 +2,11 @@ import { Knex } from "knex"; export async function up(knex: Knex): Promise { return knex.schema.createTable('credentials', (table) => { - table.increments('id'); + table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()')) table.string('key').notNullable(); table.string('display_name').notNullable(); table.text('data').notNullable(); - table.integer('user_id').references('id').inTable('users'); + table.uuid('user_id').references('id').inTable('users'); table.boolean('verified').defaultTo(false); table.timestamps(true, true); diff --git a/packages/backend/src/db/migrations/20211106214730_create_steps.ts b/packages/backend/src/db/migrations/20211106214730_create_steps.ts index d9135b0f..54cf3488 100644 --- a/packages/backend/src/db/migrations/20211106214730_create_steps.ts +++ b/packages/backend/src/db/migrations/20211106214730_create_steps.ts @@ -2,11 +2,11 @@ import { Knex } from 'knex'; export async function up(knex: Knex): Promise { return knex.schema.createTable('steps', (table) => { - table.increments('id'); + table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()')) table.string('key').notNullable(); table.string('app_key').notNullable(); table.string('type').notNullable(); - table.integer('connection_id').references('id').inTable('connections'); + table.uuid('connection_id').references('id').inTable('connections'); table.text('parameters'); table.timestamps(true, true); diff --git a/packages/backend/src/db/migrations/20211122140336_create_flows.ts b/packages/backend/src/db/migrations/20211122140336_create_flows.ts index 693c8d27..12028680 100644 --- a/packages/backend/src/db/migrations/20211122140336_create_flows.ts +++ b/packages/backend/src/db/migrations/20211122140336_create_flows.ts @@ -2,9 +2,9 @@ import { Knex } from "knex"; export async function up(knex: Knex): Promise { return knex.schema.createTable('flows', (table) => { - table.increments('id'); + table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()')) table.string('name'); - table.integer('user_id').references('id').inTable('users'); + table.uuid('user_id').references('id').inTable('users'); table.timestamps(true, true); }); diff --git a/packages/backend/src/db/migrations/20211122140612_add_flow_id_to_steps.ts b/packages/backend/src/db/migrations/20211122140612_add_flow_id_to_steps.ts index fb9f6b88..fc223546 100644 --- a/packages/backend/src/db/migrations/20211122140612_add_flow_id_to_steps.ts +++ b/packages/backend/src/db/migrations/20211122140612_add_flow_id_to_steps.ts @@ -3,7 +3,7 @@ import { Knex } from "knex"; export async function up(knex: Knex): Promise { return knex.schema.table('steps', (table) => { table - .integer('flow_id') + .uuid('flow_id') .references('id') .inTable('flows'); }); diff --git a/packages/backend/src/db/migrations/20220219093113_create_executions.ts b/packages/backend/src/db/migrations/20220219093113_create_executions.ts index a5140d52..dfba81b8 100644 --- a/packages/backend/src/db/migrations/20220219093113_create_executions.ts +++ b/packages/backend/src/db/migrations/20220219093113_create_executions.ts @@ -2,8 +2,8 @@ import { Knex } from 'knex'; export async function up(knex: Knex): Promise { return knex.schema.createTable('executions', (table) => { - table.increments('id'); - table.integer('flow_id').references('id').inTable('flows'); + table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()')) + table.uuid('flow_id').references('id').inTable('flows'); table.boolean('test_run').notNullable().defaultTo(false); table.timestamps(true, true); diff --git a/packages/backend/src/db/migrations/20220219100800_create_execution_steps.ts b/packages/backend/src/db/migrations/20220219100800_create_execution_steps.ts index eef61a81..2260056b 100644 --- a/packages/backend/src/db/migrations/20220219100800_create_execution_steps.ts +++ b/packages/backend/src/db/migrations/20220219100800_create_execution_steps.ts @@ -2,9 +2,9 @@ import { Knex } from 'knex'; export async function up(knex: Knex): Promise { return knex.schema.createTable('execution_steps', (table) => { - table.increments('id'); - table.integer('execution_id').references('id').inTable('executions'); - table.integer('step_id').references('id').inTable('steps'); + table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()')) + table.uuid('execution_id').references('id').inTable('executions'); + table.uuid('step_id').references('id').inTable('steps'); table.string('status'); table.text('data_in'); table.text('data_out'); diff --git a/packages/backend/src/db/migrations/20220221225537_alter_parameters_column_of_steps.ts b/packages/backend/src/db/migrations/20220221225537_alter_parameters_column_of_steps.ts index 0f912860..aaeb8d84 100644 --- a/packages/backend/src/db/migrations/20220221225537_alter_parameters_column_of_steps.ts +++ b/packages/backend/src/db/migrations/20220221225537_alter_parameters_column_of_steps.ts @@ -2,7 +2,7 @@ import { Knex } from 'knex'; export async function up(knex: Knex): Promise { return knex.schema.alterTable('steps', (table) => { - table.jsonb('parameters').alter(); + table.jsonb('parameters').defaultTo('{}').alter(); }); } diff --git a/packages/backend/src/graphql/mutations/create-step.ts b/packages/backend/src/graphql/mutations/create-step.ts index 89e2a48b..8d02cb16 100644 --- a/packages/backend/src/graphql/mutations/create-step.ts +++ b/packages/backend/src/graphql/mutations/create-step.ts @@ -7,13 +7,13 @@ type Params = { key: string; appKey: string; flow: { - id: number; + id: string; }; connection: { - id: number; + id: string; }; previousStep: { - id: number; + id: string; }; }; }; @@ -43,7 +43,6 @@ const createStepResolver = async ( appKey: input.appKey, type: 'action', position: previousStep.position + 1, - parameters: {}, }); const nextSteps = await flow diff --git a/packages/backend/src/models/base.ts b/packages/backend/src/models/base.ts index 20e5d8bc..1d982bd6 100644 --- a/packages/backend/src/models/base.ts +++ b/packages/backend/src/models/base.ts @@ -1,5 +1,6 @@ -import { Model, snakeCaseMappers } from 'objection'; +import { AjvValidator, Model, snakeCaseMappers } from 'objection'; import type { QueryContext, ModelOptions, ColumnNameMappers } from 'objection'; +import addFormats from 'ajv-formats'; class Base extends Model { createdAt!: string; @@ -9,6 +10,19 @@ class Base extends Model { return snakeCaseMappers(); } + static createValidator() { + return new AjvValidator({ + onCreateAjv: (ajv) => { + addFormats.default(ajv); + }, + options: { + allErrors: true, + validateSchema: true, + ownProperties: true, + }, + }); + } + async $beforeInsert(queryContext: QueryContext): Promise { await super.$beforeInsert(queryContext); diff --git a/packages/backend/src/models/connection.ts b/packages/backend/src/models/connection.ts index 866fd1b6..997a2b33 100644 --- a/packages/backend/src/models/connection.ts +++ b/packages/backend/src/models/connection.ts @@ -20,10 +20,10 @@ class Connection extends Base { required: ['key', 'data'], properties: { - id: { type: 'string' }, + id: { type: 'string', format: 'uuid' }, key: { type: 'string', minLength: 1, maxLength: 255 }, data: { type: 'object' }, - userId: { type: 'string' }, + userId: { type: 'string', format: 'uuid' }, verified: { type: 'boolean' }, }, }; diff --git a/packages/backend/src/models/execution-step.ts b/packages/backend/src/models/execution-step.ts index 3f696c31..080efe28 100644 --- a/packages/backend/src/models/execution-step.ts +++ b/packages/backend/src/models/execution-step.ts @@ -16,8 +16,8 @@ class ExecutionStep extends Base { type: 'object', properties: { - id: { type: 'string' }, - executionId: { type: 'string' }, + id: { type: 'string', format: 'uuid' }, + executionId: { type: 'string', format: 'uuid' }, stepId: { type: 'string' }, dataIn: { type: 'object' }, dataOut: { type: 'object' }, diff --git a/packages/backend/src/models/execution.ts b/packages/backend/src/models/execution.ts index e4d6772f..7cd11029 100644 --- a/packages/backend/src/models/execution.ts +++ b/packages/backend/src/models/execution.ts @@ -14,8 +14,8 @@ class Execution extends Base { type: 'object', properties: { - id: { type: 'string' }, - flowId: { type: 'integer' }, + id: { type: 'string', format: 'uuid' }, + flowId: { type: 'string', format: 'uuid' }, testRun: { type: 'boolean' }, }, }; diff --git a/packages/backend/src/models/flow.ts b/packages/backend/src/models/flow.ts index ee84a915..5d994664 100644 --- a/packages/backend/src/models/flow.ts +++ b/packages/backend/src/models/flow.ts @@ -15,9 +15,9 @@ class Flow extends Base { type: 'object', properties: { - id: { type: 'string' }, + id: { type: 'string', format: 'uuid' }, name: { type: 'string' }, - userId: { type: 'string' }, + userId: { type: 'string', format: 'uuid' }, active: { type: 'boolean' }, }, }; diff --git a/packages/backend/src/models/step.ts b/packages/backend/src/models/step.ts index c8ca29e3..fec08153 100644 --- a/packages/backend/src/models/step.ts +++ b/packages/backend/src/models/step.ts @@ -25,12 +25,12 @@ class Step extends Base { required: ['type'], properties: { - id: { type: 'string' }, - flowId: { type: 'string' }, + id: { type: 'string', format: 'uuid' }, + flowId: { type: 'string', format: 'uuid' }, key: { type: ['string', 'null'] }, appKey: { type: ['string', 'null'], minLength: 1, maxLength: 255 }, type: { type: 'string', enum: ['action', 'trigger'] }, - connectionId: { type: ['string', 'null'] }, + connectionId: { type: ['string', 'null'], format: 'uuid' }, status: { type: 'string', enum: ['incomplete', 'completed'] }, position: { type: 'integer' }, parameters: { type: 'object' }, diff --git a/packages/backend/src/models/user.ts b/packages/backend/src/models/user.ts index a2c11952..6fa30489 100644 --- a/packages/backend/src/models/user.ts +++ b/packages/backend/src/models/user.ts @@ -20,7 +20,7 @@ class User extends Base { required: ['email', 'password'], properties: { - id: { type: 'string' }, + id: { type: 'string', format: 'uuid' }, email: { type: 'string', format: 'email', minLength: 1, maxLength: 255 }, password: { type: 'string', minLength: 1, maxLength: 255 }, },