datafolder 1.0.40 → 1.0.42

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/src/QyCache.js CHANGED
@@ -17,15 +17,15 @@ import {
17
17
  } from "./QyKVData.js";
18
18
 
19
19
  import {
20
- QyTriggerNode as R,
21
- updateTriggerNodes as a
20
+ QyTriggerNode as C,
21
+ updateTriggerNodes as s
22
22
  } from "./QyTrigger.js";
23
23
 
24
24
  import {
25
- isString as C,
26
- lockExclusiveFilePath as q,
25
+ isString as q,
26
+ lockExclusiveFilePath as x,
27
27
  unlockExclusiveFilePath as o,
28
- ensureDir as x,
28
+ ensureDir as w,
29
29
  SpecialFilePaths as e
30
30
  } from "./QyUtils.js";
31
31
 
@@ -46,7 +46,7 @@ import {
46
46
  } from "./QyUnionNode.js";
47
47
 
48
48
  import {
49
- QyKVDataLoader as w
49
+ QyKVDataLoader as O
50
50
  } from "./QyKVDataLoader.js";
51
51
 
52
52
  import {
@@ -54,7 +54,7 @@ import {
54
54
  } from "./QyMod.js";
55
55
 
56
56
  import {
57
- logger as O
57
+ logger as b
58
58
  } from "./QyLogger.js";
59
59
 
60
60
  import {
@@ -64,13 +64,13 @@ import {
64
64
  let {
65
65
  HiddenFolderName: D,
66
66
  IndexDirPath: F,
67
- TriggerDirPath: b,
68
- RpcDirPath: E,
67
+ TriggerDirPath: E,
68
+ RpcDirPath: Q,
69
69
  ExpireDirPath: y,
70
70
  MetaFilePath: t,
71
71
  HNSWDirPath: m,
72
72
  InfoDirPath: f,
73
- RecycleDirPath: Q
73
+ RecycleDirPath: R
74
74
  } = e;
75
75
 
76
76
  class i extends r {
@@ -88,7 +88,7 @@ class i extends r {
88
88
  infoRootDir;
89
89
  recycleRootDir;
90
90
  exclusiveFilePath;
91
- rpcFunMap = {};
91
+ rpcFunMap = new Map();
92
92
  qyKVData;
93
93
  qyFileLogger;
94
94
  qyEmbeddings;
@@ -97,13 +97,11 @@ class i extends r {
97
97
  ...d("QyCache"),
98
98
  ...e
99
99
  }, this.qyDB = t;
100
- var i, o = this, t = o.rootDir = new l("", !0, void 0, o), s = new l(D, !0, t);
101
- t._subdirMap = {
102
- [D]: s
103
- }, s._subdirMap = {};
104
- for ([ a, i ] of [ [ F, "indexRootDir" ], [ y, "expireRootDir" ], [ m, "hnswRootDir" ], [ f, "infoRootDir" ], [ Q, "recycleRootDir" ] ]) {
105
- var a = a.at(-1), n = new l(a, !0, s);
106
- s._subdirMap[a] = n, o[i] = n;
100
+ var i, o = this, t = o.rootDir = new l("", !0, void 0, o), a = new l(D, !0, t);
101
+ t._subdirMap = new Map([ [ D, a ] ]), a._subdirMap = new Map();
102
+ for ([ s, i ] of [ [ F, "indexRootDir" ], [ y, "expireRootDir" ], [ m, "hnswRootDir" ], [ f, "infoRootDir" ], [ R, "recycleRootDir" ] ]) {
103
+ var s = s.at(-1), n = new l(s, !0, a);
104
+ a._subdirMap.set(s, n), o[i] = n;
107
105
  }
108
106
  t = v(r, "qykv");
109
107
  this.kvFolder = t, this.rpcFolder = v(r, "rpc"), this.exclusiveFilePath = v(r, ".opened"),
@@ -117,15 +115,15 @@ class i extends r {
117
115
  options: t,
118
116
  qyKVData: i,
119
117
  qyFileLogger: o,
120
- exclusiveFilePath: s,
121
- rootDir: a,
118
+ exclusiveFilePath: a,
119
+ rootDir: s,
122
120
  qyEmbeddings: n
123
121
  } = this;
124
- O.log("Starting at " + r);
122
+ b.log("Starting at " + r);
125
123
  try {
126
- await x(e);
127
- var [ [ l, g, h, d ] ] = await Promise.all([ ((r, e) => (r = new w(r, e)).load())(e, t), q(s) ]);
128
- o.start(), i.start(l, g, h, d), await n.start();
124
+ await w(e);
125
+ var l = new O(e, t), [ [ g, h, d, u ] ] = await Promise.all([ l.load(), x(a) ]);
126
+ o.start(), i.start(g, h, d, u), await n.start();
129
127
  } catch (r) {
130
128
  throw o.stop(), n.stop(), r;
131
129
  }
@@ -135,42 +133,42 @@ class i extends r {
135
133
  fileMap: i
136
134
  } = e;
137
135
  for (var o of t) r(o);
138
- }(a);
139
- var u = this, e = u.rootDir;
140
- e.triggerNodes = [ new R() ];
141
- for (p of (e = u.triggerRootDir = e.searchOrCreateSubdir(b)).fileList) {
136
+ }(s);
137
+ var p = this, e = p.rootDir;
138
+ e.triggerNodes = [ new C() ];
139
+ for (c of (e = p.triggerRootDir = e.searchOrCreateSubdir(E)).fileList) {
142
140
  var {
143
- name: p,
144
- fileContent: c
145
- } = p, [ c, D, F ] = c;
146
- u.insertTriggerToTree(p, c, D, F);
141
+ name: c,
142
+ fileContent: D
143
+ } = c, [ D, F, y ] = D;
144
+ p.insertTriggerToTree(c, D, F, y);
147
145
  }
148
- var y = this;
149
- y.rpcRootDir = y.rootDir.searchOrCreateSubdir(E);
150
- for (m of y.rpcRootDir.fileList) {
146
+ var m = this;
147
+ m.rpcRootDir = m.rootDir.searchOrCreateSubdir(Q);
148
+ for (f of m.rpcRootDir.fileList) {
151
149
  var {
152
- name: m,
153
- fileContent: f
154
- } = m;
155
- C(f) && y.insertRpc(m, f);
150
+ name: f,
151
+ fileContent: R
152
+ } = f;
153
+ q(R) && m.insertRpc(f, R);
156
154
  }
157
- return t.dumpStructureAtStart && await P(v(r, "qystruct"), a), O.log("Started."),
155
+ return t.dumpStructureAtStart && await P(v(r, "qystruct"), s), b.log("Started."),
158
156
  this;
159
157
  }
160
158
  async stop() {
161
- O.log("Stopping...");
159
+ b.log("Stopping...");
162
160
  var {
163
161
  qyKVData: r,
164
162
  qyEmbeddings: e,
165
163
  qyFileLogger: t,
166
164
  exclusiveFilePath: i
167
165
  } = this;
168
- return await r.stop(), await e.stop(), O.log("QyFileLogger stopped."), await t.stop(),
166
+ return await r.stop(), await e.stop(), b.log("QyFileLogger stopped."), await t.stop(),
169
167
  o(i), this.rootDir = void 0, this.indexRootDir = void 0, this.expireRootDir = void 0,
170
168
  this.triggerRootDir = void 0, this.rpcRootDir = void 0, this.hnswRootDir = void 0,
171
169
  this.infoRootDir = void 0, this.recycleRootDir = void 0, this.qyKVData = void 0,
172
- this.rpcFunMap = void 0, this.qyDB = void 0, this.qyFileLogger = void 0,
173
- O.log("Stopped."), this;
170
+ this.rpcFunMap.clear(), this.qyDB = void 0, this.qyFileLogger = void 0,
171
+ b.log("Stopped."), this;
174
172
  }
175
173
  increaseChangeId() {
176
174
  return this.qyKVData.increaseChangeId();
@@ -180,22 +178,22 @@ class i extends r {
180
178
  }
181
179
  save(r, e, t, i, o) {
182
180
  var {
183
- qyKVData: s,
184
- qyFileLogger: a
181
+ qyKVData: a,
182
+ qyFileLogger: s
185
183
  } = this;
186
- return t && a.save(r, t), s.save(r, e, i, o);
184
+ return t && s.save(r, t), a.save(r, e, i, o);
187
185
  }
188
186
  getFile(r, e = this.rootDir) {
189
- return r.isFile ? r : C(r) ? e.getFile(r) : e.searchFile(r);
187
+ return r.isFile ? r : q(r) ? e.getFile(r) : e.searchFile(r);
190
188
  }
191
189
  getOrCreateFile(r, e = this.rootDir) {
192
- return r.isFile ? r : C(r) ? e.getOrCreateFile(r) : e.searchOrCreateFile(r);
190
+ return r.isFile ? r : q(r) ? e.getOrCreateFile(r) : e.searchOrCreateFile(r);
193
191
  }
194
192
  getDir(r, e = this.rootDir) {
195
- return r.isDir ? r : C(r) ? e.getSubdir(r) : e.searchSubdir(r);
193
+ return r.isDir ? r : q(r) ? e.getSubdir(r) : e.searchSubdir(r);
196
194
  }
197
195
  getOrCreateDir(r, e = this.rootDir) {
198
- return r.isDir ? r : C(r) ? e.getOrCreateSubdir(r) : e.searchOrCreateSubdir(r);
196
+ return r.isDir ? r : q(r) ? e.getOrCreateSubdir(r) : e.searchOrCreateSubdir(r);
199
197
  }
200
198
  getIndexDir(r) {
201
199
  return this.indexRootDir.searchSubdir(I(r.fullPathHash));
@@ -216,13 +214,13 @@ class i extends r {
216
214
  return this.expireRootDir.searchOrCreateFile(S(r, e));
217
215
  }
218
216
  getInfoFile(r) {
219
- return this.infoRootDir.searchFile(s(r.fullPathHash));
217
+ return this.infoRootDir.searchFile(a(r.fullPathHash));
220
218
  }
221
219
  getOrCreateInfoFile(r) {
222
- return this.infoRootDir.searchOrCreateFile(s(r.fullPathHash));
220
+ return this.infoRootDir.searchOrCreateFile(a(r.fullPathHash));
223
221
  }
224
222
  hToSrcFile(r) {
225
- r = this.infoRootDir.searchFile(s(r));
223
+ r = this.infoRootDir.searchFile(a(r));
226
224
  if (r && r.fileContent) {
227
225
  r = r.fileContent.namePath;
228
226
  if (r) return this.getOrCreateFile(r);
@@ -259,40 +257,40 @@ class i extends r {
259
257
  insertTriggerToTree(r, e, t, i) {
260
258
  var {
261
259
  rootDir: o,
262
- qyDB: s
263
- } = this, i = p("trigger", r, i, s);
264
- o.triggerNodes[0].insertTrigger(r, e, t, i), a(o, e);
260
+ qyDB: a
261
+ } = this, i = p("trigger", r, i, a);
262
+ o.triggerNodes[0].insertTrigger(r, e, t, i), s(o, e);
265
263
  }
266
264
  removeTriggerFromTree(r, e) {
267
265
  var t = this.rootDir;
268
- t.triggerNodes[0].removeTrigger(r, e) && a(t, e);
266
+ t.triggerNodes[0].removeTrigger(r, e) && s(t, e);
269
267
  }
270
268
  insertRpc(r, e) {
271
269
  var {
272
270
  rpcFunMap: t,
273
271
  qyDB: i
274
272
  } = this, e = p("rpc", r, e, i);
275
- e && (t[r] = e);
273
+ e && t?.set(r, e);
276
274
  }
277
275
  removeRpc(r) {
278
- delete this.rpcFunMap[r];
276
+ this.rpcFunMap.delete(r);
279
277
  }
280
278
  queryFiles(r, e, t, i, o = this.rootDir) {
281
- var s = [], t = (C(e) && !t && (t = 1), new u(t, i)), i = this.options.queryAutoIndex;
282
- return L(r, e, s, t, o, i), s;
279
+ var a = [], t = (q(e) && !t && (t = 1), new u(t, i)), i = this.options.queryAutoIndex;
280
+ return L(r, e, a, t, o, i), a;
283
281
  }
284
282
  queryFilesMulti(r, e, t, i = this.rootDir) {
285
- var o, s, a = [], n = new u(e, t), l = this.options.queryAutoIndex;
286
- for ([ o, s ] of r) L(o, s, a, n, i, l);
287
- return a;
283
+ var o, a, s = [], n = new u(e, t), l = this.options.queryAutoIndex;
284
+ for ([ o, a ] of r) L(o, a, s, n, i, l);
285
+ return s;
288
286
  }
289
287
  async callRpc(e, r, t) {
290
- var i, o = this.rpcFunMap[e];
291
- if (!o) return O.warn(i = `RPC ${e} not implemented.`), new Error(i);
288
+ var i, o = this.rpcFunMap.get(e);
289
+ if (!o) return b.warn(i = `RPC ${e} not implemented.`), new Error(i);
292
290
  try {
293
291
  return await o(r, t);
294
292
  } catch (r) {
295
- return O.error(`Calling RPC ${e} failed:`, r), r;
293
+ return b.error(`Calling RPC ${e} failed:`, r), r;
296
294
  }
297
295
  }
298
296
  monitorItemExpire(r, e) {
@@ -309,7 +307,7 @@ class i extends r {
309
307
  }
310
308
  }
311
309
 
312
- function s(r) {
310
+ function a(r) {
313
311
  return [ r.substring(0, 2), r ];
314
312
  }
315
313
 
@@ -321,8 +319,8 @@ function I(r) {
321
319
  return [ r[0], r ];
322
320
  }
323
321
 
324
- function L(r, e, t, i, o, s) {
325
- void 0 !== e && n(r, o, s, e, t, i);
322
+ function L(r, e, t, i, o, a) {
323
+ void 0 !== e && n(r, o, a, e, t, i);
326
324
  }
327
325
 
328
326
  export {
package/src/QyDB.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { QyBatch } from "./QyBatch.ts";
2
+ import { QyCache } from "./QyCache.ts";
2
3
  import { QyCD } from "./QyCD.ts";
3
4
  import type { QyDir } from "./QyDir.ts";
4
5
  import type { QyFile } from "./QyFile.ts";
@@ -17,6 +18,6 @@ export declare class QyDB extends QyCD {
17
18
  get currentBatch(): any;
18
19
  createDir(namePath: string | string[]): QyDir;
19
20
  createFile(namePath: string | string[]): QyFile;
20
- on(eventName: any, listener: any): any;
21
- callRpc(rpcFunName: any, argList: any, body?: undefined): any;
21
+ on(eventName: any, listener: any): QyCache;
22
+ callRpc(rpcFunName: any, argList: any, body?: undefined): Promise<any>;
22
23
  }
@@ -53,9 +53,6 @@ let t = {
53
53
  QyKVDataSaver_Worker: {
54
54
  noAcl: !1
55
55
  },
56
- QyAclWriter: {
57
- minBatchSize: 2
58
- },
59
56
  QyEmbeddingWriter: {
60
57
  append: !0,
61
58
  read: !0
package/src/QyDir.d.ts CHANGED
@@ -19,8 +19,8 @@ export declare class QyDir extends QyItem {
19
19
  get isHiddenFolder(): boolean;
20
20
  get subdirMapKey(): string;
21
21
  get fileMapKey(): string;
22
- get subdirMap(): {};
23
- get fileMap(): {};
22
+ get subdirMap(): Map<string | number, QyDir> | undefined;
23
+ get fileMap(): Map<string | number, QyFile> | undefined;
24
24
  get subdirMapLoaded(): boolean;
25
25
  set subdirMapLoaded(val: boolean);
26
26
  get fileMapLoaded(): boolean;
@@ -52,6 +52,6 @@ export declare class QyDir extends QyItem {
52
52
  setChildTriggerNodes(child: QyDir | QyFile): void;
53
53
  filterSubdirNames(filterFun: any): Generator<QyDir, void, unknown>;
54
54
  filterFileNames(filterFun: any): Generator<QyFile, void, unknown>;
55
- compareItemRange(cmpFun: any, isFile?: boolean, reverse?: boolean): Generator<QyDir | QyFile | undefined, void, unknown>;
55
+ compareItemRange(cmpFun: any, isFile?: boolean, reverse?: boolean): Generator<QyFile | QyDir | undefined, void, unknown>;
56
56
  ensureAllLoaded(): this;
57
57
  }