dataply 0.0.26-alpha.0 → 0.0.26-alpha.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/cjs/index.js CHANGED
@@ -8053,6 +8053,14 @@ var HookallSync = class _HookallSync {
8053
8053
  // src/core/WALManager.ts
8054
8054
  var import_node_fs = __toESM(require("node:fs"));
8055
8055
  var WALManager = class {
8056
+ fd = null;
8057
+ walFilePath;
8058
+ pageSize;
8059
+ entrySize;
8060
+ buffer;
8061
+ view;
8062
+ totalWrittenPages = 0;
8063
+ logger;
8056
8064
  /**
8057
8065
  * Constructor
8058
8066
  * @param walFilePath WAL file path
@@ -8060,7 +8068,6 @@ var WALManager = class {
8060
8068
  * @param logger Logger instance
8061
8069
  */
8062
8070
  constructor(walFilePath, pageSize, logger) {
8063
- this.logger = logger;
8064
8071
  if ((pageSize & pageSize - 1) !== 0) {
8065
8072
  throw new Error("Page size must be a power of 2");
8066
8073
  }
@@ -8069,14 +8076,8 @@ var WALManager = class {
8069
8076
  this.entrySize = 4 + pageSize;
8070
8077
  this.buffer = new Uint8Array(this.entrySize);
8071
8078
  this.view = new DataView(this.buffer.buffer);
8079
+ this.logger = logger;
8072
8080
  }
8073
- fd = null;
8074
- walFilePath;
8075
- pageSize;
8076
- entrySize;
8077
- buffer;
8078
- view;
8079
- totalWrittenPages = 0;
8080
8081
  /**
8081
8082
  * Opens the log file.
8082
8083
  */
@@ -8424,21 +8425,22 @@ var PageFileSystem = class {
8424
8425
  * @param pageCacheCapacity 페이지 캐시 크기
8425
8426
  * @param options 데이터플라이 옵션
8426
8427
  */
8427
- constructor(fileHandle, pageSize, pageCacheCapacity, options, logger) {
8428
+ constructor(fileHandle, pageSize, pageCacheCapacity, options, logger, walLogger) {
8428
8429
  this.fileHandle = fileHandle;
8429
8430
  this.pageSize = pageSize;
8430
8431
  this.pageCacheCapacity = pageCacheCapacity;
8431
8432
  this.options = options;
8432
- this.logger = logger;
8433
8433
  const walPath = options.wal;
8434
- this.walManager = walPath ? new WALManager(walPath, pageSize, this.logger) : null;
8434
+ this.walManager = walPath && walLogger ? new WALManager(walPath, pageSize, walLogger) : null;
8435
8435
  this.pageManagerFactory = new PageManagerFactory();
8436
8436
  this.pageStrategy = new PageMVCCStrategy(fileHandle, pageSize, pageCacheCapacity);
8437
+ this.logger = logger;
8437
8438
  }
8438
8439
  pageFactory = new PageManagerFactory();
8439
8440
  walManager;
8440
8441
  pageManagerFactory;
8441
8442
  pageStrategy;
8443
+ logger;
8442
8444
  /** 글로벌 동기화(체크포인트/커밋)를 위한 Mutex */
8443
8445
  lockPromise = Promise.resolve();
8444
8446
  /**
@@ -9052,13 +9054,13 @@ var RowTableEngine = class {
9052
9054
  this.pfs = pfs;
9053
9055
  this.txContext = txContext;
9054
9056
  this.options = options;
9055
- this.logger = logger;
9056
9057
  this.factory = new PageManagerFactory();
9057
9058
  this.metadataPageManager = this.factory.getManagerFromType(MetadataPageManager.CONSTANT.PAGE_TYPE_METADATA);
9058
9059
  this.dataPageManager = this.factory.getManagerFromType(DataPageManager.CONSTANT.PAGE_TYPE_DATA);
9059
9060
  this.overflowPageManager = this.factory.getManagerFromType(OverflowPageManager.CONSTANT.PAGE_TYPE_OVERFLOW);
9060
9061
  this.rowManager = new Row();
9061
9062
  this.keyManager = new KeyManager();
9063
+ this.logger = logger;
9062
9064
  this.ridBuffer = new Uint8Array(Row.CONSTANT.SIZE_RID);
9063
9065
  this.pageIdBuffer = new Uint8Array(DataPageManager.CONSTANT.SIZE_PAGE_ID);
9064
9066
  this.maxBodySize = this.pfs.pageSize - DataPageManager.CONSTANT.SIZE_PAGE_HEADER;
@@ -9087,6 +9089,7 @@ var RowTableEngine = class {
9087
9089
  maxBodySize;
9088
9090
  ridBuffer;
9089
9091
  pageIdBuffer;
9092
+ logger;
9090
9093
  initialized = false;
9091
9094
  /**
9092
9095
  * Retrieves the BPTree transaction associated with the given transaction.
@@ -9860,12 +9863,11 @@ var Colors = {
9860
9863
  white: "\x1B[37m",
9861
9864
  // White
9862
9865
  grey: "\x1B[90m"
9866
+ // Grey
9863
9867
  };
9864
- var Logger = class {
9868
+ var LoggerManager = class {
9865
9869
  level;
9866
- moduleName;
9867
- constructor(moduleName, level = 2 /* Info */) {
9868
- this.moduleName = moduleName;
9870
+ constructor(level = 2 /* Info */) {
9869
9871
  this.level = level;
9870
9872
  }
9871
9873
  setLevel(level) {
@@ -9875,23 +9877,32 @@ var Logger = class {
9875
9877
  if (this.level === 0 /* None */) return false;
9876
9878
  return level >= this.level;
9877
9879
  }
9880
+ create(moduleName) {
9881
+ return new Logger(this, moduleName);
9882
+ }
9883
+ };
9884
+ var Logger = class {
9885
+ constructor(parent, moduleName) {
9886
+ this.parent = parent;
9887
+ this.moduleName = moduleName;
9888
+ }
9878
9889
  debug(message, ...args) {
9879
- if (this.shouldLog(1 /* Debug */)) {
9890
+ if (this.parent.shouldLog(1 /* Debug */)) {
9880
9891
  console.debug(`${Colors.debug}[DEBUG] [${this.moduleName}]${Colors.reset} ${Colors.white}${message}${Colors.reset}`, ...args);
9881
9892
  }
9882
9893
  }
9883
9894
  info(message, ...args) {
9884
- if (this.shouldLog(2 /* Info */)) {
9895
+ if (this.parent.shouldLog(2 /* Info */)) {
9885
9896
  console.info(`${Colors.info}[INFO] [${this.moduleName}]${Colors.reset} ${Colors.white}${message}${Colors.reset}`, ...args);
9886
9897
  }
9887
9898
  }
9888
9899
  warn(message, ...args) {
9889
- if (this.shouldLog(3 /* Warning */)) {
9900
+ if (this.parent.shouldLog(3 /* Warning */)) {
9890
9901
  console.warn(`${Colors.warn}[WARN] [${this.moduleName}]${Colors.reset} ${Colors.white}${message}${Colors.reset}`, ...args);
9891
9902
  }
9892
9903
  }
9893
9904
  error(message, ...args) {
9894
- if (this.shouldLog(4 /* Error */)) {
9905
+ if (this.parent.shouldLog(4 /* Error */)) {
9895
9906
  console.error(`${Colors.error}[ERROR] [${this.moduleName}]${Colors.reset} ${Colors.white}${message}${Colors.reset}`, ...args);
9896
9907
  }
9897
9908
  }
@@ -9903,7 +9914,8 @@ var DataplyAPI = class {
9903
9914
  this.file = file;
9904
9915
  this.hook = useHookall(this);
9905
9916
  this.options = this.verboseOptions(options);
9906
- this.logger = new Logger("DataplyAPI", this.options.logLevel);
9917
+ this.loggerManager = new LoggerManager(this.options.logLevel);
9918
+ this.logger = this.loggerManager.create("DataplyAPI");
9907
9919
  this.isNewlyCreated = !import_node_fs3.default.existsSync(file);
9908
9920
  this.fileHandle = this.createOrOpen(file, this.options);
9909
9921
  this.pfs = new PageFileSystem(
@@ -9911,12 +9923,13 @@ var DataplyAPI = class {
9911
9923
  this.options.pageSize,
9912
9924
  this.options.pageCacheCapacity,
9913
9925
  this.options,
9914
- this.logger
9926
+ this.loggerManager.create("PageFileSystem"),
9927
+ options.wal ? this.loggerManager.create("WALManager") : void 0
9915
9928
  );
9916
9929
  this.textCodec = new TextCodec();
9917
9930
  this.txContext = new TransactionContext();
9918
9931
  this.lockManager = new LockManager();
9919
- this.rowTableEngine = new RowTableEngine(this.pfs, this.txContext, this.options, this.logger);
9932
+ this.rowTableEngine = new RowTableEngine(this.pfs, this.txContext, this.options, this.loggerManager.create("RowTableEngine"));
9920
9933
  this.initialized = false;
9921
9934
  this.txIdCounter = 0;
9922
9935
  this.logger.debug(`DataplyAPI instance created with file: ${file}`);
@@ -9941,7 +9954,9 @@ var DataplyAPI = class {
9941
9954
  txContext;
9942
9955
  /** Hook */
9943
9956
  hook;
9944
- /** Logger */
9957
+ /** Base Logger */
9958
+ loggerManager;
9959
+ /** Logger module for DataplyAPI */
9945
9960
  logger;
9946
9961
  /** Whether the database was initialized via `init()` */
9947
9962
  initialized;
@@ -6,7 +6,7 @@ import { TextCodec } from '../utils/TextCodec';
6
6
  import { LockManager } from './transaction/LockManager';
7
7
  import { Transaction } from './transaction/Transaction';
8
8
  import { TransactionContext } from './transaction/TxContext';
9
- import { Logger } from './Logger';
9
+ import { LoggerManager, Logger } from './Logger';
10
10
  interface DataplyAPIAsyncHook {
11
11
  init: (tx: Transaction, isNewlyCreated: boolean) => Promise<Transaction>;
12
12
  close: () => Promise<void>;
@@ -36,7 +36,9 @@ export declare class DataplyAPI {
36
36
  protected readonly txContext: TransactionContext;
37
37
  /** Hook */
38
38
  protected readonly hook: IHookall<DataplyAPIAsyncHook>;
39
- /** Logger */
39
+ /** Base Logger */
40
+ protected readonly loggerManager: LoggerManager;
41
+ /** Logger module for DataplyAPI */
40
42
  protected readonly logger: Logger;
41
43
  /** Whether the database was initialized via `init()` */
42
44
  protected initialized: boolean;
@@ -1,10 +1,15 @@
1
1
  import { LogLevel } from '../types';
2
- export declare class Logger {
2
+ export declare class LoggerManager {
3
3
  private level;
4
- private moduleName;
5
- constructor(moduleName: string, level?: LogLevel);
4
+ constructor(level?: LogLevel);
6
5
  setLevel(level: LogLevel): void;
7
- private shouldLog;
6
+ shouldLog(level: LogLevel): boolean;
7
+ create(moduleName: string): Logger;
8
+ }
9
+ export declare class Logger {
10
+ private readonly parent;
11
+ private readonly moduleName;
12
+ constructor(parent: LoggerManager, moduleName: string);
8
13
  debug(message: string, ...args: any[]): void;
9
14
  info(message: string, ...args: any[]): void;
10
15
  warn(message: string, ...args: any[]): void;
@@ -13,18 +13,18 @@ export declare class PageFileSystem {
13
13
  readonly pageSize: number;
14
14
  readonly pageCacheCapacity: number;
15
15
  readonly options: Required<DataplyOptions>;
16
- protected readonly logger: Logger;
17
16
  protected readonly pageFactory: PageManagerFactory;
18
17
  protected readonly walManager: WALManager | null;
19
18
  protected readonly pageManagerFactory: PageManagerFactory;
20
19
  protected readonly pageStrategy: PageMVCCStrategy;
20
+ protected readonly logger: Logger;
21
21
  /** 글로벌 동기화(체크포인트/커밋)를 위한 Mutex */
22
22
  private lockPromise;
23
23
  /**
24
24
  * @param pageCacheCapacity 페이지 캐시 크기
25
25
  * @param options 데이터플라이 옵션
26
26
  */
27
- constructor(fileHandle: number, pageSize: number, pageCacheCapacity: number, options: Required<DataplyOptions>, logger: Logger);
27
+ constructor(fileHandle: number, pageSize: number, pageCacheCapacity: number, options: Required<DataplyOptions>, logger: Logger, walLogger?: Logger);
28
28
  /**
29
29
  * 글로벌 동기화 범위 내에서 작업을 실행합니다.
30
30
  * @param task 수행할 비동기 작업
@@ -12,7 +12,6 @@ export declare class RowTableEngine {
12
12
  protected readonly pfs: PageFileSystem;
13
13
  protected readonly txContext: TransactionContext;
14
14
  protected readonly options: Required<DataplyOptions>;
15
- protected readonly logger: Logger;
16
15
  protected readonly bptree: BPTreeAsync<number, number>;
17
16
  protected readonly strategy: RowIdentifierStrategy;
18
17
  protected readonly order: number;
@@ -25,6 +24,7 @@ export declare class RowTableEngine {
25
24
  protected readonly maxBodySize: number;
26
25
  private readonly ridBuffer;
27
26
  private readonly pageIdBuffer;
27
+ private readonly logger;
28
28
  private initialized;
29
29
  constructor(pfs: PageFileSystem, txContext: TransactionContext, options: Required<DataplyOptions>, logger: Logger);
30
30
  /**
@@ -5,7 +5,6 @@ import { Logger } from './Logger';
5
5
  * Handles commit phases and crash recovery.
6
6
  */
7
7
  export declare class WALManager {
8
- private readonly logger;
9
8
  private fd;
10
9
  private readonly walFilePath;
11
10
  private readonly pageSize;
@@ -13,6 +12,7 @@ export declare class WALManager {
13
12
  private buffer;
14
13
  private view;
15
14
  private totalWrittenPages;
15
+ private readonly logger;
16
16
  /**
17
17
  * Constructor
18
18
  * @param walFilePath WAL file path
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataply",
3
- "version": "0.0.26-alpha.0",
3
+ "version": "0.0.26-alpha.1",
4
4
  "description": "A lightweight storage engine for Node.js with support for MVCC, WAL.",
5
5
  "license": "MIT",
6
6
  "author": "izure <admin@izure.org>",