@hot-updater/postgres 0.20.10 → 0.20.12

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
@@ -24,127 +24,15 @@ var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(
24
24
  }) : target, mod));
25
25
 
26
26
  //#endregion
27
+ let __hot_updater_core = require("@hot-updater/core");
28
+ __hot_updater_core = __toESM$1(__hot_updater_core);
27
29
  let __hot_updater_plugin_core = require("@hot-updater/plugin-core");
28
30
  __hot_updater_plugin_core = __toESM$1(__hot_updater_plugin_core);
29
31
  let kysely = require("kysely");
30
32
  kysely = __toESM$1(kysely);
31
33
  let pg = require("pg");
32
34
  pg = __toESM$1(pg);
33
- let __hot_updater_core = require("@hot-updater/core");
34
- __hot_updater_core = __toESM$1(__hot_updater_core);
35
35
 
36
- //#region src/postgres.ts
37
- const postgres = (config, hooks) => {
38
- return (0, __hot_updater_plugin_core.createDatabasePlugin)("postgres", {
39
- getContext: () => {
40
- const pool = new pg.Pool(config);
41
- const dialect = new kysely.PostgresDialect({ pool });
42
- const db = new kysely.Kysely({ dialect });
43
- return {
44
- db,
45
- pool
46
- };
47
- },
48
- async onUnmount(context) {
49
- await context.db.destroy();
50
- await context.pool.end();
51
- },
52
- async getBundleById(context, bundleId) {
53
- const data = await context.db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
54
- if (!data) return null;
55
- return {
56
- enabled: data.enabled,
57
- shouldForceUpdate: data.should_force_update,
58
- fileHash: data.file_hash,
59
- gitCommitHash: data.git_commit_hash,
60
- id: data.id,
61
- message: data.message,
62
- platform: data.platform,
63
- targetAppVersion: data.target_app_version,
64
- channel: data.channel,
65
- storageUri: data.storage_uri,
66
- fingerprintHash: data.fingerprint_hash
67
- };
68
- },
69
- async getBundles(context, options) {
70
- const { where, limit, offset } = options ?? {};
71
- let countQuery = context.db.selectFrom("bundles");
72
- if (where?.channel) countQuery = countQuery.where("channel", "=", where.channel);
73
- if (where?.platform) countQuery = countQuery.where("platform", "=", where.platform);
74
- const countResult = await countQuery.select(context.db.fn.count("id").as("total")).executeTakeFirst();
75
- const total = countResult?.total || 0;
76
- let query = context.db.selectFrom("bundles").orderBy("id", "desc");
77
- if (where?.channel) query = query.where("channel", "=", where.channel);
78
- if (where?.platform) query = query.where("platform", "=", where.platform);
79
- if (limit) query = query.limit(limit);
80
- if (offset) query = query.offset(offset);
81
- const data = await query.selectAll().execute();
82
- const bundles = data.map((bundle) => ({
83
- enabled: bundle.enabled,
84
- shouldForceUpdate: bundle.should_force_update,
85
- fileHash: bundle.file_hash,
86
- gitCommitHash: bundle.git_commit_hash,
87
- id: bundle.id,
88
- message: bundle.message,
89
- platform: bundle.platform,
90
- targetAppVersion: bundle.target_app_version,
91
- channel: bundle.channel,
92
- storageUri: bundle.storage_uri,
93
- fingerprintHash: bundle.fingerprint_hash
94
- }));
95
- const pagination = (0, __hot_updater_plugin_core.calculatePagination)(total, {
96
- limit,
97
- offset
98
- });
99
- return {
100
- data: bundles,
101
- pagination
102
- };
103
- },
104
- async getChannels(context) {
105
- const data = await context.db.selectFrom("bundles").select("channel").groupBy("channel").execute();
106
- return data.map((bundle) => bundle.channel);
107
- },
108
- async commitBundle(context, { changedSets }) {
109
- if (changedSets.length === 0) return;
110
- await context.db.transaction().execute(async (tx) => {
111
- for (const op of changedSets) if (op.operation === "delete") {
112
- const result = await tx.deleteFrom("bundles").where("id", "=", op.data.id).executeTakeFirst();
113
- if (result.numDeletedRows === 0n) throw new Error(`Bundle with id ${op.data.id} not found`);
114
- } else if (op.operation === "insert" || op.operation === "update") {
115
- const bundle = op.data;
116
- await tx.insertInto("bundles").values({
117
- id: bundle.id,
118
- enabled: bundle.enabled,
119
- should_force_update: bundle.shouldForceUpdate,
120
- file_hash: bundle.fileHash,
121
- git_commit_hash: bundle.gitCommitHash,
122
- message: bundle.message,
123
- platform: bundle.platform,
124
- target_app_version: bundle.targetAppVersion,
125
- channel: bundle.channel,
126
- storage_uri: bundle.storageUri,
127
- fingerprint_hash: bundle.fingerprintHash
128
- }).onConflict((oc) => oc.column("id").doUpdateSet({
129
- enabled: bundle.enabled,
130
- should_force_update: bundle.shouldForceUpdate,
131
- file_hash: bundle.fileHash,
132
- git_commit_hash: bundle.gitCommitHash,
133
- message: bundle.message,
134
- platform: bundle.platform,
135
- target_app_version: bundle.targetAppVersion,
136
- channel: bundle.channel,
137
- storage_uri: bundle.storageUri,
138
- fingerprint_hash: bundle.fingerprintHash
139
- })).execute();
140
- }
141
- });
142
- hooks?.onDatabaseUpdated?.();
143
- }
144
- }, hooks);
145
- };
146
-
147
- //#endregion
148
36
  //#region ../js/dist/index.js
