datafolder 1.0.28 → 1.0.30

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.
Files changed (57) hide show
  1. package/ChangeLog.md +4 -0
  2. package/package.json +1 -1
  3. package/scripts/airbnb.js +5 -5
  4. package/scripts/airbnb2.js +4 -4
  5. package/scripts/airbnb_queries.js +6 -6
  6. package/scripts/convertBinFiles.js +2 -2
  7. package/scripts/fastify.js +2 -1
  8. package/scripts/flights.js +1 -1
  9. package/scripts/flights2.js +2 -2
  10. package/scripts/flights2_queries.js +6 -6
  11. package/scripts/flights_queries.js +6 -6
  12. package/src/QyAcl.d.ts +1 -1
  13. package/src/QyAcl.js +85 -87
  14. package/src/QyBatch.d.ts +1 -1
  15. package/src/QyBatch.js +188 -212
  16. package/src/QyBinWriter.js +11 -14
  17. package/src/QyBinaryHeap.js +2 -2
  18. package/src/QyCD.js +1 -1
  19. package/src/QyCache.js +24 -27
  20. package/src/QyCompressor.js +2 -2
  21. package/src/QyDB.js +1 -1
  22. package/src/QyDir.js +9 -9
  23. package/src/QyEmbeddingWriter.js +1 -1
  24. package/src/QyEmbeddings.js +45 -48
  25. package/src/QyExpire.js +20 -28
  26. package/src/QyExpireInfo.js +32 -32
  27. package/src/QyExpire_Worker.js +2 -5
  28. package/src/QyFile.js +67 -67
  29. package/src/QyFileContentUtils.js +95 -95
  30. package/src/QyFileLogger.js +1 -1
  31. package/src/QyIndex.js +113 -113
  32. package/src/QyIndexPropTree.js +5 -5
  33. package/src/QyIntersectNode.js +8 -10
  34. package/src/QyItem.js +28 -28
  35. package/src/QyKVData.js +40 -45
  36. package/src/QyKVDataCleaner_Worker.js +1 -1
  37. package/src/QyKVDataSaver_Worker.js +5 -7
  38. package/src/QyMessageWorker.js +1 -1
  39. package/src/QyMessager.js +2 -2
  40. package/src/QySaver.js +20 -20
  41. package/src/QySnapshotCompactor_Worker.js +6 -15
  42. package/src/QySnapshotSaver_Worker.js +1 -1
  43. package/src/QySnapshots.js +78 -88
  44. package/src/QyStructure.js +1 -1
  45. package/src/QyTrigger.js +3 -8
  46. package/src/QyUtils.d.ts +1 -5
  47. package/src/QyUtils.js +73 -98
  48. package/src/hackernews.js +77 -59
  49. package/src/rpc/getFileContent.js +4 -3
  50. package/src/rpc/getSubItems.js +6 -4
  51. package/src/simulate.js +4 -4
  52. package/src/simulate2.js +3 -3
  53. package/src/soc_pokec.js +1 -1
  54. package/static/codemirror.bundle/editor.bundle.js +348 -178
  55. package/test/testQyAQL.js +23 -23
  56. package/test/testQyGraphQL.js +1 -1
  57. package/test/testQyNorthwind.js +4 -4
