@pipedream/supabase 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ import supabase from "../../supabase.app.mjs";
2
+ import fs from "fs";
3
+ import { parse } from "csv-parse/sync";
4
+
5
+ export default {
6
+ key: "supabase-batch-insert-rows",
7
+ name: "Batch Insert Rows",
8
+ description: "Inserts new rows into a database. [See the documentation](https://supabase.com/docs/reference/javascript/insert)",
9
+ version: "0.0.2",
10
+ type: "action",
11
+ props: {
12
+ supabase,
13
+ table: {
14
+ propDefinition: [
15
+ supabase,
16
+ "table",
17
+ ],
18
+ description: "Name of the table to insert rows into",
19
+ },
20
+ source: {
21
+ type: "string",
22
+ label: "Source of data",
23
+ description: "Whether to enter the row data as an array of objects or to import from a CSV file",
24
+ options: [
25
+ "Array",
26
+ "CSV File",
27
+ ],
28
+ reloadProps: true,
29
+ },
30
+ },
31
+ async additionalProps() {
32
+ const props = {};
33
+ if (this.source === "Array") {
34
+ props.data = {
35
+ type: "string[]",
36
+ label: "Row Data",
37
+ description: "An array of objects, each object representing a row. Enter column names and values as key/value pairs",
38
+ };
39
+ }
40
+ if (this.source === "CSV File") {
41
+ props.filePath = {
42
+ type: "string",
43
+ label: "File Path",
44
+ description: "The path to a csv file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
45
+ };
46
+ }
47
+ return props;
48
+ },
49
+ methods: {
50
+ parseArray(arr) {
51
+ if (Array.isArray(arr)) {
52
+ return arr.map((item) => {
53
+ return typeof item === "string"
54
+ ? JSON.parse(item)
55
+ : item;
56
+ });
57
+ }
58
+ if (typeof arr === "string") {
59
+ return JSON.parse(arr);
60
+ }
61
+ },
62
+ getRowsFromCSV(filePath) {
63
+ const fileContent = fs.readFileSync(filePath.includes("tmp/")
64
+ ? filePath
65
+ : `/tmp/${filePath}`, "utf-8");
66
+ const rows = parse(fileContent, {
67
+ columns: true,
68
+ skip_empty_lines: true,
69
+ });
70
+ return rows;
71
+ },
72
+ },
73
+ async run({ $ }) {
74
+ const data = this.source === "CSV File"
75
+ ? this.getRowsFromCSV(this.filePath)
76
+ : this.parseArray(this.data);
77
+
78
+ const response = await this.supabase.insertRow(this.table, data);
79
+
80
+ $.export("$summary", `Successfully inserted rows into table ${this.table}`);
81
+ return response;
82
+ },
83
+ };
@@ -4,7 +4,7 @@ export default {
4
4
  key: "supabase-delete-row",
5
5
  name: "Delete Row",
6
6
  type: "action",
7
- version: "0.1.2",
7
+ version: "0.1.3",
8
8
  description: "Deletes row(s) in a database. [See the docs here](https://supabase.com/docs/reference/javascript/delete)",
9
9
  props: {
10
10
  supabase,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "supabase-insert-row",
5
5
  name: "Insert Row",
6
6
  type: "action",
7
- version: "0.1.2",
7
+ version: "0.1.3",
8
8
  description: "Inserts a new row into a database. [See the docs here](https://supabase.com/docs/reference/javascript/insert)",
9
9
  props: {
10
10
  supabase,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "supabase-remote-procedure-call",
5
5
  name: "Remote Procedure Call",
6
6
  type: "action",
7
- version: "0.1.2",
7
+ version: "0.1.3",
8
8
  description: "Call a Postgres function in a database. [See the docs here](https://supabase.com/docs/reference/javascript/rpc)",
9
9
  props: {
10
10
  supabase,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "supabase-select-row",
6
6
  name: "Select Row",
7
7
  type: "action",
8
- version: "0.1.2",
8
+ version: "0.1.3",
9
9
  description: "Selects row(s) in a database. [See the docs here](https://supabase.com/docs/reference/javascript/select)",
10
10
  props: {
11
11
  supabase,
@@ -81,7 +81,7 @@ export default {
81
81
  sortOrder,
82
82
  max,
83
83
  });
84
- $.export("$summary", `Successfully retrieved ${response.length} rows from table ${table}`);
84
+ $.export("$summary", `Successfully retrieved ${response.data?.length || 0} row(s) from table ${table}`);
85
85
  return response;
86
86
  },
87
87
  };
@@ -4,7 +4,7 @@ export default {
4
4
  key: "supabase-update-row",
5
5
  name: "Update Row",
6
6
  type: "action",
7
- version: "0.1.2",
7
+ version: "0.1.3",
8
8
  description: "Updates row(s) in a database. [See the docs here](https://supabase.com/docs/reference/javascript/update)",
9
9
  props: {
10
10
  supabase,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "supabase-upsert-row",
5
5
  name: "Upsert Row",
6
6
  type: "action",
7
- version: "0.1.2",
7
+ version: "0.1.3",
8
8
  description: "Updates a row in a database or inserts new row if not found. [See the docs here](https://supabase.com/docs/reference/javascript/upsert)",
9
9
  props: {
10
10
  supabase,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/supabase",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Pipedream Supabase Components",
5
5
  "main": "supabase.app.mjs",
6
6
  "keywords": [
@@ -13,7 +13,8 @@
13
13
  "access": "public"
14
14
  },
15
15
  "dependencies": {
16
- "@pipedream/platform": "^1.2.1",
17
- "@supabase/supabase-js": "^2.45.6"
16
+ "@pipedream/platform": "^3.0.3",
17
+ "@supabase/supabase-js": "^2.45.6",
18
+ "csv-parse": "^5.5.6"
18
19
  }
19
20
  }
@@ -9,7 +9,7 @@ export default {
9
9
  key: "supabase-new-row-added",
10
10
  name: "New Row Added",
11
11
  description: "Emit new event for every new row added in a table. [See documentation here](https://supabase.com/docs/reference/javascript/select)",
12
- version: "0.0.4",
12
+ version: "0.0.5",
13
13
  type: "source",
14
14
  props: {
15
15
  ...base.props,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "supabase-new-webhook-event",
6
6
  name: "New Webhook Event (Instant)",
7
7
  description: "Emit new event for every `insert`, `update`, or `delete` operation in a table. This source requires user configuration using the Supabase website. More information in the README. [Also see documentation here](https://supabase.com/docs/guides/database/webhooks#creating-a-webhook)",
8
- version: "0.0.5",
8
+ version: "0.0.6",
9
9
  type: "source",
10
10
  props: {
11
11
  ...base.props,
package/supabase.app.mjs CHANGED
@@ -52,6 +52,30 @@ export default {
52
52
  async _client() {
53
53
  return createClient(`https://${this.$auth.subdomain}.supabase.co`, this.$auth.service_key);
54
54
  },
55
+ retryWithExponentialBackoff(func, maxAttempts = 3, baseDelayS = 2) {
56
+ let attempt = 0;
57
+ const verifyForErrors = this.verifyForErrors;
58
+
59
+ const execute = async () => {
60
+ try {
61
+ const resp = await func();
62
+ verifyForErrors(resp);
63
+ return resp;
64
+ } catch (error) {
65
+ if (attempt === maxAttempts - 1) {
66
+ throw error;
67
+ }
68
+
69
+ const delayMs = Math.pow(baseDelayS, attempt) * 1000;
70
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
71
+
72
+ attempt++;
73
+ return execute();
74
+ }
75
+ };
76
+
77
+ return execute();
78
+ },
55
79
  async selectRow(args) {
56
80
  const client = await this._client();
57
81
  const {
@@ -63,13 +87,14 @@ export default {
63
87
  ascending = args.sortOrder === "ascending",
64
88
  max,
65
89
  } = args;
66
- const query = this.baseFilter(client, table, orderBy, ascending, max);
67
- if (filter) {
68
- const filterMethod = this[filter];
69
- filterMethod(query, column, value);
70
- }
71
- const resp = await query;
72
- this.verifyForErrors(resp);
90
+ const ctx = this;
91
+ const resp = await this.retryWithExponentialBackoff(async () => {
92
+ let query = ctx.baseFilter(client, table, orderBy, ascending, max);
93
+ if (filter) {
94
+ query = ctx[filter](query, column, value);
95
+ }
96
+ return await query;
97
+ });
73
98
  return resp;
74
99
  },
75
100
  baseFilter(client, table, orderBy, ascending, max) {