@walkthru-earth/objex-utils 1.0.0 → 1.1.0
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/README.md +92 -0
- package/dist/index.cjs +1183 -954
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +167 -1
- package/dist/index.d.ts +167 -1
- package/dist/index.js +1161 -955
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var apacheArrow = require('apache-arrow');
|
|
4
|
+
var YAML = require('yaml');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var YAML__default = /*#__PURE__*/_interopDefault(YAML);
|
|
4
9
|
|
|
5
10
|
// ../../src/lib/constants.ts
|
|
6
11
|
var STORAGE_KEYS = {
|
|
@@ -1059,959 +1064,6 @@ var QueryCancelledError = class extends Error {
|
|
|
1059
1064
|
}
|
|
1060
1065
|
};
|
|
1061
1066
|
|
|
1062
|
-
// ../../src/lib/storage/url-adapter.ts
|
|
1063
|
-
var UrlAdapter = class {
|
|
1064
|
-
supportsWrite = false;
|
|
1065
|
-
async read(url, offset, length, signal) {
|
|
1066
|
-
const headers = {};
|
|
1067
|
-
if (offset !== void 0 && length !== void 0) {
|
|
1068
|
-
headers.Range = `bytes=${offset}-${offset + length - 1}`;
|
|
1069
|
-
} else if (offset !== void 0) {
|
|
1070
|
-
headers.Range = `bytes=${offset}-`;
|
|
1071
|
-
}
|
|
1072
|
-
const res = await fetch(url, { headers, signal });
|
|
1073
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
1074
|
-
return new Uint8Array(await res.arrayBuffer());
|
|
1075
|
-
}
|
|
1076
|
-
async head(url, signal) {
|
|
1077
|
-
const res = await fetch(url, { method: "HEAD", signal });
|
|
1078
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
1079
|
-
const name = url.split("/").pop()?.split("?")[0] || "file";
|
|
1080
|
-
const ext = name.includes(".") ? name.split(".").pop().toLowerCase() : "";
|
|
1081
|
-
return {
|
|
1082
|
-
name,
|
|
1083
|
-
path: url,
|
|
1084
|
-
is_dir: false,
|
|
1085
|
-
size: Number(res.headers.get("content-length") || 0),
|
|
1086
|
-
modified: new Date(res.headers.get("last-modified") || 0).getTime(),
|
|
1087
|
-
extension: ext
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
async list() {
|
|
1091
|
-
return [];
|
|
1092
|
-
}
|
|
1093
|
-
async put() {
|
|
1094
|
-
throw new Error("Write not supported for direct URL sources");
|
|
1095
|
-
}
|
|
1096
|
-
async delete() {
|
|
1097
|
-
throw new Error("Delete not supported for direct URL sources");
|
|
1098
|
-
}
|
|
1099
|
-
async deletePrefix() {
|
|
1100
|
-
throw new Error("Delete not supported for direct URL sources");
|
|
1101
|
-
}
|
|
1102
|
-
async copy() {
|
|
1103
|
-
throw new Error("Copy not supported for direct URL sources");
|
|
1104
|
-
}
|
|
1105
|
-
};
|
|
1106
|
-
|
|
1107
|
-
// ../../src/lib/utils/column-types.ts
|
|
1108
|
-
var NUMBER_TYPES = [
|
|
1109
|
-
"TINYINT",
|
|
1110
|
-
"SMALLINT",
|
|
1111
|
-
"INTEGER",
|
|
1112
|
-
"BIGINT",
|
|
1113
|
-
"HUGEINT",
|
|
1114
|
-
"UTINYINT",
|
|
1115
|
-
"USMALLINT",
|
|
1116
|
-
"UINTEGER",
|
|
1117
|
-
"UBIGINT",
|
|
1118
|
-
"FLOAT",
|
|
1119
|
-
"DOUBLE",
|
|
1120
|
-
"DECIMAL",
|
|
1121
|
-
"NUMERIC",
|
|
1122
|
-
"REAL",
|
|
1123
|
-
"INT",
|
|
1124
|
-
"INT1",
|
|
1125
|
-
"INT2",
|
|
1126
|
-
"INT4",
|
|
1127
|
-
"INT8",
|
|
1128
|
-
"SIGNED",
|
|
1129
|
-
"SHORT",
|
|
1130
|
-
"LONG"
|
|
1131
|
-
];
|
|
1132
|
-
var STRING_TYPES = ["VARCHAR", "TEXT", "STRING", "CHAR", "BPCHAR", "NAME", "UUID", "ENUM"];
|
|
1133
|
-
var DATE_TYPES = [
|
|
1134
|
-
"DATE",
|
|
1135
|
-
"TIME",
|
|
1136
|
-
"TIMESTAMP",
|
|
1137
|
-
"TIMESTAMP_S",
|
|
1138
|
-
"TIMESTAMP_MS",
|
|
1139
|
-
"TIMESTAMP_NS",
|
|
1140
|
-
"TIMESTAMP WITH TIME ZONE",
|
|
1141
|
-
"TIMESTAMPTZ",
|
|
1142
|
-
"INTERVAL",
|
|
1143
|
-
"TIMESTAMP_TZ"
|
|
1144
|
-
];
|
|
1145
|
-
var BOOLEAN_TYPES = ["BOOLEAN", "BOOL", "LOGICAL"];
|
|
1146
|
-
var GEO_TYPES = [
|
|
1147
|
-
"GEOMETRY",
|
|
1148
|
-
"POINT",
|
|
1149
|
-
"LINESTRING",
|
|
1150
|
-
"POLYGON",
|
|
1151
|
-
"MULTIPOINT",
|
|
1152
|
-
"MULTILINESTRING",
|
|
1153
|
-
"MULTIPOLYGON",
|
|
1154
|
-
"GEOMETRYCOLLECTION",
|
|
1155
|
-
"WKB_GEOMETRY"
|
|
1156
|
-
];
|
|
1157
|
-
var BINARY_TYPES = ["BLOB", "BYTEA", "BINARY", "VARBINARY"];
|
|
1158
|
-
var JSON_TYPES = ["JSON", "JSONB"];
|
|
1159
|
-
function classifyType(duckdbType) {
|
|
1160
|
-
const upper = duckdbType.toUpperCase().trim();
|
|
1161
|
-
const base = upper.replace(/\(.*\)/, "").trim();
|
|
1162
|
-
if (NUMBER_TYPES.includes(base)) return "number";
|
|
1163
|
-
if (STRING_TYPES.includes(base)) return "string";
|
|
1164
|
-
if (DATE_TYPES.includes(base)) return "date";
|
|
1165
|
-
if (BOOLEAN_TYPES.includes(base)) return "boolean";
|
|
1166
|
-
if (GEO_TYPES.includes(base)) return "geo";
|
|
1167
|
-
if (BINARY_TYPES.includes(base)) return "binary";
|
|
1168
|
-
if (JSON_TYPES.includes(base)) return "json";
|
|
1169
|
-
if (base.startsWith("STRUCT") || base.startsWith("MAP") || base.startsWith("UNION"))
|
|
1170
|
-
return "json";
|
|
1171
|
-
if (base.endsWith("[]") || base.startsWith("LIST")) return "json";
|
|
1172
|
-
if (upper.includes("INT") || upper.includes("FLOAT") || upper.includes("DOUBLE") || upper.includes("DECIMAL") || upper.includes("NUMERIC"))
|
|
1173
|
-
return "number";
|
|
1174
|
-
if (upper.includes("CHAR") || upper.includes("TEXT") || upper.includes("STRING")) return "string";
|
|
1175
|
-
if (upper.includes("TIME") || upper.includes("DATE")) return "date";
|
|
1176
|
-
if (upper.includes("BOOL")) return "boolean";
|
|
1177
|
-
if (upper.includes("GEOMETRY") || upper.includes("GEO") || upper.includes("WKB")) return "geo";
|
|
1178
|
-
if (upper.includes("BLOB") || upper.includes("BINARY")) return "binary";
|
|
1179
|
-
if (upper.includes("JSON") || upper.includes("STRUCT") || upper.includes("MAP") || upper.includes("LIST"))
|
|
1180
|
-
return "json";
|
|
1181
|
-
return "other";
|
|
1182
|
-
}
|
|
1183
|
-
var TYPE_COLORS = {
|
|
1184
|
-
number: "text-blue-500",
|
|
1185
|
-
string: "text-green-500",
|
|
1186
|
-
date: "text-amber-500",
|
|
1187
|
-
boolean: "text-purple-500",
|
|
1188
|
-
geo: "text-teal-500",
|
|
1189
|
-
binary: "text-zinc-500",
|
|
1190
|
-
json: "text-orange-500",
|
|
1191
|
-
other: "text-zinc-400"
|
|
1192
|
-
};
|
|
1193
|
-
var TYPE_BADGE_CLASSES = {
|
|
1194
|
-
number: "bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20",
|
|
1195
|
-
string: "bg-green-500/10 text-green-600 dark:text-green-400 border-green-500/20",
|
|
1196
|
-
date: "bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20",
|
|
1197
|
-
boolean: "bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/20",
|
|
1198
|
-
geo: "bg-teal-500/10 text-teal-600 dark:text-teal-400 border-teal-500/20",
|
|
1199
|
-
binary: "bg-zinc-500/10 text-zinc-600 dark:text-zinc-400 border-zinc-500/20",
|
|
1200
|
-
json: "bg-orange-500/10 text-orange-600 dark:text-orange-400 border-orange-500/20",
|
|
1201
|
-
other: "bg-zinc-500/10 text-zinc-500 dark:text-zinc-400 border-zinc-500/20"
|
|
1202
|
-
};
|
|
1203
|
-
var TYPE_LABELS = {
|
|
1204
|
-
number: "#",
|
|
1205
|
-
string: "Aa",
|
|
1206
|
-
date: "dt",
|
|
1207
|
-
boolean: "T/F",
|
|
1208
|
-
geo: "geo",
|
|
1209
|
-
binary: "01",
|
|
1210
|
-
json: "{}",
|
|
1211
|
-
other: "?"
|
|
1212
|
-
};
|
|
1213
|
-
function typeColor(category) {
|
|
1214
|
-
return TYPE_COLORS[category];
|
|
1215
|
-
}
|
|
1216
|
-
function typeBadgeClass(category) {
|
|
1217
|
-
return TYPE_BADGE_CLASSES[category];
|
|
1218
|
-
}
|
|
1219
|
-
function typeLabel(category) {
|
|
1220
|
-
return TYPE_LABELS[category];
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
// ../../src/lib/utils/error.ts
|
|
1224
|
-
function handleLoadError(err) {
|
|
1225
|
-
if (err instanceof DOMException && err.name === "AbortError") return null;
|
|
1226
|
-
return err instanceof Error ? err.message : String(err);
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
// ../../src/lib/utils/format.ts
|
|
1230
|
-
function formatFileSize(bytes) {
|
|
1231
|
-
if (bytes < 0) return "0 B";
|
|
1232
|
-
if (bytes === 0) return "0 B";
|
|
1233
|
-
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
1234
|
-
const base = 1024;
|
|
1235
|
-
const exponent = Math.min(Math.floor(Math.log(bytes) / Math.log(base)), units.length - 1);
|
|
1236
|
-
const value = bytes / base ** exponent;
|
|
1237
|
-
if (exponent === 0) return `${bytes} B`;
|
|
1238
|
-
return `${value.toFixed(1)} ${units[exponent]}`;
|
|
1239
|
-
}
|
|
1240
|
-
function formatDate(timestamp) {
|
|
1241
|
-
if (!timestamp || timestamp <= 0 || !Number.isFinite(timestamp)) return "--";
|
|
1242
|
-
const date = new Date(timestamp);
|
|
1243
|
-
const now = Date.now();
|
|
1244
|
-
const diffMs = now - timestamp;
|
|
1245
|
-
const diffSeconds = Math.floor(diffMs / 1e3);
|
|
1246
|
-
const diffMinutes = Math.floor(diffSeconds / 60);
|
|
1247
|
-
const diffHours = Math.floor(diffMinutes / 60);
|
|
1248
|
-
const diffDays = Math.floor(diffHours / 24);
|
|
1249
|
-
if (diffSeconds < 60) return "Just now";
|
|
1250
|
-
if (diffMinutes < 60) return `${diffMinutes}m ago`;
|
|
1251
|
-
if (diffHours < 24) return `${diffHours}h ago`;
|
|
1252
|
-
if (diffDays < 7) return `${diffDays}d ago`;
|
|
1253
|
-
return date.toLocaleDateString(void 0, {
|
|
1254
|
-
year: "numeric",
|
|
1255
|
-
month: "short",
|
|
1256
|
-
day: "numeric"
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
function getFileExtension(filename) {
|
|
1260
|
-
const lastDot = filename.lastIndexOf(".");
|
|
1261
|
-
if (lastDot <= 0) return "";
|
|
1262
|
-
return filename.slice(lastDot).toLowerCase();
|
|
1263
|
-
}
|
|
1264
|
-
function jsonReplacerBigInt(_key, value) {
|
|
1265
|
-
return typeof value === "bigint" ? value.toString() : value;
|
|
1266
|
-
}
|
|
1267
|
-
function formatValue(value) {
|
|
1268
|
-
if (value === null || value === void 0) return "NULL";
|
|
1269
|
-
if (value instanceof Date) return value.toISOString();
|
|
1270
|
-
if (typeof value === "bigint") return value.toString();
|
|
1271
|
-
if (typeof value === "object") return JSON.stringify(value, jsonReplacerBigInt);
|
|
1272
|
-
return String(value);
|
|
1273
|
-
}
|
|
1274
|
-
function normalizeGeomType(raw) {
|
|
1275
|
-
const s = raw.toUpperCase().replace(/\s+/g, "");
|
|
1276
|
-
if (s === "POINT") return "point";
|
|
1277
|
-
if (s === "LINESTRING") return "linestring";
|
|
1278
|
-
if (s === "POLYGON") return "polygon";
|
|
1279
|
-
if (s === "MULTIPOINT") return "multipoint";
|
|
1280
|
-
if (s === "MULTILINESTRING") return "multilinestring";
|
|
1281
|
-
if (s === "MULTIPOLYGON") return "multipolygon";
|
|
1282
|
-
return "polygon";
|
|
1283
|
-
}
|
|
1284
|
-
var EXTENSION_NAMES = {
|
|
1285
|
-
point: "geoarrow.point",
|
|
1286
|
-
linestring: "geoarrow.linestring",
|
|
1287
|
-
polygon: "geoarrow.polygon",
|
|
1288
|
-
multipoint: "geoarrow.multipoint",
|
|
1289
|
-
multilinestring: "geoarrow.multilinestring",
|
|
1290
|
-
multipolygon: "geoarrow.multipolygon"
|
|
1291
|
-
};
|
|
1292
|
-
function readWkbHeader(wkb) {
|
|
1293
|
-
if (wkb.length < 5) return null;
|
|
1294
|
-
const le = wkb[0] === 1;
|
|
1295
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1296
|
-
const rawType = dv.getUint32(1, le);
|
|
1297
|
-
let headerSize = 5;
|
|
1298
|
-
if ((rawType & 536870912) !== 0) headerSize += 4;
|
|
1299
|
-
const ewkbZ = (rawType & 2147483648) !== 0;
|
|
1300
|
-
const ewkbM = (rawType & 1073741824) !== 0;
|
|
1301
|
-
let type = rawType & 268435455;
|
|
1302
|
-
let isoZ = false;
|
|
1303
|
-
let isoM = false;
|
|
1304
|
-
if (type > 3e3) {
|
|
1305
|
-
isoZ = true;
|
|
1306
|
-
isoM = true;
|
|
1307
|
-
type -= 3e3;
|
|
1308
|
-
} else if (type > 2e3) {
|
|
1309
|
-
isoM = true;
|
|
1310
|
-
type -= 2e3;
|
|
1311
|
-
} else if (type > 1e3) {
|
|
1312
|
-
isoZ = true;
|
|
1313
|
-
type -= 1e3;
|
|
1314
|
-
}
|
|
1315
|
-
const dims = (ewkbZ || isoZ ? 1 : 0) + (ewkbM || isoM ? 1 : 0);
|
|
1316
|
-
const coordStride = (2 + dims) * 8;
|
|
1317
|
-
return { type, le, coordStride, dataOffset: headerSize };
|
|
1318
|
-
}
|
|
1319
|
-
function classifyWkbType(wkb) {
|
|
1320
|
-
const h = readWkbHeader(wkb);
|
|
1321
|
-
if (!h) return null;
|
|
1322
|
-
switch (h.type) {
|
|
1323
|
-
case 1:
|
|
1324
|
-
return "point";
|
|
1325
|
-
case 2:
|
|
1326
|
-
return "linestring";
|
|
1327
|
-
case 3:
|
|
1328
|
-
return "polygon";
|
|
1329
|
-
case 4:
|
|
1330
|
-
return "multipoint";
|
|
1331
|
-
case 5:
|
|
1332
|
-
return "multilinestring";
|
|
1333
|
-
case 6:
|
|
1334
|
-
return "multipolygon";
|
|
1335
|
-
default:
|
|
1336
|
-
return null;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
function newBounds() {
|
|
1340
|
-
return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
|
|
1341
|
-
}
|
|
1342
|
-
function expandBounds(b, x, y) {
|
|
1343
|
-
if (Number.isNaN(x) || Number.isNaN(y)) return;
|
|
1344
|
-
if (x < b.minX) b.minX = x;
|
|
1345
|
-
if (y < b.minY) b.minY = y;
|
|
1346
|
-
if (x > b.maxX) b.maxX = x;
|
|
1347
|
-
if (y > b.maxY) b.maxY = y;
|
|
1348
|
-
}
|
|
1349
|
-
var coordField = new apacheArrow.Field("xy", new apacheArrow.Float64());
|
|
1350
|
-
var coordType = new apacheArrow.FixedSizeList(2, coordField);
|
|
1351
|
-
function makeCoordData(coords, numPoints) {
|
|
1352
|
-
const floatData = apacheArrow.makeData({ type: new apacheArrow.Float64(), length: coords.length, data: coords });
|
|
1353
|
-
return apacheArrow.makeData({ type: coordType, length: numPoints, nullCount: 0, child: floatData });
|
|
1354
|
-
}
|
|
1355
|
-
function buildPointData(wkbs, b) {
|
|
1356
|
-
const n = wkbs.length;
|
|
1357
|
-
const coords = new Float64Array(n * 2);
|
|
1358
|
-
for (let i = 0; i < n; i++) {
|
|
1359
|
-
const wkb = wkbs[i];
|
|
1360
|
-
const h = readWkbHeader(wkb);
|
|
1361
|
-
if (!h || h.type !== 1) {
|
|
1362
|
-
coords[i * 2] = 0;
|
|
1363
|
-
coords[i * 2 + 1] = 0;
|
|
1364
|
-
continue;
|
|
1365
|
-
}
|
|
1366
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1367
|
-
const x = dv.getFloat64(h.dataOffset, h.le);
|
|
1368
|
-
const y = dv.getFloat64(h.dataOffset + 8, h.le);
|
|
1369
|
-
coords[i * 2] = x;
|
|
1370
|
-
coords[i * 2 + 1] = y;
|
|
1371
|
-
expandBounds(b, x, y);
|
|
1372
|
-
}
|
|
1373
|
-
return makeCoordData(coords, n);
|
|
1374
|
-
}
|
|
1375
|
-
function buildLineStringData(wkbs, b) {
|
|
1376
|
-
const n = wkbs.length;
|
|
1377
|
-
const geomOffsets = new Int32Array(n + 1);
|
|
1378
|
-
let totalCoords = 0;
|
|
1379
|
-
for (let i = 0; i < n; i++) {
|
|
1380
|
-
geomOffsets[i] = totalCoords;
|
|
1381
|
-
const h = readWkbHeader(wkbs[i]);
|
|
1382
|
-
if (!h || h.type !== 2) continue;
|
|
1383
|
-
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1384
|
-
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1385
|
-
totalCoords += numPts;
|
|
1386
|
-
}
|
|
1387
|
-
geomOffsets[n] = totalCoords;
|
|
1388
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1389
|
-
let ci = 0;
|
|
1390
|
-
for (const wkb of wkbs) {
|
|
1391
|
-
const h = readWkbHeader(wkb);
|
|
1392
|
-
if (!h || h.type !== 2) continue;
|
|
1393
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1394
|
-
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1395
|
-
let off = h.dataOffset + 4;
|
|
1396
|
-
for (let j = 0; j < numPts; j++) {
|
|
1397
|
-
const x = dv.getFloat64(off, h.le);
|
|
1398
|
-
const y = dv.getFloat64(off + 8, h.le);
|
|
1399
|
-
coords[ci++] = x;
|
|
1400
|
-
coords[ci++] = y;
|
|
1401
|
-
expandBounds(b, x, y);
|
|
1402
|
-
off += h.coordStride;
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
const fslData = makeCoordData(coords, totalCoords);
|
|
1406
|
-
const listType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
1407
|
-
return apacheArrow.makeData({
|
|
1408
|
-
type: listType,
|
|
1409
|
-
length: n,
|
|
1410
|
-
nullCount: 0,
|
|
1411
|
-
valueOffsets: geomOffsets,
|
|
1412
|
-
child: fslData
|
|
1413
|
-
});
|
|
1414
|
-
}
|
|
1415
|
-
function buildPolygonData(wkbs, b) {
|
|
1416
|
-
const n = wkbs.length;
|
|
1417
|
-
const geomOffsets = new Int32Array(n + 1);
|
|
1418
|
-
let totalRings = 0;
|
|
1419
|
-
let totalCoords = 0;
|
|
1420
|
-
for (let i = 0; i < n; i++) {
|
|
1421
|
-
geomOffsets[i] = totalRings;
|
|
1422
|
-
const h = readWkbHeader(wkbs[i]);
|
|
1423
|
-
if (!h || h.type !== 3) continue;
|
|
1424
|
-
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1425
|
-
const numRings = dv.getUint32(h.dataOffset, h.le);
|
|
1426
|
-
let off = h.dataOffset + 4;
|
|
1427
|
-
for (let r = 0; r < numRings; r++) {
|
|
1428
|
-
const numPts = dv.getUint32(off, h.le);
|
|
1429
|
-
off += 4 + numPts * h.coordStride;
|
|
1430
|
-
totalCoords += numPts;
|
|
1431
|
-
totalRings++;
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
geomOffsets[n] = totalRings;
|
|
1435
|
-
const ringOffsets = new Int32Array(totalRings + 1);
|
|
1436
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1437
|
-
let ri = 0;
|
|
1438
|
-
let ci = 0;
|
|
1439
|
-
for (const wkb of wkbs) {
|
|
1440
|
-
const h = readWkbHeader(wkb);
|
|
1441
|
-
if (!h || h.type !== 3) continue;
|
|
1442
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1443
|
-
const numRings = dv.getUint32(h.dataOffset, h.le);
|
|
1444
|
-
let off = h.dataOffset + 4;
|
|
1445
|
-
for (let r = 0; r < numRings; r++) {
|
|
1446
|
-
ringOffsets[ri++] = ci >> 1;
|
|
1447
|
-
const numPts = dv.getUint32(off, h.le);
|
|
1448
|
-
off += 4;
|
|
1449
|
-
for (let j = 0; j < numPts; j++) {
|
|
1450
|
-
const x = dv.getFloat64(off, h.le);
|
|
1451
|
-
const y = dv.getFloat64(off + 8, h.le);
|
|
1452
|
-
coords[ci++] = x;
|
|
1453
|
-
coords[ci++] = y;
|
|
1454
|
-
expandBounds(b, x, y);
|
|
1455
|
-
off += h.coordStride;
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
ringOffsets[totalRings] = ci >> 1;
|
|
1460
|
-
const coordCount = ci >> 1;
|
|
1461
|
-
const fslData = makeCoordData(coords, coordCount);
|
|
1462
|
-
const ringListType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
1463
|
-
const ringListData = apacheArrow.makeData({
|
|
1464
|
-
type: ringListType,
|
|
1465
|
-
length: totalRings,
|
|
1466
|
-
nullCount: 0,
|
|
1467
|
-
valueOffsets: ringOffsets,
|
|
1468
|
-
child: fslData
|
|
1469
|
-
});
|
|
1470
|
-
const polyType = new apacheArrow.List(new apacheArrow.Field("rings", ringListType));
|
|
1471
|
-
return apacheArrow.makeData({
|
|
1472
|
-
type: polyType,
|
|
1473
|
-
length: n,
|
|
1474
|
-
nullCount: 0,
|
|
1475
|
-
valueOffsets: geomOffsets,
|
|
1476
|
-
child: ringListData
|
|
1477
|
-
});
|
|
1478
|
-
}
|
|
1479
|
-
function buildMultiPointData(wkbs, b) {
|
|
1480
|
-
const n = wkbs.length;
|
|
1481
|
-
const geomOffsets = new Int32Array(n + 1);
|
|
1482
|
-
let totalCoords = 0;
|
|
1483
|
-
for (let i = 0; i < n; i++) {
|
|
1484
|
-
geomOffsets[i] = totalCoords;
|
|
1485
|
-
const h = readWkbHeader(wkbs[i]);
|
|
1486
|
-
if (!h || h.type !== 4) continue;
|
|
1487
|
-
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1488
|
-
totalCoords += dv.getUint32(h.dataOffset, h.le);
|
|
1489
|
-
}
|
|
1490
|
-
geomOffsets[n] = totalCoords;
|
|
1491
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1492
|
-
let ci = 0;
|
|
1493
|
-
for (const wkb of wkbs) {
|
|
1494
|
-
const h = readWkbHeader(wkb);
|
|
1495
|
-
if (!h || h.type !== 4) continue;
|
|
1496
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1497
|
-
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1498
|
-
let off = h.dataOffset + 4;
|
|
1499
|
-
for (let j = 0; j < numPts; j++) {
|
|
1500
|
-
const innerH = readWkbHeader(
|
|
1501
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1502
|
-
);
|
|
1503
|
-
if (innerH) {
|
|
1504
|
-
const x = dv.getFloat64(off + innerH.dataOffset, innerH.le);
|
|
1505
|
-
const y = dv.getFloat64(off + innerH.dataOffset + 8, innerH.le);
|
|
1506
|
-
coords[ci++] = x;
|
|
1507
|
-
coords[ci++] = y;
|
|
1508
|
-
expandBounds(b, x, y);
|
|
1509
|
-
off += innerH.dataOffset + innerH.coordStride;
|
|
1510
|
-
} else {
|
|
1511
|
-
coords[ci++] = 0;
|
|
1512
|
-
coords[ci++] = 0;
|
|
1513
|
-
off += 21;
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
const fslData = makeCoordData(coords, totalCoords);
|
|
1518
|
-
const listType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
1519
|
-
return apacheArrow.makeData({
|
|
1520
|
-
type: listType,
|
|
1521
|
-
length: n,
|
|
1522
|
-
nullCount: 0,
|
|
1523
|
-
valueOffsets: geomOffsets,
|
|
1524
|
-
child: fslData
|
|
1525
|
-
});
|
|
1526
|
-
}
|
|
1527
|
-
function buildMultiLineStringData(wkbs, b) {
|
|
1528
|
-
const n = wkbs.length;
|
|
1529
|
-
const geomOffsetsArr = [0];
|
|
1530
|
-
let totalLines = 0;
|
|
1531
|
-
let totalCoords = 0;
|
|
1532
|
-
for (const wkb of wkbs) {
|
|
1533
|
-
const h = readWkbHeader(wkb);
|
|
1534
|
-
if (!h || h.type !== 5) {
|
|
1535
|
-
geomOffsetsArr.push(totalLines);
|
|
1536
|
-
continue;
|
|
1537
|
-
}
|
|
1538
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1539
|
-
const numLines = dv.getUint32(h.dataOffset, h.le);
|
|
1540
|
-
let off = h.dataOffset + 4;
|
|
1541
|
-
for (let l = 0; l < numLines; l++) {
|
|
1542
|
-
const innerH = readWkbHeader(
|
|
1543
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1544
|
-
);
|
|
1545
|
-
if (!innerH) break;
|
|
1546
|
-
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
1547
|
-
const numPts = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
1548
|
-
totalCoords += numPts;
|
|
1549
|
-
off += innerH.dataOffset + 4 + numPts * innerH.coordStride;
|
|
1550
|
-
totalLines++;
|
|
1551
|
-
}
|
|
1552
|
-
geomOffsetsArr.push(totalLines);
|
|
1553
|
-
}
|
|
1554
|
-
const geomOffsets = new Int32Array(geomOffsetsArr);
|
|
1555
|
-
const lineOffsets = new Int32Array(totalLines + 1);
|
|
1556
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1557
|
-
let li = 0;
|
|
1558
|
-
let ci = 0;
|
|
1559
|
-
for (const wkb of wkbs) {
|
|
1560
|
-
const h = readWkbHeader(wkb);
|
|
1561
|
-
if (!h || h.type !== 5) continue;
|
|
1562
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1563
|
-
const numLines = dv.getUint32(h.dataOffset, h.le);
|
|
1564
|
-
let off = h.dataOffset + 4;
|
|
1565
|
-
for (let l = 0; l < numLines; l++) {
|
|
1566
|
-
lineOffsets[li++] = ci >> 1;
|
|
1567
|
-
const innerH = readWkbHeader(
|
|
1568
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1569
|
-
);
|
|
1570
|
-
if (!innerH) break;
|
|
1571
|
-
const numPts = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off).getUint32(
|
|
1572
|
-
innerH.dataOffset,
|
|
1573
|
-
innerH.le
|
|
1574
|
-
);
|
|
1575
|
-
let ptOff = off + innerH.dataOffset + 4;
|
|
1576
|
-
for (let j = 0; j < numPts; j++) {
|
|
1577
|
-
const x = dv.getFloat64(ptOff, innerH.le);
|
|
1578
|
-
const y = dv.getFloat64(ptOff + 8, innerH.le);
|
|
1579
|
-
coords[ci++] = x;
|
|
1580
|
-
coords[ci++] = y;
|
|
1581
|
-
expandBounds(b, x, y);
|
|
1582
|
-
ptOff += innerH.coordStride;
|
|
1583
|
-
}
|
|
1584
|
-
off = ptOff;
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
lineOffsets[totalLines] = ci >> 1;
|
|
1588
|
-
const fslData = makeCoordData(coords, ci >> 1);
|
|
1589
|
-
const lineListType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
1590
|
-
const lineListData = apacheArrow.makeData({
|
|
1591
|
-
type: lineListType,
|
|
1592
|
-
length: totalLines,
|
|
1593
|
-
nullCount: 0,
|
|
1594
|
-
valueOffsets: lineOffsets,
|
|
1595
|
-
child: fslData
|
|
1596
|
-
});
|
|
1597
|
-
const multiLineType = new apacheArrow.List(new apacheArrow.Field("lines", lineListType));
|
|
1598
|
-
return apacheArrow.makeData({
|
|
1599
|
-
type: multiLineType,
|
|
1600
|
-
length: n,
|
|
1601
|
-
nullCount: 0,
|
|
1602
|
-
valueOffsets: geomOffsets,
|
|
1603
|
-
child: lineListData
|
|
1604
|
-
});
|
|
1605
|
-
}
|
|
1606
|
-
function buildMultiPolygonData(wkbs, b) {
|
|
1607
|
-
const n = wkbs.length;
|
|
1608
|
-
const geomOffsetsArr = [0];
|
|
1609
|
-
let totalPolys = 0;
|
|
1610
|
-
let totalRings = 0;
|
|
1611
|
-
let totalCoords = 0;
|
|
1612
|
-
for (const wkb of wkbs) {
|
|
1613
|
-
const h = readWkbHeader(wkb);
|
|
1614
|
-
if (!h || h.type !== 6) {
|
|
1615
|
-
geomOffsetsArr.push(totalPolys);
|
|
1616
|
-
continue;
|
|
1617
|
-
}
|
|
1618
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1619
|
-
const numPolys = dv.getUint32(h.dataOffset, h.le);
|
|
1620
|
-
let off = h.dataOffset + 4;
|
|
1621
|
-
for (let p = 0; p < numPolys; p++) {
|
|
1622
|
-
const innerH = readWkbHeader(
|
|
1623
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1624
|
-
);
|
|
1625
|
-
if (!innerH) break;
|
|
1626
|
-
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
1627
|
-
const numRings = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
1628
|
-
let ringOff = innerH.dataOffset + 4;
|
|
1629
|
-
for (let r = 0; r < numRings; r++) {
|
|
1630
|
-
const numPts = innerDv.getUint32(ringOff, innerH.le);
|
|
1631
|
-
ringOff += 4 + numPts * innerH.coordStride;
|
|
1632
|
-
totalCoords += numPts;
|
|
1633
|
-
totalRings++;
|
|
1634
|
-
}
|
|
1635
|
-
off += ringOff;
|
|
1636
|
-
totalPolys++;
|
|
1637
|
-
}
|
|
1638
|
-
geomOffsetsArr.push(totalPolys);
|
|
1639
|
-
}
|
|
1640
|
-
const geomOffsets = new Int32Array(geomOffsetsArr);
|
|
1641
|
-
const polyOffsets = new Int32Array(totalPolys + 1);
|
|
1642
|
-
const ringOffsets = new Int32Array(totalRings + 1);
|
|
1643
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1644
|
-
let pi = 0;
|
|
1645
|
-
let ri = 0;
|
|
1646
|
-
let ci = 0;
|
|
1647
|
-
for (const wkb of wkbs) {
|
|
1648
|
-
const h = readWkbHeader(wkb);
|
|
1649
|
-
if (!h || h.type !== 6) continue;
|
|
1650
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1651
|
-
const numPolys = dv.getUint32(h.dataOffset, h.le);
|
|
1652
|
-
let off = h.dataOffset + 4;
|
|
1653
|
-
for (let p = 0; p < numPolys; p++) {
|
|
1654
|
-
polyOffsets[pi++] = ri;
|
|
1655
|
-
const innerH = readWkbHeader(
|
|
1656
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1657
|
-
);
|
|
1658
|
-
if (!innerH) break;
|
|
1659
|
-
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
1660
|
-
const numRings = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
1661
|
-
let ringOff = off + innerH.dataOffset + 4;
|
|
1662
|
-
for (let r = 0; r < numRings; r++) {
|
|
1663
|
-
ringOffsets[ri++] = ci >> 1;
|
|
1664
|
-
const numPts = dv.getUint32(ringOff, innerH.le);
|
|
1665
|
-
ringOff += 4;
|
|
1666
|
-
for (let j = 0; j < numPts; j++) {
|
|
1667
|
-
const x = dv.getFloat64(ringOff, innerH.le);
|
|
1668
|
-
const y = dv.getFloat64(ringOff + 8, innerH.le);
|
|
1669
|
-
coords[ci++] = x;
|
|
1670
|
-
coords[ci++] = y;
|
|
1671
|
-
expandBounds(b, x, y);
|
|
1672
|
-
ringOff += innerH.coordStride;
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
off = ringOff;
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
polyOffsets[totalPolys] = ri;
|
|
1679
|
-
ringOffsets[totalRings] = ci >> 1;
|
|
1680
|
-
const fslData = makeCoordData(coords, ci >> 1);
|
|
1681
|
-
const ringListType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
1682
|
-
const ringListData = apacheArrow.makeData({
|
|
1683
|
-
type: ringListType,
|
|
1684
|
-
length: totalRings,
|
|
1685
|
-
nullCount: 0,
|
|
1686
|
-
valueOffsets: ringOffsets,
|
|
1687
|
-
child: fslData
|
|
1688
|
-
});
|
|
1689
|
-
const polyListType = new apacheArrow.List(new apacheArrow.Field("rings", ringListType));
|
|
1690
|
-
const polyListData = apacheArrow.makeData({
|
|
1691
|
-
type: polyListType,
|
|
1692
|
-
length: totalPolys,
|
|
1693
|
-
nullCount: 0,
|
|
1694
|
-
valueOffsets: polyOffsets,
|
|
1695
|
-
child: ringListData
|
|
1696
|
-
});
|
|
1697
|
-
const multiPolyType = new apacheArrow.List(new apacheArrow.Field("polygons", polyListType));
|
|
1698
|
-
return apacheArrow.makeData({
|
|
1699
|
-
type: multiPolyType,
|
|
1700
|
-
length: n,
|
|
1701
|
-
nullCount: 0,
|
|
1702
|
-
valueOffsets: geomOffsets,
|
|
1703
|
-
child: polyListData
|
|
1704
|
-
});
|
|
1705
|
-
}
|
|
1706
|
-
function buildAttributeColumns(indices, attributes) {
|
|
1707
|
-
const n = indices.length;
|
|
1708
|
-
const fields = [];
|
|
1709
|
-
const dataArr = [];
|
|
1710
|
-
for (const [name, col] of attributes) {
|
|
1711
|
-
const { values } = col;
|
|
1712
|
-
let isNumeric = true;
|
|
1713
|
-
const sampleEnd = Math.min(n, 100);
|
|
1714
|
-
for (let i = 0; i < sampleEnd; i++) {
|
|
1715
|
-
if (values[indices[i]] != null && typeof values[indices[i]] !== "number") {
|
|
1716
|
-
isNumeric = false;
|
|
1717
|
-
break;
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
if (isNumeric) {
|
|
1721
|
-
const arr = new Float64Array(n);
|
|
1722
|
-
for (let i = 0; i < n; i++) arr[i] = values[indices[i]] ?? NaN;
|
|
1723
|
-
const data = apacheArrow.makeData({ type: new apacheArrow.Float64(), length: n, data: arr });
|
|
1724
|
-
fields.push(new apacheArrow.Field(name, new apacheArrow.Float64(), true));
|
|
1725
|
-
dataArr.push(data);
|
|
1726
|
-
} else {
|
|
1727
|
-
const encoder = new TextEncoder();
|
|
1728
|
-
const offsets = new Int32Array(n + 1);
|
|
1729
|
-
let totalBytes = 0;
|
|
1730
|
-
const strParts = [];
|
|
1731
|
-
for (let i = 0; i < n; i++) {
|
|
1732
|
-
offsets[i] = totalBytes;
|
|
1733
|
-
const s = values[indices[i]] != null ? String(values[indices[i]]) : "";
|
|
1734
|
-
const encoded = encoder.encode(s);
|
|
1735
|
-
strParts.push(encoded);
|
|
1736
|
-
totalBytes += encoded.length;
|
|
1737
|
-
}
|
|
1738
|
-
offsets[n] = totalBytes;
|
|
1739
|
-
const valueBuffer = new Uint8Array(totalBytes);
|
|
1740
|
-
let pos = 0;
|
|
1741
|
-
for (const sv of strParts) {
|
|
1742
|
-
valueBuffer.set(sv, pos);
|
|
1743
|
-
pos += sv.length;
|
|
1744
|
-
}
|
|
1745
|
-
const data = apacheArrow.makeData({
|
|
1746
|
-
type: new apacheArrow.Utf8(),
|
|
1747
|
-
length: n,
|
|
1748
|
-
valueOffsets: offsets,
|
|
1749
|
-
data: valueBuffer
|
|
1750
|
-
});
|
|
1751
|
-
fields.push(new apacheArrow.Field(name, new apacheArrow.Utf8(), true));
|
|
1752
|
-
dataArr.push(data);
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
return { fields, data: dataArr };
|
|
1756
|
-
}
|
|
1757
|
-
function buildSingleTable(geomType, wkbs, indices, attributes, b) {
|
|
1758
|
-
const n = wkbs.length;
|
|
1759
|
-
let geomData;
|
|
1760
|
-
switch (geomType) {
|
|
1761
|
-
case "point":
|
|
1762
|
-
geomData = buildPointData(wkbs, b);
|
|
1763
|
-
break;
|
|
1764
|
-
case "linestring":
|
|
1765
|
-
geomData = buildLineStringData(wkbs, b);
|
|
1766
|
-
break;
|
|
1767
|
-
case "polygon":
|
|
1768
|
-
geomData = buildPolygonData(wkbs, b);
|
|
1769
|
-
break;
|
|
1770
|
-
case "multipoint":
|
|
1771
|
-
geomData = buildMultiPointData(wkbs, b);
|
|
1772
|
-
break;
|
|
1773
|
-
case "multilinestring":
|
|
1774
|
-
geomData = buildMultiLineStringData(wkbs, b);
|
|
1775
|
-
break;
|
|
1776
|
-
case "multipolygon":
|
|
1777
|
-
geomData = buildMultiPolygonData(wkbs, b);
|
|
1778
|
-
break;
|
|
1779
|
-
}
|
|
1780
|
-
const extensionName = EXTENSION_NAMES[geomType];
|
|
1781
|
-
const geomMetadata = /* @__PURE__ */ new Map([
|
|
1782
|
-
["ARROW:extension:name", extensionName],
|
|
1783
|
-
[
|
|
1784
|
-
"ARROW:extension:metadata",
|
|
1785
|
-
JSON.stringify({
|
|
1786
|
-
crs: {
|
|
1787
|
-
type: "name",
|
|
1788
|
-
properties: { name: "urn:ogc:def:crs:OGC:1.3:CRS84" }
|
|
1789
|
-
}
|
|
1790
|
-
})
|
|
1791
|
-
]
|
|
1792
|
-
]);
|
|
1793
|
-
const geomField = new apacheArrow.Field("geometry", geomData.type, false, geomMetadata);
|
|
1794
|
-
const attrCols = buildAttributeColumns(indices, attributes);
|
|
1795
|
-
const fields = [geomField, ...attrCols.fields];
|
|
1796
|
-
const childrenData = [geomData, ...attrCols.data];
|
|
1797
|
-
const arrowSchema = new apacheArrow.Schema(fields);
|
|
1798
|
-
const structType = new apacheArrow.Struct(fields);
|
|
1799
|
-
const structData = apacheArrow.makeData({
|
|
1800
|
-
type: structType,
|
|
1801
|
-
length: n,
|
|
1802
|
-
nullCount: 0,
|
|
1803
|
-
children: childrenData
|
|
1804
|
-
});
|
|
1805
|
-
const batch = new apacheArrow.RecordBatch(arrowSchema, structData);
|
|
1806
|
-
const table = new apacheArrow.Table(arrowSchema, batch);
|
|
1807
|
-
return {
|
|
1808
|
-
table,
|
|
1809
|
-
geometryType: geomType,
|
|
1810
|
-
bounds: [b.minX, b.minY, b.maxX, b.maxY],
|
|
1811
|
-
sourceIndices: indices
|
|
1812
|
-
};
|
|
1813
|
-
}
|
|
1814
|
-
function buildGeoArrowTables(wkbArrays, attributes, knownGeomType) {
|
|
1815
|
-
if (wkbArrays.length === 0) return [];
|
|
1816
|
-
if (knownGeomType) {
|
|
1817
|
-
const globalBounds2 = newBounds();
|
|
1818
|
-
const indices = Array.from({ length: wkbArrays.length }, (_, i) => i);
|
|
1819
|
-
const result = buildSingleTable(knownGeomType, wkbArrays, indices, attributes, globalBounds2);
|
|
1820
|
-
return [result];
|
|
1821
|
-
}
|
|
1822
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1823
|
-
for (let i = 0; i < wkbArrays.length; i++) {
|
|
1824
|
-
const geomType = classifyWkbType(wkbArrays[i]);
|
|
1825
|
-
if (!geomType) continue;
|
|
1826
|
-
let group = groups.get(geomType);
|
|
1827
|
-
if (!group) {
|
|
1828
|
-
group = { wkbs: [], indices: [] };
|
|
1829
|
-
groups.set(geomType, group);
|
|
1830
|
-
}
|
|
1831
|
-
group.wkbs.push(wkbArrays[i]);
|
|
1832
|
-
group.indices.push(i);
|
|
1833
|
-
}
|
|
1834
|
-
if (groups.size === 0) return [];
|
|
1835
|
-
const globalBounds = newBounds();
|
|
1836
|
-
const results = [];
|
|
1837
|
-
for (const [geomType, { wkbs, indices }] of groups) {
|
|
1838
|
-
const result = buildSingleTable(geomType, wkbs, indices, attributes, globalBounds);
|
|
1839
|
-
results.push(result);
|
|
1840
|
-
}
|
|
1841
|
-
const mergedBounds = [
|
|
1842
|
-
globalBounds.minX,
|
|
1843
|
-
globalBounds.minY,
|
|
1844
|
-
globalBounds.maxX,
|
|
1845
|
-
globalBounds.maxY
|
|
1846
|
-
];
|
|
1847
|
-
for (const r of results) r.bounds = mergedBounds;
|
|
1848
|
-
return results;
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
// ../../src/lib/utils/hex.ts
|
|
1852
|
-
function generateHexDump(data, bytesPerRow = 16) {
|
|
1853
|
-
const rows = [];
|
|
1854
|
-
for (let i = 0; i < data.length; i += bytesPerRow) {
|
|
1855
|
-
const slice = data.slice(i, i + bytesPerRow);
|
|
1856
|
-
const offset = i.toString(16).padStart(8, "0");
|
|
1857
|
-
const hex = [];
|
|
1858
|
-
for (let j = 0; j < bytesPerRow; j++) {
|
|
1859
|
-
if (j < slice.length) {
|
|
1860
|
-
hex.push(slice[j].toString(16).padStart(2, "0"));
|
|
1861
|
-
} else {
|
|
1862
|
-
hex.push(" ");
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
let ascii = "";
|
|
1866
|
-
for (let j = 0; j < slice.length; j++) {
|
|
1867
|
-
const byte = slice[j];
|
|
1868
|
-
ascii += byte >= 32 && byte <= 126 ? String.fromCharCode(byte) : ".";
|
|
1869
|
-
}
|
|
1870
|
-
rows.push({ offset, hex, ascii });
|
|
1871
|
-
}
|
|
1872
|
-
return rows;
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
// ../../src/lib/utils/parquet-metadata.ts
|
|
1876
|
-
function mapParquetType(col) {
|
|
1877
|
-
const lt = col.logical_type;
|
|
1878
|
-
if (lt) {
|
|
1879
|
-
if (lt.type === "GEOMETRY" || lt.type === "GEOGRAPHY") return "GEOMETRY";
|
|
1880
|
-
if (lt.type === "STRING" || lt.type === "UTF8") return "VARCHAR";
|
|
1881
|
-
if (lt.type === "JSON") return "JSON";
|
|
1882
|
-
if (lt.type === "UUID") return "UUID";
|
|
1883
|
-
if (lt.type === "ENUM") return "VARCHAR";
|
|
1884
|
-
if (lt.type === "INT" || lt.type === "INTEGER") {
|
|
1885
|
-
const bits = lt.bitWidth ?? 32;
|
|
1886
|
-
const signed = lt.isSigned !== false;
|
|
1887
|
-
if (bits <= 8) return signed ? "TINYINT" : "UTINYINT";
|
|
1888
|
-
if (bits <= 16) return signed ? "SMALLINT" : "USMALLINT";
|
|
1889
|
-
if (bits <= 32) return signed ? "INTEGER" : "UINTEGER";
|
|
1890
|
-
return signed ? "BIGINT" : "UBIGINT";
|
|
1891
|
-
}
|
|
1892
|
-
if (lt.type === "DECIMAL") return `DECIMAL(${lt.precision ?? 18},${lt.scale ?? 0})`;
|
|
1893
|
-
if (lt.type === "DATE") return "DATE";
|
|
1894
|
-
if (lt.type === "TIME") return "TIME";
|
|
1895
|
-
if (lt.type === "TIMESTAMP") return "TIMESTAMP";
|
|
1896
|
-
if (lt.type === "BSON") return "BLOB";
|
|
1897
|
-
}
|
|
1898
|
-
const ct = col.converted_type;
|
|
1899
|
-
if (ct === "UTF8") return "VARCHAR";
|
|
1900
|
-
if (ct === "JSON") return "JSON";
|
|
1901
|
-
if (ct === "DATE") return "DATE";
|
|
1902
|
-
if (ct === "TIMESTAMP_MILLIS" || ct === "TIMESTAMP_MICROS") return "TIMESTAMP";
|
|
1903
|
-
if (ct === "DECIMAL") return `DECIMAL(${col.precision ?? 18},${col.scale ?? 0})`;
|
|
1904
|
-
if (ct === "INT_8") return "TINYINT";
|
|
1905
|
-
if (ct === "INT_16") return "SMALLINT";
|
|
1906
|
-
if (ct === "INT_32") return "INTEGER";
|
|
1907
|
-
if (ct === "INT_64") return "BIGINT";
|
|
1908
|
-
if (ct === "UINT_8") return "UTINYINT";
|
|
1909
|
-
if (ct === "UINT_16") return "USMALLINT";
|
|
1910
|
-
if (ct === "UINT_32") return "UINTEGER";
|
|
1911
|
-
if (ct === "UINT_64") return "UBIGINT";
|
|
1912
|
-
const pt = col.type;
|
|
1913
|
-
if (pt === "BOOLEAN") return "BOOLEAN";
|
|
1914
|
-
if (pt === "INT32") return "INTEGER";
|
|
1915
|
-
if (pt === "INT64") return "BIGINT";
|
|
1916
|
-
if (pt === "INT96") return "TIMESTAMP";
|
|
1917
|
-
if (pt === "FLOAT") return "FLOAT";
|
|
1918
|
-
if (pt === "DOUBLE") return "DOUBLE";
|
|
1919
|
-
if (pt === "BYTE_ARRAY") return "BLOB";
|
|
1920
|
-
if (pt === "FIXED_LEN_BYTE_ARRAY") return "BLOB";
|
|
1921
|
-
return "VARCHAR";
|
|
1922
|
-
}
|
|
1923
|
-
async function readParquetMetadata(url) {
|
|
1924
|
-
const { parquetMetadataAsync, asyncBufferFromUrl } = await import('hyparquet');
|
|
1925
|
-
const file = await asyncBufferFromUrl({ url });
|
|
1926
|
-
const metadata = await parquetMetadataAsync(file);
|
|
1927
|
-
const rowCount = metadata.row_groups.reduce(
|
|
1928
|
-
(sum, rg) => sum + Number(rg.num_rows),
|
|
1929
|
-
0
|
|
1930
|
-
);
|
|
1931
|
-
const schema = metadata.schema.slice(1).filter((col) => col.num_children === void 0).map((col) => ({
|
|
1932
|
-
name: col.name,
|
|
1933
|
-
type: mapParquetType(col)
|
|
1934
|
-
}));
|
|
1935
|
-
let geo = null;
|
|
1936
|
-
let legacyGeoParquet = false;
|
|
1937
|
-
const geoKv = metadata.key_value_metadata?.find((kv) => kv.key === "geo");
|
|
1938
|
-
if (geoKv) {
|
|
1939
|
-
try {
|
|
1940
|
-
const geoJson = JSON.parse(geoKv.value ?? "");
|
|
1941
|
-
if (geoJson.schema_version && !geoJson.version) {
|
|
1942
|
-
legacyGeoParquet = true;
|
|
1943
|
-
}
|
|
1944
|
-
geo = {
|
|
1945
|
-
primaryColumn: geoJson.primary_column ?? "geometry",
|
|
1946
|
-
columns: {}
|
|
1947
|
-
};
|
|
1948
|
-
if (geoJson.columns) {
|
|
1949
|
-
for (const [colName, colMeta] of Object.entries(geoJson.columns)) {
|
|
1950
|
-
geo.columns[colName] = {
|
|
1951
|
-
encoding: colMeta.encoding ?? "WKB",
|
|
1952
|
-
geometryTypes: colMeta.geometry_types ?? [],
|
|
1953
|
-
crs: colMeta.crs ?? null,
|
|
1954
|
-
bbox: colMeta.bbox
|
|
1955
|
-
};
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
} catch {
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
const createdBy = metadata.created_by ?? null;
|
|
1962
|
-
const numRowGroups = metadata.row_groups.length;
|
|
1963
|
-
let compression = null;
|
|
1964
|
-
if (numRowGroups > 0 && metadata.row_groups[0].columns) {
|
|
1965
|
-
const codecs = /* @__PURE__ */ new Set();
|
|
1966
|
-
for (const col of metadata.row_groups[0].columns) {
|
|
1967
|
-
const codec = col.meta_data?.codec;
|
|
1968
|
-
if (codec) codecs.add(codec);
|
|
1969
|
-
}
|
|
1970
|
-
if (codecs.size === 1) {
|
|
1971
|
-
compression = [...codecs][0];
|
|
1972
|
-
} else if (codecs.size > 1) {
|
|
1973
|
-
compression = [...codecs].join(", ");
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
return { rowCount, schema, geo, legacyGeoParquet, createdBy, numRowGroups, compression };
|
|
1977
|
-
}
|
|
1978
|
-
function extractEpsgFromGeoMeta(geo) {
|
|
1979
|
-
const primaryCol = geo.columns[geo.primaryColumn];
|
|
1980
|
-
if (!primaryCol?.crs) return null;
|
|
1981
|
-
const crs = primaryCol.crs;
|
|
1982
|
-
if (crs.type === "name" && crs.properties?.name?.includes("CRS84")) return null;
|
|
1983
|
-
if (crs.id?.authority === "EPSG") {
|
|
1984
|
-
const code = crs.id.code;
|
|
1985
|
-
if (WGS84_CODES.has(code)) return null;
|
|
1986
|
-
return `EPSG:${code}`;
|
|
1987
|
-
}
|
|
1988
|
-
return null;
|
|
1989
|
-
}
|
|
1990
|
-
function extractGeometryTypes(geo) {
|
|
1991
|
-
const primaryCol = geo.columns[geo.primaryColumn];
|
|
1992
|
-
if (!primaryCol?.geometryTypes?.length) return [];
|
|
1993
|
-
const typeMap = {
|
|
1994
|
-
Point: "point",
|
|
1995
|
-
LineString: "linestring",
|
|
1996
|
-
Polygon: "polygon",
|
|
1997
|
-
MultiPoint: "multipoint",
|
|
1998
|
-
MultiLineString: "multilinestring",
|
|
1999
|
-
MultiPolygon: "multipolygon"
|
|
2000
|
-
};
|
|
2001
|
-
const types = [];
|
|
2002
|
-
for (const raw of primaryCol.geometryTypes) {
|
|
2003
|
-
const base = raw.split(" ")[0];
|
|
2004
|
-
const mapped = typeMap[base];
|
|
2005
|
-
if (mapped && !types.includes(mapped)) types.push(mapped);
|
|
2006
|
-
}
|
|
2007
|
-
return types;
|
|
2008
|
-
}
|
|
2009
|
-
function extractBounds(geo) {
|
|
2010
|
-
const primaryCol = geo.columns[geo.primaryColumn];
|
|
2011
|
-
if (!primaryCol?.bbox || primaryCol.bbox.length < 4) return null;
|
|
2012
|
-
return [primaryCol.bbox[0], primaryCol.bbox[1], primaryCol.bbox[2], primaryCol.bbox[3]];
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
1067
|
// ../../src/lib/storage/providers.ts
|
|
2016
1068
|
var PROVIDERS = {
|
|
2017
1069
|
s3: {
|
|
@@ -2271,7 +1323,1165 @@ var PROVIDERS = {
|
|
|
2271
1323
|
endpointPlaceholder: "https://s3.gra.io.cloud.ovh.net",
|
|
2272
1324
|
schemes: []
|
|
2273
1325
|
}
|
|
2274
|
-
};
|
|
1326
|
+
};
|
|
1327
|
+
var PROVIDER_IDS = [
|
|
1328
|
+
"s3",
|
|
1329
|
+
"gcs",
|
|
1330
|
+
"r2",
|
|
1331
|
+
"azure",
|
|
1332
|
+
"b2",
|
|
1333
|
+
"digitalocean",
|
|
1334
|
+
"wasabi",
|
|
1335
|
+
"storj",
|
|
1336
|
+
"hetzner",
|
|
1337
|
+
"contabo",
|
|
1338
|
+
"linode",
|
|
1339
|
+
"ovhcloud",
|
|
1340
|
+
"minio"
|
|
1341
|
+
];
|
|
1342
|
+
function getProvider(id) {
|
|
1343
|
+
return PROVIDERS[id] ?? PROVIDERS.s3;
|
|
1344
|
+
}
|
|
1345
|
+
function buildEndpointFromTemplate(id, region) {
|
|
1346
|
+
const def = PROVIDERS[id];
|
|
1347
|
+
if (!def?.endpointTemplate) return "";
|
|
1348
|
+
return def.endpointTemplate.replace("{region}", region);
|
|
1349
|
+
}
|
|
1350
|
+
function buildProviderBaseUrl(provider, endpoint, bucket, region) {
|
|
1351
|
+
if (endpoint) {
|
|
1352
|
+
return `${endpoint.replace(/\/$/, "")}/${bucket}`;
|
|
1353
|
+
}
|
|
1354
|
+
const def = PROVIDERS[provider];
|
|
1355
|
+
if (def?.endpointTemplate) {
|
|
1356
|
+
const resolved = def.endpointTemplate.replace("{region}", region || def.defaultRegion);
|
|
1357
|
+
return `${resolved}/${bucket}`;
|
|
1358
|
+
}
|
|
1359
|
+
return `https://s3.${region || "us-east-1"}.amazonaws.com/${bucket}`;
|
|
1360
|
+
}
|
|
1361
|
+
function isGcsProvider(provider, endpoint) {
|
|
1362
|
+
return provider === "gcs" || !!endpoint && /storage\.googleapis\.com/i.test(endpoint);
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// ../../src/lib/storage/url-adapter.ts
|
|
1366
|
+
var UrlAdapter = class {
|
|
1367
|
+
supportsWrite = false;
|
|
1368
|
+
async read(url, offset, length, signal) {
|
|
1369
|
+
const headers = {};
|
|
1370
|
+
if (offset !== void 0 && length !== void 0) {
|
|
1371
|
+
headers.Range = `bytes=${offset}-${offset + length - 1}`;
|
|
1372
|
+
} else if (offset !== void 0) {
|
|
1373
|
+
headers.Range = `bytes=${offset}-`;
|
|
1374
|
+
}
|
|
1375
|
+
const res = await fetch(url, { headers, signal });
|
|
1376
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
1377
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
1378
|
+
}
|
|
1379
|
+
async head(url, signal) {
|
|
1380
|
+
const res = await fetch(url, { method: "HEAD", signal });
|
|
1381
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
1382
|
+
const name = url.split("/").pop()?.split("?")[0] || "file";
|
|
1383
|
+
const ext = name.includes(".") ? name.split(".").pop().toLowerCase() : "";
|
|
1384
|
+
return {
|
|
1385
|
+
name,
|
|
1386
|
+
path: url,
|
|
1387
|
+
is_dir: false,
|
|
1388
|
+
size: Number(res.headers.get("content-length") || 0),
|
|
1389
|
+
modified: new Date(res.headers.get("last-modified") || 0).getTime(),
|
|
1390
|
+
extension: ext
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
async list() {
|
|
1394
|
+
return [];
|
|
1395
|
+
}
|
|
1396
|
+
async put() {
|
|
1397
|
+
throw new Error("Write not supported for direct URL sources");
|
|
1398
|
+
}
|
|
1399
|
+
async delete() {
|
|
1400
|
+
throw new Error("Delete not supported for direct URL sources");
|
|
1401
|
+
}
|
|
1402
|
+
async deletePrefix() {
|
|
1403
|
+
throw new Error("Delete not supported for direct URL sources");
|
|
1404
|
+
}
|
|
1405
|
+
async copy() {
|
|
1406
|
+
throw new Error("Copy not supported for direct URL sources");
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
// ../../src/lib/utils/cloud-url.ts
|
|
1411
|
+
var AWS_REGION_RE = /^(us|eu|ap|sa|ca|me|af|il)-(north|south|east|west|central|northeast|southeast|northwest|southwest)-\d+/;
|
|
1412
|
+
function getNativeScheme(provider) {
|
|
1413
|
+
const def = PROVIDERS[provider];
|
|
1414
|
+
if (def?.schemes.length) return def.schemes[0];
|
|
1415
|
+
return "s3";
|
|
1416
|
+
}
|
|
1417
|
+
function safeDecodeURIComponent(s) {
|
|
1418
|
+
try {
|
|
1419
|
+
return decodeURIComponent(s);
|
|
1420
|
+
} catch {
|
|
1421
|
+
return s;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
function resolveCloudUrl(url) {
|
|
1425
|
+
const s3Match = url.match(/^s3[an]?:\/\/([^/]+)\/?(.*)$/);
|
|
1426
|
+
if (s3Match) {
|
|
1427
|
+
const [, bucket, key] = s3Match;
|
|
1428
|
+
const regionMatch = bucket.match(AWS_REGION_RE);
|
|
1429
|
+
const region = regionMatch ? regionMatch[0] : "us-east-1";
|
|
1430
|
+
const base = buildProviderBaseUrl("s3", "", bucket, region);
|
|
1431
|
+
return key ? `${base}/${key}` : base;
|
|
1432
|
+
}
|
|
1433
|
+
const gcsMatch = url.match(/^gcs?:\/\/([^/]+)\/?(.*)$/);
|
|
1434
|
+
if (gcsMatch) {
|
|
1435
|
+
const [, bucket, key] = gcsMatch;
|
|
1436
|
+
const base = buildProviderBaseUrl("gcs", "", bucket, "");
|
|
1437
|
+
return key ? `${base}/${key}` : base;
|
|
1438
|
+
}
|
|
1439
|
+
return url;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
// ../../src/lib/utils/column-types.ts
|
|
1443
|
+
var NUMBER_TYPES = [
|
|
1444
|
+
"TINYINT",
|
|
1445
|
+
"SMALLINT",
|
|
1446
|
+
"INTEGER",
|
|
1447
|
+
"BIGINT",
|
|
1448
|
+
"HUGEINT",
|
|
1449
|
+
"UTINYINT",
|
|
1450
|
+
"USMALLINT",
|
|
1451
|
+
"UINTEGER",
|
|
1452
|
+
"UBIGINT",
|
|
1453
|
+
"FLOAT",
|
|
1454
|
+
"DOUBLE",
|
|
1455
|
+
"DECIMAL",
|
|
1456
|
+
"NUMERIC",
|
|
1457
|
+
"REAL",
|
|
1458
|
+
"INT",
|
|
1459
|
+
"INT1",
|
|
1460
|
+
"INT2",
|
|
1461
|
+
"INT4",
|
|
1462
|
+
"INT8",
|
|
1463
|
+
"SIGNED",
|
|
1464
|
+
"SHORT",
|
|
1465
|
+
"LONG"
|
|
1466
|
+
];
|
|
1467
|
+
var STRING_TYPES = ["VARCHAR", "TEXT", "STRING", "CHAR", "BPCHAR", "NAME", "UUID", "ENUM"];
|
|
1468
|
+
var DATE_TYPES = [
|
|
1469
|
+
"DATE",
|
|
1470
|
+
"TIME",
|
|
1471
|
+
"TIMESTAMP",
|
|
1472
|
+
"TIMESTAMP_S",
|
|
1473
|
+
"TIMESTAMP_MS",
|
|
1474
|
+
"TIMESTAMP_NS",
|
|
1475
|
+
"TIMESTAMP WITH TIME ZONE",
|
|
1476
|
+
"TIMESTAMPTZ",
|
|
1477
|
+
"INTERVAL",
|
|
1478
|
+
"TIMESTAMP_TZ"
|
|
1479
|
+
];
|
|
1480
|
+
var BOOLEAN_TYPES = ["BOOLEAN", "BOOL", "LOGICAL"];
|
|
1481
|
+
var GEO_TYPES = [
|
|
1482
|
+
"GEOMETRY",
|
|
1483
|
+
"POINT",
|
|
1484
|
+
"LINESTRING",
|
|
1485
|
+
"POLYGON",
|
|
1486
|
+
"MULTIPOINT",
|
|
1487
|
+
"MULTILINESTRING",
|
|
1488
|
+
"MULTIPOLYGON",
|
|
1489
|
+
"GEOMETRYCOLLECTION",
|
|
1490
|
+
"WKB_GEOMETRY"
|
|
1491
|
+
];
|
|
1492
|
+
var BINARY_TYPES = ["BLOB", "BYTEA", "BINARY", "VARBINARY"];
|
|
1493
|
+
var JSON_TYPES = ["JSON", "JSONB"];
|
|
1494
|
+
function classifyType(duckdbType) {
|
|
1495
|
+
const upper = duckdbType.toUpperCase().trim();
|
|
1496
|
+
const base = upper.replace(/\(.*\)/, "").trim();
|
|
1497
|
+
if (NUMBER_TYPES.includes(base)) return "number";
|
|
1498
|
+
if (STRING_TYPES.includes(base)) return "string";
|
|
1499
|
+
if (DATE_TYPES.includes(base)) return "date";
|
|
1500
|
+
if (BOOLEAN_TYPES.includes(base)) return "boolean";
|
|
1501
|
+
if (GEO_TYPES.includes(base)) return "geo";
|
|
1502
|
+
if (BINARY_TYPES.includes(base)) return "binary";
|
|
1503
|
+
if (JSON_TYPES.includes(base)) return "json";
|
|
1504
|
+
if (base.startsWith("STRUCT") || base.startsWith("MAP") || base.startsWith("UNION"))
|
|
1505
|
+
return "json";
|
|
1506
|
+
if (base.endsWith("[]") || base.startsWith("LIST")) return "json";
|
|
1507
|
+
if (upper.includes("INT") || upper.includes("FLOAT") || upper.includes("DOUBLE") || upper.includes("DECIMAL") || upper.includes("NUMERIC"))
|
|
1508
|
+
return "number";
|
|
1509
|
+
if (upper.includes("CHAR") || upper.includes("TEXT") || upper.includes("STRING")) return "string";
|
|
1510
|
+
if (upper.includes("TIME") || upper.includes("DATE")) return "date";
|
|
1511
|
+
if (upper.includes("BOOL")) return "boolean";
|
|
1512
|
+
if (upper.includes("GEOMETRY") || upper.includes("GEO") || upper.includes("WKB")) return "geo";
|
|
1513
|
+
if (upper.includes("BLOB") || upper.includes("BINARY")) return "binary";
|
|
1514
|
+
if (upper.includes("JSON") || upper.includes("STRUCT") || upper.includes("MAP") || upper.includes("LIST"))
|
|
1515
|
+
return "json";
|
|
1516
|
+
return "other";
|
|
1517
|
+
}
|
|
1518
|
+
var TYPE_COLORS = {
|
|
1519
|
+
number: "text-blue-500",
|
|
1520
|
+
string: "text-green-500",
|
|
1521
|
+
date: "text-amber-500",
|
|
1522
|
+
boolean: "text-purple-500",
|
|
1523
|
+
geo: "text-teal-500",
|
|
1524
|
+
binary: "text-zinc-500",
|
|
1525
|
+
json: "text-orange-500",
|
|
1526
|
+
other: "text-zinc-400"
|
|
1527
|
+
};
|
|
1528
|
+
var TYPE_BADGE_CLASSES = {
|
|
1529
|
+
number: "bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20",
|
|
1530
|
+
string: "bg-green-500/10 text-green-600 dark:text-green-400 border-green-500/20",
|
|
1531
|
+
date: "bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20",
|
|
1532
|
+
boolean: "bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/20",
|
|
1533
|
+
geo: "bg-teal-500/10 text-teal-600 dark:text-teal-400 border-teal-500/20",
|
|
1534
|
+
binary: "bg-zinc-500/10 text-zinc-600 dark:text-zinc-400 border-zinc-500/20",
|
|
1535
|
+
json: "bg-orange-500/10 text-orange-600 dark:text-orange-400 border-orange-500/20",
|
|
1536
|
+
other: "bg-zinc-500/10 text-zinc-500 dark:text-zinc-400 border-zinc-500/20"
|
|
1537
|
+
};
|
|
1538
|
+
var TYPE_LABELS = {
|
|
1539
|
+
number: "#",
|
|
1540
|
+
string: "Aa",
|
|
1541
|
+
date: "dt",
|
|
1542
|
+
boolean: "T/F",
|
|
1543
|
+
geo: "geo",
|
|
1544
|
+
binary: "01",
|
|
1545
|
+
json: "{}",
|
|
1546
|
+
other: "?"
|
|
1547
|
+
};
|
|
1548
|
+
function typeColor(category) {
|
|
1549
|
+
return TYPE_COLORS[category];
|
|
1550
|
+
}
|
|
1551
|
+
function typeBadgeClass(category) {
|
|
1552
|
+
return TYPE_BADGE_CLASSES[category];
|
|
1553
|
+
}
|
|
1554
|
+
function typeLabel(category) {
|
|
1555
|
+
return TYPE_LABELS[category];
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// ../../src/lib/utils/error.ts
|
|
1559
|
+
function handleLoadError(err) {
|
|
1560
|
+
if (err instanceof DOMException && err.name === "AbortError") return null;
|
|
1561
|
+
return err instanceof Error ? err.message : String(err);
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
// ../../src/lib/utils/format.ts
|
|
1565
|
+
function formatFileSize(bytes) {
|
|
1566
|
+
if (bytes < 0) return "0 B";
|
|
1567
|
+
if (bytes === 0) return "0 B";
|
|
1568
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
1569
|
+
const base = 1024;
|
|
1570
|
+
const exponent = Math.min(Math.floor(Math.log(bytes) / Math.log(base)), units.length - 1);
|
|
1571
|
+
const value = bytes / base ** exponent;
|
|
1572
|
+
if (exponent === 0) return `${bytes} B`;
|
|
1573
|
+
return `${value.toFixed(1)} ${units[exponent]}`;
|
|
1574
|
+
}
|
|
1575
|
+
function formatDate(timestamp) {
|
|
1576
|
+
if (!timestamp || timestamp <= 0 || !Number.isFinite(timestamp)) return "--";
|
|
1577
|
+
const date = new Date(timestamp);
|
|
1578
|
+
const now = Date.now();
|
|
1579
|
+
const diffMs = now - timestamp;
|
|
1580
|
+
const diffSeconds = Math.floor(diffMs / 1e3);
|
|
1581
|
+
const diffMinutes = Math.floor(diffSeconds / 60);
|
|
1582
|
+
const diffHours = Math.floor(diffMinutes / 60);
|
|
1583
|
+
const diffDays = Math.floor(diffHours / 24);
|
|
1584
|
+
if (diffSeconds < 60) return "Just now";
|
|
1585
|
+
if (diffMinutes < 60) return `${diffMinutes}m ago`;
|
|
1586
|
+
if (diffHours < 24) return `${diffHours}h ago`;
|
|
1587
|
+
if (diffDays < 7) return `${diffDays}d ago`;
|
|
1588
|
+
return date.toLocaleDateString(void 0, {
|
|
1589
|
+
year: "numeric",
|
|
1590
|
+
month: "short",
|
|
1591
|
+
day: "numeric"
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
function getFileExtension(filename) {
|
|
1595
|
+
const lastDot = filename.lastIndexOf(".");
|
|
1596
|
+
if (lastDot <= 0) return "";
|
|
1597
|
+
return filename.slice(lastDot).toLowerCase();
|
|
1598
|
+
}
|
|
1599
|
+
function jsonReplacerBigInt(_key, value) {
|
|
1600
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
1601
|
+
}
|
|
1602
|
+
function formatValue(value) {
|
|
1603
|
+
if (value === null || value === void 0) return "NULL";
|
|
1604
|
+
if (value instanceof Date) return value.toISOString();
|
|
1605
|
+
if (typeof value === "bigint") return value.toString();
|
|
1606
|
+
if (typeof value === "object") return JSON.stringify(value, jsonReplacerBigInt);
|
|
1607
|
+
return String(value);
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
// ../../src/lib/utils/export.ts
|
|
1611
|
+
function formatCellValue(value) {
|
|
1612
|
+
if (value === null || value === void 0) return "";
|
|
1613
|
+
if (value instanceof Date) return value.toISOString();
|
|
1614
|
+
if (typeof value === "bigint") return value.toString();
|
|
1615
|
+
if (typeof value === "object") return JSON.stringify(value, jsonReplacerBigInt);
|
|
1616
|
+
return String(value);
|
|
1617
|
+
}
|
|
1618
|
+
function escapeCsvField(value) {
|
|
1619
|
+
if (value.includes(",") || value.includes('"') || value.includes("\n") || value.includes("\r")) {
|
|
1620
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
1621
|
+
}
|
|
1622
|
+
return value;
|
|
1623
|
+
}
|
|
1624
|
+
function serializeToCsv(columns, rows) {
|
|
1625
|
+
const header = columns.map(escapeCsvField).join(",");
|
|
1626
|
+
const body = rows.map((row) => columns.map((col) => escapeCsvField(formatCellValue(row[col]))).join(",")).join("\n");
|
|
1627
|
+
return `${header}
|
|
1628
|
+
${body}`;
|
|
1629
|
+
}
|
|
1630
|
+
function serializeToJson(columns, rows) {
|
|
1631
|
+
const data = rows.map((row) => {
|
|
1632
|
+
const obj = {};
|
|
1633
|
+
for (const col of columns) {
|
|
1634
|
+
const val = row[col];
|
|
1635
|
+
if (val instanceof Date) {
|
|
1636
|
+
obj[col] = val.toISOString();
|
|
1637
|
+
} else {
|
|
1638
|
+
obj[col] = val ?? null;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
return obj;
|
|
1642
|
+
});
|
|
1643
|
+
return JSON.stringify(data, jsonReplacerBigInt, 2);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
// ../../src/lib/utils/file-sort.ts
|
|
1647
|
+
function sortFileEntries(entries, config) {
|
|
1648
|
+
const sorted = [...entries];
|
|
1649
|
+
const dir = config.direction === "asc" ? 1 : -1;
|
|
1650
|
+
sorted.sort((a, b) => {
|
|
1651
|
+
if (a.is_dir && !b.is_dir) return -1;
|
|
1652
|
+
if (!a.is_dir && b.is_dir) return 1;
|
|
1653
|
+
switch (config.field) {
|
|
1654
|
+
case "name":
|
|
1655
|
+
return dir * a.name.localeCompare(b.name, void 0, { sensitivity: "base" });
|
|
1656
|
+
case "size":
|
|
1657
|
+
return dir * (a.size - b.size);
|
|
1658
|
+
case "modified":
|
|
1659
|
+
return dir * (a.modified - b.modified);
|
|
1660
|
+
case "extension":
|
|
1661
|
+
return dir * a.extension.localeCompare(b.extension, void 0, { sensitivity: "base" });
|
|
1662
|
+
default:
|
|
1663
|
+
return 0;
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
return sorted;
|
|
1667
|
+
}
|
|
1668
|
+
function toggleSortField(current, field) {
|
|
1669
|
+
if (current.field === field) {
|
|
1670
|
+
return { field, direction: current.direction === "asc" ? "desc" : "asc" };
|
|
1671
|
+
}
|
|
1672
|
+
return { field, direction: "asc" };
|
|
1673
|
+
}
|
|
1674
|
+
function normalizeGeomType(raw) {
|
|
1675
|
+
const s = raw.toUpperCase().replace(/\s+/g, "");
|
|
1676
|
+
if (s === "POINT") return "point";
|
|
1677
|
+
if (s === "LINESTRING") return "linestring";
|
|
1678
|
+
if (s === "POLYGON") return "polygon";
|
|
1679
|
+
if (s === "MULTIPOINT") return "multipoint";
|
|
1680
|
+
if (s === "MULTILINESTRING") return "multilinestring";
|
|
1681
|
+
if (s === "MULTIPOLYGON") return "multipolygon";
|
|
1682
|
+
return "polygon";
|
|
1683
|
+
}
|
|
1684
|
+
var EXTENSION_NAMES = {
|
|
1685
|
+
point: "geoarrow.point",
|
|
1686
|
+
linestring: "geoarrow.linestring",
|
|
1687
|
+
polygon: "geoarrow.polygon",
|
|
1688
|
+
multipoint: "geoarrow.multipoint",
|
|
1689
|
+
multilinestring: "geoarrow.multilinestring",
|
|
1690
|
+
multipolygon: "geoarrow.multipolygon"
|
|
1691
|
+
};
|
|
1692
|
+
function readWkbHeader(wkb) {
|
|
1693
|
+
if (wkb.length < 5) return null;
|
|
1694
|
+
const le = wkb[0] === 1;
|
|
1695
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1696
|
+
const rawType = dv.getUint32(1, le);
|
|
1697
|
+
let headerSize = 5;
|
|
1698
|
+
if ((rawType & 536870912) !== 0) headerSize += 4;
|
|
1699
|
+
const ewkbZ = (rawType & 2147483648) !== 0;
|
|
1700
|
+
const ewkbM = (rawType & 1073741824) !== 0;
|
|
1701
|
+
let type = rawType & 268435455;
|
|
1702
|
+
let isoZ = false;
|
|
1703
|
+
let isoM = false;
|
|
1704
|
+
if (type > 3e3) {
|
|
1705
|
+
isoZ = true;
|
|
1706
|
+
isoM = true;
|
|
1707
|
+
type -= 3e3;
|
|
1708
|
+
} else if (type > 2e3) {
|
|
1709
|
+
isoM = true;
|
|
1710
|
+
type -= 2e3;
|
|
1711
|
+
} else if (type > 1e3) {
|
|
1712
|
+
isoZ = true;
|
|
1713
|
+
type -= 1e3;
|
|
1714
|
+
}
|
|
1715
|
+
const dims = (ewkbZ || isoZ ? 1 : 0) + (ewkbM || isoM ? 1 : 0);
|
|
1716
|
+
const coordStride = (2 + dims) * 8;
|
|
1717
|
+
return { type, le, coordStride, dataOffset: headerSize };
|
|
1718
|
+
}
|
|
1719
|
+
function classifyWkbType(wkb) {
|
|
1720
|
+
const h = readWkbHeader(wkb);
|
|
1721
|
+
if (!h) return null;
|
|
1722
|
+
switch (h.type) {
|
|
1723
|
+
case 1:
|
|
1724
|
+
return "point";
|
|
1725
|
+
case 2:
|
|
1726
|
+
return "linestring";
|
|
1727
|
+
case 3:
|
|
1728
|
+
return "polygon";
|
|
1729
|
+
case 4:
|
|
1730
|
+
return "multipoint";
|
|
1731
|
+
case 5:
|
|
1732
|
+
return "multilinestring";
|
|
1733
|
+
case 6:
|
|
1734
|
+
return "multipolygon";
|
|
1735
|
+
default:
|
|
1736
|
+
return null;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
function newBounds() {
|
|
1740
|
+
return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
|
|
1741
|
+
}
|
|
1742
|
+
function expandBounds(b, x, y) {
|
|
1743
|
+
if (Number.isNaN(x) || Number.isNaN(y)) return;
|
|
1744
|
+
if (x < b.minX) b.minX = x;
|
|
1745
|
+
if (y < b.minY) b.minY = y;
|
|
1746
|
+
if (x > b.maxX) b.maxX = x;
|
|
1747
|
+
if (y > b.maxY) b.maxY = y;
|
|
1748
|
+
}
|
|
1749
|
+
var coordField = new apacheArrow.Field("xy", new apacheArrow.Float64());
|
|
1750
|
+
var coordType = new apacheArrow.FixedSizeList(2, coordField);
|
|
1751
|
+
function makeCoordData(coords, numPoints) {
|
|
1752
|
+
const floatData = apacheArrow.makeData({ type: new apacheArrow.Float64(), length: coords.length, data: coords });
|
|
1753
|
+
return apacheArrow.makeData({ type: coordType, length: numPoints, nullCount: 0, child: floatData });
|
|
1754
|
+
}
|
|
1755
|
+
function buildPointData(wkbs, b) {
|
|
1756
|
+
const n = wkbs.length;
|
|
1757
|
+
const coords = new Float64Array(n * 2);
|
|
1758
|
+
for (let i = 0; i < n; i++) {
|
|
1759
|
+
const wkb = wkbs[i];
|
|
1760
|
+
const h = readWkbHeader(wkb);
|
|
1761
|
+
if (!h || h.type !== 1) {
|
|
1762
|
+
coords[i * 2] = 0;
|
|
1763
|
+
coords[i * 2 + 1] = 0;
|
|
1764
|
+
continue;
|
|
1765
|
+
}
|
|
1766
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1767
|
+
const x = dv.getFloat64(h.dataOffset, h.le);
|
|
1768
|
+
const y = dv.getFloat64(h.dataOffset + 8, h.le);
|
|
1769
|
+
coords[i * 2] = x;
|
|
1770
|
+
coords[i * 2 + 1] = y;
|
|
1771
|
+
expandBounds(b, x, y);
|
|
1772
|
+
}
|
|
1773
|
+
return makeCoordData(coords, n);
|
|
1774
|
+
}
|
|
1775
|
+
function buildLineStringData(wkbs, b) {
|
|
1776
|
+
const n = wkbs.length;
|
|
1777
|
+
const geomOffsets = new Int32Array(n + 1);
|
|
1778
|
+
let totalCoords = 0;
|
|
1779
|
+
for (let i = 0; i < n; i++) {
|
|
1780
|
+
geomOffsets[i] = totalCoords;
|
|
1781
|
+
const h = readWkbHeader(wkbs[i]);
|
|
1782
|
+
if (!h || h.type !== 2) continue;
|
|
1783
|
+
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1784
|
+
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1785
|
+
totalCoords += numPts;
|
|
1786
|
+
}
|
|
1787
|
+
geomOffsets[n] = totalCoords;
|
|
1788
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
1789
|
+
let ci = 0;
|
|
1790
|
+
for (const wkb of wkbs) {
|
|
1791
|
+
const h = readWkbHeader(wkb);
|
|
1792
|
+
if (!h || h.type !== 2) continue;
|
|
1793
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1794
|
+
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1795
|
+
let off = h.dataOffset + 4;
|
|
1796
|
+
for (let j = 0; j < numPts; j++) {
|
|
1797
|
+
const x = dv.getFloat64(off, h.le);
|
|
1798
|
+
const y = dv.getFloat64(off + 8, h.le);
|
|
1799
|
+
coords[ci++] = x;
|
|
1800
|
+
coords[ci++] = y;
|
|
1801
|
+
expandBounds(b, x, y);
|
|
1802
|
+
off += h.coordStride;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
const fslData = makeCoordData(coords, totalCoords);
|
|
1806
|
+
const listType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
1807
|
+
return apacheArrow.makeData({
|
|
1808
|
+
type: listType,
|
|
1809
|
+
length: n,
|
|
1810
|
+
nullCount: 0,
|
|
1811
|
+
valueOffsets: geomOffsets,
|
|
1812
|
+
child: fslData
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
function buildPolygonData(wkbs, b) {
|
|
1816
|
+
const n = wkbs.length;
|
|
1817
|
+
const geomOffsets = new Int32Array(n + 1);
|
|
1818
|
+
let totalRings = 0;
|
|
1819
|
+
let totalCoords = 0;
|
|
1820
|
+
for (let i = 0; i < n; i++) {
|
|
1821
|
+
geomOffsets[i] = totalRings;
|
|
1822
|
+
const h = readWkbHeader(wkbs[i]);
|
|
1823
|
+
if (!h || h.type !== 3) continue;
|
|
1824
|
+
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1825
|
+
const numRings = dv.getUint32(h.dataOffset, h.le);
|
|
1826
|
+
let off = h.dataOffset + 4;
|
|
1827
|
+
for (let r = 0; r < numRings; r++) {
|
|
1828
|
+
const numPts = dv.getUint32(off, h.le);
|
|
1829
|
+
off += 4 + numPts * h.coordStride;
|
|
1830
|
+
totalCoords += numPts;
|
|
1831
|
+
totalRings++;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
geomOffsets[n] = totalRings;
|
|
1835
|
+
const ringOffsets = new Int32Array(totalRings + 1);
|
|
1836
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
1837
|
+
let ri = 0;
|
|
1838
|
+
let ci = 0;
|
|
1839
|
+
for (const wkb of wkbs) {
|
|
1840
|
+
const h = readWkbHeader(wkb);
|
|
1841
|
+
if (!h || h.type !== 3) continue;
|
|
1842
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1843
|
+
const numRings = dv.getUint32(h.dataOffset, h.le);
|
|
1844
|
+
let off = h.dataOffset + 4;
|
|
1845
|
+
for (let r = 0; r < numRings; r++) {
|
|
1846
|
+
ringOffsets[ri++] = ci >> 1;
|
|
1847
|
+
const numPts = dv.getUint32(off, h.le);
|
|
1848
|
+
off += 4;
|
|
1849
|
+
for (let j = 0; j < numPts; j++) {
|
|
1850
|
+
const x = dv.getFloat64(off, h.le);
|
|
1851
|
+
const y = dv.getFloat64(off + 8, h.le);
|
|
1852
|
+
coords[ci++] = x;
|
|
1853
|
+
coords[ci++] = y;
|
|
1854
|
+
expandBounds(b, x, y);
|
|
1855
|
+
off += h.coordStride;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
ringOffsets[totalRings] = ci >> 1;
|
|
1860
|
+
const coordCount = ci >> 1;
|
|
1861
|
+
const fslData = makeCoordData(coords, coordCount);
|
|
1862
|
+
const ringListType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
1863
|
+
const ringListData = apacheArrow.makeData({
|
|
1864
|
+
type: ringListType,
|
|
1865
|
+
length: totalRings,
|
|
1866
|
+
nullCount: 0,
|
|
1867
|
+
valueOffsets: ringOffsets,
|
|
1868
|
+
child: fslData
|
|
1869
|
+
});
|
|
1870
|
+
const polyType = new apacheArrow.List(new apacheArrow.Field("rings", ringListType));
|
|
1871
|
+
return apacheArrow.makeData({
|
|
1872
|
+
type: polyType,
|
|
1873
|
+
length: n,
|
|
1874
|
+
nullCount: 0,
|
|
1875
|
+
valueOffsets: geomOffsets,
|
|
1876
|
+
child: ringListData
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
function buildMultiPointData(wkbs, b) {
|
|
1880
|
+
const n = wkbs.length;
|
|
1881
|
+
const geomOffsets = new Int32Array(n + 1);
|
|
1882
|
+
let totalCoords = 0;
|
|
1883
|
+
for (let i = 0; i < n; i++) {
|
|
1884
|
+
geomOffsets[i] = totalCoords;
|
|
1885
|
+
const h = readWkbHeader(wkbs[i]);
|
|
1886
|
+
if (!h || h.type !== 4) continue;
|
|
1887
|
+
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1888
|
+
totalCoords += dv.getUint32(h.dataOffset, h.le);
|
|
1889
|
+
}
|
|
1890
|
+
geomOffsets[n] = totalCoords;
|
|
1891
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
1892
|
+
let ci = 0;
|
|
1893
|
+
for (const wkb of wkbs) {
|
|
1894
|
+
const h = readWkbHeader(wkb);
|
|
1895
|
+
if (!h || h.type !== 4) continue;
|
|
1896
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1897
|
+
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1898
|
+
let off = h.dataOffset + 4;
|
|
1899
|
+
for (let j = 0; j < numPts; j++) {
|
|
1900
|
+
const innerH = readWkbHeader(
|
|
1901
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1902
|
+
);
|
|
1903
|
+
if (innerH) {
|
|
1904
|
+
const x = dv.getFloat64(off + innerH.dataOffset, innerH.le);
|
|
1905
|
+
const y = dv.getFloat64(off + innerH.dataOffset + 8, innerH.le);
|
|
1906
|
+
coords[ci++] = x;
|
|
1907
|
+
coords[ci++] = y;
|
|
1908
|
+
expandBounds(b, x, y);
|
|
1909
|
+
off += innerH.dataOffset + innerH.coordStride;
|
|
1910
|
+
} else {
|
|
1911
|
+
coords[ci++] = 0;
|
|
1912
|
+
coords[ci++] = 0;
|
|
1913
|
+
off += 21;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
const fslData = makeCoordData(coords, totalCoords);
|
|
1918
|
+
const listType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
1919
|
+
return apacheArrow.makeData({
|
|
1920
|
+
type: listType,
|
|
1921
|
+
length: n,
|
|
1922
|
+
nullCount: 0,
|
|
1923
|
+
valueOffsets: geomOffsets,
|
|
1924
|
+
child: fslData
|
|
1925
|
+
});
|
|
1926
|
+
}
|
|
1927
|
+
function buildMultiLineStringData(wkbs, b) {
|
|
1928
|
+
const n = wkbs.length;
|
|
1929
|
+
const geomOffsetsArr = [0];
|
|
1930
|
+
let totalLines = 0;
|
|
1931
|
+
let totalCoords = 0;
|
|
1932
|
+
for (const wkb of wkbs) {
|
|
1933
|
+
const h = readWkbHeader(wkb);
|
|
1934
|
+
if (!h || h.type !== 5) {
|
|
1935
|
+
geomOffsetsArr.push(totalLines);
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1939
|
+
const numLines = dv.getUint32(h.dataOffset, h.le);
|
|
1940
|
+
let off = h.dataOffset + 4;
|
|
1941
|
+
for (let l = 0; l < numLines; l++) {
|
|
1942
|
+
const innerH = readWkbHeader(
|
|
1943
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1944
|
+
);
|
|
1945
|
+
if (!innerH) break;
|
|
1946
|
+
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
1947
|
+
const numPts = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
1948
|
+
totalCoords += numPts;
|
|
1949
|
+
off += innerH.dataOffset + 4 + numPts * innerH.coordStride;
|
|
1950
|
+
totalLines++;
|
|
1951
|
+
}
|
|
1952
|
+
geomOffsetsArr.push(totalLines);
|
|
1953
|
+
}
|
|
1954
|
+
const geomOffsets = new Int32Array(geomOffsetsArr);
|
|
1955
|
+
const lineOffsets = new Int32Array(totalLines + 1);
|
|
1956
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
1957
|
+
let li = 0;
|
|
1958
|
+
let ci = 0;
|
|
1959
|
+
for (const wkb of wkbs) {
|
|
1960
|
+
const h = readWkbHeader(wkb);
|
|
1961
|
+
if (!h || h.type !== 5) continue;
|
|
1962
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1963
|
+
const numLines = dv.getUint32(h.dataOffset, h.le);
|
|
1964
|
+
let off = h.dataOffset + 4;
|
|
1965
|
+
for (let l = 0; l < numLines; l++) {
|
|
1966
|
+
lineOffsets[li++] = ci >> 1;
|
|
1967
|
+
const innerH = readWkbHeader(
|
|
1968
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1969
|
+
);
|
|
1970
|
+
if (!innerH) break;
|
|
1971
|
+
const numPts = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off).getUint32(
|
|
1972
|
+
innerH.dataOffset,
|
|
1973
|
+
innerH.le
|
|
1974
|
+
);
|
|
1975
|
+
let ptOff = off + innerH.dataOffset + 4;
|
|
1976
|
+
for (let j = 0; j < numPts; j++) {
|
|
1977
|
+
const x = dv.getFloat64(ptOff, innerH.le);
|
|
1978
|
+
const y = dv.getFloat64(ptOff + 8, innerH.le);
|
|
1979
|
+
coords[ci++] = x;
|
|
1980
|
+
coords[ci++] = y;
|
|
1981
|
+
expandBounds(b, x, y);
|
|
1982
|
+
ptOff += innerH.coordStride;
|
|
1983
|
+
}
|
|
1984
|
+
off = ptOff;
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
lineOffsets[totalLines] = ci >> 1;
|
|
1988
|
+
const fslData = makeCoordData(coords, ci >> 1);
|
|
1989
|
+
const lineListType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
1990
|
+
const lineListData = apacheArrow.makeData({
|
|
1991
|
+
type: lineListType,
|
|
1992
|
+
length: totalLines,
|
|
1993
|
+
nullCount: 0,
|
|
1994
|
+
valueOffsets: lineOffsets,
|
|
1995
|
+
child: fslData
|
|
1996
|
+
});
|
|
1997
|
+
const multiLineType = new apacheArrow.List(new apacheArrow.Field("lines", lineListType));
|
|
1998
|
+
return apacheArrow.makeData({
|
|
1999
|
+
type: multiLineType,
|
|
2000
|
+
length: n,
|
|
2001
|
+
nullCount: 0,
|
|
2002
|
+
valueOffsets: geomOffsets,
|
|
2003
|
+
child: lineListData
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
function buildMultiPolygonData(wkbs, b) {
|
|
2007
|
+
const n = wkbs.length;
|
|
2008
|
+
const geomOffsetsArr = [0];
|
|
2009
|
+
let totalPolys = 0;
|
|
2010
|
+
let totalRings = 0;
|
|
2011
|
+
let totalCoords = 0;
|
|
2012
|
+
for (const wkb of wkbs) {
|
|
2013
|
+
const h = readWkbHeader(wkb);
|
|
2014
|
+
if (!h || h.type !== 6) {
|
|
2015
|
+
geomOffsetsArr.push(totalPolys);
|
|
2016
|
+
continue;
|
|
2017
|
+
}
|
|
2018
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
2019
|
+
const numPolys = dv.getUint32(h.dataOffset, h.le);
|
|
2020
|
+
let off = h.dataOffset + 4;
|
|
2021
|
+
for (let p = 0; p < numPolys; p++) {
|
|
2022
|
+
const innerH = readWkbHeader(
|
|
2023
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
2024
|
+
);
|
|
2025
|
+
if (!innerH) break;
|
|
2026
|
+
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
2027
|
+
const numRings = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
2028
|
+
let ringOff = innerH.dataOffset + 4;
|
|
2029
|
+
for (let r = 0; r < numRings; r++) {
|
|
2030
|
+
const numPts = innerDv.getUint32(ringOff, innerH.le);
|
|
2031
|
+
ringOff += 4 + numPts * innerH.coordStride;
|
|
2032
|
+
totalCoords += numPts;
|
|
2033
|
+
totalRings++;
|
|
2034
|
+
}
|
|
2035
|
+
off += ringOff;
|
|
2036
|
+
totalPolys++;
|
|
2037
|
+
}
|
|
2038
|
+
geomOffsetsArr.push(totalPolys);
|
|
2039
|
+
}
|
|
2040
|
+
const geomOffsets = new Int32Array(geomOffsetsArr);
|
|
2041
|
+
const polyOffsets = new Int32Array(totalPolys + 1);
|
|
2042
|
+
const ringOffsets = new Int32Array(totalRings + 1);
|
|
2043
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
2044
|
+
let pi = 0;
|
|
2045
|
+
let ri = 0;
|
|
2046
|
+
let ci = 0;
|
|
2047
|
+
for (const wkb of wkbs) {
|
|
2048
|
+
const h = readWkbHeader(wkb);
|
|
2049
|
+
if (!h || h.type !== 6) continue;
|
|
2050
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
2051
|
+
const numPolys = dv.getUint32(h.dataOffset, h.le);
|
|
2052
|
+
let off = h.dataOffset + 4;
|
|
2053
|
+
for (let p = 0; p < numPolys; p++) {
|
|
2054
|
+
polyOffsets[pi++] = ri;
|
|
2055
|
+
const innerH = readWkbHeader(
|
|
2056
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
2057
|
+
);
|
|
2058
|
+
if (!innerH) break;
|
|
2059
|
+
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
2060
|
+
const numRings = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
2061
|
+
let ringOff = off + innerH.dataOffset + 4;
|
|
2062
|
+
for (let r = 0; r < numRings; r++) {
|
|
2063
|
+
ringOffsets[ri++] = ci >> 1;
|
|
2064
|
+
const numPts = dv.getUint32(ringOff, innerH.le);
|
|
2065
|
+
ringOff += 4;
|
|
2066
|
+
for (let j = 0; j < numPts; j++) {
|
|
2067
|
+
const x = dv.getFloat64(ringOff, innerH.le);
|
|
2068
|
+
const y = dv.getFloat64(ringOff + 8, innerH.le);
|
|
2069
|
+
coords[ci++] = x;
|
|
2070
|
+
coords[ci++] = y;
|
|
2071
|
+
expandBounds(b, x, y);
|
|
2072
|
+
ringOff += innerH.coordStride;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
off = ringOff;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
polyOffsets[totalPolys] = ri;
|
|
2079
|
+
ringOffsets[totalRings] = ci >> 1;
|
|
2080
|
+
const fslData = makeCoordData(coords, ci >> 1);
|
|
2081
|
+
const ringListType = new apacheArrow.List(new apacheArrow.Field("vertices", coordType));
|
|
2082
|
+
const ringListData = apacheArrow.makeData({
|
|
2083
|
+
type: ringListType,
|
|
2084
|
+
length: totalRings,
|
|
2085
|
+
nullCount: 0,
|
|
2086
|
+
valueOffsets: ringOffsets,
|
|
2087
|
+
child: fslData
|
|
2088
|
+
});
|
|
2089
|
+
const polyListType = new apacheArrow.List(new apacheArrow.Field("rings", ringListType));
|
|
2090
|
+
const polyListData = apacheArrow.makeData({
|
|
2091
|
+
type: polyListType,
|
|
2092
|
+
length: totalPolys,
|
|
2093
|
+
nullCount: 0,
|
|
2094
|
+
valueOffsets: polyOffsets,
|
|
2095
|
+
child: ringListData
|
|
2096
|
+
});
|
|
2097
|
+
const multiPolyType = new apacheArrow.List(new apacheArrow.Field("polygons", polyListType));
|
|
2098
|
+
return apacheArrow.makeData({
|
|
2099
|
+
type: multiPolyType,
|
|
2100
|
+
length: n,
|
|
2101
|
+
nullCount: 0,
|
|
2102
|
+
valueOffsets: geomOffsets,
|
|
2103
|
+
child: polyListData
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
function buildAttributeColumns(indices, attributes) {
|
|
2107
|
+
const n = indices.length;
|
|
2108
|
+
const fields = [];
|
|
2109
|
+
const dataArr = [];
|
|
2110
|
+
for (const [name, col] of attributes) {
|
|
2111
|
+
const { values } = col;
|
|
2112
|
+
let isNumeric = true;
|
|
2113
|
+
const sampleEnd = Math.min(n, 100);
|
|
2114
|
+
for (let i = 0; i < sampleEnd; i++) {
|
|
2115
|
+
if (values[indices[i]] != null && typeof values[indices[i]] !== "number") {
|
|
2116
|
+
isNumeric = false;
|
|
2117
|
+
break;
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
if (isNumeric) {
|
|
2121
|
+
const arr = new Float64Array(n);
|
|
2122
|
+
for (let i = 0; i < n; i++) arr[i] = values[indices[i]] ?? NaN;
|
|
2123
|
+
const data = apacheArrow.makeData({ type: new apacheArrow.Float64(), length: n, data: arr });
|
|
2124
|
+
fields.push(new apacheArrow.Field(name, new apacheArrow.Float64(), true));
|
|
2125
|
+
dataArr.push(data);
|
|
2126
|
+
} else {
|
|
2127
|
+
const encoder = new TextEncoder();
|
|
2128
|
+
const offsets = new Int32Array(n + 1);
|
|
2129
|
+
let totalBytes = 0;
|
|
2130
|
+
const strParts = [];
|
|
2131
|
+
for (let i = 0; i < n; i++) {
|
|
2132
|
+
offsets[i] = totalBytes;
|
|
2133
|
+
const s = values[indices[i]] != null ? String(values[indices[i]]) : "";
|
|
2134
|
+
const encoded = encoder.encode(s);
|
|
2135
|
+
strParts.push(encoded);
|
|
2136
|
+
totalBytes += encoded.length;
|
|
2137
|
+
}
|
|
2138
|
+
offsets[n] = totalBytes;
|
|
2139
|
+
const valueBuffer = new Uint8Array(totalBytes);
|
|
2140
|
+
let pos = 0;
|
|
2141
|
+
for (const sv of strParts) {
|
|
2142
|
+
valueBuffer.set(sv, pos);
|
|
2143
|
+
pos += sv.length;
|
|
2144
|
+
}
|
|
2145
|
+
const data = apacheArrow.makeData({
|
|
2146
|
+
type: new apacheArrow.Utf8(),
|
|
2147
|
+
length: n,
|
|
2148
|
+
valueOffsets: offsets,
|
|
2149
|
+
data: valueBuffer
|
|
2150
|
+
});
|
|
2151
|
+
fields.push(new apacheArrow.Field(name, new apacheArrow.Utf8(), true));
|
|
2152
|
+
dataArr.push(data);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
return { fields, data: dataArr };
|
|
2156
|
+
}
|
|
2157
|
+
function buildSingleTable(geomType, wkbs, indices, attributes, b) {
|
|
2158
|
+
const n = wkbs.length;
|
|
2159
|
+
let geomData;
|
|
2160
|
+
switch (geomType) {
|
|
2161
|
+
case "point":
|
|
2162
|
+
geomData = buildPointData(wkbs, b);
|
|
2163
|
+
break;
|
|
2164
|
+
case "linestring":
|
|
2165
|
+
geomData = buildLineStringData(wkbs, b);
|
|
2166
|
+
break;
|
|
2167
|
+
case "polygon":
|
|
2168
|
+
geomData = buildPolygonData(wkbs, b);
|
|
2169
|
+
break;
|
|
2170
|
+
case "multipoint":
|
|
2171
|
+
geomData = buildMultiPointData(wkbs, b);
|
|
2172
|
+
break;
|
|
2173
|
+
case "multilinestring":
|
|
2174
|
+
geomData = buildMultiLineStringData(wkbs, b);
|
|
2175
|
+
break;
|
|
2176
|
+
case "multipolygon":
|
|
2177
|
+
geomData = buildMultiPolygonData(wkbs, b);
|
|
2178
|
+
break;
|
|
2179
|
+
}
|
|
2180
|
+
const extensionName = EXTENSION_NAMES[geomType];
|
|
2181
|
+
const geomMetadata = /* @__PURE__ */ new Map([
|
|
2182
|
+
["ARROW:extension:name", extensionName],
|
|
2183
|
+
[
|
|
2184
|
+
"ARROW:extension:metadata",
|
|
2185
|
+
JSON.stringify({
|
|
2186
|
+
crs: {
|
|
2187
|
+
type: "name",
|
|
2188
|
+
properties: { name: "urn:ogc:def:crs:OGC:1.3:CRS84" }
|
|
2189
|
+
}
|
|
2190
|
+
})
|
|
2191
|
+
]
|
|
2192
|
+
]);
|
|
2193
|
+
const geomField = new apacheArrow.Field("geometry", geomData.type, false, geomMetadata);
|
|
2194
|
+
const attrCols = buildAttributeColumns(indices, attributes);
|
|
2195
|
+
const fields = [geomField, ...attrCols.fields];
|
|
2196
|
+
const childrenData = [geomData, ...attrCols.data];
|
|
2197
|
+
const arrowSchema = new apacheArrow.Schema(fields);
|
|
2198
|
+
const structType = new apacheArrow.Struct(fields);
|
|
2199
|
+
const structData = apacheArrow.makeData({
|
|
2200
|
+
type: structType,
|
|
2201
|
+
length: n,
|
|
2202
|
+
nullCount: 0,
|
|
2203
|
+
children: childrenData
|
|
2204
|
+
});
|
|
2205
|
+
const batch = new apacheArrow.RecordBatch(arrowSchema, structData);
|
|
2206
|
+
const table = new apacheArrow.Table(arrowSchema, batch);
|
|
2207
|
+
return {
|
|
2208
|
+
table,
|
|
2209
|
+
geometryType: geomType,
|
|
2210
|
+
bounds: [b.minX, b.minY, b.maxX, b.maxY],
|
|
2211
|
+
sourceIndices: indices
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
function buildGeoArrowTables(wkbArrays, attributes, knownGeomType) {
|
|
2215
|
+
if (wkbArrays.length === 0) return [];
|
|
2216
|
+
if (knownGeomType) {
|
|
2217
|
+
const globalBounds2 = newBounds();
|
|
2218
|
+
const indices = Array.from({ length: wkbArrays.length }, (_, i) => i);
|
|
2219
|
+
const result = buildSingleTable(knownGeomType, wkbArrays, indices, attributes, globalBounds2);
|
|
2220
|
+
return [result];
|
|
2221
|
+
}
|
|
2222
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2223
|
+
for (let i = 0; i < wkbArrays.length; i++) {
|
|
2224
|
+
const geomType = classifyWkbType(wkbArrays[i]);
|
|
2225
|
+
if (!geomType) continue;
|
|
2226
|
+
let group = groups.get(geomType);
|
|
2227
|
+
if (!group) {
|
|
2228
|
+
group = { wkbs: [], indices: [] };
|
|
2229
|
+
groups.set(geomType, group);
|
|
2230
|
+
}
|
|
2231
|
+
group.wkbs.push(wkbArrays[i]);
|
|
2232
|
+
group.indices.push(i);
|
|
2233
|
+
}
|
|
2234
|
+
if (groups.size === 0) return [];
|
|
2235
|
+
const globalBounds = newBounds();
|
|
2236
|
+
const results = [];
|
|
2237
|
+
for (const [geomType, { wkbs, indices }] of groups) {
|
|
2238
|
+
const result = buildSingleTable(geomType, wkbs, indices, attributes, globalBounds);
|
|
2239
|
+
results.push(result);
|
|
2240
|
+
}
|
|
2241
|
+
const mergedBounds = [
|
|
2242
|
+
globalBounds.minX,
|
|
2243
|
+
globalBounds.minY,
|
|
2244
|
+
globalBounds.maxX,
|
|
2245
|
+
globalBounds.maxY
|
|
2246
|
+
];
|
|
2247
|
+
for (const r of results) r.bounds = mergedBounds;
|
|
2248
|
+
return results;
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
// ../../src/lib/utils/hex.ts
|
|
2252
|
+
function generateHexDump(data, bytesPerRow = 16) {
|
|
2253
|
+
const rows = [];
|
|
2254
|
+
for (let i = 0; i < data.length; i += bytesPerRow) {
|
|
2255
|
+
const slice = data.slice(i, i + bytesPerRow);
|
|
2256
|
+
const offset = i.toString(16).padStart(8, "0");
|
|
2257
|
+
const hex = [];
|
|
2258
|
+
for (let j = 0; j < bytesPerRow; j++) {
|
|
2259
|
+
if (j < slice.length) {
|
|
2260
|
+
hex.push(slice[j].toString(16).padStart(2, "0"));
|
|
2261
|
+
} else {
|
|
2262
|
+
hex.push(" ");
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
let ascii = "";
|
|
2266
|
+
for (let j = 0; j < slice.length; j++) {
|
|
2267
|
+
const byte = slice[j];
|
|
2268
|
+
ascii += byte >= 32 && byte <= 126 ? String.fromCharCode(byte) : ".";
|
|
2269
|
+
}
|
|
2270
|
+
rows.push({ offset, hex, ascii });
|
|
2271
|
+
}
|
|
2272
|
+
return rows;
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
// ../../src/lib/utils/local-storage.ts
|
|
2276
|
+
function loadFromStorage(key, defaultValue) {
|
|
2277
|
+
if (typeof window === "undefined") return defaultValue;
|
|
2278
|
+
try {
|
|
2279
|
+
const raw = localStorage.getItem(key);
|
|
2280
|
+
if (raw) return JSON.parse(raw);
|
|
2281
|
+
} catch {
|
|
2282
|
+
}
|
|
2283
|
+
return defaultValue;
|
|
2284
|
+
}
|
|
2285
|
+
function persistToStorage(key, value) {
|
|
2286
|
+
if (typeof window === "undefined") return;
|
|
2287
|
+
try {
|
|
2288
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
2289
|
+
} catch {
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
function parseMarkdownDocument(markdown) {
|
|
2293
|
+
let frontmatter = {};
|
|
2294
|
+
let content = markdown;
|
|
2295
|
+
const fmMatch = markdown.match(/^---\n([\s\S]*?)\n---\n/);
|
|
2296
|
+
if (fmMatch) {
|
|
2297
|
+
try {
|
|
2298
|
+
frontmatter = YAML__default.default.parse(fmMatch[1]) || {};
|
|
2299
|
+
} catch {
|
|
2300
|
+
}
|
|
2301
|
+
content = markdown.slice(fmMatch[0].length);
|
|
2302
|
+
}
|
|
2303
|
+
const sqlBlocks = [];
|
|
2304
|
+
const lines = content.split("\n");
|
|
2305
|
+
let i = 0;
|
|
2306
|
+
while (i < lines.length) {
|
|
2307
|
+
const line = lines[i];
|
|
2308
|
+
const match = line.match(/^```sql\s+(\w[\w-]*)\s*$/);
|
|
2309
|
+
if (match) {
|
|
2310
|
+
const name = match[1];
|
|
2311
|
+
const startLine = i;
|
|
2312
|
+
const sqlLines = [];
|
|
2313
|
+
i++;
|
|
2314
|
+
while (i < lines.length && lines[i] !== "```") {
|
|
2315
|
+
sqlLines.push(lines[i]);
|
|
2316
|
+
i++;
|
|
2317
|
+
}
|
|
2318
|
+
sqlBlocks.push({
|
|
2319
|
+
name,
|
|
2320
|
+
sql: sqlLines.join("\n"),
|
|
2321
|
+
startLine,
|
|
2322
|
+
endLine: i
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
i++;
|
|
2326
|
+
}
|
|
2327
|
+
return { frontmatter, content, sqlBlocks };
|
|
2328
|
+
}
|
|
2329
|
+
function interpolateTemplates(text, queryResults) {
|
|
2330
|
+
return text.replace(/\{(\w+)\.rows\[(\d+)\]\.(\w+)\}/g, (match, queryName, rowIdx, colName) => {
|
|
2331
|
+
const rows = queryResults.get(queryName);
|
|
2332
|
+
if (!rows) return match;
|
|
2333
|
+
const row = rows[parseInt(rowIdx, 10)];
|
|
2334
|
+
if (!row) return match;
|
|
2335
|
+
const value = row[colName];
|
|
2336
|
+
return value !== void 0 ? String(value) : match;
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2339
|
+
function markSqlBlocks(content) {
|
|
2340
|
+
return content.replace(
|
|
2341
|
+
/```sql\s+(\w[\w-]*)\s*\n([\s\S]*?)```/g,
|
|
2342
|
+
(_, name) => `<div data-sql-block="${name}"></div>`
|
|
2343
|
+
);
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2346
|
+
// ../../src/lib/utils/parquet-metadata.ts
|
|
2347
|
+
function mapParquetType(col) {
|
|
2348
|
+
const lt = col.logical_type;
|
|
2349
|
+
if (lt) {
|
|
2350
|
+
if (lt.type === "GEOMETRY" || lt.type === "GEOGRAPHY") return "GEOMETRY";
|
|
2351
|
+
if (lt.type === "STRING" || lt.type === "UTF8") return "VARCHAR";
|
|
2352
|
+
if (lt.type === "JSON") return "JSON";
|
|
2353
|
+
if (lt.type === "UUID") return "UUID";
|
|
2354
|
+
if (lt.type === "ENUM") return "VARCHAR";
|
|
2355
|
+
if (lt.type === "INT" || lt.type === "INTEGER") {
|
|
2356
|
+
const bits = lt.bitWidth ?? 32;
|
|
2357
|
+
const signed = lt.isSigned !== false;
|
|
2358
|
+
if (bits <= 8) return signed ? "TINYINT" : "UTINYINT";
|
|
2359
|
+
if (bits <= 16) return signed ? "SMALLINT" : "USMALLINT";
|
|
2360
|
+
if (bits <= 32) return signed ? "INTEGER" : "UINTEGER";
|
|
2361
|
+
return signed ? "BIGINT" : "UBIGINT";
|
|
2362
|
+
}
|
|
2363
|
+
if (lt.type === "DECIMAL") return `DECIMAL(${lt.precision ?? 18},${lt.scale ?? 0})`;
|
|
2364
|
+
if (lt.type === "DATE") return "DATE";
|
|
2365
|
+
if (lt.type === "TIME") return "TIME";
|
|
2366
|
+
if (lt.type === "TIMESTAMP") return "TIMESTAMP";
|
|
2367
|
+
if (lt.type === "BSON") return "BLOB";
|
|
2368
|
+
}
|
|
2369
|
+
const ct = col.converted_type;
|
|
2370
|
+
if (ct === "UTF8") return "VARCHAR";
|
|
2371
|
+
if (ct === "JSON") return "JSON";
|
|
2372
|
+
if (ct === "DATE") return "DATE";
|
|
2373
|
+
if (ct === "TIMESTAMP_MILLIS" || ct === "TIMESTAMP_MICROS") return "TIMESTAMP";
|
|
2374
|
+
if (ct === "DECIMAL") return `DECIMAL(${col.precision ?? 18},${col.scale ?? 0})`;
|
|
2375
|
+
if (ct === "INT_8") return "TINYINT";
|
|
2376
|
+
if (ct === "INT_16") return "SMALLINT";
|
|
2377
|
+
if (ct === "INT_32") return "INTEGER";
|
|
2378
|
+
if (ct === "INT_64") return "BIGINT";
|
|
2379
|
+
if (ct === "UINT_8") return "UTINYINT";
|
|
2380
|
+
if (ct === "UINT_16") return "USMALLINT";
|
|
2381
|
+
if (ct === "UINT_32") return "UINTEGER";
|
|
2382
|
+
if (ct === "UINT_64") return "UBIGINT";
|
|
2383
|
+
const pt = col.type;
|
|
2384
|
+
if (pt === "BOOLEAN") return "BOOLEAN";
|
|
2385
|
+
if (pt === "INT32") return "INTEGER";
|
|
2386
|
+
if (pt === "INT64") return "BIGINT";
|
|
2387
|
+
if (pt === "INT96") return "TIMESTAMP";
|
|
2388
|
+
if (pt === "FLOAT") return "FLOAT";
|
|
2389
|
+
if (pt === "DOUBLE") return "DOUBLE";
|
|
2390
|
+
if (pt === "BYTE_ARRAY") return "BLOB";
|
|
2391
|
+
if (pt === "FIXED_LEN_BYTE_ARRAY") return "BLOB";
|
|
2392
|
+
return "VARCHAR";
|
|
2393
|
+
}
|
|
2394
|
+
async function readParquetMetadata(url) {
|
|
2395
|
+
const { parquetMetadataAsync, asyncBufferFromUrl } = await import('hyparquet');
|
|
2396
|
+
const file = await asyncBufferFromUrl({ url });
|
|
2397
|
+
const metadata = await parquetMetadataAsync(file);
|
|
2398
|
+
const rowCount = metadata.row_groups.reduce(
|
|
2399
|
+
(sum, rg) => sum + Number(rg.num_rows),
|
|
2400
|
+
0
|
|
2401
|
+
);
|
|
2402
|
+
const schema = metadata.schema.slice(1).filter((col) => col.num_children === void 0).map((col) => ({
|
|
2403
|
+
name: col.name,
|
|
2404
|
+
type: mapParquetType(col)
|
|
2405
|
+
}));
|
|
2406
|
+
let geo = null;
|
|
2407
|
+
let legacyGeoParquet = false;
|
|
2408
|
+
const geoKv = metadata.key_value_metadata?.find((kv) => kv.key === "geo");
|
|
2409
|
+
if (geoKv) {
|
|
2410
|
+
try {
|
|
2411
|
+
const geoJson = JSON.parse(geoKv.value ?? "");
|
|
2412
|
+
if (geoJson.schema_version && !geoJson.version) {
|
|
2413
|
+
legacyGeoParquet = true;
|
|
2414
|
+
}
|
|
2415
|
+
geo = {
|
|
2416
|
+
primaryColumn: geoJson.primary_column ?? "geometry",
|
|
2417
|
+
columns: {}
|
|
2418
|
+
};
|
|
2419
|
+
if (geoJson.columns) {
|
|
2420
|
+
for (const [colName, colMeta] of Object.entries(geoJson.columns)) {
|
|
2421
|
+
geo.columns[colName] = {
|
|
2422
|
+
encoding: colMeta.encoding ?? "WKB",
|
|
2423
|
+
geometryTypes: colMeta.geometry_types ?? [],
|
|
2424
|
+
crs: colMeta.crs ?? null,
|
|
2425
|
+
bbox: colMeta.bbox
|
|
2426
|
+
};
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
} catch {
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
const createdBy = metadata.created_by ?? null;
|
|
2433
|
+
const numRowGroups = metadata.row_groups.length;
|
|
2434
|
+
let compression = null;
|
|
2435
|
+
if (numRowGroups > 0 && metadata.row_groups[0].columns) {
|
|
2436
|
+
const codecs = /* @__PURE__ */ new Set();
|
|
2437
|
+
for (const col of metadata.row_groups[0].columns) {
|
|
2438
|
+
const codec = col.meta_data?.codec;
|
|
2439
|
+
if (codec) codecs.add(codec);
|
|
2440
|
+
}
|
|
2441
|
+
if (codecs.size === 1) {
|
|
2442
|
+
compression = [...codecs][0];
|
|
2443
|
+
} else if (codecs.size > 1) {
|
|
2444
|
+
compression = [...codecs].join(", ");
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
return { rowCount, schema, geo, legacyGeoParquet, createdBy, numRowGroups, compression };
|
|
2448
|
+
}
|
|
2449
|
+
function extractEpsgFromGeoMeta(geo) {
|
|
2450
|
+
const primaryCol = geo.columns[geo.primaryColumn];
|
|
2451
|
+
if (!primaryCol?.crs) return null;
|
|
2452
|
+
const crs = primaryCol.crs;
|
|
2453
|
+
if (crs.type === "name" && crs.properties?.name?.includes("CRS84")) return null;
|
|
2454
|
+
if (crs.id?.authority === "EPSG") {
|
|
2455
|
+
const code = crs.id.code;
|
|
2456
|
+
if (WGS84_CODES.has(code)) return null;
|
|
2457
|
+
return `EPSG:${code}`;
|
|
2458
|
+
}
|
|
2459
|
+
return null;
|
|
2460
|
+
}
|
|
2461
|
+
function extractGeometryTypes(geo) {
|
|
2462
|
+
const primaryCol = geo.columns[geo.primaryColumn];
|
|
2463
|
+
if (!primaryCol?.geometryTypes?.length) return [];
|
|
2464
|
+
const typeMap = {
|
|
2465
|
+
Point: "point",
|
|
2466
|
+
LineString: "linestring",
|
|
2467
|
+
Polygon: "polygon",
|
|
2468
|
+
MultiPoint: "multipoint",
|
|
2469
|
+
MultiLineString: "multilinestring",
|
|
2470
|
+
MultiPolygon: "multipolygon"
|
|
2471
|
+
};
|
|
2472
|
+
const types = [];
|
|
2473
|
+
for (const raw of primaryCol.geometryTypes) {
|
|
2474
|
+
const base = raw.split(" ")[0];
|
|
2475
|
+
const mapped = typeMap[base];
|
|
2476
|
+
if (mapped && !types.includes(mapped)) types.push(mapped);
|
|
2477
|
+
}
|
|
2478
|
+
return types;
|
|
2479
|
+
}
|
|
2480
|
+
function extractBounds(geo) {
|
|
2481
|
+
const primaryCol = geo.columns[geo.primaryColumn];
|
|
2482
|
+
if (!primaryCol?.bbox || primaryCol.bbox.length < 4) return null;
|
|
2483
|
+
return [primaryCol.bbox[0], primaryCol.bbox[1], primaryCol.bbox[2], primaryCol.bbox[3]];
|
|
2484
|
+
}
|
|
2275
2485
|
|
|
2276
2486
|
// ../../src/lib/utils/storage-url.ts
|
|
2277
2487
|
function buildSchemeMap() {
|
|
@@ -2854,6 +3064,8 @@ exports.DEFAULT_TARGET_CRS = DEFAULT_TARGET_CRS;
|
|
|
2854
3064
|
exports.DUCKDB_INIT_TIMEOUT_MS = DUCKDB_INIT_TIMEOUT_MS;
|
|
2855
3065
|
exports.LAYER_HUE_MULTIPLIER = LAYER_HUE_MULTIPLIER;
|
|
2856
3066
|
exports.MAX_QUERY_HISTORY_ENTRIES = MAX_QUERY_HISTORY_ENTRIES;
|
|
3067
|
+
exports.PROVIDERS = PROVIDERS;
|
|
3068
|
+
exports.PROVIDER_IDS = PROVIDER_IDS;
|
|
2857
3069
|
exports.QueryCancelledError = QueryCancelledError;
|
|
2858
3070
|
exports.SQL_PREVIEW_LENGTH = SQL_PREVIEW_LENGTH;
|
|
2859
3071
|
exports.STORAGE_KEYS = STORAGE_KEYS;
|
|
@@ -2861,9 +3073,12 @@ exports.UrlAdapter = UrlAdapter;
|
|
|
2861
3073
|
exports.VIEWER_DIR_EXTENSIONS = VIEWER_DIR_EXTENSIONS;
|
|
2862
3074
|
exports.WGS84_CODES = WGS84_CODES;
|
|
2863
3075
|
exports.buildDuckDbSource = buildDuckDbSource;
|
|
3076
|
+
exports.buildEndpointFromTemplate = buildEndpointFromTemplate;
|
|
2864
3077
|
exports.buildGeoArrowTables = buildGeoArrowTables;
|
|
3078
|
+
exports.buildProviderBaseUrl = buildProviderBaseUrl;
|
|
2865
3079
|
exports.classifyType = classifyType;
|
|
2866
3080
|
exports.describeParseResult = describeParseResult;
|
|
3081
|
+
exports.escapeCsvField = escapeCsvField;
|
|
2867
3082
|
exports.extractBounds = extractBounds;
|
|
2868
3083
|
exports.extractEpsgFromGeoMeta = extractEpsgFromGeoMeta;
|
|
2869
3084
|
exports.extractGeometryTypes = extractGeometryTypes;
|
|
@@ -2877,17 +3092,31 @@ exports.getDuckDbReadFn = getDuckDbReadFn;
|
|
|
2877
3092
|
exports.getFileExtension = getFileExtension;
|
|
2878
3093
|
exports.getFileTypeInfo = getFileTypeInfo;
|
|
2879
3094
|
exports.getMimeType = getMimeType;
|
|
3095
|
+
exports.getNativeScheme = getNativeScheme;
|
|
3096
|
+
exports.getProvider = getProvider;
|
|
2880
3097
|
exports.getViewerKind = getViewerKind;
|
|
2881
3098
|
exports.handleLoadError = handleLoadError;
|
|
3099
|
+
exports.interpolateTemplates = interpolateTemplates;
|
|
2882
3100
|
exports.isCloudNativeFormat = isCloudNativeFormat;
|
|
3101
|
+
exports.isGcsProvider = isGcsProvider;
|
|
2883
3102
|
exports.isQueryable = isQueryable;
|
|
2884
3103
|
exports.jsonReplacerBigInt = jsonReplacerBigInt;
|
|
3104
|
+
exports.loadFromStorage = loadFromStorage;
|
|
2885
3105
|
exports.looksLikeUrl = looksLikeUrl;
|
|
3106
|
+
exports.markSqlBlocks = markSqlBlocks;
|
|
2886
3107
|
exports.normalizeGeomType = normalizeGeomType;
|
|
3108
|
+
exports.parseMarkdownDocument = parseMarkdownDocument;
|
|
2887
3109
|
exports.parseStorageUrl = parseStorageUrl;
|
|
2888
3110
|
exports.parseWKB = parseWKB;
|
|
3111
|
+
exports.persistToStorage = persistToStorage;
|
|
2889
3112
|
exports.readParquetMetadata = readParquetMetadata;
|
|
3113
|
+
exports.resolveCloudUrl = resolveCloudUrl;
|
|
3114
|
+
exports.safeDecodeURIComponent = safeDecodeURIComponent;
|
|
3115
|
+
exports.serializeToCsv = serializeToCsv;
|
|
3116
|
+
exports.serializeToJson = serializeToJson;
|
|
3117
|
+
exports.sortFileEntries = sortFileEntries;
|
|
2890
3118
|
exports.toBinary = toBinary;
|
|
3119
|
+
exports.toggleSortField = toggleSortField;
|
|
2891
3120
|
exports.typeBadgeClass = typeBadgeClass;
|
|
2892
3121
|
exports.typeColor = typeColor;
|
|
2893
3122
|
exports.typeLabel = typeLabel;
|