@nmakarov/cli-toolkit 0.18.0 → 0.23.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 +9 -0
- package/dist/args.cjs +1 -4
- package/dist/args.cjs.map +1 -1
- package/dist/args.js +1 -1
- package/dist/args.js.map +1 -1
- package/dist/cli-runner.cjs +1493 -516
- package/dist/cli-runner.cjs.map +1 -1
- package/dist/cli-runner.js +1509 -531
- package/dist/cli-runner.js.map +1 -1
- package/dist/db.cjs +85 -157
- package/dist/db.cjs.map +1 -1
- package/dist/db.js +84 -150
- package/dist/db.js.map +1 -1
- package/dist/errors.cjs +2 -2
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +2 -1
- package/dist/errors.js.map +1 -1
- package/dist/filedatabase.cjs +19 -19
- package/dist/filedatabase.cjs.map +1 -1
- package/dist/filedatabase.js +19 -16
- package/dist/filedatabase.js.map +1 -1
- package/dist/http-client.cjs +9 -11
- package/dist/http-client.cjs.map +1 -1
- package/dist/http-client.js +10 -9
- package/dist/http-client.js.map +1 -1
- package/dist/http-client2.cjs +34 -33
- package/dist/http-client2.cjs.map +1 -1
- package/dist/http-client2.js +34 -30
- package/dist/http-client2.js.map +1 -1
- package/dist/index.cjs +2063 -658
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2063 -663
- package/dist/index.js.map +1 -1
- package/dist/init.cjs +97 -69
- package/dist/init.cjs.map +1 -1
- package/dist/init.js +112 -83
- package/dist/init.js.map +1 -1
- package/dist/logger.cjs +5 -5
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.js +5 -4
- package/dist/logger.js.map +1 -1
- package/dist/mock-server.cjs +21 -33
- package/dist/mock-server.cjs.map +1 -1
- package/dist/mock-server.js +21 -28
- package/dist/mock-server.js.map +1 -1
- package/dist/params.cjs +22 -10
- package/dist/params.cjs.map +1 -1
- package/dist/params.js +22 -7
- package/dist/params.js.map +1 -1
- package/dist/s3.cjs +286 -0
- package/dist/s3.cjs.map +1 -0
- package/dist/s3.js +273 -0
- package/dist/s3.js.map +1 -0
- package/dist/screen.cjs +34 -39
- package/dist/screen.cjs.map +1 -1
- package/dist/screen.js +48 -46
- package/dist/screen.js.map +1 -1
- package/dist/tasks.cjs +1640 -416
- package/dist/tasks.cjs.map +1 -1
- package/dist/tasks.js +1614 -412
- package/dist/tasks.js.map +1 -1
- package/dist/utils.cjs +7 -8
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +6 -6
- package/dist/utils.js.map +1 -1
- package/package.json +36 -44
- package/scripts/ssm/parse-cli.js +35 -0
- package/scripts/ssm/ssm-admin.js +151 -0
- package/scripts/ssm/ssm-pull.js +147 -0
package/dist/http-client2.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// src/http-client2/index.
|
|
1
|
+
// src/http-client2/index.js
|
|
2
2
|
import path4 from "path";
|
|
3
3
|
|
|
4
|
-
// src/errors.
|
|
4
|
+
// src/errors.js
|
|
5
5
|
var FrameworkError = class extends Error {
|
|
6
6
|
constructor(message) {
|
|
7
7
|
super(message);
|
|
@@ -18,6 +18,7 @@ var HttpClientError = class extends FrameworkError {
|
|
|
18
18
|
constructor(message, cause) {
|
|
19
19
|
super(message);
|
|
20
20
|
this.cause = cause;
|
|
21
|
+
;
|
|
21
22
|
this.name = "HttpClientError";
|
|
22
23
|
}
|
|
23
24
|
};
|
|
@@ -28,7 +29,7 @@ var FileDatabaseError = class extends FrameworkError {
|
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
// src/http-client2/errors.
|
|
32
|
+
// src/http-client2/errors.js
|
|
32
33
|
function classifyError(error) {
|
|
33
34
|
if (error.response) {
|
|
34
35
|
const { status } = error.response;
|
|
@@ -113,7 +114,7 @@ function getErrorDescription(errorType) {
|
|
|
113
114
|
return descriptions[errorType] || "An unknown error occurred";
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
// src/http-client2/retry.
|
|
117
|
+
// src/http-client2/retry.js
|
|
117
118
|
function calculateRetryDelay(attempt, baseDelay, maxDelay, jitterFactor = 0.1) {
|
|
118
119
|
const exponentialDelay = baseDelay * Math.pow(2, attempt - 1);
|
|
119
120
|
const cappedDelay = Math.min(exponentialDelay, maxDelay);
|
|
@@ -128,11 +129,11 @@ function shouldRetryError(classification) {
|
|
|
128
129
|
return classification.retryable;
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
// src/filedatabase/index.
|
|
132
|
+
// src/filedatabase/index.js
|
|
132
133
|
import fs3 from "fs";
|
|
133
134
|
import path3 from "path";
|
|
134
135
|
|
|
135
|
-
// src/utils/os-utils.
|
|
136
|
+
// src/utils/os-utils.js
|
|
136
137
|
import fs from "fs";
|
|
137
138
|
import path from "path";
|
|
138
139
|
import { execSync } from "child_process";
|
|
@@ -161,7 +162,7 @@ function getFreeDiskSpace(targetPath) {
|
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
|
|
164
|
-
// src/utils/fs-utils.
|
|
165
|
+
// src/utils/fs-utils.js
|
|
165
166
|
import fs2 from "fs";
|
|
166
167
|
import path2 from "path";
|
|
167
168
|
async function ensurePath(...pathParts) {
|
|
@@ -185,7 +186,7 @@ function getFileExtension(dataType) {
|
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
// src/utils/format-utils.
|
|
189
|
+
// src/utils/format-utils.js
|
|
189
190
|
function bytesToHumanReadable(bytes) {
|
|
190
191
|
if (bytes === 0) return "0 B";
|
|
191
192
|
const k = 1024;
|
|
@@ -194,7 +195,7 @@ function bytesToHumanReadable(bytes) {
|
|
|
194
195
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
195
196
|
}
|
|
196
197
|
|
|
197
|
-
// src/utils/date-utils.
|
|
198
|
+
// src/utils/date-utils.js
|
|
198
199
|
function isTimestampFolder(folderName) {
|
|
199
200
|
const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|\.\d{3}Z)$/;
|
|
200
201
|
if (!isoRegex.test(folderName)) {
|
|
@@ -204,7 +205,7 @@ function isTimestampFolder(folderName) {
|
|
|
204
205
|
return !isNaN(date.getTime()) && date.getTime() > 0;
|
|
205
206
|
}
|
|
206
207
|
|
|
207
|
-
// src/filedatabase/serializers.
|
|
208
|
+
// src/filedatabase/serializers.js
|
|
208
209
|
function detectDataType(data) {
|
|
209
210
|
if (Array.isArray(data)) {
|
|
210
211
|
return "json-array";
|
|
@@ -236,7 +237,7 @@ function deserializeData(rawData, dataType) {
|
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
239
|
|
|
239
|
-
// src/filedatabase/index.
|
|
240
|
+
// src/filedatabase/index.js
|
|
240
241
|
var FileDatabase = class _FileDatabase {
|
|
241
242
|
basePath;
|
|
242
243
|
namespace;
|
|
@@ -322,7 +323,7 @@ var FileDatabase = class _FileDatabase {
|
|
|
322
323
|
if (errors.length) {
|
|
323
324
|
throw new FileDatabaseError(`[FileDatabase] ${errors.join("; ")}`);
|
|
324
325
|
}
|
|
325
|
-
|
|
326
|
+
const parts = [this.basePath, this.namespace];
|
|
326
327
|
if (this.tableName) {
|
|
327
328
|
parts.push(...this.tableName.split("/"));
|
|
328
329
|
}
|
|
@@ -815,14 +816,17 @@ var FileDatabase = class _FileDatabase {
|
|
|
815
816
|
* Prepare the instance for read or write operations
|
|
816
817
|
* This discovers state and sets up internal members based on mode and current data
|
|
817
818
|
*/
|
|
818
|
-
async prepare(
|
|
819
|
+
async prepare(options) {
|
|
820
|
+
const { write, read, version, deferInitialVersion } = options;
|
|
819
821
|
if (write) {
|
|
820
822
|
if (this.versioned) {
|
|
821
823
|
if (this.currentVersion === null) {
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
824
|
+
if (!deferInitialVersion) {
|
|
825
|
+
await this.makeNewVersion();
|
|
826
|
+
this.metadata = this.getDefaultMetadata();
|
|
827
|
+
this.metadata.version = this.currentVersion;
|
|
828
|
+
this.makeNewFile();
|
|
829
|
+
}
|
|
826
830
|
} else {
|
|
827
831
|
if (!this.metadata.files.length) {
|
|
828
832
|
this.metadata = await this.figureMetadata(this.currentVersion);
|
|
@@ -932,7 +936,7 @@ var FileDatabase = class _FileDatabase {
|
|
|
932
936
|
if (options.forceNewVersion && !this.versioned) {
|
|
933
937
|
throw new FileDatabaseError("Cannot use forceNewVersion in non-versioned mode");
|
|
934
938
|
}
|
|
935
|
-
await this.prepare({ write: true });
|
|
939
|
+
await this.prepare({ write: true, deferInitialVersion: !!(options.forceNewVersion && this.versioned) });
|
|
936
940
|
const incomingDataType = detectDataType(data);
|
|
937
941
|
this.metadata.dataType = incomingDataType;
|
|
938
942
|
if (options.forceNewVersion) {
|
|
@@ -1226,7 +1230,7 @@ var FileDatabase = class _FileDatabase {
|
|
|
1226
1230
|
}
|
|
1227
1231
|
};
|
|
1228
1232
|
|
|
1229
|
-
// src/mock-server/mock-storage.
|
|
1233
|
+
// src/mock-server/mock-storage.js
|
|
1230
1234
|
function stableStringify(obj) {
|
|
1231
1235
|
if (obj === null) return "null";
|
|
1232
1236
|
if (obj === void 0) return "undefined";
|
|
@@ -1323,7 +1327,7 @@ var MockStorage = class {
|
|
|
1323
1327
|
}
|
|
1324
1328
|
};
|
|
1325
1329
|
|
|
1326
|
-
// src/http-client2/index.
|
|
1330
|
+
// src/http-client2/index.js
|
|
1327
1331
|
function buildUrl(baseURL, url, params) {
|
|
1328
1332
|
let full = url;
|
|
1329
1333
|
if (baseURL) {
|
|
@@ -1421,7 +1425,8 @@ var HttpClient = class _HttpClient {
|
|
|
1421
1425
|
}
|
|
1422
1426
|
}
|
|
1423
1427
|
/**
|
|
1424
|
-
* Static init - discovers params via context.params.getAllForModule("http-client2", defs).
|
|
1428
|
+
* Static init - discovers params via context.params.getAllForModule("http-client2", defs).
|
|
1429
|
+
* Whatever is in options wins. Params are grouped under `http-client2` for --showUsedParams.
|
|
1425
1430
|
*/
|
|
1426
1431
|
static init(context, options = {}) {
|
|
1427
1432
|
const defs = {
|
|
@@ -1444,7 +1449,7 @@ var HttpClient = class _HttpClient {
|
|
|
1444
1449
|
showMaxArrayItems: "number default 5",
|
|
1445
1450
|
showMaxChars: "number default 300"
|
|
1446
1451
|
};
|
|
1447
|
-
const discovered = context?.params?.getAllForModule?.(defs) ?? {};
|
|
1452
|
+
const discovered = context?.params?.getAllForModule?.("http-client2", defs) ?? {};
|
|
1448
1453
|
const merged = { ...discovered, ...options };
|
|
1449
1454
|
if ((merged.saveMock || merged.useMock) && !merged.mocksPath) {
|
|
1450
1455
|
throw new ParamError("[http-client2] mocksPath is required when saveMock or useMock is set");
|
|
@@ -1459,7 +1464,7 @@ var HttpClient = class _HttpClient {
|
|
|
1459
1464
|
const timeout = options.timeout ?? this.config.timeout;
|
|
1460
1465
|
const retryCount = options.retryCount ?? this.config.retryCount ?? 3;
|
|
1461
1466
|
const retryDelay = options.retryDelay ?? this.config.retryDelay ?? 1e3;
|
|
1462
|
-
|
|
1467
|
+
const fullUrl = buildUrl(this.config.baseURL, url, options.params);
|
|
1463
1468
|
if (this.config.useMock && this.mockStorage) {
|
|
1464
1469
|
try {
|
|
1465
1470
|
const urlObj = new URL(fullUrl);
|
|
@@ -1640,21 +1645,20 @@ var HttpClient = class _HttpClient {
|
|
|
1640
1645
|
const maxKeys = this.config.showMaxKeys ?? 20;
|
|
1641
1646
|
const maxArray = this.config.showMaxArrayItems ?? 5;
|
|
1642
1647
|
const maxChars = this.config.showMaxChars ?? 300;
|
|
1643
|
-
|
|
1644
|
-
log(`[HttpClient] ${method} ${url}`);
|
|
1648
|
+
this.logger.info(`[HttpClient] ${method} ${url}`);
|
|
1645
1649
|
if (this.config.showRequestHeaders && reqHeaders && Object.keys(reqHeaders).length > 0) {
|
|
1646
|
-
|
|
1650
|
+
this.logger.info(` Request headers: ${formatForDisplay(reqHeaders, maxKeys, maxArray, maxChars)}`);
|
|
1647
1651
|
}
|
|
1648
1652
|
if (options.data != null) {
|
|
1649
|
-
|
|
1653
|
+
this.logger.info(` Request body: ${formatForDisplay(options.data, maxKeys, maxArray, maxChars)}`);
|
|
1650
1654
|
}
|
|
1651
1655
|
if (res) {
|
|
1652
|
-
|
|
1656
|
+
this.logger.info(` \u2192 ${res.status}${fromMock ? " (from mock)" : ""} ${durationMs}ms`);
|
|
1653
1657
|
if (this.config.showResponseHeaders && res.headers && Object.keys(res.headers).length > 0) {
|
|
1654
|
-
|
|
1658
|
+
this.logger.info(` Response headers: ${formatForDisplay(res.headers, maxKeys, maxArray, maxChars)}`);
|
|
1655
1659
|
}
|
|
1656
1660
|
if (res.data != null) {
|
|
1657
|
-
|
|
1661
|
+
this.logger.info(` Response body: ${formatForDisplay(res.data, maxKeys, maxArray, maxChars)}`);
|
|
1658
1662
|
}
|
|
1659
1663
|
}
|
|
1660
1664
|
}
|