@hot-updater/standalone 0.27.1 → 0.29.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.
- package/dist/index.cjs +79 -56
- package/dist/index.d.cts +11 -6
- package/dist/{index.d.ts → index.d.mts} +11 -6
- package/dist/{index.js → index.mjs} +75 -52
- package/package.json +9 -6
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
11
10
|
var __copyProps = (to, from, except, desc) => {
|
|
12
11
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
12
|
key = keys[i];
|
|
@@ -22,18 +21,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
21
|
value: mod,
|
|
23
22
|
enumerable: true
|
|
24
23
|
}) : target, mod));
|
|
25
|
-
|
|
26
24
|
//#endregion
|
|
27
|
-
let
|
|
28
|
-
__hot_updater_plugin_core = __toESM(__hot_updater_plugin_core);
|
|
25
|
+
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
29
26
|
let fs_promises = require("fs/promises");
|
|
30
27
|
fs_promises = __toESM(fs_promises);
|
|
31
28
|
let path = require("path");
|
|
32
29
|
path = __toESM(path);
|
|
33
|
-
|
|
34
30
|
//#region src/standaloneRepository.ts
|
|
35
31
|
const defaultRoutes$1 = {
|
|
36
|
-
|
|
32
|
+
create: () => ({ path: "/api/bundles" }),
|
|
33
|
+
update: (bundleId) => ({ path: `/api/bundles/${bundleId}` }),
|
|
37
34
|
list: () => ({
|
|
38
35
|
path: "/api/bundles",
|
|
39
36
|
headers: { "Cache-Control": "no-cache" }
|
|
@@ -51,16 +48,44 @@ const createRoute$1 = (defaultRoute, customRoute) => ({
|
|
|
51
48
|
...customRoute?.headers
|
|
52
49
|
}
|
|
53
50
|
});
|
|
54
|
-
const
|
|
51
|
+
const bundleMatchesQueryWhere = (bundle, where) => {
|
|
52
|
+
if (!where) return true;
|
|
53
|
+
if (where.channel !== void 0 && bundle.channel !== where.channel) return false;
|
|
54
|
+
if (where.platform !== void 0 && bundle.platform !== where.platform) return false;
|
|
55
|
+
if (where.enabled !== void 0 && bundle.enabled !== where.enabled) return false;
|
|
56
|
+
if (where.id?.eq !== void 0 && bundle.id !== where.id.eq) return false;
|
|
57
|
+
if (where.id?.gt !== void 0 && bundle.id.localeCompare(where.id.gt) <= 0) return false;
|
|
58
|
+
if (where.id?.gte !== void 0 && bundle.id.localeCompare(where.id.gte) < 0) return false;
|
|
59
|
+
if (where.id?.lt !== void 0 && bundle.id.localeCompare(where.id.lt) >= 0) return false;
|
|
60
|
+
if (where.id?.lte !== void 0 && bundle.id.localeCompare(where.id.lte) > 0) return false;
|
|
61
|
+
if (where.id?.in && !where.id.in.includes(bundle.id)) return false;
|
|
62
|
+
if (where.targetAppVersionNotNull && bundle.targetAppVersion === null) return false;
|
|
63
|
+
if (where.targetAppVersion !== void 0 && bundle.targetAppVersion !== where.targetAppVersion) return false;
|
|
64
|
+
if (where.targetAppVersionIn && !where.targetAppVersionIn.includes(bundle.targetAppVersion ?? "")) return false;
|
|
65
|
+
if (where.fingerprintHash !== void 0 && bundle.fingerprintHash !== where.fingerprintHash) return false;
|
|
66
|
+
return true;
|
|
67
|
+
};
|
|
68
|
+
const sortBundles = (bundles, orderBy) => {
|
|
69
|
+
if (!orderBy) return bundles;
|
|
70
|
+
const direction = orderBy?.direction ?? "desc";
|
|
71
|
+
return bundles.slice().sort((a, b) => {
|
|
72
|
+
const result = a.id.localeCompare(b.id);
|
|
73
|
+
return direction === "asc" ? result : -result;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const standaloneRepository = (0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
55
77
|
name: "standalone-repository",
|
|
56
78
|
factory: (config) => {
|
|
79
|
+
const legacyUpsertRoute = config.routes?.upsert;
|
|
57
80
|
const routes = {
|
|
58
|
-
|
|
81
|
+
create: () => createRoute$1(defaultRoutes$1.create(), config.routes?.create?.() ?? legacyUpsertRoute?.()),
|
|
82
|
+
update: (bundleId) => createRoute$1(defaultRoutes$1.update(bundleId), config.routes?.update?.(bundleId)),
|
|
83
|
+
legacyUpsert: () => legacyUpsertRoute ? createRoute$1(defaultRoutes$1.create(), legacyUpsertRoute()) : null,
|
|
59
84
|
list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
|
|
60
85
|
retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
|
|
61
86
|
delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
|
|
62
87
|
};
|
|
63
|
-
const buildUrl = (path
|
|
88
|
+
const buildUrl = (path) => `${config.baseUrl}${path}`;
|
|
64
89
|
const getHeaders = (routeHeaders) => ({
|
|
65
90
|
"Content-Type": "application/json",
|
|
66
91
|
...config.commonHeaders,
|
|
@@ -69,8 +94,8 @@ const standaloneRepository = (0, __hot_updater_plugin_core.createDatabasePlugin)
|
|
|
69
94
|
return {
|
|
70
95
|
async getBundleById(bundleId) {
|
|
71
96
|
try {
|
|
72
|
-
const { path
|
|
73
|
-
const response = await fetch(buildUrl(path
|
|
97
|
+
const { path, headers: routeHeaders } = routes.retrieve(bundleId);
|
|
98
|
+
const response = await fetch(buildUrl(path), {
|
|
74
99
|
method: "GET",
|
|
75
100
|
headers: getHeaders(routeHeaders)
|
|
76
101
|
});
|
|
@@ -81,28 +106,26 @@ const standaloneRepository = (0, __hot_updater_plugin_core.createDatabasePlugin)
|
|
|
81
106
|
}
|
|
82
107
|
},
|
|
83
108
|
async getBundles(options) {
|
|
84
|
-
const { where, limit, offset = 0 } = options ?? {};
|
|
85
|
-
const { path
|
|
86
|
-
const response = await fetch(buildUrl(path
|
|
109
|
+
const { where, limit, offset = 0, orderBy } = options ?? {};
|
|
110
|
+
const { path, headers: routeHeaders } = routes.list();
|
|
111
|
+
const response = await fetch(buildUrl(path), {
|
|
87
112
|
method: "GET",
|
|
88
113
|
headers: getHeaders(routeHeaders)
|
|
89
114
|
});
|
|
90
115
|
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
91
|
-
|
|
92
|
-
if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
|
|
93
|
-
if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
|
|
116
|
+
const filteredBundles = sortBundles((await response.json()).filter((bundle) => bundleMatchesQueryWhere(bundle, where)), orderBy);
|
|
94
117
|
const total = filteredBundles.length;
|
|
95
118
|
return {
|
|
96
119
|
data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
|
|
97
|
-
pagination: (0,
|
|
120
|
+
pagination: (0, _hot_updater_plugin_core.calculatePagination)(total, {
|
|
98
121
|
limit,
|
|
99
122
|
offset
|
|
100
123
|
})
|
|
101
124
|
};
|
|
102
125
|
},
|
|
103
126
|
async getChannels() {
|
|
104
|
-
const { path
|
|
105
|
-
const response = await fetch(buildUrl(path
|
|
127
|
+
const { path, headers: routeHeaders } = routes.list();
|
|
128
|
+
const response = await fetch(buildUrl(path), {
|
|
106
129
|
method: "GET",
|
|
107
130
|
headers: getHeaders(routeHeaders)
|
|
108
131
|
});
|
|
@@ -113,8 +136,8 @@ const standaloneRepository = (0, __hot_updater_plugin_core.createDatabasePlugin)
|
|
|
113
136
|
async commitBundle({ changedSets }) {
|
|
114
137
|
if (changedSets.length === 0) return;
|
|
115
138
|
for (const op of changedSets) if (op.operation === "delete") {
|
|
116
|
-
const { path
|
|
117
|
-
const response = await fetch(buildUrl(path
|
|
139
|
+
const { path, headers: routeHeaders } = routes.delete(op.data.id);
|
|
140
|
+
const response = await fetch(buildUrl(path), {
|
|
118
141
|
method: "DELETE",
|
|
119
142
|
headers: getHeaders(routeHeaders)
|
|
120
143
|
});
|
|
@@ -127,29 +150,38 @@ const standaloneRepository = (0, __hot_updater_plugin_core.createDatabasePlugin)
|
|
|
127
150
|
} catch (_jsonError) {
|
|
128
151
|
if (!response.ok) throw new Error("Failed to parse response");
|
|
129
152
|
}
|
|
130
|
-
} else if (op.operation === "insert"
|
|
131
|
-
const { path
|
|
132
|
-
const response = await fetch(buildUrl(path
|
|
153
|
+
} else if (op.operation === "insert") {
|
|
154
|
+
const { path, headers: routeHeaders } = routes.create();
|
|
155
|
+
const response = await fetch(buildUrl(path), {
|
|
133
156
|
method: "POST",
|
|
134
157
|
headers: getHeaders(routeHeaders),
|
|
135
158
|
body: JSON.stringify([op.data])
|
|
136
159
|
});
|
|
137
160
|
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
138
161
|
if (!(await response.json()).success) throw new Error("Failed to commit bundle");
|
|
162
|
+
} else if (op.operation === "update") {
|
|
163
|
+
const legacyRoute = !config.routes?.update && routes.legacyUpsert();
|
|
164
|
+
const { path, headers: routeHeaders } = legacyRoute ? legacyRoute : routes.update(op.data.id);
|
|
165
|
+
const response = await fetch(buildUrl(path), {
|
|
166
|
+
method: legacyRoute ? "POST" : "PATCH",
|
|
167
|
+
headers: getHeaders(routeHeaders),
|
|
168
|
+
body: JSON.stringify(legacyRoute ? [op.data] : op.data)
|
|
169
|
+
});
|
|
170
|
+
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
171
|
+
if (!(await response.json()).success) throw new Error("Failed to commit bundle");
|
|
139
172
|
}
|
|
140
173
|
}
|
|
141
174
|
};
|
|
142
175
|
}
|
|
143
176
|
});
|
|
144
|
-
|
|
145
177
|
//#endregion
|
|
146
178
|
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js
|
|
147
|
-
var require_Mime = /* @__PURE__ */
|
|
179
|
+
var require_Mime = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
148
180
|
/**
|
|
149
181
|
* @param typeMap [Object] Map of MIME type -> Array[extensions]
|
|
150
182
|
* @param ...
|
|
151
183
|
*/
|
|
152
|
-
function Mime
|
|
184
|
+
function Mime() {
|
|
153
185
|
this._types = Object.create(null);
|
|
154
186
|
this._extensions = Object.create(null);
|
|
155
187
|
for (let i = 0; i < arguments.length; i++) this.define(arguments[i]);
|
|
@@ -176,7 +208,7 @@ var require_Mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
|
|
|
176
208
|
* @param map (Object) type definitions
|
|
177
209
|
* @param force (Boolean) if true, force overriding of existing definitions
|
|
178
210
|
*/
|
|
179
|
-
Mime
|
|
211
|
+
Mime.prototype.define = function(typeMap, force) {
|
|
180
212
|
for (let type in typeMap) {
|
|
181
213
|
let extensions = typeMap[type].map(function(t) {
|
|
182
214
|
return t.toLowerCase();
|
|
@@ -197,26 +229,25 @@ var require_Mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
|
|
|
197
229
|
/**
|
|
198
230
|
* Lookup a mime type based on extension
|
|
199
231
|
*/
|
|
200
|
-
Mime
|
|
201
|
-
path
|
|
202
|
-
let last = path
|
|
232
|
+
Mime.prototype.getType = function(path) {
|
|
233
|
+
path = String(path);
|
|
234
|
+
let last = path.replace(/^.*[/\\]/, "").toLowerCase();
|
|
203
235
|
let ext = last.replace(/^.*\./, "").toLowerCase();
|
|
204
|
-
let hasPath = last.length < path
|
|
236
|
+
let hasPath = last.length < path.length;
|
|
205
237
|
return (ext.length < last.length - 1 || !hasPath) && this._types[ext] || null;
|
|
206
238
|
};
|
|
207
239
|
/**
|
|
208
240
|
* Return file extension associated with a mime type
|
|
209
241
|
*/
|
|
210
|
-
Mime
|
|
242
|
+
Mime.prototype.getExtension = function(type) {
|
|
211
243
|
type = /^\s*([^;\s]*)/.test(type) && RegExp.$1;
|
|
212
244
|
return type && this._extensions[type.toLowerCase()] || null;
|
|
213
245
|
};
|
|
214
|
-
module.exports = Mime
|
|
215
|
-
})
|
|
216
|
-
|
|
246
|
+
module.exports = Mime;
|
|
247
|
+
}));
|
|
217
248
|
//#endregion
|
|
218
249
|
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/types/standard.js
|
|
219
|
-
var require_standard = /* @__PURE__ */
|
|
250
|
+
var require_standard = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
220
251
|
module.exports = {
|
|
221
252
|
"application/andrew-inset": ["ez"],
|
|
222
253
|
"application/applixware": ["aw"],
|
|
@@ -629,11 +660,10 @@ var require_standard = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mi
|
|
|
629
660
|
"video/quicktime": ["qt", "mov"],
|
|
630
661
|
"video/webm": ["webm"]
|
|
631
662
|
};
|
|
632
|
-
})
|
|
633
|
-
|
|
663
|
+
}));
|
|
634
664
|
//#endregion
|
|
635
665
|
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/types/other.js
|
|
636
|
-
var require_other = /* @__PURE__ */
|
|
666
|
+
var require_other = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
637
667
|
module.exports = {
|
|
638
668
|
"application/prs.cww": ["cww"],
|
|
639
669
|
"application/vnd.1000minds.decision-model+xml": ["1km"],
|
|
@@ -1438,18 +1468,12 @@ var require_other = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@
|
|
|
1438
1468
|
"video/x-smv": ["smv"],
|
|
1439
1469
|
"x-conference/x-cooltalk": ["ice"]
|
|
1440
1470
|
};
|
|
1441
|
-
})
|
|
1442
|
-
|
|
1443
|
-
//#endregion
|
|
1444
|
-
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/index.js
|
|
1445
|
-
var require_mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/index.js": ((exports, module) => {
|
|
1446
|
-
let Mime = require_Mime();
|
|
1447
|
-
module.exports = new Mime(require_standard(), require_other());
|
|
1448
|
-
}) });
|
|
1449
|
-
|
|
1471
|
+
}));
|
|
1450
1472
|
//#endregion
|
|
1451
1473
|
//#region src/standaloneStorage.ts
|
|
1452
|
-
var import_mime = /* @__PURE__ */ __toESM(
|
|
1474
|
+
var import_mime = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1475
|
+
module.exports = new (require_Mime())(require_standard(), require_other());
|
|
1476
|
+
})))(), 1);
|
|
1453
1477
|
const defaultRoutes = {
|
|
1454
1478
|
upload: (_key, _filePath) => ({ path: "/upload" }),
|
|
1455
1479
|
delete: (_storageUri) => ({ path: "/delete" }),
|
|
@@ -1531,7 +1555,6 @@ const standaloneStorage = (config, hooks) => () => {
|
|
|
1531
1555
|
}
|
|
1532
1556
|
};
|
|
1533
1557
|
};
|
|
1534
|
-
|
|
1535
1558
|
//#endregion
|
|
1536
1559
|
exports.standaloneRepository = standaloneRepository;
|
|
1537
|
-
exports.standaloneStorage = standaloneStorage;
|
|
1560
|
+
exports.standaloneStorage = standaloneStorage;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
1
|
+
import * as _$_hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
2
2
|
import { StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
|
|
3
3
|
|
|
4
4
|
//#region src/standaloneRepository.d.ts
|
|
@@ -7,17 +7,22 @@ interface RouteConfig {
|
|
|
7
7
|
headers?: Record<string, string>;
|
|
8
8
|
}
|
|
9
9
|
interface Routes {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `create` and `update`. Kept for backward compatibility.
|
|
12
|
+
*/
|
|
13
|
+
upsert?: () => RouteConfig;
|
|
14
|
+
create?: () => RouteConfig;
|
|
15
|
+
update?: (bundleId: string) => RouteConfig;
|
|
16
|
+
list?: () => RouteConfig;
|
|
17
|
+
retrieve?: (bundleId: string) => RouteConfig;
|
|
18
|
+
delete?: (bundleId: string) => RouteConfig;
|
|
14
19
|
}
|
|
15
20
|
interface StandaloneRepositoryConfig {
|
|
16
21
|
baseUrl: string;
|
|
17
22
|
commonHeaders?: Record<string, string>;
|
|
18
23
|
routes?: Routes;
|
|
19
24
|
}
|
|
20
|
-
declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => (
|
|
25
|
+
declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: _$_hot_updater_plugin_core0.DatabasePluginHooks) => () => _$_hot_updater_plugin_core0.DatabasePlugin<unknown>;
|
|
21
26
|
//#endregion
|
|
22
27
|
//#region src/standaloneStorage.d.ts
|
|
23
28
|
interface StorageRoutes {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
1
|
+
import * as _$_hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
2
2
|
import { StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
|
|
3
3
|
|
|
4
4
|
//#region src/standaloneRepository.d.ts
|
|
@@ -7,17 +7,22 @@ interface RouteConfig {
|
|
|
7
7
|
headers?: Record<string, string>;
|
|
8
8
|
}
|
|
9
9
|
interface Routes {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `create` and `update`. Kept for backward compatibility.
|
|
12
|
+
*/
|
|
13
|
+
upsert?: () => RouteConfig;
|
|
14
|
+
create?: () => RouteConfig;
|
|
15
|
+
update?: (bundleId: string) => RouteConfig;
|
|
16
|
+
list?: () => RouteConfig;
|
|
17
|
+
retrieve?: (bundleId: string) => RouteConfig;
|
|
18
|
+
delete?: (bundleId: string) => RouteConfig;
|
|
14
19
|
}
|
|
15
20
|
interface StandaloneRepositoryConfig {
|
|
16
21
|
baseUrl: string;
|
|
17
22
|
commonHeaders?: Record<string, string>;
|
|
18
23
|
routes?: Routes;
|
|
19
24
|
}
|
|
20
|
-
declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => (
|
|
25
|
+
declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: _$_hot_updater_plugin_core0.DatabasePluginHooks) => () => _$_hot_updater_plugin_core0.DatabasePlugin<unknown>;
|
|
21
26
|
//#endregion
|
|
22
27
|
//#region src/standaloneStorage.d.ts
|
|
23
28
|
interface StorageRoutes {
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { calculatePagination, createDatabasePlugin } from "@hot-updater/plugin-core";
|
|
2
2
|
import fs from "fs/promises";
|
|
3
3
|
import path from "path";
|
|
4
|
-
|
|
5
|
-
//#region rolldown:runtime
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
6
5
|
var __create = Object.create;
|
|
7
6
|
var __defProp = Object.defineProperty;
|
|
8
7
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
8
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
9
|
var __getProtoOf = Object.getPrototypeOf;
|
|
11
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var
|
|
13
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
-
};
|
|
11
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
15
12
|
var __copyProps = (to, from, except, desc) => {
|
|
16
13
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
17
14
|
key = keys[i];
|
|
@@ -26,11 +23,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
23
|
value: mod,
|
|
27
24
|
enumerable: true
|
|
28
25
|
}) : target, mod));
|
|
29
|
-
|
|
30
26
|
//#endregion
|
|
31
27
|
//#region src/standaloneRepository.ts
|
|
32
28
|
const defaultRoutes$1 = {
|
|
33
|
-
|
|
29
|
+
create: () => ({ path: "/api/bundles" }),
|
|
30
|
+
update: (bundleId) => ({ path: `/api/bundles/${bundleId}` }),
|
|
34
31
|
list: () => ({
|
|
35
32
|
path: "/api/bundles",
|
|
36
33
|
headers: { "Cache-Control": "no-cache" }
|
|
@@ -48,16 +45,44 @@ const createRoute$1 = (defaultRoute, customRoute) => ({
|
|
|
48
45
|
...customRoute?.headers
|
|
49
46
|
}
|
|
50
47
|
});
|
|
48
|
+
const bundleMatchesQueryWhere = (bundle, where) => {
|
|
49
|
+
if (!where) return true;
|
|
50
|
+
if (where.channel !== void 0 && bundle.channel !== where.channel) return false;
|
|
51
|
+
if (where.platform !== void 0 && bundle.platform !== where.platform) return false;
|
|
52
|
+
if (where.enabled !== void 0 && bundle.enabled !== where.enabled) return false;
|
|
53
|
+
if (where.id?.eq !== void 0 && bundle.id !== where.id.eq) return false;
|
|
54
|
+
if (where.id?.gt !== void 0 && bundle.id.localeCompare(where.id.gt) <= 0) return false;
|
|
55
|
+
if (where.id?.gte !== void 0 && bundle.id.localeCompare(where.id.gte) < 0) return false;
|
|
56
|
+
if (where.id?.lt !== void 0 && bundle.id.localeCompare(where.id.lt) >= 0) return false;
|
|
57
|
+
if (where.id?.lte !== void 0 && bundle.id.localeCompare(where.id.lte) > 0) return false;
|
|
58
|
+
if (where.id?.in && !where.id.in.includes(bundle.id)) return false;
|
|
59
|
+
if (where.targetAppVersionNotNull && bundle.targetAppVersion === null) return false;
|
|
60
|
+
if (where.targetAppVersion !== void 0 && bundle.targetAppVersion !== where.targetAppVersion) return false;
|
|
61
|
+
if (where.targetAppVersionIn && !where.targetAppVersionIn.includes(bundle.targetAppVersion ?? "")) return false;
|
|
62
|
+
if (where.fingerprintHash !== void 0 && bundle.fingerprintHash !== where.fingerprintHash) return false;
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
const sortBundles = (bundles, orderBy) => {
|
|
66
|
+
if (!orderBy) return bundles;
|
|
67
|
+
const direction = orderBy?.direction ?? "desc";
|
|
68
|
+
return bundles.slice().sort((a, b) => {
|
|
69
|
+
const result = a.id.localeCompare(b.id);
|
|
70
|
+
return direction === "asc" ? result : -result;
|
|
71
|
+
});
|
|
72
|
+
};
|
|
51
73
|
const standaloneRepository = createDatabasePlugin({
|
|
52
74
|
name: "standalone-repository",
|
|
53
75
|
factory: (config) => {
|
|
76
|
+
const legacyUpsertRoute = config.routes?.upsert;
|
|
54
77
|
const routes = {
|
|
55
|
-
|
|
78
|
+
create: () => createRoute$1(defaultRoutes$1.create(), config.routes?.create?.() ?? legacyUpsertRoute?.()),
|
|
79
|
+
update: (bundleId) => createRoute$1(defaultRoutes$1.update(bundleId), config.routes?.update?.(bundleId)),
|
|
80
|
+
legacyUpsert: () => legacyUpsertRoute ? createRoute$1(defaultRoutes$1.create(), legacyUpsertRoute()) : null,
|
|
56
81
|
list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
|
|
57
82
|
retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
|
|
58
83
|
delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
|
|
59
84
|
};
|
|
60
|
-
const buildUrl = (path
|
|
85
|
+
const buildUrl = (path) => `${config.baseUrl}${path}`;
|
|
61
86
|
const getHeaders = (routeHeaders) => ({
|
|
62
87
|
"Content-Type": "application/json",
|
|
63
88
|
...config.commonHeaders,
|
|
@@ -66,8 +91,8 @@ const standaloneRepository = createDatabasePlugin({
|
|
|
66
91
|
return {
|
|
67
92
|
async getBundleById(bundleId) {
|
|
68
93
|
try {
|
|
69
|
-
const { path
|
|
70
|
-
const response = await fetch(buildUrl(path
|
|
94
|
+
const { path, headers: routeHeaders } = routes.retrieve(bundleId);
|
|
95
|
+
const response = await fetch(buildUrl(path), {
|
|
71
96
|
method: "GET",
|
|
72
97
|
headers: getHeaders(routeHeaders)
|
|
73
98
|
});
|
|
@@ -78,16 +103,14 @@ const standaloneRepository = createDatabasePlugin({
|
|
|
78
103
|
}
|
|
79
104
|
},
|
|
80
105
|
async getBundles(options) {
|
|
81
|
-
const { where, limit, offset = 0 } = options ?? {};
|
|
82
|
-
const { path
|
|
83
|
-
const response = await fetch(buildUrl(path
|
|
106
|
+
const { where, limit, offset = 0, orderBy } = options ?? {};
|
|
107
|
+
const { path, headers: routeHeaders } = routes.list();
|
|
108
|
+
const response = await fetch(buildUrl(path), {
|
|
84
109
|
method: "GET",
|
|
85
110
|
headers: getHeaders(routeHeaders)
|
|
86
111
|
});
|
|
87
112
|
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
88
|
-
|
|
89
|
-
if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
|
|
90
|
-
if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
|
|
113
|
+
const filteredBundles = sortBundles((await response.json()).filter((bundle) => bundleMatchesQueryWhere(bundle, where)), orderBy);
|
|
91
114
|
const total = filteredBundles.length;
|
|
92
115
|
return {
|
|
93
116
|
data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
|
|
@@ -98,8 +121,8 @@ const standaloneRepository = createDatabasePlugin({
|
|
|
98
121
|
};
|
|
99
122
|
},
|
|
100
123
|
async getChannels() {
|
|
101
|
-
const { path
|
|
102
|
-
const response = await fetch(buildUrl(path
|
|
124
|
+
const { path, headers: routeHeaders } = routes.list();
|
|
125
|
+
const response = await fetch(buildUrl(path), {
|
|
103
126
|
method: "GET",
|
|
104
127
|
headers: getHeaders(routeHeaders)
|
|
105
128
|
});
|
|
@@ -110,8 +133,8 @@ const standaloneRepository = createDatabasePlugin({
|
|
|
110
133
|
async commitBundle({ changedSets }) {
|
|
111
134
|
if (changedSets.length === 0) return;
|
|
112
135
|
for (const op of changedSets) if (op.operation === "delete") {
|
|
113
|
-
const { path
|
|
114
|
-
const response = await fetch(buildUrl(path
|
|
136
|
+
const { path, headers: routeHeaders } = routes.delete(op.data.id);
|
|
137
|
+
const response = await fetch(buildUrl(path), {
|
|
115
138
|
method: "DELETE",
|
|
116
139
|
headers: getHeaders(routeHeaders)
|
|
117
140
|
});
|
|
@@ -124,29 +147,38 @@ const standaloneRepository = createDatabasePlugin({
|
|
|
124
147
|
} catch (_jsonError) {
|
|
125
148
|
if (!response.ok) throw new Error("Failed to parse response");
|
|
126
149
|
}
|
|
127
|
-
} else if (op.operation === "insert"
|
|
128
|
-
const { path
|
|
129
|
-
const response = await fetch(buildUrl(path
|
|
150
|
+
} else if (op.operation === "insert") {
|
|
151
|
+
const { path, headers: routeHeaders } = routes.create();
|
|
152
|
+
const response = await fetch(buildUrl(path), {
|
|
130
153
|
method: "POST",
|
|
131
154
|
headers: getHeaders(routeHeaders),
|
|
132
155
|
body: JSON.stringify([op.data])
|
|
133
156
|
});
|
|
134
157
|
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
135
158
|
if (!(await response.json()).success) throw new Error("Failed to commit bundle");
|
|
159
|
+
} else if (op.operation === "update") {
|
|
160
|
+
const legacyRoute = !config.routes?.update && routes.legacyUpsert();
|
|
161
|
+
const { path, headers: routeHeaders } = legacyRoute ? legacyRoute : routes.update(op.data.id);
|
|
162
|
+
const response = await fetch(buildUrl(path), {
|
|
163
|
+
method: legacyRoute ? "POST" : "PATCH",
|
|
164
|
+
headers: getHeaders(routeHeaders),
|
|
165
|
+
body: JSON.stringify(legacyRoute ? [op.data] : op.data)
|
|
166
|
+
});
|
|
167
|
+
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
168
|
+
if (!(await response.json()).success) throw new Error("Failed to commit bundle");
|
|
136
169
|
}
|
|
137
170
|
}
|
|
138
171
|
};
|
|
139
172
|
}
|
|
140
173
|
});
|
|
141
|
-
|
|
142
174
|
//#endregion
|
|
143
175
|
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js
|
|
144
|
-
var require_Mime = /* @__PURE__ */
|
|
176
|
+
var require_Mime = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
145
177
|
/**
|
|
146
178
|
* @param typeMap [Object] Map of MIME type -> Array[extensions]
|
|
147
179
|
* @param ...
|
|
148
180
|
*/
|
|
149
|
-
function Mime
|
|
181
|
+
function Mime() {
|
|
150
182
|
this._types = Object.create(null);
|
|
151
183
|
this._extensions = Object.create(null);
|
|
152
184
|
for (let i = 0; i < arguments.length; i++) this.define(arguments[i]);
|
|
@@ -173,7 +205,7 @@ var require_Mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
|
|
|
173
205
|
* @param map (Object) type definitions
|
|
174
206
|
* @param force (Boolean) if true, force overriding of existing definitions
|
|
175
207
|
*/
|
|
176
|
-
Mime
|
|
208
|
+
Mime.prototype.define = function(typeMap, force) {
|
|
177
209
|
for (let type in typeMap) {
|
|
178
210
|
let extensions = typeMap[type].map(function(t) {
|
|
179
211
|
return t.toLowerCase();
|
|
@@ -194,26 +226,25 @@ var require_Mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
|
|
|
194
226
|
/**
|
|
195
227
|
* Lookup a mime type based on extension
|
|
196
228
|
*/
|
|
197
|
-
Mime
|
|
198
|
-
path
|
|
199
|
-
let last = path
|
|
229
|
+
Mime.prototype.getType = function(path) {
|
|
230
|
+
path = String(path);
|
|
231
|
+
let last = path.replace(/^.*[/\\]/, "").toLowerCase();
|
|
200
232
|
let ext = last.replace(/^.*\./, "").toLowerCase();
|
|
201
|
-
let hasPath = last.length < path
|
|
233
|
+
let hasPath = last.length < path.length;
|
|
202
234
|
return (ext.length < last.length - 1 || !hasPath) && this._types[ext] || null;
|
|
203
235
|
};
|
|
204
236
|
/**
|
|
205
237
|
* Return file extension associated with a mime type
|
|
206
238
|
*/
|
|
207
|
-
Mime
|
|
239
|
+
Mime.prototype.getExtension = function(type) {
|
|
208
240
|
type = /^\s*([^;\s]*)/.test(type) && RegExp.$1;
|
|
209
241
|
return type && this._extensions[type.toLowerCase()] || null;
|
|
210
242
|
};
|
|
211
|
-
module.exports = Mime
|
|
212
|
-
})
|
|
213
|
-
|
|
243
|
+
module.exports = Mime;
|
|
244
|
+
}));
|
|
214
245
|
//#endregion
|
|
215
246
|
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/types/standard.js
|
|
216
|
-
var require_standard = /* @__PURE__ */
|
|
247
|
+
var require_standard = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
217
248
|
module.exports = {
|
|
218
249
|
"application/andrew-inset": ["ez"],
|
|
219
250
|
"application/applixware": ["aw"],
|
|
@@ -626,11 +657,10 @@ var require_standard = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mi
|
|
|
626
657
|
"video/quicktime": ["qt", "mov"],
|
|
627
658
|
"video/webm": ["webm"]
|
|
628
659
|
};
|
|
629
|
-
})
|
|
630
|
-
|
|
660
|
+
}));
|
|
631
661
|
//#endregion
|
|
632
662
|
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/types/other.js
|
|
633
|
-
var require_other = /* @__PURE__ */
|
|
663
|
+
var require_other = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
634
664
|
module.exports = {
|
|
635
665
|
"application/prs.cww": ["cww"],
|
|
636
666
|
"application/vnd.1000minds.decision-model+xml": ["1km"],
|
|
@@ -1435,18 +1465,12 @@ var require_other = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@
|
|
|
1435
1465
|
"video/x-smv": ["smv"],
|
|
1436
1466
|
"x-conference/x-cooltalk": ["ice"]
|
|
1437
1467
|
};
|
|
1438
|
-
})
|
|
1439
|
-
|
|
1440
|
-
//#endregion
|
|
1441
|
-
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/index.js
|
|
1442
|
-
var require_mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/index.js": ((exports, module) => {
|
|
1443
|
-
let Mime = require_Mime();
|
|
1444
|
-
module.exports = new Mime(require_standard(), require_other());
|
|
1445
|
-
}) });
|
|
1446
|
-
|
|
1468
|
+
}));
|
|
1447
1469
|
//#endregion
|
|
1448
1470
|
//#region src/standaloneStorage.ts
|
|
1449
|
-
var import_mime = /* @__PURE__ */ __toESM(
|
|
1471
|
+
var import_mime = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1472
|
+
module.exports = new (require_Mime())(require_standard(), require_other());
|
|
1473
|
+
})))(), 1);
|
|
1450
1474
|
const defaultRoutes = {
|
|
1451
1475
|
upload: (_key, _filePath) => ({ path: "/upload" }),
|
|
1452
1476
|
delete: (_storageUri) => ({ path: "/delete" }),
|
|
@@ -1528,6 +1552,5 @@ const standaloneStorage = (config, hooks) => () => {
|
|
|
1528
1552
|
}
|
|
1529
1553
|
};
|
|
1530
1554
|
};
|
|
1531
|
-
|
|
1532
1555
|
//#endregion
|
|
1533
|
-
export { standaloneRepository, standaloneStorage };
|
|
1556
|
+
export { standaloneRepository, standaloneStorage };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/standalone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
8
|
-
"module": "./dist/index.
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.cts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"import": "./dist/index.
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
14
|
},
|
|
15
15
|
"./package.json": "./package.json"
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@hot-updater/core": "0.
|
|
43
|
-
"@hot-updater/plugin-core": "0.
|
|
42
|
+
"@hot-updater/core": "0.29.0",
|
|
43
|
+
"@hot-updater/plugin-core": "0.29.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"mime": "2.6.0",
|
|
@@ -49,7 +49,10 @@
|
|
|
49
49
|
"@types/semver": "^7.5.8",
|
|
50
50
|
"msw": "^2.7.0",
|
|
51
51
|
"semver": "^7.6.3",
|
|
52
|
-
"vitest": "
|
|
52
|
+
"vitest": "4.1.0"
|
|
53
|
+
},
|
|
54
|
+
"inlinedDependencies": {
|
|
55
|
+
"mime": "2.6.0"
|
|
53
56
|
},
|
|
54
57
|
"scripts": {
|
|
55
58
|
"build": "tsdown",
|