@hot-updater/postgres 0.18.1 → 0.18.2
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 +26 -13
- package/dist/index.d.cts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +27 -14
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -63,14 +63,19 @@ const postgres = (config, hooks) => {
|
|
|
63
63
|
};
|
|
64
64
|
},
|
|
65
65
|
async getBundles(context, options) {
|
|
66
|
-
const { where, limit, offset
|
|
66
|
+
const { where, limit, offset } = options ?? {};
|
|
67
|
+
let countQuery = context.db.selectFrom("bundles");
|
|
68
|
+
if (where?.channel) countQuery = countQuery.where("channel", "=", where.channel);
|
|
69
|
+
if (where?.platform) countQuery = countQuery.where("platform", "=", where.platform);
|
|
70
|
+
const countResult = await countQuery.select(context.db.fn.count("id").as("total")).executeTakeFirst();
|
|
71
|
+
const total = countResult?.total || 0;
|
|
67
72
|
let query = context.db.selectFrom("bundles").orderBy("id", "desc");
|
|
68
73
|
if (where?.channel) query = query.where("channel", "=", where.channel);
|
|
69
74
|
if (where?.platform) query = query.where("platform", "=", where.platform);
|
|
70
75
|
if (limit) query = query.limit(limit);
|
|
71
76
|
if (offset) query = query.offset(offset);
|
|
72
77
|
const data = await query.selectAll().execute();
|
|
73
|
-
|
|
78
|
+
const bundles = data.map((bundle) => ({
|
|
74
79
|
enabled: bundle.enabled,
|
|
75
80
|
shouldForceUpdate: bundle.should_force_update,
|
|
76
81
|
fileHash: bundle.file_hash,
|
|
@@ -83,6 +88,14 @@ const postgres = (config, hooks) => {
|
|
|
83
88
|
storageUri: bundle.storage_uri,
|
|
84
89
|
fingerprintHash: bundle.fingerprint_hash
|
|
85
90
|
}));
|
|
91
|
+
const pagination = (0, __hot_updater_plugin_core.calculatePagination)(total, {
|
|
92
|
+
limit,
|
|
93
|
+
offset
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
data: bundles,
|
|
97
|
+
pagination
|
|
98
|
+
};
|
|
86
99
|
},
|
|
87
100
|
async getChannels(context) {
|
|
88
101
|
const data = await context.db.selectFrom("bundles").select("channel").groupBy("channel").execute();
|
|
@@ -674,7 +687,7 @@ var require_lrucache = __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_
|
|
|
674
687
|
var LRUCache = class {
|
|
675
688
|
constructor() {
|
|
676
689
|
this.max = 1e3;
|
|
677
|
-
this.map = new Map();
|
|
690
|
+
this.map = /* @__PURE__ */ new Map();
|
|
678
691
|
}
|
|
679
692
|
get(key) {
|
|
680
693
|
const value = this.map.get(key);
|
|
@@ -775,7 +788,7 @@ var require_range = __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_mod
|
|
|
775
788
|
return !!comp.match(re$1[t$1.COMPARATORLOOSE]);
|
|
776
789
|
});
|
|
777
790
|
debug$1("range list", rangeList);
|
|
778
|
-
const rangeMap = new Map();
|
|
791
|
+
const rangeMap = /* @__PURE__ */ new Map();
|
|
779
792
|
const comparators = rangeList.map((comp) => new Comparator$4(comp, this.options));
|
|
780
793
|
for (const comp of comparators) {
|
|
781
794
|
if (isNullSet(comp)) return [comp];
|
|
@@ -1287,7 +1300,7 @@ var require_subset = __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_mo
|
|
|
1287
1300
|
else sub = minimumVersion;
|
|
1288
1301
|
if (dom.length === 1 && dom[0].semver === ANY) if (options.includePrerelease) return true;
|
|
1289
1302
|
else dom = minimumVersion;
|
|
1290
|
-
const eqSet = new Set();
|
|
1303
|
+
const eqSet = /* @__PURE__ */ new Set();
|
|
1291
1304
|
let gt$5, lt$4;
|
|
1292
1305
|
for (const c of sub) if (c.operator === ">" || c.operator === ">=") gt$5 = higherGT(gt$5, c, options);
|
|
1293
1306
|
else if (c.operator === "<" || c.operator === "<=") lt$4 = lowerLT(lt$4, c, options);
|
|
@@ -1440,7 +1453,7 @@ var require_semver = __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_mo
|
|
|
1440
1453
|
rcompareIdentifiers: identifiers.rcompareIdentifiers
|
|
1441
1454
|
};
|
|
1442
1455
|
} });
|
|
1443
|
-
var import_semver = __toESM(require_semver()
|
|
1456
|
+
var import_semver = __toESM(require_semver());
|
|
1444
1457
|
const semverSatisfies = (targetAppVersion, currentVersion) => {
|
|
1445
1458
|
const currentCoerce = import_semver.default.coerce(currentVersion);
|
|
1446
1459
|
if (!currentCoerce) return false;
|
|
@@ -1489,7 +1502,7 @@ const year = day * 365.25;
|
|
|
1489
1502
|
const isObject$1 = (value) => typeof value === "object" && value !== null;
|
|
1490
1503
|
const isObjectCustom = (value) => isObject$1(value) && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date);
|
|
1491
1504
|
const mapObjectSkip = Symbol("mapObjectSkip");
|
|
1492
|
-
const _mapObject = (object, mapper, options, isSeen = new WeakMap()) => {
|
|
1505
|
+
const _mapObject = (object, mapper, options, isSeen = /* @__PURE__ */ new WeakMap()) => {
|
|
1493
1506
|
options = {
|
|
1494
1507
|
deep: false,
|
|
1495
1508
|
target: {},
|
|
@@ -1596,8 +1609,8 @@ var QuickLRU = class extends Map {
|
|
|
1596
1609
|
this.maxSize = options.maxSize;
|
|
1597
1610
|
this.maxAge = options.maxAge || Number.POSITIVE_INFINITY;
|
|
1598
1611
|
this.onEviction = options.onEviction;
|
|
1599
|
-
this.cache = new Map();
|
|
1600
|
-
this.oldCache = new Map();
|
|
1612
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1613
|
+
this.oldCache = /* @__PURE__ */ new Map();
|
|
1601
1614
|
this._size = 0;
|
|
1602
1615
|
}
|
|
1603
1616
|
_emitEvictions(cache$1) {
|
|
@@ -1629,7 +1642,7 @@ var QuickLRU = class extends Map {
|
|
|
1629
1642
|
this._size = 0;
|
|
1630
1643
|
this._emitEvictions(this.oldCache);
|
|
1631
1644
|
this.oldCache = this.cache;
|
|
1632
|
-
this.cache = new Map();
|
|
1645
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1633
1646
|
}
|
|
1634
1647
|
}
|
|
1635
1648
|
_moveToRecent(key, item) {
|
|
@@ -1700,12 +1713,12 @@ var QuickLRU = class extends Map {
|
|
|
1700
1713
|
const removeCount = items.length - newSize;
|
|
1701
1714
|
if (removeCount < 0) {
|
|
1702
1715
|
this.cache = new Map(items);
|
|
1703
|
-
this.oldCache = new Map();
|
|
1716
|
+
this.oldCache = /* @__PURE__ */ new Map();
|
|
1704
1717
|
this._size = items.length;
|
|
1705
1718
|
} else {
|
|
1706
1719
|
if (removeCount > 0) this._emitEvictions(items.slice(0, removeCount));
|
|
1707
1720
|
this.oldCache = new Map(items.slice(removeCount));
|
|
1708
|
-
this.cache = new Map();
|
|
1721
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1709
1722
|
this._size = 0;
|
|
1710
1723
|
}
|
|
1711
1724
|
this.maxSize = newSize;
|
|
@@ -2048,7 +2061,7 @@ var require_lib = __commonJS$1({ "../../node_modules/.pnpm/pg-minify@1.6.5/node_
|
|
|
2048
2061
|
|
|
2049
2062
|
//#endregion
|
|
2050
2063
|
//#region src/getUpdateInfo.ts
|
|
2051
|
-
var import_lib = __toESM$1(require_lib()
|
|
2064
|
+
var import_lib = __toESM$1(require_lib());
|
|
2052
2065
|
const appVersionStrategy = async (pool, { platform, appVersion, bundleId, minBundleId = __hot_updater_core.NIL_UUID, channel = "production" }) => {
|
|
2053
2066
|
const sqlGetTargetAppVersionList = (0, import_lib.default)(`
|
|
2054
2067
|
SELECT target_app_version
|
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,6 @@ import { AppVersionGetBundlesArgs, GetBundlesArgs, UpdateInfo } from "@hot-updat
|
|
|
6
6
|
//#region src/postgres.d.ts
|
|
7
7
|
interface PostgresConfig extends PoolConfig {}
|
|
8
8
|
declare const postgres: (config: PostgresConfig, hooks?: DatabasePluginHooks) => (options: _hot_updater_plugin_core0.BasePluginArgs) => _hot_updater_plugin_core0.DatabasePlugin;
|
|
9
|
-
|
|
10
9
|
//#endregion
|
|
11
10
|
//#region src/getUpdateInfo.d.ts
|
|
12
11
|
declare const appVersionStrategy: (pool: pg.Pool, {
|
|
@@ -17,6 +16,5 @@ declare const appVersionStrategy: (pool: pg.Pool, {
|
|
|
17
16
|
channel
|
|
18
17
|
}: AppVersionGetBundlesArgs) => Promise<UpdateInfo | null>;
|
|
19
18
|
declare const getUpdateInfo: (pool: pg.Pool, args: GetBundlesArgs) => Promise<UpdateInfo | null> | null;
|
|
20
|
-
|
|
21
19
|
//#endregion
|
|
22
20
|
export { PostgresConfig, appVersionStrategy, getUpdateInfo, postgres };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { AppVersionGetBundlesArgs, GetBundlesArgs, UpdateInfo } from "@hot-updat
|
|
|
6
6
|
//#region src/postgres.d.ts
|
|
7
7
|
interface PostgresConfig extends PoolConfig {}
|
|
8
8
|
declare const postgres: (config: PostgresConfig, hooks?: DatabasePluginHooks) => (options: _hot_updater_plugin_core0.BasePluginArgs) => _hot_updater_plugin_core0.DatabasePlugin;
|
|
9
|
-
|
|
10
9
|
//#endregion
|
|
11
10
|
//#region src/getUpdateInfo.d.ts
|
|
12
11
|
declare const appVersionStrategy: (pool: pg.Pool, {
|
|
@@ -17,6 +16,5 @@ declare const appVersionStrategy: (pool: pg.Pool, {
|
|
|
17
16
|
channel
|
|
18
17
|
}: AppVersionGetBundlesArgs) => Promise<UpdateInfo | null>;
|
|
19
18
|
declare const getUpdateInfo: (pool: pg.Pool, args: GetBundlesArgs) => Promise<UpdateInfo | null> | null;
|
|
20
|
-
|
|
21
19
|
//#endregion
|
|
22
20
|
export { PostgresConfig, appVersionStrategy, getUpdateInfo, postgres };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { createDatabasePlugin } from "@hot-updater/plugin-core";
|
|
2
|
+
import { calculatePagination, createDatabasePlugin } from "@hot-updater/plugin-core";
|
|
3
3
|
import { Kysely, PostgresDialect } from "kysely";
|
|
4
4
|
import { Pool } from "pg";
|
|
5
5
|
import { NIL_UUID } from "@hot-updater/core";
|
|
@@ -65,14 +65,19 @@ const postgres = (config, hooks) => {
|
|
|
65
65
|
};
|
|
66
66
|
},
|
|
67
67
|
async getBundles(context, options) {
|
|
68
|
-
const { where, limit, offset
|
|
68
|
+
const { where, limit, offset } = options ?? {};
|
|
69
|
+
let countQuery = context.db.selectFrom("bundles");
|
|
70
|
+
if (where?.channel) countQuery = countQuery.where("channel", "=", where.channel);
|
|
71
|
+
if (where?.platform) countQuery = countQuery.where("platform", "=", where.platform);
|
|
72
|
+
const countResult = await countQuery.select(context.db.fn.count("id").as("total")).executeTakeFirst();
|
|
73
|
+
const total = countResult?.total || 0;
|
|
69
74
|
let query = context.db.selectFrom("bundles").orderBy("id", "desc");
|
|
70
75
|
if (where?.channel) query = query.where("channel", "=", where.channel);
|
|
71
76
|
if (where?.platform) query = query.where("platform", "=", where.platform);
|
|
72
77
|
if (limit) query = query.limit(limit);
|
|
73
78
|
if (offset) query = query.offset(offset);
|
|
74
79
|
const data = await query.selectAll().execute();
|
|
75
|
-
|
|
80
|
+
const bundles = data.map((bundle) => ({
|
|
76
81
|
enabled: bundle.enabled,
|
|
77
82
|
shouldForceUpdate: bundle.should_force_update,
|
|
78
83
|
fileHash: bundle.file_hash,
|
|
@@ -85,6 +90,14 @@ const postgres = (config, hooks) => {
|
|
|
85
90
|
storageUri: bundle.storage_uri,
|
|
86
91
|
fingerprintHash: bundle.fingerprint_hash
|
|
87
92
|
}));
|
|
93
|
+
const pagination = calculatePagination(total, {
|
|
94
|
+
limit,
|
|
95
|
+
offset
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
data: bundles,
|
|
99
|
+
pagination
|
|
100
|
+
};
|
|
88
101
|
},
|
|
89
102
|
async getChannels(context) {
|
|
90
103
|
const data = await context.db.selectFrom("bundles").select("channel").groupBy("channel").execute();
|
|
@@ -676,7 +689,7 @@ var require_lrucache = __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_
|
|
|
676
689
|
var LRUCache = class {
|
|
677
690
|
constructor() {
|
|
678
691
|
this.max = 1e3;
|
|
679
|
-
this.map = new Map();
|
|
692
|
+
this.map = /* @__PURE__ */ new Map();
|
|
680
693
|
}
|
|
681
694
|
get(key) {
|
|
682
695
|
const value = this.map.get(key);
|
|
@@ -777,7 +790,7 @@ var require_range = __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_mod
|
|
|
777
790
|
return !!comp.match(re$1[t$1.COMPARATORLOOSE]);
|
|
778
791
|
});
|
|
779
792
|
debug$1("range list", rangeList);
|
|
780
|
-
const rangeMap = new Map();
|
|
793
|
+
const rangeMap = /* @__PURE__ */ new Map();
|
|
781
794
|
const comparators = rangeList.map((comp) => new Comparator$4(comp, this.options));
|
|
782
795
|
for (const comp of comparators) {
|
|
783
796
|
if (isNullSet(comp)) return [comp];
|
|
@@ -1289,7 +1302,7 @@ var require_subset = __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_mo
|
|
|
1289
1302
|
else sub = minimumVersion;
|
|
1290
1303
|
if (dom.length === 1 && dom[0].semver === ANY) if (options.includePrerelease) return true;
|
|
1291
1304
|
else dom = minimumVersion;
|
|
1292
|
-
const eqSet = new Set();
|
|
1305
|
+
const eqSet = /* @__PURE__ */ new Set();
|
|
1293
1306
|
let gt$5, lt$4;
|
|
1294
1307
|
for (const c of sub) if (c.operator === ">" || c.operator === ">=") gt$5 = higherGT(gt$5, c, options);
|
|
1295
1308
|
else if (c.operator === "<" || c.operator === "<=") lt$4 = lowerLT(lt$4, c, options);
|
|
@@ -1442,7 +1455,7 @@ var require_semver = __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_mo
|
|
|
1442
1455
|
rcompareIdentifiers: identifiers.rcompareIdentifiers
|
|
1443
1456
|
};
|
|
1444
1457
|
} });
|
|
1445
|
-
var import_semver = __toESM(require_semver()
|
|
1458
|
+
var import_semver = __toESM(require_semver());
|
|
1446
1459
|
const semverSatisfies = (targetAppVersion, currentVersion) => {
|
|
1447
1460
|
const currentCoerce = import_semver.default.coerce(currentVersion);
|
|
1448
1461
|
if (!currentCoerce) return false;
|
|
@@ -1491,7 +1504,7 @@ const year = day * 365.25;
|
|
|
1491
1504
|
const isObject$1 = (value) => typeof value === "object" && value !== null;
|
|
1492
1505
|
const isObjectCustom = (value) => isObject$1(value) && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date);
|
|
1493
1506
|
const mapObjectSkip = Symbol("mapObjectSkip");
|
|
1494
|
-
const _mapObject = (object, mapper, options, isSeen = new WeakMap()) => {
|
|
1507
|
+
const _mapObject = (object, mapper, options, isSeen = /* @__PURE__ */ new WeakMap()) => {
|
|
1495
1508
|
options = {
|
|
1496
1509
|
deep: false,
|
|
1497
1510
|
target: {},
|
|
@@ -1598,8 +1611,8 @@ var QuickLRU = class extends Map {
|
|
|
1598
1611
|
this.maxSize = options.maxSize;
|
|
1599
1612
|
this.maxAge = options.maxAge || Number.POSITIVE_INFINITY;
|
|
1600
1613
|
this.onEviction = options.onEviction;
|
|
1601
|
-
this.cache = new Map();
|
|
1602
|
-
this.oldCache = new Map();
|
|
1614
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1615
|
+
this.oldCache = /* @__PURE__ */ new Map();
|
|
1603
1616
|
this._size = 0;
|
|
1604
1617
|
}
|
|
1605
1618
|
_emitEvictions(cache$1) {
|
|
@@ -1631,7 +1644,7 @@ var QuickLRU = class extends Map {
|
|
|
1631
1644
|
this._size = 0;
|
|
1632
1645
|
this._emitEvictions(this.oldCache);
|
|
1633
1646
|
this.oldCache = this.cache;
|
|
1634
|
-
this.cache = new Map();
|
|
1647
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1635
1648
|
}
|
|
1636
1649
|
}
|
|
1637
1650
|
_moveToRecent(key, item) {
|
|
@@ -1702,12 +1715,12 @@ var QuickLRU = class extends Map {
|
|
|
1702
1715
|
const removeCount = items.length - newSize;
|
|
1703
1716
|
if (removeCount < 0) {
|
|
1704
1717
|
this.cache = new Map(items);
|
|
1705
|
-
this.oldCache = new Map();
|
|
1718
|
+
this.oldCache = /* @__PURE__ */ new Map();
|
|
1706
1719
|
this._size = items.length;
|
|
1707
1720
|
} else {
|
|
1708
1721
|
if (removeCount > 0) this._emitEvictions(items.slice(0, removeCount));
|
|
1709
1722
|
this.oldCache = new Map(items.slice(removeCount));
|
|
1710
|
-
this.cache = new Map();
|
|
1723
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1711
1724
|
this._size = 0;
|
|
1712
1725
|
}
|
|
1713
1726
|
this.maxSize = newSize;
|
|
@@ -2050,7 +2063,7 @@ var require_lib = __commonJS$1({ "../../node_modules/.pnpm/pg-minify@1.6.5/node_
|
|
|
2050
2063
|
|
|
2051
2064
|
//#endregion
|
|
2052
2065
|
//#region src/getUpdateInfo.ts
|
|
2053
|
-
var import_lib = __toESM$1(require_lib()
|
|
2066
|
+
var import_lib = __toESM$1(require_lib());
|
|
2054
2067
|
const appVersionStrategy = async (pool, { platform, appVersion, bundleId, minBundleId = NIL_UUID, channel = "production" }) => {
|
|
2055
2068
|
const sqlGetTargetAppVersionList = (0, import_lib.default)(`
|
|
2056
2069
|
SELECT target_app_version
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/postgres",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.18.
|
|
4
|
+
"version": "0.18.2",
|
|
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/
|
|
35
|
-
"@hot-updater/core": "0.18.
|
|
34
|
+
"@hot-updater/core": "0.18.2",
|
|
35
|
+
"@hot-updater/plugin-core": "0.18.2"
|
|
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.
|
|
42
|
+
"@hot-updater/js": "0.18.2"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsdown",
|