datasette-ts 0.0.8 → 0.0.9
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/cli.js +49 -4
- package/dist/cli.js.map +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -24017,6 +24017,7 @@ function normalizeLibsqlRows(result) {
|
|
|
24017
24017
|
|
|
24018
24018
|
// src/cli/deploy-cloudflare.ts
|
|
24019
24019
|
var DEFAULT_IMPORTS_DIR = ".datasette-ts/imports";
|
|
24020
|
+
var MAX_TEXT_BINDING_BYTES = 5 * 1024;
|
|
24020
24021
|
async function runCloudflareDeploy(args) {
|
|
24021
24022
|
const startedAt = Date.now();
|
|
24022
24023
|
logStep("Starting Cloudflare deploy");
|
|
@@ -24057,6 +24058,28 @@ async function runCloudflareDeploy(args) {
|
|
|
24057
24058
|
logStep("Precomputing inspect data");
|
|
24058
24059
|
inspectData = await loadInspectDataFromFile(options.dbFile, options.dbName);
|
|
24059
24060
|
}
|
|
24061
|
+
const schemaJson = JSON.stringify({ [options.dbName]: schema });
|
|
24062
|
+
const schemaSize = byteLength(schemaJson);
|
|
24063
|
+
let schemaBinding = null;
|
|
24064
|
+
if (schemaSize <= MAX_TEXT_BINDING_BYTES) {
|
|
24065
|
+
schemaBinding = schemaJson;
|
|
24066
|
+
} else {
|
|
24067
|
+
logStep(
|
|
24068
|
+
`Schema JSON is ${formatBytes2(schemaSize)}; skipping text binding and using runtime introspection.`
|
|
24069
|
+
);
|
|
24070
|
+
}
|
|
24071
|
+
let inspectBinding = null;
|
|
24072
|
+
if (inspectData) {
|
|
24073
|
+
const inspectJson = JSON.stringify(inspectData);
|
|
24074
|
+
const inspectSize = byteLength(inspectJson);
|
|
24075
|
+
if (inspectSize <= MAX_TEXT_BINDING_BYTES) {
|
|
24076
|
+
inspectBinding = inspectJson;
|
|
24077
|
+
} else {
|
|
24078
|
+
logStep(
|
|
24079
|
+
`Inspect data is ${formatBytes2(inspectSize)}; skipping text binding.`
|
|
24080
|
+
);
|
|
24081
|
+
}
|
|
24082
|
+
}
|
|
24060
24083
|
logStep("Initializing Alchemy app");
|
|
24061
24084
|
const app = await alchemy(options.workerName);
|
|
24062
24085
|
logStep("Creating D1 database");
|
|
@@ -24073,11 +24096,13 @@ async function runCloudflareDeploy(args) {
|
|
|
24073
24096
|
const bindings = {
|
|
24074
24097
|
DATASETTE_DB: db,
|
|
24075
24098
|
ASSETS: staticAssets,
|
|
24076
|
-
DATASETTE_DB_NAME: options.dbName
|
|
24077
|
-
DATASETTE_SCHEMA: JSON.stringify({ [options.dbName]: schema })
|
|
24099
|
+
DATASETTE_DB_NAME: options.dbName
|
|
24078
24100
|
};
|
|
24079
|
-
if (
|
|
24080
|
-
bindings.
|
|
24101
|
+
if (schemaBinding) {
|
|
24102
|
+
bindings.DATASETTE_SCHEMA = schemaBinding;
|
|
24103
|
+
}
|
|
24104
|
+
if (inspectBinding) {
|
|
24105
|
+
bindings.DATASETTE_INSPECT_DATA = inspectBinding;
|
|
24081
24106
|
}
|
|
24082
24107
|
logStep("Deploying worker");
|
|
24083
24108
|
const worker = await Worker(`worker-${options.workerName}`, {
|
|
@@ -24281,6 +24306,26 @@ function formatDuration(ms) {
|
|
|
24281
24306
|
const seconds = (ms / 1e3).toFixed(1);
|
|
24282
24307
|
return `${seconds}s`;
|
|
24283
24308
|
}
|
|
24309
|
+
function byteLength(value) {
|
|
24310
|
+
if (typeof Buffer !== "undefined") {
|
|
24311
|
+
return Buffer.byteLength(value, "utf8");
|
|
24312
|
+
}
|
|
24313
|
+
return new TextEncoder().encode(value).length;
|
|
24314
|
+
}
|
|
24315
|
+
function formatBytes2(bytes) {
|
|
24316
|
+
if (!Number.isFinite(bytes) || bytes < 0) {
|
|
24317
|
+
return "0 B";
|
|
24318
|
+
}
|
|
24319
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
24320
|
+
let value = bytes;
|
|
24321
|
+
let index = 0;
|
|
24322
|
+
while (value >= 1024 && index < units.length - 1) {
|
|
24323
|
+
value /= 1024;
|
|
24324
|
+
index += 1;
|
|
24325
|
+
}
|
|
24326
|
+
const rounded = index === 0 ? value.toFixed(0) : value.toFixed(1);
|
|
24327
|
+
return `${rounded} ${units[index]}`;
|
|
24328
|
+
}
|
|
24284
24329
|
|
|
24285
24330
|
// src/cli/serve.ts
|
|
24286
24331
|
init_registry();
|