@hot-updater/server 0.21.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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  3. package/dist/adapters/drizzle.cjs +9 -0
  4. package/dist/adapters/drizzle.d.cts +1 -0
  5. package/dist/adapters/drizzle.d.ts +1 -0
  6. package/dist/adapters/drizzle.js +3 -0
  7. package/dist/adapters/kysely.cjs +9 -0
  8. package/dist/adapters/kysely.d.cts +1 -0
  9. package/dist/adapters/kysely.d.ts +1 -0
  10. package/dist/adapters/kysely.js +3 -0
  11. package/dist/adapters/mongodb.cjs +9 -0
  12. package/dist/adapters/mongodb.d.cts +1 -0
  13. package/dist/adapters/mongodb.d.ts +1 -0
  14. package/dist/adapters/mongodb.js +3 -0
  15. package/dist/adapters/prisma.cjs +9 -0
  16. package/dist/adapters/prisma.d.cts +1 -0
  17. package/dist/adapters/prisma.d.ts +1 -0
  18. package/dist/adapters/prisma.js +3 -0
  19. package/dist/adapters/typeorm.cjs +9 -0
  20. package/dist/adapters/typeorm.d.cts +1 -0
  21. package/dist/adapters/typeorm.d.ts +1 -0
  22. package/dist/adapters/typeorm.js +3 -0
  23. package/dist/calculatePagination.cjs +27 -0
  24. package/dist/calculatePagination.js +26 -0
  25. package/dist/db/index.cjs +289 -0
  26. package/dist/db/index.d.cts +62 -0
  27. package/dist/db/index.d.ts +62 -0
  28. package/dist/db/index.js +284 -0
  29. package/dist/handler.cjs +141 -0
  30. package/dist/handler.d.cts +37 -0
  31. package/dist/handler.d.ts +37 -0
  32. package/dist/handler.js +140 -0
  33. package/dist/index.cjs +6 -0
  34. package/dist/index.d.cts +4 -0
  35. package/dist/index.d.ts +4 -0
  36. package/dist/index.js +4 -0
  37. package/dist/schema/v1.cjs +26 -0
  38. package/dist/schema/v1.js +24 -0
  39. package/dist/types/index.d.cts +20 -0
  40. package/dist/types/index.d.ts +20 -0
  41. package/package.json +73 -0
  42. package/src/adapters/drizzle.ts +1 -0
  43. package/src/adapters/kysely.ts +1 -0
  44. package/src/adapters/mongodb.ts +1 -0
  45. package/src/adapters/prisma.ts +1 -0
  46. package/src/adapters/typeorm.ts +1 -0
  47. package/src/calculatePagination.ts +34 -0
  48. package/src/db/index.spec.ts +231 -0
  49. package/src/db/index.ts +490 -0
  50. package/src/handler-standalone-integration.spec.ts +341 -0
  51. package/src/handler.ts +231 -0
  52. package/src/index.ts +3 -0
  53. package/src/schema/v1.ts +22 -0
  54. package/src/types/index.ts +21 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Sungyu Kang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ exports.__toESM = __toESM;
