document-dataply 0.0.7-alpha.1 → 0.0.7
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 +45 -45
- package/dist/types/core/documentAPI.d.ts +20 -9
- package/package.json +3 -3
- package/dist/types/utils/hash.d.ts +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -10148,15 +10148,6 @@ function tokenize(text, options) {
|
|
|
10148
10148
|
return [];
|
|
10149
10149
|
}
|
|
10150
10150
|
|
|
10151
|
-
// src/utils/hash.ts
|
|
10152
|
-
function fastStringHash(str) {
|
|
10153
|
-
let hash = 0;
|
|
10154
|
-
for (let i = 0; i < str.length; i++) {
|
|
10155
|
-
hash = (hash << 5) - hash + str.charCodeAt(i) | 0;
|
|
10156
|
-
}
|
|
10157
|
-
return hash >>> 0;
|
|
10158
|
-
}
|
|
10159
|
-
|
|
10160
10151
|
// src/core/documentAPI.ts
|
|
10161
10152
|
var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
10162
10153
|
indices = {};
|
|
@@ -10322,7 +10313,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10322
10313
|
tokens = tokenize(v, indexConfig);
|
|
10323
10314
|
}
|
|
10324
10315
|
const batchInsertData = [];
|
|
10325
|
-
for (
|
|
10316
|
+
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
10317
|
+
const token = tokens[i];
|
|
10326
10318
|
const keyToInsert = isFts ? this.getTokenKey(k, token) : k;
|
|
10327
10319
|
const entry = { k, v: token };
|
|
10328
10320
|
batchInsertData.push([keyToInsert, entry]);
|
|
@@ -10387,25 +10379,24 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10387
10379
|
const data = JSON.parse(row);
|
|
10388
10380
|
return data.magicString === "document-dataply" && data.version === 1;
|
|
10389
10381
|
}
|
|
10382
|
+
flatten(obj, parentKey = "", result = {}) {
|
|
10383
|
+
for (const key in obj) {
|
|
10384
|
+
const newKey = parentKey ? `${parentKey}.${key}` : key;
|
|
10385
|
+
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
10386
|
+
this.flatten(obj[key], newKey, result);
|
|
10387
|
+
} else {
|
|
10388
|
+
result[newKey] = obj[key];
|
|
10389
|
+
}
|
|
10390
|
+
}
|
|
10391
|
+
return result;
|
|
10392
|
+
}
|
|
10390
10393
|
/**
|
|
10391
10394
|
* returns flattened document
|
|
10392
10395
|
* @param document
|
|
10393
10396
|
* @returns
|
|
10394
10397
|
*/
|
|
10395
10398
|
flattenDocument(document) {
|
|
10396
|
-
|
|
10397
|
-
const flatten = (obj, parentKey = "") => {
|
|
10398
|
-
for (const key in obj) {
|
|
10399
|
-
const newKey = parentKey ? `${parentKey}.${key}` : key;
|
|
10400
|
-
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
10401
|
-
flatten(obj[key], newKey);
|
|
10402
|
-
} else {
|
|
10403
|
-
result[newKey] = obj[key];
|
|
10404
|
-
}
|
|
10405
|
-
}
|
|
10406
|
-
};
|
|
10407
|
-
flatten(document);
|
|
10408
|
-
return result;
|
|
10399
|
+
return this.flatten(document, "", {});
|
|
10409
10400
|
}
|
|
10410
10401
|
async getDocumentMetadata(tx) {
|
|
10411
10402
|
const metadata = await this.getMetadata(tx);
|
|
@@ -10533,21 +10524,21 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10533
10524
|
return { verySmallChunkSize, smallChunkSize };
|
|
10534
10525
|
}
|
|
10535
10526
|
getTokenKey(pk, token) {
|
|
10536
|
-
return
|
|
10527
|
+
return pk + ":" + token;
|
|
10537
10528
|
}
|
|
10538
10529
|
async applyCandidateByFTS(candidate, matchedTokens, filterValues, order) {
|
|
10539
10530
|
const keys = /* @__PURE__ */ new Set();
|
|
10540
|
-
for (
|
|
10531
|
+
for (let i = 0, len = matchedTokens.length; i < len; i++) {
|
|
10532
|
+
const token = matchedTokens[i];
|
|
10541
10533
|
const pairs = await candidate.tree.where(
|
|
10542
10534
|
{ primaryEqual: { v: token } },
|
|
10543
|
-
{
|
|
10544
|
-
|
|
10545
|
-
for (const c of pairs.values()) {
|
|
10546
|
-
if (!c || typeof c.k !== "number") continue;
|
|
10547
|
-
const dpk = c.k;
|
|
10548
|
-
if (filterValues === void 0 || filterValues.has(dpk)) {
|
|
10549
|
-
keys.add(dpk);
|
|
10535
|
+
{
|
|
10536
|
+
order
|
|
10550
10537
|
}
|
|
10538
|
+
);
|
|
10539
|
+
for (const pair of pairs.values()) {
|
|
10540
|
+
if (filterValues && !filterValues.has(pair.k)) continue;
|
|
10541
|
+
keys.add(pair.k);
|
|
10551
10542
|
}
|
|
10552
10543
|
}
|
|
10553
10544
|
return keys;
|
|
@@ -10580,7 +10571,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10580
10571
|
const useIndexOrder = orderBy === void 0 || driver.field === orderBy;
|
|
10581
10572
|
const candidates = [driver, ...others];
|
|
10582
10573
|
let keys = void 0;
|
|
10583
|
-
for (
|
|
10574
|
+
for (let i = 0, len = candidates.length; i < len; i++) {
|
|
10575
|
+
const candidate = candidates[i];
|
|
10584
10576
|
const currentOrder = useIndexOrder ? sortOrder : void 0;
|
|
10585
10577
|
if (candidate.isFtsMatch && candidate.matchTokens && candidate.matchTokens.length > 0) {
|
|
10586
10578
|
keys = await this.applyCandidateByFTS(
|
|
@@ -10631,7 +10623,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10631
10623
|
if (isFts) {
|
|
10632
10624
|
tokens = tokenize(v, indexConfig);
|
|
10633
10625
|
}
|
|
10634
|
-
for (
|
|
10626
|
+
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
10627
|
+
const token = tokens[i];
|
|
10635
10628
|
const keyToInsert = isFts ? this.getTokenKey(dpk, token) : dpk;
|
|
10636
10629
|
const [error] = await catchPromise(tree.insert(keyToInsert, { k: dpk, v: token }));
|
|
10637
10630
|
if (error) {
|
|
@@ -10685,7 +10678,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10685
10678
|
if (isFts) {
|
|
10686
10679
|
tokens = tokenize(v, indexConfig);
|
|
10687
10680
|
}
|
|
10688
|
-
for (
|
|
10681
|
+
for (let j = 0, len2 = tokens.length; j < len2; j++) {
|
|
10682
|
+
const token = tokens[j];
|
|
10689
10683
|
const keyToInsert = isFts ? this.getTokenKey(item.pk, token) : item.pk;
|
|
10690
10684
|
batchInsertData.push([keyToInsert, { k: item.pk, v: token }]);
|
|
10691
10685
|
}
|
|
@@ -10736,7 +10730,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10736
10730
|
if (isFts && typeof oldV === "string") {
|
|
10737
10731
|
oldTokens = tokenize(oldV, indexConfig);
|
|
10738
10732
|
}
|
|
10739
|
-
for (
|
|
10733
|
+
for (let j = 0, len2 = oldTokens.length; j < len2; j++) {
|
|
10734
|
+
const oldToken = oldTokens[j];
|
|
10740
10735
|
const keyToDelete = isFts ? this.getTokenKey(pk, oldToken) : pk;
|
|
10741
10736
|
await treeTx.delete(keyToDelete, { k: pk, v: oldToken });
|
|
10742
10737
|
}
|
|
@@ -10747,7 +10742,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10747
10742
|
newTokens = tokenize(newV, indexConfig);
|
|
10748
10743
|
}
|
|
10749
10744
|
const batchInsertData = [];
|
|
10750
|
-
for (
|
|
10745
|
+
for (let j = 0, len2 = newTokens.length; j < len2; j++) {
|
|
10746
|
+
const newToken = newTokens[j];
|
|
10751
10747
|
const keyToInsert = isFts ? this.getTokenKey(pk, newToken) : pk;
|
|
10752
10748
|
batchInsertData.push([keyToInsert, { k: pk, v: newToken }]);
|
|
10753
10749
|
}
|
|
@@ -10825,7 +10821,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10825
10821
|
if (isFts) {
|
|
10826
10822
|
tokens = tokenize(v, indexConfig);
|
|
10827
10823
|
}
|
|
10828
|
-
for (
|
|
10824
|
+
for (let j = 0, len2 = tokens.length; j < len2; j++) {
|
|
10825
|
+
const token = tokens[j];
|
|
10829
10826
|
const keyToDelete = isFts ? this.getTokenKey(pk, token) : pk;
|
|
10830
10827
|
await tree.delete(keyToDelete, { k: pk, v: token });
|
|
10831
10828
|
}
|
|
@@ -10852,10 +10849,13 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10852
10849
|
* FTS 조건에 대해 문서가 유효한지 검증합니다.
|
|
10853
10850
|
*/
|
|
10854
10851
|
verifyFts(doc, ftsConditions) {
|
|
10855
|
-
|
|
10856
|
-
|
|
10852
|
+
const flatDoc = this.flattenDocument(doc);
|
|
10853
|
+
for (let i = 0, len = ftsConditions.length; i < len; i++) {
|
|
10854
|
+
const { field, matchTokens } = ftsConditions[i];
|
|
10855
|
+
const docValue = flatDoc[field];
|
|
10857
10856
|
if (typeof docValue !== "string") return false;
|
|
10858
|
-
for (
|
|
10857
|
+
for (let j = 0, jLen = matchTokens.length; j < jLen; j++) {
|
|
10858
|
+
const token = matchTokens[j];
|
|
10859
10859
|
if (!docValue.includes(token)) return false;
|
|
10860
10860
|
}
|
|
10861
10861
|
}
|
|
@@ -10899,8 +10899,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10899
10899
|
if (!s) continue;
|
|
10900
10900
|
const doc = JSON.parse(s);
|
|
10901
10901
|
chunkTotalSize += s.length * 2;
|
|
10902
|
-
if (!this.verifyFts(doc, ftsConditions)) continue;
|
|
10903
|
-
yield
|
|
10902
|
+
if (ftsConditions.length > 0 && !this.verifyFts(doc, ftsConditions)) continue;
|
|
10903
|
+
yield doc;
|
|
10904
10904
|
}
|
|
10905
10905
|
currentChunkSize = this.adjustChunkSize(currentChunkSize, chunkTotalSize);
|
|
10906
10906
|
}
|
|
@@ -10962,7 +10962,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10962
10962
|
});
|
|
10963
10963
|
}
|
|
10964
10964
|
const results = [];
|
|
10965
|
-
for await (const
|
|
10965
|
+
for await (const doc of self.processChunkedKeys(
|
|
10966
10966
|
keys,
|
|
10967
10967
|
0,
|
|
10968
10968
|
self.options.pageSize,
|
|
@@ -10998,7 +10998,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10998
10998
|
}
|
|
10999
10999
|
} else {
|
|
11000
11000
|
let yieldedCount = 0;
|
|
11001
|
-
for await (const
|
|
11001
|
+
for await (const doc of self.processChunkedKeys(
|
|
11002
11002
|
keys,
|
|
11003
11003
|
offset,
|
|
11004
11004
|
self.options.pageSize,
|
|
@@ -5,7 +5,7 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON, IC extends Index
|
|
|
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'];
|
|
8
|
-
readonly trees: Map<string, BPTreeAsync<number, DataplyTreeValue<Primitive>>>;
|
|
8
|
+
readonly trees: Map<string, BPTreeAsync<string | number, DataplyTreeValue<Primitive>>>;
|
|
9
9
|
readonly comparator: DocumentValueComparator<DataplyTreeValue<Primitive>, Primitive>;
|
|
10
10
|
private pendingBackfillFields;
|
|
11
11
|
private readonly lock;
|
|
@@ -26,6 +26,7 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON, IC extends Index
|
|
|
26
26
|
createDocumentInnerMetadata(indices: DocumentDataplyInnerMetadata['indices']): DocumentDataplyInnerMetadata;
|
|
27
27
|
initializeDocumentFile(tx: Transaction): Promise<void>;
|
|
28
28
|
verifyDocumentFile(tx: Transaction): Promise<boolean>;
|
|
29
|
+
private flatten;
|
|
29
30
|
/**
|
|
30
31
|
* returns flattened document
|
|
31
32
|
* @param document
|
|
@@ -48,20 +49,30 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON, IC extends Index
|
|
|
48
49
|
* @returns Driver and other candidates for query execution
|
|
49
50
|
*/
|
|
50
51
|
getSelectivityCandidate<U extends Partial<DocumentDataplyIndexedQuery<T, IC>>, V extends DataplyTreeValue<U>>(query: Partial<DocumentDataplyQuery<V>>, orderByField?: string): Promise<{
|
|
51
|
-
driver: {
|
|
52
|
+
driver: ({
|
|
52
53
|
tree: BPTreeAsync<number, V>;
|
|
53
54
|
condition: Partial<DocumentDataplyCondition<U>>;
|
|
54
55
|
field: string;
|
|
55
|
-
isFtsMatch
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
isFtsMatch: false;
|
|
57
|
+
} | {
|
|
58
|
+
tree: BPTreeAsync<string, V>;
|
|
59
|
+
condition: Partial<DocumentDataplyCondition<U>>;
|
|
60
|
+
field: string;
|
|
61
|
+
isFtsMatch: true;
|
|
62
|
+
matchTokens: string[];
|
|
63
|
+
});
|
|
64
|
+
others: ({
|
|
59
65
|
tree: BPTreeAsync<number, V>;
|
|
60
66
|
condition: Partial<DocumentDataplyCondition<U>>;
|
|
61
67
|
field: string;
|
|
62
|
-
isFtsMatch
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
isFtsMatch: false;
|
|
69
|
+
} | {
|
|
70
|
+
tree: BPTreeAsync<string, V>;
|
|
71
|
+
condition: Partial<DocumentDataplyCondition<U>>;
|
|
72
|
+
field: string;
|
|
73
|
+
isFtsMatch: true;
|
|
74
|
+
matchTokens: string[];
|
|
75
|
+
})[];
|
|
65
76
|
rollback: () => void;
|
|
66
77
|
} | null>;
|
|
67
78
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-dataply",
|
|
3
|
-
"version": "0.0.7
|
|
3
|
+
"version": "0.0.7",
|
|
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,11 +42,11 @@
|
|
|
42
42
|
"dataply"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"dataply": "^0.0.23
|
|
45
|
+
"dataply": "^0.0.23"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/jest": "^30.0.0",
|
|
49
|
-
"esbuild": "^0.27.
|
|
49
|
+
"esbuild": "^0.27.3",
|
|
50
50
|
"jest": "^30.2.0",
|
|
51
51
|
"ts-jest": "^29.4.6",
|
|
52
52
|
"typescript": "^5.9.3"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function fastStringHash(str: string): number;
|