package/src/QyKVData.js CHANGED
@@ -24,7 +24,7 @@ import {
24
24
 
25
25
  import {
26
26
  readBufferAsync as y,
27
- sleep as l
27
+ sleep as d
28
28
  } from "./QyUtils.js";
29
29
 
30
30
  import {
@@ -91,9 +91,9 @@ class t {
91
91
  let t = 0, a = 0;
92
92
  if (e) {
93
93
  var s, i = n.maxFileCountToUnload, n = e.rootDir;
94
- a = d(o, n), t = a;
95
- for (s of n.allLoadedSubdirs()) if ((a += d(o, s)) > i && (t += a,
96
- a = 0, await l(0), o.isStopping)) break;
94
+ a = l(o, n), t = a;
95
+ for (s of n.allLoadedSubdirs()) if ((a += l(o, s)) > i && (t += a,
96
+ a = 0, await d(0), o.isStopping)) break;
97
97
  }
98
98
  t += a, global.gc && global.gc(), o.unloadingMemory = !1;
99
99
  }
@@ -112,34 +112,34 @@ class t {
112
112
  } = t;
113
113
  console.time("bgLoadPosMaps");
114
114
  for (a of Object.keys(o.numToSnapshotMap).sort((t, a) => a - t)) {
115
- if (await async function s(i, r, p = void 0, h = void 0, c = void 0, l = void 0) {
116
- if (i.isStopping) return void (l && l.close());
115
+ if (await async function s(i, r, p = void 0, h = void 0, c = void 0, d = void 0) {
116
+ if (i.isStopping) return void (d && d.close());
117
117
  let m = i.qySnapshots;
118
- let d = m.numToSnapshotMap;
119
- let u = d[r];
120
- if (!u) return void (l && l.close());
118
+ let l = m.numToSnapshotMap;
119
+ let u = l[r];
120
+ if (!u) return void (d && d.close());
121
121
  let {
122
- info: S,
123
- prefixPM: v
122
+ info: v,
123
+ prefixPM: S
124
124
  } = u;
125
- p = p || Object.keys(v).sort().reverse();
126
- if (0 == p.length) return void (l && l.close());
127
- if (null == h || h != S.pMVersion) return l && l.close(), c = m.getPMFilePath(u),
128
- s(i, r, p, S.pMVersion, c, await f(c));
125
+ p = p || Object.keys(S).sort().reverse();
126
+ if (0 === p.length) return void (d && d.close());
127
+ if (void 0 === h || h !== v.pMVersion) return d && d.close(),
128
+ c = m.getPMFilePath(u), s(i, r, p, v.pMVersion, c, await f(c));
129
129
  for (;0 < p.length; ) {
130
- let e = p.at(-1), n = v[e];
130
+ let e = p.at(-1), n = S[e];
131
131
  if (n) {
132
- let [ t, a ] = n, o = await y(c, l, t, a);
133
- if (i.isStopping || !d[r]) return void l.close();
134
- if (h != S.pMVersion) return l.close(), s(i, r, p);
135
- e in v && m.loadPartialPosMapBuffer(u, e, o);
132
+ let [ t, a ] = n, o = await y(c, d, t, a);
133
+ if (i.isStopping || !l[r]) return void d.close();
134
+ if (h !== v.pMVersion) return d.close(), s(i, r, p);
135
+ e in S && m.loadPartialPosMapBuffer(u, e, o);
136
136
  }
137
137
  p.pop();
138
138
  }
139
- l.close();
139
+ d.close();
140
140
  C.info("bgLoadPosMap:" + r);
141
141
  }(t, a), t.isStopping) break;
142
- if (await l(0), t.isStopping) break;
142
+ if (await d(0), t.isStopping) break;
143
143
  }
144
144
  console.timeEnd("bgLoadPosMaps"), !t.isStopping && e.compactAtStart && m(t);
145
145
  })(this) : n.compactAtStart && m(this), this;
@@ -191,7 +191,7 @@ class t {
191
191
  compactMaxChangeId: e,
192
192
  qyKVDataSaver: n
193
193
  } = this;
194
- if (3 == o && e <= t && (x(this), this.compactState = 1), a) {
194
+ if (3 === o && e <= t && (x(this), this.compactState = 1), a) {
195
195
  var s, o = a, i = this.qySnapshots, r = i.keyToSnapshotMap;
196
196
  for (s in o.posMap) {
197
197
  var p = r[s];
@@ -202,14 +202,14 @@ class t {
202
202
  }
203
203
  }
204
204
  onCompactUpdates(t) {
205
- if (2 == this.compactState) {
206
- var l = this, {
205
+ if (2 === this.compactState) {
206
+ var d = this, {
207
207
  pMUpdates: t,
208
208
  vLUpdates: m,
209
- combinationUpdate: d
209
+ combinationUpdate: l
210
210
  } = t = t;
211
211
  if (t) {
212
- var a = t, o = l.qySnapshots.numToSnapshotMap;
212
+ var a = t, o = d.qySnapshots.numToSnapshotMap;
213
213
  for (s in a) {
214
214
  var e, n = a[s], s = o[s], {
215
215
  prefixPM: i,
@@ -227,25 +227,25 @@ class t {
227
227
  }
228
228
  }
229
229
  if (m) {
230
- var p = m, h = (t = l).qySnapshots.numToSnapshotMap;
230
+ var p = m, h = (t = d).qySnapshots.numToSnapshotMap;
231
231
  for (f in p) {
232
232
  var c, u, {
233
- posMap: S,
234
- prefixPM: v
233
+ posMap: v,
234
+ prefixPM: S
235
235
  } = p[f], f = h[f], {
236
236
  posMap: y,
237
237
  prefixPM: C,
238
238
  info: g
239
239
  } = f;
240
240
  for (c in ++g.pMVersion, ++g.vLVersion, g.verList[0] = g.pMVersion + g.vLVersion,
241
- y) y[c] = S[c];
242
- for (u in C) C[u] = v[u];
241
+ y) y[c] = v[c];
242
+ for (u in C) C[u] = S[u];
243
243
  I(f);
244
244
  }
245
245
  }
246
- if (d) {
247
- var M, m = d;
248
- let e = l.qySnapshots, {
246
+ if (l) {
247
+ var M, m = l;
248
+ let e = d.qySnapshots, {
249
249
  numToSnapshotMap: n,
250
250
  keyToSnapshotMap: s
251
251
  } = e, {
@@ -298,7 +298,7 @@ function I(t) {
298
298
  }
299
299
 
300
300
  function m(t) {
301
- if (1 == t.compactState) {
301
+ if (1 === t.compactState) {
302
302
  var {
303
303
  maxChangeId: a,
304
304
  qySnapshots: o,
@@ -310,21 +310,16 @@ function m(t) {
310
310
  combiningSnapshotList: i
311
311
  } = o.calOutdates();
312
312
  if (0 < i.length || 0 < n.length || 0 < s.length) {
313
- Object.assign(t, {
314
- compactState: 2,
315
- compactMaxChangeId: a
316
- });
313
+ t.compactState = 2, t.compactMaxChangeId = a;
317
314
  for (var r of [ n, s, i ]) for (var p of r) p.compactOutedCount = p.outdatedCount;
318
315
  e.compactSnapshots(n, s, i);
319
316
  }
320
- 0 < o.length && (t.emptySnapshotNumVerList.push(...o), t.snapshotSavedChangeId >= a ? c(t) : 1 == t.compactState && Object.assign(t, {
321
- compactState: 3,
322
- compactMaxChangeId: a
323
- }));
317
+ 0 < o.length && (t.emptySnapshotNumVerList.push(...o), t.snapshotSavedChangeId >= a ? c(t) : 1 === t.compactState && (t.compactState = 3,
318
+ t.compactMaxChangeId = a));
324
319
  }
325
320
  }
326
321
 
327
- function d(t, a) {
322
+ function l(t, a) {
328
323
  var o = t.qySnapshots.snapshotMaxChangeId;
329
324
  let e = 0;
330
325
  if (a.fileMapLoaded) for (var n of a.fileList) ++e, n.cChangeId <= o && (n.visited ? n.visited = !1 : n.unloadFileContent());
@@ -116,7 +116,7 @@ async function n(o, e, a, r) {
116
116
  var l, n = [];
117
117
  for (l of await d(i)) {
118
118
  var p = new RegExp("^([0-9]+)_" + r).exec(l);
119
- p && (p = parseInt(p[1])) < a && (1 == p ? (s || (s = m(t, "" + e),
119
+ p && (p = parseInt(p[1])) < a && (1 === p ? (s || (s = m(t, "" + e),
120
120
  await f(s)), n.push(y(o, l, i, s))) : (p = m(i, l), F.info("Removing " + p),
121
121
  n.push(c(p))));
122
122
  }
@@ -90,16 +90,14 @@ function h(a, s, t, e, o = !1) {
90
90
  qySnapshotSaver: r,
91
91
  options: h,
92
92
  snapshotMaxChangeId: p,
93
- currentAclNum: i,
94
- isSavingSnapshot: S
93
+ currentAclNum: S,
94
+ isSavingSnapshot: i
95
95
  } = a;
96
96
  let v;
97
97
  return n && (o ? v = n.callSave(s, t) : n.castSave(s, t)), r.castSave(s, t, e),
98
- a.maxChangeId = s, !S && s - p >= h.snapshotMaxChangeCount && (++a.currentAclNum,
99
- n && n.switch(l(a)), r.saveSnapshot(i), Object.assign(a, {
100
- snapshotMaxChangeId: s,
101
- isSavingSnapshot: !0
102
- })), v;
98
+ a.maxChangeId = s, !i && s - p >= h.snapshotMaxChangeCount && (++a.currentAclNum,
99
+ n && n.switch(l(a)), r.saveSnapshot(S), a.snapshotMaxChangeId = s, a.isSavingSnapshot = !0),
100
+ v;
103
101
  }
104
102
 
105
103
  function l(a) {
@@ -31,7 +31,7 @@ class s extends e {
31
31
  r && t?.postMessage({
32
32
  ack: s,
33
33
  result: o
34
- }), "stop" == s && process.exit();
34
+ }), "stop" === s && process.exit();
35
35
  } catch (e) {
36
36
  p.error(`Running ${s} failed:`, e), r && t?.postMessage({
37
37
  ack: s,
package/src/QyMessager.js CHANGED
@@ -71,10 +71,10 @@ class r {
71
71
  ack: o,
72
72
  result: s
73
73
  } = e;
74
- r ? "%o_" == r ? n.handleOutMsg(e) : "%e_" == r ? n.handleErrMsg(e) : (e = e.args || [],
74
+ r ? "%o_" === r ? n.handleOutMsg(e) : "%e_" === r ? n.handleErrMsg(e) : (e = e.args || [],
75
75
  t[r](...e)) : a[o]?.shift().resolve(s);
76
76
  }), i.on("exit", e => {
77
- for (var r in i.removeAllListeners(), 0 != e ? n.warn(`Worker ${s} stopped with exitCode ` + e) : n.info(`Worker ${s} stopped.`),
77
+ for (var r in i.removeAllListeners(), 0 !== e ? n.warn(`Worker ${s} stopped with exitCode ` + e) : n.info(`Worker ${s} stopped.`),
78
78
  a) for (var o = a[r]; !o.isEmpty; ) o.shift()?.resolve();
79
79
  p.worker = void 0;
80
80
  });
package/src/QySaver.js CHANGED
@@ -1,4 +1,4 @@
1
- import s, {
1
+ import o, {
2
2
  readFile as a,
3
3
  rm as e
4
4
  } from "node:fs/promises";
@@ -13,11 +13,11 @@ import {
13
13
 
14
14
  import {
15
15
  toBuffer as r,
16
- folderOrFileExists as u,
17
- getSizeStr as o,
16
+ folderOrFileExists as v,
17
+ getSizeStr as s,
18
18
  sleep as g,
19
19
  getSize as n,
20
- ensureParentDir as l
20
+ ensureParentDir as d
21
21
  } from "./QyUtils.js";
22
22
 
23
23
  import {
@@ -55,13 +55,13 @@ class i {
55
55
  }
56
56
  async loadFromFile(r, t = void 0) {
57
57
  r = f(this.dataFolder, r);
58
- if (null != t && !await u(r)) return t;
58
+ if (void 0 !== t && !await v(r)) return t;
59
59
  try {
60
60
  var e = await a(r);
61
- return m.info(`Loading "${r}" succeeded. Total size:${o(e.length)}.`),
61
+ return m.info(`Loading "${r}" succeeded. Total size:${s(e.length)}.`),
62
62
  this.processAfterLoad(e);
63
63
  } catch (e) {
64
- if (null != t) return t;
64
+ if (void 0 !== t) return t;
65
65
  m.error(`Loading "${r}" failed:`, e);
66
66
  }
67
67
  }
@@ -69,27 +69,27 @@ class i {
69
69
  var {
70
70
  dataFolder: a,
71
71
  options: i
72
- } = this, s = f(a, t);
73
- if (!r && await u(s)) m.error(s + " already exists."); else {
72
+ } = this, o = f(a, t);
73
+ if (!r && await v(o)) m.error(o + " already exists."); else {
74
74
  var {
75
- retryTimes: o,
75
+ retryTimes: s,
76
76
  retryIntervalFactor: n,
77
- maxRetryInterval: l
78
- } = i, d = f(a, ".tmp", t), c = this.processBeforeSave(e);
77
+ maxRetryInterval: d
78
+ } = i, l = f(a, ".tmp", t), c = this.processBeforeSave(e);
79
79
  let r;
80
- for (let e = 0; e < o; ++e) {
81
- if (await this._saveTmpFileAndRename(c, d, s)) return !0;
82
- r = r ? Math.min(l, r * n) : 1, m.warn(`Retrying to create ${s} in ${r} seconds.`),
80
+ for (let e = 0; e < s; ++e) {
81
+ if (await this._saveTmpFileAndRename(c, l, o)) return !0;
82
+ r = r ? Math.min(d, r * n) : 1, m.warn(`Retrying to create ${o} in ${r} seconds.`),
83
83
  await g(r);
84
84
  }
85
- m.error(`Failed to create ${t} after retrying ${o} times.`);
85
+ m.error(`Failed to create ${t} after retrying ${s} times.`);
86
86
  }
87
87
  return !1;
88
88
  }
89
89
  async _saveTmpFileAndRename(e, r, t) {
90
90
  var a = e.length;
91
- if (await this._saveContent(r, e) != a) m.error(`Creating ${t} failed when trying to create ${r} first.`); else try {
92
- if (await s.rename(r, t), await n(t) === a) return m.info(`Renaming ${r} to ${t} succeeded.`),
91
+ if (await this._saveContent(r, e) !== a) m.error(`Creating ${t} failed when trying to create ${r} first.`); else try {
92
+ if (await o.rename(r, t), await n(t) === a) return m.info(`Renaming ${r} to ${t} succeeded.`),
93
93
  !0;
94
94
  m.error(t + " size is not correct.");
95
95
  } catch (e) {
@@ -100,10 +100,10 @@ class i {
100
100
  async _saveContent(r, e) {
101
101
  var t = e.length;
102
102
  try {
103
- await l(r), await s.writeFile(r, e, {
103
+ await d(r), await o.writeFile(r, e, {
104
104
  flush: !0
105
105
  });
106
- var a = `Saving ${r} size ` + o(t), i = await n(r);
106
+ var a = `Saving ${r} size ` + s(t), i = await n(r);
107
107
  return i === t ? m.info(a + " succeeded.") : m.warn(a + " failed."),
108
108
  i;
109
109
  } catch (e) {
@@ -71,7 +71,7 @@ export default class extends a {
71
71
  info: n,
72
72
  prefixPM: i
73
73
  } = s;
74
- (null == i || r(i) || await M(a, s)) && (await t.savePosMap(s),
74
+ (void 0 === i || r(i) || await M(a, s)) && (await t.savePosMap(s),
75
75
  e[p] = n, o[p] = s.prefixPM);
76
76
  })(this, a, s)));
77
77
  }
@@ -103,22 +103,16 @@ export default class extends a {
103
103
  info: r,
104
104
  keyValueMap: f
105
105
  } = (await y(t, n), n);
106
- Object.assign(n, {
107
- posMap: void 0,
108
- prefixPM: void 0
109
- });
110
- for (var h of a) if (h != n) {
106
+ n.posMap = void 0, n.prefixPM = void 0;
107
+ for (var h of a) if (h !== n) {
111
108
  await y(t, h);
112
109
  let {
113
110
  snapshotNum: a,
114
111
  info: s,
115
112
  keyValueMap: o
116
113
  } = h;
117
- p.push([ a, s.verList[0] ]), Object.assign(f, o), Object.assign(h, {
118
- keyValueMap: void 0,
119
- posMap: void 0,
120
- prefixPM: void 0
121
- });
114
+ p.push([ a, s.verList[0] ]), Object.assign(f, o), h.keyValueMap = void 0,
115
+ h.posMap = void 0, h.prefixPM = void 0;
122
116
  }
123
117
  await o.saveKeyValueMap(n), e[i] = r, s.combinationUpdate = {
124
118
  snapshotNum: i,
@@ -134,10 +128,7 @@ export default class extends a {
134
128
  vLInfoMap: e,
135
129
  combinedSnapshotNumVerList: p,
136
130
  qyKVDataCleaner: n
137
- } = this, i = (Object.assign(this, {
138
- pMInfoMap: {},
139
- vLInfoMap: {}
140
- }), []);
131
+ } = this, i = (this.pMInfoMap = {}, this.vLInfoMap = {}, []);
141
132
  for (a in t) i.push(o.saveSnapshotInfo(a, t[a]));
142
133
  for (s in e) i.push(o.saveSnapshotInfo(s, e[s]));
143
134
  await Promise.all(i);
@@ -140,7 +140,7 @@ function h(a, s, e, t) {
140
140
  info: o,
141
141
  snapshotNum: v
142
142
  } = m = e.getMaxCombinedSnapshot(a);
143
- for (S of a) if (m != S) {
143
+ for (S of a) if (m !== S) {
144
144
  var g, {
145
145
  keyValueMap: M,
146
146
  snapshotNum: f,