@geolonia/geonicdb-cli 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +37 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -240,14 +240,34 @@ function collectKeys(items) {
|
|
|
240
240
|
sorted.push(...Array.from(keySet).sort());
|
|
241
241
|
return sorted;
|
|
242
242
|
}
|
|
243
|
+
function formatGeoJSON(geo) {
|
|
244
|
+
const geoType = String(geo.type);
|
|
245
|
+
const coords = geo.coordinates;
|
|
246
|
+
if (geoType === "Point" && Array.isArray(coords) && coords.length >= 2) {
|
|
247
|
+
return `Point(${Number(coords[0]).toFixed(2)}, ${Number(coords[1]).toFixed(2)})`;
|
|
248
|
+
}
|
|
249
|
+
if (Array.isArray(coords)) {
|
|
250
|
+
const count = geoType === "Polygon" ? Array.isArray(coords[0]) ? coords[0].length : 0 : coords.length;
|
|
251
|
+
return `${geoType}(${count} coords)`;
|
|
252
|
+
}
|
|
253
|
+
return `${geoType}(...)`;
|
|
254
|
+
}
|
|
255
|
+
function isGeoJSON(v) {
|
|
256
|
+
if (typeof v !== "object" || v === null) return false;
|
|
257
|
+
const o = v;
|
|
258
|
+
return typeof o.type === "string" && "coordinates" in o;
|
|
259
|
+
}
|
|
243
260
|
function cellValue(val) {
|
|
244
261
|
if (val === void 0 || val === null) return "";
|
|
245
|
-
if (typeof val
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
262
|
+
if (typeof val !== "object") return String(val);
|
|
263
|
+
const obj = val;
|
|
264
|
+
if (isGeoJSON(obj)) return formatGeoJSON(obj);
|
|
265
|
+
if ("value" in obj) {
|
|
266
|
+
const v = obj.value;
|
|
267
|
+
if (isGeoJSON(v)) return formatGeoJSON(v);
|
|
268
|
+
return String(v);
|
|
249
269
|
}
|
|
250
|
-
return
|
|
270
|
+
return JSON.stringify(val);
|
|
251
271
|
}
|
|
252
272
|
function toGeoJSON(data) {
|
|
253
273
|
if (Array.isArray(data)) {
|
|
@@ -1696,7 +1716,7 @@ function registerAttrsSubcommand(entitiesCmd) {
|
|
|
1696
1716
|
// src/commands/entities.ts
|
|
1697
1717
|
function registerEntitiesCommand(program2) {
|
|
1698
1718
|
const entities = program2.command("entities").description("Manage context entities");
|
|
1699
|
-
const list = entities.command("list").description("List entities with optional filters").option("--type <type>", "Filter by entity type").option("--id-pattern <pat>", "Filter by entity ID pattern (regex)").option("--query <q>", "NGSI query expression").option("--attrs <a,b>", "Comma-separated list of attributes to include").option("--georel <rel>", "Geo-relationship (e.g. near;maxDistance:1000)").option("--geometry <geo>", "Geometry type for geo-query (e.g. point)").option("--coords <coords>", "Coordinates for geo-query").option("--spatial-id <zfxy>", "Spatial ID filter (ZFXY tile)").option("--limit <n>", "Maximum number of entities to return", parseInt).option("--offset <n>", "Skip first N entities", parseInt).option("--order-by <field>", "Order results by field").option("--count", "Include total count in response").option("--key-values", "Request simplified key-value format").action(
|
|
1719
|
+
const list = entities.command("list").description("List entities with optional filters").option("--type <type>", "Filter by entity type").option("--id-pattern <pat>", "Filter by entity ID pattern (regex)").option("--query <q>", "NGSI query expression").option("--attrs <a,b>", "Comma-separated list of attributes to include").option("--georel <rel>", "Geo-relationship (e.g. near;maxDistance:1000)").option("--geometry <geo>", "Geometry type for geo-query (e.g. point)").option("--coords <coords>", "Coordinates for geo-query").option("--spatial-id <zfxy>", "Spatial ID filter (ZFXY tile)").option("--limit <n>", "Maximum number of entities to return", parseInt).option("--offset <n>", "Skip first N entities", parseInt).option("--order-by <field>", "Order results by field").option("--count", "Include total count in response").option("--count-only", "Only show the total count without listing entities").option("--key-values", "Request simplified key-value format").action(
|
|
1700
1720
|
withErrorHandler(async (opts, cmd) => {
|
|
1701
1721
|
const client = createClient(cmd);
|
|
1702
1722
|
const format = getFormat(cmd);
|
|
@@ -1712,10 +1732,15 @@ function registerEntitiesCommand(program2) {
|
|
|
1712
1732
|
if (opts.limit !== void 0) params.limit = String(opts.limit);
|
|
1713
1733
|
if (opts.offset !== void 0) params.offset = String(opts.offset);
|
|
1714
1734
|
if (opts.orderBy) params.orderBy = String(opts.orderBy);
|
|
1715
|
-
if (opts.count) params.count = "true";
|
|
1735
|
+
if (opts.count || opts.countOnly) params.count = "true";
|
|
1736
|
+
if (opts.countOnly) params.limit = "0";
|
|
1716
1737
|
if (opts.keyValues) params.options = "keyValues";
|
|
1717
1738
|
const response = await client.get("/entities", params);
|
|
1718
|
-
|
|
1739
|
+
if (opts.countOnly) {
|
|
1740
|
+
printCount(response.count ?? 0);
|
|
1741
|
+
} else {
|
|
1742
|
+
outputResponse(response, format, !!opts.count);
|
|
1743
|
+
}
|
|
1719
1744
|
})
|
|
1720
1745
|
);
|
|
1721
1746
|
addExamples(list, [
|
|
@@ -1774,6 +1799,10 @@ function registerEntitiesCommand(program2) {
|
|
|
1774
1799
|
{
|
|
1775
1800
|
description: "Get total count with results",
|
|
1776
1801
|
command: "geonic entities list --type Sensor --count"
|
|
1802
|
+
},
|
|
1803
|
+
{
|
|
1804
|
+
description: "Get only the total count (no entity data)",
|
|
1805
|
+
command: "geonic entities list --type Sensor --count-only"
|
|
1777
1806
|
}
|
|
1778
1807
|
]);
|
|
1779
1808
|
const get = entities.command("get").description("Get a single entity by ID").argument("<id>", "Entity ID").option("--key-values", "Request simplified key-value format").action(
|