149
37
  var __create = Object.create;
150
38
  var __defProp = Object.defineProperty;
@@ -173,31 +61,27 @@ var require_constants = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/s
173
61
  const SEMVER_SPEC_VERSION = "2.0.0";
174
62
  const MAX_LENGTH$2 = 256;
175
63
  const MAX_SAFE_INTEGER$1 = Number.MAX_SAFE_INTEGER || 9007199254740991;
176
- const MAX_SAFE_COMPONENT_LENGTH$1 = 16;
177
- const MAX_SAFE_BUILD_LENGTH$1 = MAX_LENGTH$2 - 6;
178
- const RELEASE_TYPES = [
179
- "major",
180
- "premajor",
181
- "minor",
182
- "preminor",
183
- "patch",
184
- "prepatch",
185
- "prerelease"
186
- ];
187
64
  module$1.exports = {
188
65
  MAX_LENGTH: MAX_LENGTH$2,
189
- MAX_SAFE_COMPONENT_LENGTH: MAX_SAFE_COMPONENT_LENGTH$1,
190
- MAX_SAFE_BUILD_LENGTH: MAX_SAFE_BUILD_LENGTH$1,
66
+ MAX_SAFE_COMPONENT_LENGTH: 16,
67
+ MAX_SAFE_BUILD_LENGTH: MAX_LENGTH$2 - 6,
191
68
  MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1,
192
- RELEASE_TYPES,
69
+ RELEASE_TYPES: [
70
+ "major",
71
+ "premajor",
72
+ "minor",
73
+ "preminor",
74
+ "patch",
75
+ "prepatch",
76
+ "prerelease"
77
+ ],
193
78
  SEMVER_SPEC_VERSION,
194
79
  FLAG_INCLUDE_PRERELEASE: 1,
195
80
  FLAG_LOOSE: 2
196
81
  };
197
82
  }) });
198
83
  var require_debug = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/debug.js": ((exports$1, module$1) => {
199
- const debug$4 = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {};
200
- module$1.exports = debug$4;
84
+ module$1.exports = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {};
201
85
  }) });
202
86
  var require_re = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/re.js": ((exports$1, module$1) => {
203
87
  const { MAX_SAFE_COMPONENT_LENGTH, MAX_SAFE_BUILD_LENGTH, MAX_LENGTH: MAX_LENGTH$1 } = require_constants();
@@ -309,10 +193,10 @@ var require_semver$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/se
309
193
  const { safeRe: re$3, t: t$3 } = require_re();
310
194
  const parseOptions$2 = require_parse_options();
311
195
  const { compareIdentifiers } = require_identifiers();
312
- var SemVer$15 = class SemVer$15$1 {
196
+ module$1.exports = class SemVer$15 {
313
197
  constructor(version, options) {
314
198
  options = parseOptions$2(options);
315
- if (version instanceof SemVer$15$1) if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) return version;
199
+ if (version instanceof SemVer$15) if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) return version;
316
200
  else version = version.version;
317
201
  else if (typeof version !== "string") throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
318
202
  if (version.length > MAX_LENGTH) throw new TypeError(`version is longer than ${MAX_LENGTH} characters`);
@@ -350,19 +234,19 @@ var require_semver$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/se
350
234
  }
