@hot-updater/plugin-core 0.29.5 → 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/dist/createBlobDatabasePlugin.cjs +449 -41
- package/dist/createBlobDatabasePlugin.d.cts +4 -1
- package/dist/createBlobDatabasePlugin.d.mts +4 -1
- package/dist/createBlobDatabasePlugin.mjs +449 -41
- package/dist/createDatabasePlugin.cjs +143 -2
- package/dist/createDatabasePlugin.d.cts +4 -1
- package/dist/createDatabasePlugin.d.mts +4 -1
- package/dist/createDatabasePlugin.mjs +143 -2
- package/dist/createDatabasePluginGetUpdateInfo.cjs +28 -0
- package/dist/createDatabasePluginGetUpdateInfo.d.cts +27 -0
- package/dist/createDatabasePluginGetUpdateInfo.d.mts +27 -0
- package/dist/createDatabasePluginGetUpdateInfo.mjs +27 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +5 -3
- package/dist/index.d.mts +5 -3
- package/dist/index.mjs +3 -1
- package/dist/paginateBundles.cjs +53 -0
- package/dist/paginateBundles.d.cts +18 -0
- package/dist/paginateBundles.d.mts +18 -0
- package/dist/paginateBundles.mjs +53 -0
- package/dist/types/index.d.cts +27 -3
- package/dist/types/index.d.mts +27 -3
- package/package.json +4 -4
|
@@ -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,6 +109,59 @@ function createDatabasePlugin(options) {
|
|
|
48
109
|
data
|
|
49
110
|
});
|
|
50
111
|
};
|
|
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
|
+
};
|
|
51
165
|
const plugin = {
|
|
52
166
|
name: options.name,
|
|
53
167
|
async getBundleById(bundleId, context) {
|
|
@@ -55,8 +169,35 @@ function createDatabasePlugin(options) {
|
|
|
55
169
|
return getMethods().getBundleById(bundleId, context);
|
|
56
170
|
},
|
|
57
171
|
async getBundles(options, context) {
|
|
58
|
-
if (
|
|
59
|
-
|
|
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();
|
|
@@ -3,9 +3,12 @@ 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
8
|
getUpdateInfo?: (args: GetBundlesArgs, context?: HotUpdaterContext<TContext>) => Promise<UpdateInfo | null>;
|
|
8
|
-
getBundles: (options: DatabaseBundleQueryOptions
|
|
9
|
+
getBundles: (options: DatabaseBundleQueryOptions & {
|
|
10
|
+
offset?: number;
|
|
11
|
+
}, context?: HotUpdaterContext<TContext>) => Promise<Paginated<Bundle[]>>;
|
|
9
12
|
getChannels: (context?: HotUpdaterContext<TContext>) => Promise<string[]>;
|
|
10
13
|
onUnmount?: () => Promise<void>;
|
|
11
14
|
commitBundle: (params: {
|
|
@@ -3,9 +3,12 @@ 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
8
|
getUpdateInfo?: (args: GetBundlesArgs, context?: HotUpdaterContext<TContext>) => Promise<UpdateInfo | null>;
|
|
8
|
-
getBundles: (options: DatabaseBundleQueryOptions
|
|
9
|
+
getBundles: (options: DatabaseBundleQueryOptions & {
|
|
10
|
+
offset?: number;
|
|
11
|
+
}, context?: HotUpdaterContext<TContext>) => Promise<Paginated<Bundle[]>>;
|
|
9
12
|
getChannels: (context?: HotUpdaterContext<TContext>) => Promise<string[]>;
|
|
10
13
|
onUnmount?: () => Promise<void>;
|
|
11
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,6 +108,59 @@ function createDatabasePlugin(options) {
|
|
|
47
108
|
data
|
|
48
109
|
});
|
|
49
110
|
};
|
|
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
|
+
};
|
|
50
164
|
const plugin = {
|
|
51
165
|
name: options.name,
|
|
52
166
|
async getBundleById(bundleId, context) {
|
|
@@ -54,8 +168,35 @@ function createDatabasePlugin(options) {
|
|
|
54
168
|
return getMethods().getBundleById(bundleId, context);
|
|
55
169
|
},
|
|
56
170
|
async getBundles(options, context) {
|
|
57
|
-
if (
|
|
58
|
-
|
|
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();
|
|
@@ -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
|
@@ -5,7 +5,9 @@ const require_createDatabasePlugin = require("./createDatabasePlugin.cjs");
|
|
|
5
5
|
const require_semverSatisfies = require("./semverSatisfies.cjs");
|
|
6
6
|
const require_filterCompatibleAppVersions = require("./filterCompatibleAppVersions.cjs");
|
|
7
7
|
const require_queryBundles = require("./queryBundles.cjs");
|
|
8
|
+
const require_paginateBundles = require("./paginateBundles.cjs");
|
|
8
9
|
const require_createBlobDatabasePlugin = require("./createBlobDatabasePlugin.cjs");
|
|
10
|
+
const require_createDatabasePluginGetUpdateInfo = require("./createDatabasePluginGetUpdateInfo.cjs");
|
|
9
11
|
const require_createStorageKeyBuilder = require("./createStorageKeyBuilder.cjs");
|
|
10
12
|
const require_createStoragePlugin = require("./createStoragePlugin.cjs");
|
|
11
13
|
const require_generateMinBundleId = require("./generateMinBundleId.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 { AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, 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";
|
|
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, AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginOptions, CreateStoragePluginOptions, 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, 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 { AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, 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";
|
|
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, AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginOptions, CreateStoragePluginOptions, 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, 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.mjs
CHANGED
|
@@ -4,10 +4,12 @@ import { createDatabasePlugin } from "./createDatabasePlugin.mjs";
|
|
|
4
4
|
import { semverSatisfies } from "./semverSatisfies.mjs";
|
|
5
5
|
import { filterCompatibleAppVersions } from "./filterCompatibleAppVersions.mjs";
|
|
6
6
|
import { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles } from "./queryBundles.mjs";
|
|
7
|
+
import { paginateBundles } from "./paginateBundles.mjs";
|
|
7
8
|
import { createBlobDatabasePlugin } from "./createBlobDatabasePlugin.mjs";
|
|
9
|
+
import { createDatabasePluginGetUpdateInfo } from "./createDatabasePluginGetUpdateInfo.mjs";
|
|
8
10
|
import { createStorageKeyBuilder } from "./createStorageKeyBuilder.mjs";
|
|
9
11
|
import { createStoragePlugin } from "./createStoragePlugin.mjs";
|
|
10
12
|
import { generateMinBundleId } from "./generateMinBundleId.mjs";
|
|
11
13
|
import { parseStorageUri } from "./parseStorageUri.mjs";
|
|
12
14
|
import { supportedIosPlatforms } from "./types/index.mjs";
|
|
13
|
-
export { bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, parseStorageUri, semverSatisfies, sortBundles, supportedIosPlatforms };
|
|
15
|
+
export { bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createDatabasePluginGetUpdateInfo, createStorageKeyBuilder, createStoragePlugin, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, paginateBundles, parseStorageUri, semverSatisfies, sortBundles, supportedIosPlatforms };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const require_calculatePagination = require("./calculatePagination.cjs");
|
|
2
|
+
const require_queryBundles = require("./queryBundles.cjs");
|
|
3
|
+
//#region src/paginateBundles.ts
|
|
4
|
+
function paginateBundles({ bundles, limit, offset, cursor, orderBy }) {
|
|
5
|
+
const sortedBundles = require_queryBundles.sortBundles(bundles, orderBy);
|
|
6
|
+
const direction = orderBy?.direction ?? "desc";
|
|
7
|
+
const total = sortedBundles.length;
|
|
8
|
+
if (offset !== void 0) {
|
|
9
|
+
const normalizedOffset = Math.max(0, offset);
|
|
10
|
+
const data = limit > 0 ? sortedBundles.slice(normalizedOffset, normalizedOffset + limit) : sortedBundles.slice(normalizedOffset);
|
|
11
|
+
const pagination = require_calculatePagination.calculatePagination(total, {
|
|
12
|
+
limit,
|
|
13
|
+
offset: normalizedOffset
|
|
14
|
+
});
|
|
15
|
+
const nextCursor = data.length > 0 && normalizedOffset + data.length < total ? data.at(-1)?.id : void 0;
|
|
16
|
+
const previousCursor = data.length > 0 && normalizedOffset > 0 ? data[0]?.id : void 0;
|
|
17
|
+
return {
|
|
18
|
+
data,
|
|
19
|
+
pagination: {
|
|
20
|
+
...pagination,
|
|
21
|
+
...nextCursor ? { nextCursor } : {},
|
|
22
|
+
...previousCursor ? { previousCursor } : {}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
let data;
|
|
27
|
+
if (cursor?.after) {
|
|
28
|
+
const candidates = sortedBundles.filter((bundle) => direction === "desc" ? bundle.id.localeCompare(cursor.after) < 0 : bundle.id.localeCompare(cursor.after) > 0);
|
|
29
|
+
data = limit > 0 ? candidates.slice(0, limit) : candidates;
|
|
30
|
+
} else if (cursor?.before) {
|
|
31
|
+
const candidates = sortedBundles.filter((bundle) => direction === "desc" ? bundle.id.localeCompare(cursor.before) > 0 : bundle.id.localeCompare(cursor.before) < 0);
|
|
32
|
+
data = limit > 0 ? candidates.slice(Math.max(0, candidates.length - limit)) : candidates;
|
|
33
|
+
} else data = limit > 0 ? sortedBundles.slice(0, limit) : sortedBundles;
|
|
34
|
+
const startIndex = data.length > 0 ? sortedBundles.findIndex((bundle) => bundle.id === data[0].id) : cursor?.after ? total : 0;
|
|
35
|
+
const pagination = require_calculatePagination.calculatePagination(total, {
|
|
36
|
+
limit,
|
|
37
|
+
offset: startIndex
|
|
38
|
+
});
|
|
39
|
+
const nextCursor = data.length > 0 && startIndex + data.length < total ? data.at(-1)?.id : void 0;
|
|
40
|
+
const previousCursor = data.length > 0 && startIndex > 0 ? data[0]?.id : void 0;
|
|
41
|
+
return {
|
|
42
|
+
data,
|
|
43
|
+
pagination: {
|
|
44
|
+
...pagination,
|
|
45
|
+
...nextCursor ? { nextCursor } : {},
|
|
46
|
+
...previousCursor ? { previousCursor } : {},
|
|
47
|
+
...data.length === 0 && cursor?.after ? { previousCursor: cursor.after } : {},
|
|
48
|
+
...data.length === 0 && cursor?.before ? { nextCursor: cursor.before } : {}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.paginateBundles = paginateBundles;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Bundle, DatabaseBundleCursor, DatabaseBundleQueryOrder, Paginated } from "./types/index.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/paginateBundles.d.ts
|
|
4
|
+
declare function paginateBundles({
|
|
5
|
+
bundles,
|
|
6
|
+
limit,
|
|
7
|
+
offset,
|
|
8
|
+
cursor,
|
|
9
|
+
orderBy
|
|
10
|
+
}: {
|
|
11
|
+
bundles: Bundle[];
|
|
12
|
+
limit: number;
|
|
13
|
+
offset?: number;
|
|
14
|
+
cursor?: DatabaseBundleCursor;
|
|
15
|
+
orderBy?: DatabaseBundleQueryOrder;
|
|
16
|
+
}): Paginated<Bundle[]>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { paginateBundles };
|