@geolonia/geonicdb-cli 0.1.0 → 0.2.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/dist/index.js +150 -19
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1052,7 +1052,6 @@ async function clientCredentialsGrant(options) {
|
|
|
1052
1052
|
}
|
|
1053
1053
|
|
|
1054
1054
|
// src/commands/auth.ts
|
|
1055
|
-
import chalk3 from "chalk";
|
|
1056
1055
|
function createLoginCommand() {
|
|
1057
1056
|
return new Command("login").description("Authenticate and save token").option("--client-credentials", "Use OAuth 2.0 Client Credentials flow").option("--client-id <id>", "OAuth client ID").option("--client-secret <secret>", "OAuth client secret").option("--scope <scopes>", "OAuth scopes (space-separated)").option("--tenant-id <id>", "Tenant ID for scoped authentication").action(
|
|
1058
1057
|
withErrorHandler(async (...args) => {
|
|
@@ -1163,7 +1162,7 @@ function createMeAction() {
|
|
|
1163
1162
|
const status = getTokenStatus(latestConfig.token);
|
|
1164
1163
|
if (status.expiresAt) {
|
|
1165
1164
|
if (status.isExpired) {
|
|
1166
|
-
|
|
1165
|
+
printError(`Token expires: ${status.expiresAt.toISOString()} (expired)`);
|
|
1167
1166
|
} else if (status.isExpiringSoon) {
|
|
1168
1167
|
printWarning(
|
|
1169
1168
|
`Token expires: ${status.expiresAt.toISOString()} (${formatDuration(status.remainingMs)} remaining)`
|
|
@@ -1537,15 +1536,13 @@ function registerEntitiesCommand(program2) {
|
|
|
1537
1536
|
if (opts.attrs) params.attrs = String(opts.attrs);
|
|
1538
1537
|
if (opts.georel) params.georel = String(opts.georel);
|
|
1539
1538
|
if (opts.geometry) params.geometry = String(opts.geometry);
|
|
1540
|
-
if (opts.coords) params.
|
|
1539
|
+
if (opts.coords) params.coordinates = String(opts.coords);
|
|
1541
1540
|
if (opts.spatialId) params.spatialId = String(opts.spatialId);
|
|
1542
1541
|
if (opts.limit !== void 0) params.limit = String(opts.limit);
|
|
1543
1542
|
if (opts.offset !== void 0) params.offset = String(opts.offset);
|
|
1544
1543
|
if (opts.orderBy) params.orderBy = String(opts.orderBy);
|
|
1545
|
-
if (opts.count) params.
|
|
1546
|
-
if (opts.keyValues)
|
|
1547
|
-
params.options = params.options ? `${params.options},keyValues` : "keyValues";
|
|
1548
|
-
}
|
|
1544
|
+
if (opts.count) params.count = "true";
|
|
1545
|
+
if (opts.keyValues) params.options = "keyValues";
|
|
1549
1546
|
const response = await client.get("/entities", params);
|
|
1550
1547
|
outputResponse(response, format, !!opts.count);
|
|
1551
1548
|
})
|
|
@@ -1861,7 +1858,7 @@ function registerSubscriptionsCommand(program2) {
|
|
|
1861
1858
|
const params = {};
|
|
1862
1859
|
if (cmdOpts.limit !== void 0) params["limit"] = String(cmdOpts.limit);
|
|
1863
1860
|
if (cmdOpts.offset !== void 0) params["offset"] = String(cmdOpts.offset);
|
|
1864
|
-
if (cmdOpts.count) params["
|
|
1861
|
+
if (cmdOpts.count) params["count"] = "true";
|
|
1865
1862
|
const response = await client.get("/subscriptions", params);
|
|
1866
1863
|
outputResponse(response, format, !!cmdOpts.count);
|
|
1867
1864
|
})
|
|
@@ -1965,8 +1962,8 @@ function registerRegistrationsCommand(program2) {
|
|
|
1965
1962
|
const params = {};
|
|
1966
1963
|
if (cmdOpts.limit !== void 0) params["limit"] = String(cmdOpts.limit);
|
|
1967
1964
|
if (cmdOpts.offset !== void 0) params["offset"] = String(cmdOpts.offset);
|
|
1968
|
-
if (cmdOpts.count) params["
|
|
1969
|
-
const response = await client.get("/
|
|
1965
|
+
if (cmdOpts.count) params["count"] = "true";
|
|
1966
|
+
const response = await client.get("/csourceRegistrations", params);
|
|
1970
1967
|
outputResponse(response, format, !!cmdOpts.count);
|
|
1971
1968
|
})
|
|
1972
1969
|
);
|
|
@@ -1985,7 +1982,7 @@ function registerRegistrationsCommand(program2) {
|
|
|
1985
1982
|
const client = createClient(cmd);
|
|
1986
1983
|
const format = getFormat(cmd);
|
|
1987
1984
|
const response = await client.get(
|
|
1988
|
-
`/
|
|
1985
|
+
`/csourceRegistrations/${encodeURIComponent(String(id))}`
|
|
1989
1986
|
);
|
|
1990
1987
|
outputResponse(response, format);
|
|
1991
1988
|
})
|
|
@@ -2001,7 +1998,7 @@ function registerRegistrationsCommand(program2) {
|
|
|
2001
1998
|
const client = createClient(cmd);
|
|
2002
1999
|
const format = getFormat(cmd);
|
|
2003
2000
|
const data = await parseJsonInput(json);
|
|
2004
|
-
const response = await client.post("/
|
|
2001
|
+
const response = await client.post("/csourceRegistrations", data);
|
|
2005
2002
|
outputResponse(response, format);
|
|
2006
2003
|
printSuccess("Registration created.");
|
|
2007
2004
|
})
|
|
@@ -2019,7 +2016,7 @@ function registerRegistrationsCommand(program2) {
|
|
|
2019
2016
|
const format = getFormat(cmd);
|
|
2020
2017
|
const data = await parseJsonInput(json);
|
|
2021
2018
|
const response = await client.patch(
|
|
2022
|
-
`/
|
|
2019
|
+
`/csourceRegistrations/${encodeURIComponent(String(id))}`,
|
|
2023
2020
|
data
|
|
2024
2021
|
);
|
|
2025
2022
|
outputResponse(response, format);
|
|
@@ -2037,7 +2034,7 @@ function registerRegistrationsCommand(program2) {
|
|
|
2037
2034
|
withErrorHandler(async (id, _opts, cmd) => {
|
|
2038
2035
|
const client = createClient(cmd);
|
|
2039
2036
|
await client.delete(
|
|
2040
|
-
`/
|
|
2037
|
+
`/csourceRegistrations/${encodeURIComponent(String(id))}`
|
|
2041
2038
|
);
|
|
2042
2039
|
printSuccess("Registration deleted.");
|
|
2043
2040
|
})
|
|
@@ -2102,14 +2099,14 @@ function createListAction() {
|
|
|
2102
2099
|
if (cmdOpts.query) params["q"] = cmdOpts.query;
|
|
2103
2100
|
if (cmdOpts.georel) params["georel"] = cmdOpts.georel;
|
|
2104
2101
|
if (cmdOpts.geometry) params["geometry"] = cmdOpts.geometry;
|
|
2105
|
-
if (cmdOpts.coords) params["
|
|
2102
|
+
if (cmdOpts.coords) params["coordinates"] = cmdOpts.coords;
|
|
2106
2103
|
if (cmdOpts.timeRel) params["timerel"] = cmdOpts.timeRel;
|
|
2107
2104
|
if (cmdOpts.timeAt) params["timeAt"] = cmdOpts.timeAt;
|
|
2108
2105
|
if (cmdOpts.endTimeAt) params["endTimeAt"] = cmdOpts.endTimeAt;
|
|
2109
2106
|
if (cmdOpts.lastN !== void 0) params["lastN"] = String(cmdOpts.lastN);
|
|
2110
2107
|
if (cmdOpts.limit !== void 0) params["limit"] = String(cmdOpts.limit);
|
|
2111
2108
|
if (cmdOpts.offset !== void 0) params["offset"] = String(cmdOpts.offset);
|
|
2112
|
-
if (cmdOpts.count) params["
|
|
2109
|
+
if (cmdOpts.count) params["count"] = "true";
|
|
2113
2110
|
const response = await client.get("/temporal/entities", params);
|
|
2114
2111
|
outputResponse(response, format, cmdOpts.count);
|
|
2115
2112
|
});
|
|
@@ -3238,8 +3235,8 @@ function generateCompletions(program2, line, point) {
|
|
|
3238
3235
|
i++;
|
|
3239
3236
|
}
|
|
3240
3237
|
if (currentCmd.name() === "help" && currentCmd.parent === program2) {
|
|
3241
|
-
const helpIdx = walkTokens.
|
|
3242
|
-
const rawArgs =
|
|
3238
|
+
const helpIdx = walkTokens.indexOf("help");
|
|
3239
|
+
const rawArgs = walkTokens.slice(helpIdx + 1);
|
|
3243
3240
|
const helpArgs = [];
|
|
3244
3241
|
for (let j = 0; j < rawArgs.length; j++) {
|
|
3245
3242
|
const t = rawArgs[j];
|
|
@@ -3407,7 +3404,141 @@ function createProgram() {
|
|
|
3407
3404
|
return program2;
|
|
3408
3405
|
}
|
|
3409
3406
|
|
|
3407
|
+
// src/update-notifier.ts
|
|
3408
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
3409
|
+
import { join as join2 } from "path";
|
|
3410
|
+
import chalk3 from "chalk";
|
|
3411
|
+
var PACKAGE_NAME = "@geolonia/geonicdb-cli";
|
|
3412
|
+
var REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
|
|
3413
|
+
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
3414
|
+
var FETCH_TIMEOUT_MS = 5e3;
|
|
3415
|
+
var CI_ENV_VARS = [
|
|
3416
|
+
"CI",
|
|
3417
|
+
"CONTINUOUS_INTEGRATION",
|
|
3418
|
+
"BUILD_NUMBER",
|
|
3419
|
+
"GITHUB_ACTIONS",
|
|
3420
|
+
"GITLAB_CI",
|
|
3421
|
+
"CIRCLECI",
|
|
3422
|
+
"JENKINS_URL",
|
|
3423
|
+
"HUDSON_URL",
|
|
3424
|
+
"TRAVIS"
|
|
3425
|
+
];
|
|
3426
|
+
function getCacheFile() {
|
|
3427
|
+
return join2(getConfigDir(), "update-check.json");
|
|
3428
|
+
}
|
|
3429
|
+
function isCheckDisabled() {
|
|
3430
|
+
if (process.env.NO_UPDATE_NOTIFIER) return true;
|
|
3431
|
+
if (!process.stdout.isTTY) return true;
|
|
3432
|
+
for (const envVar of CI_ENV_VARS) {
|
|
3433
|
+
if (process.env[envVar]) return true;
|
|
3434
|
+
}
|
|
3435
|
+
return false;
|
|
3436
|
+
}
|
|
3437
|
+
function loadCache() {
|
|
3438
|
+
try {
|
|
3439
|
+
const raw = readFileSync3(getCacheFile(), "utf-8");
|
|
3440
|
+
return JSON.parse(raw);
|
|
3441
|
+
} catch {
|
|
3442
|
+
return null;
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
function saveCache(cache) {
|
|
3446
|
+
try {
|
|
3447
|
+
ensureConfigDir();
|
|
3448
|
+
writeFileSync2(getCacheFile(), JSON.stringify(cache), "utf-8");
|
|
3449
|
+
} catch {
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
function shouldCheck(cache) {
|
|
3453
|
+
if (!cache) return true;
|
|
3454
|
+
return Date.now() - cache.lastCheck >= CHECK_INTERVAL_MS;
|
|
3455
|
+
}
|
|
3456
|
+
function compareSemver(current, latest) {
|
|
3457
|
+
const parse = (v) => v.replace(/^v/, "").split(".").map(Number);
|
|
3458
|
+
const [cMajor, cMinor, cPatch] = parse(current);
|
|
3459
|
+
const [lMajor, lMinor, lPatch] = parse(latest);
|
|
3460
|
+
if (lMajor !== cMajor) return lMajor > cMajor;
|
|
3461
|
+
if (lMinor !== cMinor) return lMinor > cMinor;
|
|
3462
|
+
return lPatch > cPatch;
|
|
3463
|
+
}
|
|
3464
|
+
async function fetchLatestVersion() {
|
|
3465
|
+
try {
|
|
3466
|
+
const res = await fetch(REGISTRY_URL, {
|
|
3467
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
3468
|
+
});
|
|
3469
|
+
if (!res.ok) return null;
|
|
3470
|
+
const data = await res.json();
|
|
3471
|
+
return data.version ?? null;
|
|
3472
|
+
} catch {
|
|
3473
|
+
return null;
|
|
3474
|
+
}
|
|
3475
|
+
}
|
|
3476
|
+
function getCurrentVersion() {
|
|
3477
|
+
return process.env.npm_package_version ?? "0.0.0";
|
|
3478
|
+
}
|
|
3479
|
+
function formatUpdateBox(current, latest) {
|
|
3480
|
+
const message = `Update available: ${current} \u2192 ${latest}`;
|
|
3481
|
+
const install = `Run ${chalk3.cyan(`npm i -g ${PACKAGE_NAME}`)} to update`;
|
|
3482
|
+
const lines = [message, install];
|
|
3483
|
+
const maxLen = Math.max(
|
|
3484
|
+
...lines.map((l) => stripAnsi(l).length)
|
|
3485
|
+
);
|
|
3486
|
+
const pad = (line) => {
|
|
3487
|
+
const visible = stripAnsi(line).length;
|
|
3488
|
+
return line + " ".repeat(maxLen - visible);
|
|
3489
|
+
};
|
|
3490
|
+
const empty = " ".repeat(maxLen);
|
|
3491
|
+
const top = `\u256D${"\u2500".repeat(maxLen + 4)}\u256E`;
|
|
3492
|
+
const bottom = `\u2570${"\u2500".repeat(maxLen + 4)}\u256F`;
|
|
3493
|
+
const boxLines = [
|
|
3494
|
+
top,
|
|
3495
|
+
`\u2502 ${empty} \u2502`,
|
|
3496
|
+
...lines.map((l) => `\u2502 ${pad(l)} \u2502`),
|
|
3497
|
+
`\u2502 ${empty} \u2502`,
|
|
3498
|
+
bottom
|
|
3499
|
+
];
|
|
3500
|
+
return chalk3.yellow(boxLines.join("\n"));
|
|
3501
|
+
}
|
|
3502
|
+
function stripAnsi(str) {
|
|
3503
|
+
return str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
3504
|
+
}
|
|
3505
|
+
async function startUpdateCheck() {
|
|
3506
|
+
if (isCheckDisabled()) return null;
|
|
3507
|
+
let currentVersion;
|
|
3508
|
+
try {
|
|
3509
|
+
const pkgPath = new URL("../package.json", import.meta.url);
|
|
3510
|
+
const pkg = JSON.parse(readFileSync3(pkgPath, "utf-8"));
|
|
3511
|
+
currentVersion = pkg.version;
|
|
3512
|
+
} catch {
|
|
3513
|
+
currentVersion = getCurrentVersion();
|
|
3514
|
+
}
|
|
3515
|
+
const cache = loadCache();
|
|
3516
|
+
if (!shouldCheck(cache)) {
|
|
3517
|
+
if (cache?.latestVersion && compareSemver(currentVersion, cache.latestVersion)) {
|
|
3518
|
+
return { currentVersion, latestVersion: cache.latestVersion };
|
|
3519
|
+
}
|
|
3520
|
+
return null;
|
|
3521
|
+
}
|
|
3522
|
+
const latestVersion = await fetchLatestVersion();
|
|
3523
|
+
saveCache({
|
|
3524
|
+
lastCheck: Date.now(),
|
|
3525
|
+
latestVersion: latestVersion ?? cache?.latestVersion
|
|
3526
|
+
});
|
|
3527
|
+
if (latestVersion && compareSemver(currentVersion, latestVersion)) {
|
|
3528
|
+
return { currentVersion, latestVersion };
|
|
3529
|
+
}
|
|
3530
|
+
return null;
|
|
3531
|
+
}
|
|
3532
|
+
function printUpdateNotification(result) {
|
|
3533
|
+
if (!result) return;
|
|
3534
|
+
const box = formatUpdateBox(result.currentVersion, result.latestVersion);
|
|
3535
|
+
process.stderr.write("\n" + box + "\n");
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3410
3538
|
// src/index.ts
|
|
3539
|
+
var updateCheckPromise = startUpdateCheck();
|
|
3411
3540
|
var program = createProgram();
|
|
3412
|
-
program.
|
|
3541
|
+
await program.parseAsync();
|
|
3542
|
+
var updateResult = await updateCheckPromise;
|
|
3543
|
+
printUpdateNotification(updateResult);
|
|
3413
3544
|
//# sourceMappingURL=index.js.map
|