351
235
  compare(other) {
352
236
  debug$2("SemVer.compare", this.version, this.options, other);
353
- if (!(other instanceof SemVer$15$1)) {
237
+ if (!(other instanceof SemVer$15)) {
354
238
  if (typeof other === "string" && other === this.version) return 0;
355
- other = new SemVer$15$1(other, this.options);
239
+ other = new SemVer$15(other, this.options);
356
240
  }
357
241
  if (other.version === this.version) return 0;
358
242
  return this.compareMain(other) || this.comparePre(other);
359
243
  }
360
244
  compareMain(other) {
361
- if (!(other instanceof SemVer$15$1)) other = new SemVer$15$1(other, this.options);
245
+ if (!(other instanceof SemVer$15)) other = new SemVer$15(other, this.options);
362
246
  return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
363
247
  }
364
248
  comparePre(other) {
365
- if (!(other instanceof SemVer$15$1)) other = new SemVer$15$1(other, this.options);
249
+ if (!(other instanceof SemVer$15)) other = new SemVer$15(other, this.options);
366
250
  if (this.prerelease.length && !other.prerelease.length) return -1;
367
251
  else if (!this.prerelease.length && other.prerelease.length) return 1;
368
252
  else if (!this.prerelease.length && !other.prerelease.length) return 0;
@@ -379,7 +263,7 @@ var require_semver$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/se
379
263
  } while (++i);
380
264
  }
381
265
  compareBuild(other) {
382
- if (!(other instanceof SemVer$15$1)) other = new SemVer$15$1(other, this.options);
266
+ if (!(other instanceof SemVer$15)) other = new SemVer$15(other, this.options);
383
267
  let i = 0;
384
268
  do {
385
269
  const a = this.build[i];
@@ -472,7 +356,6 @@ var require_semver$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/se
472
356
  return this;
473
357
  }
474
358
  };
475
- module$1.exports = SemVer$15;
476
359
  }) });
477
360
  var require_parse = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/parse.js": ((exports$1, module$1) => {
478
361
  const SemVer$14 = require_semver$1();
@@ -530,8 +413,7 @@ var require_diff = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semver
530
413
  const highVersion = v1Higher ? v1 : v2;
531
414
  const lowVersion = v1Higher ? v2 : v1;
532
415
  const highHasPre = !!highVersion.prerelease.length;
533
- const lowHasPre = !!lowVersion.prerelease.length;
534
- if (lowHasPre && !highHasPre) {
416
+ if (!!lowVersion.prerelease.length && !highHasPre) {
535
417
  if (!lowVersion.patch && !lowVersion.minor) return "major";
536
418
  if (lowVersion.compareMain(highVersion) === 0) {
537
419
  if (lowVersion.minor && !lowVersion.patch) return "minor";
@@ -685,11 +567,7 @@ var require_coerce = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semv
685
567
  }
686
568
  if (match === null) return null;
687
569
  const major$2 = match[2];
688
- const minor$2 = match[3] || "0";
689
- const patch$2 = match[4] || "0";
690
- const prerelease$2 = options.includePrerelease && match[5] ? `-${match[5]}` : "";
691
- const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
692
- return parse$1(`${major$2}.${minor$2}.${patch$2}${prerelease$2}${build}`, options);
570
+ return parse$1(`${major$2}.${match[3] || "0"}.${match[4] || "0"}${options.includePrerelease && match[5] ? `-${match[5]}` : ""}${options.includePrerelease && match[6] ? `+${match[6]}` : ""}`, options);
693
571
  };
694
572
  module$1.exports = coerce$1;
695
573
  }) });
@@ -701,7 +579,7 @@ var require_lrucache = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/se
701
579
  }
