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