document-dataply 0.0.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 +7346 -0
- package/dist/types/core/bptree/documentComparator.d.ts +7 -0
- package/dist/types/core/bptree/documentStrategy.d.ts +15 -0
- package/dist/types/core/document.d.ts +50 -0
- package/dist/types/core/index.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types/index.d.ts +55 -0
- package/package.json +38 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ValueComparator } from 'dataply';
|
|
2
|
+
import type { DataplyTreeValue, Primitive } from '../../types';
|
|
3
|
+
export declare class DocumentValueComparator<T extends DataplyTreeValue<U>, U extends Primitive> extends ValueComparator<T> {
|
|
4
|
+
primaryAsc(a: T, b: T): number;
|
|
5
|
+
asc(a: T, b: T): number;
|
|
6
|
+
match(value: T): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DataplyTreeValue, Primitive } from '../../types';
|
|
2
|
+
import { BPTreeNode, SerializeStrategyAsync, type SerializeStrategyHead } from 'dataply';
|
|
3
|
+
import { DocumentDataplyAPI } from '../document';
|
|
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>['txContext'];
|
|
7
|
+
protected readonly treeKey: string;
|
|
8
|
+
constructor(order: number, api: DocumentDataplyAPI<any>, txContext: DocumentDataplyAPI<any>['txContext'], treeKey: string);
|
|
9
|
+
id(isLeaf: boolean): Promise<string>;
|
|
10
|
+
read(id: string): Promise<BPTreeNode<number, DataplyTreeValue<T>>>;
|
|
11
|
+
write(id: string, node: BPTreeNode<number, DataplyTreeValue<T>>): Promise<void>;
|
|
12
|
+
delete(id: string): Promise<void>;
|
|
13
|
+
readHead(): Promise<SerializeStrategyHead | null>;
|
|
14
|
+
writeHead(head: SerializeStrategyHead): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { DataplyTreeValue, DocumentDataplyMetadata, DocumentDataplyOptions, DocumentJSON, FlattenedDocumentJSON, Primitive, DocumentDataplyQuery, FinalFlatten, DocumentDataplyCondition, DataplyDocument } from '../types';
|
|
2
|
+
import { DataplyAPI, Transaction, BPTreeAsync } from 'dataply';
|
|
3
|
+
import { DocumentValueComparator } from './bptree/documentComparator';
|
|
4
|
+
export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyAPI {
|
|
5
|
+
runWithDefault: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
|
|
6
|
+
treeHeads: DocumentDataplyMetadata['treeHeads'];
|
|
7
|
+
readonly trees: Map<string, BPTreeAsync<number, DataplyTreeValue<Primitive>>>;
|
|
8
|
+
readonly comparator: DocumentValueComparator<DataplyTreeValue<Primitive>, Primitive>;
|
|
9
|
+
constructor(file: string, options: DocumentDataplyOptions);
|
|
10
|
+
ensureTree<T extends Primitive>(field: string): Promise<BPTreeAsync<number, DataplyTreeValue<T>>>;
|
|
11
|
+
createDocumentMetadata(): DocumentDataplyMetadata;
|
|
12
|
+
initializeDocumentFile(tx: Transaction): Promise<void>;
|
|
13
|
+
verifyDocumentFile(tx: Transaction): Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* returns flattened document
|
|
16
|
+
* @param document
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
flattenDocument(document: T): FlattenedDocumentJSON;
|
|
20
|
+
getDocumentMetadata(tx: Transaction): Promise<DocumentDataplyMetadata>;
|
|
21
|
+
updateDocumentMetadata(metadata: DocumentDataplyMetadata, tx: Transaction): Promise<void>;
|
|
22
|
+
updateTreeHead(tx: Transaction): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare class DocumentDataply<T extends DocumentJSON> {
|
|
25
|
+
protected readonly api: DocumentDataplyAPI<T>;
|
|
26
|
+
private readonly operatorConverters;
|
|
27
|
+
constructor(file: string, options?: DocumentDataplyOptions);
|
|
28
|
+
init(): Promise<void>;
|
|
29
|
+
createTransaction(): Transaction;
|
|
30
|
+
private verboseQuery;
|
|
31
|
+
/**
|
|
32
|
+
* Return optimized tree for query
|
|
33
|
+
* @param query
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
getSelectivityCandidate<U extends FinalFlatten<DataplyDocument<T>>, V extends DataplyTreeValue<U>>(query: Partial<DocumentDataplyQuery<V>>): Promise<{
|
|
37
|
+
driver: {
|
|
38
|
+
tree: BPTreeAsync<number, V>;
|
|
39
|
+
condition: Partial<DocumentDataplyCondition<U>>;
|
|
40
|
+
};
|
|
41
|
+
others: {
|
|
42
|
+
tree: BPTreeAsync<number, V>;
|
|
43
|
+
condition: Partial<DocumentDataplyCondition<U>>;
|
|
44
|
+
}[];
|
|
45
|
+
} | null>;
|
|
46
|
+
private insertDocument;
|
|
47
|
+
insert(document: T, tx?: Transaction): Promise<boolean>;
|
|
48
|
+
select(query: Partial<DocumentDataplyQuery<FinalFlatten<DataplyDocument<T>>>>, limit?: number, tx?: Transaction): Promise<DataplyDocument<T>[]>;
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './core';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { DataplyOptions, SerializeStrategyHead } from 'dataply';
|
|
2
|
+
export type Primitive = string | number | boolean | null;
|
|
3
|
+
export type JSONValue = Primitive | JSONValue[] | {
|
|
4
|
+
[key: string]: JSONValue;
|
|
5
|
+
};
|
|
6
|
+
export type DocumentJSON = {
|
|
7
|
+
[key: string]: JSONValue;
|
|
8
|
+
};
|
|
9
|
+
export type FlattenedDocumentJSON = {
|
|
10
|
+
[key: string]: Primitive;
|
|
11
|
+
};
|
|
12
|
+
export interface DocumentDataplyMetadata {
|
|
13
|
+
magicString: string;
|
|
14
|
+
version: number;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
updatedAt: number;
|
|
17
|
+
lastId: number;
|
|
18
|
+
treeHeads: Record<string, SerializeStrategyHead>;
|
|
19
|
+
}
|
|
20
|
+
export type DataplyDocumentBase = {
|
|
21
|
+
_id: number;
|
|
22
|
+
};
|
|
23
|
+
export type DataplyDocument<T extends DocumentJSON> = DataplyDocumentBase & T;
|
|
24
|
+
export type DocumentDataplyCondition<V> = {
|
|
25
|
+
lt?: Partial<V>;
|
|
26
|
+
lte?: Partial<V>;
|
|
27
|
+
gt?: Partial<V>;
|
|
28
|
+
gte?: Partial<V>;
|
|
29
|
+
equal?: Partial<V>;
|
|
30
|
+
notEqual?: Partial<V>;
|
|
31
|
+
like?: Partial<V>;
|
|
32
|
+
};
|
|
33
|
+
export type DocumentDataplyQuery<T> = {
|
|
34
|
+
[key in keyof T]: T[key] | DocumentDataplyCondition<T[key]>;
|
|
35
|
+
};
|
|
36
|
+
export interface DataplyTreeValue<T> {
|
|
37
|
+
k: number;
|
|
38
|
+
v: T;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* T가 객체인지 확인하고, 객체라면 하위 키를 재귀적으로 탐색합니다.
|
|
42
|
+
*/
|
|
43
|
+
type DeepFlattenKeys<T, Prefix extends string = ""> = T extends object ? {
|
|
44
|
+
[K in keyof T & string]: NonNullable<T[K]> extends object ? DeepFlattenKeys<NonNullable<T[K]>, `${Prefix}${K}.`> : `${Prefix}${K}`;
|
|
45
|
+
}[keyof T & string] : Prefix extends `${infer P}.` ? P : "";
|
|
46
|
+
/**
|
|
47
|
+
* 경로 문자열(Path)을 기반으로 원본 객체(T)에서 타입을 찾아옵니다.
|
|
48
|
+
*/
|
|
49
|
+
type GetTypeByPath<T, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? GetTypeByPath<NonNullable<T[Key]>, Rest> : never : Path extends keyof T ? T[Path] : never;
|
|
50
|
+
export type FinalFlatten<T> = {
|
|
51
|
+
[P in DeepFlattenKeys<T>]: GetTypeByPath<T, P & string>;
|
|
52
|
+
};
|
|
53
|
+
export interface DocumentDataplyOptions extends DataplyOptions {
|
|
54
|
+
}
|
|
55
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "document-dataply",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "izure <admin@izure.org>",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"main": "./dist/cjs/index.js",
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"require": "./dist/cjs/index.js",
|
|
14
|
+
"import": "./dist/cjs/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/**/*"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/izure1/document-dataply.git"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "jest -i",
|
|
26
|
+
"build": "node build/index.js && tsc"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"dataply": "^0.0.14"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^30.0.0",
|
|
33
|
+
"esbuild": "^0.27.2",
|
|
34
|
+
"jest": "^30.2.0",
|
|
35
|
+
"ts-jest": "^29.4.6",
|
|
36
|
+
"typescript": "^5.9.3"
|
|
37
|
+
}
|
|
38
|
+
}
|