document-dataply 0.0.10-alpha.2 → 0.0.10-alpha.4
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 +1354 -1248
- package/dist/types/core/DocumentFormatter.d.ts +10 -0
- package/dist/types/core/IndexManager.d.ts +68 -0
- package/dist/types/core/MetadataManager.d.ts +18 -0
- package/dist/types/core/MutationManager.d.ts +53 -0
- package/dist/types/core/Optimizer.d.ts +78 -0
- package/dist/types/core/QueryManager.d.ts +73 -0
- package/dist/types/core/documentAPI.d.ts +21 -198
- package/dist/types/types/index.d.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DocumentJSON, FlattenedDocumentJSON } from '../types';
|
|
2
|
+
export declare class DocumentFormatter<T extends DocumentJSON> {
|
|
3
|
+
private flattenInternal;
|
|
4
|
+
/**
|
|
5
|
+
* returns flattened document
|
|
6
|
+
* @param document
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
flattenDocument(document: T): FlattenedDocumentJSON;
|
|
10
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { DataplyTreeValue, DocumentDataplyInnerMetadata, Primitive, CreateIndexOption, IndexMetaConfig, FTSConfig, DocumentJSON, FlattenedDocumentJSON } from '../types';
|
|
2
|
+
import type { DocumentDataplyAPI } from './documentAPI';
|
|
3
|
+
import { BPTreeAsync, Transaction } from 'dataply';
|
|
4
|
+
export declare class IndexManager<T extends DocumentJSON> {
|
|
5
|
+
private api;
|
|
6
|
+
indices: DocumentDataplyInnerMetadata['indices'];
|
|
7
|
+
readonly trees: Map<string, BPTreeAsync<string | number, DataplyTreeValue<Primitive>>>;
|
|
8
|
+
readonly indexedFields: Set<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Registered indices via createIndex() (before init)
|
|
11
|
+
* Key: index name, Value: index configuration
|
|
12
|
+
*/
|
|
13
|
+
readonly pendingCreateIndices: Map<string, CreateIndexOption<T>>;
|
|
14
|
+
/**
|
|
15
|
+
* Resolved index configurations after init.
|
|
16
|
+
* Key: index name, Value: index config (from metadata)
|
|
17
|
+
*/
|
|
18
|
+
registeredIndices: Map<string, IndexMetaConfig>;
|
|
19
|
+
/**
|
|
20
|
+
* Maps field name → index names that cover this field.
|
|
21
|
+
* Used for query resolution.
|
|
22
|
+
*/
|
|
23
|
+
fieldToIndices: Map<string, string[]>;
|
|
24
|
+
pendingBackfillFields: string[];
|
|
25
|
+
constructor(api: DocumentDataplyAPI<T>);
|
|
26
|
+
/**
|
|
27
|
+
* Validate and apply indices from DB metadata and pending indices.
|
|
28
|
+
* Called during database initialization.
|
|
29
|
+
*/
|
|
30
|
+
initializeIndices(metadata: DocumentDataplyInnerMetadata, isNewlyCreated: boolean, tx: Transaction): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Register an index. If called before init(), queues it.
|
|
33
|
+
*/
|
|
34
|
+
registerIndex(name: string, option: CreateIndexOption<T>, tx?: Transaction): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Register an index at runtime (after init).
|
|
37
|
+
*/
|
|
38
|
+
private registerIndexRuntime;
|
|
39
|
+
/**
|
|
40
|
+
* Drop (remove) a named index.
|
|
41
|
+
*/
|
|
42
|
+
dropIndex(name: string, tx?: Transaction): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Backfill indices for newly created indices after data was inserted.
|
|
45
|
+
*/
|
|
46
|
+
backfillIndices(tx?: Transaction): Promise<number>;
|
|
47
|
+
/**
|
|
48
|
+
* Convert CreateIndexOption to IndexMetaConfig for metadata storage.
|
|
49
|
+
*/
|
|
50
|
+
toIndexMetaConfig(option: CreateIndexOption<T>): IndexMetaConfig;
|
|
51
|
+
/**
|
|
52
|
+
* Get all field names from an IndexMetaConfig.
|
|
53
|
+
*/
|
|
54
|
+
getFieldsFromConfig(config: IndexMetaConfig): string[];
|
|
55
|
+
/**
|
|
56
|
+
* Get the primary field of an index.
|
|
57
|
+
*/
|
|
58
|
+
getPrimaryField(config: IndexMetaConfig): string;
|
|
59
|
+
/**
|
|
60
|
+
* Create B+Tree value string for indexing a document
|
|
61
|
+
*/
|
|
62
|
+
getIndexValue(config: IndexMetaConfig, flatDoc: FlattenedDocumentJSON): Primitive | Primitive[] | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Get FTSConfig from IndexMetaConfig
|
|
65
|
+
*/
|
|
66
|
+
getFtsConfig(config: IndexMetaConfig): FTSConfig | null;
|
|
67
|
+
getTokenKey(pk: number, token: string): string;
|
|
68
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DocumentDataplyMetadata, DocumentDataplyInnerMetadata, DocumentJSON } from '../types';
|
|
2
|
+
import type { DocumentDataplyAPI } from './documentAPI';
|
|
3
|
+
import { Transaction } from 'dataply';
|
|
4
|
+
export declare class MetadataManager<T extends DocumentJSON> {
|
|
5
|
+
private api;
|
|
6
|
+
constructor(api: DocumentDataplyAPI<T>);
|
|
7
|
+
getDocumentMetadata(tx: Transaction): Promise<DocumentDataplyMetadata>;
|
|
8
|
+
getDocumentInnerMetadata(tx: Transaction): Promise<DocumentDataplyInnerMetadata>;
|
|
9
|
+
updateDocumentInnerMetadata(metadata: DocumentDataplyInnerMetadata, tx: Transaction): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Run a migration if the current schemeVersion is lower than the target version.
|
|
12
|
+
* After the callback completes, schemeVersion is updated to the target version.
|
|
13
|
+
* @param version The target scheme version
|
|
14
|
+
* @param callback The migration callback
|
|
15
|
+
* @param tx Optional transaction
|
|
16
|
+
*/
|
|
17
|
+
migration(version: number, callback: (tx: Transaction) => Promise<void>, tx?: Transaction): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DocumentJSON, DataplyDocument, DocumentDataplyQuery } from '../types';
|
|
2
|
+
import type { DocumentDataplyAPI } from './documentAPI';
|
|
3
|
+
import { Transaction } from 'dataply';
|
|
4
|
+
export declare class MutationManager<T extends DocumentJSON> {
|
|
5
|
+
private api;
|
|
6
|
+
constructor(api: DocumentDataplyAPI<T>);
|
|
7
|
+
private insertDocumentInternal;
|
|
8
|
+
/**
|
|
9
|
+
* Insert a document into the database
|
|
10
|
+
* @param document The document to insert
|
|
11
|
+
* @param tx The transaction to use
|
|
12
|
+
* @returns The primary key of the inserted document
|
|
13
|
+
*/
|
|
14
|
+
insertSingleDocument(document: T, tx?: Transaction): Promise<number>;
|
|
15
|
+
/**
|
|
16
|
+
* Insert a batch of documents into the database
|
|
17
|
+
* @param documents The documents to insert
|
|
18
|
+
* @param tx The transaction to use
|
|
19
|
+
* @returns The primary keys of the inserted documents
|
|
20
|
+
*/
|
|
21
|
+
insertBatchDocuments(documents: T[], tx?: Transaction): Promise<number[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Internal update method used by both fullUpdate and partialUpdate
|
|
24
|
+
* @param query The query to use
|
|
25
|
+
* @param computeUpdatedDoc Function that computes the updated document from the original
|
|
26
|
+
* @param tx The transaction to use
|
|
27
|
+
* @returns The number of updated documents
|
|
28
|
+
*/
|
|
29
|
+
private updateInternal;
|
|
30
|
+
/**
|
|
31
|
+
* Fully update documents from the database that match the query
|
|
32
|
+
* @param query The query to use
|
|
33
|
+
* @param newRecord Complete document to replace with, or function that receives current document and returns new document
|
|
34
|
+
* @param tx The transaction to use
|
|
35
|
+
* @returns The number of updated documents
|
|
36
|
+
*/
|
|
37
|
+
fullUpdate(query: Partial<DocumentDataplyQuery<T>>, newRecord: T | ((document: DataplyDocument<T>) => T), tx?: Transaction): Promise<number>;
|
|
38
|
+
/**
|
|
39
|
+
* Partially update documents from the database that match the query
|
|
40
|
+
* @param query The query to use
|
|
41
|
+
* @param newRecord Partial document to merge, or function that receives current document and returns partial update
|
|
42
|
+
* @param tx The transaction to use
|
|
43
|
+
* @returns The number of updated documents
|
|
44
|
+
*/
|
|
45
|
+
partialUpdate(query: Partial<DocumentDataplyQuery<T>>, newRecord: Partial<DataplyDocument<T>> | ((document: DataplyDocument<T>) => Partial<DataplyDocument<T>>), tx?: Transaction): Promise<number>;
|
|
46
|
+
/**
|
|
47
|
+
* Delete documents from the database that match the query
|
|
48
|
+
* @param query The query to use
|
|
49
|
+
* @param tx The transaction to use
|
|
50
|
+
* @returns The number of deleted documents
|
|
51
|
+
*/
|
|
52
|
+
deleteDocuments(query: Partial<DocumentDataplyQuery<T>>, tx?: Transaction): Promise<number>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { DataplyTreeValue, DocumentDataplyQuery, DocumentDataplyCondition } from '../types';
|
|
2
|
+
import type { DocumentDataplyAPI } from './documentAPI';
|
|
3
|
+
import { BPTreeAsync } from 'dataply';
|
|
4
|
+
export declare class Optimizer<T extends Record<string, any>> {
|
|
5
|
+
private api;
|
|
6
|
+
constructor(api: DocumentDataplyAPI<T>);
|
|
7
|
+
/**
|
|
8
|
+
* B-Tree 타입 인덱스의 선택도를 평가하고 트리에 부여할 조건을 산출합니다.
|
|
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>;
|
|
12
|
+
readonly condition: any;
|
|
13
|
+
readonly field: any;
|
|
14
|
+
readonly indexName: string;
|
|
15
|
+
readonly isFtsMatch: false;
|
|
16
|
+
readonly score: number;
|
|
17
|
+
readonly compositeVerifyFields: string[];
|
|
18
|
+
readonly coveredFields: string[];
|
|
19
|
+
readonly isIndexOrderSupported: boolean;
|
|
20
|
+
} | null;
|
|
21
|
+
/**
|
|
22
|
+
* FTS 타입 인덱스의 선택도를 평가합니다.
|
|
23
|
+
*/
|
|
24
|
+
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>): {
|
|
25
|
+
readonly tree: BPTreeAsync<string | number, V>;
|
|
26
|
+
readonly condition: any;
|
|
27
|
+
readonly field: any;
|
|
28
|
+
readonly indexName: string;
|
|
29
|
+
readonly isFtsMatch: true;
|
|
30
|
+
readonly matchTokens: string[];
|
|
31
|
+
readonly score: 90;
|
|
32
|
+
readonly compositeVerifyFields: readonly [];
|
|
33
|
+
readonly coveredFields: readonly [any];
|
|
34
|
+
readonly isIndexOrderSupported: false;
|
|
35
|
+
} | null;
|
|
36
|
+
/**
|
|
37
|
+
* 실행할 최적의 인덱스를 선택합니다. (최적 드라이버 선택)
|
|
38
|
+
*/
|
|
39
|
+
getSelectivityCandidate<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(query: Partial<DocumentDataplyQuery<V>>, orderByField?: string): Promise<{
|
|
40
|
+
driver: ({
|
|
41
|
+
tree: BPTreeAsync<number, V>;
|
|
42
|
+
condition: Partial<DocumentDataplyCondition<U>>;
|
|
43
|
+
field: string;
|
|
44
|
+
indexName: string;
|
|
45
|
+
isFtsMatch: false;
|
|
46
|
+
isIndexOrderSupported: boolean;
|
|
47
|
+
} | {
|
|
48
|
+
tree: BPTreeAsync<string, V>;
|
|
49
|
+
condition: Partial<DocumentDataplyCondition<U>>;
|
|
50
|
+
field: string;
|
|
51
|
+
indexName: string;
|
|
52
|
+
isFtsMatch: true;
|
|
53
|
+
matchTokens: string[];
|
|
54
|
+
isIndexOrderSupported: boolean;
|
|
55
|
+
});
|
|
56
|
+
others: ({
|
|
57
|
+
tree: BPTreeAsync<number, V>;
|
|
58
|
+
condition: Partial<DocumentDataplyCondition<U>>;
|
|
59
|
+
field: string;
|
|
60
|
+
indexName: string;
|
|
61
|
+
isFtsMatch: false;
|
|
62
|
+
isIndexOrderSupported: boolean;
|
|
63
|
+
} | {
|
|
64
|
+
tree: BPTreeAsync<string, V>;
|
|
65
|
+
condition: Partial<DocumentDataplyCondition<U>>;
|
|
66
|
+
field: string;
|
|
67
|
+
indexName: string;
|
|
68
|
+
isFtsMatch: true;
|
|
69
|
+
matchTokens: string[];
|
|
70
|
+
isIndexOrderSupported: boolean;
|
|
71
|
+
})[];
|
|
72
|
+
compositeVerifyConditions: {
|
|
73
|
+
field: string;
|
|
74
|
+
condition: any;
|
|
75
|
+
}[];
|
|
76
|
+
rollback: () => void;
|
|
77
|
+
} | null>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { DataplyTreeValue, DocumentDataplyQuery, DocumentDataplyQueryOptions, DataplyDocument, Primitive, DocumentJSON } from '../types';
|
|
2
|
+
import type { DocumentDataplyAPI } from './documentAPI';
|
|
3
|
+
import type { Optimizer } from './Optimizer';
|
|
4
|
+
import { BPTreeAsync } from 'dataply';
|
|
5
|
+
export declare class QueryManager<T extends DocumentJSON> {
|
|
6
|
+
private api;
|
|
7
|
+
private optimizer;
|
|
8
|
+
private readonly operatorConverters;
|
|
9
|
+
constructor(api: DocumentDataplyAPI<T>, optimizer: Optimizer<T>);
|
|
10
|
+
/**
|
|
11
|
+
* Transforms a query object into a verbose query object
|
|
12
|
+
*/
|
|
13
|
+
verboseQuery<U extends Partial<DocumentDataplyQuery<T>>, V extends DataplyTreeValue<U>>(query: Partial<DocumentDataplyQuery<U>>): Partial<DocumentDataplyQuery<V>>;
|
|
14
|
+
getFreeMemoryChunkSize(): {
|
|
15
|
+
verySmallChunkSize: number;
|
|
16
|
+
smallChunkSize: number;
|
|
17
|
+
};
|
|
18
|
+
private applyCandidateByFTSStream;
|
|
19
|
+
private applyCandidateStream;
|
|
20
|
+
getKeys(query: Partial<DocumentDataplyQuery<T>>, orderBy?: string, sortOrder?: 'asc' | 'desc'): Promise<Float64Array>;
|
|
21
|
+
getDriverKeys(query: Partial<DocumentDataplyQuery<T>>, orderBy?: string, sortOrder?: 'asc' | 'desc'): Promise<{
|
|
22
|
+
keysStream: AsyncIterableIterator<number>;
|
|
23
|
+
others: {
|
|
24
|
+
tree: BPTreeAsync<string | number, DataplyTreeValue<Primitive>>;
|
|
25
|
+
condition: any;
|
|
26
|
+
field: string;
|
|
27
|
+
indexName: string;
|
|
28
|
+
isFtsMatch: boolean;
|
|
29
|
+
matchTokens?: string[];
|
|
30
|
+
}[];
|
|
31
|
+
compositeVerifyConditions: {
|
|
32
|
+
field: string;
|
|
33
|
+
condition: any;
|
|
34
|
+
}[];
|
|
35
|
+
isDriverOrderByField: boolean;
|
|
36
|
+
rollback: () => void;
|
|
37
|
+
} | null>;
|
|
38
|
+
verifyFts(doc: DataplyDocument<T>, ftsConditions: {
|
|
39
|
+
field: string;
|
|
40
|
+
matchTokens: string[];
|
|
41
|
+
}[]): boolean;
|
|
42
|
+
verifyCompositeConditions(doc: DataplyDocument<T>, conditions: {
|
|
43
|
+
field: string;
|
|
44
|
+
condition: any;
|
|
45
|
+
}[]): boolean;
|
|
46
|
+
verifyValue(value: Primitive, condition: any): boolean;
|
|
47
|
+
adjustChunkSize(currentChunkSize: number, chunkTotalSize: number): number;
|
|
48
|
+
processChunkedKeysWithVerify(keysStream: AsyncIterableIterator<number>, startIdx: number, initialChunkSize: number, limit: number, ftsConditions: {
|
|
49
|
+
field: string;
|
|
50
|
+
matchTokens: string[];
|
|
51
|
+
}[], compositeVerifyConditions: {
|
|
52
|
+
field: string;
|
|
53
|
+
condition: any;
|
|
54
|
+
}[], others: {
|
|
55
|
+
tree: BPTreeAsync<string | number, DataplyTreeValue<Primitive>>;
|
|
56
|
+
condition: any;
|
|
57
|
+
field: string;
|
|
58
|
+
indexName: string;
|
|
59
|
+
isFtsMatch: boolean;
|
|
60
|
+
matchTokens?: string[];
|
|
61
|
+
}[], tx: any): AsyncGenerator<DataplyDocument<T>>;
|
|
62
|
+
/**
|
|
63
|
+
* Count documents from the database that match the query
|
|
64
|
+
* @param query The query to use
|
|
65
|
+
* @param tx The transaction to use
|
|
66
|
+
* @returns The number of documents that match the query
|
|
67
|
+
*/
|
|
68
|
+
countDocuments(query: Partial<DocumentDataplyQuery<T>>, tx?: any): Promise<number>;
|
|
69
|
+
selectDocuments(query: Partial<DocumentDataplyQuery<T>>, options?: DocumentDataplyQueryOptions, tx?: any): {
|
|
70
|
+
stream: () => AsyncIterableIterator<DataplyDocument<T>>;
|
|
71
|
+
drain: () => Promise<DataplyDocument<T>[]>;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -1,92 +1,48 @@
|
|
|
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';
|
|
4
10
|
export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyAPI {
|
|
5
11
|
runWithDefault: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
|
|
6
12
|
runWithDefaultWrite: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
|
|
7
13
|
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;
|
|
14
|
+
readonly comparator: DocumentValueComparator<import("../types").DataplyTreeValue<import("../types").Primitive>, import("../types").Primitive>;
|
|
12
15
|
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;
|
|
16
|
+
readonly optimizer: Optimizer<T>;
|
|
17
|
+
readonly queryManager: QueryManager<T>;
|
|
18
|
+
readonly indexManager: IndexManager<T>;
|
|
19
|
+
readonly mutationManager: MutationManager<T>;
|
|
20
|
+
readonly metadataManager: MetadataManager<T>;
|
|
21
|
+
readonly documentFormatter: DocumentFormatter<T>;
|
|
30
22
|
constructor(file: string, options: DocumentDataplyOptions);
|
|
31
23
|
/**
|
|
32
24
|
* Whether the document database has been initialized.
|
|
33
25
|
*/
|
|
34
26
|
get isDocInitialized(): boolean;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
get indices(): {
|
|
28
|
+
[key: string]: [number, import("../types").IndexMetaConfig];
|
|
29
|
+
};
|
|
30
|
+
get trees(): Map<string, import("dataply").BPTreeAsync<string | number, import("../types").DataplyTreeValue<import("../types").Primitive>>>;
|
|
31
|
+
get indexedFields(): Set<string>;
|
|
39
32
|
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
33
|
/**
|
|
46
34
|
* 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
35
|
*/
|
|
51
36
|
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;
|
|
78
37
|
getDocument(pk: number, tx?: Transaction): Promise<DataplyDocument<T>>;
|
|
79
38
|
/**
|
|
80
39
|
* Backfill indices for newly created indices after data was inserted.
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* @returns Number of documents that were backfilled
|
|
40
|
+
* Delegated to IndexManager.
|
|
84
41
|
*/
|
|
85
42
|
backfillIndices(tx?: Transaction): Promise<number>;
|
|
86
43
|
createDocumentInnerMetadata(indices: DocumentDataplyInnerMetadata['indices']): DocumentDataplyInnerMetadata;
|
|
87
44
|
initializeDocumentFile(tx: Transaction): Promise<void>;
|
|
88
45
|
verifyDocumentFile(tx: Transaction): Promise<boolean>;
|
|
89
|
-
private flatten;
|
|
90
46
|
/**
|
|
91
47
|
* returns flattened document
|
|
92
48
|
* @param document
|
|
@@ -104,110 +60,6 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyA
|
|
|
104
60
|
* @param tx Optional transaction
|
|
105
61
|
*/
|
|
106
62
|
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
63
|
/**
|
|
212
64
|
* Insert a document into the database
|
|
213
65
|
* @param document The document to insert
|
|
@@ -222,14 +74,6 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyA
|
|
|
222
74
|
* @returns The primary keys of the inserted documents
|
|
223
75
|
*/
|
|
224
76
|
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
77
|
/**
|
|
234
78
|
* Fully update documents from the database that match the query
|
|
235
79
|
* @param query The query to use
|
|
@@ -260,27 +104,6 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyA
|
|
|
260
104
|
* @returns The number of documents that match the query
|
|
261
105
|
*/
|
|
262
106
|
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
107
|
/**
|
|
285
108
|
* Select documents from the database
|
|
286
109
|
* @param query The query to use
|
|
@@ -53,6 +53,11 @@ export interface DocumentDataplyMetadata {
|
|
|
53
53
|
* The total number of data rows in the dataply.
|
|
54
54
|
*/
|
|
55
55
|
rowCount: number;
|
|
56
|
+
/**
|
|
57
|
+
* The usage of the dataply. It is calculated based on the remaining page capacity.
|
|
58
|
+
* The value is between 0 and 1.
|
|
59
|
+
*/
|
|
60
|
+
usage: number;
|
|
56
61
|
/**
|
|
57
62
|
* The list of user-created index names (excludes internal '_id' index).
|
|
58
63
|
*/
|
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.4",
|
|
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>",
|