document-dataply 0.0.10-alpha.3 → 0.0.10-alpha.5
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 +1871 -1310
- package/dist/types/core/AnalysisManager.d.ts +105 -0
- package/dist/types/core/AnalysisProvider.d.ts +30 -0
- package/dist/types/core/DocumentFormatter.d.ts +5 -0
- package/dist/types/core/IndexManager.d.ts +68 -0
- package/dist/types/core/IntervalAnalysisProvider.d.ts +31 -0
- package/dist/types/core/MetadataManager.d.ts +11 -0
- package/dist/types/core/MutationManager.d.ts +14 -0
- package/dist/types/core/Optimizer.d.ts +79 -0
- package/dist/types/core/QueryManager.d.ts +75 -0
- package/dist/types/core/RealtimeAnalysisProvider.d.ts +27 -0
- package/dist/types/core/analysis/FTSTermCount.d.ts +28 -0
- package/dist/types/core/analysis/index.d.ts +2 -0
- package/dist/types/core/document.d.ts +6 -0
- package/dist/types/core/documentAPI.d.ts +62 -193
- package/dist/types/types/index.d.ts +8 -0
- package/package.json +2 -2
|
@@ -1,100 +1,102 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { DataplyAPI, Transaction
|
|
1
|
+
import type { DocumentDataplyInnerMetadata, DocumentDataplyOptions, DocumentJSON, FlattenedDocumentJSON, DataplyDocument, DocumentDataplyMetadata, DocumentDataplyQuery, DocumentDataplyQueryOptions, CreateIndexOption } from '../types';
|
|
2
|
+
import { DataplyAPI, Transaction } from 'dataply';
|
|
3
3
|
import { DocumentValueComparator } from './bptree/documentComparator';
|
|
4
|
+
import { Optimizer } from './Optimizer';
|
|
5
|
+
import { QueryManager } from './QueryManager';
|
|
6
|
+
import { IndexManager } from './IndexManager';
|
|
7
|
+
import { MutationManager } from './MutationManager';
|
|
8
|
+
import { MetadataManager } from './MetadataManager';
|
|
9
|
+
import { DocumentFormatter } from './DocumentFormatter';
|
|
10
|
+
import { AnalysisManager } from './AnalysisManager';
|
|
4
11
|
export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyAPI {
|
|
5
12
|
runWithDefault: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
|
|
6
13
|
runWithDefaultWrite: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
|
|
7
14
|
streamWithDefault: <T_1>(callback: (tx: Transaction) => AsyncGenerator<T_1>, tx?: Transaction) => AsyncGenerator<T_1>;
|
|
8
|
-
|
|
9
|
-
readonly trees: Map<string, BPTreeAsync<string | number, DataplyTreeValue<Primitive>>>;
|
|
10
|
-
readonly comparator: DocumentValueComparator<DataplyTreeValue<Primitive>, Primitive>;
|
|
11
|
-
private pendingBackfillFields;
|
|
15
|
+
readonly comparator: DocumentValueComparator<import("../types").DataplyTreeValue<import("../types").Primitive>, import("../types").Primitive>;
|
|
12
16
|
private _initialized;
|
|
13
|
-
readonly
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* Resolved index configurations after init.
|
|
21
|
-
* Key: index name, Value: index config (from metadata)
|
|
22
|
-
*/
|
|
23
|
-
private registeredIndices;
|
|
24
|
-
/**
|
|
25
|
-
* Maps field name → index names that cover this field.
|
|
26
|
-
* Used for query resolution.
|
|
27
|
-
*/
|
|
28
|
-
private fieldToIndices;
|
|
29
|
-
private readonly operatorConverters;
|
|
17
|
+
readonly optimizer: Optimizer<T>;
|
|
18
|
+
readonly queryManager: QueryManager<T>;
|
|
19
|
+
readonly indexManager: IndexManager<T>;
|
|
20
|
+
readonly mutationManager: MutationManager<T>;
|
|
21
|
+
readonly metadataManager: MetadataManager<T>;
|
|
22
|
+
readonly documentFormatter: DocumentFormatter<T>;
|
|
23
|
+
readonly analysisManager: AnalysisManager<T>;
|
|
30
24
|
constructor(file: string, options: DocumentDataplyOptions);
|
|
31
25
|
/**
|
|
32
26
|
* Whether the document database has been initialized.
|
|
33
27
|
*/
|
|
34
28
|
get isDocInitialized(): boolean;
|
|
29
|
+
get indices(): {
|
|
30
|
+
[key: string]: [number, import("../types").IndexMetaConfig];
|
|
31
|
+
};
|
|
32
|
+
get trees(): Map<string, import("dataply").BPTreeAsync<string | number, import("../types").DataplyTreeValue<import("../types").Primitive>>>;
|
|
33
|
+
get indexedFields(): Set<string>;
|
|
35
34
|
/**
|
|
36
|
-
* Register an index.
|
|
37
|
-
*
|
|
35
|
+
* Register an index.
|
|
36
|
+
* @param name The name of the index
|
|
37
|
+
* @param option The option of the index
|
|
38
|
+
* @param tx The transaction to use
|
|
38
39
|
*/
|
|
39
40
|
registerIndex(name: string, option: CreateIndexOption<T>, tx?: Transaction): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Register an index at runtime (after init).
|
|
42
|
-
* Creates the tree, updates metadata, and backfills existing data.
|
|
43
|
-
*/
|
|
44
|
-
private registerIndexRuntime;
|
|
45
41
|
/**
|
|
46
42
|
* Drop (remove) a named index.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @param name The name of the index to drop
|
|
43
|
+
* @param name The name of the index
|
|
44
|
+
* @param tx The transaction to use
|
|
50
45
|
*/
|
|
51
46
|
dropIndex(name: string, tx?: Transaction): Promise<void>;
|
|
52
47
|
/**
|
|
53
|
-
*
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* Get all field names from an IndexMetaConfig.
|
|
48
|
+
* Get a document by its primary key.
|
|
49
|
+
* @param pk The primary key of the document
|
|
50
|
+
* @param tx The transaction to use
|
|
51
|
+
* @returns The document
|
|
58
52
|
*/
|
|
59
|
-
|
|
53
|
+
getDocument(pk: number, tx?: Transaction): Promise<DataplyDocument<T>>;
|
|
60
54
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* For fts: the single field.
|
|
55
|
+
* Backfill indices for newly created indices after data was inserted.
|
|
56
|
+
* Delegated to IndexManager.
|
|
64
57
|
*/
|
|
65
|
-
|
|
58
|
+
backfillIndices(tx?: Transaction): Promise<number>;
|
|
66
59
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* - fts: 별도 처리 (이 메서드 사용 안 함)
|
|
71
|
-
* @returns undefined면 해당 문서에 필수 필드가 없으므로 인덱싱 스킵
|
|
60
|
+
* Flush all interval analysis providers, forcing statistics to be recalculated.
|
|
61
|
+
* Call this after bulk inserts or periodically to keep statistics fresh.
|
|
62
|
+
* @param tx The transaction to use
|
|
72
63
|
*/
|
|
73
|
-
|
|
64
|
+
flushAnalysis(tx?: Transaction): Promise<void>;
|
|
65
|
+
createDocumentInnerMetadata(indices: DocumentDataplyInnerMetadata['indices']): DocumentDataplyInnerMetadata;
|
|
74
66
|
/**
|
|
75
|
-
*
|
|
67
|
+
* Initialize the document database file.
|
|
68
|
+
* @param tx The transaction to use
|
|
76
69
|
*/
|
|
77
|
-
|
|
78
|
-
getDocument(pk: number, tx?: Transaction): Promise<DataplyDocument<T>>;
|
|
70
|
+
initializeDocumentFile(tx: Transaction): Promise<void>;
|
|
79
71
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* @returns Number of documents that were backfilled
|
|
72
|
+
* Verify the document database file.
|
|
73
|
+
* @param tx The transaction to use
|
|
74
|
+
* @returns True if the document database file is valid, false otherwise
|
|
84
75
|
*/
|
|
85
|
-
backfillIndices(tx?: Transaction): Promise<number>;
|
|
86
|
-
createDocumentInnerMetadata(indices: DocumentDataplyInnerMetadata['indices']): DocumentDataplyInnerMetadata;
|
|
87
|
-
initializeDocumentFile(tx: Transaction): Promise<void>;
|
|
88
76
|
verifyDocumentFile(tx: Transaction): Promise<boolean>;
|
|
89
|
-
private flatten;
|
|
90
77
|
/**
|
|
91
78
|
* returns flattened document
|
|
92
79
|
* @param document
|
|
93
80
|
* @returns
|
|
94
81
|
*/
|
|
95
82
|
flattenDocument(document: T): FlattenedDocumentJSON;
|
|
83
|
+
/**
|
|
84
|
+
* Get the document metadata.
|
|
85
|
+
* @param tx The transaction to use
|
|
86
|
+
* @returns The document metadata
|
|
87
|
+
*/
|
|
96
88
|
getDocumentMetadata(tx: Transaction): Promise<DocumentDataplyMetadata>;
|
|
89
|
+
/**
|
|
90
|
+
* Get the document inner metadata.
|
|
91
|
+
* @param tx The transaction to use
|
|
92
|
+
* @returns The document inner metadata
|
|
93
|
+
*/
|
|
97
94
|
getDocumentInnerMetadata(tx: Transaction): Promise<DocumentDataplyInnerMetadata>;
|
|
95
|
+
/**
|
|
96
|
+
* Update the document inner metadata.
|
|
97
|
+
* @param metadata The document inner metadata
|
|
98
|
+
* @param tx The transaction to use
|
|
99
|
+
*/
|
|
98
100
|
updateDocumentInnerMetadata(metadata: DocumentDataplyInnerMetadata, tx: Transaction): Promise<void>;
|
|
99
101
|
/**
|
|
100
102
|
* Run a migration if the current schemeVersion is lower than the target version.
|
|
@@ -104,110 +106,6 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyA
|
|
|
104
106
|
* @param tx Optional transaction
|
|
105
107
|
*/
|
|
106
108
|
migration(version: number, callback: (tx: Transaction) => Promise<void>, tx?: Transaction): Promise<void>;
|
|
107
|
-
/**
|
|
108
|
-
* Transforms a query object into a verbose query object
|
|
109
|
-
* @param query The query object to transform
|
|
110
|
-
* @returns The verbose query object
|
|
111
|
-
*/
|
|
112
|
-
verboseQuery<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(query: Partial<DocumentDataplyQuery<U>>): Partial<DocumentDataplyQuery<V>>;
|
|
113
|
-
/**
|
|
114
|
-
* B-Tree 타입 인덱스의 선택도를 평가하고 트리에 부여할 조건을 산출합니다.
|
|
115
|
-
* 필드 매칭 여부를 검사하고, 연속된(Prefix) 조건에 대해 점수를 부여하며 Start/End 바운드를 구성합니다.
|
|
116
|
-
*
|
|
117
|
-
* @param indexName 평가할 인덱스의 이름 (예: idx_nickname_createdat)
|
|
118
|
-
* @param config 등록된 인덱스의 설정 객체
|
|
119
|
-
* @param query 쿼리 객체
|
|
120
|
-
* @param queryFields 쿼리에 포함된 필드 목록 집합
|
|
121
|
-
* @param treeTx 조회를 수행할 B-Tree 트랜잭션 객체
|
|
122
|
-
* @param orderByField 정렬에 사용할 필드명 (옵션)
|
|
123
|
-
* @returns B-Tree 인덱스 후보 정보 (조건, 점수, 커버된 필드 등), 적합하지 않으면 null
|
|
124
|
-
*/
|
|
125
|
-
private evaluateBTreeCandidate;
|
|
126
|
-
/**
|
|
127
|
-
* FTS (Full Text Search) 타입 인덱스의 선택도를 평가합니다.
|
|
128
|
-
* 'match' 연산자가 쿼리에 존재하는지 확인하고, 검색용 토큰으로 분해(tokenize)하여 점수를 매깁니다.
|
|
129
|
-
*
|
|
130
|
-
* @param indexName 평가할 인덱스의 이름
|
|
131
|
-
* @param config 등록된 인덱스의 설정 객체
|
|
132
|
-
* @param query 쿼리 객체
|
|
133
|
-
* @param queryFields 쿼리에 포함된 필드 목록 집합
|
|
134
|
-
* @param treeTx 조회를 수행할 B-Tree 트랜잭션 객체
|
|
135
|
-
* @returns FTS 인덱스 후보 정보 (조건, 점수, 분석된 토큰 등), 적합하지 않으면 null
|
|
136
|
-
*/
|
|
137
|
-
private evaluateFTSCandidate;
|
|
138
|
-
/**
|
|
139
|
-
* Choose the best index (driver) for the given query.
|
|
140
|
-
* Scores each index based on field coverage and condition type.
|
|
141
|
-
*
|
|
142
|
-
* @param query The verbose query conditions
|
|
143
|
-
* @param orderByField Optional field name for orderBy optimization
|
|
144
|
-
* @returns Driver and other candidates for query execution
|
|
145
|
-
*/
|
|
146
|
-
getSelectivityCandidate<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(query: Partial<DocumentDataplyQuery<V>>, orderByField?: string): Promise<{
|
|
147
|
-
driver: ({
|
|
148
|
-
tree: BPTreeAsync<number, V>;
|
|
149
|
-
condition: Partial<DocumentDataplyCondition<U>>;
|
|
150
|
-
field: string;
|
|
151
|
-
indexName: string;
|
|
152
|
-
isFtsMatch: false;
|
|
153
|
-
isIndexOrderSupported: boolean;
|
|
154
|
-
} | {
|
|
155
|
-
tree: BPTreeAsync<string, V>;
|
|
156
|
-
condition: Partial<DocumentDataplyCondition<U>>;
|
|
157
|
-
field: string;
|
|
158
|
-
indexName: string;
|
|
159
|
-
isFtsMatch: true;
|
|
160
|
-
matchTokens: string[];
|
|
161
|
-
isIndexOrderSupported: boolean;
|
|
162
|
-
});
|
|
163
|
-
others: ({
|
|
164
|
-
tree: BPTreeAsync<number, V>;
|
|
165
|
-
condition: Partial<DocumentDataplyCondition<U>>;
|
|
166
|
-
field: string;
|
|
167
|
-
indexName: string;
|
|
168
|
-
isFtsMatch: false;
|
|
169
|
-
isIndexOrderSupported: boolean;
|
|
170
|
-
} | {
|
|
171
|
-
tree: BPTreeAsync<string, V>;
|
|
172
|
-
condition: Partial<DocumentDataplyCondition<U>>;
|
|
173
|
-
field: string;
|
|
174
|
-
indexName: string;
|
|
175
|
-
isFtsMatch: true;
|
|
176
|
-
matchTokens: string[];
|
|
177
|
-
isIndexOrderSupported: boolean;
|
|
178
|
-
})[];
|
|
179
|
-
compositeVerifyConditions: {
|
|
180
|
-
field: string;
|
|
181
|
-
condition: any;
|
|
182
|
-
}[];
|
|
183
|
-
rollback: () => void;
|
|
184
|
-
} | null>;
|
|
185
|
-
/**
|
|
186
|
-
* Get Free Memory Chunk Size
|
|
187
|
-
* @returns { verySmallChunkSize, smallChunkSize }
|
|
188
|
-
*/
|
|
189
|
-
getFreeMemoryChunkSize(): {
|
|
190
|
-
verySmallChunkSize: number;
|
|
191
|
-
smallChunkSize: number;
|
|
192
|
-
};
|
|
193
|
-
private getTokenKey;
|
|
194
|
-
private applyCandidateByFTSStream;
|
|
195
|
-
/**
|
|
196
|
-
* 특정 인덱스 후보를 조회하여 PK 집합을 필터링합니다.
|
|
197
|
-
*/
|
|
198
|
-
private applyCandidateStream;
|
|
199
|
-
/**
|
|
200
|
-
* 쿼리와 인덱스 선택을 기반으로 기본 키(Primary Keys)를 가져옵니다.
|
|
201
|
-
* 쿼리 최적화를 통합하기 위한 내부 공통 메서드입니다.
|
|
202
|
-
*/
|
|
203
|
-
getKeys(query: Partial<DocumentDataplyQuery<T>>, orderBy?: string, sortOrder?: 'asc' | 'desc'): Promise<Float64Array>;
|
|
204
|
-
/**
|
|
205
|
-
* 드라이버 인덱스만으로 PK 스트림을 가져옵니다. (교집합 없이)
|
|
206
|
-
* selectDocuments에서 사용하며, 나머지 조건(others)은 스트리밍 중 tree.verify()로 검증합니다.
|
|
207
|
-
* @returns 드라이버 키 스트림, others 후보 목록, rollback 함수. 또는 null.
|
|
208
|
-
*/
|
|
209
|
-
private getDriverKeys;
|
|
210
|
-
private insertDocumentInternal;
|
|
211
109
|
/**
|
|
212
110
|
* Insert a document into the database
|
|
213
111
|
* @param document The document to insert
|
|
@@ -222,14 +120,6 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyA
|
|
|
222
120
|
* @returns The primary keys of the inserted documents
|
|
223
121
|
*/
|
|
224
122
|
insertBatchDocuments(documents: T[], tx?: Transaction): Promise<number[]>;
|
|
225
|
-
/**
|
|
226
|
-
* Internal update method used by both fullUpdate and partialUpdate
|
|
227
|
-
* @param query The query to use
|
|
228
|
-
* @param computeUpdatedDoc Function that computes the updated document from the original
|
|
229
|
-
* @param tx The transaction to use
|
|
230
|
-
* @returns The number of updated documents
|
|
231
|
-
*/
|
|
232
|
-
private updateInternal;
|
|
233
123
|
/**
|
|
234
124
|
* Fully update documents from the database that match the query
|
|
235
125
|
* @param query The query to use
|
|
@@ -260,27 +150,6 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyA
|
|
|
260
150
|
* @returns The number of documents that match the query
|
|
261
151
|
*/
|
|
262
152
|
countDocuments(query: Partial<DocumentDataplyQuery<T>>, tx?: Transaction): Promise<number>;
|
|
263
|
-
/**
|
|
264
|
-
* FTS 조건에 대해 문서가 유효한지 검증합니다.
|
|
265
|
-
*/
|
|
266
|
-
private verifyFts;
|
|
267
|
-
/**
|
|
268
|
-
* 복합 인덱스의 non-primary 필드에 대해 문서가 유효한지 검증합니다.
|
|
269
|
-
*/
|
|
270
|
-
private verifyCompositeConditions;
|
|
271
|
-
/**
|
|
272
|
-
* 단일 값에 대해 verbose 조건을 검증합니다.
|
|
273
|
-
*/
|
|
274
|
-
private verifyValue;
|
|
275
|
-
/**
|
|
276
|
-
* 메모리 기반으로 청크 크기를 동적 조절합니다.
|
|
277
|
-
*/
|
|
278
|
-
private adjustChunkSize;
|
|
279
|
-
/**
|
|
280
|
-
* Prefetch 방식으로 키 스트림을 청크 단위로 조회하여 문서를 순회합니다.
|
|
281
|
-
* FTS 검증, 복합 인덱스 검증, others 후보에 대한 tree.verify() 검증을 통과한 문서만 yield 합니다.
|
|
282
|
-
*/
|
|
283
|
-
private processChunkedKeysWithVerify;
|
|
284
153
|
/**
|
|
285
154
|
* Select documents from the database
|
|
286
155
|
* @param query The query to use
|
|
@@ -39,6 +39,14 @@ export interface DocumentDataplyInnerMetadata {
|
|
|
39
39
|
IndexMetaConfig
|
|
40
40
|
];
|
|
41
41
|
};
|
|
42
|
+
analysis?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Analysis header row structure.
|
|
46
|
+
* Maps analysis type names to their overflow row PKs.
|
|
47
|
+
*/
|
|
48
|
+
export interface AnalysisHeader {
|
|
49
|
+
[type: string]: number;
|
|
42
50
|
}
|
|
43
51
|
export interface DocumentDataplyMetadata {
|
|
44
52
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-dataply",
|
|
3
|
-
"version": "0.0.10-alpha.
|
|
3
|
+
"version": "0.0.10-alpha.5",
|
|
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>",
|
|
@@ -51,4 +51,4 @@
|
|
|
51
51
|
"ts-jest": "^29.4.6",
|
|
52
52
|
"typescript": "^5.9.3"
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
}
|