@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.
Files changed (69) hide show
  1. package/README.md +9 -0
  2. package/dist/args.cjs +1 -4
  3. package/dist/args.cjs.map +1 -1
  4. package/dist/args.js +1 -1
  5. package/dist/args.js.map +1 -1
  6. package/dist/cli-runner.cjs +1493 -516
  7. package/dist/cli-runner.cjs.map +1 -1
  8. package/dist/cli-runner.js +1509 -531
  9. package/dist/cli-runner.js.map +1 -1
  10. package/dist/db.cjs +85 -157
  11. package/dist/db.cjs.map +1 -1
  12. package/dist/db.js +84 -150
  13. package/dist/db.js.map +1 -1
  14. package/dist/errors.cjs +2 -2
  15. package/dist/errors.cjs.map +1 -1
  16. package/dist/errors.js +2 -1
  17. package/dist/errors.js.map +1 -1
  18. package/dist/filedatabase.cjs +19 -19
  19. package/dist/filedatabase.cjs.map +1 -1
  20. package/dist/filedatabase.js +19 -16
  21. package/dist/filedatabase.js.map +1 -1
  22. package/dist/http-client.cjs +9 -11
  23. package/dist/http-client.cjs.map +1 -1
  24. package/dist/http-client.js +10 -9
  25. package/dist/http-client.js.map +1 -1
  26. package/dist/http-client2.cjs +34 -33
  27. package/dist/http-client2.cjs.map +1 -1
  28. package/dist/http-client2.js +34 -30
  29. package/dist/http-client2.js.map +1 -1
  30. package/dist/index.cjs +2063 -658
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.js +2063 -663
  33. package/dist/index.js.map +1 -1
  34. package/dist/init.cjs +97 -69
  35. package/dist/init.cjs.map +1 -1
  36. package/dist/init.js +112 -83
  37. package/dist/init.js.map +1 -1
  38. package/dist/logger.cjs +5 -5
  39. package/dist/logger.cjs.map +1 -1
  40. package/dist/logger.js +5 -4
  41. package/dist/logger.js.map +1 -1
  42. package/dist/mock-server.cjs +21 -33
  43. package/dist/mock-server.cjs.map +1 -1
  44. package/dist/mock-server.js +21 -28
  45. package/dist/mock-server.js.map +1 -1
  46. package/dist/params.cjs +22 -10
  47. package/dist/params.cjs.map +1 -1
  48. package/dist/params.js +22 -7
  49. package/dist/params.js.map +1 -1
  50. package/dist/s3.cjs +286 -0
  51. package/dist/s3.cjs.map +1 -0
  52. package/dist/s3.js +273 -0
  53. package/dist/s3.js.map +1 -0
  54. package/dist/screen.cjs +34 -39
  55. package/dist/screen.cjs.map +1 -1
  56. package/dist/screen.js +48 -46
  57. package/dist/screen.js.map +1 -1
  58. package/dist/tasks.cjs +1640 -416
  59. package/dist/tasks.cjs.map +1 -1
  60. package/dist/tasks.js +1614 -412
  61. package/dist/tasks.js.map +1 -1
  62. package/dist/utils.cjs +7 -8
  63. package/dist/utils.cjs.map +1 -1
  64. package/dist/utils.js +6 -6
  65. package/dist/utils.js.map +1 -1
  66. package/package.json +36 -44
  67. package/scripts/ssm/parse-cli.js +35 -0
  68. package/scripts/ssm/ssm-admin.js +151 -0
  69. package/scripts/ssm/ssm-pull.js +147 -0
@@ -1,7 +1,7 @@
1
- // src/http-client2/index.ts
1
+ // src/http-client2/index.js
2
2
  import path4 from "path";
3
3
 
4
- // src/errors.ts
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.ts
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.ts
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.ts
132
+ // src/filedatabase/index.js
132
133
  import fs3 from "fs";
133
134
  import path3 from "path";
134
135
 
135
- // src/utils/os-utils.ts
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.ts
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.ts
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.ts
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.ts
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.ts
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
- let parts = [this.basePath, this.namespace];
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({ write, read, version }) {
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
- await this.makeNewVersion();
823
- this.metadata = this.getDefaultMetadata();
824
- this.metadata.version = this.currentVersion;
825
- this.makeNewFile();
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.ts
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.ts
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). Whatever is in options goes.
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
- let fullUrl = buildUrl(this.config.baseURL, url, options.params);
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
- const log = this.logger.info ?? this.logger.log ?? console.log;
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
- log(` Request headers: ${formatForDisplay(reqHeaders, maxKeys, maxArray, maxChars)}`);
1650
+ this.logger.info(` Request headers: ${formatForDisplay(reqHeaders, maxKeys, maxArray, maxChars)}`);
1647
1651
  }
1648
1652
  if (options.data != null) {
1649
- log(` Request body: ${formatForDisplay(options.data, maxKeys, maxArray, maxChars)}`);
1653
+ this.logger.info(` Request body: ${formatForDisplay(options.data, maxKeys, maxArray, maxChars)}`);
1650
1654
  }
1651
1655
  if (res) {
1652
- log(` \u2192 ${res.status}${fromMock ? " (from mock)" : ""} ${durationMs}ms`);
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
- log(` Response headers: ${formatForDisplay(res.headers, maxKeys, maxArray, maxChars)}`);
1658
+ this.logger.info(` Response headers: ${formatForDisplay(res.headers, maxKeys, maxArray, maxChars)}`);
1655
1659
  }
1656
1660
  if (res.data != null) {
1657
- log(` Response body: ${formatForDisplay(res.data, maxKeys, maxArray, maxChars)}`);
1661
+ this.logger.info(` Response body: ${formatForDisplay(res.data, maxKeys, maxArray, maxChars)}`);
1658
1662
  }
1659
1663
  }
1660
1664
  }