702
580
  get(key) {
703
581
  const value = this.map.get(key);
704
- if (value === void 0) return void 0;
582
+ if (value === void 0) return;
705
583
  else {
706
584
  this.map.delete(key);
707
585
  this.map.set(key, value);
@@ -712,8 +590,7 @@ var require_lrucache = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/se
712
590
  return this.map.delete(key);
713
591
  }
714
592
  set(key, value) {
715
- const deleted = this.delete(key);
716
- if (!deleted && value !== void 0) {
593
+ if (!this.delete(key) && value !== void 0) {
717
594
  if (this.map.size >= this.max) {
718
595
  const firstKey = this.map.keys().next().value;
719
596
  this.delete(firstKey);
@@ -727,11 +604,11 @@ var require_lrucache = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/se
727
604
  }) });
728
605
  var require_range = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/range.js": ((exports$1, module$1) => {
729
606
  const SPACE_CHARACTERS = /\s+/g;
730
- var Range$11 = class Range$11$1 {
607
+ module$1.exports = class Range$11 {
731
608
  constructor(range, options) {
732
609
  options = parseOptions$1(options);
733
- if (range instanceof Range$11$1) if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) return range;
734
- else return new Range$11$1(range.raw, options);
610
+ if (range instanceof Range$11) if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) return range;
611
+ else return new Range$11(range.raw, options);
735
612
  if (range instanceof Comparator$4) {
736
613
  this.raw = range.value;
737
614
  this.set = [[range]];
@@ -778,8 +655,7 @@ var require_range = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semve
778
655
  return this.range;
779
656
  }
780
657
  parseRange(range) {
781
- const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE);
782
- const memoKey = memoOpts + ":" + range;
658
+ const memoKey = ((this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE)) + ":" + range;
783
659
  const cached = cache$1.get(memoKey);
784
660
  if (cached) return cached;
785
661
  const loose = this.options.loose;
@@ -810,7 +686,7 @@ var require_range = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semve
810
686
  return result;
811
687
  }
812
688
  intersects(range, options) {
813
- if (!(range instanceof Range$11$1)) throw new TypeError("a Range is required");
689
+ if (!(range instanceof Range$11)) throw new TypeError("a Range is required");
814
690
  return this.set.some((thisComparators) => {
815
691
  return isSatisfiable(thisComparators, options) && range.set.some((rangeComparators) => {
816
692
  return isSatisfiable(rangeComparators, options) && thisComparators.every((thisComparator) => {
@@ -832,9 +708,7 @@ var require_range = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semve
832
708
  return false;
833
709
  }
834
710
  };
835
- module$1.exports = Range$11;
836
- const LRU = require_lrucache();
837
- const cache$1 = new LRU();
711
+ const cache$1 = new (require_lrucache())();
838
712
  const parseOptions$1 = require_parse_options();
839
713
  const Comparator$4 = require_comparator();
840
714
  const debug$1 = require_debug();
@@ -999,13 +873,13 @@ var require_range = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semve
999
873
  }) });
1000
874
  var require_comparator = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/comparator.js": ((exports$1, module$1) => {
1001
875
  const ANY$2 = Symbol("SemVer ANY");
1002
- var Comparator$3 = class Comparator$3$1 {
876
+ module$1.exports = class Comparator$3 {
1003
877
  static get ANY() {
1004
878
  return ANY$2;
1005
879
  }
1006
880
  constructor(comp, options) {
1007
881
  options = parseOptions(options);
1008
- if (comp instanceof Comparator$3$1) if (comp.loose === !!options.loose) return comp;
882
+ if (comp instanceof Comparator$3) if (comp.loose === !!options.loose) return comp;
1009
883
  else comp = comp.value;
1010
884
  comp = comp.trim().split(/\s+/).join(" ");
1011
885
  debug("comparator", comp, options);
@@ -1039,7 +913,7 @@ var require_comparator = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/
1039
913
  return cmp$1(version, this.operator, this.semver, this.options);
1040
914
  }
1041
915
  intersects(comp, options) {
1042
- if (!(comp instanceof Comparator$3$1)) throw new TypeError("a Comparator is required");
916
+ if (!(comp instanceof Comparator$3)) throw new TypeError("a Comparator is required");
1043
917
  if (this.operator === "") {
1044
918
  if (this.value === "") return true;
1045
919
  return new Range$10(comp.value, options).test(this.value);
@@ -1058,7 +932,6 @@ var require_comparator = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/
1058
932
  return false;
1059
933
  }
1060
934
  };
1061
- module$1.exports = Comparator$3;
1062
935
  const parseOptions = require_parse_options();
1063
936
  const { safeRe: re, t } = require_re();
1064
937
  const cmp$1 = require_cmp();
@@ -1257,16 +1130,13 @@ var require_simplify = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/se
1257
1130
  let first = null;
1258
1131
  let prev = null;
1259
1132
  const v = versions.sort((a, b) => compare$2(a, b, options));
1260
- for (const version of v) {
1261
- const included = satisfies$2(version, range, options);
1262
- if (included) {
1263
- prev = version;
1264
- if (!first) first = version;
1265
- } else {
1266
- if (prev) set.push([first, prev]);
1267
- prev = null;
1268
- first = null;
1269
- }
1133
+ for (const version of v) if (satisfies$2(version, range, options)) {
1134
+ prev = version;
1135
+ if (!first) first = version;
1136
+ } else {
1137
+ if (prev) set.push([first, prev]);
1138
+ prev = null;
1139
+ first = null;
1270
1140
  }
1271
1141
  if (first) set.push([first, null]);
1272
1142
  const ranges = [];
@@ -1373,86 +1243,49 @@ var require_subset = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semv
1373
1243
  };
1374
1244
  module$1.exports = subset$1;
1375
1245
  }) });
