@nmakarov/cli-toolkit 0.11.0 → 0.11.2

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 CHANGED
@@ -2108,7 +2108,37 @@ var FileDatabase = class {
2108
2108
  // Synopsis calculation functions
2109
2109
  fileSynopsisFunction = null;
2110
2110
  versionSynopsisFunction = null;
2111
- constructor(config2) {
2111
+ /**
2112
+ * Constructor - accepts context as first parameter (new pattern)
2113
+ * or config object (legacy pattern for backward compatibility)
2114
+ */
2115
+ constructor(contextOrConfig, options) {
2116
+ let config2;
2117
+ if (contextOrConfig && typeof contextOrConfig === "object" && "params" in contextOrConfig) {
2118
+ const context = contextOrConfig;
2119
+ const opts = options || {};
2120
+ const defs = {
2121
+ basePath: "string default ./data",
2122
+ namespace: "string default default",
2123
+ tableName: "string",
2124
+ maxVersions: "number default 5",
2125
+ pageSize: "number default 5000"
2126
+ };
2127
+ const paramsConfig = context.params.getAll(defs);
2128
+ config2 = {
2129
+ basePath: opts.basePath ?? paramsConfig.basePath,
2130
+ namespace: opts.namespace ?? paramsConfig.namespace,
2131
+ tableName: opts.tableName ?? paramsConfig.tableName ?? null,
2132
+ versioned: opts.versioned ?? true,
2133
+ maxVersions: opts.maxVersions ?? paramsConfig.maxVersions,
2134
+ pageSize: opts.pageSize ?? paramsConfig.pageSize,
2135
+ useMetadata: opts.useMetadata ?? true,
2136
+ freeSpaceThreshold: opts.freeSpaceThreshold ?? 100 * 1024 * 1024,
2137
+ logger: context.logger
2138
+ };
2139
+ } else {
2140
+ config2 = contextOrConfig;
2141
+ }
2112
2142
  if (!config2.basePath) {
2113
2143
  throw new ParamError("[FileDatabase] basePath is required");
2114
2144
  }
@@ -2476,6 +2506,12 @@ var FileDatabase = class {
2476
2506
  figureOutDataAndFileToWrite(data) {
2477
2507
  let dataToWrite;
2478
2508
  let dataLeftOver;
2509
+ if (!this.metadata.dataType) {
2510
+ this.metadata.dataType = detectDataType(data);
2511
+ }
2512
+ if (this.metadata.files.length === 0) {
2513
+ this.makeNewFile();
2514
+ }
2479
2515
  const lastFile = this.metadata.files[this.metadata.files.length - 1];
2480
2516
  const lastFileRecordsCount = lastFile.recordsCount;
2481
2517
  if (Array.isArray(data)) {
@@ -2791,6 +2827,9 @@ var FileDatabase = class {
2791
2827
  return { ...this.metadata };
2792
2828
  }
2793
2829
  };
2830
+ function fileDatabaseInit(context, options = {}) {
2831
+ return new FileDatabase(context, options);
2832
+ }
2794
2833
 
2795
2834
  // src/db/index.ts
2796
2835
  import knex from "knex";
@@ -3482,6 +3521,7 @@ export {
3482
3521
  buildFooter,
3483
3522
  defaultFileSynopsisFunction,
3484
3523
  defaultVersionSynopsisFunction,
3524
+ fileDatabaseInit,
3485
3525
  getArgsInstance,
3486
3526
  createElement2 as h,
3487
3527
  joiEdateType,