Skip to content

Commit 48bdf93

Browse files
committed
updates
1 parent 9dddce1 commit 48bdf93

File tree

5 files changed

+111
-132
lines changed

5 files changed

+111
-132
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
],
42+
reloadProps: true,
43+
},
44+
},
45+
async additionalProps(props) {
46+
const {
47+
endpoint,
48+
database,
49+
branch,
50+
table,
51+
} = this;
52+
53+
const description = "The keys and values of the data that will be recorded in the database.";
54+
55+
if (endpoint && database && branch && table) {
56+
try {
57+
const { columns } = await this.app.listColumns({
58+
endpoint,
59+
database,
60+
branch,
61+
table,
62+
});
63+
if (columns?.length) {
64+
let descriptionWithColumns = `${description} Available Columns:`;
65+
for (const column of columns) {
66+
descriptionWithColumns += ` \`${column.name}\``;
67+
}
68+
props.recordData.description = descriptionWithColumns;
69+
return {};
70+
}
71+
} catch (e) {
72+
props.recordData.description = description;
73+
// Columns not found. Occurs when the user hasn't finished entering the table name
74+
}
75+
}
76+
props.recordData.description = description;
77+
return {};
78+
},
79+
};

components/xata/actions/create-record/create-record.mjs

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,17 @@
1-
import app from "../../xata.app.mjs";
1+
import common from "../common/common.mjs";
22

33
export default {
4+
...common,
45
key: "xata-create-record",
56
name: "Create Record",
67
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)",
78
version: "0.0.1",
89
type: "action",
910
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-
branch: {
33-
propDefinition: [
34-
app,
35-
"branch",
36-
(c) => ({
37-
endpoint: c.endpoint,
38-
database: c.database,
39-
}),
40-
],
41-
},
42-
table: {
43-
propDefinition: [
44-
app,
45-
"table",
46-
],
47-
},
11+
...common.props,
4812
recordData: {
4913
propDefinition: [
50-
app,
14+
common.props.app,
5115
"recordData",
5216
],
5317
},

components/xata/actions/replace-record/replace-record.mjs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,17 @@
1-
import app from "../../xata.app.mjs";
1+
import common from "../common/common.mjs";
22

33
export default {
4+
...common,
45
key: "xata-replace-record",
56
name: "Replace Record",
67
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)",
78
version: "0.0.1",
89
type: "action",
910
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-
branch: {
33-
propDefinition: [
34-
app,
35-
"branch",
36-
(c) => ({
37-
endpoint: c.endpoint,
38-
database: c.database,
39-
}),
40-
],
41-
},
42-
table: {
43-
propDefinition: [
44-
app,
45-
"table",
46-
],
47-
},
11+
...common.props,
4812
recordId: {
4913
propDefinition: [
50-
app,
14+
common.props.app,
5115
"recordId",
5216
(c) => ({
5317
endpoint: c.endpoint,
@@ -59,7 +23,7 @@ export default {
5923
},
6024
recordData: {
6125
propDefinition: [
62-
app,
26+
common.props.app,
6327
"recordData",
6428
],
6529
},

components/xata/actions/update-record/update-record.mjs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,17 @@
1-
import app from "../../xata.app.mjs";
1+
import common from "../common/common.mjs";
22

33
export default {
4+
...common,
45
key: "xata-update-record",
56
name: "Update Record",
67
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)",
78
version: "0.0.1",
89
type: "action",
910
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-
branch: {
33-
propDefinition: [
34-
app,
35-
"branch",
36-
(c) => ({
37-
endpoint: c.endpoint,
38-
database: c.database,
39-
}),
40-
],
41-
},
42-
table: {
43-
propDefinition: [
44-
app,
45-
"table",
46-
],
47-
},
11+
...common.props,
4812
recordId: {
4913
propDefinition: [
50-
app,
14+
common.props.app,
5115
"recordId",
5216
(c) => ({
5317
endpoint: c.endpoint,
@@ -59,7 +23,7 @@ export default {
5923
},
6024
recordData: {
6125
propDefinition: [
62-
app,
26+
common.props.app,
6327
"recordData",
6428
],
6529
},

components/xata/xata.app.mjs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
recordData: {
3737
type: "object",
3838
label: "Record Data",
39-
description: "The key and value of the data that will be recorded in the database",
39+
description: "The keys and values of the data that will be recorded in the database",
4040
},
4141
workspace: {
4242
type: "string",
@@ -56,7 +56,7 @@ export default {
5656
database: {
5757
type: "string",
5858
label: "Database Name",
59-
description: "Name of the database",
59+
description: "Name of the database. Must be **non postgres enabled**.",
6060
async options({ workspace }) {
6161
const response = await this.listDatabases({
6262
workspace,
@@ -99,7 +99,7 @@ export default {
9999
headers,
100100
...otherOpts
101101
} = opts;
102-
const finalUrl = url || (this._baseUrl() + path);
102+
const finalUrl = url || `${this._baseUrl()}${path}`;
103103
return axios($, {
104104
...otherOpts,
105105
url: finalUrl,
@@ -109,7 +109,7 @@ export default {
109109
},
110110
});
111111
},
112-
async createRecord({
112+
createRecord({
113113
endpoint, database, branch, table, ...args
114114
}) {
115115
return this._makeRequest({
@@ -118,7 +118,7 @@ export default {
118118
...args,
119119
});
120120
},
121-
async replaceRecord({
121+
replaceRecord({
122122
endpoint, database, branch, table, recordId, ...args
123123
}) {
124124
return this._makeRequest({
@@ -127,7 +127,7 @@ export default {
127127
...args,
128128
});
129129
},
130-
async updateRecord({
130+
updateRecord({
131131
endpoint, database, branch, table, recordId, ...args
132132
}) {
133133
return this._makeRequest({
@@ -136,7 +136,7 @@ export default {
136136
...args,
137137
});
138138
},
139-
async listRecords({
139+
listRecords({
140140
endpoint, database, branch, table, ...args
141141
}) {
142142
return this._makeRequest({
@@ -145,27 +145,35 @@ export default {
145145
...args,
146146
});
147147
},
148-
async listWorkspaces(args = {}) {
148+
listWorkspaces(args = {}) {
149149
return this._makeRequest({
150150
path: "/workspaces",
151151
...args,
152152
});
153153
},
154-
async listDatabases({
154+
listDatabases({
155155
workspace, ...args
156156
}) {
157157
return this._makeRequest({
158158
path: `/workspaces/${workspace}/dbs`,
159159
...args,
160160
});
161161
},
162-
async listBranches({
162+
listBranches({
163163
endpoint, database, ...args
164164
}) {
165165
return this._makeRequest({
166166
url: `${endpoint}/dbs/${database}`,
167167
...args,
168168
});
169169
},
170+
listColumns({
171+
endpoint, database, branch, table, ...args
172+
}) {
173+
return this._makeRequest({
174+
url: `${endpoint}/db/${database}:${branch}/tables/${table}/columns`,
175+
...args,
176+
});
177+
},
170178
},
171179
};

0 commit comments

Comments
 (0)