@hot-updater/firebase 1.2.0-rc.43 → 1.2.0-rc.45
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/firebase/functions/index.cjs +104 -40
- package/package.json +7 -7
|
@@ -2602,6 +2602,10 @@ const iosDevices = defineTable({
|
|
|
2602
2602
|
eq: ["status"],
|
|
2603
2603
|
sort: ["id"]
|
|
2604
2604
|
},
|
|
2605
|
+
byRegistration: {
|
|
2606
|
+
eq: [],
|
|
2607
|
+
sort: ["registered_at_ms"]
|
|
2608
|
+
},
|
|
2605
2609
|
all: {
|
|
2606
2610
|
eq: [],
|
|
2607
2611
|
sort: ["id"]
|
|
@@ -2851,6 +2855,12 @@ const WINDOW_MS$1 = 6e4;
|
|
|
2851
2855
|
/** Log rows a compaction reads from each log table for one group. */
|
|
2852
2856
|
const LOG_PAGE = 200;
|
|
2853
2857
|
/**
|
|
2858
|
+
* How old a log row this process can't apply must be before its reads step
|
|
2859
|
+
* past it: older than any transaction still committing, between servers
|
|
2860
|
+
* whose clocks agree this closely.
|
|
2861
|
+
*/
|
|
2862
|
+
const SKIP_AFTER_MS = 3e5;
|
|
2863
|
+
/**
|
|
2854
2864
|
* Groups one compaction applies: after a commit, so the request that runs
|
|
2855
2865
|
* it waits for one group; before a read; and on flush.
|
|
2856
2866
|
*/
|
|
@@ -2981,23 +2991,41 @@ const rewrite = (change, key, current) => {
|
|
|
2981
2991
|
previous: current
|
|
2982
2992
|
};
|
|
2983
2993
|
};
|
|
2994
|
+
/** A shard row's place in what `readCurrent` read. */
|
|
2995
|
+
const rowId = (model, key) => JSON.stringify([model.table.name, key]);
|
|
2996
|
+
/** The shard key each change writes: shard 0, since one compaction runs at a time. */
|
|
2997
|
+
const keysOf = (changes) => changes.map(({ key }) => [...key.slice(0, -1), 0]);
|
|
2984
2998
|
/**
|
|
2985
|
-
* The
|
|
2986
|
-
*
|
|
2987
|
-
* for gauges and sketches, whose rows are read in one batch per table.
|
|
2999
|
+
* The current rows of the changes that rewrite theirs (gauges and sketches),
|
|
3000
|
+
* each once, in one batch per table.
|
|
2988
3001
|
*/
|
|
2989
|
-
const
|
|
2990
|
-
const keys = changes
|
|
3002
|
+
const readCurrent = async (adapter, changes) => {
|
|
3003
|
+
const keys = keysOf(changes);
|
|
2991
3004
|
const reads = /* @__PURE__ */ new Map();
|
|
2992
3005
|
changes.forEach((change, at) => {
|
|
2993
|
-
if (rewrites(change))
|
|
3006
|
+
if (!rewrites(change)) return;
|
|
3007
|
+
const wanted = reads.get(change.model) ?? /* @__PURE__ */ new Map();
|
|
3008
|
+
wanted.set(rowId(change.model, keys[at]), keys[at]);
|
|
3009
|
+
reads.set(change.model, wanted);
|
|
2994
3010
|
});
|
|
2995
3011
|
const current = /* @__PURE__ */ new Map();
|
|
2996
|
-
await Promise.all([...reads].map(async ([model,
|
|
2997
|
-
const
|
|
2998
|
-
|
|
3012
|
+
await Promise.all([...reads].map(async ([model, wanted]) => {
|
|
3013
|
+
const keys = [...wanted.values()];
|
|
3014
|
+
const rows = await adapter.get(model.table, keys);
|
|
3015
|
+
keys.forEach((key, at) => {
|
|
3016
|
+
current.set(rowId(model, key), rows[at] ?? null);
|
|
3017
|
+
});
|
|
2999
3018
|
}));
|
|
3000
|
-
return
|
|
3019
|
+
return current;
|
|
3020
|
+
};
|
|
3021
|
+
/**
|
|
3022
|
+
* The write for each change: a blind increment that creates the row for
|
|
3023
|
+
* counters, and a guarded rewrite for gauges and sketches, over the rows
|
|
3024
|
+
* `current` read.
|
|
3025
|
+
*/
|
|
3026
|
+
const build = (changes, current) => {
|
|
3027
|
+
const keys = keysOf(changes);
|
|
3028
|
+
return changes.map((change, at) => rewrites(change) ? rewrite(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
|
|
3001
3029
|
};
|
|
3002
3030
|
const isOp = (op) => op !== void 0;
|
|
3003
3031
|
const sleep = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
|
|
@@ -3079,6 +3107,16 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
3079
3107
|
let compacting;
|
|
3080
3108
|
/** Log rows this process read, by `[log table's index, id]`, for the deletes after a group. */
|
|
3081
3109
|
const known = /* @__PURE__ */ new Map();
|
|
3110
|
+
/**
|
|
3111
|
+
* Each log table's last row of a run at its head that this process can't
|
|
3112
|
+
* apply (it names an aggregate or metric this schema lacks), whose reads
|
|
3113
|
+
* start past it. The rows wait for a process that can apply them, and a
|
|
3114
|
+
* restart reads them again.
|
|
3115
|
+
*/
|
|
3116
|
+
const skipped = LOG_TABLES.map(() => void 0);
|
|
3117
|
+
const past = (shard) => skipped[shard] === void 0 ? {} : { range: { gt: skipped[shard] } };
|
|
3118
|
+
/** When a log row's transaction stamped its ID. */
|
|
3119
|
+
const stampOf = (id) => Number.parseInt(id.slice(0, 9), 36);
|
|
3082
3120
|
const idOf = (shard, id) => JSON.stringify([shard, id]);
|
|
3083
3121
|
/** The lease row as stored once `set` is written over it. */
|
|
3084
3122
|
const leaseOp = (held, set) => {
|
|
@@ -3194,14 +3232,22 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
3194
3232
|
logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
|
|
3195
3233
|
const page = await engine.reads.findMany(name, {
|
|
3196
3234
|
index: "oldest",
|
|
3197
|
-
limit: LOG_PAGE
|
|
3235
|
+
limit: LOG_PAGE,
|
|
3236
|
+
...past(shard)
|
|
3198
3237
|
});
|
|
3199
3238
|
more ||= page.next !== void 0;
|
|
3200
|
-
|
|
3239
|
+
const decoded = await Promise.all(page.rows.map(async (row) => ({
|
|
3201
3240
|
shard,
|
|
3202
3241
|
row,
|
|
3203
3242
|
changes: await decode(String(row.changes))
|
|
3204
|
-
})))
|
|
3243
|
+
})));
|
|
3244
|
+
const settled = now() - SKIP_AFTER_MS;
|
|
3245
|
+
for (const { row, changes } of decoded) {
|
|
3246
|
+
const id = String(row.id);
|
|
3247
|
+
if (changes !== void 0 || stampOf(id) >= settled) break;
|
|
3248
|
+
skipped[shard] = id;
|
|
3249
|
+
}
|
|
3250
|
+
return decoded.flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
|
|
3205
3251
|
...entry,
|
|
3206
3252
|
changes
|
|
3207
3253
|
}]);
|
|
@@ -3209,7 +3255,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
3209
3255
|
more
|
|
3210
3256
|
};
|
|
3211
3257
|
};
|
|
3212
|
-
const rowsFor = async (changes) => (await compile(adapter, changes)).filter(isOp);
|
|
3213
3258
|
/**
|
|
3214
3259
|
* Applies the oldest pending log rows whose merged changes fit in one
|
|
3215
3260
|
* atomic write with the lease, which lists them as applied; the rows are
|
|
@@ -3218,12 +3263,14 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
3218
3263
|
* log rows it applied whole, or undefined when a conflict stopped it.
|
|
3219
3264
|
*/
|
|
3220
3265
|
const applyGroup = async (held, logs) => {
|
|
3266
|
+
const current = await readCurrent(adapter, logs.flatMap((entry) => [...entry.changes.values()]));
|
|
3267
|
+
const rowsFor = (changes) => build(changes, current).filter(isOp);
|
|
3221
3268
|
for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
|
|
3222
3269
|
const batch = logs.slice(0, count);
|
|
3223
3270
|
const changes = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
|
|
3224
3271
|
const applied = batch.map(({ shard, row }) => [shard, row.id]);
|
|
3225
3272
|
const lease = leaseOp(held, { applied: JSON.stringify(applied) });
|
|
3226
|
-
const ops = [...
|
|
3273
|
+
const ops = [...rowsFor([...changes.values()]), lease.op];
|
|
3227
3274
|
if (!adapter.fits(ops)) continue;
|
|
3228
3275
|
for (const { shard, row } of batch) known.set(idOf(shard, row.id), row);
|
|
3229
3276
|
return await commit(ops) ? {
|
|
@@ -3245,7 +3292,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
3245
3292
|
};
|
|
3246
3293
|
const lease = leaseOp(held, {});
|
|
3247
3294
|
const ops = [
|
|
3248
|
-
...
|
|
3295
|
+
...rowsFor(entries.slice(0, take)),
|
|
3249
3296
|
kept,
|
|
3250
3297
|
lease.op
|
|
3251
3298
|
];
|
|
@@ -3266,11 +3313,12 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
3266
3313
|
if (held === void 0) return;
|
|
3267
3314
|
let pending = true;
|
|
3268
3315
|
let clear = false;
|
|
3316
|
+
let carried;
|
|
3269
3317
|
try {
|
|
3270
3318
|
for (let group = 0;; group += 1) {
|
|
3271
3319
|
clear = await deleteApplied(held);
|
|
3272
3320
|
if (!clear || !pending || group === groups) break;
|
|
3273
|
-
const { logs, more } = await readLogs();
|
|
3321
|
+
const { logs, more } = carried ?? await readLogs();
|
|
3274
3322
|
if (logs.length === 0) {
|
|
3275
3323
|
pending = false;
|
|
3276
3324
|
break;
|
|
@@ -3278,6 +3326,11 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
3278
3326
|
const applied = await applyGroup(held, logs);
|
|
3279
3327
|
if (applied === void 0) break;
|
|
3280
3328
|
[held, clear] = [applied.held, false];
|
|
3329
|
+
const rest = applied.count === 0 ? [] : logs.slice(applied.count);
|
|
3330
|
+
carried = rest.length > 0 ? {
|
|
3331
|
+
logs: rest,
|
|
3332
|
+
more
|
|
3333
|
+
} : void 0;
|
|
3281
3334
|
pending = more || applied.count < logs.length;
|
|
3282
3335
|
}
|
|
3283
3336
|
} finally {
|
|
@@ -3297,9 +3350,10 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
3297
3350
|
});
|
|
3298
3351
|
let checking;
|
|
3299
3352
|
/** Whether any log row waits; reads at once share one check. */
|
|
3300
|
-
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name) => engine.reads.findMany(name, {
|
|
3353
|
+
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name, shard) => engine.reads.findMany(name, {
|
|
3301
3354
|
index: "oldest",
|
|
3302
|
-
limit: 1
|
|
3355
|
+
limit: 1,
|
|
3356
|
+
...past(shard)
|
|
3303
3357
|
}))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
|
|
3304
3358
|
checking = void 0;
|
|
3305
3359
|
});
|
|
@@ -4762,7 +4816,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
4762
4816
|
};
|
|
4763
4817
|
//#endregion
|
|
4764
4818
|
//#region ../../packages/server/dist/version.mjs
|
|
4765
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
4819
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.45";
|
|
4766
4820
|
//#endregion
|
|
4767
4821
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
4768
4822
|
/**
|
|
@@ -5855,8 +5909,6 @@ const NAME_MAX_LENGTH = 100;
|
|
|
5855
5909
|
const EMAIL_MAX_LENGTH = 320;
|
|
5856
5910
|
/** `ios_devices.apple_issuer_id`'s bound. */
|
|
5857
5911
|
const ISSUER_MAX_LENGTH = 64;
|
|
5858
|
-
/** How many registry rows one read takes while finding its account. */
|
|
5859
|
-
const ACCOUNT_SCAN_PAGE = 200;
|
|
5860
5912
|
/** The one row of `ios_device_account`. */
|
|
5861
5913
|
const ACCOUNT_ROW = "registry";
|
|
5862
5914
|
/** `ios_devices.apple_error`'s bound. */
|
|
@@ -5931,25 +5983,19 @@ const createIosDeviceApi = (db, { now = Date.now } = {}) => {
|
|
|
5931
5983
|
/**
|
|
5932
5984
|
* The issuer of the registry's earliest registration among its rows, by
|
|
5933
5985
|
* when and then by ID, or null when no row names one: read only while the
|
|
5934
|
-
* registry has no account yet,
|
|
5986
|
+
* registry has no account yet, in one read of its first registration. A
|
|
5987
|
+
* row names an issuer exactly when it has a registration time: both are
|
|
5988
|
+
* set by its first registration and never cleared.
|
|
5935
5989
|
*/
|
|
5936
5990
|
const accountOfRows = async () => {
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
});
|
|
5946
|
-
for (const row of rows.map(pick$1)) {
|
|
5947
|
-
if (row.apple_issuer_id === null) continue;
|
|
5948
|
-
if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
|
|
5949
|
-
}
|
|
5950
|
-
if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
|
|
5951
|
-
after = rows.at(-1).id;
|
|
5952
|
-
}
|
|
5991
|
+
const { rows } = await db.findMany("ios_devices", {
|
|
5992
|
+
index: "byRegistration",
|
|
5993
|
+
where: {},
|
|
5994
|
+
order: "asc",
|
|
5995
|
+
limit: 1,
|
|
5996
|
+
range: { gte: 0 }
|
|
5997
|
+
});
|
|
5998
|
+
return (rows[0] === void 0 ? null : pick$1(rows[0]))?.apple_issuer_id ?? null;
|
|
5953
5999
|
};
|
|
5954
6000
|
return {
|
|
5955
6001
|
async listIosDevices(input) {
|
|
@@ -6338,6 +6384,12 @@ const EXPORT_METHODS = /* @__PURE__ */ new Set([
|
|
|
6338
6384
|
* a bundle when a build made after the bundle is the newest.
|
|
6339
6385
|
*/
|
|
6340
6386
|
const OLDER_BUILDS_PAGE = 20;
|
|
6387
|
+
/**
|
|
6388
|
+
* How many pages of older builds that look reads before it answers null: 100
|
|
6389
|
+
* builds made after the bundle in one scope, where a deploy's new bundle has
|
|
6390
|
+
* none or a few registered while it deploys.
|
|
6391
|
+
*/
|
|
6392
|
+
const OLDER_BUILDS_PAGES = 5;
|
|
6341
6393
|
/** How many times a mark runs again after losing its scope's mark to another. */
|
|
6342
6394
|
const MARK_ATTEMPTS = 8;
|
|
6343
6395
|
/** `native_builds.build_number`'s bound in core's schema. */
|
|
@@ -6573,6 +6625,10 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
6573
6625
|
const row = await db.findOne("native_builds", { id });
|
|
6574
6626
|
return row === null ? null : pick(row);
|
|
6575
6627
|
},
|
|
6628
|
+
async findNativeBuildByBuiltInBundle(bundleId) {
|
|
6629
|
+
const row = await db.findOne("native_builds", { min_bundle_id: bundleId });
|
|
6630
|
+
return row === null ? null : pick(row);
|
|
6631
|
+
},
|
|
6576
6632
|
async findNativeBuild(scope, options) {
|
|
6577
6633
|
const scopeKey = nativeBuildScopeKey(scope);
|
|
6578
6634
|
const buildKey = options?.buildKey;
|
|
@@ -6621,7 +6677,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
6621
6677
|
}).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick(row) : void 0) : void 0);
|
|
6622
6678
|
if (newest === void 0 || !ofKind(newest)) return null;
|
|
6623
6679
|
if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
|
|
6624
|
-
|
|
6680
|
+
let before = newest.id;
|
|
6681
|
+
for (let page = 0; page < OLDER_BUILDS_PAGES; page += 1) {
|
|
6625
6682
|
const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
|
|
6626
6683
|
const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
|
|
6627
6684
|
if (usable !== void 0) return ofKind(usable) ? pick(usable) : null;
|
|
@@ -6629,6 +6686,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
6629
6686
|
if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
|
|
6630
6687
|
before = last.id;
|
|
6631
6688
|
}
|
|
6689
|
+
return null;
|
|
6632
6690
|
},
|
|
6633
6691
|
async findNativeBuildSibling(build) {
|
|
6634
6692
|
const artifactKind = SIBLING_KINDS[build.artifact_kind];
|
|
@@ -7842,6 +7900,7 @@ const createAdminRouteHandlers = () => ({
|
|
|
7842
7900
|
return json$2({ data: build === null ? null : await core.findNativeBuildSibling(build) });
|
|
7843
7901
|
}),
|
|
7844
7902
|
getNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
|
|
7903
|
+
findNativeBuildByBuiltInBundle: onCore(async (core, _request, params) => json$2({ data: await core.findNativeBuildByBuiltInBundle(requireRouteParam(params, "bundleId")) })),
|
|
7845
7904
|
listNativeBuilds: onCore(async (core, request) => {
|
|
7846
7905
|
const url = new URL(request.url);
|
|
7847
7906
|
const input = keyset(url);
|
|
@@ -8072,6 +8131,11 @@ const ADMIN_ROUTES = [
|
|
|
8072
8131
|
path: "/native-builds/latest",
|
|
8073
8132
|
handler: "findNativeBuild"
|
|
8074
8133
|
},
|
|
8134
|
+
{
|
|
8135
|
+
method: "GET",
|
|
8136
|
+
path: "/native-builds/built-in/:bundleId",
|
|
8137
|
+
handler: "findNativeBuildByBuiltInBundle"
|
|
8138
|
+
},
|
|
8075
8139
|
{
|
|
8076
8140
|
method: "GET",
|
|
8077
8141
|
path: "/native-builds/:id/sibling",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/firebase",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.45",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"hono": "4.12.34",
|
|
40
40
|
"google-auth-library": "10.7.0",
|
|
41
|
-
"@hot-updater/cli-tools": "1.2.0-rc.
|
|
42
|
-
"@hot-updater/
|
|
43
|
-
"@hot-updater/
|
|
44
|
-
"@hot-updater/
|
|
41
|
+
"@hot-updater/cli-tools": "1.2.0-rc.45",
|
|
42
|
+
"@hot-updater/protocol": "1.2.0-rc.45",
|
|
43
|
+
"@hot-updater/server": "1.2.0-rc.45",
|
|
44
|
+
"@hot-updater/plugin-core": "1.2.0-rc.45"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"firebase-tools": "15.29.0",
|
|
57
57
|
"fkill": "^9.0.0",
|
|
58
58
|
"mime": "^4.0.4",
|
|
59
|
-
"@hot-updater/mock": "1.2.0-rc.
|
|
60
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
59
|
+
"@hot-updater/mock": "1.2.0-rc.45",
|
|
60
|
+
"@hot-updater/test-utils": "1.2.0-rc.45"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"firebase-admin": ">=11.10.0",
|