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.
- package/README.md +2 -0
- package/package.json +1 -1
- package/sample.js +9 -0
- package/scripts/fastify.js +1 -0
- package/scripts/hnsw.js +39 -0
- package/src/QyAcl.js +1 -1
- package/src/QyBatch.d.ts +2 -1
- package/src/QyBatch.js +142 -101
- package/src/QyBinWriter.d.ts +5 -9
- package/src/QyBinWriter.js +36 -45
- package/src/QyCD.d.ts +1 -1
- package/src/QyCD.js +66 -64
- package/src/QyCache.d.ts +11 -9
- package/src/QyCache.js +125 -121
- package/src/QyDB.js +1 -4
- package/src/QyDefaultOptions.js +8 -0
- package/src/QyEmbeddingWriter.d.ts +12 -0
- package/src/QyEmbeddingWriter.js +55 -0
- package/src/QyEmbeddings.d.ts +15 -0
- package/src/QyEmbeddings.js +128 -0
- package/src/QyFileContentUtils.js +123 -111
- package/src/QyHNSW.d.ts +5 -8
- package/src/QyHNSW.js +36 -44
- package/src/QySnapshots.js +177 -184
- package/src/QyUtils.d.ts +5 -3
- package/src/QyUtils.js +130 -114
- package/static/codemirror.bundle/editor.bundle.js +16 -9
package/src/QyBinWriter.d.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { QyOpRunner } from "./QyOpRunner.ts";
|
|
2
2
|
export declare class QyBinWriter extends QyOpRunner {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
filePath: any;
|
|
4
|
+
totalSavedSize: number;
|
|
5
5
|
fileHandle: any;
|
|
6
|
-
constructor(options?: any, filePath?: any);
|
|
7
|
-
|
|
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
|
|
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>;
|
package/src/QyBinWriter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
open as
|
|
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
|
|
11
|
-
getSize as
|
|
10
|
+
ensureParentDir as l,
|
|
11
|
+
getSize as f,
|
|
12
12
|
getSizeStr as v,
|
|
13
13
|
sleep as _,
|
|
14
|
-
setPromise as
|
|
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
|
|
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
|
-
|
|
28
|
-
|
|
29
|
+
filePath;
|
|
30
|
+
totalSavedSize = 0;
|
|
29
31
|
fileHandle;
|
|
30
|
-
constructor(t = void 0, e = void 0) {
|
|
31
|
-
super({
|
|
32
|
-
...
|
|
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,
|
|
36
|
+
}, a, i), this.filePath = e, h(this);
|
|
35
37
|
}
|
|
36
|
-
|
|
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 &&
|
|
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
|
-
|
|
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:
|
|
86
|
+
options: o
|
|
97
87
|
} = t, {
|
|
98
|
-
emitSaveEvent:
|
|
88
|
+
emitSaveEvent: n,
|
|
99
89
|
maxFileSize: l,
|
|
100
90
|
maxRetryInterval: f,
|
|
101
|
-
retryIntervalFactor:
|
|
102
|
-
} =
|
|
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.
|
|
105
|
-
flush: !0
|
|
106
|
-
});
|
|
94
|
+
await i.write(h, 0, h.byteLength, r);
|
|
107
95
|
var m = t.totalSavedSize = r + u;
|
|
108
|
-
return
|
|
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 ${
|
|
112
|
-
|
|
113
|
-
await _(
|
|
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
|
-
|
|
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
|
-
|
|
131
|
+
h(t);
|
|
144
132
|
try {
|
|
145
|
-
a && (a.close(), t.fileHandle = void 0), await
|
|
146
|
-
var
|
|
147
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
2
|
+
isString as i,
|
|
3
3
|
pathSplit as n
|
|
4
4
|
} from "./QyUtils.js";
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class r {
|
|
7
7
|
qyCache;
|
|
8
8
|
currentDir;
|
|
9
|
-
constructor(
|
|
10
|
-
this.qyCache =
|
|
9
|
+
constructor(r) {
|
|
10
|
+
this.qyCache = r;
|
|
11
11
|
}
|
|
12
|
-
cd(
|
|
13
|
-
return
|
|
12
|
+
cd(r, e = this.currentDir) {
|
|
13
|
+
return i(r) && (r = n(r)), this.cdP(r, e);
|
|
14
14
|
}
|
|
15
|
-
cdP(
|
|
16
|
-
return this.currentDir = this.qyCache.getOrCreateDir(
|
|
15
|
+
cdP(r, e = this.currentDir) {
|
|
16
|
+
return this.currentDir = this.qyCache.getOrCreateDir(r, e), this;
|
|
17
17
|
}
|
|
18
|
-
dir(
|
|
19
|
-
return
|
|
18
|
+
dir(r, e = this.currentDir) {
|
|
19
|
+
return i(r) && (r = n(r)), this.dirP(r, e);
|
|
20
20
|
}
|
|
21
|
-
dirP(
|
|
22
|
-
return this.qyCache.getDir(
|
|
21
|
+
dirP(r, e = this.currentDir) {
|
|
22
|
+
return this.qyCache.getDir(r, e);
|
|
23
23
|
}
|
|
24
|
-
indexDir(
|
|
25
|
-
return
|
|
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(
|
|
28
|
-
var
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
if (
|
|
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(
|
|
35
|
-
return
|
|
34
|
+
file(r, e = this.currentDir) {
|
|
35
|
+
return i(r) && (r = n(r)), this.fileP(r, e);
|
|
36
36
|
}
|
|
37
|
-
fileP(
|
|
38
|
-
return this.qyCache.getFile(
|
|
37
|
+
fileP(r, e = this.currentDir) {
|
|
38
|
+
return this.qyCache.getFile(r, e);
|
|
39
39
|
}
|
|
40
|
-
fileContent(
|
|
41
|
-
return this.file(
|
|
40
|
+
fileContent(r, e = this.currentDir) {
|
|
41
|
+
return this.file(r, e)?.fileContent;
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
return
|
|
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(
|
|
49
|
-
|
|
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(
|
|
52
|
-
return this.qyCache.getTriggerFile(
|
|
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(
|
|
58
|
-
return this.qyCache.getRpcFile(
|
|
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(
|
|
64
|
-
return
|
|
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(
|
|
67
|
-
return this.qyCache.getFile(
|
|
68
|
+
viewP(r, e, t = this.currentDir) {
|
|
69
|
+
return this.qyCache.getFile(r, t)?.view(e);
|
|
68
70
|
}
|
|
69
|
-
queryFiles(
|
|
70
|
-
return this.qyCache.queryFiles(e,
|
|
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,
|
|
73
|
-
return this.qyCache.queryFilesMulti(e,
|
|
74
|
+
queryFilesMulti(r, e, t, i = this.currentDir) {
|
|
75
|
+
return this.qyCache.queryFilesMulti(r, e, t, i);
|
|
74
76
|
}
|
|
75
|
-
queryTree(e,
|
|
76
|
-
return h(this.qyCache.queryFiles(
|
|
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,
|
|
79
|
-
return h(this.qyCache.queryFilesMulti(
|
|
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(
|
|
85
|
-
return h(
|
|
86
|
+
fileListToTree(r, e) {
|
|
87
|
+
return h(r, e);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
function h(
|
|
90
|
-
var
|
|
91
|
-
for (
|
|
92
|
-
var s, h =
|
|
93
|
-
let
|
|
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:
|
|
99
|
+
fullPathHash: c
|
|
98
100
|
} = s;
|
|
99
|
-
let
|
|
100
|
-
|
|
101
|
-
fullPathHash:
|
|
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
|
|
105
|
-
(
|
|
106
|
-
fileContent:
|
|
107
|
-
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:
|
|
114
|
+
count: r.length
|
|
113
115
|
};
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
export {
|
|
117
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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;
|