1376
- var require_semver = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.js": ((exports$1, module$1) => {
1246
+ var import_semver = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.js": ((exports$1, module$1) => {
1377
1247
  const internalRe = require_re();
1378
1248
  const constants = require_constants();
1379
1249
  const SemVer = require_semver$1();
1380
1250
  const identifiers = require_identifiers();
1381
- const parse = require_parse();
1382
- const valid = require_valid$1();
1383
- const clean = require_clean();
1384
- const inc = require_inc();
1385
- const diff = require_diff();
1386
- const major = require_major();
1387
- const minor = require_minor();
1388
- const patch = require_patch();
1389
- const prerelease = require_prerelease();
1390
- const compare = require_compare();
1391
- const rcompare = require_rcompare();
1392
- const compareLoose = require_compare_loose();
1393
- const compareBuild = require_compare_build();
1394
- const sort = require_sort();
1395
- const rsort = require_rsort();
1396
- const gt = require_gt();
1397
- const lt = require_lt();
1398
- const eq = require_eq();
1399
- const neq = require_neq();
1400
- const gte = require_gte();
1401
- const lte = require_lte();
1402
- const cmp = require_cmp();
1403
- const coerce = require_coerce();
1404
- const Comparator = require_comparator();
1405
- const Range = require_range();
1406
- const satisfies = require_satisfies();
1407
- const toComparators = require_to_comparators();
1408
- const maxSatisfying = require_max_satisfying();
1409
- const minSatisfying = require_min_satisfying();
1410
- const minVersion = require_min_version();
1411
- const validRange = require_valid();
1412
- const outside = require_outside();
1413
- const gtr = require_gtr();
1414
- const ltr = require_ltr();
1415
- const intersects = require_intersects();
1416
- const simplifyRange = require_simplify();
1417
- const subset = require_subset();
1418
1251
  module$1.exports = {
1419
- parse,
1420
- valid,
1421
- clean,
1422
- inc,
1423
- diff,
1424
- major,
1425
- minor,
1426
- patch,
1427
- prerelease,
1428
- compare,
1429
- rcompare,
1430
- compareLoose,
1431
- compareBuild,
1432
- sort,
1433
- rsort,
1434
- gt,
1435
- lt,
1436
- eq,
1437
- neq,
1438
- gte,
1439
- lte,
1440
- cmp,
1441
- coerce,
1442
- Comparator,
1443
- Range,
1444
- satisfies,
1445
- toComparators,
1446
- maxSatisfying,
1447
- minSatisfying,
1448
- minVersion,
1449
- validRange,
1450
- outside,
1451
- gtr,
1452
- ltr,
1453
- intersects,
1454
- simplifyRange,
1455
- subset,
1252
+ parse: require_parse(),
1253
+ valid: require_valid$1(),
1254
+ clean: require_clean(),
1255
+ inc: require_inc(),
1256
+ diff: require_diff(),
1257
+ major: require_major(),
1258
+ minor: require_minor(),
1259
+ patch: require_patch(),
1260
+ prerelease: require_prerelease(),
1261
+ compare: require_compare(),
1262
+ rcompare: require_rcompare(),
1263
+ compareLoose: require_compare_loose(),
1264
+ compareBuild: require_compare_build(),
1265
+ sort: require_sort(),
1266
+ rsort: require_rsort(),
1267
+ gt: require_gt(),
1268
+ lt: require_lt(),
1269
+ eq: require_eq(),
1270
+ neq: require_neq(),
1271
+ gte: require_gte(),
1272
+ lte: require_lte(),
1273
+ cmp: require_cmp(),
1274
+ coerce: require_coerce(),
1275
+ Comparator: require_comparator(),
1276
+ Range: require_range(),
1277
+ satisfies: require_satisfies(),
1278
+ toComparators: require_to_comparators(),
1279
+ maxSatisfying: require_max_satisfying(),
1280
+ minSatisfying: require_min_satisfying(),
1281
+ minVersion: require_min_version(),
1282
+ validRange: require_valid(),
1283
+ outside: require_outside(),
1284
+ gtr: require_gtr(),
1285
+ ltr: require_ltr(),
1286
+ intersects: require_intersects(),
1287
+ simplifyRange: require_simplify(),
1288
+ subset: require_subset(),
1456
1289
  SemVer,
1457
1290
  re: internalRe.re,
1458
1291
  src: internalRe.src,
@@ -1462,8 +1295,7 @@ var require_semver = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/semv
1462
1295
  compareIdentifiers: identifiers.compareIdentifiers,
1463
1296
  rcompareIdentifiers: identifiers.rcompareIdentifiers
1464
1297
  };
