document-dataply 0.0.14-alpha.1 → 0.0.14-alpha.3

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.
@@ -1,7 +1,7 @@
1
1
  import type { AnalysisHeader, DocumentJSON, FlattenedDocumentJSON } from '../types';
2
2
  import type { DocumentDataplyAPI } from './documentAPI';
3
3
  import type { AnalysisProvider } from './AnalysisProvider';
4
- import { Transaction } from 'dataply';
4
+ import { Transaction, Logger } from 'dataply';
5
5
  export declare class AnalysisManager<T extends DocumentJSON> {
6
6
  private api;
7
7
  readonly sampleSize: number;
@@ -9,7 +9,7 @@ export declare class AnalysisManager<T extends DocumentJSON> {
9
9
  private providers;
10
10
  private cron;
11
11
  private flushing;
12
- constructor(api: DocumentDataplyAPI<T>, schedule: string, sampleSize: number, logger: any);
12
+ constructor(api: DocumentDataplyAPI<T>, schedule: string, sampleSize: number, logger: Logger);
13
13
  /**
14
14
  * Stop the background analysis cron job.
15
15
  */
@@ -1,11 +1,11 @@
1
1
  import type { DataplyTreeValue, DocumentDataplyInnerMetadata, Primitive, CreateIndexOption, IndexMetaConfig, FTSConfig, DocumentJSON, FlattenedDocumentJSON } from '../types';
2
2
  import type { DocumentDataplyAPI } from './documentAPI';
3
- import { BPTreeAsync, Transaction } from 'dataply';
3
+ import { BPTreePureAsync, Transaction, Logger } from 'dataply';
4
4
  export declare class IndexManager<T extends DocumentJSON> {
5
5
  private api;
6
6
  private logger;
7
7
  indices: DocumentDataplyInnerMetadata['indices'];
8
- readonly trees: Map<string, BPTreeAsync<string | number, DataplyTreeValue<Primitive>>>;
8
+ readonly trees: Map<string, BPTreePureAsync<string | number, DataplyTreeValue<Primitive>>>;
9
9
  readonly indexedFields: Set<string>;
10
10
  /**
11
11
  * Registered indices via createIndex() (before init)
@@ -23,7 +23,7 @@ export declare class IndexManager<T extends DocumentJSON> {
23
23
  */
24
24
  fieldToIndices: Map<string, string[]>;
25
25
  pendingBackfillFields: string[];
26
- constructor(api: DocumentDataplyAPI<T>, logger: any);
26
+ constructor(api: DocumentDataplyAPI<T>, logger: Logger);
27
27
  /**
28
28
  * Validate and apply indices from DB metadata and pending indices.
29
29
  * Called during database initialization.
@@ -1,10 +1,10 @@
1
1
  import type { DocumentDataplyMetadata, DocumentDataplyInnerMetadata, DocumentJSON } from '../types';
2
2
  import type { DocumentDataplyAPI } from './documentAPI';
3
- import { Transaction } from 'dataply';
3
+ import { Transaction, Logger } from 'dataply';
4
4
  export declare class MetadataManager<T extends DocumentJSON> {
5
5
  private api;
6
6
  private logger;
7
- constructor(api: DocumentDataplyAPI<T>, logger: any);
7
+ constructor(api: DocumentDataplyAPI<T>, logger: Logger);
8
8
  getDocumentMetadata(tx: Transaction): Promise<DocumentDataplyMetadata>;
9
9
  getDocumentInnerMetadata(tx: Transaction): Promise<DocumentDataplyInnerMetadata>;
10
10
  updateDocumentInnerMetadata(metadata: DocumentDataplyInnerMetadata, tx: Transaction): Promise<void>;
@@ -1,10 +1,10 @@
1
1
  import type { DocumentJSON, DataplyDocument, DocumentDataplyQuery } from '../types';
2
2
  import type { DocumentDataplyAPI } from './documentAPI';
3
- import { Transaction } from 'dataply';
3
+ import { Transaction, Logger } from 'dataply';
4
4
  export declare class MutationManager<T extends DocumentJSON> {
5
5
  private api;
6
6
  private logger;
7
- constructor(api: DocumentDataplyAPI<T>, logger: any);
7
+ constructor(api: DocumentDataplyAPI<T>, logger: Logger);
8
8
  private isTreeEmpty;
9
9
  private insertDocumentInternal;
10
10
  insertSingleDocument(document: T, tx?: Transaction): Promise<number>;
@@ -1,14 +1,14 @@
1
1
  import type { DataplyTreeValue, DocumentDataplyQuery, DocumentDataplyCondition } from '../types';
2
2
  import type { DocumentDataplyAPI } from './documentAPI';
3
- import { BPTreeAsync } from 'dataply';
3
+ import { BPTreePureAsync } from 'dataply';
4
4
  export declare class Optimizer<T extends Record<string, any>> {
5
5
  private api;
6
6
  constructor(api: DocumentDataplyAPI<T>);
7
7
  /**
8
8
  * B-Tree 타입 인덱스의 선택도를 평가하고 트리에 부여할 조건을 산출합니다.
9
9
  */
10
- evaluateBTreeCandidate<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(indexName: string, config: any, query: Partial<DocumentDataplyQuery<V>>, queryFields: Set<string>, treeTx: BPTreeAsync<string | number, V>, orderByField?: string): {
11
- readonly tree: BPTreeAsync<string | number, V>;
10
+ evaluateBTreeCandidate<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(indexName: string, config: any, query: Partial<DocumentDataplyQuery<V>>, queryFields: Set<string>, treeTx: BPTreePureAsync<string | number, V>, orderByField?: string): {
11
+ readonly tree: BPTreePureAsync<string | number, V>;
12
12
  readonly condition: any;
13
13
  readonly field: any;
14
14
  readonly indexName: string;
@@ -22,8 +22,8 @@ export declare class Optimizer<T extends Record<string, any>> {
22
22
  * FTS 타입 인덱스의 선택도를 평가합니다.
23
23
  * FTSTermCount 통계가 있으면 실측 데이터 기반으로 선택도를 산출합니다.
24
24
  */
25
- evaluateFTSCandidate<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(indexName: string, config: any, query: Partial<DocumentDataplyQuery<V>>, queryFields: Set<string>, treeTx: BPTreeAsync<string | number, V>): {
26
- tree: BPTreeAsync<string | number, V>;
25
+ evaluateFTSCandidate<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(indexName: string, config: any, query: Partial<DocumentDataplyQuery<V>>, queryFields: Set<string>, tree: BPTreePureAsync<string | number, V>): {
26
+ tree: BPTreePureAsync<string | number, V>;
27
27
  condition: any;
28
28
  field: any;
29
29
  indexName: string;
@@ -49,14 +49,14 @@ export declare class Optimizer<T extends Record<string, any>> {
49
49
  */
50
50
  getSelectivityCandidate<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(query: Partial<DocumentDataplyQuery<V>>, orderByField?: string, limit?: number, offset?: number): Promise<{
51
51
  driver: ({
52
- tree: BPTreeAsync<number, V>;
52
+ tree: BPTreePureAsync<number, V>;
53
53
  condition: Partial<DocumentDataplyCondition<U>>;
54
54
  field: string;
55
55
  indexName: string;
56
56
  isFtsMatch: false;
57
57
  isIndexOrderSupported: boolean;
58
58
  } | {
59
- tree: BPTreeAsync<string, V>;
59
+ tree: BPTreePureAsync<string, V>;
60
60
  condition: Partial<DocumentDataplyCondition<U>>;
61
61
  field: string;
62
62
  indexName: string;
@@ -65,14 +65,14 @@ export declare class Optimizer<T extends Record<string, any>> {
65
65
  isIndexOrderSupported: boolean;
66
66
  });
67
67
  others: ({
68
- tree: BPTreeAsync<number, V>;
68
+ tree: BPTreePureAsync<number, V>;
69
69
  condition: Partial<DocumentDataplyCondition<U>>;
70
70
  field: string;
71
71
  indexName: string;
72
72
  isFtsMatch: false;
73
73
  isIndexOrderSupported: boolean;
74
74
  } | {
75
- tree: BPTreeAsync<string, V>;
75
+ tree: BPTreePureAsync<string, V>;
76
76
  condition: Partial<DocumentDataplyCondition<U>>;
77
77
  field: string;
78
78
  indexName: string;
@@ -84,6 +84,5 @@ export declare class Optimizer<T extends Record<string, any>> {
84
84
  field: string;
85
85
  condition: any;
86
86
  }[];
87
- rollback: () => void;
88
87
  } | null>;
89
88
  }
@@ -1,13 +1,13 @@
1
1
  import type { DataplyTreeValue, DocumentDataplyQuery, DocumentDataplyQueryOptions, DataplyDocument, Primitive, DocumentJSON } from '../types';
2
2
  import type { DocumentDataplyAPI } from './documentAPI';
3
3
  import type { Optimizer } from './Optimizer';
4
- import { BPTreeAsync } from 'dataply';
4
+ import { BPTreePureAsync, Logger } from 'dataply';
5
5
  export declare class QueryManager<T extends DocumentJSON> {
6
6
  private api;
7
7
  private optimizer;
8
8
  private logger;
9
9
  private readonly operatorConverters;
10
- constructor(api: DocumentDataplyAPI<T>, optimizer: Optimizer<T>, logger: any);
10
+ constructor(api: DocumentDataplyAPI<T>, optimizer: Optimizer<T>, logger: Logger);
11
11
  /**
12
12
  * Transforms a query object into a verbose query object
13
13
  */
@@ -22,7 +22,7 @@ export declare class QueryManager<T extends DocumentJSON> {
22
22
  getDriverKeys(query: Partial<DocumentDataplyQuery<T>>, orderBy?: string, sortOrder?: 'asc' | 'desc', limit?: number, offset?: number): Promise<{
23
23
  keysStream: AsyncIterableIterator<number>;
24
24
  others: {
25
- tree: BPTreeAsync<string | number, DataplyTreeValue<Primitive>>;
25
+ tree: BPTreePureAsync<string | number, DataplyTreeValue<Primitive>>;
26
26
  condition: any;
27
27
  field: string;
28
28
  indexName: string;
@@ -35,7 +35,6 @@ export declare class QueryManager<T extends DocumentJSON> {
35
35
  condition: any;
36
36
  }[];
37
37
  isDriverOrderByField: boolean;
38
- rollback: () => void;
39
38
  } | null>;
40
39
  verifyFts(doc: DataplyDocument<T>, ftsConditions: {
41
40
  field: string;
@@ -62,7 +61,7 @@ export declare class QueryManager<T extends DocumentJSON> {
62
61
  field: string;
63
62
  condition: any;
64
63
  }[], others: {
65
- tree: BPTreeAsync<string | number, DataplyTreeValue<Primitive>>;
64
+ tree: BPTreePureAsync<string | number, DataplyTreeValue<Primitive>>;
66
65
  condition: any;
67
66
  field: string;
68
67
  indexName: string;
@@ -1,5 +1,5 @@
1
1
  import type { DataplyTreeValue, Primitive } from '../../types';
2
- import { BPTreeNode, SerializeStrategyAsync, type SerializeStrategyHead } from 'dataply';
2
+ import { type SerializeStrategyHead, type BPTreeNode, SerializeStrategyAsync } from 'dataply';
3
3
  import { DocumentDataplyAPI } from '../documentAPI';
4
4
  export declare class DocumentSerializeStrategyAsync<T extends Primitive> extends SerializeStrategyAsync<number, DataplyTreeValue<T>> {
5
5
  protected readonly api: DocumentDataplyAPI<any>;
@@ -15,6 +15,11 @@ export declare class DocumentSerializeStrategyAsync<T extends Primitive> extends
15
15
  read(id: string): Promise<BPTreeNode<number, DataplyTreeValue<T>>>;
16
16
  write(id: string, node: BPTreeNode<number, DataplyTreeValue<T>>): Promise<void>;
17
17
  delete(id: string): Promise<void>;
18
+ /**
19
+ * headPk 행이 가리키는 B+Tree의 모든 노드 행과 head 행 자체를 삭제합니다.
20
+ * dropIndex 시 행을 회수하기 위해 사용합니다.
21
+ */
22
+ clearAllNodes(headPk: number): Promise<void>;
18
23
  readHead(): Promise<SerializeStrategyHead | null>;
19
24
  writeHead(head: SerializeStrategyHead): Promise<void>;
20
25
  }
@@ -30,6 +30,20 @@ export declare class DocumentDataply<T extends DocumentJSON> {
30
30
  private static Open;
31
31
  protected readonly api: DocumentDataplyAPI<T>;
32
32
  protected constructor(file: string, options?: DocumentDataplyOptions);
33
+ /**
34
+ * Method for reliably processing large batches (chunks) of data.
35
+ * Processes data in fragments to prevent blocking the event loop while handling large volumes of data.
36
+ * @param items The items to process
37
+ * @param callback The callback to process each chunk
38
+ * @param options The options for the chunk splitter
39
+ * @param options.firstChunkSize The size of the first chunk. Subsequent chunk sizes are determined based on this value and the processing time. If not specified or set to 0, 5% of the total data is used as the initial value.
40
+ * @param options.alpha A value that determines the weight given to recent processing times. Higher values weigh recent times more heavily. Lower values are recommended for stability, but excessively low values may impact performance. Default is 0.5.
41
+ * @returns The processed items
42
+ */
43
+ processInChunks<T>(items: T[], callback: (chunk: T[]) => Promise<void>, options?: {
44
+ firstChunkSize?: number;
45
+ alpha?: number;
46
+ }): Promise<void>;
33
47
  /**
34
48
  * Create a named index on the database.
35
49
  * Can be called before or after init().
@@ -80,9 +94,17 @@ export declare class DocumentDataply<T extends DocumentJSON> {
80
94
  */
81
95
  getMetadata(tx?: Transaction): Promise<DocumentDataplyMetadata>;
82
96
  /**
83
- * Create a transaction
97
+ * Run a callback in a write transaction
98
+ * @param callback The callback to run
99
+ * @param tx Optional transaction
100
+ */
101
+ withWriteTransaction(callback: (tx: Transaction) => Promise<void>, tx?: Transaction): Promise<void>;
102
+ /**
103
+ * Run a callback in a read transaction
104
+ * @param callback The callback to run
105
+ * @param tx Optional transaction
84
106
  */
85
- createTransaction(): Transaction;
107
+ withReadTransaction(callback: (tx: Transaction) => Promise<void>, tx?: Transaction): Promise<void>;
86
108
  /**
87
109
  * Insert a document into the database
88
110
  * @param document The document to insert
@@ -9,9 +9,6 @@ import { MetadataManager } from './MetadataManager';
9
9
  import { DocumentFormatter } from './DocumentFormatter';
10
10
  import { AnalysisManager } from './AnalysisManager';
11
11
  export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyAPI {
12
- runWithDefault: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
13
- runWithDefaultWrite: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
14
- streamWithDefault: <T_1>(callback: (tx: Transaction) => AsyncGenerator<T_1>, tx?: Transaction) => AsyncGenerator<T_1>;
15
12
  readonly comparator: DocumentValueComparator<import("../types").DataplyTreeValue<import("../types").Primitive>, import("../types").Primitive>;
16
13
  private _initialized;
17
14
  readonly optimizer: Optimizer<T>;
@@ -29,8 +26,22 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyA
29
26
  get indices(): {
30
27
  [key: string]: [number, import("../types").IndexMetaConfig];
31
28
  };
32
- get trees(): Map<string, import("dataply").BPTreeAsync<string | number, import("../types").DataplyTreeValue<import("../types").Primitive>>>;
29
+ get trees(): Map<string, import("dataply").BPTreePureAsync<string | number, import("../types").DataplyTreeValue<import("../types").Primitive>>>;
33
30
  get indexedFields(): Set<string>;
31
+ /**
32
+ * Method for reliably processing large batches (chunks) of data.
33
+ * Processes data in fragments to prevent blocking the event loop while handling large volumes of data.
34
+ * @param items The items to process
35
+ * @param callback The callback to process each chunk
36
+ * @param options The options for the chunk splitter
37
+ * @param options.firstChunkSize The size of the first chunk. Subsequent chunk sizes are determined based on this value and the processing time. If not specified or set to 0, 5% of the total data is used as the initial value.
38
+ * @param options.alpha A value that determines the weight given to recent processing times. Higher values weigh recent times more heavily. Lower values are recommended for stability, but excessively low values may impact performance. Default is 0.5.
39
+ * @returns The processed items
40
+ */
41
+ processInChunks<T>(items: T[], callback: (chunk: T[]) => Promise<void>, options?: {
42
+ firstChunkSize?: number;
43
+ alpha?: number;
44
+ }): Promise<void>;
34
45
  /**
35
46
  * Register an index.
36
47
  * @param name The name of the index
@@ -1,3 +1,4 @@
1
+ export declare function yieldEventLoop(): Promise<unknown>;
1
2
  /**
2
3
  * 이벤트 루프를 막지 않고 대량의 데이터를 처리하기 위한 유틸리티 클래스
3
4
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-dataply",
3
- "version": "0.0.14-alpha.1",
3
+ "version": "0.0.14-alpha.3",
4
4
  "description": "Simple and powerful JSON document database supporting complex queries and flexible indexing policies.",
5
5
  "license": "MIT",
6
6
  "author": "izure <admin@izure.org>",
@@ -43,7 +43,7 @@
43
43
  ],
44
44
  "dependencies": {
45
45
  "croner": "^10.0.1",
46
- "dataply": "^0.0.26-alpha.2"
46
+ "dataply": "^0.0.26-alpha.15"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/jest": "^30.0.0",
@@ -52,4 +52,4 @@
52
52
  "ts-jest": "^29.4.6",
53
53
  "typescript": "^5.9.3"
54
54
  }
55
- }
55
+ }