@hot-updater/azure 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/functions/index.mjs +108 -43
- package/dist/index.cjs +45 -8
- package/dist/index.mjs +45 -8
- package/dist/init/index.cjs +45 -8
- package/dist/init/index.mjs +45 -8
- package/package.json +6 -6
package/dist/functions/index.mjs
CHANGED
|
@@ -6220,6 +6220,10 @@ const iosDevices = defineTable({
|
|
|
6220
6220
|
eq: ["status"],
|
|
6221
6221
|
sort: ["id"]
|
|
6222
6222
|
},
|
|
6223
|
+
byRegistration: {
|
|
6224
|
+
eq: [],
|
|
6225
|
+
sort: ["registered_at_ms"]
|
|
6226
|
+
},
|
|
6223
6227
|
all: {
|
|
6224
6228
|
eq: [],
|
|
6225
6229
|
sort: ["id"]
|
|
@@ -6433,6 +6437,7 @@ const LEASE = { id: "compaction" };
|
|
|
6433
6437
|
const LEASE_MS = 3e4;
|
|
6434
6438
|
const WINDOW_MS$1 = 6e4;
|
|
6435
6439
|
const LOG_PAGE = 200;
|
|
6440
|
+
const SKIP_AFTER_MS = 3e5;
|
|
6436
6441
|
const GROUPS = {
|
|
6437
6442
|
commit: 1,
|
|
6438
6443
|
read: 8,
|
|
@@ -6539,18 +6544,30 @@ const rewrite = (change, key, current) => {
|
|
|
6539
6544
|
previous: current
|
|
6540
6545
|
};
|
|
6541
6546
|
};
|
|
6542
|
-
const
|
|
6543
|
-
|
|
6547
|
+
const rowId = (model, key) => JSON.stringify([model.table.name, key]);
|
|
6548
|
+
const keysOf = (changes) => changes.map(({ key }) => [...key.slice(0, -1), 0]);
|
|
6549
|
+
const readCurrent = async (adapter, changes) => {
|
|
6550
|
+
const keys = keysOf(changes);
|
|
6544
6551
|
const reads = /* @__PURE__ */ new Map();
|
|
6545
6552
|
changes.forEach((change, at) => {
|
|
6546
|
-
if (rewrites(change))
|
|
6553
|
+
if (!rewrites(change)) return;
|
|
6554
|
+
const wanted = reads.get(change.model) ?? /* @__PURE__ */ new Map();
|
|
6555
|
+
wanted.set(rowId(change.model, keys[at]), keys[at]);
|
|
6556
|
+
reads.set(change.model, wanted);
|
|
6547
6557
|
});
|
|
6548
6558
|
const current = /* @__PURE__ */ new Map();
|
|
6549
|
-
await Promise.all([...reads].map(async ([model,
|
|
6550
|
-
const
|
|
6551
|
-
|
|
6559
|
+
await Promise.all([...reads].map(async ([model, wanted]) => {
|
|
6560
|
+
const keys = [...wanted.values()];
|
|
6561
|
+
const rows = await adapter.get(model.table, keys);
|
|
6562
|
+
keys.forEach((key, at) => {
|
|
6563
|
+
current.set(rowId(model, key), rows[at] ?? null);
|
|
6564
|
+
});
|
|
6552
6565
|
}));
|
|
6553
|
-
return
|
|
6566
|
+
return current;
|
|
6567
|
+
};
|
|
6568
|
+
const build = (changes, current) => {
|
|
6569
|
+
const keys = keysOf(changes);
|
|
6570
|
+
return changes.map((change, at) => rewrites(change) ? rewrite(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
|
|
6554
6571
|
};
|
|
6555
6572
|
const isOp = (op) => op !== void 0;
|
|
6556
6573
|
const sleep$1 = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
|
|
@@ -6616,6 +6633,9 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
6616
6633
|
let nextDue = 0;
|
|
6617
6634
|
let compacting;
|
|
6618
6635
|
const known = /* @__PURE__ */ new Map();
|
|
6636
|
+
const skipped = LOG_TABLES.map(() => void 0);
|
|
6637
|
+
const past = (shard) => skipped[shard] === void 0 ? {} : { range: { gt: skipped[shard] } };
|
|
6638
|
+
const stampOf = (id) => Number.parseInt(id.slice(0, 9), 36);
|
|
6619
6639
|
const idOf = (shard, id) => JSON.stringify([shard, id]);
|
|
6620
6640
|
const leaseOp = (held, set) => {
|
|
6621
6641
|
const next = {
|
|
@@ -6719,14 +6739,22 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
6719
6739
|
logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
|
|
6720
6740
|
const page = await engine.reads.findMany(name, {
|
|
6721
6741
|
index: "oldest",
|
|
6722
|
-
limit: LOG_PAGE
|
|
6742
|
+
limit: LOG_PAGE,
|
|
6743
|
+
...past(shard)
|
|
6723
6744
|
});
|
|
6724
6745
|
more ||= page.next !== void 0;
|
|
6725
|
-
|
|
6746
|
+
const decoded = await Promise.all(page.rows.map(async (row) => ({
|
|
6726
6747
|
shard,
|
|
6727
6748
|
row,
|
|
6728
6749
|
changes: await decode(String(row.changes))
|
|
6729
|
-
})))
|
|
6750
|
+
})));
|
|
6751
|
+
const settled = now() - SKIP_AFTER_MS;
|
|
6752
|
+
for (const { row, changes } of decoded) {
|
|
6753
|
+
const id = String(row.id);
|
|
6754
|
+
if (changes !== void 0 || stampOf(id) >= settled) break;
|
|
6755
|
+
skipped[shard] = id;
|
|
6756
|
+
}
|
|
6757
|
+
return decoded.flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
|
|
6730
6758
|
...entry,
|
|
6731
6759
|
changes
|
|
6732
6760
|
}]);
|
|
@@ -6734,14 +6762,15 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
6734
6762
|
more
|
|
6735
6763
|
};
|
|
6736
6764
|
};
|
|
6737
|
-
const rowsFor = async (changes) => (await compile(adapter, changes)).filter(isOp);
|
|
6738
6765
|
const applyGroup = async (held, logs) => {
|
|
6766
|
+
const current = await readCurrent(adapter, logs.flatMap((entry) => [...entry.changes.values()]));
|
|
6767
|
+
const rowsFor = (changes) => build(changes, current).filter(isOp);
|
|
6739
6768
|
for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
|
|
6740
6769
|
const batch = logs.slice(0, count);
|
|
6741
6770
|
const changes = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
|
|
6742
6771
|
const applied = batch.map(({ shard, row }) => [shard, row.id]);
|
|
6743
6772
|
const lease = leaseOp(held, { applied: JSON.stringify(applied) });
|
|
6744
|
-
const ops = [...
|
|
6773
|
+
const ops = [...rowsFor([...changes.values()]), lease.op];
|
|
6745
6774
|
if (!adapter.fits(ops)) continue;
|
|
6746
6775
|
for (const { shard, row } of batch) known.set(idOf(shard, row.id), row);
|
|
6747
6776
|
return await commit(ops) ? {
|
|
@@ -6763,7 +6792,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
6763
6792
|
};
|
|
6764
6793
|
const lease = leaseOp(held, {});
|
|
6765
6794
|
const ops = [
|
|
6766
|
-
...
|
|
6795
|
+
...rowsFor(entries.slice(0, take)),
|
|
6767
6796
|
kept,
|
|
6768
6797
|
lease.op
|
|
6769
6798
|
];
|
|
@@ -6779,11 +6808,12 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
6779
6808
|
if (held === void 0) return;
|
|
6780
6809
|
let pending = true;
|
|
6781
6810
|
let clear = false;
|
|
6811
|
+
let carried;
|
|
6782
6812
|
try {
|
|
6783
6813
|
for (let group = 0;; group += 1) {
|
|
6784
6814
|
clear = await deleteApplied(held);
|
|
6785
6815
|
if (!clear || !pending || group === groups) break;
|
|
6786
|
-
const { logs, more } = await readLogs();
|
|
6816
|
+
const { logs, more } = carried ?? await readLogs();
|
|
6787
6817
|
if (logs.length === 0) {
|
|
6788
6818
|
pending = false;
|
|
6789
6819
|
break;
|
|
@@ -6791,6 +6821,11 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
6791
6821
|
const applied = await applyGroup(held, logs);
|
|
6792
6822
|
if (applied === void 0) break;
|
|
6793
6823
|
[held, clear] = [applied.held, false];
|
|
6824
|
+
const rest = applied.count === 0 ? [] : logs.slice(applied.count);
|
|
6825
|
+
carried = rest.length > 0 ? {
|
|
6826
|
+
logs: rest,
|
|
6827
|
+
more
|
|
6828
|
+
} : void 0;
|
|
6794
6829
|
pending = more || applied.count < logs.length;
|
|
6795
6830
|
}
|
|
6796
6831
|
} finally {
|
|
@@ -6808,9 +6843,10 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
|
|
|
6808
6843
|
compacting = void 0;
|
|
6809
6844
|
});
|
|
6810
6845
|
let checking;
|
|
6811
|
-
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name) => engine.reads.findMany(name, {
|
|
6846
|
+
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name, shard) => engine.reads.findMany(name, {
|
|
6812
6847
|
index: "oldest",
|
|
6813
|
-
limit: 1
|
|
6848
|
+
limit: 1,
|
|
6849
|
+
...past(shard)
|
|
6814
6850
|
}))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
|
|
6815
6851
|
checking = void 0;
|
|
6816
6852
|
});
|
|
@@ -8159,7 +8195,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
8159
8195
|
};
|
|
8160
8196
|
//#endregion
|
|
8161
8197
|
//#region ../../packages/server/dist/version.mjs
|
|
8162
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
8198
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.45";
|
|
8163
8199
|
//#endregion
|
|
8164
8200
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
8165
8201
|
const createVersionRouteHandlers = (plugins = []) => {
|
|
@@ -9166,7 +9202,6 @@ const normalizeIosUdid = (value) => {
|
|
|
9166
9202
|
const NAME_MAX_LENGTH = 100;
|
|
9167
9203
|
const EMAIL_MAX_LENGTH = 320;
|
|
9168
9204
|
const ISSUER_MAX_LENGTH = 64;
|
|
9169
|
-
const ACCOUNT_SCAN_PAGE = 200;
|
|
9170
9205
|
const ACCOUNT_ROW = "registry";
|
|
9171
9206
|
const ERROR_MAX_LENGTH = 512;
|
|
9172
9207
|
const STATUSES = [
|
|
@@ -9227,22 +9262,14 @@ const createIosDeviceApi = (db, { now = Date.now } = {}) => {
|
|
|
9227
9262
|
return row === null ? null : pick$1(row);
|
|
9228
9263
|
};
|
|
9229
9264
|
const accountOfRows = async () => {
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
});
|
|
9239
|
-
for (const row of rows.map(pick$1)) {
|
|
9240
|
-
if (row.apple_issuer_id === null) continue;
|
|
9241
|
-
if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
|
|
9242
|
-
}
|
|
9243
|
-
if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
|
|
9244
|
-
after = rows.at(-1).id;
|
|
9245
|
-
}
|
|
9265
|
+
const { rows } = await db.findMany("ios_devices", {
|
|
9266
|
+
index: "byRegistration",
|
|
9267
|
+
where: {},
|
|
9268
|
+
order: "asc",
|
|
9269
|
+
limit: 1,
|
|
9270
|
+
range: { gte: 0 }
|
|
9271
|
+
});
|
|
9272
|
+
return (rows[0] === void 0 ? null : pick$1(rows[0]))?.apple_issuer_id ?? null;
|
|
9246
9273
|
};
|
|
9247
9274
|
return {
|
|
9248
9275
|
async listIosDevices(input) {
|
|
@@ -9591,6 +9618,7 @@ const EXPORT_METHODS = /* @__PURE__ */ new Set([
|
|
|
9591
9618
|
"enterprise"
|
|
9592
9619
|
]);
|
|
9593
9620
|
const OLDER_BUILDS_PAGE = 20;
|
|
9621
|
+
const OLDER_BUILDS_PAGES = 5;
|
|
9594
9622
|
const MARK_ATTEMPTS = 8;
|
|
9595
9623
|
const BUILD_NUMBER_MAX_LENGTH = 64;
|
|
9596
9624
|
const SUBMITTED_VERSION_MAX_LENGTH = 255;
|
|
@@ -9781,6 +9809,10 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
9781
9809
|
const row = await db.findOne("native_builds", { id });
|
|
9782
9810
|
return row === null ? null : pick(row);
|
|
9783
9811
|
},
|
|
9812
|
+
async findNativeBuildByBuiltInBundle(bundleId) {
|
|
9813
|
+
const row = await db.findOne("native_builds", { min_bundle_id: bundleId });
|
|
9814
|
+
return row === null ? null : pick(row);
|
|
9815
|
+
},
|
|
9784
9816
|
async findNativeBuild(scope, options) {
|
|
9785
9817
|
const scopeKey = nativeBuildScopeKey(scope);
|
|
9786
9818
|
const buildKey = options?.buildKey;
|
|
@@ -9829,7 +9861,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
9829
9861
|
}).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick(row) : void 0) : void 0);
|
|
9830
9862
|
if (newest === void 0 || !ofKind(newest)) return null;
|
|
9831
9863
|
if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
|
|
9832
|
-
|
|
9864
|
+
let before = newest.id;
|
|
9865
|
+
for (let page = 0; page < OLDER_BUILDS_PAGES; page += 1) {
|
|
9833
9866
|
const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
|
|
9834
9867
|
const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
|
|
9835
9868
|
if (usable !== void 0) return ofKind(usable) ? pick(usable) : null;
|
|
@@ -9837,6 +9870,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
9837
9870
|
if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
|
|
9838
9871
|
before = last.id;
|
|
9839
9872
|
}
|
|
9873
|
+
return null;
|
|
9840
9874
|
},
|
|
9841
9875
|
async findNativeBuildSibling(build) {
|
|
9842
9876
|
const artifactKind = SIBLING_KINDS[build.artifact_kind];
|
|
@@ -10989,6 +11023,7 @@ const createAdminRouteHandlers = () => ({
|
|
|
10989
11023
|
return json$2({ data: build === null ? null : await core.findNativeBuildSibling(build) });
|
|
10990
11024
|
}),
|
|
10991
11025
|
getNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
|
|
11026
|
+
findNativeBuildByBuiltInBundle: onCore(async (core, _request, params) => json$2({ data: await core.findNativeBuildByBuiltInBundle(requireRouteParam(params, "bundleId")) })),
|
|
10992
11027
|
listNativeBuilds: onCore(async (core, request) => {
|
|
10993
11028
|
const url = new URL(request.url);
|
|
10994
11029
|
const input = keyset(url);
|
|
@@ -11218,6 +11253,11 @@ const ADMIN_ROUTES = [
|
|
|
11218
11253
|
path: "/native-builds/latest",
|
|
11219
11254
|
handler: "findNativeBuild"
|
|
11220
11255
|
},
|
|
11256
|
+
{
|
|
11257
|
+
method: "GET",
|
|
11258
|
+
path: "/native-builds/built-in/:bundleId",
|
|
11259
|
+
handler: "findNativeBuildByBuiltInBundle"
|
|
11260
|
+
},
|
|
11221
11261
|
{
|
|
11222
11262
|
method: "GET",
|
|
11223
11263
|
path: "/native-builds/:id/sibling",
|
|
@@ -71550,6 +71590,7 @@ const statusOf = (error) => {
|
|
|
71550
71590
|
if (typeof status === "number") return status;
|
|
71551
71591
|
}
|
|
71552
71592
|
};
|
|
71593
|
+
const POINT_READS = 2;
|
|
71553
71594
|
const missingContainer = (error) => {
|
|
71554
71595
|
throw statusOf(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
71555
71596
|
};
|
|
@@ -71612,16 +71653,36 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
71612
71653
|
throw error;
|
|
71613
71654
|
});
|
|
71614
71655
|
const container = async () => (await open()).container;
|
|
71656
|
+
const pointRead = async (id) => {
|
|
71657
|
+
const response = await (await container()).item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
71658
|
+
if (response.statusCode !== 404) return response.resource;
|
|
71659
|
+
const headers = response.headers;
|
|
71660
|
+
if (headers["x-ms-documentdb-partitionkeyrangeid"] === void 0 && headers["x-ms-substatus"] !== void 0) missingContainer(Object.assign(/* @__PURE__ */ new Error(`Cosmos DB container ${containerId} is missing.`), { code: 404 }));
|
|
71661
|
+
};
|
|
71615
71662
|
const readStates = async (ids, rowIds) => {
|
|
71616
71663
|
const states = /* @__PURE__ */ new Map();
|
|
71617
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
71618
|
-
|
|
71619
|
-
|
|
71620
|
-
|
|
71621
|
-
|
|
71622
|
-
|
|
71623
|
-
|
|
71624
|
-
|
|
71664
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
71665
|
+
if (group.length <= POINT_READS) {
|
|
71666
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
71667
|
+
if (item === void 0) continue;
|
|
71668
|
+
states.set(item.id, {
|
|
71669
|
+
etag: item._etag,
|
|
71670
|
+
v: item.row?._v,
|
|
71671
|
+
expireAt: item.expireAt ?? null,
|
|
71672
|
+
row: projection === "" ? void 0 : item.row
|
|
71673
|
+
});
|
|
71674
|
+
}
|
|
71675
|
+
continue;
|
|
71676
|
+
}
|
|
71677
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
71678
|
+
const { resources } = await (await container()).items.query(`SELECT c.id, c._etag AS etag, c.row._v AS v, c.expireAt${projection} FROM c WHERE c.id IN (${idList(group.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
71679
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
71680
|
+
etag,
|
|
71681
|
+
v,
|
|
71682
|
+
expireAt: expireAt ?? null,
|
|
71683
|
+
row
|
|
71684
|
+
});
|
|
71685
|
+
}
|
|
71625
71686
|
}
|
|
71626
71687
|
return states;
|
|
71627
71688
|
};
|
|
@@ -71746,6 +71807,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
71746
71807
|
async get(keys) {
|
|
71747
71808
|
const found = /* @__PURE__ */ new Map();
|
|
71748
71809
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
71810
|
+
if (ids.length <= POINT_READS) {
|
|
71811
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
71812
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
71813
|
+
}
|
|
71749
71814
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
71750
71815
|
const { resources } = await (await container()).items.query(`SELECT c.id, c.row FROM c WHERE c.id IN (${idList(ids.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
71751
71816
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
package/dist/index.cjs
CHANGED
|
@@ -300,6 +300,14 @@ const statusOf$1 = (error) => {
|
|
|
300
300
|
if (typeof status === "number") return status;
|
|
301
301
|
}
|
|
302
302
|
};
|
|
303
|
+
/**
|
|
304
|
+
* The most items read by point reads rather than one query. On Strong
|
|
305
|
+
* consistency a point read of a ~600 B item costs 2 RU and a query of 1, 3,
|
|
306
|
+
* or 10 ids 5.9, 6.4, and 8.3 RU (Azure Cosmos DB, 2026-11-14). A point
|
|
307
|
+
* read's charge grows faster with the item's size: it costs more than the
|
|
308
|
+
* query from about 50 KB, where rows such as release catalogs hold 1–2 KB.
|
|
309
|
+
*/
|
|
310
|
+
const POINT_READS = 2;
|
|
303
311
|
/** A missing database or container reads as a missing schema, like SQL's 42P01. */
|
|
304
312
|
const missingContainer = (error) => {
|
|
305
313
|
throw statusOf$1(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
@@ -406,19 +414,44 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
406
414
|
});
|
|
407
415
|
const container = async () => (await open()).container;
|
|
408
416
|
/**
|
|
417
|
+
* The item `id` names, or undefined when it is missing. A missing item
|
|
418
|
+
* answers 404 from its partition; a missing container or database answers
|
|
419
|
+
* 404 with a substatus and no partition, and reads as a missing schema.
|
|
420
|
+
*/
|
|
421
|
+
const pointRead = async (id) => {
|
|
422
|
+
const response = await (await container()).item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
423
|
+
if (response.statusCode !== 404) return response.resource;
|
|
424
|
+
const headers = response.headers;
|
|
425
|
+
if (headers["x-ms-documentdb-partitionkeyrangeid"] === void 0 && headers["x-ms-substatus"] !== void 0) missingContainer(Object.assign(/* @__PURE__ */ new Error(`Cosmos DB container ${containerId} is missing.`), { code: 404 }));
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
409
428
|
* The state of the items `ids` names, by id, with the rows of `rowIds`;
|
|
410
429
|
* a missing item has none.
|
|
411
430
|
*/
|
|
412
431
|
const readStates = async (ids, rowIds) => {
|
|
413
432
|
const states = /* @__PURE__ */ new Map();
|
|
414
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
433
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
434
|
+
if (group.length <= POINT_READS) {
|
|
435
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
436
|
+
if (item === void 0) continue;
|
|
437
|
+
states.set(item.id, {
|
|
438
|
+
etag: item._etag,
|
|
439
|
+
v: item.row?._v,
|
|
440
|
+
expireAt: item.expireAt ?? null,
|
|
441
|
+
row: projection === "" ? void 0 : item.row
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
447
|
+
const { resources } = await (await container()).items.query(`SELECT c.id, c._etag AS etag, c.row._v AS v, c.expireAt${projection} FROM c WHERE c.id IN (${idList(group.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
448
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
449
|
+
etag,
|
|
450
|
+
v,
|
|
451
|
+
expireAt: expireAt ?? null,
|
|
452
|
+
row
|
|
453
|
+
});
|
|
454
|
+
}
|
|
422
455
|
}
|
|
423
456
|
return states;
|
|
424
457
|
};
|
|
@@ -549,6 +582,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
549
582
|
async get(keys) {
|
|
550
583
|
const found = /* @__PURE__ */ new Map();
|
|
551
584
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
585
|
+
if (ids.length <= POINT_READS) {
|
|
586
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
587
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
588
|
+
}
|
|
552
589
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
553
590
|
const { resources } = await (await container()).items.query(`SELECT c.id, c.row FROM c WHERE c.id IN (${idList(ids.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
554
591
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
package/dist/index.mjs
CHANGED
|
@@ -299,6 +299,14 @@ const statusOf$1 = (error) => {
|
|
|
299
299
|
if (typeof status === "number") return status;
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
|
+
/**
|
|
303
|
+
* The most items read by point reads rather than one query. On Strong
|
|
304
|
+
* consistency a point read of a ~600 B item costs 2 RU and a query of 1, 3,
|
|
305
|
+
* or 10 ids 5.9, 6.4, and 8.3 RU (Azure Cosmos DB, 2026-11-14). A point
|
|
306
|
+
* read's charge grows faster with the item's size: it costs more than the
|
|
307
|
+
* query from about 50 KB, where rows such as release catalogs hold 1–2 KB.
|
|
308
|
+
*/
|
|
309
|
+
const POINT_READS = 2;
|
|
302
310
|
/** A missing database or container reads as a missing schema, like SQL's 42P01. */
|
|
303
311
|
const missingContainer = (error) => {
|
|
304
312
|
throw statusOf$1(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
@@ -405,19 +413,44 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
405
413
|
});
|
|
406
414
|
const container = async () => (await open()).container;
|
|
407
415
|
/**
|
|
416
|
+
* The item `id` names, or undefined when it is missing. A missing item
|
|
417
|
+
* answers 404 from its partition; a missing container or database answers
|
|
418
|
+
* 404 with a substatus and no partition, and reads as a missing schema.
|
|
419
|
+
*/
|
|
420
|
+
const pointRead = async (id) => {
|
|
421
|
+
const response = await (await container()).item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
422
|
+
if (response.statusCode !== 404) return response.resource;
|
|
423
|
+
const headers = response.headers;
|
|
424
|
+
if (headers["x-ms-documentdb-partitionkeyrangeid"] === void 0 && headers["x-ms-substatus"] !== void 0) missingContainer(Object.assign(/* @__PURE__ */ new Error(`Cosmos DB container ${containerId} is missing.`), { code: 404 }));
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
408
427
|
* The state of the items `ids` names, by id, with the rows of `rowIds`;
|
|
409
428
|
* a missing item has none.
|
|
410
429
|
*/
|
|
411
430
|
const readStates = async (ids, rowIds) => {
|
|
412
431
|
const states = /* @__PURE__ */ new Map();
|
|
413
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
432
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
433
|
+
if (group.length <= POINT_READS) {
|
|
434
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
435
|
+
if (item === void 0) continue;
|
|
436
|
+
states.set(item.id, {
|
|
437
|
+
etag: item._etag,
|
|
438
|
+
v: item.row?._v,
|
|
439
|
+
expireAt: item.expireAt ?? null,
|
|
440
|
+
row: projection === "" ? void 0 : item.row
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
446
|
+
const { resources } = await (await container()).items.query(`SELECT c.id, c._etag AS etag, c.row._v AS v, c.expireAt${projection} FROM c WHERE c.id IN (${idList(group.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
447
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
448
|
+
etag,
|
|
449
|
+
v,
|
|
450
|
+
expireAt: expireAt ?? null,
|
|
451
|
+
row
|
|
452
|
+
});
|
|
453
|
+
}
|
|
421
454
|
}
|
|
422
455
|
return states;
|
|
423
456
|
};
|
|
@@ -548,6 +581,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
548
581
|
async get(keys) {
|
|
549
582
|
const found = /* @__PURE__ */ new Map();
|
|
550
583
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
584
|
+
if (ids.length <= POINT_READS) {
|
|
585
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
586
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
587
|
+
}
|
|
551
588
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
552
589
|
const { resources } = await (await container()).items.query(`SELECT c.id, c.row FROM c WHERE c.id IN (${idList(ids.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
553
590
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
package/dist/init/index.cjs
CHANGED
|
@@ -173,6 +173,14 @@ const statusOf = (error) => {
|
|
|
173
173
|
if (typeof status === "number") return status;
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
|
+
/**
|
|
177
|
+
* The most items read by point reads rather than one query. On Strong
|
|
178
|
+
* consistency a point read of a ~600 B item costs 2 RU and a query of 1, 3,
|
|
179
|
+
* or 10 ids 5.9, 6.4, and 8.3 RU (Azure Cosmos DB, 2026-11-14). A point
|
|
180
|
+
* read's charge grows faster with the item's size: it costs more than the
|
|
181
|
+
* query from about 50 KB, where rows such as release catalogs hold 1–2 KB.
|
|
182
|
+
*/
|
|
183
|
+
const POINT_READS = 2;
|
|
176
184
|
/** A missing database or container reads as a missing schema, like SQL's 42P01. */
|
|
177
185
|
const missingContainer = (error) => {
|
|
178
186
|
throw statusOf(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
@@ -279,19 +287,44 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
279
287
|
});
|
|
280
288
|
const container = async () => (await open()).container;
|
|
281
289
|
/**
|
|
290
|
+
* The item `id` names, or undefined when it is missing. A missing item
|
|
291
|
+
* answers 404 from its partition; a missing container or database answers
|
|
292
|
+
* 404 with a substatus and no partition, and reads as a missing schema.
|
|
293
|
+
*/
|
|
294
|
+
const pointRead = async (id) => {
|
|
295
|
+
const response = await (await container()).item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
296
|
+
if (response.statusCode !== 404) return response.resource;
|
|
297
|
+
const headers = response.headers;
|
|
298
|
+
if (headers["x-ms-documentdb-partitionkeyrangeid"] === void 0 && headers["x-ms-substatus"] !== void 0) missingContainer(Object.assign(/* @__PURE__ */ new Error(`Cosmos DB container ${containerId} is missing.`), { code: 404 }));
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
282
301
|
* The state of the items `ids` names, by id, with the rows of `rowIds`;
|
|
283
302
|
* a missing item has none.
|
|
284
303
|
*/
|
|
285
304
|
const readStates = async (ids, rowIds) => {
|
|
286
305
|
const states = /* @__PURE__ */ new Map();
|
|
287
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
306
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
307
|
+
if (group.length <= POINT_READS) {
|
|
308
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
309
|
+
if (item === void 0) continue;
|
|
310
|
+
states.set(item.id, {
|
|
311
|
+
etag: item._etag,
|
|
312
|
+
v: item.row?._v,
|
|
313
|
+
expireAt: item.expireAt ?? null,
|
|
314
|
+
row: projection === "" ? void 0 : item.row
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
320
|
+
const { resources } = await (await container()).items.query(`SELECT c.id, c._etag AS etag, c.row._v AS v, c.expireAt${projection} FROM c WHERE c.id IN (${idList(group.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
321
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
322
|
+
etag,
|
|
323
|
+
v,
|
|
324
|
+
expireAt: expireAt ?? null,
|
|
325
|
+
row
|
|
326
|
+
});
|
|
327
|
+
}
|
|
295
328
|
}
|
|
296
329
|
return states;
|
|
297
330
|
};
|
|
@@ -422,6 +455,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
422
455
|
async get(keys) {
|
|
423
456
|
const found = /* @__PURE__ */ new Map();
|
|
424
457
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
458
|
+
if (ids.length <= POINT_READS) {
|
|
459
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
460
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
461
|
+
}
|
|
425
462
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
426
463
|
const { resources } = await (await container()).items.query(`SELECT c.id, c.row FROM c WHERE c.id IN (${idList(ids.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
427
464
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
package/dist/init/index.mjs
CHANGED
|
@@ -168,6 +168,14 @@ const statusOf = (error) => {
|
|
|
168
168
|
if (typeof status === "number") return status;
|
|
169
169
|
}
|
|
170
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* The most items read by point reads rather than one query. On Strong
|
|
173
|
+
* consistency a point read of a ~600 B item costs 2 RU and a query of 1, 3,
|
|
174
|
+
* or 10 ids 5.9, 6.4, and 8.3 RU (Azure Cosmos DB, 2026-11-14). A point
|
|
175
|
+
* read's charge grows faster with the item's size: it costs more than the
|
|
176
|
+
* query from about 50 KB, where rows such as release catalogs hold 1–2 KB.
|
|
177
|
+
*/
|
|
178
|
+
const POINT_READS = 2;
|
|
171
179
|
/** A missing database or container reads as a missing schema, like SQL's 42P01. */
|
|
172
180
|
const missingContainer = (error) => {
|
|
173
181
|
throw statusOf(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
@@ -274,19 +282,44 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
274
282
|
});
|
|
275
283
|
const container = async () => (await open()).container;
|
|
276
284
|
/**
|
|
285
|
+
* The item `id` names, or undefined when it is missing. A missing item
|
|
286
|
+
* answers 404 from its partition; a missing container or database answers
|
|
287
|
+
* 404 with a substatus and no partition, and reads as a missing schema.
|
|
288
|
+
*/
|
|
289
|
+
const pointRead = async (id) => {
|
|
290
|
+
const response = await (await container()).item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
291
|
+
if (response.statusCode !== 404) return response.resource;
|
|
292
|
+
const headers = response.headers;
|
|
293
|
+
if (headers["x-ms-documentdb-partitionkeyrangeid"] === void 0 && headers["x-ms-substatus"] !== void 0) missingContainer(Object.assign(/* @__PURE__ */ new Error(`Cosmos DB container ${containerId} is missing.`), { code: 404 }));
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
277
296
|
* The state of the items `ids` names, by id, with the rows of `rowIds`;
|
|
278
297
|
* a missing item has none.
|
|
279
298
|
*/
|
|
280
299
|
const readStates = async (ids, rowIds) => {
|
|
281
300
|
const states = /* @__PURE__ */ new Map();
|
|
282
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
301
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
302
|
+
if (group.length <= POINT_READS) {
|
|
303
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
304
|
+
if (item === void 0) continue;
|
|
305
|
+
states.set(item.id, {
|
|
306
|
+
etag: item._etag,
|
|
307
|
+
v: item.row?._v,
|
|
308
|
+
expireAt: item.expireAt ?? null,
|
|
309
|
+
row: projection === "" ? void 0 : item.row
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
315
|
+
const { resources } = await (await container()).items.query(`SELECT c.id, c._etag AS etag, c.row._v AS v, c.expireAt${projection} FROM c WHERE c.id IN (${idList(group.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
316
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
317
|
+
etag,
|
|
318
|
+
v,
|
|
319
|
+
expireAt: expireAt ?? null,
|
|
320
|
+
row
|
|
321
|
+
});
|
|
322
|
+
}
|
|
290
323
|
}
|
|
291
324
|
return states;
|
|
292
325
|
};
|
|
@@ -417,6 +450,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
417
450
|
async get(keys) {
|
|
418
451
|
const found = /* @__PURE__ */ new Map();
|
|
419
452
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
453
|
+
if (ids.length <= POINT_READS) {
|
|
454
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
455
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
456
|
+
}
|
|
420
457
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
421
458
|
const { resources } = await (await container()).items.query(`SELECT c.id, c.row FROM c WHERE c.id IN (${idList(ids.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
422
459
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/azure",
|
|
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
|
"engines": {
|
|
7
7
|
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@azure/identity": "4.14.0",
|
|
45
45
|
"@azure/keyvault-secrets": "4.11.2",
|
|
46
46
|
"@azure/storage-blob": "12.34.0",
|
|
47
|
-
"@hot-updater/cli-tools": "1.2.0-rc.
|
|
48
|
-
"@hot-updater/
|
|
49
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
50
|
-
"@hot-updater/
|
|
47
|
+
"@hot-updater/cli-tools": "1.2.0-rc.45",
|
|
48
|
+
"@hot-updater/plugin-core": "1.2.0-rc.45",
|
|
49
|
+
"@hot-updater/protocol": "1.2.0-rc.45",
|
|
50
|
+
"@hot-updater/server": "1.2.0-rc.45"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@azure/functions": "4.16.5",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"execa": "9.5.2",
|
|
56
56
|
"jszip": "^3.10.1",
|
|
57
57
|
"vitest": "4.1.4",
|
|
58
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
58
|
+
"@hot-updater/test-utils": "1.2.0-rc.45"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "tsdown",
|