@hot-updater/azure 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.
- package/dist/functions/index.mjs +83 -25
- package/dist/index.cjs +43 -8
- package/dist/index.mjs +43 -8
- package/dist/init/index.cjs +43 -8
- package/dist/init/index.mjs +43 -8
- package/package.json +6 -6
package/dist/functions/index.mjs
CHANGED
|
@@ -6196,6 +6196,7 @@ const WINDOW_MS$1 = {
|
|
|
6196
6196
|
memory: 15e3
|
|
6197
6197
|
};
|
|
6198
6198
|
const LOG_PAGE = 200;
|
|
6199
|
+
const SKIP_AFTER_MS = 3e5;
|
|
6199
6200
|
const GROUPS = {
|
|
6200
6201
|
commit: 1,
|
|
6201
6202
|
read: 8,
|
|
@@ -6303,19 +6304,32 @@ const rewrite = (change, key, current) => {
|
|
|
6303
6304
|
previous: current
|
|
6304
6305
|
};
|
|
6305
6306
|
};
|
|
6306
|
-
const
|
|
6307
|
-
|
|
6307
|
+
const rowId = (model, key) => JSON.stringify([model.table.name, key]);
|
|
6308
|
+
const keysOf = (changes, shard) => changes.map(({ model, key }) => [...key.slice(0, -1), shard(model)]);
|
|
6309
|
+
const readCurrent = async (adapter, changes, shard) => {
|
|
6310
|
+
const keys = keysOf(changes, shard);
|
|
6308
6311
|
const reads = /* @__PURE__ */ new Map();
|
|
6309
6312
|
changes.forEach((change, at) => {
|
|
6310
|
-
if (rewrites(change))
|
|
6313
|
+
if (!rewrites(change)) return;
|
|
6314
|
+
const wanted = reads.get(change.model) ?? /* @__PURE__ */ new Map();
|
|
6315
|
+
wanted.set(rowId(change.model, keys[at]), keys[at]);
|
|
6316
|
+
reads.set(change.model, wanted);
|
|
6311
6317
|
});
|
|
6312
6318
|
const current = /* @__PURE__ */ new Map();
|
|
6313
|
-
await Promise.all([...reads].map(async ([model,
|
|
6314
|
-
const
|
|
6315
|
-
|
|
6319
|
+
await Promise.all([...reads].map(async ([model, wanted]) => {
|
|
6320
|
+
const keys = [...wanted.values()];
|
|
6321
|
+
const rows = await adapter.get(model.table, keys);
|
|
6322
|
+
keys.forEach((key, at) => {
|
|
6323
|
+
current.set(rowId(model, key), rows[at] ?? null);
|
|
6324
|
+
});
|
|
6316
6325
|
}));
|
|
6317
|
-
return
|
|
6326
|
+
return current;
|
|
6327
|
+
};
|
|
6328
|
+
const build = (changes, shard, current) => {
|
|
6329
|
+
const keys = keysOf(changes, shard);
|
|
6330
|
+
return changes.map((change, at) => rewrites(change) ? rewrite(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
|
|
6318
6331
|
};
|
|
6332
|
+
const compile = async (adapter, changes, shard) => build(changes, shard, await readCurrent(adapter, changes, shard));
|
|
6319
6333
|
const isOp = (op) => op !== void 0;
|
|
6320
6334
|
const sleep$1 = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
|
|
6321
6335
|
const pack = (text) => {
|
|
@@ -6435,6 +6449,9 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
6435
6449
|
let nextDue = 0;
|
|
6436
6450
|
let compacting;
|
|
6437
6451
|
const known = /* @__PURE__ */ new Map();
|
|
6452
|
+
const skipped = LOG_TABLES.map(() => void 0);
|
|
6453
|
+
const past = (shard) => skipped[shard] === void 0 ? {} : { range: { gt: skipped[shard] } };
|
|
6454
|
+
const stampOf = (id) => Number.parseInt(id.slice(0, 9), 36);
|
|
6438
6455
|
const idOf = (shard, id) => JSON.stringify([shard, id]);
|
|
6439
6456
|
const leaseOp = (held, set) => {
|
|
6440
6457
|
const next = {
|
|
@@ -6538,14 +6555,22 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
6538
6555
|
logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
|
|
6539
6556
|
const page = await engine.reads.findMany(name, {
|
|
6540
6557
|
index: "oldest",
|
|
6541
|
-
limit: LOG_PAGE
|
|
6558
|
+
limit: LOG_PAGE,
|
|
6559
|
+
...past(shard)
|
|
6542
6560
|
});
|
|
6543
6561
|
more ||= page.next !== void 0;
|
|
6544
|
-
|
|
6562
|
+
const decoded = await Promise.all(page.rows.map(async (row) => ({
|
|
6545
6563
|
shard,
|
|
6546
6564
|
row,
|
|
6547
6565
|
changes: await decode(String(row.changes))
|
|
6548
|
-
})))
|
|
6566
|
+
})));
|
|
6567
|
+
const settled = now() - SKIP_AFTER_MS;
|
|
6568
|
+
for (const { row, changes } of decoded) {
|
|
6569
|
+
const id = String(row.id);
|
|
6570
|
+
if (changes !== void 0 || stampOf(id) >= settled) break;
|
|
6571
|
+
skipped[shard] = id;
|
|
6572
|
+
}
|
|
6573
|
+
return decoded.flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
|
|
6549
6574
|
...entry,
|
|
6550
6575
|
changes
|
|
6551
6576
|
}]);
|
|
@@ -6553,14 +6578,15 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
6553
6578
|
more
|
|
6554
6579
|
};
|
|
6555
6580
|
};
|
|
6556
|
-
const rowsFor = async (changes) => (await compile(adapter, changes, () => 0)).filter(isOp);
|
|
6557
6581
|
const applyGroup = async (held, logs) => {
|
|
6582
|
+
const current = await readCurrent(adapter, logs.flatMap((entry) => [...entry.changes.values()]), () => 0);
|
|
6583
|
+
const rowsFor = (changes) => build(changes, () => 0, current).filter(isOp);
|
|
6558
6584
|
for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
|
|
6559
6585
|
const batch = logs.slice(0, count);
|
|
6560
6586
|
const changes = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
|
|
6561
6587
|
const applied = batch.map(({ shard, row }) => [shard, row.id]);
|
|
6562
6588
|
const lease = leaseOp(held, { applied: JSON.stringify(applied) });
|
|
6563
|
-
const ops = [...
|
|
6589
|
+
const ops = [...rowsFor([...changes.values()]), lease.op];
|
|
6564
6590
|
if (!adapter.fits(ops)) continue;
|
|
6565
6591
|
for (const { shard, row } of batch) known.set(idOf(shard, row.id), row);
|
|
6566
6592
|
return await commit(ops) ? {
|
|
@@ -6582,7 +6608,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
6582
6608
|
};
|
|
6583
6609
|
const lease = leaseOp(held, {});
|
|
6584
6610
|
const ops = [
|
|
6585
|
-
...
|
|
6611
|
+
...rowsFor(entries.slice(0, take)),
|
|
6586
6612
|
kept,
|
|
6587
6613
|
lease.op
|
|
6588
6614
|
];
|
|
@@ -6598,11 +6624,12 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
6598
6624
|
if (held === void 0) return;
|
|
6599
6625
|
let pending = true;
|
|
6600
6626
|
let clear = false;
|
|
6627
|
+
let carried;
|
|
6601
6628
|
try {
|
|
6602
6629
|
for (let group = 0;; group += 1) {
|
|
6603
6630
|
clear = await deleteApplied(held);
|
|
6604
6631
|
if (!clear || !pending || group === groups) break;
|
|
6605
|
-
const { logs, more } = await readLogs();
|
|
6632
|
+
const { logs, more } = carried ?? await readLogs();
|
|
6606
6633
|
if (logs.length === 0) {
|
|
6607
6634
|
pending = false;
|
|
6608
6635
|
break;
|
|
@@ -6610,6 +6637,11 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
6610
6637
|
const applied = await applyGroup(held, logs);
|
|
6611
6638
|
if (applied === void 0) break;
|
|
6612
6639
|
[held, clear] = [applied.held, false];
|
|
6640
|
+
const rest = applied.count === 0 ? [] : logs.slice(applied.count);
|
|
6641
|
+
carried = rest.length > 0 ? {
|
|
6642
|
+
logs: rest,
|
|
6643
|
+
more
|
|
6644
|
+
} : void 0;
|
|
6613
6645
|
pending = more || applied.count < logs.length;
|
|
6614
6646
|
}
|
|
6615
6647
|
} finally {
|
|
@@ -6627,9 +6659,10 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
6627
6659
|
compacting = void 0;
|
|
6628
6660
|
});
|
|
6629
6661
|
let checking;
|
|
6630
|
-
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name) => engine.reads.findMany(name, {
|
|
6662
|
+
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name, shard) => engine.reads.findMany(name, {
|
|
6631
6663
|
index: "oldest",
|
|
6632
|
-
limit: 1
|
|
6664
|
+
limit: 1,
|
|
6665
|
+
...past(shard)
|
|
6633
6666
|
}))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
|
|
6634
6667
|
checking = void 0;
|
|
6635
6668
|
});
|
|
@@ -7998,7 +8031,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
7998
8031
|
};
|
|
7999
8032
|
//#endregion
|
|
8000
8033
|
//#region ../../packages/server/dist/version.mjs
|
|
8001
|
-
const HOT_UPDATER_SERVER_VERSION = "1.1.
|
|
8034
|
+
const HOT_UPDATER_SERVER_VERSION = "1.1.16";
|
|
8002
8035
|
//#endregion
|
|
8003
8036
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
8004
8037
|
const createVersionRouteHandlers = (plugins = []) => {
|
|
@@ -70348,6 +70381,7 @@ const statusOf = (error) => {
|
|
|
70348
70381
|
if (typeof status === "number") return status;
|
|
70349
70382
|
}
|
|
70350
70383
|
};
|
|
70384
|
+
const POINT_READS = 2;
|
|
70351
70385
|
const missingContainer = (error) => {
|
|
70352
70386
|
throw statusOf(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
70353
70387
|
};
|
|
@@ -70399,16 +70433,36 @@ const isWideAdd = (op) => op.type === "add" && Object.keys(op.by).length + (op.e
|
|
|
70399
70433
|
const emulatorAborted = (error) => statusOf(error) === 500 && /PostgresError\(SqlState\(E(25P02|40001|40P01)\)/.test(String(error instanceof Error ? error.message : error));
|
|
70400
70434
|
const createCosmosStore = ({ client, databaseId, containerId, engine, nativePageSize }) => {
|
|
70401
70435
|
const container = client.database(databaseId).container(containerId);
|
|
70436
|
+
const pointRead = async (id) => {
|
|
70437
|
+
const response = await container.item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
70438
|
+
if (response.statusCode !== 404) return response.resource;
|
|
70439
|
+
const headers = response.headers;
|
|
70440
|
+
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 }));
|
|
70441
|
+
};
|
|
70402
70442
|
const readStates = async (ids, rowIds) => {
|
|
70403
70443
|
const states = /* @__PURE__ */ new Map();
|
|
70404
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
70405
|
-
|
|
70406
|
-
|
|
70407
|
-
|
|
70408
|
-
|
|
70409
|
-
|
|
70410
|
-
|
|
70411
|
-
|
|
70444
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
70445
|
+
if (group.length <= POINT_READS) {
|
|
70446
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
70447
|
+
if (item === void 0) continue;
|
|
70448
|
+
states.set(item.id, {
|
|
70449
|
+
etag: item._etag,
|
|
70450
|
+
v: item.row?._v,
|
|
70451
|
+
expireAt: item.expireAt ?? null,
|
|
70452
|
+
row: projection === "" ? void 0 : item.row
|
|
70453
|
+
});
|
|
70454
|
+
}
|
|
70455
|
+
continue;
|
|
70456
|
+
}
|
|
70457
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
70458
|
+
const { resources } = 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);
|
|
70459
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
70460
|
+
etag,
|
|
70461
|
+
v,
|
|
70462
|
+
expireAt: expireAt ?? null,
|
|
70463
|
+
row
|
|
70464
|
+
});
|
|
70465
|
+
}
|
|
70412
70466
|
}
|
|
70413
70467
|
return states;
|
|
70414
70468
|
};
|
|
@@ -70533,6 +70587,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
70533
70587
|
async get(keys) {
|
|
70534
70588
|
const found = /* @__PURE__ */ new Map();
|
|
70535
70589
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
70590
|
+
if (ids.length <= POINT_READS) {
|
|
70591
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
70592
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
70593
|
+
}
|
|
70536
70594
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
70537
70595
|
const { resources } = 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);
|
|
70538
70596
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
package/dist/index.cjs
CHANGED
|
@@ -271,6 +271,12 @@ const statusOf = (error) => {
|
|
|
271
271
|
if (typeof status === "number") return status;
|
|
272
272
|
}
|
|
273
273
|
};
|
|
274
|
+
/**
|
|
275
|
+
* The most items read by point reads rather than one query. On Strong
|
|
276
|
+
* consistency a point read costs 2 RU and a query of 1, 3, or 10 ids 5.9,
|
|
277
|
+
* 6.4, and 8.3 RU (Azure Cosmos DB, 2026-11-14).
|
|
278
|
+
*/
|
|
279
|
+
const POINT_READS = 2;
|
|
274
280
|
/** A missing database or container reads as a missing schema, like SQL's 42P01. */
|
|
275
281
|
const missingContainer = (error) => {
|
|
276
282
|
throw statusOf(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
@@ -366,19 +372,44 @@ const emulatorAborted = (error) => statusOf(error) === 500 && /PostgresError\(Sq
|
|
|
366
372
|
const createCosmosStore = ({ client, databaseId, containerId, engine, nativePageSize }) => {
|
|
367
373
|
const container = client.database(databaseId).container(containerId);
|
|
368
374
|
/**
|
|
375
|
+
* The item `id` names, or undefined when it is missing. A missing item
|
|
376
|
+
* answers 404 from its partition; a missing container or database answers
|
|
377
|
+
* 404 with a substatus and no partition, and reads as a missing schema.
|
|
378
|
+
*/
|
|
379
|
+
const pointRead = async (id) => {
|
|
380
|
+
const response = await container.item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
381
|
+
if (response.statusCode !== 404) return response.resource;
|
|
382
|
+
const headers = response.headers;
|
|
383
|
+
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 }));
|
|
384
|
+
};
|
|
385
|
+
/**
|
|
369
386
|
* The state of the items `ids` names, by id, with the rows of `rowIds`;
|
|
370
387
|
* a missing item has none.
|
|
371
388
|
*/
|
|
372
389
|
const readStates = async (ids, rowIds) => {
|
|
373
390
|
const states = /* @__PURE__ */ new Map();
|
|
374
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
391
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
392
|
+
if (group.length <= POINT_READS) {
|
|
393
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
394
|
+
if (item === void 0) continue;
|
|
395
|
+
states.set(item.id, {
|
|
396
|
+
etag: item._etag,
|
|
397
|
+
v: item.row?._v,
|
|
398
|
+
expireAt: item.expireAt ?? null,
|
|
399
|
+
row: projection === "" ? void 0 : item.row
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
405
|
+
const { resources } = 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);
|
|
406
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
407
|
+
etag,
|
|
408
|
+
v,
|
|
409
|
+
expireAt: expireAt ?? null,
|
|
410
|
+
row
|
|
411
|
+
});
|
|
412
|
+
}
|
|
382
413
|
}
|
|
383
414
|
return states;
|
|
384
415
|
};
|
|
@@ -509,6 +540,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
509
540
|
async get(keys) {
|
|
510
541
|
const found = /* @__PURE__ */ new Map();
|
|
511
542
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
543
|
+
if (ids.length <= POINT_READS) {
|
|
544
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
545
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
546
|
+
}
|
|
512
547
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
513
548
|
const { resources } = 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);
|
|
514
549
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
package/dist/index.mjs
CHANGED
|
@@ -270,6 +270,12 @@ const statusOf = (error) => {
|
|
|
270
270
|
if (typeof status === "number") return status;
|
|
271
271
|
}
|
|
272
272
|
};
|
|
273
|
+
/**
|
|
274
|
+
* The most items read by point reads rather than one query. On Strong
|
|
275
|
+
* consistency a point read costs 2 RU and a query of 1, 3, or 10 ids 5.9,
|
|
276
|
+
* 6.4, and 8.3 RU (Azure Cosmos DB, 2026-11-14).
|
|
277
|
+
*/
|
|
278
|
+
const POINT_READS = 2;
|
|
273
279
|
/** A missing database or container reads as a missing schema, like SQL's 42P01. */
|
|
274
280
|
const missingContainer = (error) => {
|
|
275
281
|
throw statusOf(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
@@ -365,19 +371,44 @@ const emulatorAborted = (error) => statusOf(error) === 500 && /PostgresError\(Sq
|
|
|
365
371
|
const createCosmosStore = ({ client, databaseId, containerId, engine, nativePageSize }) => {
|
|
366
372
|
const container = client.database(databaseId).container(containerId);
|
|
367
373
|
/**
|
|
374
|
+
* The item `id` names, or undefined when it is missing. A missing item
|
|
375
|
+
* answers 404 from its partition; a missing container or database answers
|
|
376
|
+
* 404 with a substatus and no partition, and reads as a missing schema.
|
|
377
|
+
*/
|
|
378
|
+
const pointRead = async (id) => {
|
|
379
|
+
const response = await container.item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
380
|
+
if (response.statusCode !== 404) return response.resource;
|
|
381
|
+
const headers = response.headers;
|
|
382
|
+
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 }));
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
368
385
|
* The state of the items `ids` names, by id, with the rows of `rowIds`;
|
|
369
386
|
* a missing item has none.
|
|
370
387
|
*/
|
|
371
388
|
const readStates = async (ids, rowIds) => {
|
|
372
389
|
const states = /* @__PURE__ */ new Map();
|
|
373
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
390
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
391
|
+
if (group.length <= POINT_READS) {
|
|
392
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
393
|
+
if (item === void 0) continue;
|
|
394
|
+
states.set(item.id, {
|
|
395
|
+
etag: item._etag,
|
|
396
|
+
v: item.row?._v,
|
|
397
|
+
expireAt: item.expireAt ?? null,
|
|
398
|
+
row: projection === "" ? void 0 : item.row
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
404
|
+
const { resources } = 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);
|
|
405
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
406
|
+
etag,
|
|
407
|
+
v,
|
|
408
|
+
expireAt: expireAt ?? null,
|
|
409
|
+
row
|
|
410
|
+
});
|
|
411
|
+
}
|
|
381
412
|
}
|
|
382
413
|
return states;
|
|
383
414
|
};
|
|
@@ -508,6 +539,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
508
539
|
async get(keys) {
|
|
509
540
|
const found = /* @__PURE__ */ new Map();
|
|
510
541
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
542
|
+
if (ids.length <= POINT_READS) {
|
|
543
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
544
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
545
|
+
}
|
|
511
546
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
512
547
|
const { resources } = 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);
|
|
513
548
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
package/dist/init/index.cjs
CHANGED
|
@@ -173,6 +173,12 @@ 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 costs 2 RU and a query of 1, 3, or 10 ids 5.9,
|
|
179
|
+
* 6.4, and 8.3 RU (Azure Cosmos DB, 2026-11-14).
|
|
180
|
+
*/
|
|
181
|
+
const POINT_READS = 2;
|
|
176
182
|
/** A missing database or container reads as a missing schema, like SQL's 42P01. */
|
|
177
183
|
const missingContainer = (error) => {
|
|
178
184
|
throw statusOf(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
@@ -268,19 +274,44 @@ const emulatorAborted = (error) => statusOf(error) === 500 && /PostgresError\(Sq
|
|
|
268
274
|
const createCosmosStore = ({ client, databaseId, containerId, engine, nativePageSize }) => {
|
|
269
275
|
const container = client.database(databaseId).container(containerId);
|
|
270
276
|
/**
|
|
277
|
+
* The item `id` names, or undefined when it is missing. A missing item
|
|
278
|
+
* answers 404 from its partition; a missing container or database answers
|
|
279
|
+
* 404 with a substatus and no partition, and reads as a missing schema.
|
|
280
|
+
*/
|
|
281
|
+
const pointRead = async (id) => {
|
|
282
|
+
const response = await container.item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
283
|
+
if (response.statusCode !== 404) return response.resource;
|
|
284
|
+
const headers = response.headers;
|
|
285
|
+
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 }));
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
271
288
|
* The state of the items `ids` names, by id, with the rows of `rowIds`;
|
|
272
289
|
* a missing item has none.
|
|
273
290
|
*/
|
|
274
291
|
const readStates = async (ids, rowIds) => {
|
|
275
292
|
const states = /* @__PURE__ */ new Map();
|
|
276
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
293
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
294
|
+
if (group.length <= POINT_READS) {
|
|
295
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
296
|
+
if (item === void 0) continue;
|
|
297
|
+
states.set(item.id, {
|
|
298
|
+
etag: item._etag,
|
|
299
|
+
v: item.row?._v,
|
|
300
|
+
expireAt: item.expireAt ?? null,
|
|
301
|
+
row: projection === "" ? void 0 : item.row
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
307
|
+
const { resources } = 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);
|
|
308
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
309
|
+
etag,
|
|
310
|
+
v,
|
|
311
|
+
expireAt: expireAt ?? null,
|
|
312
|
+
row
|
|
313
|
+
});
|
|
314
|
+
}
|
|
284
315
|
}
|
|
285
316
|
return states;
|
|
286
317
|
};
|
|
@@ -411,6 +442,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
411
442
|
async get(keys) {
|
|
412
443
|
const found = /* @__PURE__ */ new Map();
|
|
413
444
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
445
|
+
if (ids.length <= POINT_READS) {
|
|
446
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
447
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
448
|
+
}
|
|
414
449
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
415
450
|
const { resources } = 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);
|
|
416
451
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
package/dist/init/index.mjs
CHANGED
|
@@ -168,6 +168,12 @@ 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 costs 2 RU and a query of 1, 3, or 10 ids 5.9,
|
|
174
|
+
* 6.4, and 8.3 RU (Azure Cosmos DB, 2026-11-14).
|
|
175
|
+
*/
|
|
176
|
+
const POINT_READS = 2;
|
|
171
177
|
/** A missing database or container reads as a missing schema, like SQL's 42P01. */
|
|
172
178
|
const missingContainer = (error) => {
|
|
173
179
|
throw statusOf(error) === 404 ? Object.assign(new Error(error.message, { cause: error }), { code: "42P01" }) : error;
|
|
@@ -263,19 +269,44 @@ const emulatorAborted = (error) => statusOf(error) === 500 && /PostgresError\(Sq
|
|
|
263
269
|
const createCosmosStore = ({ client, databaseId, containerId, engine, nativePageSize }) => {
|
|
264
270
|
const container = client.database(databaseId).container(containerId);
|
|
265
271
|
/**
|
|
272
|
+
* The item `id` names, or undefined when it is missing. A missing item
|
|
273
|
+
* answers 404 from its partition; a missing container or database answers
|
|
274
|
+
* 404 with a substatus and no partition, and reads as a missing schema.
|
|
275
|
+
*/
|
|
276
|
+
const pointRead = async (id) => {
|
|
277
|
+
const response = await container.item(id, COSMOS_PARTITION).read().catch(missingContainer);
|
|
278
|
+
if (response.statusCode !== 404) return response.resource;
|
|
279
|
+
const headers = response.headers;
|
|
280
|
+
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 }));
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
266
283
|
* The state of the items `ids` names, by id, with the rows of `rowIds`;
|
|
267
284
|
* a missing item has none.
|
|
268
285
|
*/
|
|
269
286
|
const readStates = async (ids, rowIds) => {
|
|
270
287
|
const states = /* @__PURE__ */ new Map();
|
|
271
|
-
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]])
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
288
|
+
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) {
|
|
289
|
+
if (group.length <= POINT_READS) {
|
|
290
|
+
for (const item of await Promise.all(group.map(pointRead))) {
|
|
291
|
+
if (item === void 0) continue;
|
|
292
|
+
states.set(item.id, {
|
|
293
|
+
etag: item._etag,
|
|
294
|
+
v: item.row?._v,
|
|
295
|
+
expireAt: item.expireAt ?? null,
|
|
296
|
+
row: projection === "" ? void 0 : item.row
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
302
|
+
const { resources } = 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);
|
|
303
|
+
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
304
|
+
etag,
|
|
305
|
+
v,
|
|
306
|
+
expireAt: expireAt ?? null,
|
|
307
|
+
row
|
|
308
|
+
});
|
|
309
|
+
}
|
|
279
310
|
}
|
|
280
311
|
return states;
|
|
281
312
|
};
|
|
@@ -406,6 +437,10 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
406
437
|
async get(keys) {
|
|
407
438
|
const found = /* @__PURE__ */ new Map();
|
|
408
439
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
440
|
+
if (ids.length <= POINT_READS) {
|
|
441
|
+
for (const item of await Promise.all(ids.map(pointRead))) if (item !== void 0) found.set(item.id, toRow(item.row));
|
|
442
|
+
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
443
|
+
}
|
|
409
444
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
410
445
|
const { resources } = 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);
|
|
411
446
|
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.1.
|
|
4
|
+
"version": "1.1.16",
|
|
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"
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"@azure/core-auth": "1.11.0",
|
|
43
43
|
"@azure/cosmos": "4.10.1",
|
|
44
44
|
"@azure/storage-blob": "12.34.0",
|
|
45
|
-
"@hot-updater/cli-tools": "1.1.
|
|
46
|
-
"@hot-updater/
|
|
47
|
-
"@hot-updater/
|
|
48
|
-
"@hot-updater/
|
|
45
|
+
"@hot-updater/cli-tools": "1.1.16",
|
|
46
|
+
"@hot-updater/plugin-core": "1.1.16",
|
|
47
|
+
"@hot-updater/protocol": "1.1.16",
|
|
48
|
+
"@hot-updater/server": "1.1.16"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@azure/functions": "4.16.5",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"execa": "9.5.2",
|
|
54
54
|
"jszip": "^3.10.1",
|
|
55
55
|
"vitest": "4.1.4",
|
|
56
|
-
"@hot-updater/test-utils": "1.1.
|
|
56
|
+
"@hot-updater/test-utils": "1.1.16"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsdown",
|