@hot-updater/plugin-core 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.
@@ -1,12 +1,73 @@
1
1
  require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_calculatePagination = require("./calculatePagination.cjs");
2
3
  let es_toolkit = require("es-toolkit");
3
4
  //#region src/createDatabasePlugin.ts
4
5
  const REPLACE_ON_UPDATE_KEYS = ["targetCohorts"];
6
+ const DEFAULT_DESC_ORDER = {
7
+ field: "id",
8
+ direction: "desc"
9
+ };
10
+ function normalizePage(value) {
11
+ if (!Number.isInteger(value) || value === void 0 || value < 1) return;
12
+ return value;
13
+ }
5
14
  function mergeBundleUpdate(baseBundle, patch) {
6
15
  return (0, es_toolkit.mergeWith)(baseBundle, patch, (_targetValue, sourceValue, key) => {
7
16
  if (REPLACE_ON_UPDATE_KEYS.includes(key)) return sourceValue;
8
17
  });
9
18
  }
19
+ function mergeIdFilter(base, patch) {
20
+ return {
21
+ ...base,
22
+ ...patch
23
+ };
24
+ }
25
+ function mergeWhereWithIdFilter(where, idFilter) {
26
+ return {
27
+ ...where,
28
+ id: mergeIdFilter(where?.id, idFilter)
29
+ };
30
+ }
31
+ function buildCursorPageQuery(where, cursor, orderBy) {
32
+ const direction = orderBy.direction;
33
+ if (cursor.after) return {
34
+ reverseData: false,
35
+ where: mergeWhereWithIdFilter(where, { [direction === "desc" ? "lt" : "gt"]: cursor.after }),
36
+ orderBy
37
+ };
38
+ if (cursor.before) return {
39
+ reverseData: true,
40
+ where: mergeWhereWithIdFilter(where, { [direction === "desc" ? "gt" : "lt"]: cursor.before }),
41
+ orderBy: {
42
+ field: orderBy.field,
43
+ direction: direction === "desc" ? "asc" : "desc"
44
+ }
45
+ };
46
+ return {
47
+ reverseData: false,
48
+ where: where ?? {},
49
+ orderBy
50
+ };
51
+ }
52
+ function buildCountBeforeWhere(where, firstBundleId, orderBy) {
53
+ return mergeWhereWithIdFilter(where, { [orderBy.direction === "desc" ? "gt" : "lt"]: firstBundleId });
54
+ }
55
+ function createPaginatedResult(total, limit, startIndex, data) {
56
+ const pagination = require_calculatePagination.calculatePagination(total, {
57
+ limit,
58
+ offset: startIndex
59
+ });
60
+ const nextCursor = data.length > 0 && startIndex + data.length < total ? data.at(-1)?.id : void 0;
61
+ const previousCursor = data.length > 0 && startIndex > 0 ? data[0]?.id : void 0;
62
+ return {
63
+ data,
64
+ pagination: {
65
+ ...pagination,
66
+ ...nextCursor ? { nextCursor } : {},
67
+ ...previousCursor ? { previousCursor } : {}
68
+ }
69
+ };
70
+ }
10
71
  /**
11
72
  * Creates a database plugin with lazy initialization and automatic hook execution.
12
73
  *
@@ -48,15 +109,95 @@ function createDatabasePlugin(options) {
48
109
  data
49
110
  });
50
111
  };
51
- return {
112
+ const runGetBundles = async (options, context) => {
113
+ if (context === void 0) return getMethods().getBundles(options);
114
+ return getMethods().getBundles(options, context);
115
+ };
116
+ const getBundlesWithLegacyCursorFallback = async (options, context) => {
117
+ const orderBy = options.orderBy ?? DEFAULT_DESC_ORDER;
118
+ const baseWhere = options.where;
119
+ const total = (await runGetBundles({
120
+ where: baseWhere,
121
+ limit: 1,
122
+ offset: 0,
123
+ orderBy
124
+ }, context)).pagination.total;
125
+ if (!options.cursor?.after && !options.cursor?.before) {
126
+ const firstPage = await runGetBundles({
127
+ where: baseWhere,
128
+ limit: options.limit,
129
+ offset: 0,
130
+ orderBy
131
+ }, context);
132
+ return createPaginatedResult(total, options.limit, 0, firstPage.data);
133
+ }
134
+ const { where, orderBy: queryOrderBy, reverseData } = buildCursorPageQuery(baseWhere, options.cursor, orderBy);
135
+ const cursorPage = await runGetBundles({
136
+ where,
137
+ limit: options.limit,
138
+ offset: 0,
139
+ orderBy: queryOrderBy
140
+ }, context);
141
+ const data = reverseData ? cursorPage.data.slice().reverse() : cursorPage.data;
142
+ if (data.length === 0) {
143
+ const emptyStartIndex = options.cursor.after ? total : 0;
144
+ return {
145
+ data,
146
+ pagination: {
147
+ ...require_calculatePagination.calculatePagination(total, {
148
+ limit: options.limit,
149
+ offset: emptyStartIndex
150
+ }),
151
+ ...options.cursor.after ? { previousCursor: options.cursor.after } : {},
152
+ ...options.cursor.before ? { nextCursor: options.cursor.before } : {}
153
+ }
154
+ };
155
+ }
156
+ const firstBundleId = data[0].id;
157
+ const countBeforeResult = await runGetBundles({
158
+ where: buildCountBeforeWhere(baseWhere, firstBundleId, orderBy),
159
+ limit: 1,
160
+ offset: 0,
161
+ orderBy
162
+ }, context);
163
+ return createPaginatedResult(total, options.limit, countBeforeResult.pagination.total, data);
164
+ };
165
+ const plugin = {
52
166
  name: options.name,
53
167
  async getBundleById(bundleId, context) {
54
168
  if (context === void 0) return getMethods().getBundleById(bundleId);
55
169
  return getMethods().getBundleById(bundleId, context);
56
170
  },
57
171
  async getBundles(options, context) {
58
- if (context === void 0) return getMethods().getBundles(options);
59
- return getMethods().getBundles(options, context);
172
+ if (typeof options === "object" && options !== null && "offset" in options && options.offset !== void 0) throw new Error("Bundle offset pagination has been removed. Use cursor.after or cursor.before instead.");
173
+ const methods = getMethods();
174
+ const normalizedOptions = {
175
+ ...options,
176
+ page: normalizePage(options.page),
177
+ orderBy: options.orderBy ?? DEFAULT_DESC_ORDER
178
+ };
179
+ if (normalizedOptions.page !== void 0) {
180
+ const { page, ...pageOptions } = normalizedOptions;
181
+ const requestedOffset = (page - 1) * normalizedOptions.limit;
182
+ let pageResult = await runGetBundles({
183
+ ...pageOptions,
184
+ offset: requestedOffset
185
+ }, context);
186
+ const total = pageResult.pagination.total;
187
+ const totalPages = total === 0 ? 0 : Math.ceil(total / normalizedOptions.limit);
188
+ const maxOffset = totalPages === 0 ? 0 : (Math.max(1, totalPages) - 1) * normalizedOptions.limit;
189
+ const resolvedOffset = Math.min(requestedOffset, maxOffset);
190
+ if (resolvedOffset !== requestedOffset) pageResult = await runGetBundles({
191
+ ...pageOptions,
192
+ offset: resolvedOffset
193
+ }, context);
194
+ return createPaginatedResult(total, normalizedOptions.limit, resolvedOffset, pageResult.data);
195
+ }
196
+ if (methods.supportsCursorPagination) {
197
+ if (context === void 0) return methods.getBundles(normalizedOptions);
198
+ return methods.getBundles(normalizedOptions, context);
199
+ }
200
+ return getBundlesWithLegacyCursorFallback(normalizedOptions, context);
60
201
  },
61
202
  async getChannels(context) {
62
203
  if (context === void 0) return getMethods().getChannels();
@@ -95,6 +236,32 @@ function createDatabasePlugin(options) {
95
236
  markChanged("delete", deleteBundle);
96
237
  }
97
238
  };
239
+ Object.defineProperty(plugin, "getUpdateInfo", {
240
+ configurable: true,
241
+ enumerable: true,
242
+ get() {
243
+ const directGetUpdateInfo = getMethods().getUpdateInfo;
244
+ if (!directGetUpdateInfo) {
245
+ Object.defineProperty(plugin, "getUpdateInfo", {
246
+ configurable: true,
247
+ enumerable: true,
248
+ value: void 0
249
+ });
250
+ return;
251
+ }
252
+ const wrappedGetUpdateInfo = async (args, context) => {
253
+ if (context === void 0) return directGetUpdateInfo(args);
254
+ return directGetUpdateInfo(args, context);
255
+ };
256
+ Object.defineProperty(plugin, "getUpdateInfo", {
257
+ configurable: true,
258
+ enumerable: true,
259
+ value: wrappedGetUpdateInfo
260
+ });
261
+ return wrappedGetUpdateInfo;
262
+ }
263
+ });
264
+ return plugin;
98
265
  };
99
266
  };
100
267
  }
@@ -1,10 +1,14 @@
1
1
  import { DatabaseBundleQueryOptions, DatabasePlugin, DatabasePluginHooks, HotUpdaterContext, Paginated } from "./types/index.cjs";
2
- import { Bundle } from "@hot-updater/core";
2
+ import { Bundle, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
3
3
 
4
4
  //#region src/createDatabasePlugin.d.ts
5
5
  interface AbstractDatabasePlugin<TContext = unknown> {
6
+ supportsCursorPagination?: boolean;
6
7
  getBundleById: (bundleId: string, context?: HotUpdaterContext<TContext>) => Promise<Bundle | null>;
7
- getBundles: (options: DatabaseBundleQueryOptions, context?: HotUpdaterContext<TContext>) => Promise<Paginated<Bundle[]>>;
8
+ getUpdateInfo?: (args: GetBundlesArgs, context?: HotUpdaterContext<TContext>) => Promise<UpdateInfo | null>;
9
+ getBundles: (options: DatabaseBundleQueryOptions & {
10
+ offset?: number;
11
+ }, context?: HotUpdaterContext<TContext>) => Promise<Paginated<Bundle[]>>;
8
12
  getChannels: (context?: HotUpdaterContext<TContext>) => Promise<string[]>;
9
13
  onUnmount?: () => Promise<void>;
10
14
  commitBundle: (params: {
@@ -1,10 +1,14 @@
1
1
  import { DatabaseBundleQueryOptions, DatabasePlugin, DatabasePluginHooks, HotUpdaterContext, Paginated } from "./types/index.mjs";
2
- import { Bundle } from "@hot-updater/core";
2
+ import { Bundle, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
3
3
 
4
4
  //#region src/createDatabasePlugin.d.ts
5
5
  interface AbstractDatabasePlugin<TContext = unknown> {
6
+ supportsCursorPagination?: boolean;
6
7
  getBundleById: (bundleId: string, context?: HotUpdaterContext<TContext>) => Promise<Bundle | null>;
7
- getBundles: (options: DatabaseBundleQueryOptions, context?: HotUpdaterContext<TContext>) => Promise<Paginated<Bundle[]>>;
8
+ getUpdateInfo?: (args: GetBundlesArgs, context?: HotUpdaterContext<TContext>) => Promise<UpdateInfo | null>;
9
+ getBundles: (options: DatabaseBundleQueryOptions & {
10
+ offset?: number;
11
+ }, context?: HotUpdaterContext<TContext>) => Promise<Paginated<Bundle[]>>;
8
12
  getChannels: (context?: HotUpdaterContext<TContext>) => Promise<string[]>;
9
13
  onUnmount?: () => Promise<void>;
10
14
  commitBundle: (params: {
@@ -1,11 +1,72 @@
1
+ import { calculatePagination } from "./calculatePagination.mjs";
1
2
  import { mergeWith } from "es-toolkit";
2
3
  //#region src/createDatabasePlugin.ts
3
4
  const REPLACE_ON_UPDATE_KEYS = ["targetCohorts"];
5
+ const DEFAULT_DESC_ORDER = {
6
+ field: "id",
7
+ direction: "desc"
8
+ };
9
+ function normalizePage(value) {
10
+ if (!Number.isInteger(value) || value === void 0 || value < 1) return;
11
+ return value;
12
+ }
4
13
  function mergeBundleUpdate(baseBundle, patch) {
5
14
  return mergeWith(baseBundle, patch, (_targetValue, sourceValue, key) => {
6
15
  if (REPLACE_ON_UPDATE_KEYS.includes(key)) return sourceValue;
7
16
  });
8
17
  }
18
+ function mergeIdFilter(base, patch) {
19
+ return {
20
+ ...base,
21
+ ...patch
22
+ };
23
+ }
24
+ function mergeWhereWithIdFilter(where, idFilter) {
25
+ return {
26
+ ...where,
27
+ id: mergeIdFilter(where?.id, idFilter)
28
+ };
29
+ }
30
+ function buildCursorPageQuery(where, cursor, orderBy) {
31
+ const direction = orderBy.direction;
32
+ if (cursor.after) return {
33
+ reverseData: false,
34
+ where: mergeWhereWithIdFilter(where, { [direction === "desc" ? "lt" : "gt"]: cursor.after }),
35
+ orderBy
36
+ };
37
+ if (cursor.before) return {
38
+ reverseData: true,
39
+ where: mergeWhereWithIdFilter(where, { [direction === "desc" ? "gt" : "lt"]: cursor.before }),
40
+ orderBy: {
41
+ field: orderBy.field,
42
+ direction: direction === "desc" ? "asc" : "desc"
43
+ }
44
+ };
45
+ return {
46
+ reverseData: false,
47
+ where: where ?? {},
48
+ orderBy
49
+ };
50
+ }
51
+ function buildCountBeforeWhere(where, firstBundleId, orderBy) {
52
+ return mergeWhereWithIdFilter(where, { [orderBy.direction === "desc" ? "gt" : "lt"]: firstBundleId });
53
+ }
54
+ function createPaginatedResult(total, limit, startIndex, data) {
55
+ const pagination = calculatePagination(total, {
56
+ limit,
57
+ offset: startIndex
58
+ });
59
+ const nextCursor = data.length > 0 && startIndex + data.length < total ? data.at(-1)?.id : void 0;
60
+ const previousCursor = data.length > 0 && startIndex > 0 ? data[0]?.id : void 0;
61
+ return {
62
+ data,
63
+ pagination: {
64
+ ...pagination,
65
+ ...nextCursor ? { nextCursor } : {},
66
+ ...previousCursor ? { previousCursor } : {}
67
+ }
68
+ };
69
+ }
9
70
  /**
10
71
  * Creates a database plugin with lazy initialization and automatic hook execution.
11
72
  *
@@ -47,15 +108,95 @@ function createDatabasePlugin(options) {
47
108
  data
48
109
  });
49
110
  };
50
- return {
111
+ const runGetBundles = async (options, context) => {
112
+ if (context === void 0) return getMethods().getBundles(options);
113
+ return getMethods().getBundles(options, context);
114
+ };
115
+ const getBundlesWithLegacyCursorFallback = async (options, context) => {
116
+ const orderBy = options.orderBy ?? DEFAULT_DESC_ORDER;
117
+ const baseWhere = options.where;
118
+ const total = (await runGetBundles({
119
+ where: baseWhere,
120
+ limit: 1,
121
+ offset: 0,
122
+ orderBy
123
+ }, context)).pagination.total;
124
+ if (!options.cursor?.after && !options.cursor?.before) {
125
+ const firstPage = await runGetBundles({
126
+ where: baseWhere,
127
+ limit: options.limit,
128
+ offset: 0,
129
+ orderBy
130
+ }, context);
131
+ return createPaginatedResult(total, options.limit, 0, firstPage.data);
132
+ }
133
+ const { where, orderBy: queryOrderBy, reverseData } = buildCursorPageQuery(baseWhere, options.cursor, orderBy);
134
+ const cursorPage = await runGetBundles({
135
+ where,
136
+ limit: options.limit,
137
+ offset: 0,
138
+ orderBy: queryOrderBy
139
+ }, context);
140
+ const data = reverseData ? cursorPage.data.slice().reverse() : cursorPage.data;
141
+ if (data.length === 0) {
142
+ const emptyStartIndex = options.cursor.after ? total : 0;
143
+ return {
144
+ data,
145
+ pagination: {
146
+ ...calculatePagination(total, {
147
+ limit: options.limit,
148
+ offset: emptyStartIndex
149
+ }),
150
+ ...options.cursor.after ? { previousCursor: options.cursor.after } : {},
151
+ ...options.cursor.before ? { nextCursor: options.cursor.before } : {}
152
+ }
153
+ };
154
+ }
155
+ const firstBundleId = data[0].id;
156
+ const countBeforeResult = await runGetBundles({
157
+ where: buildCountBeforeWhere(baseWhere, firstBundleId, orderBy),
158
+ limit: 1,
159
+ offset: 0,
160
+ orderBy
161
+ }, context);
162
+ return createPaginatedResult(total, options.limit, countBeforeResult.pagination.total, data);
163
+ };
164
+ const plugin = {
51
165
  name: options.name,
52
166
  async getBundleById(bundleId, context) {
53
167
  if (context === void 0) return getMethods().getBundleById(bundleId);
54
168
  return getMethods().getBundleById(bundleId, context);
55
169
  },
56
170
  async getBundles(options, context) {
57
- if (context === void 0) return getMethods().getBundles(options);
58
- return getMethods().getBundles(options, context);
171
+ if (typeof options === "object" && options !== null && "offset" in options && options.offset !== void 0) throw new Error("Bundle offset pagination has been removed. Use cursor.after or cursor.before instead.");
172
+ const methods = getMethods();
173
+ const normalizedOptions = {
174
+ ...options,
175
+ page: normalizePage(options.page),
176
+ orderBy: options.orderBy ?? DEFAULT_DESC_ORDER
177
+ };
178
+ if (normalizedOptions.page !== void 0) {
179
+ const { page, ...pageOptions } = normalizedOptions;
180
+ const requestedOffset = (page - 1) * normalizedOptions.limit;
181
+ let pageResult = await runGetBundles({
182
+ ...pageOptions,
183
+ offset: requestedOffset
184
+ }, context);
185
+ const total = pageResult.pagination.total;
186
+ const totalPages = total === 0 ? 0 : Math.ceil(total / normalizedOptions.limit);
187
+ const maxOffset = totalPages === 0 ? 0 : (Math.max(1, totalPages) - 1) * normalizedOptions.limit;
188
+ const resolvedOffset = Math.min(requestedOffset, maxOffset);
189
+ if (resolvedOffset !== requestedOffset) pageResult = await runGetBundles({
190
+ ...pageOptions,
191
+ offset: resolvedOffset
192
+ }, context);
193
+ return createPaginatedResult(total, normalizedOptions.limit, resolvedOffset, pageResult.data);
194
+ }
195
+ if (methods.supportsCursorPagination) {
196
+ if (context === void 0) return methods.getBundles(normalizedOptions);
197
+ return methods.getBundles(normalizedOptions, context);
198
+ }
199
+ return getBundlesWithLegacyCursorFallback(normalizedOptions, context);
59
200
  },
60
201
  async getChannels(context) {
61
202
  if (context === void 0) return getMethods().getChannels();
@@ -94,6 +235,32 @@ function createDatabasePlugin(options) {
94
235
  markChanged("delete", deleteBundle);
95
236
  }
96
237
  };
238
+ Object.defineProperty(plugin, "getUpdateInfo", {
239
+ configurable: true,
240
+ enumerable: true,
241
+ get() {
242
+ const directGetUpdateInfo = getMethods().getUpdateInfo;
243
+ if (!directGetUpdateInfo) {
244
+ Object.defineProperty(plugin, "getUpdateInfo", {
245
+ configurable: true,
246
+ enumerable: true,
247
+ value: void 0
248
+ });
249
+ return;
250
+ }
251
+ const wrappedGetUpdateInfo = async (args, context) => {
252
+ if (context === void 0) return directGetUpdateInfo(args);
253
+ return directGetUpdateInfo(args, context);
254
+ };
255
+ Object.defineProperty(plugin, "getUpdateInfo", {
256
+ configurable: true,
257
+ enumerable: true,
258
+ value: wrappedGetUpdateInfo
259
+ });
260
+ return wrappedGetUpdateInfo;
261
+ }
262
+ });
263
+ return plugin;
97
264
  };
98
265
  };
99
266
  }
@@ -0,0 +1,28 @@
1
+ require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_filterCompatibleAppVersions = require("./filterCompatibleAppVersions.cjs");
3
+ let _hot_updater_js = require("@hot-updater/js");
4
+ let _hot_updater_core = require("@hot-updater/core");
5
+ //#region src/createDatabasePluginGetUpdateInfo.ts
6
+ const normalizeAppVersionArgs = (args) => ({
7
+ ...args,
8
+ channel: args.channel ?? "production",
9
+ minBundleId: args.minBundleId ?? _hot_updater_core.NIL_UUID
10
+ });
11
+ const normalizeFingerprintArgs = (args) => ({
12
+ ...args,
13
+ channel: args.channel ?? "production",
14
+ minBundleId: args.minBundleId ?? _hot_updater_core.NIL_UUID
15
+ });
16
+ const createDatabasePluginGetUpdateInfo = ({ getBundlesByFingerprint, getBundlesByTargetAppVersions, listTargetAppVersions }) => {
17
+ return async (args, context) => {
18
+ if (args._updateStrategy === "appVersion") {
19
+ const normalizedArgs = normalizeAppVersionArgs(args);
20
+ const compatibleAppVersions = require_filterCompatibleAppVersions.filterCompatibleAppVersions(await listTargetAppVersions(normalizedArgs, context), normalizedArgs.appVersion);
21
+ return (0, _hot_updater_js.getUpdateInfo)(compatibleAppVersions.length > 0 ? await getBundlesByTargetAppVersions(normalizedArgs, compatibleAppVersions, context) : [], normalizedArgs);
22
+ }
23
+ const normalizedArgs = normalizeFingerprintArgs(args);
24
+ return (0, _hot_updater_js.getUpdateInfo)(await getBundlesByFingerprint(normalizedArgs, context), normalizedArgs);
25
+ };
26
+ };
27
+ //#endregion
28
+ exports.createDatabasePluginGetUpdateInfo = createDatabasePluginGetUpdateInfo;
@@ -0,0 +1,27 @@
1
+ import { Bundle as Bundle$1, HotUpdaterContext } from "./types/index.cjs";
2
+ import { AppVersionGetBundlesArgs, FingerprintGetBundlesArgs, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
3
+
4
+ //#region src/createDatabasePluginGetUpdateInfo.d.ts
5
+ type AppVersionLookupArgs = {
6
+ channel: string;
7
+ minBundleId: string;
8
+ platform: AppVersionGetBundlesArgs["platform"];
9
+ };
10
+ type FingerprintLookupArgs = {
11
+ channel: string;
12
+ fingerprintHash: string;
13
+ minBundleId: string;
14
+ platform: FingerprintGetBundlesArgs["platform"];
15
+ };
16
+ interface CreateDatabasePluginGetUpdateInfoOptions<TContext = unknown> {
17
+ getBundlesByFingerprint: (args: FingerprintLookupArgs, context?: HotUpdaterContext<TContext>) => Promise<Bundle$1[]>;
18
+ getBundlesByTargetAppVersions: (args: AppVersionLookupArgs, targetAppVersions: string[], context?: HotUpdaterContext<TContext>) => Promise<Bundle$1[]>;
19
+ listTargetAppVersions: (args: AppVersionLookupArgs, context?: HotUpdaterContext<TContext>) => Promise<string[]>;
20
+ }
21
+ declare const createDatabasePluginGetUpdateInfo: <TContext = unknown>({
22
+ getBundlesByFingerprint,
23
+ getBundlesByTargetAppVersions,
24
+ listTargetAppVersions
25
+ }: CreateDatabasePluginGetUpdateInfoOptions<TContext>) => (args: GetBundlesArgs, context?: HotUpdaterContext<TContext>) => Promise<UpdateInfo | null>;
26
+ //#endregion
27
+ export { CreateDatabasePluginGetUpdateInfoOptions, createDatabasePluginGetUpdateInfo };
@@ -0,0 +1,27 @@
1
+ import { Bundle as Bundle$1, HotUpdaterContext } from "./types/index.mjs";
2
+ import { AppVersionGetBundlesArgs, FingerprintGetBundlesArgs, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
3
+
4
+ //#region src/createDatabasePluginGetUpdateInfo.d.ts
5
+ type AppVersionLookupArgs = {
6
+ channel: string;
7
+ minBundleId: string;
8
+ platform: AppVersionGetBundlesArgs["platform"];
9
+ };
10
+ type FingerprintLookupArgs = {
11
+ channel: string;
12
+ fingerprintHash: string;
13
+ minBundleId: string;
14
+ platform: FingerprintGetBundlesArgs["platform"];
15
+ };
16
+ interface CreateDatabasePluginGetUpdateInfoOptions<TContext = unknown> {
17
+ getBundlesByFingerprint: (args: FingerprintLookupArgs, context?: HotUpdaterContext<TContext>) => Promise<Bundle$1[]>;
18
+ getBundlesByTargetAppVersions: (args: AppVersionLookupArgs, targetAppVersions: string[], context?: HotUpdaterContext<TContext>) => Promise<Bundle$1[]>;
19
+ listTargetAppVersions: (args: AppVersionLookupArgs, context?: HotUpdaterContext<TContext>) => Promise<string[]>;
20
+ }
21
+ declare const createDatabasePluginGetUpdateInfo: <TContext = unknown>({
22
+ getBundlesByFingerprint,
23
+ getBundlesByTargetAppVersions,
24
+ listTargetAppVersions
25
+ }: CreateDatabasePluginGetUpdateInfoOptions<TContext>) => (args: GetBundlesArgs, context?: HotUpdaterContext<TContext>) => Promise<UpdateInfo | null>;
26
+ //#endregion
27
+ export { CreateDatabasePluginGetUpdateInfoOptions, createDatabasePluginGetUpdateInfo };
@@ -0,0 +1,27 @@
1
+ import { filterCompatibleAppVersions } from "./filterCompatibleAppVersions.mjs";
2
+ import { getUpdateInfo } from "@hot-updater/js";
3
+ import { NIL_UUID } from "@hot-updater/core";
4
+ //#region src/createDatabasePluginGetUpdateInfo.ts
5
+ const normalizeAppVersionArgs = (args) => ({
6
+ ...args,
7
+ channel: args.channel ?? "production",
8
+ minBundleId: args.minBundleId ?? NIL_UUID
9
+ });
10
+ const normalizeFingerprintArgs = (args) => ({
11
+ ...args,
12
+ channel: args.channel ?? "production",
13
+ minBundleId: args.minBundleId ?? NIL_UUID
14
+ });
15
+ const createDatabasePluginGetUpdateInfo = ({ getBundlesByFingerprint, getBundlesByTargetAppVersions, listTargetAppVersions }) => {
16
+ return async (args, context) => {
17
+ if (args._updateStrategy === "appVersion") {
18
+ const normalizedArgs = normalizeAppVersionArgs(args);
19
+ const compatibleAppVersions = filterCompatibleAppVersions(await listTargetAppVersions(normalizedArgs, context), normalizedArgs.appVersion);
20
+ return getUpdateInfo(compatibleAppVersions.length > 0 ? await getBundlesByTargetAppVersions(normalizedArgs, compatibleAppVersions, context) : [], normalizedArgs);
21
+ }
22
+ const normalizedArgs = normalizeFingerprintArgs(args);
23
+ return getUpdateInfo(await getBundlesByFingerprint(normalizedArgs, context), normalizedArgs);
24
+ };
25
+ };
26
+ //#endregion
27
+ export { createDatabasePluginGetUpdateInfo };
package/dist/index.cjs CHANGED
@@ -2,12 +2,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_calculatePagination = require("./calculatePagination.cjs");
3
3
  const require_compressionFormat = require("./compressionFormat.cjs");
4
4
  const require_createDatabasePlugin = require("./createDatabasePlugin.cjs");
5
+ const require_semverSatisfies = require("./semverSatisfies.cjs");
6
+ const require_filterCompatibleAppVersions = require("./filterCompatibleAppVersions.cjs");
5
7
  const require_queryBundles = require("./queryBundles.cjs");
8
+ const require_paginateBundles = require("./paginateBundles.cjs");
6
9
  const require_createBlobDatabasePlugin = require("./createBlobDatabasePlugin.cjs");
10
+ const require_createDatabasePluginGetUpdateInfo = require("./createDatabasePluginGetUpdateInfo.cjs");
7
11
  const require_createStorageKeyBuilder = require("./createStorageKeyBuilder.cjs");
8
12
  const require_createStoragePlugin = require("./createStoragePlugin.cjs");
9
- const require_semverSatisfies = require("./semverSatisfies.cjs");
10
- const require_filterCompatibleAppVersions = require("./filterCompatibleAppVersions.cjs");
11
13
  const require_generateMinBundleId = require("./generateMinBundleId.cjs");
12
14
  const require_parseStorageUri = require("./parseStorageUri.cjs");
13
15
  const require_index = require("./types/index.cjs");
@@ -16,6 +18,7 @@ exports.bundleMatchesQueryWhere = require_queryBundles.bundleMatchesQueryWhere;
16
18
  exports.calculatePagination = require_calculatePagination.calculatePagination;
17
19
  exports.createBlobDatabasePlugin = require_createBlobDatabasePlugin.createBlobDatabasePlugin;
18
20
  exports.createDatabasePlugin = require_createDatabasePlugin.createDatabasePlugin;
21
+ exports.createDatabasePluginGetUpdateInfo = require_createDatabasePluginGetUpdateInfo.createDatabasePluginGetUpdateInfo;
19
22
  exports.createStorageKeyBuilder = require_createStorageKeyBuilder.createStorageKeyBuilder;
20
23
  exports.createStoragePlugin = require_createStoragePlugin.createStoragePlugin;
21
24
  exports.detectCompressionFormat = require_compressionFormat.detectCompressionFormat;
@@ -23,6 +26,7 @@ exports.filterCompatibleAppVersions = require_filterCompatibleAppVersions.filter
23
26
  exports.generateMinBundleId = require_generateMinBundleId.generateMinBundleId;
24
27
  exports.getCompressionMimeType = require_compressionFormat.getCompressionMimeType;
25
28
  exports.getContentType = require_compressionFormat.getContentType;
29
+ exports.paginateBundles = require_paginateBundles.paginateBundles;
26
30
  exports.parseStorageUri = require_parseStorageUri.parseStorageUri;
27
31
  exports.semverSatisfies = require_semverSatisfies.semverSatisfies;
28
32
  exports.sortBundles = require_queryBundles.sortBundles;
package/dist/index.d.cts CHANGED
@@ -1,14 +1,16 @@
1
1
  import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./types/utils.cjs";
2
- import { ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, RequestEnvContext, SigningConfig, StoragePlugin, StoragePluginHooks, StorageResolveContext, supportedIosPlatforms } from "./types/index.cjs";
2
+ import { AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, RequestEnvContext, SigningConfig, StoragePlugin, StoragePluginHooks, StorageResolveContext, UpdateInfo, supportedIosPlatforms } from "./types/index.cjs";
3
3
  import { PaginationOptions, calculatePagination } from "./calculatePagination.cjs";
4
4
  import { CompressionFormat, CompressionFormatInfo, detectCompressionFormat, getCompressionMimeType, getContentType } from "./compressionFormat.cjs";
5
- import { BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.cjs";
5
+ import { BlobDatabasePluginConfig, BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.cjs";
6
6
  import { AbstractDatabasePlugin, CreateDatabasePluginOptions, createDatabasePlugin } from "./createDatabasePlugin.cjs";
7
+ import { CreateDatabasePluginGetUpdateInfoOptions, createDatabasePluginGetUpdateInfo } from "./createDatabasePluginGetUpdateInfo.cjs";
7
8
  import { createStorageKeyBuilder } from "./createStorageKeyBuilder.cjs";
8
9
  import { CreateStoragePluginOptions, createStoragePlugin } from "./createStoragePlugin.cjs";
9
10
  import { filterCompatibleAppVersions } from "./filterCompatibleAppVersions.cjs";
10
11
  import { generateMinBundleId } from "./generateMinBundleId.cjs";
11
12
  import { ParsedStorageUri, parseStorageUri } from "./parseStorageUri.cjs";
13
+ import { paginateBundles } from "./paginateBundles.cjs";
12
14
  import { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles } from "./queryBundles.cjs";
13
15
  import { semverSatisfies } from "./semverSatisfies.cjs";
14
- export { AbstractDatabasePlugin, ApplePlatform, BasePluginArgs, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginOptions, CreateStoragePluginOptions, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, HasMultipleCallSignatures, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequestEnvContext, RequiredDeep, SigningConfig, StoragePlugin, StoragePluginHooks, StorageResolveContext, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, parseStorageUri, semverSatisfies, sortBundles, supportedIosPlatforms };
16
+ export { AbstractDatabasePlugin, AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BlobDatabasePluginConfig, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginGetUpdateInfoOptions, CreateDatabasePluginOptions, CreateStoragePluginOptions, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HasMultipleCallSignatures, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequestEnvContext, RequiredDeep, SigningConfig, StoragePlugin, StoragePluginHooks, StorageResolveContext, UpdateInfo, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createDatabasePluginGetUpdateInfo, createStorageKeyBuilder, createStoragePlugin, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, paginateBundles, parseStorageUri, semverSatisfies, sortBundles, supportedIosPlatforms };
package/dist/index.d.mts CHANGED
@@ -1,14 +1,16 @@
1
1
  import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./types/utils.mjs";
2
- import { ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, RequestEnvContext, SigningConfig, StoragePlugin, StoragePluginHooks, StorageResolveContext, supportedIosPlatforms } from "./types/index.mjs";
2
+ import { AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, RequestEnvContext, SigningConfig, StoragePlugin, StoragePluginHooks, StorageResolveContext, UpdateInfo, supportedIosPlatforms } from "./types/index.mjs";
3
3
  import { PaginationOptions, calculatePagination } from "./calculatePagination.mjs";
4
4
  import { CompressionFormat, CompressionFormatInfo, detectCompressionFormat, getCompressionMimeType, getContentType } from "./compressionFormat.mjs";
5
- import { BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.mjs";
5
+ import { BlobDatabasePluginConfig, BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.mjs";
6
6
  import { AbstractDatabasePlugin, CreateDatabasePluginOptions, createDatabasePlugin } from "./createDatabasePlugin.mjs";
7
+ import { CreateDatabasePluginGetUpdateInfoOptions, createDatabasePluginGetUpdateInfo } from "./createDatabasePluginGetUpdateInfo.mjs";
7
8
  import { createStorageKeyBuilder } from "./createStorageKeyBuilder.mjs";
8
9
  import { CreateStoragePluginOptions, createStoragePlugin } from "./createStoragePlugin.mjs";
9
10
  import { filterCompatibleAppVersions } from "./filterCompatibleAppVersions.mjs";
10
11
  import { generateMinBundleId } from "./generateMinBundleId.mjs";
11
12
  import { ParsedStorageUri, parseStorageUri } from "./parseStorageUri.mjs";
13
+ import { paginateBundles } from "./paginateBundles.mjs";
12
14
  import { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles } from "./queryBundles.mjs";
13
15
  import { semverSatisfies } from "./semverSatisfies.mjs";
14
- export { AbstractDatabasePlugin, ApplePlatform, BasePluginArgs, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginOptions, CreateStoragePluginOptions, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, HasMultipleCallSignatures, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequestEnvContext, RequiredDeep, SigningConfig, StoragePlugin, StoragePluginHooks, StorageResolveContext, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, parseStorageUri, semverSatisfies, sortBundles, supportedIosPlatforms };
16
+ export { AbstractDatabasePlugin, AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BlobDatabasePluginConfig, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginGetUpdateInfoOptions, CreateDatabasePluginOptions, CreateStoragePluginOptions, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HasMultipleCallSignatures, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequestEnvContext, RequiredDeep, SigningConfig, StoragePlugin, StoragePluginHooks, StorageResolveContext, UpdateInfo, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createDatabasePluginGetUpdateInfo, createStorageKeyBuilder, createStoragePlugin, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, paginateBundles, parseStorageUri, semverSatisfies, sortBundles, supportedIosPlatforms };