feat: Implement datastore built-in app
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Get value',
|
||||||
|
key: 'getValue',
|
||||||
|
description: 'Get value from the persistent datastore',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Key',
|
||||||
|
key: 'key',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'The key of your value to get.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const keyValuePair = await $.datastore.get({
|
||||||
|
key: $.step.parameters.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: keyValuePair,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
4
packages/backend/src/apps/datastore/actions/index.js
Normal file
4
packages/backend/src/apps/datastore/actions/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import getValue from './get-value/index.js';
|
||||||
|
import setValue from './set-value/index.js';
|
||||||
|
|
||||||
|
export default [getValue, setValue];
|
@@ -0,0 +1,36 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Set value',
|
||||||
|
key: 'setValue',
|
||||||
|
description: 'Set value to the persistent datastore',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Key',
|
||||||
|
key: 'key',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'The key of your value to set.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Value',
|
||||||
|
key: 'value',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'The value to set.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const keyValuePair = await $.datastore.set({
|
||||||
|
key: $.step.parameters.key,
|
||||||
|
value: $.step.parameters.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: keyValuePair,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
13
packages/backend/src/apps/datastore/assets/favicon.svg
Normal file
13
packages/backend/src/apps/datastore/assets/favicon.svg
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="#000000" width="800px" height="800px" viewBox="0 0 32 32" id="icon">
|
||||||
|
<defs>
|
||||||
|
<style>.cls-1{fill:none;}</style>
|
||||||
|
</defs>
|
||||||
|
<title>datastore</title>
|
||||||
|
<circle cx="23" cy="23" r="1"/>
|
||||||
|
<rect x="8" y="22" width="12" height="2"/>
|
||||||
|
<circle cx="23" cy="9" r="1"/>
|
||||||
|
<rect x="8" y="8" width="12" height="2"/>
|
||||||
|
<path d="M26,14a2,2,0,0,0,2-2V6a2,2,0,0,0-2-2H6A2,2,0,0,0,4,6v6a2,2,0,0,0,2,2H8v4H6a2,2,0,0,0-2,2v6a2,2,0,0,0,2,2H26a2,2,0,0,0,2-2V20a2,2,0,0,0-2-2H24V14ZM6,6H26v6H6ZM26,26H6V20H26Zm-4-8H10V14H22Z"/>
|
||||||
|
<rect id="_Transparent_Rectangle_" data-name="<Transparent Rectangle>" class="cls-1" width="32" height="32"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 704 B |
14
packages/backend/src/apps/datastore/index.js
Normal file
14
packages/backend/src/apps/datastore/index.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import defineApp from '../../helpers/define-app.js';
|
||||||
|
import actions from './actions/index.js';
|
||||||
|
|
||||||
|
export default defineApp({
|
||||||
|
name: 'Datastore',
|
||||||
|
key: 'datastore',
|
||||||
|
iconUrl: '{BASE_URL}/apps/datastore/assets/favicon.svg',
|
||||||
|
authDocUrl: 'https://automatisch.io/docs/apps/datastore/connection',
|
||||||
|
supportsConnections: false,
|
||||||
|
baseUrl: '',
|
||||||
|
apiBaseUrl: '',
|
||||||
|
primaryColor: '001F52',
|
||||||
|
actions,
|
||||||
|
});
|
@@ -0,0 +1,16 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
return knex.schema.createTable('datastore', (table) => {
|
||||||
|
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'));
|
||||||
|
table.string('key').notNullable();
|
||||||
|
table.string('value');
|
||||||
|
table.string('scope').notNullable();
|
||||||
|
table.uuid('scope_id').notNullable();
|
||||||
|
table.index(['key', 'scope', 'scope_id']);
|
||||||
|
|
||||||
|
table.timestamps(true, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
return knex.schema.dropTable('datastore');
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
import createHttpClient from './http-client/index.js';
|
import createHttpClient from './http-client/index.js';
|
||||||
import EarlyExitError from '../errors/early-exit.js';
|
import EarlyExitError from '../errors/early-exit.js';
|
||||||
import AlreadyProcessedError from '../errors/already-processed.js';
|
import AlreadyProcessedError from '../errors/already-processed.js';
|
||||||
|
import Datastore from '../models/datastore.js';
|
||||||
|
|
||||||
const globalVariable = async (options) => {
|
const globalVariable = async (options) => {
|
||||||
const {
|
const {
|
||||||
@@ -88,6 +89,43 @@ const globalVariable = async (options) => {
|
|||||||
setActionItem: (actionItem) => {
|
setActionItem: (actionItem) => {
|
||||||
$.actionOutput.data = actionItem;
|
$.actionOutput.data = actionItem;
|
||||||
},
|
},
|
||||||
|
datastore: {
|
||||||
|
get: async ({ key }) => {
|
||||||
|
const datastore = await Datastore.query().findOne({
|
||||||
|
key,
|
||||||
|
scope: 'flow',
|
||||||
|
scope_id: $.flow.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
key: datastore.key,
|
||||||
|
value: datastore.value,
|
||||||
|
[datastore.key]: datastore.value,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
set: async ({ key, value }) => {
|
||||||
|
let datastore = await Datastore.query()
|
||||||
|
.where({ key, scope: 'flow', scope_id: $.flow.id })
|
||||||
|
.first();
|
||||||
|
|
||||||
|
if (datastore) {
|
||||||
|
await datastore.$query().patchAndFetch({ value: value });
|
||||||
|
} else {
|
||||||
|
datastore = await Datastore.query().insert({
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
scope: 'flow',
|
||||||
|
scopeId: $.flow.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
key: datastore.key,
|
||||||
|
value: datastore.value,
|
||||||
|
[datastore.key]: datastore.value,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (request) {
|
if (request) {
|
||||||
|
24
packages/backend/src/models/datastore.js
Normal file
24
packages/backend/src/models/datastore.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import Base from './base.js';
|
||||||
|
|
||||||
|
class Datastore extends Base {
|
||||||
|
static tableName = 'datastore';
|
||||||
|
|
||||||
|
static jsonSchema = {
|
||||||
|
type: 'object',
|
||||||
|
required: ['key', 'value', 'scope', 'scopeId'],
|
||||||
|
|
||||||
|
properties: {
|
||||||
|
id: { type: 'string', format: 'uuid' },
|
||||||
|
key: { type: 'string', minLength: 1 },
|
||||||
|
value: { type: 'string', minLength: 1 },
|
||||||
|
scope: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['flow'],
|
||||||
|
default: 'flow',
|
||||||
|
},
|
||||||
|
scopeId: { type: 'string', format: 'uuid' },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Datastore;
|
Reference in New Issue
Block a user