Skip to content

Commit 42abe7a

Browse files
[Components] xata #13198 (#13853)
* Added actions * Added actions * Update components/xata/actions/list-branches/list-branches.mjs Co-authored-by: michelle0927 <[email protected]> * Requested changes done * updates * pnpm-lock.yaml * format recordData * updates * update --------- Co-authored-by: michelle0927 <[email protected]> Co-authored-by: michelle0927 <[email protected]>
1 parent 6b118ed commit 42abe7a

File tree

14 files changed

+507
-86
lines changed

14 files changed

+507
-86
lines changed

components/algodocs/algodocs.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/ical/ical.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/virifi/virifi.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/xata/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import app from "../../xata.app.mjs";
2+
3+
export default {
4+
props: {
5+
app,
6+
endpoint: {
7+
propDefinition: [
8+
app,
9+
"endpoint",
10+
],
11+
},
12+
workspace: {
13+
propDefinition: [
14+
app,
15+
"workspace",
16+
],
17+
},
18+
database: {
19+
propDefinition: [
20+
app,
21+
"database",
22+
(c) => ({
23+
workspace: c.workspace,
24+
}),
25+
],
26+
},
27+
branch: {
28+
propDefinition: [
29+
app,
30+
"branch",
31+
(c) => ({
32+
endpoint: c.endpoint,
33+
database: c.database,
34+
}),
35+
],
36+
},
37+
table: {
38+
propDefinition: [
39+
app,
40+
"table",
41+
(c) => ({
42+
endpoint: c.endpoint,
43+
database: c.database,
44+
branch: c.branch,
45+
}),
46+
],
47+
reloadProps: true,
48+
},
49+
},
50+
async additionalProps(props) {
51+
const {
52+
endpoint,
53+
database,
54+
branch,
55+
table,
56+
} = this;
57+
58+
const description = "The keys and values of the data that will be recorded in the database.";
59+
60+
if (endpoint && database && branch && table) {
61+
const { columns } = await this.app.listColumns({
62+
endpoint,
63+
database,
64+
branch,
65+
table,
66+
});
67+
if (columns?.length) {
68+
let descriptionWithColumns = `${description} Available Columns:`;
69+
for (const column of columns) {
70+
descriptionWithColumns += ` \`${column.name}\``;
71+
}
72+
props.recordData.description = descriptionWithColumns;
73+
return {};
74+
}
75+
}
76+
props.recordData.description = description;
77+
return {};
78+
},
79+
methods: {
80+
async formatRecordData() {
81+
const recordData = this.recordData;
82+
const { columns } = await this.app.listColumns({
83+
endpoint: this.endpoint,
84+
database: this.database,
85+
branch: this.branch,
86+
table: this.table,
87+
});
88+
if (!columns?.length) {
89+
return this.recordData;
90+
}
91+
for (const column of columns) {
92+
if (!recordData[column.name] || typeof recordData[column.name] !== "string") {
93+
continue;
94+
}
95+
if ((column.type === "int" || column.type === "float")) {
96+
recordData[column.name] = +recordData[column.name];
97+
}
98+
if (column.type === "bool") {
99+
recordData[column.name] = !(recordData[column.name] === "false" || recordData[column.name === "0"]);
100+
}
101+
if (column.type === "multiple" || column.type === "vector") {
102+
recordData[column.name] = JSON.parse(recordData[column.name]);
103+
}
104+
}
105+
return recordData;
106+
},
107+
},
108+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import common from "../common/common.mjs";
2+
3+
export default {
4+
...common,
5+
key: "xata-create-record",
6+
name: "Create Record",
7+
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)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
recordData: {
13+
propDefinition: [
14+
common.props.app,
15+
"recordData",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.app.createRecord({
21+
$,
22+
endpoint: this.endpoint,
23+
database: this.database,
24+
branch: this.branch,
25+
table: this.table,
26+
data: await this.formatRecordData(),
27+
});
28+
$.export("$summary", `Successfully created Record with ID: '${response.id}'`);
29+
return response;
30+
},
31+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import app from "../../xata.app.mjs";
2+
3+
export default {
4+
key: "xata-list-branches",
5+
name: "List Branches",
6+
description: "List branches of the specified database. [See the documentation](https://xata.io/docs/api-reference/dbs/db_name#list-branches)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
endpoint: {
12+
propDefinition: [
13+
app,
14+
"endpoint",
15+
],
16+
},
17+
workspace: {
18+
propDefinition: [
19+
app,
20+
"workspace",
21+
],
22+
},
23+
database: {
24+
propDefinition: [
25+
app,
26+
"database",
27+
(c) => ({
28+
workspace: c.workspace,
29+
}),
30+
],
31+
},
32+
},
33+
async run({ $ }) {
34+
const response = await this.app.listBranches({
35+
$,
36+
endpoint: this.endpoint,
37+
database: this.database,
38+
});
39+
$.export("$summary", `Successfully retrieved '${response.branches.length}' branches`);
40+
return response;
41+
},
42+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import common from "../common/common.mjs";
2+
3+
export default {
4+
...common,
5+
key: "xata-replace-record",
6+
name: "Replace Record",
7+
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)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
recordId: {
13+
propDefinition: [
14+
common.props.app,
15+
"recordId",
16+
(c) => ({
17+
endpoint: c.endpoint,
18+
database: c.database,
19+
table: c.table,
20+
branch: c.branch,
21+
}),
22+
],
23+
},
24+
recordData: {
25+
propDefinition: [
26+
common.props.app,
27+
"recordData",
28+
],
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.app.replaceRecord({
33+
$,
34+
endpoint: this.endpoint,
35+
database: this.database,
36+
branch: this.branch,
37+
table: this.table,
38+
recordId: this.recordId,
39+
data: await this.formatRecordData(),
40+
});
41+
$.export("$summary", `Successfully replaced Record with ID: '${response.id}'`);
42+
return response;
43+
},
44+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import common from "../common/common.mjs";
2+
3+
export default {
4+
...common,
5+
key: "xata-update-record",
6+
name: "Update Record",
7+
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)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
recordId: {
13+
propDefinition: [
14+
common.props.app,
15+
"recordId",
16+
(c) => ({
17+
endpoint: c.endpoint,
18+
database: c.database,
19+
table: c.table,
20+
branch: c.branch,
21+
}),
22+
],
23+
},
24+
recordData: {
25+
propDefinition: [
26+
common.props.app,
27+
"recordData",
28+
],
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.app.updateRecord({
33+
$,
34+
endpoint: this.endpoint,
35+
database: this.database,
36+
branch: this.branch,
37+
table: this.table,
38+
recordId: this.recordId,
39+
data: await this.formatRecordData(),
40+
});
41+
$.export("$summary", `Successfully updated/created Record with ID: '${response.id}'`);
42+
return response;
43+
},
44+
};

components/xata/app/xata.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)