@hot-updater/firebase 1.1.14 → 1.1.16
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.
|
@@ -2528,6 +2528,12 @@ const WINDOW_MS$1 = {
|
|
|
2528
2528
|
/** Log rows a compaction reads from each log table for one group. */
|
|
2529
2529
|
const LOG_PAGE = 200;
|
|
2530
2530
|
/**
|
|
2531
|
+
* How old a log row this process can't apply must be before its reads step
|
|
2532
|
+
* past it: older than any transaction still committing, between servers
|
|
2533
|
+
* whose clocks agree this closely.
|
|
2534
|
+
*/
|
|
2535
|
+
const SKIP_AFTER_MS = 3e5;
|
|
2536
|
+
/**
|
|
2531
2537
|
* Groups one compaction applies: after a commit, so the request that runs
|
|
2532
2538
|
* it waits for one group; before a read; and on flush.
|
|
2533
2539
|
*/
|
|
@@ -2660,24 +2666,44 @@ const rewrite = (change, key, current) => {
|
|
|
2660
2666
|
previous: current
|
|
2661
2667
|
};
|
|
2662
2668
|
};
|
|
2669
|
+
/** A shard row's place in what `readCurrent` read. */
|
|
2670
|
+
const rowId = (model, key) => JSON.stringify([model.table.name, key]);
|
|
2671
|
+
/** The shard key each change writes. */
|
|
2672
|
+
const keysOf = (changes, shard) => changes.map(({ model, key }) => [...key.slice(0, -1), shard(model)]);
|
|
2663
2673
|
/**
|
|
2664
|
-
* The
|
|
2665
|
-
*
|
|
2666
|
-
* rows are read in one batch per table.
|
|
2674
|
+
* The current rows of the changes that rewrite theirs (gauges and sketches),
|
|
2675
|
+
* each once, in one batch per table.
|
|
2667
2676
|
*/
|
|
2668
|
-
const
|
|
2669
|
-
const keys = changes
|
|
2677
|
+
const readCurrent = async (adapter, changes, shard) => {
|
|
2678
|
+
const keys = keysOf(changes, shard);
|
|
2670
2679
|
const reads = /* @__PURE__ */ new Map();
|
|
2671
2680
|
changes.forEach((change, at) => {
|
|
2672
|
-
if (rewrites(change))
|
|
2681
|
+
if (!rewrites(change)) return;
|
|
2682
|
+
const wanted = reads.get(change.model) ?? /* @__PURE__ */ new Map();
|
|
2683
|
+
wanted.set(rowId(change.model, keys[at]), keys[at]);
|
|
2684
|
+
reads.set(change.model, wanted);
|
|
2673
2685
|
});
|
|
2674
2686
|
const current = /* @__PURE__ */ new Map();
|
|
2675
|
-
await Promise.all([...reads].map(async ([model,
|
|
2676
|
-
const
|
|
2677
|
-
|
|
2687
|
+
await Promise.all([...reads].map(async ([model, wanted]) => {
|
|
2688
|
+
const keys = [...wanted.values()];
|
|
2689
|
+
const rows = await adapter.get(model.table, keys);
|
|
2690
|
+
keys.forEach((key, at) => {
|
|
2691
|
+
current.set(rowId(model, key), rows[at] ?? null);
|
|
2692
|
+
});
|
|
2678
2693
|
}));
|
|
2679
|
-
return
|
|
2694
|
+
return current;
|
|
2695
|
+
};
|
|
2696
|
+
/**
|
|
2697
|
+
* The write for each change on its shard: a blind increment that creates
|
|
2698
|
+
* the row for counters, and a guarded rewrite for gauges and sketches, over
|
|
2699
|
+
* the rows `current` read.
|
|
2700
|
+
*/
|
|
2701
|
+
const build = (changes, shard, current) => {
|
|
2702
|
+
const keys = keysOf(changes, shard);
|
|
2703
|
+
return changes.map((change, at) => rewrites(change) ? rewrite(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
|
|
2680
2704
|
};
|
|
2705
|
+
/** `build` over rows read for these changes. */
|
|
2706
|
+
const compile = async (adapter, changes, shard) => build(changes, shard, await readCurrent(adapter, changes, shard));
|
|
2681
2707
|
const isOp = (op) => op !== void 0;
|
|
2682
2708
|
const sleep = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
|
|
2683
2709
|
/** Runs of one character, where shorter: a sparse sketch packs into a few. */
|
|
@@ -2821,6 +2847,16 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2821
2847
|
let compacting;
|
|
2822
2848
|
/** Log rows this process read, by `[log table's index, id]`, for the deletes after a group. */
|
|
2823
2849
|
const known = /* @__PURE__ */ new Map();
|
|
2850
|
+
/**
|
|
2851
|
+
* Each log table's last row of a run at its head that this process can't
|
|
2852
|
+
* apply (it names an aggregate or metric this schema lacks), whose reads
|
|
2853
|
+
* start past it. The rows wait for a process that can apply them, and a
|
|
2854
|
+
* restart reads them again.
|
|
2855
|
+
*/
|
|
2856
|
+
const skipped = LOG_TABLES.map(() => void 0);
|
|
2857
|
+
const past = (shard) => skipped[shard] === void 0 ? {} : { range: { gt: skipped[shard] } };
|
|
2858
|
+
/** When a log row's transaction stamped its ID. */
|
|
2859
|
+
const stampOf = (id) => Number.parseInt(id.slice(0, 9), 36);
|
|
2824
2860
|
const idOf = (shard, id) => JSON.stringify([shard, id]);
|
|
2825
2861
|
/** The lease row as stored once `set` is written over it. */
|
|
2826
2862
|
const leaseOp = (held, set) => {
|
|
@@ -2936,14 +2972,22 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2936
2972
|
logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
|
|
2937
2973
|
const page = await engine.reads.findMany(name, {
|
|
2938
2974
|
index: "oldest",
|
|
2939
|
-
limit: LOG_PAGE
|
|
2975
|
+
limit: LOG_PAGE,
|
|
2976
|
+
...past(shard)
|
|
2940
2977
|
});
|
|
2941
2978
|
more ||= page.next !== void 0;
|
|
2942
|
-
|
|
2979
|
+
const decoded = await Promise.all(page.rows.map(async (row) => ({
|
|
2943
2980
|
shard,
|
|
2944
2981
|
row,
|
|
2945
2982
|
changes: await decode(String(row.changes))
|
|
2946
|
-
})))
|
|
2983
|
+
})));
|
|
2984
|
+
const settled = now() - SKIP_AFTER_MS;
|
|
2985
|
+
for (const { row, changes } of decoded) {
|
|
2986
|
+
const id = String(row.id);
|
|
2987
|
+
if (changes !== void 0 || stampOf(id) >= settled) break;
|
|
2988
|
+
skipped[shard] = id;
|
|
2989
|
+
}
|
|
2990
|
+
return decoded.flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
|
|
2947
2991
|
...entry,
|
|
2948
2992
|
changes
|
|
2949
2993
|
}]);
|
|
@@ -2951,7 +2995,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2951
2995
|
more
|
|
2952
2996
|
};
|
|
2953
2997
|
};
|
|
2954
|
-
const rowsFor = async (changes) => (await compile(adapter, changes, () => 0)).filter(isOp);
|
|
2955
2998
|
/**
|
|
2956
2999
|
* Applies the oldest pending log rows whose merged changes fit in one
|
|
2957
3000
|
* atomic write with the lease, which lists them as applied; the rows are
|
|
@@ -2960,12 +3003,14 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2960
3003
|
* log rows it applied whole, or undefined when a conflict stopped it.
|
|
2961
3004
|
*/
|
|
2962
3005
|
const applyGroup = async (held, logs) => {
|
|
3006
|
+
const current = await readCurrent(adapter, logs.flatMap((entry) => [...entry.changes.values()]), () => 0);
|
|
3007
|
+
const rowsFor = (changes) => build(changes, () => 0, current).filter(isOp);
|
|
2963
3008
|
for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
|
|
2964
3009
|
const batch = logs.slice(0, count);
|
|
2965
3010
|
const changes = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
|
|
2966
3011
|
const applied = batch.map(({ shard, row }) => [shard, row.id]);
|
|
2967
3012
|
const lease = leaseOp(held, { applied: JSON.stringify(applied) });
|
|
2968
|
-
const ops = [...
|
|
3013
|
+
const ops = [...rowsFor([...changes.values()]), lease.op];
|
|
2969
3014
|
if (!adapter.fits(ops)) continue;
|
|
2970
3015
|
for (const { shard, row } of batch) known.set(idOf(shard, row.id), row);
|
|
2971
3016
|
return await commit(ops) ? {
|
|
@@ -2987,7 +3032,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2987
3032
|
};
|
|
2988
3033
|
const lease = leaseOp(held, {});
|
|
2989
3034
|
const ops = [
|
|
2990
|
-
...
|
|
3035
|
+
...rowsFor(entries.slice(0, take)),
|
|
2991
3036
|
kept,
|
|
2992
3037
|
lease.op
|
|
2993
3038
|
];
|
|
@@ -3008,11 +3053,12 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3008
3053
|
if (held === void 0) return;
|
|
3009
3054
|
let pending = true;
|
|
3010
3055
|
let clear = false;
|
|
3056
|
+
let carried;
|
|
3011
3057
|
try {
|
|
3012
3058
|
for (let group = 0;; group += 1) {
|
|
3013
3059
|
clear = await deleteApplied(held);
|
|
3014
3060
|
if (!clear || !pending || group === groups) break;
|
|
3015
|
-
const { logs, more } = await readLogs();
|
|
3061
|
+
const { logs, more } = carried ?? await readLogs();
|
|
3016
3062
|
if (logs.length === 0) {
|
|
3017
3063
|
pending = false;
|
|
3018
3064
|
break;
|
|
@@ -3020,6 +3066,11 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3020
3066
|
const applied = await applyGroup(held, logs);
|
|
3021
3067
|
if (applied === void 0) break;
|
|
3022
3068
|
[held, clear] = [applied.held, false];
|
|
3069
|
+
const rest = applied.count === 0 ? [] : logs.slice(applied.count);
|
|
3070
|
+
carried = rest.length > 0 ? {
|
|
3071
|
+
logs: rest,
|
|
3072
|
+
more
|
|
3073
|
+
} : void 0;
|
|
3023
3074
|
pending = more || applied.count < logs.length;
|
|
3024
3075
|
}
|
|
3025
3076
|
} finally {
|
|
@@ -3039,9 +3090,10 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3039
3090
|
});
|
|
3040
3091
|
let checking;
|
|
3041
3092
|
/** Whether any log row waits; reads at once share one check. */
|
|
3042
|
-
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name) => engine.reads.findMany(name, {
|
|
3093
|
+
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name, shard) => engine.reads.findMany(name, {
|
|
3043
3094
|
index: "oldest",
|
|
3044
|
-
limit: 1
|
|
3095
|
+
limit: 1,
|
|
3096
|
+
...past(shard)
|
|
3045
3097
|
}))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
|
|
3046
3098
|
checking = void 0;
|
|
3047
3099
|
});
|
|
@@ -4525,7 +4577,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
4525
4577
|
};
|
|
4526
4578
|
//#endregion
|
|
4527
4579
|
//#region ../../packages/server/dist/version.mjs
|
|
4528
|
-
const HOT_UPDATER_SERVER_VERSION = "1.1.
|
|
4580
|
+
const HOT_UPDATER_SERVER_VERSION = "1.1.16";
|
|
4529
4581
|
//#endregion
|
|
4530
4582
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
4531
4583
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/firebase",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.16",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"hono": "4.12.34",
|
|
40
|
-
"@hot-updater/cli-tools": "1.1.
|
|
41
|
-
"@hot-updater/
|
|
42
|
-
"@hot-updater/
|
|
43
|
-
"@hot-updater/
|
|
40
|
+
"@hot-updater/cli-tools": "1.1.16",
|
|
41
|
+
"@hot-updater/protocol": "1.1.16",
|
|
42
|
+
"@hot-updater/plugin-core": "1.1.16",
|
|
43
|
+
"@hot-updater/server": "1.1.16"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"firebase-tools": "15.29.0",
|
|
56
56
|
"fkill": "^9.0.0",
|
|
57
57
|
"mime": "^4.0.4",
|
|
58
|
-
"@hot-updater/mock": "1.1.
|
|
59
|
-
"@hot-updater/test-utils": "1.1.
|
|
58
|
+
"@hot-updater/mock": "1.1.16",
|
|
59
|
+
"@hot-updater/test-utils": "1.1.16"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"firebase-admin": ">=11.10.0",
|