1465
- }) });
1466
- var import_semver = /* @__PURE__ */ __toESM(require_semver(), 1);
1298
+ }) }))(), 1);
1467
1299
  const semverSatisfies = (targetAppVersion, currentVersion) => {
1468
1300
  const currentCoerce = import_semver.default.coerce(currentVersion);
1469
1301
  if (!currentCoerce) return false;
@@ -1478,8 +1310,7 @@ const semverSatisfies = (targetAppVersion, currentVersion) => {
1478
1310
  * @returns Array of target app versions compatible with the current version
1479
1311
  */
1480
1312
  const filterCompatibleAppVersions = (targetAppVersionList, currentVersion) => {
1481
- const compatibleAppVersionList = targetAppVersionList.filter((version) => semverSatisfies(version, currentVersion));
1482
- return compatibleAppVersionList.sort((a, b) => b.localeCompare(a));
1313
+ return targetAppVersionList.filter((version) => semverSatisfies(version, currentVersion)).sort((a, b) => b.localeCompare(a));
1483
1314
  };
1484
1315
  const encoder = new TextEncoder();
1485
1316
  const decoder = new TextDecoder();
@@ -1583,8 +1414,7 @@ function camelCase(input, options) {
1583
1414
  if (SEPARATORS.test(input)) return "";
1584
1415
  return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
1585
1416
  }
1586
- const hasUpperCase = input !== toLowerCase(input);
1587
- if (hasUpperCase) input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase);
1417
+ if (input !== toLowerCase(input)) input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase);
1588
1418
  input = input.replace(LEADING_SEPARATORS, "");
1589
1419
  input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input);
1590
1420
  if (options.pascalCase) input = toUpperCase(input.charAt(0)) + input.slice(1);
@@ -1617,8 +1447,7 @@ var QuickLRU = class extends Map {
1617
1447
  return false;
1618
1448
  }
1619
1449
  _getOrDeleteIfExpired(key, item) {
1620
- const deleted = this._deleteIfExpired(key, item);
1621
- if (deleted === false) return item.value;
1450
+ if (this._deleteIfExpired(key, item) === false) return item.value;
1622
1451
  }
