document-dataply 0.0.7-alpha.2 → 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 CHANGED
@@ -10313,7 +10313,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10313
10313
  tokens = tokenize(v, indexConfig);
10314
10314
  }
10315
10315
  const batchInsertData = [];
10316
- for (const token of tokens) {
10316
+ for (let i = 0, len = tokens.length; i < len; i++) {
10317
+ const token = tokens[i];
10317
10318
  const keyToInsert = isFts ? this.getTokenKey(k, token) : k;
10318
10319
  const entry = { k, v: token };
10319
10320
  batchInsertData.push([keyToInsert, entry]);
@@ -10378,25 +10379,24 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10378
10379
  const data = JSON.parse(row);
10379
10380
  return data.magicString === "document-dataply" && data.version === 1;
10380
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
+ }
10381
10393
  /**
10382
10394
  * returns flattened document
10383
10395
  * @param document
10384
10396
  * @returns
10385
10397
  */
10386
10398
  flattenDocument(document) {
10387
- const result = {};
10388
- const flatten = (obj, parentKey = "") => {
10389
- for (const key in obj) {
10390
- const newKey = parentKey ? `${parentKey}.${key}` : key;
10391
- if (typeof obj[key] === "object" && obj[key] !== null) {
10392
- flatten(obj[key], newKey);
10393
- } else {
10394
- result[newKey] = obj[key];
10395
- }
10396
- }
10397
- };
10398
- flatten(document);
10399
- return result;
10399
+ return this.flatten(document, "", {});
10400
10400
  }
10401
10401
  async getDocumentMetadata(tx) {
10402
10402
  const metadata = await this.getMetadata(tx);
@@ -10528,17 +10528,17 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10528
10528
  }
10529
10529
  async applyCandidateByFTS(candidate, matchedTokens, filterValues, order) {
10530
10530
  const keys = /* @__PURE__ */ new Set();
10531
- for (const token of matchedTokens) {
10531
+ for (let i = 0, len = matchedTokens.length; i < len; i++) {
10532
+ const token = matchedTokens[i];
10532
10533
  const pairs = await candidate.tree.where(
10533
10534
  { primaryEqual: { v: token } },
10534
- { order }
10535
- );
10536
- for (const c of pairs.values()) {
10537
- if (!c || typeof c.k !== "number") continue;
10538
- const dpk = c.k;
10539
- if (filterValues === void 0 || filterValues.has(dpk)) {
10540
- keys.add(dpk);
10535
+ {
10536
+ order
10541
10537
  }
10538
+ );
10539
+ for (const pair of pairs.values()) {
10540
+ if (filterValues && !filterValues.has(pair.k)) continue;
10541
+ keys.add(pair.k);
10542
10542
  }
10543
10543
  }
10544
10544
  return keys;
@@ -10571,7 +10571,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10571
10571
  const useIndexOrder = orderBy === void 0 || driver.field === orderBy;
10572
10572
  const candidates = [driver, ...others];
10573
10573
  let keys = void 0;
10574
- for (const candidate of candidates) {
10574
+ for (let i = 0, len = candidates.length; i < len; i++) {
10575
+ const candidate = candidates[i];
10575
10576
  const currentOrder = useIndexOrder ? sortOrder : void 0;
10576
10577
  if (candidate.isFtsMatch && candidate.matchTokens && candidate.matchTokens.length > 0) {
10577
10578
  keys = await this.applyCandidateByFTS(
@@ -10622,7 +10623,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10622
10623
  if (isFts) {
10623
10624
  tokens = tokenize(v, indexConfig);
10624
10625
  }
10625
- for (const token of tokens) {
10626
+ for (let i = 0, len = tokens.length; i < len; i++) {
10627
+ const token = tokens[i];
10626
10628
  const keyToInsert = isFts ? this.getTokenKey(dpk, token) : dpk;
10627
10629
  const [error] = await catchPromise(tree.insert(keyToInsert, { k: dpk, v: token }));
10628
10630
  if (error) {
@@ -10676,7 +10678,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10676
10678
  if (isFts) {
10677
10679
  tokens = tokenize(v, indexConfig);
10678
10680
  }
10679
- for (const token of tokens) {
10681
+ for (let j = 0, len2 = tokens.length; j < len2; j++) {
10682
+ const token = tokens[j];
10680
10683
  const keyToInsert = isFts ? this.getTokenKey(item.pk, token) : item.pk;
10681
10684
  batchInsertData.push([keyToInsert, { k: item.pk, v: token }]);
10682
10685
  }
@@ -10727,7 +10730,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10727
10730
  if (isFts && typeof oldV === "string") {
10728
10731
  oldTokens = tokenize(oldV, indexConfig);
10729
10732
  }
10730
- for (const oldToken of oldTokens) {
10733
+ for (let j = 0, len2 = oldTokens.length; j < len2; j++) {
10734
+ const oldToken = oldTokens[j];
10731
10735
  const keyToDelete = isFts ? this.getTokenKey(pk, oldToken) : pk;
10732
10736
  await treeTx.delete(keyToDelete, { k: pk, v: oldToken });
10733
10737
  }
@@ -10738,7 +10742,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10738
10742
  newTokens = tokenize(newV, indexConfig);
10739
10743
  }
10740
10744
  const batchInsertData = [];
10741
- for (const newToken of newTokens) {
10745
+ for (let j = 0, len2 = newTokens.length; j < len2; j++) {
10746
+ const newToken = newTokens[j];
10742
10747
  const keyToInsert = isFts ? this.getTokenKey(pk, newToken) : pk;
10743
10748
  batchInsertData.push([keyToInsert, { k: pk, v: newToken }]);
10744
10749
  }
@@ -10816,7 +10821,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10816
10821
  if (isFts) {
10817
10822
  tokens = tokenize(v, indexConfig);
10818
10823
  }
10819
- for (const token of tokens) {
10824
+ for (let j = 0, len2 = tokens.length; j < len2; j++) {
10825
+ const token = tokens[j];
10820
10826
  const keyToDelete = isFts ? this.getTokenKey(pk, token) : pk;
10821
10827
  await tree.delete(keyToDelete, { k: pk, v: token });
10822
10828
  }
@@ -10843,10 +10849,13 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10843
10849
  * FTS 조건에 대해 문서가 유효한지 검증합니다.
10844
10850
  */
10845
10851
  verifyFts(doc, ftsConditions) {
10846
- for (const { field, matchTokens } of ftsConditions) {
10847
- const docValue = this.flattenDocument(doc)[field];
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];
10848
10856
  if (typeof docValue !== "string") return false;
10849
- for (const token of matchTokens) {
10857
+ for (let j = 0, jLen = matchTokens.length; j < jLen; j++) {
10858
+ const token = matchTokens[j];
10850
10859
  if (!docValue.includes(token)) return false;
10851
10860
  }
10852
10861
  }
@@ -10890,8 +10899,8 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10890
10899
  if (!s) continue;
10891
10900
  const doc = JSON.parse(s);
10892
10901
  chunkTotalSize += s.length * 2;
10893
- if (!this.verifyFts(doc, ftsConditions)) continue;
10894
- yield { doc, rawSize: s.length * 2 };
10902
+ if (ftsConditions.length > 0 && !this.verifyFts(doc, ftsConditions)) continue;
10903
+ yield doc;
10895
10904
  }
10896
10905
  currentChunkSize = this.adjustChunkSize(currentChunkSize, chunkTotalSize);
10897
10906
  }
@@ -10953,7 +10962,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10953
10962
  });
10954
10963
  }
10955
10964
  const results = [];
10956
- for await (const { doc } of self.processChunkedKeys(
10965
+ for await (const doc of self.processChunkedKeys(
10957
10966
  keys,
10958
10967
  0,
10959
10968
  self.options.pageSize,
@@ -10989,7 +10998,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10989
10998
  }
10990
10999
  } else {
10991
11000
  let yieldedCount = 0;
10992
- for await (const { doc } of self.processChunkedKeys(
11001
+ for await (const doc of self.processChunkedKeys(
10993
11002
  keys,
10994
11003
  offset,
10995
11004
  self.options.pageSize,
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-dataply",
3
- "version": "0.0.7-alpha.2",
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-alpha.2"
45
+ "dataply": "^0.0.23"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/jest": "^30.0.0",
49
- "esbuild": "^0.27.2",
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;