@hot-updater/postgres 0.1.6-0 → 0.3.0
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 +121 -123
- package/dist/index.d.ts +1 -8
- package/dist/index.js +90 -99
- package/dist/postgres.d.ts +5 -0
- package/dist/types.d.ts +10 -0
- package/package.json +12 -5
- package/sql/bundles.sql +5 -1
- package/sql/get_update_info.sql +13 -11
- package/sql/get_update_info.test.ts +2 -2
- package/sql/{semver.sql → semver_satisfies.sql} +2 -0
- package/sql/semver_satisfies.test.ts +2 -2
- package/dist/index.d.cts +0 -8
package/dist/index.cjs
CHANGED
|
@@ -1,126 +1,124 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = function(exports1, definition) {
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = function(obj, prop) {
|
|
13
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
(()=>{
|
|
17
|
+
__webpack_require__.r = function(exports1) {
|
|
18
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
19
|
+
value: 'Module'
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
22
|
+
value: true
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
var __webpack_exports__ = {};
|
|
27
|
+
__webpack_require__.r(__webpack_exports__);
|
|
28
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
29
|
+
postgres: ()=>postgres
|
|
24
30
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
targetVersion: bundle.target_version
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
124
|
-
0 && (module.exports = {
|
|
125
|
-
postgres
|
|
31
|
+
const external_kysely_namespaceObject = require("kysely");
|
|
32
|
+
const external_pg_namespaceObject = require("pg");
|
|
33
|
+
const postgres = (config, hooks)=>(_)=>{
|
|
34
|
+
const pool = new external_pg_namespaceObject.Pool(config);
|
|
35
|
+
const dialect = new external_kysely_namespaceObject.PostgresDialect({
|
|
36
|
+
pool
|
|
37
|
+
});
|
|
38
|
+
const db = new external_kysely_namespaceObject.Kysely({
|
|
39
|
+
dialect
|
|
40
|
+
});
|
|
41
|
+
let bundles = [];
|
|
42
|
+
let isUnmount = false;
|
|
43
|
+
return {
|
|
44
|
+
name: "postgres",
|
|
45
|
+
async onUnmount () {
|
|
46
|
+
if (isUnmount) return;
|
|
47
|
+
isUnmount = true;
|
|
48
|
+
await pool.end();
|
|
49
|
+
},
|
|
50
|
+
async commitBundle () {
|
|
51
|
+
await db.transaction().execute(async (tx)=>{
|
|
52
|
+
for (const bundle of bundles)await tx.insertInto("bundles").values({
|
|
53
|
+
id: bundle.id,
|
|
54
|
+
enabled: bundle.enabled,
|
|
55
|
+
file_url: bundle.fileUrl,
|
|
56
|
+
force_update: bundle.forceUpdate,
|
|
57
|
+
file_hash: bundle.fileHash,
|
|
58
|
+
git_commit_hash: bundle.gitCommitHash,
|
|
59
|
+
message: bundle.message,
|
|
60
|
+
platform: bundle.platform,
|
|
61
|
+
target_app_version: bundle.targetAppVersion
|
|
62
|
+
}).onConflict((oc)=>oc.column("id").doUpdateSet({
|
|
63
|
+
enabled: bundle.enabled,
|
|
64
|
+
file_url: bundle.fileUrl,
|
|
65
|
+
force_update: bundle.forceUpdate,
|
|
66
|
+
file_hash: bundle.fileHash,
|
|
67
|
+
git_commit_hash: bundle.gitCommitHash,
|
|
68
|
+
message: bundle.message,
|
|
69
|
+
platform: bundle.platform,
|
|
70
|
+
target_app_version: bundle.targetAppVersion
|
|
71
|
+
})).execute();
|
|
72
|
+
});
|
|
73
|
+
hooks?.onDatabaseUpdated?.();
|
|
74
|
+
},
|
|
75
|
+
async updateBundle (targetBundleId, newBundle) {
|
|
76
|
+
bundles = await this.getBundles();
|
|
77
|
+
const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
|
|
78
|
+
if (-1 === targetIndex) throw new Error("target bundle version not found");
|
|
79
|
+
Object.assign(bundles[targetIndex], newBundle);
|
|
80
|
+
},
|
|
81
|
+
async appendBundle (inputBundle) {
|
|
82
|
+
bundles = await this.getBundles();
|
|
83
|
+
bundles.unshift(inputBundle);
|
|
84
|
+
},
|
|
85
|
+
async setBundles (inputBundles) {
|
|
86
|
+
bundles = inputBundles;
|
|
87
|
+
},
|
|
88
|
+
async getBundleById (bundleId) {
|
|
89
|
+
const data = await db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
|
|
90
|
+
if (!data) return null;
|
|
91
|
+
return {
|
|
92
|
+
enabled: data.enabled,
|
|
93
|
+
fileUrl: data.file_url,
|
|
94
|
+
forceUpdate: data.force_update,
|
|
95
|
+
fileHash: data.file_hash,
|
|
96
|
+
gitCommitHash: data.git_commit_hash,
|
|
97
|
+
id: data.id,
|
|
98
|
+
message: data.message,
|
|
99
|
+
platform: data.platform,
|
|
100
|
+
targetAppVersion: data.target_app_version
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
async getBundles (refresh = false) {
|
|
104
|
+
if (bundles.length > 0 && !refresh) return bundles;
|
|
105
|
+
const data = await db.selectFrom("bundles").orderBy("id", "desc").selectAll().execute();
|
|
106
|
+
return data.map((bundle)=>({
|
|
107
|
+
enabled: bundle.enabled,
|
|
108
|
+
fileUrl: bundle.file_url,
|
|
109
|
+
forceUpdate: bundle.force_update,
|
|
110
|
+
fileHash: bundle.file_hash,
|
|
111
|
+
gitCommitHash: bundle.git_commit_hash,
|
|
112
|
+
id: bundle.id,
|
|
113
|
+
message: bundle.message,
|
|
114
|
+
platform: bundle.platform,
|
|
115
|
+
targetAppVersion: bundle.target_app_version
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
var __webpack_export_target__ = exports;
|
|
121
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
122
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
123
|
+
value: true
|
|
126
124
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { PoolConfig } from 'pg';
|
|
3
|
-
|
|
4
|
-
interface PostgresConfig extends PoolConfig {
|
|
5
|
-
}
|
|
6
|
-
declare const postgres: (config: PostgresConfig, hooks?: DatabasePluginHooks) => (_: BasePluginArgs) => DatabasePlugin;
|
|
7
|
-
|
|
8
|
-
export { type PostgresConfig, postgres };
|
|
1
|
+
export * from "./postgres";
|
package/dist/index.js
CHANGED
|
@@ -1,99 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
platform: bundle.platform,
|
|
92
|
-
targetVersion: bundle.target_version
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
export {
|
|
98
|
-
postgres
|
|
99
|
-
};
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_kysely__ from "kysely";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_pg__ from "pg";
|
|
3
|
+
const postgres = (config, hooks)=>(_)=>{
|
|
4
|
+
const pool = new __WEBPACK_EXTERNAL_MODULE_pg__.Pool(config);
|
|
5
|
+
const dialect = new __WEBPACK_EXTERNAL_MODULE_kysely__.PostgresDialect({
|
|
6
|
+
pool
|
|
7
|
+
});
|
|
8
|
+
const db = new __WEBPACK_EXTERNAL_MODULE_kysely__.Kysely({
|
|
9
|
+
dialect
|
|
10
|
+
});
|
|
11
|
+
let bundles = [];
|
|
12
|
+
let isUnmount = false;
|
|
13
|
+
return {
|
|
14
|
+
name: "postgres",
|
|
15
|
+
async onUnmount () {
|
|
16
|
+
if (isUnmount) return;
|
|
17
|
+
isUnmount = true;
|
|
18
|
+
await pool.end();
|
|
19
|
+
},
|
|
20
|
+
async commitBundle () {
|
|
21
|
+
await db.transaction().execute(async (tx)=>{
|
|
22
|
+
for (const bundle of bundles)await tx.insertInto("bundles").values({
|
|
23
|
+
id: bundle.id,
|
|
24
|
+
enabled: bundle.enabled,
|
|
25
|
+
file_url: bundle.fileUrl,
|
|
26
|
+
force_update: bundle.forceUpdate,
|
|
27
|
+
file_hash: bundle.fileHash,
|
|
28
|
+
git_commit_hash: bundle.gitCommitHash,
|
|
29
|
+
message: bundle.message,
|
|
30
|
+
platform: bundle.platform,
|
|
31
|
+
target_app_version: bundle.targetAppVersion
|
|
32
|
+
}).onConflict((oc)=>oc.column("id").doUpdateSet({
|
|
33
|
+
enabled: bundle.enabled,
|
|
34
|
+
file_url: bundle.fileUrl,
|
|
35
|
+
force_update: bundle.forceUpdate,
|
|
36
|
+
file_hash: bundle.fileHash,
|
|
37
|
+
git_commit_hash: bundle.gitCommitHash,
|
|
38
|
+
message: bundle.message,
|
|
39
|
+
platform: bundle.platform,
|
|
40
|
+
target_app_version: bundle.targetAppVersion
|
|
41
|
+
})).execute();
|
|
42
|
+
});
|
|
43
|
+
hooks?.onDatabaseUpdated?.();
|
|
44
|
+
},
|
|
45
|
+
async updateBundle (targetBundleId, newBundle) {
|
|
46
|
+
bundles = await this.getBundles();
|
|
47
|
+
const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
|
|
48
|
+
if (-1 === targetIndex) throw new Error("target bundle version not found");
|
|
49
|
+
Object.assign(bundles[targetIndex], newBundle);
|
|
50
|
+
},
|
|
51
|
+
async appendBundle (inputBundle) {
|
|
52
|
+
bundles = await this.getBundles();
|
|
53
|
+
bundles.unshift(inputBundle);
|
|
54
|
+
},
|
|
55
|
+
async setBundles (inputBundles) {
|
|
56
|
+
bundles = inputBundles;
|
|
57
|
+
},
|
|
58
|
+
async getBundleById (bundleId) {
|
|
59
|
+
const data = await db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
|
|
60
|
+
if (!data) return null;
|
|
61
|
+
return {
|
|
62
|
+
enabled: data.enabled,
|
|
63
|
+
fileUrl: data.file_url,
|
|
64
|
+
forceUpdate: data.force_update,
|
|
65
|
+
fileHash: data.file_hash,
|
|
66
|
+
gitCommitHash: data.git_commit_hash,
|
|
67
|
+
id: data.id,
|
|
68
|
+
message: data.message,
|
|
69
|
+
platform: data.platform,
|
|
70
|
+
targetAppVersion: data.target_app_version
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
async getBundles (refresh = false) {
|
|
74
|
+
if (bundles.length > 0 && !refresh) return bundles;
|
|
75
|
+
const data = await db.selectFrom("bundles").orderBy("id", "desc").selectAll().execute();
|
|
76
|
+
return data.map((bundle)=>({
|
|
77
|
+
enabled: bundle.enabled,
|
|
78
|
+
fileUrl: bundle.file_url,
|
|
79
|
+
forceUpdate: bundle.force_update,
|
|
80
|
+
fileHash: bundle.file_hash,
|
|
81
|
+
gitCommitHash: bundle.git_commit_hash,
|
|
82
|
+
id: bundle.id,
|
|
83
|
+
message: bundle.message,
|
|
84
|
+
platform: bundle.platform,
|
|
85
|
+
targetAppVersion: bundle.target_app_version
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export { postgres };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BasePluginArgs, DatabasePlugin, DatabasePluginHooks } from "@hot-updater/plugin-core";
|
|
2
|
+
import { type PoolConfig } from "pg";
|
|
3
|
+
export interface PostgresConfig extends PoolConfig {
|
|
4
|
+
}
|
|
5
|
+
export declare const postgres: (config: PostgresConfig, hooks?: DatabasePluginHooks) => (_: BasePluginArgs) => DatabasePlugin;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Bundle } from "@hot-updater/core";
|
|
2
|
+
type SnakeCase<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? "_" : ""}${Lowercase<T>}${SnakeCase<U>}` : S;
|
|
3
|
+
type SnakeKeyObject<T> = T extends Record<string, any> ? {
|
|
4
|
+
[K in keyof T as SnakeCase<Extract<K, string>>]: T[K] extends object ? SnakeKeyObject<T[K]> : T[K];
|
|
5
|
+
} : T;
|
|
6
|
+
export type BundlesTable = SnakeKeyObject<Bundle>;
|
|
7
|
+
export interface Database {
|
|
8
|
+
bundles: BundlesTable;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/postgres",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./sql": "./sql"
|
|
14
|
+
},
|
|
8
15
|
"types": "dist/index.d.ts",
|
|
9
16
|
"license": "MIT",
|
|
10
17
|
"repository": "https://github.com/gronxb/hot-updater",
|
|
@@ -22,9 +29,9 @@
|
|
|
22
29
|
"package.json"
|
|
23
30
|
],
|
|
24
31
|
"dependencies": {
|
|
25
|
-
"@hot-updater/core": "0.
|
|
26
|
-
"@hot-updater/plugin-core": "0.
|
|
27
|
-
"kysely": "^0.27.
|
|
32
|
+
"@hot-updater/core": "0.3.0",
|
|
33
|
+
"@hot-updater/plugin-core": "0.3.0",
|
|
34
|
+
"kysely": "^0.27.5",
|
|
28
35
|
"pg": "^8.13.1"
|
|
29
36
|
},
|
|
30
37
|
"devDependencies": {
|
|
@@ -33,7 +40,7 @@
|
|
|
33
40
|
"camelcase-keys": "^9.1.3"
|
|
34
41
|
},
|
|
35
42
|
"scripts": {
|
|
36
|
-
"build": "
|
|
43
|
+
"build": "rslib build",
|
|
37
44
|
"test:type": "tsc --noEmit"
|
|
38
45
|
}
|
|
39
46
|
}
|
package/sql/bundles.sql
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
-- HotUpdater.bundles
|
|
2
|
+
|
|
1
3
|
CREATE TYPE platforms AS ENUM ('ios', 'android');
|
|
2
4
|
|
|
3
5
|
CREATE TABLE bundles (
|
|
4
6
|
id uuid PRIMARY KEY,
|
|
5
7
|
platform platforms NOT NULL,
|
|
6
|
-
|
|
8
|
+
target_app_version text NOT NULL,
|
|
7
9
|
force_update boolean NOT NULL,
|
|
8
10
|
enabled boolean NOT NULL,
|
|
9
11
|
file_url text NOT NULL,
|
|
@@ -11,3 +13,5 @@ CREATE TABLE bundles (
|
|
|
11
13
|
git_commit_hash text,
|
|
12
14
|
message text
|
|
13
15
|
);
|
|
16
|
+
|
|
17
|
+
CREATE INDEX bundles_target_app_version_idx ON bundles(target_app_version);
|
package/sql/get_update_info.sql
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
-- HotUpdater.get_update_info
|
|
2
|
+
|
|
1
3
|
CREATE OR REPLACE FUNCTION get_update_info (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
app_platform platforms,
|
|
5
|
+
app_version text,
|
|
6
|
+
bundle_id uuid
|
|
5
7
|
)
|
|
6
8
|
RETURNS TABLE (
|
|
7
9
|
id uuid,
|
|
@@ -27,8 +29,8 @@ BEGIN
|
|
|
27
29
|
'ROLLBACK' AS status
|
|
28
30
|
FROM bundles b
|
|
29
31
|
WHERE b.enabled = TRUE
|
|
30
|
-
AND b.platform =
|
|
31
|
-
AND b.id <
|
|
32
|
+
AND b.platform = app_platform
|
|
33
|
+
AND b.id < bundle_id
|
|
32
34
|
ORDER BY b.id DESC
|
|
33
35
|
LIMIT 1
|
|
34
36
|
),
|
|
@@ -41,9 +43,9 @@ BEGIN
|
|
|
41
43
|
'UPDATE' AS status
|
|
42
44
|
FROM bundles b
|
|
43
45
|
WHERE b.enabled = TRUE
|
|
44
|
-
AND b.platform =
|
|
45
|
-
AND b.id >=
|
|
46
|
-
AND semver_satisfies(b.
|
|
46
|
+
AND b.platform = app_platform
|
|
47
|
+
AND b.id >= bundle_id
|
|
48
|
+
AND semver_satisfies(b.target_app_version, app_version)
|
|
47
49
|
ORDER BY b.id DESC
|
|
48
50
|
LIMIT 1
|
|
49
51
|
),
|
|
@@ -58,11 +60,11 @@ BEGIN
|
|
|
58
60
|
WHERE NOT EXISTS (SELECT 1 FROM update_candidate)
|
|
59
61
|
)
|
|
60
62
|
SELECT *
|
|
61
|
-
FROM final_result WHERE final_result.id !=
|
|
63
|
+
FROM final_result WHERE final_result.id != bundle_id
|
|
62
64
|
|
|
63
65
|
UNION ALL
|
|
64
66
|
/*
|
|
65
|
-
When there are no final results and
|
|
67
|
+
When there are no final results and bundle_id != NIL_UUID,
|
|
66
68
|
add one fallback row.
|
|
67
69
|
This fallback row is also ROLLBACK so forceUpdate = TRUE.
|
|
68
70
|
*/
|
|
@@ -73,7 +75,7 @@ BEGIN
|
|
|
73
75
|
NULL AS file_hash,
|
|
74
76
|
'ROLLBACK' AS status
|
|
75
77
|
WHERE (SELECT COUNT(*) FROM final_result) = 0
|
|
76
|
-
AND
|
|
78
|
+
AND bundle_id != NIL_UUID;
|
|
77
79
|
|
|
78
80
|
END;
|
|
79
81
|
$$;
|
|
@@ -8,14 +8,14 @@ import { prepareSql } from "./prepareSql";
|
|
|
8
8
|
const createInsertBundleQuery = (bundle: Bundle) => {
|
|
9
9
|
return `
|
|
10
10
|
INSERT INTO bundles (
|
|
11
|
-
id, file_url, file_hash, platform,
|
|
11
|
+
id, file_url, file_hash, platform, target_app_version,
|
|
12
12
|
force_update, enabled, git_commit_hash, message
|
|
13
13
|
) VALUES (
|
|
14
14
|
'${bundle.id}',
|
|
15
15
|
'${bundle.fileUrl}',
|
|
16
16
|
'${bundle.fileHash}',
|
|
17
17
|
'${bundle.platform}',
|
|
18
|
-
'${bundle.
|
|
18
|
+
'${bundle.targetAppVersion}',
|
|
19
19
|
${bundle.forceUpdate},
|
|
20
20
|
${bundle.enabled},
|
|
21
21
|
${bundle.gitCommitHash ? `'${bundle.gitCommitHash}'` : "null"},
|
|
@@ -8,9 +8,9 @@ const sql = await prepareSql();
|
|
|
8
8
|
await db.exec(sql);
|
|
9
9
|
|
|
10
10
|
const createSemverSatisfies =
|
|
11
|
-
(db: PGlite) => async (
|
|
11
|
+
(db: PGlite) => async (targetAppVersion: string, currentVersion: string) => {
|
|
12
12
|
const result = await db.query<{ actual: boolean }>(`
|
|
13
|
-
SELECT semver_satisfies('${
|
|
13
|
+
SELECT semver_satisfies('${targetAppVersion}', '${currentVersion}') AS actual;
|
|
14
14
|
`);
|
|
15
15
|
return result.rows[0].actual;
|
|
16
16
|
};
|
package/dist/index.d.cts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { DatabasePluginHooks, BasePluginArgs, DatabasePlugin } from '@hot-updater/plugin-core';
|
|
2
|
-
import { PoolConfig } from 'pg';
|
|
3
|
-
|
|
4
|
-
interface PostgresConfig extends PoolConfig {
|
|
5
|
-
}
|
|
6
|
-
declare const postgres: (config: PostgresConfig, hooks?: DatabasePluginHooks) => (_: BasePluginArgs) => DatabasePlugin;
|
|
7
|
-
|
|
8
|
-
export { type PostgresConfig, postgres };
|