document-dataply 0.0.8 → 0.0.9-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 +627 -232
- package/dist/types/core/bptree/documentStrategy.d.ts +3 -3
- package/dist/types/core/document.d.ts +44 -18
- package/dist/types/core/documentAPI.d.ts +110 -23
- package/dist/types/types/index.d.ts +46 -37
- package/package.json +2 -2
- package/readme.md +69 -20
|
@@ -2,10 +2,10 @@ import type { DataplyTreeValue, Primitive } from '../../types';
|
|
|
2
2
|
import { BPTreeNode, SerializeStrategyAsync, type SerializeStrategyHead } from 'dataply';
|
|
3
3
|
import { DocumentDataplyAPI } from '../documentAPI';
|
|
4
4
|
export declare class DocumentSerializeStrategyAsync<T extends Primitive> extends SerializeStrategyAsync<number, DataplyTreeValue<T>> {
|
|
5
|
-
protected readonly api: DocumentDataplyAPI<any
|
|
6
|
-
protected readonly txContext: DocumentDataplyAPI<any
|
|
5
|
+
protected readonly api: DocumentDataplyAPI<any>;
|
|
6
|
+
protected readonly txContext: DocumentDataplyAPI<any>['txContext'];
|
|
7
7
|
readonly treeKey: string;
|
|
8
|
-
constructor(order: number, api: DocumentDataplyAPI<any
|
|
8
|
+
constructor(order: number, api: DocumentDataplyAPI<any>, txContext: DocumentDataplyAPI<any>['txContext'], treeKey: string);
|
|
9
9
|
id(isLeaf: boolean): Promise<string>;
|
|
10
10
|
read(id: string): Promise<BPTreeNode<number, DataplyTreeValue<T>>>;
|
|
11
11
|
write(id: string, node: BPTreeNode<number, DataplyTreeValue<T>>): Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { DocumentDataplyOptions, DocumentJSON,
|
|
1
|
+
import type { DocumentDataplyOptions, DocumentJSON, DocumentDataplyQuery, DataplyDocument, DocumentDataplyMetadata, DocumentDataplyQueryOptions, CreateIndexOption } from '../types';
|
|
2
2
|
import { Transaction } from 'dataply';
|
|
3
3
|
import { DocumentDataplyAPI } from './documentAPI';
|
|
4
|
-
export declare class DocumentDataply<T extends DocumentJSON
|
|
4
|
+
export declare class DocumentDataply<T extends DocumentJSON> {
|
|
5
5
|
/**
|
|
6
6
|
* Starts the database definition by setting the document type.
|
|
7
7
|
* This is used to ensure TypeScript type inference works correctly for the document structure.
|
|
@@ -9,16 +9,15 @@ export declare class DocumentDataply<T extends DocumentJSON, IC extends IndexCon
|
|
|
9
9
|
*/
|
|
10
10
|
static Define<T extends DocumentJSON>(): {
|
|
11
11
|
/**
|
|
12
|
-
* Sets the options for the database, such as
|
|
13
|
-
* @template IC The configuration of indices.
|
|
12
|
+
* Sets the options for the database, such as WAL settings.
|
|
14
13
|
* @param options The database initialization options.
|
|
15
14
|
*/
|
|
16
|
-
Options:
|
|
15
|
+
Options: (options: DocumentDataplyOptions) => {
|
|
17
16
|
/**
|
|
18
17
|
* Creates or opens the database instance with the specified file path.
|
|
19
18
|
* @param file The path to the database file.
|
|
20
19
|
*/
|
|
21
|
-
Open: (file: string) => DocumentDataply<T
|
|
20
|
+
Open: (file: string) => DocumentDataply<T>;
|
|
22
21
|
};
|
|
23
22
|
};
|
|
24
23
|
/**
|
|
@@ -29,12 +28,39 @@ export declare class DocumentDataply<T extends DocumentJSON, IC extends IndexCon
|
|
|
29
28
|
* Internal method used to finalize construction and create the instance.
|
|
30
29
|
*/
|
|
31
30
|
private static Open;
|
|
32
|
-
protected readonly api: DocumentDataplyAPI<T
|
|
33
|
-
protected constructor(file: string, options?: DocumentDataplyOptions
|
|
31
|
+
protected readonly api: DocumentDataplyAPI<T>;
|
|
32
|
+
protected constructor(file: string, options?: DocumentDataplyOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Create a named index on the database.
|
|
35
|
+
* Can be called before or after init().
|
|
36
|
+
* If called after init(), the index is immediately created and backfilled.
|
|
37
|
+
* @param name The name of the index
|
|
38
|
+
* @param option The index configuration (btree or fts)
|
|
39
|
+
* @param tx Optional transaction
|
|
40
|
+
* @returns Promise<this> for chaining
|
|
41
|
+
*/
|
|
42
|
+
createIndex(name: string, option: CreateIndexOption<T>, tx?: Transaction): Promise<this>;
|
|
43
|
+
/**
|
|
44
|
+
* Drop (remove) a named index from the database.
|
|
45
|
+
* The '_id' index cannot be dropped.
|
|
46
|
+
* @param name The name of the index to drop
|
|
47
|
+
* @param tx Optional transaction
|
|
48
|
+
* @returns Promise<this> for chaining
|
|
49
|
+
*/
|
|
50
|
+
dropIndex(name: string, tx?: Transaction): Promise<this>;
|
|
34
51
|
/**
|
|
35
52
|
* Initialize the document database
|
|
36
53
|
*/
|
|
37
54
|
init(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Run a migration if the current schemeVersion is lower than the target version.
|
|
57
|
+
* The callback is only executed when the database's schemeVersion is below the given version.
|
|
58
|
+
* After the callback completes, schemeVersion is updated to the target version.
|
|
59
|
+
* @param version The target scheme version
|
|
60
|
+
* @param callback The migration callback receiving a transaction
|
|
61
|
+
* @param tx Optional transaction
|
|
62
|
+
*/
|
|
63
|
+
migration(version: number, callback: (tx: Transaction) => Promise<void>, tx?: Transaction): Promise<void>;
|
|
38
64
|
/**
|
|
39
65
|
* Get the metadata of the document database
|
|
40
66
|
*/
|
|
@@ -59,43 +85,43 @@ export declare class DocumentDataply<T extends DocumentJSON, IC extends IndexCon
|
|
|
59
85
|
insertBatch(documents: T[], tx?: Transaction): Promise<number[]>;
|
|
60
86
|
/**
|
|
61
87
|
* Fully update documents from the database that match the query
|
|
62
|
-
* @param query The query to use
|
|
88
|
+
* @param query The query to use
|
|
63
89
|
* @param newRecord Complete document to replace with, or function that receives current document and returns new document
|
|
64
90
|
* @param tx The transaction to use
|
|
65
91
|
* @returns The number of updated documents
|
|
66
92
|
*/
|
|
67
|
-
fullUpdate(query: Partial<
|
|
93
|
+
fullUpdate(query: Partial<DocumentDataplyQuery<T>>, newRecord: T | ((document: DataplyDocument<T>) => T), tx?: Transaction): Promise<number>;
|
|
68
94
|
/**
|
|
69
95
|
* Partially update documents from the database that match the query
|
|
70
|
-
* @param query The query to use
|
|
96
|
+
* @param query The query to use
|
|
71
97
|
* @param newRecord Partial document to merge, or function that receives current document and returns partial update
|
|
72
98
|
* @param tx The transaction to use
|
|
73
99
|
* @returns The number of updated documents
|
|
74
100
|
*/
|
|
75
|
-
partialUpdate(query: Partial<
|
|
101
|
+
partialUpdate(query: Partial<DocumentDataplyQuery<T>>, newRecord: Partial<DataplyDocument<T>> | ((document: DataplyDocument<T>) => Partial<DataplyDocument<T>>), tx?: Transaction): Promise<number>;
|
|
76
102
|
/**
|
|
77
103
|
* Delete documents from the database that match the query
|
|
78
|
-
* @param query The query to use
|
|
104
|
+
* @param query The query to use
|
|
79
105
|
* @param tx The transaction to use
|
|
80
106
|
* @returns The number of deleted documents
|
|
81
107
|
*/
|
|
82
|
-
delete(query: Partial<
|
|
108
|
+
delete(query: Partial<DocumentDataplyQuery<T>>, tx?: Transaction): Promise<number>;
|
|
83
109
|
/**
|
|
84
110
|
* Count documents from the database that match the query
|
|
85
|
-
* @param query The query to use
|
|
111
|
+
* @param query The query to use
|
|
86
112
|
* @param tx The transaction to use
|
|
87
113
|
* @returns The number of documents that match the query
|
|
88
114
|
*/
|
|
89
|
-
count(query: Partial<
|
|
115
|
+
count(query: Partial<DocumentDataplyQuery<T>>, tx?: Transaction): Promise<number>;
|
|
90
116
|
/**
|
|
91
117
|
* Select documents from the database
|
|
92
|
-
* @param query The query to use
|
|
118
|
+
* @param query The query to use
|
|
93
119
|
* @param options The options to use
|
|
94
120
|
* @param tx The transaction to use
|
|
95
121
|
* @returns The documents that match the query
|
|
96
122
|
* @throws Error if query or orderBy contains non-indexed fields
|
|
97
123
|
*/
|
|
98
|
-
select(query: Partial<
|
|
124
|
+
select(query: Partial<DocumentDataplyQuery<T>>, options?: DocumentDataplyQueryOptions, tx?: Transaction): {
|
|
99
125
|
stream: AsyncIterableIterator<DataplyDocument<T>>;
|
|
100
126
|
drain: () => Promise<DataplyDocument<T>[]>;
|
|
101
127
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { DataplyTreeValue, DocumentDataplyInnerMetadata, DocumentDataplyOptions, DocumentJSON, FlattenedDocumentJSON, Primitive, DataplyDocument, DocumentDataplyMetadata,
|
|
1
|
+
import type { DataplyTreeValue, DocumentDataplyInnerMetadata, DocumentDataplyOptions, DocumentJSON, FlattenedDocumentJSON, Primitive, DataplyDocument, DocumentDataplyMetadata, DocumentDataplyQuery, DocumentDataplyCondition, DocumentDataplyQueryOptions, CreateIndexOption } from '../types';
|
|
2
2
|
import { DataplyAPI, Transaction, BPTreeAsync } from 'dataply';
|
|
3
3
|
import { DocumentValueComparator } from './bptree/documentComparator';
|
|
4
|
-
export declare class DocumentDataplyAPI<T extends DocumentJSON
|
|
4
|
+
export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyAPI {
|
|
5
5
|
runWithDefault: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
|
|
6
6
|
streamWithDefault: <T_1>(callback: (tx: Transaction) => AsyncGenerator<T_1>, tx?: Transaction) => AsyncGenerator<T_1>;
|
|
7
7
|
indices: DocumentDataplyInnerMetadata['indices'];
|
|
@@ -9,16 +9,78 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON, IC extends Index
|
|
|
9
9
|
readonly comparator: DocumentValueComparator<DataplyTreeValue<Primitive>, Primitive>;
|
|
10
10
|
private pendingBackfillFields;
|
|
11
11
|
private readonly lock;
|
|
12
|
+
private _initialized;
|
|
12
13
|
readonly indexedFields: Set<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Registered indices via createIndex() (before init)
|
|
16
|
+
* Key: index name, Value: index configuration
|
|
17
|
+
*/
|
|
18
|
+
private readonly pendingCreateIndices;
|
|
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;
|
|
13
29
|
private readonly operatorConverters;
|
|
14
|
-
constructor(file: string, options: DocumentDataplyOptions
|
|
30
|
+
constructor(file: string, options: DocumentDataplyOptions);
|
|
31
|
+
/**
|
|
32
|
+
* Whether the document database has been initialized.
|
|
33
|
+
*/
|
|
34
|
+
get isDocInitialized(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Register an index. If called before init(), queues it for processing during init.
|
|
37
|
+
* If called after init(), immediately creates the tree, updates metadata, and backfills.
|
|
38
|
+
*/
|
|
39
|
+
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
|
+
/**
|
|
46
|
+
* Drop (remove) a named index.
|
|
47
|
+
* Removes the index from metadata, in-memory maps, and trees.
|
|
48
|
+
* The '_id' index cannot be dropped.
|
|
49
|
+
* @param name The name of the index to drop
|
|
50
|
+
*/
|
|
51
|
+
dropIndex(name: string, tx?: Transaction): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Convert CreateIndexOption to IndexMetaConfig for metadata storage.
|
|
54
|
+
*/
|
|
55
|
+
private toIndexMetaConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Get all field names from an IndexMetaConfig.
|
|
58
|
+
*/
|
|
59
|
+
private getFieldsFromConfig;
|
|
60
|
+
/**
|
|
61
|
+
* Get the primary field of an index (the field used as tree key).
|
|
62
|
+
* For btree: first field in fields array.
|
|
63
|
+
* For fts: the single field.
|
|
64
|
+
*/
|
|
65
|
+
private getPrimaryField;
|
|
66
|
+
/**
|
|
67
|
+
* 인덱스 config에 따라 B+tree에 저장할 v 값을 생성합니다.
|
|
68
|
+
* - 단일 필드 btree: Primitive (단일 값)
|
|
69
|
+
* - 복합 필드 btree: Primitive[] (필드 순서대로 배열)
|
|
70
|
+
* - fts: 별도 처리 (이 메서드 사용 안 함)
|
|
71
|
+
* @returns undefined면 해당 문서에 필수 필드가 없으므로 인덱싱 스킵
|
|
72
|
+
*/
|
|
73
|
+
private getIndexValue;
|
|
74
|
+
/**
|
|
75
|
+
* Get FTSConfig from IndexMetaConfig (for tokenizer compatibility).
|
|
76
|
+
*/
|
|
77
|
+
private getFtsConfig;
|
|
15
78
|
getDocument(pk: number, tx?: Transaction): Promise<DataplyDocument<T>>;
|
|
16
79
|
readLock<T>(fn: () => T): Promise<T>;
|
|
17
80
|
writeLock<T>(fn: () => T): Promise<T>;
|
|
18
81
|
/**
|
|
19
|
-
* Backfill indices for
|
|
20
|
-
* This method should be called after `init()
|
|
21
|
-
* for newly added index fields.
|
|
82
|
+
* Backfill indices for newly created indices after data was inserted.
|
|
83
|
+
* This method should be called after `init()`.
|
|
22
84
|
*
|
|
23
85
|
* @returns Number of documents that were backfilled
|
|
24
86
|
*/
|
|
@@ -36,28 +98,40 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON, IC extends Index
|
|
|
36
98
|
getDocumentMetadata(tx: Transaction): Promise<DocumentDataplyMetadata>;
|
|
37
99
|
getDocumentInnerMetadata(tx: Transaction): Promise<DocumentDataplyInnerMetadata>;
|
|
38
100
|
updateDocumentInnerMetadata(metadata: DocumentDataplyInnerMetadata, tx: Transaction): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Run a migration if the current schemeVersion is lower than the target version.
|
|
103
|
+
* After the callback completes, schemeVersion is updated to the target version.
|
|
104
|
+
* @param version The target scheme version
|
|
105
|
+
* @param callback The migration callback
|
|
106
|
+
* @param tx Optional transaction
|
|
107
|
+
*/
|
|
108
|
+
migration(version: number, callback: (tx: Transaction) => Promise<void>, tx?: Transaction): Promise<void>;
|
|
39
109
|
/**
|
|
40
110
|
* Transforms a query object into a verbose query object
|
|
41
111
|
* @param query The query object to transform
|
|
42
112
|
* @returns The verbose query object
|
|
43
113
|
*/
|
|
44
|
-
verboseQuery<U extends Partial<
|
|
114
|
+
verboseQuery<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(query: Partial<DocumentDataplyQuery<U>>): Partial<DocumentDataplyQuery<V>>;
|
|
45
115
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
116
|
+
* Choose the best index (driver) for the given query.
|
|
117
|
+
* Scores each index based on field coverage and condition type.
|
|
118
|
+
*
|
|
119
|
+
* @param query The verbose query conditions
|
|
48
120
|
* @param orderByField Optional field name for orderBy optimization
|
|
49
121
|
* @returns Driver and other candidates for query execution
|
|
50
122
|
*/
|
|
51
|
-
getSelectivityCandidate<U extends Partial<
|
|
123
|
+
getSelectivityCandidate<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(query: Partial<DocumentDataplyQuery<V>>, orderByField?: string): Promise<{
|
|
52
124
|
driver: ({
|
|
53
125
|
tree: BPTreeAsync<number, V>;
|
|
54
126
|
condition: Partial<DocumentDataplyCondition<U>>;
|
|
55
127
|
field: string;
|
|
128
|
+
indexName: string;
|
|
56
129
|
isFtsMatch: false;
|
|
57
130
|
} | {
|
|
58
131
|
tree: BPTreeAsync<string, V>;
|
|
59
132
|
condition: Partial<DocumentDataplyCondition<U>>;
|
|
60
133
|
field: string;
|
|
134
|
+
indexName: string;
|
|
61
135
|
isFtsMatch: true;
|
|
62
136
|
matchTokens: string[];
|
|
63
137
|
});
|
|
@@ -65,14 +139,20 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON, IC extends Index
|
|
|
65
139
|
tree: BPTreeAsync<number, V>;
|
|
66
140
|
condition: Partial<DocumentDataplyCondition<U>>;
|
|
67
141
|
field: string;
|
|
142
|
+
indexName: string;
|
|
68
143
|
isFtsMatch: false;
|
|
69
144
|
} | {
|
|
70
145
|
tree: BPTreeAsync<string, V>;
|
|
71
146
|
condition: Partial<DocumentDataplyCondition<U>>;
|
|
72
147
|
field: string;
|
|
148
|
+
indexName: string;
|
|
73
149
|
isFtsMatch: true;
|
|
74
150
|
matchTokens: string[];
|
|
75
151
|
})[];
|
|
152
|
+
compositeVerifyConditions: {
|
|
153
|
+
field: string;
|
|
154
|
+
condition: any;
|
|
155
|
+
}[];
|
|
76
156
|
rollback: () => void;
|
|
77
157
|
} | null>;
|
|
78
158
|
/**
|
|
@@ -93,7 +173,7 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON, IC extends Index
|
|
|
93
173
|
* 쿼리와 인덱스 선택을 기반으로 기본 키(Primary Keys)를 가져옵니다.
|
|
94
174
|
* 쿼리 최적화를 통합하기 위한 내부 공통 메서드입니다.
|
|
95
175
|
*/
|
|
96
|
-
getKeys(query: Partial<
|
|
176
|
+
getKeys(query: Partial<DocumentDataplyQuery<T>>, orderBy?: string, sortOrder?: 'asc' | 'desc'): Promise<Float64Array>;
|
|
97
177
|
/**
|
|
98
178
|
* 드라이버 인덱스만으로 PK를 가져옵니다. (교집합 없이)
|
|
99
179
|
* selectDocuments에서 사용하며, 나머지 조건(others)은 스트리밍 중 tree.verify()로 검증합니다.
|
|
@@ -125,57 +205,64 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON, IC extends Index
|
|
|
125
205
|
private updateInternal;
|
|
126
206
|
/**
|
|
127
207
|
* Fully update documents from the database that match the query
|
|
128
|
-
* @param query The query to use
|
|
208
|
+
* @param query The query to use
|
|
129
209
|
* @param newRecord Complete document to replace with, or function that receives current document and returns new document
|
|
130
210
|
* @param tx The transaction to use
|
|
131
211
|
* @returns The number of updated documents
|
|
132
212
|
*/
|
|
133
|
-
fullUpdate(query: Partial<
|
|
213
|
+
fullUpdate(query: Partial<DocumentDataplyQuery<T>>, newRecord: T | ((document: DataplyDocument<T>) => T), tx?: Transaction): Promise<number>;
|
|
134
214
|
/**
|
|
135
215
|
* Partially update documents from the database that match the query
|
|
136
|
-
* @param query The query to use
|
|
216
|
+
* @param query The query to use
|
|
137
217
|
* @param newRecord Partial document to merge, or function that receives current document and returns partial update
|
|
138
218
|
* @param tx The transaction to use
|
|
139
219
|
* @returns The number of updated documents
|
|
140
220
|
*/
|
|
141
|
-
partialUpdate(query: Partial<
|
|
221
|
+
partialUpdate(query: Partial<DocumentDataplyQuery<T>>, newRecord: Partial<DataplyDocument<T>> | ((document: DataplyDocument<T>) => Partial<DataplyDocument<T>>), tx?: Transaction): Promise<number>;
|
|
142
222
|
/**
|
|
143
223
|
* Delete documents from the database that match the query
|
|
144
|
-
* @param query The query to use
|
|
224
|
+
* @param query The query to use
|
|
145
225
|
* @param tx The transaction to use
|
|
146
226
|
* @returns The number of deleted documents
|
|
147
227
|
*/
|
|
148
|
-
deleteDocuments(query: Partial<
|
|
228
|
+
deleteDocuments(query: Partial<DocumentDataplyQuery<T>>, tx?: Transaction): Promise<number>;
|
|
149
229
|
/**
|
|
150
230
|
* Count documents from the database that match the query
|
|
151
|
-
* @param query The query to use
|
|
231
|
+
* @param query The query to use
|
|
152
232
|
* @param tx The transaction to use
|
|
153
233
|
* @returns The number of documents that match the query
|
|
154
234
|
*/
|
|
155
|
-
countDocuments(query: Partial<
|
|
235
|
+
countDocuments(query: Partial<DocumentDataplyQuery<T>>, tx?: Transaction): Promise<number>;
|
|
156
236
|
/**
|
|
157
237
|
* FTS 조건에 대해 문서가 유효한지 검증합니다.
|
|
158
238
|
*/
|
|
159
239
|
private verifyFts;
|
|
240
|
+
/**
|
|
241
|
+
* 복합 인덱스의 non-primary 필드에 대해 문서가 유효한지 검증합니다.
|
|
242
|
+
*/
|
|
243
|
+
private verifyCompositeConditions;
|
|
244
|
+
/**
|
|
245
|
+
* 단일 값에 대해 verbose 조건을 검증합니다.
|
|
246
|
+
*/
|
|
247
|
+
private verifyValue;
|
|
160
248
|
/**
|
|
161
249
|
* 메모리 기반으로 청크 크기를 동적 조절합니다.
|
|
162
250
|
*/
|
|
163
251
|
private adjustChunkSize;
|
|
164
252
|
/**
|
|
165
253
|
* Prefetch 방식으로 키 배열을 청크 단위로 조회하여 문서를 순회합니다.
|
|
166
|
-
* FTS
|
|
167
|
-
* 교집합 대신 스트리밍 중 검증하여 첫 결과 반환 시간을 단축합니다.
|
|
254
|
+
* FTS 검증, 복합 인덱스 검증, others 후보에 대한 tree.verify() 검증을 통과한 문서만 yield 합니다.
|
|
168
255
|
*/
|
|
169
256
|
private processChunkedKeysWithVerify;
|
|
170
257
|
/**
|
|
171
258
|
* Select documents from the database
|
|
172
|
-
* @param query The query to use
|
|
259
|
+
* @param query The query to use
|
|
173
260
|
* @param options The options to use
|
|
174
261
|
* @param tx The transaction to use
|
|
175
262
|
* @returns The documents that match the query
|
|
176
263
|
* @throws Error if query or orderBy contains non-indexed fields
|
|
177
264
|
*/
|
|
178
|
-
selectDocuments(query: Partial<
|
|
265
|
+
selectDocuments(query: Partial<DocumentDataplyQuery<T>>, options?: DocumentDataplyQueryOptions, tx?: Transaction): {
|
|
179
266
|
stream: AsyncIterableIterator<DataplyDocument<T>>;
|
|
180
267
|
drain: () => Promise<DataplyDocument<T>[]>;
|
|
181
268
|
};
|
|
@@ -9,23 +9,34 @@ export type DocumentJSON = {
|
|
|
9
9
|
export type FlattenedDocumentJSON = {
|
|
10
10
|
[key: string]: Primitive;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Index metadata config stored in DB metadata.
|
|
14
|
+
* Used internally to persist index configuration.
|
|
15
|
+
*/
|
|
16
|
+
export type IndexMetaConfig = {
|
|
17
|
+
type: 'btree';
|
|
18
|
+
fields: string[];
|
|
19
|
+
} | {
|
|
20
|
+
type: 'fts';
|
|
21
|
+
fields: string;
|
|
22
|
+
tokenizer: 'whitespace';
|
|
23
|
+
} | {
|
|
24
|
+
type: 'fts';
|
|
25
|
+
fields: string;
|
|
26
|
+
tokenizer: 'ngram';
|
|
27
|
+
gramSize: number;
|
|
28
|
+
};
|
|
12
29
|
export interface DocumentDataplyInnerMetadata {
|
|
13
30
|
magicString: string;
|
|
14
31
|
version: number;
|
|
15
32
|
createdAt: number;
|
|
16
33
|
updatedAt: number;
|
|
17
34
|
lastId: number;
|
|
35
|
+
schemeVersion: number;
|
|
18
36
|
indices: {
|
|
19
37
|
[key: string]: [
|
|
20
38
|
number,
|
|
21
|
-
|
|
22
|
-
type: 'fts';
|
|
23
|
-
tokenizer: 'whitespace';
|
|
24
|
-
} | {
|
|
25
|
-
type: 'fts';
|
|
26
|
-
tokenizer: 'ngram';
|
|
27
|
-
gramSize: number;
|
|
28
|
-
}
|
|
39
|
+
IndexMetaConfig
|
|
29
40
|
];
|
|
30
41
|
};
|
|
31
42
|
}
|
|
@@ -42,6 +53,14 @@ export interface DocumentDataplyMetadata {
|
|
|
42
53
|
* The total number of data rows in the dataply.
|
|
43
54
|
*/
|
|
44
55
|
rowCount: number;
|
|
56
|
+
/**
|
|
57
|
+
* The list of user-created index names (excludes internal '_id' index).
|
|
58
|
+
*/
|
|
59
|
+
indices: string[];
|
|
60
|
+
/**
|
|
61
|
+
* The current scheme version of the database.
|
|
62
|
+
*/
|
|
63
|
+
schemeVersion: number;
|
|
45
64
|
}
|
|
46
65
|
export type DataplyDocumentBase = {
|
|
47
66
|
_id: number;
|
|
@@ -63,14 +82,6 @@ export type DocumentDataplyQuery<T> = {
|
|
|
63
82
|
} & {
|
|
64
83
|
[key: string]: any;
|
|
65
84
|
};
|
|
66
|
-
/**
|
|
67
|
-
* Query type restricted to indexed fields only
|
|
68
|
-
*/
|
|
69
|
-
export type DocumentDataplyIndexedQuery<T extends DocumentJSON, IC extends IndexConfig<T>> = {
|
|
70
|
-
[key in keyof IC]: key extends keyof FinalFlatten<DataplyDocument<T>> ? FinalFlatten<DataplyDocument<T>>[key] | DocumentDataplyCondition<FinalFlatten<DataplyDocument<T>>[key]> : never;
|
|
71
|
-
} & DocumentDataplyQuery<{
|
|
72
|
-
_id: number;
|
|
73
|
-
}>;
|
|
74
85
|
export interface DataplyTreeValue<T> {
|
|
75
86
|
k: number;
|
|
76
87
|
v: T;
|
|
@@ -78,7 +89,7 @@ export interface DataplyTreeValue<T> {
|
|
|
78
89
|
/**
|
|
79
90
|
* Options for querying documents.
|
|
80
91
|
*/
|
|
81
|
-
export type DocumentDataplyQueryOptions
|
|
92
|
+
export type DocumentDataplyQueryOptions = {
|
|
82
93
|
/**
|
|
83
94
|
* The maximum number of documents to return.
|
|
84
95
|
*/
|
|
@@ -90,7 +101,7 @@ export type DocumentDataplyQueryOptions<T extends DocumentJSON, IC extends Index
|
|
|
90
101
|
/**
|
|
91
102
|
* The field to order the results by.
|
|
92
103
|
*/
|
|
93
|
-
orderBy?:
|
|
104
|
+
orderBy?: string;
|
|
94
105
|
/**
|
|
95
106
|
* The order to sort the results by.
|
|
96
107
|
*/
|
|
@@ -117,12 +128,6 @@ type GetTypeByPath<T, Path extends string> = T extends readonly (infer U)[] ? Pa
|
|
|
117
128
|
export type FinalFlatten<T> = {
|
|
118
129
|
[P in DeepFlattenKeys<T>]: GetTypeByPath<T, P & string>;
|
|
119
130
|
};
|
|
120
|
-
export type DocumentDataplyIndices<T extends DocumentJSON, IC extends IndexConfig<T>> = {
|
|
121
|
-
[key in keyof IC & keyof FinalFlatten<T>]: GetTypeByPath<T, key>;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Index configuration type
|
|
125
|
-
*/
|
|
126
131
|
export type FTSConfig = {
|
|
127
132
|
type: 'fts';
|
|
128
133
|
tokenizer: 'whitespace';
|
|
@@ -131,20 +136,24 @@ export type FTSConfig = {
|
|
|
131
136
|
tokenizer: 'ngram';
|
|
132
137
|
gramSize: number;
|
|
133
138
|
};
|
|
134
|
-
export type IndexConfig<T> = Partial<{
|
|
135
|
-
[key in keyof FinalFlatten<T>]: boolean | FTSConfig;
|
|
136
|
-
}>;
|
|
137
139
|
/**
|
|
138
|
-
*
|
|
140
|
+
* createIndex option types
|
|
139
141
|
*/
|
|
140
|
-
export type
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
export type CreateIndexBTreeOption<T extends DocumentJSON> = {
|
|
143
|
+
type: 'btree';
|
|
144
|
+
fields: (DeepFlattenKeys<DataplyDocument<T>> & string)[];
|
|
145
|
+
};
|
|
146
|
+
export type CreateIndexFTSOption<T extends DocumentJSON> = {
|
|
147
|
+
type: 'fts';
|
|
148
|
+
fields: DeepFlattenKeys<DataplyDocument<T>> & string;
|
|
149
|
+
tokenizer: 'whitespace';
|
|
150
|
+
} | {
|
|
151
|
+
type: 'fts';
|
|
152
|
+
fields: DeepFlattenKeys<DataplyDocument<T>> & string;
|
|
153
|
+
tokenizer: 'ngram';
|
|
154
|
+
ngram: number;
|
|
155
|
+
};
|
|
156
|
+
export type CreateIndexOption<T extends DocumentJSON> = CreateIndexBTreeOption<T> | CreateIndexFTSOption<T>;
|
|
157
|
+
export interface DocumentDataplyOptions extends DataplyOptions {
|
|
149
158
|
}
|
|
150
159
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-dataply",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9-alpha.1",
|
|
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>",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dataply"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"dataply": "^0.0.
|
|
45
|
+
"dataply": "^0.0.24-alpha.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/jest": "^30.0.0",
|