datafolder 1.0.17 → 1.0.19

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.
@@ -1,18 +1,14 @@
1
1
  import { QyOpRunner } from "./QyOpRunner.ts";
2
2
  export declare class QyBinWriter extends QyOpRunner {
3
- _filePath: any;
4
- _totalSavedSize: number;
3
+ filePath: any;
4
+ totalSavedSize: number;
5
5
  fileHandle: any;
6
- constructor(options?: any, filePath?: any);
7
- get filePath(): any;
8
- set filePath(val: any);
9
- get totalSavedSize(): number;
10
- set totalSavedSize(val: number);
11
- save(changeId: any, data: any, needPromise: any): any;
6
+ constructor(options?: any, filePath?: any, callOpNameList?: any, castOpNameList?: any);
7
+ save(changeId: any, data?: any, needPromise?: any): any;
12
8
  truncate(): any;
13
9
  switch(newFilePath: any): any;
14
10
  getBinData(dataQueue: any[], changeId?: undefined): any;
15
- _op_start(filePath: any): Promise<this>;
11
+ _op_start(filePath?: any): Promise<this>;
16
12
  _op_stop(): Promise<void>;
17
13
  _op_save(changeId: any, dataQueue: any): Promise<void> | undefined;
18
14
  _op_truncate(): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import {
2
- open as s
2
+ open as n
3
3
  } from "node:fs/promises";
4
4
 
5
5
  import {
@@ -7,16 +7,18 @@ import {
7
7
  } from "./QyOpRunner.js";
8
8
 
9
9
  import {
10
- ensureParentDir as n,
11
- getSize as o,
10
+ ensureParentDir as l,
11
+ getSize as f,
12
12
  getSizeStr as v,
13
13
  sleep as _,
14
- setPromise as l,
15
- toBuffer as S
14
+ setPromise as s,
15
+ toBuffer as S,
16
+ folderOrFileExists as p,
17
+ isString as r
16
18
  } from "./QyUtils.js";
17
19
 
18
20
  import {
19
- getDefaultOptions as a
21
+ getDefaultOptions as o
20
22
  } from "./QyDefaultOptions.js";
21
23
 
22
24
  import {
@@ -24,32 +26,20 @@ import {
24
26
  } from "./QyLogger.js";
25
27
 
26
28
  class e extends t {
27
- _filePath;
28
- _totalSavedSize = 0;
29
+ filePath;
30
+ totalSavedSize = 0;
29
31
  fileHandle;
30
- constructor(t = void 0, e = void 0) {
31
- super({
32
- ...a("QyBinWriter"),
32
+ constructor(t = void 0, e = void 0, a = void 0, i = void 0) {
33
+ r(t) && ([ e, t ] = [ t, void 0 ]), super({
34
+ ...o("QyBinWriter"),
33
35
  ...t
34
- }), this.filePath = e, f(this);
36
+ }, a, i), this.filePath = e, h(this);
35
37
  }
36
- get filePath() {
37
- return this._filePath;
38
- }
39
- set filePath(t) {
40
- this._filePath = t;
41
- }
42
- get totalSavedSize() {
43
- return this._totalSavedSize;
44
- }
45
- set totalSavedSize(t) {
46
- this._totalSavedSize = t;
47
- }
48
- save(t, e, a) {
38
+ save(t, e = void 0, a = !1) {
49
39
  null == e && ([ e, t ] = [ t, 0 ]);
50
40
  var i, r = this.lastOp;
51
41
  return "_op_save" === r?.opFunName ? (i = r.args, i[0] = t, i[1].push(e),
52
- a && l(r), r.promise) : (i = {
42
+ a && s(r), r.promise) : (i = {
53
43
  opFunName: "_op_save",
54
44
  args: [ t, [ e ] ]
55
45
  }, a ? this.pushAndRunWithPromise(i) : this.pushAndRun(i));
@@ -71,7 +61,7 @@ class e extends t {
71
61
  var a = (t = t.flat()).length;
72
62
  return 0 == a ? "" : 1 == a ? t[0] : Buffer.isBuffer(t[0]) ? Buffer.concat(t) : Buffer.concat(t.map(t => Buffer.from(t)));
73
63
  }
74
- async _op_start(t) {
64
+ async _op_start(t = void 0) {
75
65
  return await i(this, t = t || this.filePath), this;
76
66
  }
77
67
  async _op_stop() {
@@ -84,7 +74,7 @@ class e extends t {
84
74
  } catch (t) {
85
75
  g.error(`Close ${e} failed:`, t);
86
76
  }
87
- f(this);
77
+ h(this);
88
78
  }
89
79
  _op_save(t, e) {
90
80
  e = this.getBinData(e, t);
@@ -93,24 +83,22 @@ class e extends t {
93
83
  fileHandle: i,
94
84
  totalSavedSize: r,
95
85
  filePath: s,
96
- options: n
86
+ options: o
97
87
  } = t, {
98
- emitSaveEvent: o,
88
+ emitSaveEvent: n,
99
89
  maxFileSize: l,
100
90
  maxRetryInterval: f,
101
- retryIntervalFactor: h
102
- } = n, p = S(a), u = p.length, c = `size ${v(u)} (MaxId:${e}) to ` + s, d;
91
+ retryIntervalFactor: p
92
+ } = o, h = S(a), u = h.length, d = `size ${v(u)} (MaxId:${e}) to ` + s, c;
103
93
  for (;"_op_truncate" !== t.firstOp?.opFunName; ) try {
104
- await i.appendFile(p, {
105
- flush: !0
106
- });
94
+ await i.write(h, 0, h.byteLength, r);
107
95
  var m = t.totalSavedSize = r + u;
108
- return o && 0 < e && t.emit("save", e), void (!t.maxFileSizeEmitted && l && m > l && (t.maxFileSizeEmitted = !0,
96
+ return n && 0 < e && t.emit("save", e), void (!t.maxFileSizeEmitted && l && m > l && (t.maxFileSizeEmitted = !0,
109
97
  t.emit("maxFileSize", m)));
110
98
  } catch (t) {
111
- g.error(`Saving ${c} failed:`, t, "Truncated back to " + r), await i.truncate(r),
112
- d = d ? Math.min(f, d * h) : 1, g.log(`Retry in ${d} seconds`),
113
- await _(d);
99
+ g.error(`Saving ${d} failed:`, t, "Truncated back to " + r), await i.truncate(r),
100
+ c = c ? Math.min(f, c * p) : 1, g.log(`Retry in ${c} seconds`),
101
+ await _(c);
114
102
  }
115
103
  })(this, t, e);
116
104
  }
@@ -124,7 +112,7 @@ class e extends t {
124
112
  } catch (t) {
125
113
  g.error(`Truncate ${e} failed:`, t);
126
114
  }
127
- f(this);
115
+ h(this);
128
116
  }
129
117
  async _op_switch(t) {
130
118
  var {
@@ -140,17 +128,20 @@ async function i(t, e) {
140
128
  fileHandle: a,
141
129
  options: i
142
130
  } = t;
143
- f(t);
131
+ h(t);
144
132
  try {
145
- a && (a.close(), t.fileHandle = void 0), await n(e);
146
- var r = i.append;
147
- t.fileHandle = await s(e, r ? "a" : "w"), t.filePath = e, r && (t.totalSavedSize = await o(e));
133
+ a && (a.close(), t.fileHandle = void 0), await l(e), t.filePath = e;
134
+ var {
135
+ append: r,
136
+ read: s
137
+ } = i, o = r && await p(e) ? "r+" : s ? "w+" : "w";
138
+ t.fileHandle = await n(e, o), r && (t.totalSavedSize = await f(e));
148
139
  } catch (t) {
149
140
  g.error(`Open ${e} failed:`, t);
150
141
  }
151
142
  }
152
143
 
153
- function f(t) {
144
+ function h(t) {
154
145
  Object.assign(t, {
155
146
  totalSavedSize: 0,
156
147
  maxFileSizeEmitted: !1
@@ -0,0 +1,10 @@
1
+ export declare class QyBinaryHeap {
2
+ items: any[];
3
+ cmpFun: any;
4
+ constructor(cmpFun?: (x: any, y: any) => number);
5
+ get size(): number;
6
+ get isEmpty(): boolean;
7
+ peek(): any;
8
+ push(item: any): void;
9
+ pop(): any;
10
+ }
@@ -0,0 +1,55 @@
1
+ class t {
2
+ items = [];
3
+ cmpFun;
4
+ constructor(t = (t, e) => t - e) {
5
+ this.cmpFun = t;
6
+ }
7
+ get size() {
8
+ return this.items.length;
9
+ }
10
+ get isEmpty() {
11
+ return 0 == this.items.length;
12
+ }
13
+ peek() {
14
+ return this.items[0];
15
+ }
16
+ push(t) {
17
+ var e = this.items;
18
+ e.push(t), i(this);
19
+ }
20
+ pop() {
21
+ if (!this.isEmpty) {
22
+ for (var t = this.items, e = t[0], [ t, i = 0 ] = (t[0] = t.at(-1),
23
+ --t.length, [ this ]), {
24
+ items: s,
25
+ cmpFun: r
26
+ } = t, h = s.length; i < h; ) {
27
+ var n = 2 * i + 1;
28
+ if (!(n < h)) break;
29
+ {
30
+ let t = i;
31
+ 0 < r(s[n], s[t]) && (t = n);
32
+ n = 1 + n;
33
+ if ((t = n < h && 0 < r(s[n], s[t]) ? n : t) == i) break;
34
+ [ s[i], s[t] ] = [ s[t], s[i] ], i = t;
35
+ }
36
+ }
37
+ return e;
38
+ }
39
+ }
40
+ }
41
+
42
+ function i(t, e = t.items.length - 1) {
43
+ for (var {
44
+ items: i,
45
+ cmpFun: s
46
+ } = t; 0 < e; ) {
47
+ var r = Math.floor((e - 1) / 2);
48
+ if (!(0 < s(i[e], i[r]))) break;
49
+ [ i[e], i[r] ] = [ i[r], i[e] ], e = r;
50
+ }
51
+ }
52
+
53
+ export {
54
+ t as QyBinaryHeap
55
+ };
package/src/QyCD.d.ts CHANGED
@@ -13,6 +13,9 @@ export declare class QyCD {
13
13
  indexDirP(indexHostDirNamePath: string | string[] | QyDir, namePath: string | string[], parentDir?: any): QyDir | undefined;
14
14
  file(namePath: string | string[], parentDir?: any): QyFile | undefined;
15
15
  fileP(namePath: string | string[], parentDir?: any): QyFile | undefined;
16
+ fileContent(namePath: string | string[], parentDir?: any): any;
17
+ infoFile(namePath: string | string[], parentDir?: any): any;
18
+ embedding(namePath: string | string[], parentDir?: any): any;
16
19
  triggerFile(triggerName: any): any;
17
20
  get triggerFileList(): any;
18
21
  rpcFile(rpcName: any): any;
package/src/QyCD.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
- isString as t,
3
- pathSplit as s
2
+ isString as i,
3
+ pathSplit as n
4
4
  } from "./QyUtils.js";
5
5
 
6
6
  class r {
@@ -10,32 +10,45 @@ class r {
10
10
  this.qyCache = r;
11
11
  }
12
12
  cd(r, e = this.currentDir) {
13
- return t(r) && (r = s(r)), this.cdP(r, e);
13
+ return i(r) && (r = n(r)), this.cdP(r, e);
14
14
  }
15
15
  cdP(r, e = this.currentDir) {
16
- return this.currentDir = this.qyCache?.getOrCreateDir(r, e), this;
16
+ return this.currentDir = this.qyCache.getOrCreateDir(r, e), this;
17
17
  }
18
18
  dir(r, e = this.currentDir) {
19
- return t(r) && (r = s(r)), this.dirP(r, e);
19
+ return i(r) && (r = n(r)), this.dirP(r, e);
20
20
  }
21
21
  dirP(r, e = this.currentDir) {
22
- return this.qyCache?.getDir(r, e);
22
+ return this.qyCache.getDir(r, e);
23
23
  }
24
- indexDir(r, e, i = this.currentDir) {
25
- return t(r) && (r = s(r)), t(e) && (e = s(e)), this.indexDirP(r, e, i);
24
+ indexDir(r, e, t = this.currentDir) {
25
+ return i(r) && (r = n(r)), i(e) && (e = n(e)), this.indexDirP(r, e, t);
26
26
  }
27
- indexDirP(r, e, i = this.currentDir) {
28
- var t = this.qyCache, r = t?.getDir(r, i);
27
+ indexDirP(r, e, t = this.currentDir) {
28
+ var i = this.qyCache, r = i.getDir(r, t);
29
29
  if (r) {
30
- i = t?.getIndexDir(r);
31
- if (i) return e && 0 != e.length ? t?.getDir(e, i) : i;
30
+ t = i.getIndexDir(r);
31
+ if (t) return e && 0 != e.length ? i.getDir(e, t) : t;
32
32
  }
33
33
  }
34
34
  file(r, e = this.currentDir) {
35
- return t(r) && (r = s(r)), this.fileP(r, e);
35
+ return i(r) && (r = n(r)), this.fileP(r, e);
36
36
  }
37
37
  fileP(r, e = this.currentDir) {
38
- return this.qyCache?.getFile(r, e);
38
+ return this.qyCache.getFile(r, e);
39
+ }
40
+ fileContent(r, e = this.currentDir) {
41
+ return this.file(r, e)?.fileContent;
42
+ }
43
+ infoFile(r, e = this.currentDir) {
44
+ i(r) && (r = n(r));
45
+ var t = this.qyCache;
46
+ return t.getInfoFile(t.getOrCreateFile(r, e));
47
+ }
48
+ embedding(r, e = this.currentDir) {
49
+ i(r) && (r = n(r));
50
+ var t = this.qyCache, r = t.getOrCreateFile(r, e);
51
+ return t.getEmbedding(r);
39
52
  }
40
53
  triggerFile(r) {
41
54
  return this.qyCache.getTriggerFile(r);
@@ -49,55 +62,55 @@ class r {
49
62
  get rpcFileList() {
50
63
  return this.qyCache.rpcFileList;
51
64
  }
52
- view(r, e = void 0, i = this.currentDir) {
53
- return t(r) && (r = s(r)), this.viewP(r, e, i);
65
+ view(r, e = void 0, t = this.currentDir) {
66
+ return i(r) && (r = n(r)), this.viewP(r, e, t);
54
67
  }
55
- viewP(r, e, i = this.currentDir) {
56
- return this.qyCache.getFile(r, i)?.view(e);
68
+ viewP(r, e, t = this.currentDir) {
69
+ return this.qyCache.getFile(r, t)?.view(e);
57
70
  }
58
- queryFiles(r, e, i = void 0, t = void 0, s = this.currentDir) {
59
- return this.qyCache.queryFiles(r, e, i, t, s);
71
+ queryFiles(r, e, t = void 0, i = void 0, n = this.currentDir) {
72
+ return this.qyCache.queryFiles(r, e, t, i, n);
60
73
  }
61
- queryFilesMulti(r, e, i, t = this.currentDir) {
62
- return this.qyCache.queryFilesMulti(r, e, i, t);
74
+ queryFilesMulti(r, e, t, i = this.currentDir) {
75
+ return this.qyCache.queryFilesMulti(r, e, t, i);
63
76
  }
64
- queryTree(r, e, i, t, s, h = this.currentDir) {
65
- return n(this.qyCache.queryFiles(r, e, t, s, h), i);
77
+ queryTree(r, e, t, i, n, s = this.currentDir) {
78
+ return h(this.qyCache.queryFiles(r, e, i, n, s), t);
66
79
  }
67
- queryTreeMulti(r, e, i, t, s = this.currentDir) {
68
- return n(this.qyCache.queryFilesMulti(r, i, t, s), e);
80
+ queryTreeMulti(r, e, t, i, n = this.currentDir) {
81
+ return h(this.qyCache.queryFilesMulti(r, t, i, n), e);
69
82
  }
70
83
  resetCurrentDir() {
71
84
  this.currentDir = void 0;
72
85
  }
73
86
  fileListToTree(r, e) {
74
- return n(r, e);
87
+ return h(r, e);
75
88
  }
76
89
  }
77
90
 
78
- function n(r, i) {
79
- var t, s = {};
80
- for (t of r) {
81
- var h, n = t.parentList;
82
- let e = s;
83
- for (h of n) {
91
+ function h(r, t) {
92
+ var i, n = {};
93
+ for (i of r) {
94
+ var s, h = i.parentList;
95
+ let e = n;
96
+ for (s of h) {
84
97
  var {
85
98
  name: u,
86
99
  fullPathHash: c
87
- } = h;
100
+ } = s;
88
101
  let r = e.subdirMap;
89
102
  r = r || (e.subdirMap = {}), e = (e = r[u]) || (r[u] = {
90
103
  fullPathHash: c
91
104
  });
92
105
  }
93
106
  let r = e.fileMap;
94
- (r = r || (e.fileMap = {}))[t.name] = {
95
- fileContent: t.view(i, !0),
96
- fileContentKey: t.fileContentKey
107
+ (r = r || (e.fileMap = {}))[i.name] = {
108
+ fileContent: i.view(t, !0),
109
+ fileContentKey: i.fileContentKey
97
110
  };
98
111
  }
99
112
  return {
100
- tree: s,
113
+ tree: n,
101
114
  count: r.length
102
115
  };
103
116
  }
package/src/QyCache.d.ts CHANGED
@@ -12,9 +12,13 @@ export declare class QyCache extends EventEmitter {
12
12
  rpcRootDir: any;
13
13
  indexRootDir: any;
14
14
  expireRootDir: any;
15
+ hnswRootDir: any;
16
+ infoRootDir: any;
17
+ recycleRootDir: any;
15
18
  exclusiveFilePath: any;
16
19
  qyKVData: any;
17
20
  qyFileLogger: any;
21
+ qyEmbeddings: any;
18
22
  rpcFunMap: {};
19
23
  constructor(rootFolder: string, options?: any, qyDB?: any);
20
24
  start(): Promise<this>;
@@ -23,8 +27,8 @@ export declare class QyCache extends EventEmitter {
23
27
  decreaseChangeId(): void;
24
28
  save(changeId: any, cmdArgAsListObj: any, logText: any, syncList: any, needPromise: any): any;
25
29
  getFile(namePath: QyFile | string | string[], parentDir?: any): QyFile | undefined;
26
- getDir(namePath: QyDir | string | string[], parentDir?: any): QyDir | undefined;
27
30
  getOrCreateFile(namePath: QyFile | string | string[], parentDir?: any): QyFile;
31
+ getDir(namePath: QyDir | string | string[], parentDir?: any): QyDir | undefined;
28
32
  getOrCreateDir(namePath: QyDir | string | string[], parentDir?: any): QyDir;
29
33
  getIndexDir(indexHostDir: QyDir): any;
30
34
  getOrCreateIndexDir(indexHostDir: any): any;
@@ -32,6 +36,12 @@ export declare class QyCache extends EventEmitter {
32
36
  getOrCreateTriggerFile(triggerName: any): any;
33
37
  getExpireInfoFile(fullPathHash: any, type?: string): any;
34
38
  getOrCreateExpireInfoFile(fullPathHash: any, type?: string): any;
39
+ getInfoFile(srcFile: any): any;
40
+ getOrCreateInfoFile(srcFile: any): any;
41
+ hToSrcFile(fullPathHash: any): QyFile | undefined;
42
+ getEmbedding(srcFile: any): any;
43
+ getOrCreateRecycleFile(length: any): any;
44
+ getRecycleFile(length: any): any;
35
45
  get triggerFileList(): any;
36
46
  getRpcFile(rpcFunName: any): any;
37
47
  getOrCreateRpcFile(rpcFunName: any): any;