@hot-updater/supabase 0.6.5 → 0.6.7

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.
package/dist/index.cjs CHANGED
@@ -48,10 +48,17 @@ const supabase_js_namespaceObject = require("@supabase/supabase-js");
48
48
  const supabaseDatabase = (config, hooks)=>(_)=>{
49
49
  const supabase = (0, supabase_js_namespaceObject.createClient)(config.supabaseUrl, config.supabaseAnonKey);
50
50
  let bundles = [];
51
+ const changedIds = new Set();
52
+ function markChanged(id) {
53
+ changedIds.add(id);
54
+ }
51
55
  return {
52
56
  name: "supabaseDatabase",
53
57
  async commitBundle () {
54
- await supabase.from("bundles").upsert(bundles.map((bundle)=>({
58
+ if (0 === changedIds.size) return;
59
+ const changedBundles = bundles.filter((b)=>changedIds.has(b.id));
60
+ if (0 === changedBundles.length) return;
61
+ await supabase.from("bundles").upsert(changedBundles.map((bundle)=>({
55
62
  id: bundle.id,
56
63
  enabled: bundle.enabled,
57
64
  file_url: bundle.fileUrl,
@@ -64,6 +71,7 @@ const supabaseDatabase = (config, hooks)=>(_)=>{
64
71
  })), {
65
72
  onConflict: "id"
66
73
  });
74
+ changedIds.clear();
67
75
  hooks?.onDatabaseUpdated?.();
68
76
  },
69
77
  async updateBundle (targetBundleId, newBundle) {
@@ -71,13 +79,12 @@ const supabaseDatabase = (config, hooks)=>(_)=>{
71
79
  const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
72
80
  if (-1 === targetIndex) throw new Error("target bundle version not found");
73
81
  Object.assign(bundles[targetIndex], newBundle);
82
+ markChanged(targetBundleId);
74
83
  },
75
84
  async appendBundle (inputBundle) {
76
85
  bundles = await this.getBundles();
77
86
  bundles.unshift(inputBundle);
78
- },
79
- async setBundles (inputBundles) {
80
- bundles = inputBundles;
87
+ markChanged(inputBundle.id);
81
88
  },
82
89
  async getBundleById (bundleId) {
83
90
  const { data } = await supabase.from("bundles").select("*").eq("id", bundleId).single();
package/dist/index.js CHANGED
@@ -4,10 +4,17 @@ import * as __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__ from "fs/promises";
4
4
  const supabaseDatabase = (config, hooks)=>(_)=>{
5
5
  const supabase = (0, __WEBPACK_EXTERNAL_MODULE__supabase_supabase_js_06b6e9fe__.createClient)(config.supabaseUrl, config.supabaseAnonKey);
6
6
  let bundles = [];
7
+ const changedIds = new Set();
8
+ function markChanged(id) {
9
+ changedIds.add(id);
10
+ }
7
11
  return {
8
12
  name: "supabaseDatabase",
9
13
  async commitBundle () {
10
- await supabase.from("bundles").upsert(bundles.map((bundle)=>({
14
+ if (0 === changedIds.size) return;
15
+ const changedBundles = bundles.filter((b)=>changedIds.has(b.id));
16
+ if (0 === changedBundles.length) return;
17
+ await supabase.from("bundles").upsert(changedBundles.map((bundle)=>({
11
18
  id: bundle.id,
12
19
  enabled: bundle.enabled,
13
20
  file_url: bundle.fileUrl,
@@ -20,6 +27,7 @@ const supabaseDatabase = (config, hooks)=>(_)=>{
20
27
  })), {
21
28
  onConflict: "id"
22
29
  });
30
+ changedIds.clear();
23
31
  hooks?.onDatabaseUpdated?.();
24
32
  },
25
33
  async updateBundle (targetBundleId, newBundle) {
@@ -27,13 +35,12 @@ const supabaseDatabase = (config, hooks)=>(_)=>{
27
35
  const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
28
36
  if (-1 === targetIndex) throw new Error("target bundle version not found");
29
37
  Object.assign(bundles[targetIndex], newBundle);
38
+ markChanged(targetBundleId);
30
39
  },
31
40
  async appendBundle (inputBundle) {
32
41
  bundles = await this.getBundles();
33
42
  bundles.unshift(inputBundle);
34
- },
35
- async setBundles (inputBundles) {
36
- bundles = inputBundles;
43
+ markChanged(inputBundle.id);
37
44
  },
38
45
  async getBundleById (bundleId) {
39
46
  const { data } = await supabase.from("bundles").select("*").eq("id", bundleId).single();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/supabase",
3
3
  "type": "module",
4
- "version": "0.6.5",
4
+ "version": "0.6.7",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -30,13 +30,13 @@
30
30
  "package.json"
31
31
  ],
32
32
  "dependencies": {
33
- "@hot-updater/core": "0.6.5",
34
- "@hot-updater/plugin-core": "0.6.5",
33
+ "@hot-updater/core": "0.6.7",
34
+ "@hot-updater/plugin-core": "0.6.7",
35
35
  "@supabase/supabase-js": "^2.47.10"
36
36
  },
37
37
  "devDependencies": {
38
38
  "picocolors": "^1.0.0",
39
- "@hot-updater/postgres": "0.6.5",
39
+ "@hot-updater/postgres": "0.6.7",
40
40
  "dayjs": "^1.11.13",
41
41
  "mime": "^4.0.4"
42
42
  },