@hot-updater/azure 1.2.0-rc.0 → 1.2.0-rc.10
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 +42 -27
- package/dist/index.cjs +295 -31
- package/dist/index.d.cts +63 -4
- package/dist/index.d.mts +63 -4
- package/dist/index.mjs +294 -31
- package/dist/init/index.cjs +45 -24
- package/dist/init/index.d.cts +2 -1
- package/dist/init/index.d.mts +2 -1
- package/dist/init/index.mjs +45 -24
- package/package.json +8 -6
package/dist/functions/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
+
import Stream, { Duplex, Readable, Transform } from "node:stream";
|
|
3
4
|
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from "node:crypto";
|
|
4
5
|
import process$1 from "node:process";
|
|
5
6
|
import os, { EOL } from "node:os";
|
|
@@ -7,7 +8,6 @@ import util, { inspect } from "node:util";
|
|
|
7
8
|
import http from "node:http";
|
|
8
9
|
import https from "node:https";
|
|
9
10
|
import zlib from "node:zlib";
|
|
10
|
-
import Stream, { Duplex, Readable, Transform } from "node:stream";
|
|
11
11
|
import { Readable as Readable$1 } from "stream";
|
|
12
12
|
import buffer from "node:buffer";
|
|
13
13
|
import { Buffer as Buffer$1 } from "buffer";
|
|
@@ -8118,7 +8118,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
8118
8118
|
};
|
|
8119
8119
|
//#endregion
|
|
8120
8120
|
//#region ../../packages/server/dist/version.mjs
|
|
8121
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
8121
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.10";
|
|
8122
8122
|
//#endregion
|
|
8123
8123
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
8124
8124
|
const createVersionRouteHandlers = (plugins = []) => {
|
|
@@ -57415,12 +57415,19 @@ const PROTOCOL = "azblob";
|
|
|
57415
57415
|
const SAS_EXPIRES_IN_MS = 36e5;
|
|
57416
57416
|
const DELEGATION_KEY_LIFETIME_MS = 864e5;
|
|
57417
57417
|
const isNotFound = (error) => error instanceof RestError && error.statusCode === 404;
|
|
57418
|
-
const serviceOf = (config) =>
|
|
57418
|
+
const serviceOf = async (config) => {
|
|
57419
|
+
if (!("connectionString" in config)) return new BlobServiceClient(config.accountUrl, config.credential);
|
|
57420
|
+
const { connectionString } = config;
|
|
57421
|
+
return BlobServiceClient.fromConnectionString(typeof connectionString === "function" ? await connectionString() : connectionString);
|
|
57422
|
+
};
|
|
57419
57423
|
function azureBlobStorage(config) {
|
|
57420
57424
|
const { containerName, basePath, getDownloadUrl } = config;
|
|
57421
57425
|
let client;
|
|
57422
|
-
const service = () => client ??= serviceOf(config)
|
|
57423
|
-
|
|
57426
|
+
const service = () => client ??= serviceOf(config).catch((error) => {
|
|
57427
|
+
client = void 0;
|
|
57428
|
+
throw error;
|
|
57429
|
+
});
|
|
57430
|
+
const container = async () => (await service()).getContainerClient(containerName);
|
|
57424
57431
|
const normalizedBasePath = basePath?.replace(/^\/+|\/+$/g, "") ?? "";
|
|
57425
57432
|
const getStorageKey = createStorageKeyBuilder(normalizedBasePath);
|
|
57426
57433
|
const getListPrefix = (prefix = "") => {
|
|
@@ -57451,7 +57458,7 @@ function azureBlobStorage(config) {
|
|
|
57451
57458
|
const delegationKey = () => {
|
|
57452
57459
|
const now = Date.now();
|
|
57453
57460
|
if (delegation === void 0 || delegation.renewAt <= now) {
|
|
57454
|
-
const key = service().getUserDelegationKey(/* @__PURE__ */ new Date(now - 3e5), new Date(now + DELEGATION_KEY_LIFETIME_MS));
|
|
57461
|
+
const key = service().then((blobService) => blobService.getUserDelegationKey(/* @__PURE__ */ new Date(now - 3e5), new Date(now + DELEGATION_KEY_LIFETIME_MS)));
|
|
57455
57462
|
key.catch(() => {
|
|
57456
57463
|
delegation = void 0;
|
|
57457
57464
|
});
|
|
@@ -57463,7 +57470,7 @@ function azureBlobStorage(config) {
|
|
|
57463
57470
|
return delegation.key;
|
|
57464
57471
|
};
|
|
57465
57472
|
const signedUrl = async (key) => {
|
|
57466
|
-
const blob = container().getBlobClient(key);
|
|
57473
|
+
const blob = (await container()).getBlobClient(key);
|
|
57467
57474
|
const expiresOn = new Date(Date.now() + SAS_EXPIRES_IN_MS);
|
|
57468
57475
|
const permissions = BlobSASPermissions.parse("r");
|
|
57469
57476
|
if (blob.credential instanceof StorageSharedKeyCredential) return blob.generateSasUrl({
|
|
@@ -57484,7 +57491,8 @@ function azureBlobStorage(config) {
|
|
|
57484
57491
|
protocol: PROTOCOL,
|
|
57485
57492
|
async listObjects(prefix) {
|
|
57486
57493
|
const objects = [];
|
|
57487
|
-
|
|
57494
|
+
const blobs = await container();
|
|
57495
|
+
for await (const blob of blobs.listBlobsFlat({ prefix: getListPrefix(prefix) })) {
|
|
57488
57496
|
const storageUri = getListedStorageUri(blob.name);
|
|
57489
57497
|
if (storageUri === null) continue;
|
|
57490
57498
|
objects.push({
|
|
@@ -57501,7 +57509,8 @@ function azureBlobStorage(config) {
|
|
|
57501
57509
|
for (let offset = 0; offset < keys.length; offset += 256) {
|
|
57502
57510
|
const batch = keys.slice(offset, offset + 256);
|
|
57503
57511
|
if (batch.length === 0) continue;
|
|
57504
|
-
const
|
|
57512
|
+
const blobs = await container();
|
|
57513
|
+
const failed = (await blobs.getBlobBatchClient().deleteBlobs(batch.map((key) => blobs.getBlobClient(key)))).subResponses.filter(({ status }) => status >= 300 && status !== 404);
|
|
57505
57514
|
if (failed.length > 0) throw new Error(`Failed to delete ${failed.length} Azure blob(s).`);
|
|
57506
57515
|
}
|
|
57507
57516
|
},
|
|
@@ -57511,7 +57520,7 @@ function azureBlobStorage(config) {
|
|
|
57511
57520
|
blobContentType: contentType,
|
|
57512
57521
|
blobCacheControl: "max-age=31536000"
|
|
57513
57522
|
} };
|
|
57514
|
-
const blob = container().getBlockBlobClient(storageKey);
|
|
57523
|
+
const blob = (await container()).getBlockBlobClient(storageKey);
|
|
57515
57524
|
if (contentLength === void 0) await blob.uploadData(new Uint8Array(await new Response(body).arrayBuffer()), options);
|
|
57516
57525
|
else {
|
|
57517
57526
|
const { Readable } = await import("node:stream");
|
|
@@ -57540,13 +57549,12 @@ function azureBlobStorage(config) {
|
|
|
57540
57549
|
async get({ storageUri }) {
|
|
57541
57550
|
const { key } = parseAndValidate(storageUri);
|
|
57542
57551
|
try {
|
|
57543
|
-
const download = await container().getBlobClient(key).download();
|
|
57552
|
+
const download = await (await container()).getBlobClient(key).download();
|
|
57544
57553
|
const body = download.readableStreamBody;
|
|
57545
57554
|
if (body === void 0) return { response: null };
|
|
57546
57555
|
const headers = new Headers();
|
|
57547
57556
|
if (download.contentType) headers.set("content-type", download.contentType);
|
|
57548
57557
|
if (download.contentLength !== void 0) headers.set("content-length", String(download.contentLength));
|
|
57549
|
-
const { Readable } = await import("node:stream");
|
|
57550
57558
|
return { response: new Response(Readable.toWeb(body), { headers }) };
|
|
57551
57559
|
} catch (error) {
|
|
57552
57560
|
if (isNotFound(error)) return { response: null };
|
|
@@ -57560,11 +57568,11 @@ function azureBlobStorage(config) {
|
|
|
57560
57568
|
},
|
|
57561
57569
|
async exists({ storageUri }) {
|
|
57562
57570
|
const { key } = parseAndValidate(storageUri);
|
|
57563
|
-
return { exists: await container().getBlobClient(key).exists() };
|
|
57571
|
+
return { exists: await (await container()).getBlobClient(key).exists() };
|
|
57564
57572
|
},
|
|
57565
57573
|
async delete({ storageUri }) {
|
|
57566
57574
|
const { key } = parseAndValidate(storageUri);
|
|
57567
|
-
await container().getBlobClient(key).deleteIfExists();
|
|
57575
|
+
await (await container()).getBlobClient(key).deleteIfExists();
|
|
57568
57576
|
return { deleted: true };
|
|
57569
57577
|
}
|
|
57570
57578
|
});
|
|
@@ -70857,18 +70865,21 @@ const isWideAdd = (op) => op.type === "add" && Object.keys(op.by).length + (op.e
|
|
|
70857
70865
|
const emulatorAborted = (error) => statusOf(error) === 500 && /PostgresError\(SqlState\(E(25P02|40001|40P01)\)/.test(String(error instanceof Error ? error.message : error));
|
|
70858
70866
|
const createCosmosStore = ({ client, databaseId, containerId, engine, nativePageSize }) => {
|
|
70859
70867
|
let opened;
|
|
70860
|
-
const open = () => opened ??= (() => {
|
|
70861
|
-
const account = typeof client === "function" ? client() : client;
|
|
70868
|
+
const open = () => opened ??= (async () => {
|
|
70869
|
+
const account = typeof client === "function" ? await client() : client;
|
|
70862
70870
|
return {
|
|
70863
70871
|
client: account,
|
|
70864
70872
|
container: account.database(databaseId).container(containerId)
|
|
70865
70873
|
};
|
|
70866
|
-
})()
|
|
70867
|
-
|
|
70874
|
+
})().catch((error) => {
|
|
70875
|
+
opened = void 0;
|
|
70876
|
+
throw error;
|
|
70877
|
+
});
|
|
70878
|
+
const container = async () => (await open()).container;
|
|
70868
70879
|
const readStates = async (ids, rowIds) => {
|
|
70869
70880
|
const states = /* @__PURE__ */ new Map();
|
|
70870
70881
|
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
70871
|
-
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);
|
|
70882
|
+
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);
|
|
70872
70883
|
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
70873
70884
|
etag,
|
|
70874
70885
|
v,
|
|
@@ -71000,7 +71011,7 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
71000
71011
|
const found = /* @__PURE__ */ new Map();
|
|
71001
71012
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
71002
71013
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
71003
|
-
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);
|
|
71014
|
+
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);
|
|
71004
71015
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
|
71005
71016
|
}
|
|
71006
71017
|
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
@@ -71036,7 +71047,7 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
71036
71047
|
value: after
|
|
71037
71048
|
});
|
|
71038
71049
|
}
|
|
71039
|
-
const { resources } = await container().items.query({
|
|
71050
|
+
const { resources } = await (await container()).items.query({
|
|
71040
71051
|
query: `SELECT TOP @size c.sk, c.row FROM c WHERE ${filters.join(" AND ")} ORDER BY c.pk ${order === "asc" ? "ASC" : "DESC"}, c.sk ${order === "asc" ? "ASC" : "DESC"}`,
|
|
71041
71052
|
parameters
|
|
71042
71053
|
}, {
|
|
@@ -71086,7 +71097,7 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
71086
71097
|
if (planned.length > BATCH_OPERATIONS) throw new Error(`A Cosmos DB batch takes ${BATCH_OPERATIONS} operations; this write needs ${planned.length}.`);
|
|
71087
71098
|
let results;
|
|
71088
71099
|
try {
|
|
71089
|
-
const response = await container().items.batch(planned.map(({ operation }) => operation), COSMOS_PARTITION);
|
|
71100
|
+
const response = await (await container()).items.batch(planned.map(({ operation }) => operation), COSMOS_PARTITION);
|
|
71090
71101
|
if (response.result === void 0) throw Object.assign(/* @__PURE__ */ new Error(`Cosmos DB refused the batch with status ${response.code}`), { code: response.code });
|
|
71091
71102
|
results = response.result;
|
|
71092
71103
|
} catch (error) {
|
|
@@ -71119,7 +71130,7 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
71119
71130
|
async deleteConsumed(keys) {
|
|
71120
71131
|
let remaining = [...new Set(keys.map(cosmosItemId))];
|
|
71121
71132
|
for (let attempt = 0; remaining.length > 0; attempt += 1) {
|
|
71122
|
-
const failed = (await container().items.executeBulkOperations(remaining.map((id) => ({
|
|
71133
|
+
const failed = (await (await container()).items.executeBulkOperations(remaining.map((id) => ({
|
|
71123
71134
|
operationType: "Delete",
|
|
71124
71135
|
id,
|
|
71125
71136
|
partitionKey: COSMOS_PARTITION
|
|
@@ -71138,8 +71149,8 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
71138
71149
|
}
|
|
71139
71150
|
},
|
|
71140
71151
|
migrations: { async apply() {
|
|
71141
|
-
if (engine !== void 0) await assertCosmosContainerReusable(container(), engine);
|
|
71142
|
-
const { database } = await open().client.databases.createIfNotExists({ id: databaseId });
|
|
71152
|
+
if (engine !== void 0) await assertCosmosContainerReusable(await container(), engine);
|
|
71153
|
+
const { database } = await (await open()).client.databases.createIfNotExists({ id: databaseId });
|
|
71143
71154
|
const { resource } = await database.containers.createIfNotExists({
|
|
71144
71155
|
id: containerId,
|
|
71145
71156
|
partitionKey: { paths: [COSMOS_PARTITION_KEY_PATH] },
|
|
@@ -71176,8 +71187,12 @@ const adapterOf = (config) => {
|
|
|
71176
71187
|
const { databaseId = AZURE_COSMOS_V1_DATABASE, containerId = AZURE_COSMOS_V1_CONTAINER, aggregateBatching: _, ...connection } = config;
|
|
71177
71188
|
if (connection.consistencyLevel !== void 0 && connection.consistencyLevel !== "Strong") throw new Error(`cosmosDatabase reads with strong consistency; consistencyLevel "${String(connection.consistencyLevel)}" is weaker.`);
|
|
71178
71189
|
let client;
|
|
71190
|
+
const { connectionString } = connection;
|
|
71179
71191
|
const store = createCosmosStore({
|
|
71180
|
-
client: () => client ??= new CosmosClient(
|
|
71192
|
+
client: async () => client ??= new CosmosClient({
|
|
71193
|
+
...connection,
|
|
71194
|
+
connectionString: typeof connectionString === "function" ? await connectionString() : connectionString
|
|
71195
|
+
}),
|
|
71181
71196
|
databaseId,
|
|
71182
71197
|
containerId,
|
|
71183
71198
|
engine: currentCosmosEngine()
|
|
@@ -71189,7 +71204,7 @@ const adapterOf = (config) => {
|
|
|
71189
71204
|
};
|
|
71190
71205
|
const DATABASE_TARGET = Symbol.for("@hot-updater/database-target");
|
|
71191
71206
|
const accountHostOf = ({ endpoint, connectionString }) => {
|
|
71192
|
-
const url = endpoint ?? connectionString
|
|
71207
|
+
const url = endpoint ?? (typeof connectionString === "string" ? connectionString.match(/AccountEndpoint=([^;]+)/iu)?.[1] : void 0);
|
|
71193
71208
|
try {
|
|
71194
71209
|
return url === void 0 ? void 0 : new URL(url).hostname;
|
|
71195
71210
|
} catch {
|