@hot-updater/postgres 0.18.3 → 0.18.5

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
@@ -103,33 +103,39 @@ const postgres = (config, hooks) => {
103
103
  },
104
104
  async commitBundle(context, { changedSets }) {
105
105
  if (changedSets.length === 0) return;
106
- const bundles = changedSets.map((op) => op.data);
107
106
  await context.db.transaction().execute(async (tx) => {
108
- for (const bundle of bundles) await tx.insertInto("bundles").values({
109
- id: bundle.id,
110
- enabled: bundle.enabled,
111
- should_force_update: bundle.shouldForceUpdate,
112
- file_hash: bundle.fileHash,
113
- git_commit_hash: bundle.gitCommitHash,
114
- message: bundle.message,
115
- platform: bundle.platform,
116
- target_app_version: bundle.targetAppVersion,
117
- channel: bundle.channel,
118
- storage_uri: bundle.storageUri,
119
- fingerprint_hash: bundle.fingerprintHash
120
- }).onConflict((oc) => oc.column("id").doUpdateSet({
121
- enabled: bundle.enabled,
122
- should_force_update: bundle.shouldForceUpdate,
123
- file_hash: bundle.fileHash,
124
- git_commit_hash: bundle.gitCommitHash,
125
- message: bundle.message,
126
- platform: bundle.platform,
127
- target_app_version: bundle.targetAppVersion,
128
- channel: bundle.channel,
129
- storage_uri: bundle.storageUri,
130
- fingerprint_hash: bundle.fingerprintHash
131
- })).execute();
107
+ for (const op of changedSets) if (op.operation === "delete") {
108
+ const result = await tx.deleteFrom("bundles").where("id", "=", op.data.id).executeTakeFirst();
109
+ if (result.numDeletedRows === 0n) throw new Error(`Bundle with id ${op.data.id} not found`);
110
+ } else if (op.operation === "insert" || op.operation === "update") {
111
+ const bundle = op.data;
112
+ await tx.insertInto("bundles").values({
113
+ id: bundle.id,
114
+ enabled: bundle.enabled,
115
+ should_force_update: bundle.shouldForceUpdate,
116
+ file_hash: bundle.fileHash,
117
+ git_commit_hash: bundle.gitCommitHash,
118
+ message: bundle.message,
119
+ platform: bundle.platform,
120
+ target_app_version: bundle.targetAppVersion,
121
+ channel: bundle.channel,
122
+ storage_uri: bundle.storageUri,
123
+ fingerprint_hash: bundle.fingerprintHash
124
+ }).onConflict((oc) => oc.column("id").doUpdateSet({
125
+ enabled: bundle.enabled,
126
+ should_force_update: bundle.shouldForceUpdate,
127
+ file_hash: bundle.fileHash,
128
+ git_commit_hash: bundle.gitCommitHash,
129
+ message: bundle.message,
130
+ platform: bundle.platform,
131
+ target_app_version: bundle.targetAppVersion,
132
+ channel: bundle.channel,
133
+ storage_uri: bundle.storageUri,
134
+ fingerprint_hash: bundle.fingerprintHash
135
+ })).execute();
136
+ }
132
137
  });
138
+ hooks?.onDatabaseUpdated?.();
133
139
  }
134
140
  }, hooks);
135
141
  };
package/dist/index.js CHANGED
@@ -105,33 +105,39 @@ const postgres = (config, hooks) => {
105
105
  },
106
106
  async commitBundle(context, { changedSets }) {
107
107
  if (changedSets.length === 0) return;
108
- const bundles = changedSets.map((op) => op.data);
109
108
  await context.db.transaction().execute(async (tx) => {
110
- for (const bundle of bundles) await tx.insertInto("bundles").values({
111
- id: bundle.id,
112
- enabled: bundle.enabled,
113
- should_force_update: bundle.shouldForceUpdate,
114
- file_hash: bundle.fileHash,
115
- git_commit_hash: bundle.gitCommitHash,
116
- message: bundle.message,
117
- platform: bundle.platform,
118
- target_app_version: bundle.targetAppVersion,
119
- channel: bundle.channel,
120
- storage_uri: bundle.storageUri,
121
- fingerprint_hash: bundle.fingerprintHash
122
- }).onConflict((oc) => oc.column("id").doUpdateSet({
123
- enabled: bundle.enabled,
124
- should_force_update: bundle.shouldForceUpdate,
125
- file_hash: bundle.fileHash,
126
- git_commit_hash: bundle.gitCommitHash,
127
- message: bundle.message,
128
- platform: bundle.platform,
129
- target_app_version: bundle.targetAppVersion,
130
- channel: bundle.channel,
131
- storage_uri: bundle.storageUri,
132
- fingerprint_hash: bundle.fingerprintHash
133
- })).execute();
109
+ for (const op of changedSets) if (op.operation === "delete") {
110
+ const result = await tx.deleteFrom("bundles").where("id", "=", op.data.id).executeTakeFirst();
111
+ if (result.numDeletedRows === 0n) throw new Error(`Bundle with id ${op.data.id} not found`);
112
+ } else if (op.operation === "insert" || op.operation === "update") {
113
+ const bundle = op.data;
114
+ await tx.insertInto("bundles").values({
115
+ id: bundle.id,
116
+ enabled: bundle.enabled,
117
+ should_force_update: bundle.shouldForceUpdate,
118
+ file_hash: bundle.fileHash,
119
+ git_commit_hash: bundle.gitCommitHash,
120
+ message: bundle.message,
121
+ platform: bundle.platform,
122
+ target_app_version: bundle.targetAppVersion,
123
+ channel: bundle.channel,
124
+ storage_uri: bundle.storageUri,
125
+ fingerprint_hash: bundle.fingerprintHash
126
+ }).onConflict((oc) => oc.column("id").doUpdateSet({
127
+ enabled: bundle.enabled,
128
+ should_force_update: bundle.shouldForceUpdate,
129
+ file_hash: bundle.fileHash,
130
+ git_commit_hash: bundle.gitCommitHash,
131
+ message: bundle.message,
132
+ platform: bundle.platform,
133
+ target_app_version: bundle.targetAppVersion,
134
+ channel: bundle.channel,
135
+ storage_uri: bundle.storageUri,
136
+ fingerprint_hash: bundle.fingerprintHash
137
+ })).execute();
138
+ }
134
139
  });
140
+ hooks?.onDatabaseUpdated?.();
135
141
  }
136
142
  }, hooks);
137
143
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/postgres",
3
3
  "type": "module",
4
- "version": "0.18.3",
4
+ "version": "0.18.5",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -31,15 +31,15 @@
31
31
  "dependencies": {
32
32
  "kysely": "^0.27.5",
33
33
  "pg": "^8.13.1",
34
- "@hot-updater/core": "0.18.3",
35
- "@hot-updater/plugin-core": "0.18.3"
34
+ "@hot-updater/core": "0.18.5",
35
+ "@hot-updater/plugin-core": "0.18.5"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@electric-sql/pglite": "^0.2.15",
39
39
  "@types/pg": "^8.11.10",
40
40
  "camelcase-keys": "^9.1.3",
41
41
  "pg-minify": "^1.6.5",
42
- "@hot-updater/js": "0.18.3"
42
+ "@hot-updater/js": "0.18.5"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "tsdown",