document-dataply 0.0.1 → 0.0.2-alpha.0
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 +50 -14
- package/dist/types/core/document.d.ts +32 -5
- package/dist/types/types/index.d.ts +15 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -6776,11 +6776,11 @@ var require_cjs = __commonJS({
|
|
|
6776
6776
|
* Retrieves metadata from the dataply.
|
|
6777
6777
|
* @returns Metadata of the dataply.
|
|
6778
6778
|
*/
|
|
6779
|
-
async getMetadata() {
|
|
6779
|
+
async getMetadata(tx) {
|
|
6780
6780
|
if (!this.initialized) {
|
|
6781
6781
|
throw new Error("Dataply instance is not initialized");
|
|
6782
6782
|
}
|
|
6783
|
-
return this.runWithDefault((
|
|
6783
|
+
return this.runWithDefault((tx2) => this.rowTableEngine.getMetadata(tx2), tx);
|
|
6784
6784
|
}
|
|
6785
6785
|
/**
|
|
6786
6786
|
* Inserts data. Returns the PK of the added row.
|
|
@@ -6932,8 +6932,8 @@ var require_cjs = __commonJS({
|
|
|
6932
6932
|
* Retrieves metadata from the dataply.
|
|
6933
6933
|
* @returns Metadata of the dataply.
|
|
6934
6934
|
*/
|
|
6935
|
-
async getMetadata() {
|
|
6936
|
-
return this.api.getMetadata();
|
|
6935
|
+
async getMetadata(tx) {
|
|
6936
|
+
return this.api.getMetadata(tx);
|
|
6937
6937
|
}
|
|
6938
6938
|
/**
|
|
6939
6939
|
* Inserts data. Returns the PK of the added row.
|
|
@@ -7073,7 +7073,7 @@ var DocumentSerializeStrategyAsync = class extends import_dataply.SerializeStrat
|
|
|
7073
7073
|
}
|
|
7074
7074
|
async readHead() {
|
|
7075
7075
|
const tx = this.txContext.get();
|
|
7076
|
-
const metadata = await this.api.
|
|
7076
|
+
const metadata = await this.api.getDocumentInnerMetadata(tx);
|
|
7077
7077
|
if (metadata.treeHeads[this.treeKey]) {
|
|
7078
7078
|
return metadata.treeHeads[this.treeKey];
|
|
7079
7079
|
}
|
|
@@ -7081,9 +7081,9 @@ var DocumentSerializeStrategyAsync = class extends import_dataply.SerializeStrat
|
|
|
7081
7081
|
}
|
|
7082
7082
|
async writeHead(head) {
|
|
7083
7083
|
const tx = this.txContext.get();
|
|
7084
|
-
const metadata = await this.api.
|
|
7084
|
+
const metadata = await this.api.getDocumentInnerMetadata(tx);
|
|
7085
7085
|
metadata.treeHeads[this.treeKey] = head;
|
|
7086
|
-
await this.api.
|
|
7086
|
+
await this.api.updateDocumentInnerMetadata(metadata, tx);
|
|
7087
7087
|
}
|
|
7088
7088
|
};
|
|
7089
7089
|
|
|
@@ -7124,7 +7124,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
7124
7124
|
if (!await this.verifyDocumentFile(tx)) {
|
|
7125
7125
|
throw new Error("Document metadata verification failed");
|
|
7126
7126
|
}
|
|
7127
|
-
const metadata = await this.
|
|
7127
|
+
const metadata = await this.getDocumentInnerMetadata(tx);
|
|
7128
7128
|
this.treeHeads = metadata.treeHeads;
|
|
7129
7129
|
return tx;
|
|
7130
7130
|
});
|
|
@@ -7193,19 +7193,27 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
7193
7193
|
return result;
|
|
7194
7194
|
}
|
|
7195
7195
|
async getDocumentMetadata(tx) {
|
|
7196
|
+
const metadata = await this.getMetadata(tx);
|
|
7197
|
+
return {
|
|
7198
|
+
pageSize: metadata.pageSize,
|
|
7199
|
+
pageCount: metadata.pageCount,
|
|
7200
|
+
rowCount: metadata.rowCount
|
|
7201
|
+
};
|
|
7202
|
+
}
|
|
7203
|
+
async getDocumentInnerMetadata(tx) {
|
|
7196
7204
|
const row = await this.select(1, false, tx);
|
|
7197
7205
|
if (!row) {
|
|
7198
7206
|
throw new Error("Document metadata not found");
|
|
7199
7207
|
}
|
|
7200
7208
|
return JSON.parse(row);
|
|
7201
7209
|
}
|
|
7202
|
-
async
|
|
7210
|
+
async updateDocumentInnerMetadata(metadata, tx) {
|
|
7203
7211
|
await this.update(1, JSON.stringify(metadata), tx);
|
|
7204
7212
|
}
|
|
7205
7213
|
async updateTreeHead(tx) {
|
|
7206
|
-
const metadata = await this.
|
|
7214
|
+
const metadata = await this.getDocumentInnerMetadata(tx);
|
|
7207
7215
|
metadata.treeHeads = this.treeHeads;
|
|
7208
|
-
await this.
|
|
7216
|
+
await this.updateDocumentInnerMetadata(metadata, tx);
|
|
7209
7217
|
}
|
|
7210
7218
|
};
|
|
7211
7219
|
var DocumentDataply = class {
|
|
@@ -7222,9 +7230,21 @@ var DocumentDataply = class {
|
|
|
7222
7230
|
constructor(file, options) {
|
|
7223
7231
|
this.api = new DocumentDataplyAPI(file, options ?? {});
|
|
7224
7232
|
}
|
|
7233
|
+
/**
|
|
7234
|
+
* Initialize the document database
|
|
7235
|
+
*/
|
|
7225
7236
|
async init() {
|
|
7226
7237
|
await this.api.init();
|
|
7227
7238
|
}
|
|
7239
|
+
/**
|
|
7240
|
+
* Get the metadata of the document database
|
|
7241
|
+
*/
|
|
7242
|
+
async getMetadata(tx) {
|
|
7243
|
+
return this.api.runWithDefault((tx2) => this.api.getDocumentMetadata(tx2), tx);
|
|
7244
|
+
}
|
|
7245
|
+
/**
|
|
7246
|
+
* Create a transaction
|
|
7247
|
+
*/
|
|
7228
7248
|
createTransaction() {
|
|
7229
7249
|
return this.api.createTransaction();
|
|
7230
7250
|
}
|
|
@@ -7250,7 +7270,7 @@ var DocumentDataply = class {
|
|
|
7250
7270
|
return result;
|
|
7251
7271
|
}
|
|
7252
7272
|
/**
|
|
7253
|
-
*
|
|
7273
|
+
* Get the selectivity candidate for the given query
|
|
7254
7274
|
* @param query
|
|
7255
7275
|
* @returns
|
|
7256
7276
|
*/
|
|
@@ -7273,9 +7293,9 @@ var DocumentDataply = class {
|
|
|
7273
7293
|
};
|
|
7274
7294
|
}
|
|
7275
7295
|
async insertDocument(document, tx) {
|
|
7276
|
-
const metadata = await this.api.
|
|
7296
|
+
const metadata = await this.api.getDocumentInnerMetadata(tx);
|
|
7277
7297
|
const id = metadata.lastId++;
|
|
7278
|
-
await this.api.
|
|
7298
|
+
await this.api.updateDocumentInnerMetadata(metadata, tx);
|
|
7279
7299
|
const dataplyDocument = Object.assign({
|
|
7280
7300
|
_id: id
|
|
7281
7301
|
}, document);
|
|
@@ -7286,6 +7306,12 @@ var DocumentDataply = class {
|
|
|
7286
7306
|
document: dataplyDocument
|
|
7287
7307
|
};
|
|
7288
7308
|
}
|
|
7309
|
+
/**
|
|
7310
|
+
* Insert a document into the database
|
|
7311
|
+
* @param document The document to insert
|
|
7312
|
+
* @param tx The transaction to use
|
|
7313
|
+
* @returns True if the document was inserted successfully
|
|
7314
|
+
*/
|
|
7289
7315
|
async insert(document, tx) {
|
|
7290
7316
|
return this.api.runWithDefault(async (tx2) => {
|
|
7291
7317
|
const { k, document: dataplyDocument } = await this.insertDocument(document, tx2);
|
|
@@ -7298,6 +7324,13 @@ var DocumentDataply = class {
|
|
|
7298
7324
|
return true;
|
|
7299
7325
|
}, tx);
|
|
7300
7326
|
}
|
|
7327
|
+
/**
|
|
7328
|
+
* Select documents from the database
|
|
7329
|
+
* @param query The query to use
|
|
7330
|
+
* @param limit The maximum number of documents to return
|
|
7331
|
+
* @param tx The transaction to use
|
|
7332
|
+
* @returns The documents that match the query
|
|
7333
|
+
*/
|
|
7301
7334
|
async select(query, limit = Infinity, tx) {
|
|
7302
7335
|
return this.api.runWithDefault(async (tx2) => {
|
|
7303
7336
|
const verbose = this.verboseQuery(query);
|
|
@@ -7331,6 +7364,9 @@ var DocumentDataply = class {
|
|
|
7331
7364
|
return documents;
|
|
7332
7365
|
}, tx);
|
|
7333
7366
|
}
|
|
7367
|
+
/**
|
|
7368
|
+
* Close the document database
|
|
7369
|
+
*/
|
|
7334
7370
|
async close() {
|
|
7335
7371
|
await this.api.close();
|
|
7336
7372
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { DataplyTreeValue,
|
|
1
|
+
import type { DataplyTreeValue, DocumentDataplyInnerMetadata, DocumentDataplyOptions, DocumentJSON, FlattenedDocumentJSON, Primitive, DocumentDataplyQuery, FinalFlatten, DocumentDataplyCondition, DataplyDocument, DocumentDataplyMetadata } from '../types';
|
|
2
2
|
import { DataplyAPI, Transaction, BPTreeAsync } from 'dataply';
|
|
3
3
|
import { DocumentValueComparator } from './bptree/documentComparator';
|
|
4
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
|
-
treeHeads:
|
|
6
|
+
treeHeads: DocumentDataplyInnerMetadata['treeHeads'];
|
|
7
7
|
readonly trees: Map<string, BPTreeAsync<number, DataplyTreeValue<Primitive>>>;
|
|
8
8
|
readonly comparator: DocumentValueComparator<DataplyTreeValue<Primitive>, Primitive>;
|
|
9
9
|
constructor(file: string, options: DocumentDataplyOptions);
|
|
10
10
|
ensureTree<T extends Primitive>(field: string): Promise<BPTreeAsync<number, DataplyTreeValue<T>>>;
|
|
11
|
-
createDocumentMetadata():
|
|
11
|
+
createDocumentMetadata(): DocumentDataplyInnerMetadata;
|
|
12
12
|
initializeDocumentFile(tx: Transaction): Promise<void>;
|
|
13
13
|
verifyDocumentFile(tx: Transaction): Promise<boolean>;
|
|
14
14
|
/**
|
|
@@ -18,18 +18,29 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyA
|
|
|
18
18
|
*/
|
|
19
19
|
flattenDocument(document: T): FlattenedDocumentJSON;
|
|
20
20
|
getDocumentMetadata(tx: Transaction): Promise<DocumentDataplyMetadata>;
|
|
21
|
-
|
|
21
|
+
getDocumentInnerMetadata(tx: Transaction): Promise<DocumentDataplyInnerMetadata>;
|
|
22
|
+
updateDocumentInnerMetadata(metadata: DocumentDataplyInnerMetadata, tx: Transaction): Promise<void>;
|
|
22
23
|
updateTreeHead(tx: Transaction): Promise<void>;
|
|
23
24
|
}
|
|
24
25
|
export declare class DocumentDataply<T extends DocumentJSON> {
|
|
25
26
|
protected readonly api: DocumentDataplyAPI<T>;
|
|
26
27
|
private readonly operatorConverters;
|
|
27
28
|
constructor(file: string, options?: DocumentDataplyOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the document database
|
|
31
|
+
*/
|
|
28
32
|
init(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Get the metadata of the document database
|
|
35
|
+
*/
|
|
36
|
+
getMetadata(tx?: Transaction): Promise<DocumentDataplyMetadata>;
|
|
37
|
+
/**
|
|
38
|
+
* Create a transaction
|
|
39
|
+
*/
|
|
29
40
|
createTransaction(): Transaction;
|
|
30
41
|
private verboseQuery;
|
|
31
42
|
/**
|
|
32
|
-
*
|
|
43
|
+
* Get the selectivity candidate for the given query
|
|
33
44
|
* @param query
|
|
34
45
|
* @returns
|
|
35
46
|
*/
|
|
@@ -44,7 +55,23 @@ export declare class DocumentDataply<T extends DocumentJSON> {
|
|
|
44
55
|
}[];
|
|
45
56
|
} | null>;
|
|
46
57
|
private insertDocument;
|
|
58
|
+
/**
|
|
59
|
+
* Insert a document into the database
|
|
60
|
+
* @param document The document to insert
|
|
61
|
+
* @param tx The transaction to use
|
|
62
|
+
* @returns True if the document was inserted successfully
|
|
63
|
+
*/
|
|
47
64
|
insert(document: T, tx?: Transaction): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Select documents from the database
|
|
67
|
+
* @param query The query to use
|
|
68
|
+
* @param limit The maximum number of documents to return
|
|
69
|
+
* @param tx The transaction to use
|
|
70
|
+
* @returns The documents that match the query
|
|
71
|
+
*/
|
|
48
72
|
select(query: Partial<DocumentDataplyQuery<FinalFlatten<DataplyDocument<T>>>>, limit?: number, tx?: Transaction): Promise<DataplyDocument<T>[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Close the document database
|
|
75
|
+
*/
|
|
49
76
|
close(): Promise<void>;
|
|
50
77
|
}
|
|
@@ -9,7 +9,7 @@ export type DocumentJSON = {
|
|
|
9
9
|
export type FlattenedDocumentJSON = {
|
|
10
10
|
[key: string]: Primitive;
|
|
11
11
|
};
|
|
12
|
-
export interface
|
|
12
|
+
export interface DocumentDataplyInnerMetadata {
|
|
13
13
|
magicString: string;
|
|
14
14
|
version: number;
|
|
15
15
|
createdAt: number;
|
|
@@ -17,6 +17,20 @@ export interface DocumentDataplyMetadata {
|
|
|
17
17
|
lastId: number;
|
|
18
18
|
treeHeads: Record<string, SerializeStrategyHead>;
|
|
19
19
|
}
|
|
20
|
+
export interface DocumentDataplyMetadata {
|
|
21
|
+
/**
|
|
22
|
+
* The size of a page in bytes.
|
|
23
|
+
*/
|
|
24
|
+
pageSize: number;
|
|
25
|
+
/**
|
|
26
|
+
* The total number of pages in the dataply.
|
|
27
|
+
*/
|
|
28
|
+
pageCount: number;
|
|
29
|
+
/**
|
|
30
|
+
* The total number of data rows in the dataply.
|
|
31
|
+
*/
|
|
32
|
+
rowCount: number;
|
|
33
|
+
}
|
|
20
34
|
export type DataplyDocumentBase = {
|
|
21
35
|
_id: number;
|
|
22
36
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-dataply",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "izure <admin@izure.org>",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"build": "node build/index.js && tsc"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"dataply": "^0.0.
|
|
29
|
+
"dataply": "^0.0.16-alpha.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/jest": "^30.0.0",
|