Skip to content

Commit

Permalink
Added actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lcaresia committed Sep 5, 2024
1 parent d2cd1e6 commit 76cc37e
Show file tree
Hide file tree
Showing 6 changed files with 413 additions and 3 deletions.
3 changes: 0 additions & 3 deletions components/xata/.gitignore

This file was deleted.

69 changes: 69 additions & 0 deletions components/xata/actions/create-record/create-record.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import app from "../../xata.app.mjs";

export default {
key: "xata-create-record",
name: "Create Record",
description: "Create a new Record in the specified database. [See the documentation](https://xata.io/docs/api-reference/db/db_branch_name/tables/table_name/data#insert-record)",
version: "0.0.1",
type: "action",
props: {
app,
endpoint: {
propDefinition: [
app,
"endpoint",
],
},
workspace: {
propDefinition: [
app,
"workspace",
],
},
database: {
propDefinition: [
app,
"database",
(c) => ({
workspace: c.workspace,
}),
],
},
branch: {
propDefinition: [
app,
"branch",
(c) => ({
endpoint: c.endpoint,
database: c.database,
}),
],
},
table: {
propDefinition: [
app,
"table",
],
},
recordData: {
propDefinition: [
app,
"recordData",
],
},
},
async run({ $ }) {
const response = await this.app.createRecord({
$,
endpoint: this.endpoint,
database: this.database,
branch: this.branch,
table: this.table,
data: this.recordData,
});

$.export("$summary", `Successfully created Record with ID: '${response.id}'`);

return response;
},
};
44 changes: 44 additions & 0 deletions components/xata/actions/list-branches/list-branches.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import app from "../../xata.app.mjs";

export default {
key: "xata-list-branches",
name: "List Branches",
description: "List branches of the specified database. [See the documentation](https://xata.io/docs/api-reference/dbs/db_name#list-branches)",
version: "0.0.1",
type: "action",
props: {
app,
endpoint: {
propDefinition: [
app,
"endpoint",
],
},
workspace: {
propDefinition: [
app,
"workspace",
],
},
database: {
propDefinition: [
app,
"database",
(c) => ({
workspace: c.workspace,
}),
],
},
},
async run({ $ }) {
const response = await this.app.listBranches({
$,
endpoint: this.endpoint,
database: this.database,
});

$.export("$summary", `Successfully retrieved '${response.branchse.length}' branches`);

return response;
},
};
76 changes: 76 additions & 0 deletions components/xata/actions/replace-record/replace-record.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import app from "../../xata.app.mjs";

export default {
key: "xata-replace-record",
name: "Replace Record",
description: "Replace a record with the specified ID. [See the documentation](https://xata.io/docs/api-reference/db/db_branch_name/tables/table_name/data/record_id#insert-record-with-id)",
version: "0.0.1",
type: "action",
props: {
app,
endpoint: {
propDefinition: [
app,
"endpoint",
],
},
workspace: {
propDefinition: [
app,
"workspace",
],
},
database: {
propDefinition: [
app,
"database",
(c) => ({
workspace: c.workspace,
}),
],
},
branch: {
propDefinition: [
app,
"branch",
(c) => ({
endpoint: c.endpoint,
database: c.database,
}),
],
},
table: {
propDefinition: [
app,
"table",
],
},
recordId: {
propDefinition: [
app,
"recordId",
],
},
recordData: {
propDefinition: [
app,
"recordData",
],
},
},
async run({ $ }) {
const response = await this.app.replaceRecord({
$,
endpoint: this.endpoint,
database: this.database,
branch: this.branch,
table: this.table,
recordId: this.recordId,
data: this.recordData,
});

$.export("$summary", `Successfully replaced Record with ID: '${response.id}'`);

return response;
},
};
76 changes: 76 additions & 0 deletions components/xata/actions/update-record/update-record.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import app from "../../xata.app.mjs";

export default {
key: "xata-update-record",
name: "Update Record",
description: "Update or create a record with the specified ID. [See the documentation](https://xata.io/docs/api-reference/db/db_branch_name/tables/table_name/data/record_id#upsert-record-with-id)",
version: "0.0.1",
type: "action",
props: {
app,
endpoint: {
propDefinition: [
app,
"endpoint",
],
},
workspace: {
propDefinition: [
app,
"workspace",
],
},
database: {
propDefinition: [
app,
"database",
(c) => ({
workspace: c.workspace,
}),
],
},
branch: {
propDefinition: [
app,
"branch",
(c) => ({
endpoint: c.endpoint,
database: c.database,
}),
],
},
table: {
propDefinition: [
app,
"table",
],
},
recordId: {
propDefinition: [
app,
"recordId",
],
},
recordData: {
propDefinition: [
app,
"recordData",
],
},
},
async run({ $ }) {
const response = await this.app.updateRecord({
$,
endpoint: this.endpoint,
database: this.database,
branch: this.branch,
table: this.table,
recordId: this.recordId,
data: this.recordData,
});

$.export("$summary", `Successfully updated/created Record with ID: '${response.id}'`);

return response;
},
};
Loading

0 comments on commit 76cc37e

Please sign in to comment.