@hot-updater/cloudflare 0.29.4 → 0.29.6

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/src/d1Database.ts CHANGED
@@ -11,6 +11,7 @@ import type {
11
11
  import {
12
12
  calculatePagination,
13
13
  createDatabasePlugin,
14
+ createDatabasePluginGetUpdateInfo,
14
15
  } from "@hot-updater/plugin-core";
15
16
  import Cloudflare from "cloudflare";
16
17
  import minify from "pg-minify";
@@ -230,7 +231,90 @@ export const d1Database = createDatabasePlugin<D1DatabaseConfig>({
230
231
  return rows.map(transformRowToBundle);
231
232
  }
232
233
 
234
+ async function queryBundlesForUpdateInfo(
235
+ conditions: QueryConditions,
236
+ ): Promise<Bundle[]> {
237
+ const { sql: whereClause, params } = buildWhereClause(conditions);
238
+ const sql = minify(`
239
+ SELECT * FROM bundles
240
+ ${whereClause}
241
+ `);
242
+
243
+ const result = await cf.d1.database.query(config.databaseId, {
244
+ account_id: config.accountId,
245
+ sql,
246
+ params,
247
+ });
248
+
249
+ const rows = await resolvePage<SnakeCaseBundle>(result);
250
+ return rows.map(transformRowToBundle);
251
+ }
252
+
253
+ async function getTargetAppVersionsForUpdateInfo({
254
+ platform,
255
+ channel,
256
+ minBundleId,
257
+ }: {
258
+ platform: Bundle["platform"];
259
+ channel: string;
260
+ minBundleId: string;
261
+ }): Promise<string[]> {
262
+ const sql = minify(`
263
+ SELECT target_app_version
264
+ FROM bundles
265
+ WHERE channel = ?
266
+ AND platform = ?
267
+ AND enabled = 1
268
+ AND id >= ?
269
+ AND target_app_version IS NOT NULL
270
+ GROUP BY target_app_version
271
+ `);
272
+
273
+ const result = await cf.d1.database.query(config.databaseId, {
274
+ account_id: config.accountId,
275
+ sql,
276
+ params: [channel, platform, minBundleId],
277
+ });
278
+
279
+ const rows = await resolvePage<{ target_app_version: string }>(result);
280
+ return rows.map((row) => row.target_app_version);
281
+ }
282
+
233
283
  return {
284
+ getUpdateInfo: createDatabasePluginGetUpdateInfo({
285
+ listTargetAppVersions: getTargetAppVersionsForUpdateInfo,
286
+ getBundlesByTargetAppVersions(
287
+ { platform, channel, minBundleId },
288
+ targetAppVersions,
289
+ ) {
290
+ return queryBundlesForUpdateInfo({
291
+ enabled: true,
292
+ platform,
293
+ channel,
294
+ id: {
295
+ gte: minBundleId,
296
+ },
297
+ targetAppVersionIn: targetAppVersions,
298
+ });
299
+ },
300
+ getBundlesByFingerprint({
301
+ platform,
302
+ channel,
303
+ minBundleId,
304
+ fingerprintHash,
305
+ }) {
306
+ return queryBundlesForUpdateInfo({
307
+ enabled: true,
308
+ platform,
309
+ channel,
310
+ id: {
311
+ gte: minBundleId,
312
+ },
313
+ fingerprintHash,
314
+ });
315
+ },
316
+ }),
317
+
234
318
  async getBundleById(bundleId) {
235
319
  const sql = minify(/* sql */ `
236
320
  SELECT * FROM bundles WHERE id = ? LIMIT 1`);
@@ -250,7 +334,11 @@ export const d1Database = createDatabasePlugin<D1DatabaseConfig>({
250
334
  },
251
335
 
252
336
  async getBundles(options) {
253
- const { where = {}, limit, offset, orderBy } = options;
337
+ const { where = {}, limit, orderBy } = options;
338
+ const offset =
339
+ (("offset" in options ? options.offset : undefined) as
340
+ | number
341
+ | undefined) ?? 0;
254
342
 
255
343
  // 1. Get total count for pagination
256
344
  const totalCount = await getTotalCount(where);
@@ -1 +1 @@
1
- This folder contains the built output assets for the worker "hot-updater" generated at 2026-04-07T10:08:43.621Z.
1
+ This folder contains the built output assets for the worker "hot-updater" generated at 2026-04-09T04:37:25.139Z.