1623
1452
  _getItemValue(key, item) {
1624
1453
  return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
@@ -1645,14 +1474,12 @@ var QuickLRU = class extends Map {
1645
1474
  for (const item of this.oldCache) {
1646
1475
  const [key, value] = item;
1647
1476
  if (!this.cache.has(key)) {
1648
- const deleted = this._deleteIfExpired(key, value);
1649
- if (deleted === false) yield item;
1477
+ if (this._deleteIfExpired(key, value) === false) yield item;
1650
1478
  }
1651
1479
  }
1652
1480
  for (const item of this.cache) {
1653
1481
  const [key, value] = item;
1654
- const deleted = this._deleteIfExpired(key, value);
1655
- if (deleted === false) yield item;
1482
+ if (this._deleteIfExpired(key, value) === false) yield item;
1656
1483
  }
1657
1484
  }
1658
1485
  get(key) {
@@ -1724,32 +1551,26 @@ var QuickLRU = class extends Map {
1724
1551
  *[Symbol.iterator]() {
1725
1552
  for (const item of this.cache) {
1726
1553
  const [key, value] = item;
1727
- const deleted = this._deleteIfExpired(key, value);
1728
- if (deleted === false) yield [key, value.value];
1554
+ if (this._deleteIfExpired(key, value) === false) yield [key, value.value];
1729
1555
  }
1730
1556
  for (const item of this.oldCache) {
1731
1557
  const [key, value] = item;
1732
1558
  if (!this.cache.has(key)) {
1733
- const deleted = this._deleteIfExpired(key, value);
1734
- if (deleted === false) yield [key, value.value];
1559
+ if (this._deleteIfExpired(key, value) === false) yield [key, value.value];
1735
1560
  }
1736
1561
  }
1737
1562
  }
1738
1563
  *entriesDescending() {
1739
1564
  let items = [...this.cache];
1740
1565
  for (let i = items.length - 1; i >= 0; --i) {
1741
- const item = items[i];
1742
- const [key, value] = item;
1743
- const deleted = this._deleteIfExpired(key, value);
1744
- if (deleted === false) yield [key, value.value];
1566
+ const [key, value] = items[i];
1567
+ if (this._deleteIfExpired(key, value) === false) yield [key, value.value];
1745
1568
  }
1746
1569
  items = [...this.oldCache];
1747
1570
  for (let i = items.length - 1; i >= 0; --i) {
1748
- const item = items[i];
1749
- const [key, value] = item;
1571
+ const [key, value] = items[i];
1750
1572
  if (!this.cache.has(key)) {
1751
- const deleted = this._deleteIfExpired(key, value);
1752
- if (deleted === false) yield [key, value.value];
1573
+ if (this._deleteIfExpired(key, value) === false) yield [key, value.value];
1753
1574
  }
1754
1575
  }
1755
1576
  }
@@ -1889,14 +1710,13 @@ var require_error = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/pg-
1889
1710
  SQLParsingError$1.prototype.toString = function(level) {
1890
1711
  level = level > 0 ? parseInt(level) : 0;
1891
1712
  const gap = messageGap(level + 1);
1892
- const lines = [
1713
+ return [
1893
1714
  "SQLParsingError {",
1894
1715
  `${gap}code: parsingErrorCode.${errorMessages[this.code].name}`,
1895
1716
  `${gap}error: "${this.error}"`,
1896
1717
  `${gap}position: {line: ${this.position.line}, col: ${this.position.column}}`,
1897
1718
  `${messageGap(level)}}`
1898
- ];
1899
- return lines.join(EOL);
1719
+ ].join(EOL);
1900
1720
  };
1901
1721
  addInspection(SQLParsingError$1.prototype, function() {
1902
1722
  return this.toString();
@@ -2031,8 +1851,7 @@ var require_parser = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/pg
2031
1851
  }
2032
1852
  }
2033
1853
  function throwError(code) {
2034
- const position = getIndexPos(sql, idx);
2035
- throw new SQLParsingError(code, position);
1854
+ throw new SQLParsingError(code, getIndexPos(sql, idx));
2036
1855
  }
2037
1856
  }
2038
1857
  function isGap(s) {
@@ -2087,6 +1906,110 @@ const getUpdateInfo = (pool, args) => {
2087
1906
  return null;
2088
1907
  };
2089
1908
 
1909
+ //#endregion
1910
+ //#region src/postgres.ts
1911
+ const postgres = (config, hooks) => {
1912
+ return (0, __hot_updater_plugin_core.createDatabasePlugin)("postgres", {
1913
+ getContext: () => {
1914
+ const pool = new pg.Pool(config);
1915
+ return {
1916
+ db: new kysely.Kysely({ dialect: new kysely.PostgresDialect({ pool }) }),
1917
+ pool
1918
+ };
1919
+ },
1920
+ async onUnmount(context) {
1921
+ await context.db.destroy();
1922
+ await context.pool.end();
1923
+ },
1924
+ async getBundleById(context, bundleId) {
1925
+ const data = await context.db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
1926
+ if (!data) return null;
1927
+ return {
1928
+ enabled: data.enabled,
1929
+ shouldForceUpdate: data.should_force_update,
1930
+ fileHash: data.file_hash,
1931
+ gitCommitHash: data.git_commit_hash,
1932
+ id: data.id,
1933
+ message: data.message,
1934
+ platform: data.platform,
1935
+ targetAppVersion: data.target_app_version,
1936
+ channel: data.channel,
1937
+ storageUri: data.storage_uri,
1938
+ fingerprintHash: data.fingerprint_hash
1939
+ };
1940
+ },
1941
+ async getBundles(context, options) {
1942
+ const { where, limit, offset } = options ?? {};
1943
+ let countQuery = context.db.selectFrom("bundles");
1944
+ if (where?.channel) countQuery = countQuery.where("channel", "=", where.channel);
1945
+ if (where?.platform) countQuery = countQuery.where("platform", "=", where.platform);
1946
+ const total = (await countQuery.select(context.db.fn.count("id").as("total")).executeTakeFirst())?.total || 0;
1947
+ let query = context.db.selectFrom("bundles").orderBy("id", "desc");
1948
+ if (where?.channel) query = query.where("channel", "=", where.channel);
1949
+ if (where?.platform) query = query.where("platform", "=", where.platform);
1950
+ if (limit) query = query.limit(limit);
1951
+ if (offset) query = query.offset(offset);
1952
+ return {
1953
+ data: (await query.selectAll().execute()).map((bundle) => ({
1954
+ enabled: bundle.enabled,
1955
+ shouldForceUpdate: bundle.should_force_update,
1956
+ fileHash: bundle.file_hash,
1957
+ gitCommitHash: bundle.git_commit_hash,
1958
+ id: bundle.id,
1959
+ message: bundle.message,
1960
+ platform: bundle.platform,
1961
+ targetAppVersion: bundle.target_app_version,
1962
+ channel: bundle.channel,
1963
+ storageUri: bundle.storage_uri,
1964
+ fingerprintHash: bundle.fingerprint_hash
1965
+ })),
1966
+ pagination: (0, __hot_updater_plugin_core.calculatePagination)(total, {
1967
+ limit,
1968
+ offset
1969
+ })
1970
+ };
1971
+ },
1972
+ async getChannels(context) {
1973
+ return (await context.db.selectFrom("bundles").select("channel").groupBy("channel").execute()).map((bundle) => bundle.channel);
1974
+ },
1975
+ async commitBundle(context, { changedSets }) {
1976
+ if (changedSets.length === 0) return;
1977
+ await context.db.transaction().execute(async (tx) => {
1978
+ for (const op of changedSets) if (op.operation === "delete") {
1979
+ if ((await tx.deleteFrom("bundles").where("id", "=", op.data.id).executeTakeFirst()).numDeletedRows === 0n) throw new Error(`Bundle with id ${op.data.id} not found`);
1980
+ } else if (op.operation === "insert" || op.operation === "update") {
1981
+ const bundle = op.data;
1982
+ await tx.insertInto("bundles").values({
1983
+ id: bundle.id,
1984
+ enabled: bundle.enabled,
1985
+ should_force_update: bundle.shouldForceUpdate,
1986
+ file_hash: bundle.fileHash,
1987
+ git_commit_hash: bundle.gitCommitHash,
1988
+ message: bundle.message,
1989
+ platform: bundle.platform,
1990
+ target_app_version: bundle.targetAppVersion,
1991
+ channel: bundle.channel,
1992
+ storage_uri: bundle.storageUri,
1993
+ fingerprint_hash: bundle.fingerprintHash
1994
+ }).onConflict((oc) => oc.column("id").doUpdateSet({
1995
+ enabled: bundle.enabled,
1996
+ should_force_update: bundle.shouldForceUpdate,
1997
+ file_hash: bundle.fileHash,
1998
+ git_commit_hash: bundle.gitCommitHash,
1999
+ message: bundle.message,
2000
+ platform: bundle.platform,
2001
+ target_app_version: bundle.targetAppVersion,
2002
+ channel: bundle.channel,
2003
+ storage_uri: bundle.storageUri,
2004
+ fingerprint_hash: bundle.fingerprintHash
2005
+ })).execute();
2006
+ }
2007
+ });
2008
+ hooks?.onDatabaseUpdated?.();
2009
+ }
2010
+ }, hooks);
2011
+ };
2012
+
2090
2013
  //#endregion
2091
2014
  exports.appVersionStrategy = appVersionStrategy;
2092
2015
  exports.getUpdateInfo = getUpdateInfo;