@@ -0,0 +1,9 @@
1
+
2
+
3
+ var fumadb_adapters_drizzle = require("fumadb/adapters/drizzle");
4
+ Object.keys(fumadb_adapters_drizzle).forEach(function (k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function () { return fumadb_adapters_drizzle[k]; }
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/drizzle";
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/drizzle";
@@ -0,0 +1,3 @@
1
+ export * from "fumadb/adapters/drizzle"
2
+
3
+ export { };
@@ -0,0 +1,9 @@
1
+
2
+
3
+ var fumadb_adapters_kysely = require("fumadb/adapters/kysely");
4
+ Object.keys(fumadb_adapters_kysely).forEach(function (k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function () { return fumadb_adapters_kysely[k]; }
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/kysely";
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/kysely";
@@ -0,0 +1,3 @@
1
+ export * from "fumadb/adapters/kysely"
2
+
3
+ export { };
@@ -0,0 +1,9 @@
1
+
2
+
3
+ var fumadb_adapters_mongodb = require("fumadb/adapters/mongodb");
4
+ Object.keys(fumadb_adapters_mongodb).forEach(function (k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function () { return fumadb_adapters_mongodb[k]; }
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/mongodb";
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/mongodb";
@@ -0,0 +1,3 @@
1
+ export * from "fumadb/adapters/mongodb"
2
+
3
+ export { };
@@ -0,0 +1,9 @@
1
+
2
+
3
+ var fumadb_adapters_prisma = require("fumadb/adapters/prisma");
4
+ Object.keys(fumadb_adapters_prisma).forEach(function (k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function () { return fumadb_adapters_prisma[k]; }
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/prisma";
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/prisma";
@@ -0,0 +1,3 @@
1
+ export * from "fumadb/adapters/prisma"
2
+
3
+ export { };
@@ -0,0 +1,9 @@
1
+
2
+
3
+ var fumadb_adapters_typeorm = require("fumadb/adapters/typeorm");
4
+ Object.keys(fumadb_adapters_typeorm).forEach(function (k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function () { return fumadb_adapters_typeorm[k]; }
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/typeorm";
@@ -0,0 +1 @@
1
+ export * from "fumadb/adapters/typeorm";
@@ -0,0 +1,3 @@
1
+ export * from "fumadb/adapters/typeorm"
2
+
3
+ export { };
@@ -0,0 +1,27 @@
1
+
2
+ //#region src/calculatePagination.ts
3
+ /**
4
+ * Calculate pagination information based on total count, limit, and offset
5
+ */
6
+ function calculatePagination(total, options) {
7
+ const { limit, offset } = options;
8
+ if (total === 0) return {
9
+ total: 0,
10
+ hasNextPage: false,
11
+ hasPreviousPage: false,
12
+ currentPage: 1,
13
+ totalPages: 0
14
+ };
15
+ const currentPage = Math.floor(offset / limit) + 1;
16
+ const totalPages = Math.ceil(total / limit);
17
+ return {
18
+ total,
19
+ hasNextPage: offset + limit < total,
20
+ hasPreviousPage: offset > 0,
21
+ currentPage,
22
+ totalPages
23
+ };
24
+ }
25
+
26
+ //#endregion
27
+ exports.calculatePagination = calculatePagination;
@@ -0,0 +1,26 @@
1
+ //#region src/calculatePagination.ts
2
+ /**
3
+ * Calculate pagination information based on total count, limit, and offset
4
+ */
5
+ function calculatePagination(total, options) {
6
+ const { limit, offset } = options;
7
+ if (total === 0) return {
8
+ total: 0,
9
+ hasNextPage: false,
10
+ hasPreviousPage: false,
11
+ currentPage: 1,
12
+ totalPages: 0
13
+ };
14
+ const currentPage = Math.floor(offset / limit) + 1;
15
+ const totalPages = Math.ceil(total / limit);
16
+ return {
17
+ total,
18
+ hasNextPage: offset + limit < total,
19
+ hasPreviousPage: offset > 0,
20
+ currentPage,
21
+ totalPages
22
+ };
23
+ }
24
+
25
+ //#endregion
26
+ export { calculatePagination };
@@ -0,0 +1,289 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_calculatePagination = require('../calculatePagination.cjs');
3
+ const require_handler = require('../handler.cjs');
4
+ const require_v1 = require('../schema/v1.cjs');
5
+ let __hot_updater_core = require("@hot-updater/core");
6
+ __hot_updater_core = require_rolldown_runtime.__toESM(__hot_updater_core);
7
+ let __hot_updater_plugin_core = require("@hot-updater/plugin-core");
8
+ __hot_updater_plugin_core = require_rolldown_runtime.__toESM(__hot_updater_plugin_core);
9
+ let fumadb = require("fumadb");
10
+ fumadb = require_rolldown_runtime.__toESM(fumadb);
11
+
12
+ //#region src/db/index.ts
13
+ const HotUpdaterDB = (0, fumadb.fumadb)({
14
+ namespace: "hot-updater",
15
+ schemas: [require_v1.v1]
16
+ });
17
+ function hotUpdater(options) {
18
+ const client = HotUpdaterDB.client(options.database);
19
+ const cwd = options.cwd ?? process.cwd();
20
+ const storagePlugins = (options?.storagePlugins ?? []).map((plugin) => typeof plugin === "function" ? plugin({ cwd }) : plugin);
21
+ const resolveFileUrl = async (storageUri) => {
22
+ if (!storageUri) return null;
23
+ const protocol = new URL(storageUri).protocol.replace(":", "");
24
+ if (protocol === "http" || protocol === "https") return storageUri;
25
+ const plugin = storagePlugins.find((p) => p.supportedProtocol === protocol);
26
+ if (!plugin) throw new Error(`No storage plugin for protocol: ${protocol}`);
27
+ const { fileUrl } = await plugin.getDownloadUrl(storageUri);
28
+ if (!fileUrl) throw new Error("Storage plugin returned empty fileUrl");
29
+ return fileUrl;
30
+ };
31
+ const api = {
32
+ async getBundleById(id) {
33
+ const version = await client.version();
34
+ const result = await client.orm(version).findFirst("bundles", {
35
+ select: [
36
+ "id",
37
+ "platform",
38
+ "should_force_update",
39
+ "enabled",
40
+ "file_hash",
41
+ "git_commit_hash",
42
+ "message",
43
+ "channel",
44
+ "storage_uri",
45
+ "target_app_version",
46
+ "fingerprint_hash",
47
+ "metadata"
48
+ ],
49
+ where: (b) => b.and(b.isNotNull("id"), b("id", "=", id))
50
+ });
51
+ if (!result) return null;
52
+ return {
53
+ id: result.id,
54
+ platform: result.platform,
55
+ shouldForceUpdate: Boolean(result.should_force_update),
56
+ enabled: Boolean(result.enabled),
57
+ fileHash: result.file_hash,
58
+ gitCommitHash: result.git_commit_hash ?? null,
59
+ message: result.message ?? null,
60
+ channel: result.channel,
61
+ storageUri: result.storage_uri,
62
+ targetAppVersion: result.target_app_version ?? null,
63
+ fingerprintHash: result.fingerprint_hash ?? null
64
+ };
65
+ },
66
+ async getUpdateInfo(args) {
67
+ const version = await client.version();
68
+ const orm = client.orm(version);
69
+ const toUpdateInfo = (row, status) => ({
70
+ id: row.id,
71
+ shouldForceUpdate: status === "ROLLBACK" ? true : Boolean(row.should_force_update),
72
+ message: row.message ?? null,
73
+ status,
74
+ storageUri: row.storage_uri ?? null,
75
+ fileHash: row.file_hash ?? null
76
+ });
77
+ const INIT_BUNDLE_ROLLBACK_UPDATE_INFO = {
78
+ id: __hot_updater_core.NIL_UUID,
79
+ message: null,
80
+ shouldForceUpdate: true,
81
+ status: "ROLLBACK",
82
+ storageUri: null,
83
+ fileHash: null
84
+ };
85
+ const appVersionStrategy = async ({ platform, appVersion, bundleId, minBundleId = __hot_updater_core.NIL_UUID, channel = "production" }) => {
86
+ const versionRows = await orm.findMany("bundles", {
87
+ select: ["target_app_version"],
88
+ where: (b) => b.and(b("platform", "=", platform))
89
+ });
90
+ const compatibleVersions = (0, __hot_updater_plugin_core.filterCompatibleAppVersions)(Array.from(new Set((versionRows ?? []).map((r) => r.target_app_version).filter((v) => Boolean(v)))), appVersion);
91
+ const candidates = ((compatibleVersions.length === 0 ? [] : await orm.findMany("bundles", {
92
+ select: [
93
+ "id",
94
+ "should_force_update",
95
+ "message",
96
+ "storage_uri",
97
+ "file_hash",
98
+ "channel",
99
+ "target_app_version",
100
+ "enabled"
101
+ ],
102
+ where: (b) => b.and(b("enabled", "=", true), b("platform", "=", platform), b("id", ">=", minBundleId ?? __hot_updater_core.NIL_UUID), b("channel", "=", channel), b.isNotNull("target_app_version"))
103
+ })) ?? []).filter((r) => r.target_app_version ? compatibleVersions.includes(r.target_app_version) : false);
104
+ const byIdDesc = (a, b) => b.id.localeCompare(a.id);
105
+ const sorted = (candidates ?? []).slice().sort(byIdDesc);
106
+ const latestCandidate = sorted[0] ?? null;
107
+ const currentBundle = sorted.find((b) => b.id === bundleId);
108
+ const updateCandidate = sorted.find((b) => b.id.localeCompare(bundleId) > 0) ?? null;
109
+ const rollbackCandidate = sorted.find((b) => b.id.localeCompare(bundleId) < 0) ?? null;
110
+ if (bundleId === __hot_updater_core.NIL_UUID) {
111
+ if (latestCandidate && latestCandidate.id !== bundleId) return toUpdateInfo(latestCandidate, "UPDATE");
112
+ return null;
113
+ }
114
+ if (currentBundle) {
115
+ if (latestCandidate && latestCandidate.id.localeCompare(currentBundle.id) > 0) return toUpdateInfo(latestCandidate, "UPDATE");
116
+ return null;
117
+ }
118
+ if (updateCandidate) return toUpdateInfo(updateCandidate, "UPDATE");
119
+ if (rollbackCandidate) return toUpdateInfo(rollbackCandidate, "ROLLBACK");
120
+ if (minBundleId && bundleId.localeCompare(minBundleId) <= 0) return null;
121
+ return INIT_BUNDLE_ROLLBACK_UPDATE_INFO;
122
+ };
123
+ const fingerprintStrategy = async ({ platform, fingerprintHash, bundleId, minBundleId = __hot_updater_core.NIL_UUID, channel = "production" }) => {
124
+ const candidates = await orm.findMany("bundles", {
125
+ select: [
126
+ "id",
127
+ "should_force_update",
128
+ "message",
129
+ "storage_uri",
130
+ "file_hash",
131
+ "channel",
132
+ "fingerprint_hash",
133
+ "enabled"
134
+ ],
135
+ where: (b) => b.and(b("enabled", "=", true), b("platform", "=", platform), b("id", ">=", minBundleId ?? __hot_updater_core.NIL_UUID), b("channel", "=", channel), b("fingerprint_hash", "=", fingerprintHash))
136
+ });
137
+ const byIdDesc = (a, b) => b.id.localeCompare(a.id);
138
+ const sorted = (candidates ?? []).slice().sort(byIdDesc);
139
+ const latestCandidate = sorted[0] ?? null;
140
+ const currentBundle = sorted.find((b) => b.id === bundleId);
141
+ const updateCandidate = sorted.find((b) => b.id.localeCompare(bundleId) > 0) ?? null;
142
+ const rollbackCandidate = sorted.find((b) => b.id.localeCompare(bundleId) < 0) ?? null;
143
+ if (bundleId === __hot_updater_core.NIL_UUID) {
144
+ if (latestCandidate && latestCandidate.id !== bundleId) return toUpdateInfo(latestCandidate, "UPDATE");
145
+ return null;
146
+ }
147
+ if (currentBundle) {
148
+ if (latestCandidate && latestCandidate.id.localeCompare(currentBundle.id) > 0) return toUpdateInfo(latestCandidate, "UPDATE");
149
+ return null;
150
+ }
151
+ if (updateCandidate) return toUpdateInfo(updateCandidate, "UPDATE");
152
+ if (rollbackCandidate) return toUpdateInfo(rollbackCandidate, "ROLLBACK");
153
+ if (minBundleId && bundleId.localeCompare(minBundleId) <= 0) return null;
154
+ return INIT_BUNDLE_ROLLBACK_UPDATE_INFO;
155
+ };
156
+ if (args._updateStrategy === "appVersion") return appVersionStrategy(args);
157
+ if (args._updateStrategy === "fingerprint") return fingerprintStrategy(args);
158
+ return null;
159
+ },
160
+ async getAppUpdateInfo(args) {
161
+ const info = await this.getUpdateInfo(args);
162
+ if (!info) return null;
163
+ const { storageUri,...rest } = info;
164
+ const fileUrl = await resolveFileUrl(storageUri ?? null);
165
+ return {
166
+ ...rest,
167
+ fileUrl
168
+ };
169
+ },
170
+ async getChannels() {
171
+ const version = await client.version();
172
+ const rows = await client.orm(version).findMany("bundles", {
173
+ select: ["channel"],
174
+ where: (b) => b.isNotNull("channel")
175
+ });
176
+ const set = new Set(rows?.map((r) => r.channel) ?? []);
177
+ return Array.from(set);
178
+ },
179
+ async getBundles(options$1) {
180
+ const version = await client.version();
181
+ const orm = client.orm(version);
182
+ const { where, limit, offset } = options$1;
183
+ const all = (await orm.findMany("bundles", {
184
+ select: [
185
+ "id",
186
+ "platform",
187
+ "should_force_update",
188
+ "enabled",
189
+ "file_hash",
190
+ "git_commit_hash",
191
+ "message",
192
+ "channel",
193
+ "storage_uri",
194
+ "target_app_version",
195
+ "fingerprint_hash",
196
+ "metadata"
197
+ ],
198
+ where: (b) => b.and(b.isNotNull("id"), where?.channel ? b("channel", "=", where.channel) : b.isNotNull("id"), where?.platform ? b("platform", "=", where.platform) : b.isNotNull("id"))
199
+ })).map((r) => ({
200
+ id: r.id,
201
+ platform: r.platform,
202
+ shouldForceUpdate: Boolean(r.should_force_update),
203
+ enabled: Boolean(r.enabled),
204
+ fileHash: r.file_hash,
205
+ gitCommitHash: r.git_commit_hash ?? null,
206
+ message: r.message ?? null,
207
+ channel: r.channel,
208
+ storageUri: r.storage_uri,
209
+ targetAppVersion: r.target_app_version ?? null,
210
+ fingerprintHash: r.fingerprint_hash ?? null
211
+ })).sort((a, b) => b.id.localeCompare(a.id));
212
+ const total = all.length;
213
+ return {
214
+ data: all.slice(offset, offset + limit),
215
+ pagination: require_calculatePagination.calculatePagination(total, {
216
+ limit,
217
+ offset
218
+ })
219
+ };
220
+ },
221
+ async insertBundle(bundle) {
222
+ const version = await client.version();
223
+ const orm = client.orm(version);
224
+ const values = {
225
+ id: bundle.id,
226
+ platform: bundle.platform,
227
+ should_force_update: bundle.shouldForceUpdate,
228
+ enabled: bundle.enabled,
229
+ file_hash: bundle.fileHash,
230
+ git_commit_hash: bundle.gitCommitHash,
231
+ message: bundle.message,
232
+ channel: bundle.channel,
233
+ storage_uri: bundle.storageUri,
234
+ target_app_version: bundle.targetAppVersion,
235
+ fingerprint_hash: bundle.fingerprintHash,
236
+ metadata: bundle.metadata ?? {}
237
+ };
238
+ const { id,...updateValues } = values;
239
+ await orm.upsert("bundles", {
240
+ where: (b) => b("id", "=", id),
241
+ create: values,
242
+ update: updateValues
243
+ });
244
+ },
245
+ async updateBundleById(bundleId, newBundle) {
246
+ const version = await client.version();
247
+ const orm = client.orm(version);
248
+ const current = await this.getBundleById(bundleId);
249
+ if (!current) throw new Error("targetBundleId not found");
250
+ const merged = {
251
+ ...current,
252
+ ...newBundle
253
+ };
254
+ const values = {
255
+ id: merged.id,
256
+ platform: merged.platform,
257
+ should_force_update: merged.shouldForceUpdate,
258
+ enabled: merged.enabled,
259
+ file_hash: merged.fileHash,
260
+ git_commit_hash: merged.gitCommitHash,
261
+ message: merged.message,
262
+ channel: merged.channel,
263
+ storage_uri: merged.storageUri,
264
+ target_app_version: merged.targetAppVersion,
265
+ fingerprint_hash: merged.fingerprintHash,
266
+ metadata: merged.metadata ?? {}
267
+ };
268
+ const { id: id2,...updateValues2 } = values;
269
+ await orm.upsert("bundles", {
270
+ where: (b) => b("id", "=", id2),
271
+ create: values,
272
+ update: updateValues2
273
+ });
274
+ },
275
+ async deleteBundleById(bundleId) {
276
+ const version = await client.version();
277
+ await client.orm(version).deleteMany("bundles", { where: (b) => b("id", "=", bundleId) });
278
+ }
279
+ };
280
+ return {
281
+ ...api,
282
+ handler: require_handler.createHandler(api, options?.basePath ? { basePath: options.basePath } : {}),
283
+ createMigrator: () => client.createMigrator()
284
+ };
285
+ }
286
+
287
+ //#endregion
288
+ exports.HotUpdaterDB = HotUpdaterDB;
289
+ exports.hotUpdater = hotUpdater;
@@ -0,0 +1,62 @@
1
+ import { PaginationInfo } from "../types/index.cjs";
2
+ import * as fumadb_schema0 from "fumadb/schema";
3
+ import * as fumadb0 from "fumadb";
4
+ import { InferFumaDB } from "fumadb";
5
+ import { AppUpdateInfo, Bundle, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
6
+ import { StoragePlugin } from "@hot-updater/plugin-core";
7
+
8
+ //#region src/db/index.d.ts
9
+ declare const HotUpdaterDB: fumadb0.FumaDBFactory<fumadb_schema0.Schema<"1.0.0", {
10
+ bundles: fumadb_schema0.Table<{
11
+ id: fumadb_schema0.IdColumn<"varchar(255)", string | null, string>;
12
+ platform: fumadb_schema0.Column<"string", string, string>;
13
+ should_force_update: fumadb_schema0.Column<"bool", boolean, boolean>;
14
+ enabled: fumadb_schema0.Column<"bool", boolean, boolean>;
15
+ file_hash: fumadb_schema0.Column<"string", string, string>;
16
+ git_commit_hash: fumadb_schema0.Column<"string", string | null, string | null>;
17
+ message: fumadb_schema0.Column<"string", string | null, string | null>;
18
+ channel: fumadb_schema0.Column<"string", string, string>;
19
+ storage_uri: fumadb_schema0.Column<"string", string, string>;
20
+ target_app_version: fumadb_schema0.Column<"string", string | null, string | null>;
21
+ fingerprint_hash: fumadb_schema0.Column<"string", string | null, string | null>;
22
+ metadata: fumadb_schema0.Column<"json", unknown, unknown>;
23
+ }, {}>;
24
+ }>[]>;
25
+ type HotUpdaterClient = InferFumaDB<typeof HotUpdaterDB>;
26
+ type DatabaseAdapter = Parameters<typeof HotUpdaterDB.client>[0];
27
+ interface DatabaseAPI {
28
+ getBundleById(id: string): Promise<Bundle | null>;
29
+ getUpdateInfo(args: GetBundlesArgs): Promise<UpdateInfo | null>;
30
+ getAppUpdateInfo(args: GetBundlesArgs): Promise<AppUpdateInfo | null>;
31
+ getChannels(): Promise<string[]>;
32
+ getBundles(options: {
33
+ where?: {
34
+ channel?: string;
35
+ platform?: string;
36
+ };
37
+ limit: number;
38
+ offset: number;
39
+ }): Promise<{
40
+ data: Bundle[];
41
+ pagination: PaginationInfo;
42
+ }>;
43
+ insertBundle(bundle: Bundle): Promise<void>;
44
+ updateBundleById(bundleId: string, newBundle: Partial<Bundle>): Promise<void>;
45
+ deleteBundleById(bundleId: string): Promise<void>;
46
+ }
47
+ type HotUpdaterAPI = DatabaseAPI & {
48
+ handler: (request: Request) => Promise<Response>;
49
+ createMigrator: () => ReturnType<HotUpdaterClient["createMigrator"]>;
50
+ };
51
+ type StoragePluginFactory = (args: {
52
+ cwd: string;
53
+ }) => StoragePlugin;
54
+ interface HotUpdaterOptions {
55
+ database: DatabaseAdapter;
56
+ storagePlugins?: (StoragePlugin | StoragePluginFactory)[];
57
+ basePath?: string;
58
+ cwd?: string;
59
+ }
60
+ declare function hotUpdater(options: HotUpdaterOptions): HotUpdaterAPI;
61
+ //#endregion
62
+ export { DatabaseAPI, DatabaseAdapter, HotUpdaterAPI, HotUpdaterClient, HotUpdaterDB, HotUpdaterOptions, StoragePluginFactory, hotUpdater };
@@ -0,0 +1,62 @@
1
+ import { PaginationInfo } from "../types/index.js";
2
+ import { AppUpdateInfo, Bundle, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
3
+ import { StoragePlugin } from "@hot-updater/plugin-core";
4
+ import * as fumadb0 from "fumadb";
5
+ import { InferFumaDB } from "fumadb";
6
+ import * as fumadb_schema0 from "fumadb/schema";
7
+
8
+ //#region src/db/index.d.ts
9
+ declare const HotUpdaterDB: fumadb0.FumaDBFactory<fumadb_schema0.Schema<"1.0.0", {
10
+ bundles: fumadb_schema0.Table<{
11
+ id: fumadb_schema0.IdColumn<"varchar(255)", string | null, string>;
12
+ platform: fumadb_schema0.Column<"string", string, string>;
13
+ should_force_update: fumadb_schema0.Column<"bool", boolean, boolean>;
14
+ enabled: fumadb_schema0.Column<"bool", boolean, boolean>;
15
+ file_hash: fumadb_schema0.Column<"string", string, string>;
16
+ git_commit_hash: fumadb_schema0.Column<"string", string | null, string | null>;
17
+ message: fumadb_schema0.Column<"string", string | null, string | null>;
18
+ channel: fumadb_schema0.Column<"string", string, string>;
19
+ storage_uri: fumadb_schema0.Column<"string", string, string>;
20
+ target_app_version: fumadb_schema0.Column<"string", string | null, string | null>;
21
+ fingerprint_hash: fumadb_schema0.Column<"string", string | null, string | null>;
22
+ metadata: fumadb_schema0.Column<"json", unknown, unknown>;
23
+ }, {}>;
24
+ }>[]>;
25
+ type HotUpdaterClient = InferFumaDB<typeof HotUpdaterDB>;
26
+ type DatabaseAdapter = Parameters<typeof HotUpdaterDB.client>[0];
27
+ interface DatabaseAPI {
28
+ getBundleById(id: string): Promise<Bundle | null>;
29
+ getUpdateInfo(args: GetBundlesArgs): Promise<UpdateInfo | null>;
30
+ getAppUpdateInfo(args: GetBundlesArgs): Promise<AppUpdateInfo | null>;
31
+ getChannels(): Promise<string[]>;
32
+ getBundles(options: {
33
+ where?: {
34
+ channel?: string;
35
+ platform?: string;
36
+ };
37
+ limit: number;
38
+ offset: number;
39
+ }): Promise<{
40
+ data: Bundle[];
41
+ pagination: PaginationInfo;
42
+ }>;
43
+ insertBundle(bundle: Bundle): Promise<void>;
44
+ updateBundleById(bundleId: string, newBundle: Partial<Bundle>): Promise<void>;
45
+ deleteBundleById(bundleId: string): Promise<void>;
46
+ }
47
+ type HotUpdaterAPI = DatabaseAPI & {
48
+ handler: (request: Request) => Promise<Response>;
49
+ createMigrator: () => ReturnType<HotUpdaterClient["createMigrator"]>;
50
+ };
51
+ type StoragePluginFactory = (args: {
52
+ cwd: string;
53
+ }) => StoragePlugin;
54
+ interface HotUpdaterOptions {
55
+ database: DatabaseAdapter;
56
+ storagePlugins?: (StoragePlugin | StoragePluginFactory)[];
57
+ basePath?: string;
58
+ cwd?: string;
59
+ }
60
+ declare function hotUpdater(options: HotUpdaterOptions): HotUpdaterAPI;
61
+ //#endregion
62
+ export { DatabaseAPI, DatabaseAdapter, HotUpdaterAPI, HotUpdaterClient, HotUpdaterDB, HotUpdaterOptions, StoragePluginFactory, hotUpdater };