datafolder 1.0.18 → 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
package/src/QyCD.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare class QyCD {
14
14
  file(namePath: string | string[], parentDir?: any): QyFile | undefined;
15
15
  fileP(namePath: string | string[], parentDir?: any): QyFile | undefined;
16
16
  fileContent(namePath: string | string[], parentDir?: any): any;
17
- embeddingFile(namePath: string | string[], parentDir?: any): any;
17
+ infoFile(namePath: string | string[], parentDir?: any): any;
18
18
  embedding(namePath: string | string[], parentDir?: any): any;
19
19
  triggerFile(triggerName: any): any;
20
20
  get triggerFileList(): any;
package/src/QyCD.js CHANGED
@@ -1,118 +1,120 @@
1
1
  import {
2
- isString as t,
2
+ isString as i,
3
3
  pathSplit as n
4
4
  } from "./QyUtils.js";
5
5
 
6
- class e {
6
+ class r {
7
7
  qyCache;
8
8
  currentDir;
9
- constructor(e) {
10
- this.qyCache = e;
9
+ constructor(r) {
10
+ this.qyCache = r;
11
11
  }
12
- cd(e, r = this.currentDir) {
13
- return t(e) && (e = n(e)), this.cdP(e, r);
12
+ cd(r, e = this.currentDir) {
13
+ return i(r) && (r = n(r)), this.cdP(r, e);
14
14
  }
15
- cdP(e, r = this.currentDir) {
16
- return this.currentDir = this.qyCache.getOrCreateDir(e, r), this;
15
+ cdP(r, e = this.currentDir) {
16
+ return this.currentDir = this.qyCache.getOrCreateDir(r, e), this;
17
17
  }
18
- dir(e, r = this.currentDir) {
19
- return t(e) && (e = n(e)), this.dirP(e, r);
18
+ dir(r, e = this.currentDir) {
19
+ return i(r) && (r = n(r)), this.dirP(r, e);
20
20
  }
21
- dirP(e, r = this.currentDir) {
22
- return this.qyCache.getDir(e, r);
21
+ dirP(r, e = this.currentDir) {
22
+ return this.qyCache.getDir(r, e);
23
23
  }
24
- indexDir(e, r, i = this.currentDir) {
25
- return t(e) && (e = n(e)), t(r) && (r = n(r)), this.indexDirP(e, r, 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(e, r, i = this.currentDir) {
28
- var t = this.qyCache, e = t.getDir(e, i);
29
- if (e) {
30
- i = t.getIndexDir(e);
31
- if (i) return r && 0 != r.length ? t.getDir(r, i) : i;
27
+ indexDirP(r, e, t = this.currentDir) {
28
+ var i = this.qyCache, r = i.getDir(r, t);
29
+ if (r) {
30
+ t = i.getIndexDir(r);
31
+ if (t) return e && 0 != e.length ? i.getDir(e, t) : t;
32
32
  }
33
33
  }
34
- file(e, r = this.currentDir) {
35
- return t(e) && (e = n(e)), this.fileP(e, r);
34
+ file(r, e = this.currentDir) {
35
+ return i(r) && (r = n(r)), this.fileP(r, e);
36
36
  }
37
- fileP(e, r = this.currentDir) {
38
- return this.qyCache.getFile(e, r);
37
+ fileP(r, e = this.currentDir) {
38
+ return this.qyCache.getFile(r, e);
39
39
  }
40
- fileContent(e, r = this.currentDir) {
41
- return this.file(e, r)?.fileContent;
40
+ fileContent(r, e = this.currentDir) {
41
+ return this.file(r, e)?.fileContent;
42
42
  }
43
- embeddingFile(e, r = this.currentDir) {
44
- t(e) && (e = n(e));
45
- var i = this.qyCache;
46
- return i.getEmbeddingFile(i.getOrCreateFile(e, r).fullPathHash);
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
47
  }
48
- embedding(e, r = this.currentDir) {
49
- return this.embeddingFile(e, r)?.fileContent;
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);
50
52
  }
51
- triggerFile(e) {
52
- return this.qyCache.getTriggerFile(e);
53
+ triggerFile(r) {
54
+ return this.qyCache.getTriggerFile(r);
53
55
  }
54
56
  get triggerFileList() {
55
57
  return this.qyCache.triggerFileList;
56
58
  }
57
- rpcFile(e) {
58
- return this.qyCache.getRpcFile(e);
59
+ rpcFile(r) {
60
+ return this.qyCache.getRpcFile(r);
59
61
  }
60
62
  get rpcFileList() {
61
63
  return this.qyCache.rpcFileList;
62
64
  }
63
- view(e, r = void 0, i = this.currentDir) {
64
- return t(e) && (e = n(e)), this.viewP(e, r, i);
65
+ view(r, e = void 0, t = this.currentDir) {
66
+ return i(r) && (r = n(r)), this.viewP(r, e, t);
65
67
  }
66
- viewP(e, r, i = this.currentDir) {
67
- return this.qyCache.getFile(e, i)?.view(r);
68
+ viewP(r, e, t = this.currentDir) {
69
+ return this.qyCache.getFile(r, t)?.view(e);
68
70
  }
69
- queryFiles(e, r, i = void 0, t = void 0, n = this.currentDir) {
70
- return this.qyCache.queryFiles(e, r, i, t, n);
71
+ queryFiles(r, e, t = void 0, i = void 0, n = this.currentDir) {
72
+ return this.qyCache.queryFiles(r, e, t, i, n);
71
73
  }
72
- queryFilesMulti(e, r, i, t = this.currentDir) {
73
- return this.qyCache.queryFilesMulti(e, r, i, t);
74
+ queryFilesMulti(r, e, t, i = this.currentDir) {
75
+ return this.qyCache.queryFilesMulti(r, e, t, i);
74
76
  }
75
- queryTree(e, r, i, t, n, s = this.currentDir) {
76
- return h(this.qyCache.queryFiles(e, r, t, n, s), i);
77
+ queryTree(r, e, t, i, n, s = this.currentDir) {
78
+ return h(this.qyCache.queryFiles(r, e, i, n, s), t);
77
79
  }
78
- queryTreeMulti(e, r, i, t, n = this.currentDir) {
79
- return h(this.qyCache.queryFilesMulti(e, i, t, n), r);
80
+ queryTreeMulti(r, e, t, i, n = this.currentDir) {
81
+ return h(this.qyCache.queryFilesMulti(r, t, i, n), e);
80
82
  }
81
83
  resetCurrentDir() {
82
84
  this.currentDir = void 0;
83
85
  }
84
- fileListToTree(e, r) {
85
- return h(e, r);
86
+ fileListToTree(r, e) {
87
+ return h(r, e);
86
88
  }
87
89
  }
88
90
 
89
- function h(e, i) {
90
- var t, n = {};
91
- for (t of e) {
92
- var s, h = t.parentList;
93
- let r = 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;
94
96
  for (s of h) {
95
97
  var {
96
98
  name: u,
97
- fullPathHash: l
99
+ fullPathHash: c
98
100
  } = s;
99
- let e = r.subdirMap;
100
- e = e || (r.subdirMap = {}), r = (r = e[u]) || (e[u] = {
101
- fullPathHash: l
101
+ let r = e.subdirMap;
102
+ r = r || (e.subdirMap = {}), e = (e = r[u]) || (r[u] = {
103
+ fullPathHash: c
102
104
  });
103
105
  }
104
- let e = r.fileMap;
105
- (e = e || (r.fileMap = {}))[t.name] = {
106
- fileContent: t.view(i, !0),
107
- fileContentKey: t.fileContentKey
106
+ let r = e.fileMap;
107
+ (r = r || (e.fileMap = {}))[i.name] = {
108
+ fileContent: i.view(t, !0),
109
+ fileContentKey: i.fileContentKey
108
110
  };
109
111
  }
110
112
  return {
111
113
  tree: n,
112
- count: e.length
114
+ count: r.length
113
115
  };
114
116
  }
115
117
 
116
118
  export {
117
- e as QyCD
119
+ r as QyCD
118
120
  };
package/src/QyCache.d.ts CHANGED
@@ -12,11 +12,13 @@ export declare class QyCache extends EventEmitter {
12
12
  rpcRootDir: any;
13
13
  indexRootDir: any;
14
14
  expireRootDir: any;
15
- embeddingRootDir: any;
16
- h2FRootDir: any;
15
+ hnswRootDir: any;
16
+ infoRootDir: any;
17
+ recycleRootDir: any;
17
18
  exclusiveFilePath: any;
18
19
  qyKVData: any;
19
20
  qyFileLogger: any;
21
+ qyEmbeddings: any;
20
22
  rpcFunMap: {};
21
23
  constructor(rootFolder: string, options?: any, qyDB?: any);
22
24
  start(): Promise<this>;
@@ -25,8 +27,8 @@ export declare class QyCache extends EventEmitter {
25
27
  decreaseChangeId(): void;
26
28
  save(changeId: any, cmdArgAsListObj: any, logText: any, syncList: any, needPromise: any): any;
27
29
  getFile(namePath: QyFile | string | string[], parentDir?: any): QyFile | undefined;
28
- getDir(namePath: QyDir | string | string[], parentDir?: any): QyDir | undefined;
29
30
  getOrCreateFile(namePath: QyFile | string | string[], parentDir?: any): QyFile;
31
+ getDir(namePath: QyDir | string | string[], parentDir?: any): QyDir | undefined;
30
32
  getOrCreateDir(namePath: QyDir | string | string[], parentDir?: any): QyDir;
31
33
  getIndexDir(indexHostDir: QyDir): any;
32
34
  getOrCreateIndexDir(indexHostDir: any): any;
@@ -34,12 +36,12 @@ export declare class QyCache extends EventEmitter {
34
36
  getOrCreateTriggerFile(triggerName: any): any;
35
37
  getExpireInfoFile(fullPathHash: any, type?: string): any;
36
38
  getOrCreateExpireInfoFile(fullPathHash: any, type?: string): any;
37
- getH2FFile(fullPathHash: any): any;
38
- getOrCreateH2FFile(fullPathHash: any): any;
39
- h2F(fullPathHash: any): QyFile | undefined;
40
- getEmbeddingFile(fullPathHash: any): any;
41
- getOrCreateEmbeddingFile(fullPathHash: any): any;
42
- getEmbedding(fullPathHash: any): 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;
43
45
  get triggerFileList(): any;
44
46
  getRpcFile(rpcFunName: any): any;
45
47
  getOrCreateRpcFile(rpcFunName: any): any;