datafolder 1.0.3 → 1.0.4

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,11 +1,11 @@
1
1
  import {
2
- close as e,
2
+ close as o,
3
3
  readSync as i,
4
4
  openSync as p
5
5
  } from "node:fs";
6
6
 
7
7
  import {
8
- readdir as f,
8
+ readdir as l,
9
9
  readFile as d
10
10
  } from "node:fs/promises";
11
11
 
@@ -21,29 +21,30 @@ import {
21
21
  Hash_Key_Length as u,
22
22
  folderOrFileExists as m,
23
23
  listToMap as r,
24
- isEmptyObj as h
24
+ isEmptyObj as h,
25
+ isString as v
25
26
  } from "./QyUtils.js";
26
27
 
27
28
  import {
28
- QyBinWriter as v
29
+ QyBinWriter as M
29
30
  } from "./QyBinWriter.js";
30
31
 
31
32
  import {
32
- bufferToNums as M,
33
- numsToBuffer as g,
34
- applyAclChange as l,
35
- iterCmdKeys as y
33
+ bufferToNums as g,
34
+ numsToBuffer as y,
35
+ applyAclChange as f,
36
+ iterCmdKeys as S
36
37
  } from "./QyAcl.js";
37
38
 
38
39
  import {
39
- QyJsonSaver as S
40
+ QyJsonSaver as c
40
41
  } from "./QyJsonSaver.js";
41
42
 
42
43
  import {
43
- logger as c
44
+ logger as C
44
45
  } from "./QyLogger.js";
45
46
 
46
- let C = Array.isArray;
47
+ let P = Array.isArray, x = Buffer.from("\n"), O = Buffer.from("'");
47
48
 
48
49
  class t {
49
50
  constructor(t, a) {
@@ -51,12 +52,12 @@ class t {
51
52
  ...n("QySnapshots"),
52
53
  ...a
53
54
  }).vLOutdatedPercent = 2 * a.pMOutdatedPercent;
54
- var o = s(t, "info");
55
+ var e = s(t, "info");
55
56
  Object.assign(this, {
56
57
  snapshotFolder: t,
57
- snapshotInfoFolder: o,
58
+ snapshotInfoFolder: e,
58
59
  options: a,
59
- qyJsonSaver: new S(o, a),
60
+ qyJsonSaver: new c(e, a),
60
61
  numToSnapshotMap: {},
61
62
  keyToSnapshotMap: {},
62
63
  fDMap: {},
@@ -70,70 +71,72 @@ class t {
70
71
  let {
71
72
  snapshotInfoFolder: t,
72
73
  qyJsonSaver: h,
73
- numToSnapshotMap: l
74
+ numToSnapshotMap: f
74
75
  } = this;
75
76
  if (await m(t)) {
76
- var a = (await f(t)).filter(t => /^[1-9]/.test(t)).map(t => parseInt(t)).sort((t, a) => t - a);
77
+ var a = (await l(t)).filter(t => /^[1-9]/.test(t)).map(t => parseInt(t)).sort((t, a) => t - a);
77
78
  let p = 0, u = 0;
78
79
  await Promise.all(a.map(async t => {
79
- var a = await h.loadFromFile(t + ".json"), o = l[t] = {
80
+ var a = await h.loadFromFile(t + ".json"), e = f[t] = {
80
81
  snapshotNum: t,
81
82
  info: a,
82
83
  posMap: {},
83
84
  outdatedCount: 0
84
85
  };
85
86
  ++this.snapshotCount, t > p && (p = t, u = a.maxChangeId);
86
- var t = o, a = O(a = this, t), e = (c.info("Loading " + a), await d(a)), s = e.length, n = t.prefixPM = {};
87
+ var t = e, a = L(a = this, t), o = (C.info("Loading " + a), await d(a)), s = o.length, n = t.prefixPM = {};
87
88
  for (let t = 0; t < s; ) {
88
- var r = t + j, i = e.toString("latin1", t, r), i = n[i] = [];
89
- t = M(e, r, i);
89
+ var r = t + V, i = o.toString("latin1", t, r), i = n[i] = [];
90
+ t = g(o, r, i);
90
91
  }
91
92
  })), Object.assign(this, {
92
93
  maxSnapshotNum: p,
93
94
  snapshotMaxChangeId: u
94
95
  });
95
96
  var {
96
- numToSnapshotMap: o,
97
- prefixMap: e
97
+ numToSnapshotMap: e,
98
+ prefixMap: o
98
99
  } = this;
99
100
  for (r of a) {
100
- var s, n = o[r], r = n.prefixPM;
101
+ var s, n = e[r], r = n.prefixPM;
101
102
  for (s in r) {
102
- var i = e[s];
103
- i ? i.push(n) : e[s] = [ n ];
103
+ var i = o[s];
104
+ i ? i.push(n) : o[s] = [ n ];
104
105
  }
105
106
  }
106
107
  }
107
108
  }
108
109
  closeAllFDs() {
109
110
  var t, a = this.fDMap;
110
- for (t in a) e(a[t]), delete a[t];
111
+ for (t in a) o(a[t]), delete a[t];
111
112
  }
112
113
  saveKeyValueMap(t) {
113
114
  var a, {
114
- keyValueMap: o,
115
- info: e
116
- } = t, s = (++e.vLVersion, new v()), n = (s.start(this.getVLFilePath(t)),
117
- Object.keys(o).sort()), r = {};
118
- let i = 0, p = 0;
115
+ keyValueMap: e,
116
+ info: o
117
+ } = t, s = (++o.vLVersion, new M()), n = (s.start(this.getVLFilePath(t)),
118
+ Object.keys(e).sort()), r = {};
119
+ let i = 0, p = 0, u;
119
120
  for (a of n) {
120
- var u, h = o[a];
121
+ var h, f = e[a];
121
122
  let t;
122
- null == h ? t = F : (u = Buffer.isBuffer(h) ? h : (u = a, h = h, Buffer.from(JSON.stringify(N(u) && !C(h) ? Object.keys(h) : h) + "\n")),
123
- h = (s.save(u), u).length, t = [ i, h ], i += h), r[a] = t, ++p;
123
+ null == f ? t = N : (u = Buffer.isBuffer(f) ? (s.save(f), f.length) : v(f) ? (h = Buffer.from(f),
124
+ s.save(O), s.save(h), s.save(x), h.length + 2) : (h = Buffer.from(JSON.stringify(B(a) && !P(f) ? Object.keys(f) : f)),
125
+ s.save(h), s.save(x), h.length + 1), t = [ i, u ], i += u), r[a] = t,
126
+ ++p;
124
127
  }
125
128
  return Object.assign(t, {
126
129
  posMap: r,
127
130
  outdatedCount: 0
128
- }), Object.assign(e, {
131
+ }), Object.assign(o, {
129
132
  totalCount: p,
130
133
  outdatedCount: 0
131
134
  }), Promise.all([ this.savePosMap(t, n), s.stop() ]);
132
135
  }
133
136
  addMaxSnapshot(t) {
134
137
  var a, {
135
- numToSnapshotMap: o,
136
- keyToSnapshotMap: e
138
+ numToSnapshotMap: e,
139
+ keyToSnapshotMap: o
137
140
  } = this, {
138
141
  posMap: s,
139
142
  keyValueMap: n,
@@ -143,77 +146,77 @@ class t {
143
146
  maxSnapshotNum: r,
144
147
  snapshotMaxChangeId: i
145
148
  }), n || s);
146
- for (a in i) e[a] = t;
147
- o[r] = t, ++this.snapshotCount;
149
+ for (a in i) o[a] = t;
150
+ e[r] = t, ++this.snapshotCount;
148
151
  }
149
152
  removeKey(t) {
150
- var a = this.keyToSnapshotMap, o = a[t];
151
- if (o) return this.removeKeyFromSnapshot(o, t), delete a[t], !0;
153
+ var a = this.keyToSnapshotMap, e = a[t];
154
+ if (e) return this.removeKeyFromSnapshot(e, t), delete a[t], !0;
152
155
  }
153
- applyCmdObj(t, a, o) {
154
- if (null != o) {
155
- var e = o.length;
156
- for (let t = 0; t < e; t += 2) {
157
- var s = o[t], n = o[t + 1];
158
- a[s] = null != n && N(s) ? r(n) : n;
156
+ applyCmdObj(t, a, e) {
157
+ if (null != e) {
158
+ var o = e.length;
159
+ for (let t = 0; t < o; t += 2) {
160
+ var s = e[t], n = e[t + 1];
161
+ a[s] = null != n && B(s) ? r(n) : n;
159
162
  }
160
163
  }
161
- y(t, t => {
164
+ S(t, t => {
162
165
  t in a || (a[t] = this.getValueSync(t)), this.removeKey(t);
163
- }), l(a, t);
166
+ }), f(a, t);
164
167
  }
165
168
  getValueSync(t) {
166
169
  var a = ((t, a) => {
167
170
  let {
168
- keyToSnapshotMap: o,
169
- prefixMap: e
170
- } = t, s = o[a];
171
+ keyToSnapshotMap: e,
172
+ prefixMap: o
173
+ } = t, s = e[a];
171
174
  if (s) return s;
172
- var n = L(a), r = e[n];
175
+ var n = b(a), r = o[n];
173
176
  if (r) for (;0 < r.length; ) {
174
177
  s = r.pop();
175
- var i = ((t, a, o) => {
176
- var e, {
178
+ var i = ((t, a, e) => {
179
+ var o, {
177
180
  posMap: s,
178
181
  prefixPM: n
179
182
  } = a;
180
- if (n = n[o]) return [ n, e ] = n, n = P(t, t.getPMFilePath(a), n, e),
181
- t.loadPartialPosMapBuffer(a, o, n), s;
183
+ if (n = n[e]) return [ n, o ] = n, n = F(t, t.getPMFilePath(a), n, o),
184
+ t.loadPartialPosMapBuffer(a, e, n), s;
182
185
  })(t, s, n);
183
186
  if (i && a in i) return s;
184
187
  }
185
188
  })(this, t);
186
189
  if (a) {
187
190
  var {
188
- keyValueMap: o,
189
- posMap: e
191
+ keyValueMap: e,
192
+ posMap: o
190
193
  } = a;
191
- if (o) return o[t];
192
- o = e[t];
193
- if (o) {
194
- var [ e, o ] = o;
195
- if (0 != o) {
194
+ if (e) return e[t];
195
+ e = o[t];
196
+ if (e) {
197
+ var [ o, e ] = e;
198
+ if (0 != e) {
196
199
  var s = this;
197
- if (a = s.getVLFilePath(a), s = P(s, a, e, o)) return a = t,
198
- e = s, e = JSON.parse(e), N(a) ? r(e) : e;
200
+ if (a = s.getVLFilePath(a), s = F(s, a, o, e)) return s[0] == O[0] ? s.toString("utf8", 1, s.length - 1) : (a = JSON.parse(s),
201
+ B(t) ? r(a) : a);
199
202
  }
200
203
  }
201
204
  }
202
205
  }
203
- iterPMBuffer(a, o) {
204
- var e = a.length;
205
- for (let t = 0; t < e; ) {
206
+ iterPMBuffer(a, e) {
207
+ var o = a.length;
208
+ for (let t = 0; t < o; ) {
206
209
  var s = t + u, n = a.toString("latin1", t, s), r = [];
207
- t = M(a, s, r), o(n, r);
210
+ t = g(a, s, r), e(n, r);
208
211
  }
209
212
  }
210
- loadPartialPosMapBuffer(o, t, a) {
213
+ loadPartialPosMapBuffer(e, t, a) {
211
214
  let {
212
- posMap: e,
215
+ posMap: o,
213
216
  prefixPM: s
214
- } = o, n = (delete s[t], this).keyToSnapshotMap;
217
+ } = e, n = (delete s[t], this).keyToSnapshotMap;
215
218
  this.iterPMBuffer(a, (t, a) => {
216
- t in n ? ++o.outdatedCount : (e[t] = a, n[t] = o);
219
+ t in n ? ++e.outdatedCount : (o[t] = a, n[t] = e);
217
220
  });
218
221
  }
219
222
  delSnapshot(t) {
@@ -221,7 +224,7 @@ class t {
221
224
  a(this, this.getPMFilePath(t));
222
225
  }
223
226
  calOutdates() {
224
- var t, a = [], o = [], e = [], s = [], {
227
+ var t, a = [], e = [], o = [], s = [], {
225
228
  options: n,
226
229
  numToSnapshotMap: r
227
230
  } = this, {
@@ -230,23 +233,23 @@ class t {
230
233
  } = n;
231
234
  for (t in r) {
232
235
  var u, h = r[t];
233
- h.isOut || (100 == (u = V(h)) ? (this.delSnapshot(h), a.push(t)) : p < u ? (x(h) ? o : s).push(h) : Math.round(h.outdatedCount / h.info.totalCount * 100) > i ? e.push(h) : (u = this,
234
- h.info.totalCount < u.options.minSnapshotKeyCount && x(h) && o.push(h)));
236
+ h.isOut || (100 == (u = T(h)) ? (this.delSnapshot(h), a.push(t)) : p < u ? (j(h) ? e : s).push(h) : Math.round(h.outdatedCount / h.info.totalCount * 100) > i ? o.push(h) : (u = this,
237
+ h.info.totalCount < u.options.minSnapshotKeyCount && j(h) && e.push(h)));
235
238
  }
236
- return 1 == o.length && V(o[0]) < p && (o.length = 0), 0 < e.length && c.log("pMCompacts:" + e.map(t => t.snapshotNum)),
237
- 0 < s.length && c.log("vLCompacts:" + s.map(t => t.snapshotNum)), 0 < o.length && c.log("combiningSnapshots:" + o.map(t => t.snapshotNum)),
239
+ return 1 == e.length && T(e[0]) < p && (e.length = 0), 0 < o.length && C.log("pMCompacts:" + o.map(t => t.snapshotNum)),
240
+ 0 < s.length && C.log("vLCompacts:" + s.map(t => t.snapshotNum)), 0 < e.length && C.log("combiningSnapshots:" + e.map(t => t.snapshotNum)),
238
241
  {
239
242
  emptySnapshotNumList: a,
240
- combiningSnapshotList: o,
241
- pMCompactSnapshotList: e,
243
+ combiningSnapshotList: e,
244
+ pMCompactSnapshotList: o,
242
245
  vLCompactSnapshotList: s
243
246
  };
244
247
  }
245
248
  getMaxCombinedSnapshot(t) {
246
- let a, o;
247
- for (var e of t) {
248
- var s = e.snapshotNum;
249
- (!o || o < s) && (a = e, o = s);
249
+ let a, e;
250
+ for (var o of t) {
251
+ var s = o.snapshotNum;
252
+ (!e || e < s) && (a = o, e = s);
250
253
  }
251
254
  return a;
252
255
  }
@@ -266,30 +269,30 @@ class t {
266
269
  }
267
270
  saveSnapshotInfo(t, a) {
268
271
  var {
269
- outdatedCount: o,
270
- totalCount: e
272
+ outdatedCount: e,
273
+ totalCount: o
271
274
  } = a;
272
- return a.outdated = Math.round(100 * o / e) + "%", c.log("Saving snapshotInfo:" + t),
275
+ return a.outdated = Math.round(100 * e / o) + "%", C.log("Saving snapshotInfo:" + t),
273
276
  this.qyJsonSaver.saveToFile(a, t + ".json", !0);
274
277
  }
275
278
  savePosMap(t, a) {
276
- var o, {
277
- outdatedCount: e,
279
+ var e, {
280
+ outdatedCount: o,
278
281
  info: s,
279
282
  posMap: n
280
- } = t, r = (s.outdatedCount += e, t.outdatedCount = 0, ++s.pMVersion, new v()), i = (r.start(this.getPMFilePath(t)),
283
+ } = t, r = (s.outdatedCount += o, t.outdatedCount = 0, ++s.pMVersion, new M()), i = (r.start(this.getPMFilePath(t)),
281
284
  t.prefixPM = {});
282
285
  let p = 0, u = 0, h;
283
- for (o of a = a || Object.keys(n).sort()) {
284
- null == h ? h = L(o) : o.startsWith(h) || (i[h] = [ p, u ], h = L(o),
286
+ for (e of a = a || Object.keys(n).sort()) {
287
+ null == h ? h = b(e) : e.startsWith(h) || (i[h] = [ p, u ], h = b(e),
285
288
  p += u, u = 0);
286
- var l = Buffer.from(o), f = g(n[o]);
287
- r.save(l), r.save(f), u += l.length + f.length;
289
+ var f = Buffer.from(e), l = y(n[e]);
290
+ r.save(f), r.save(l), u += f.length + l.length;
288
291
  }
289
292
  return null != h && (i[h] = [ p, u ]), Promise.all([ r.stop(), ((t, a) => {
290
- var o, e = new v(), s = (e.start(O(t, a)), a).prefixPM;
291
- for (o in s) e.save(Buffer.from(o)), e.save(g(s[o]));
292
- return e.stop();
293
+ var e, o = new M(), s = (o.start(L(t, a)), a).prefixPM;
294
+ for (e in s) o.save(Buffer.from(e)), o.save(y(s[e]));
295
+ return o.stop();
293
296
  })(this, t) ]);
294
297
  }
295
298
  isEmptySnapshot(t) {
@@ -301,71 +304,71 @@ class t {
301
304
  }
302
305
  removeKeyFromSnapshot(t, a) {
303
306
  var {
304
- posMap: o,
305
- keyValueMap: e
307
+ posMap: e,
308
+ keyValueMap: o
306
309
  } = t;
307
- e && delete e[a], o && delete o[a], ++t.outdatedCount;
310
+ o && delete o[a], e && delete e[a], ++t.outdatedCount;
308
311
  }
309
312
  }
310
313
 
311
- function P(t, a, o, e) {
314
+ function F(t, a, e, o) {
312
315
  var s = ((t, a) => {
313
- let o = t.fDMap, e = o[a];
314
- if (!e) {
315
- c.info("Opening " + a);
316
+ let e = t.fDMap, o = e[a];
317
+ if (!o) {
318
+ C.info("Opening " + a);
316
319
  try {
317
- e = o[a] = p(a, "r");
320
+ o = e[a] = p(a, "r");
318
321
  } catch (t) {
319
- throw c.error(`Opening ${a} failed:`, t), t;
322
+ throw C.error(`Opening ${a} failed:`, t), t;
320
323
  }
321
324
  }
322
- return e;
323
- })(t, a), n = Buffer.allocUnsafe(e);
324
- for (let t = 0; t < e; ) {
325
- var r = i(s, n, t, e - t, o + t);
326
- if (0 == r) return void c.error(`readSync ${a} at ${o + t} returning 0 byte`);
325
+ return o;
326
+ })(t, a), n = Buffer.allocUnsafe(o);
327
+ for (let t = 0; t < o; ) {
328
+ var r = i(s, n, t, o - t, e + t);
329
+ if (0 == r) return void C.error(`readSync ${a} at ${e + t} returning 0 byte`);
327
330
  t += r;
328
331
  }
329
332
  return n;
330
333
  }
331
334
 
332
- function x(t) {
335
+ function j(t) {
333
336
  var {
334
337
  keyValueMap: a,
335
- prefixPM: o
338
+ prefixPM: e
336
339
  } = t;
337
- return a || null == o || h(t.prefixPM);
340
+ return a || null == e || h(t.prefixPM);
338
341
  }
339
342
 
340
- function O(t, a) {
343
+ function L(t, a) {
341
344
  var {
342
345
  snapshotNum: a,
343
- info: o
346
+ info: e
344
347
  } = a;
345
- return s(t.snapshotFolder, "" + a, o.pMVersion + "_prefixPM.txt");
348
+ return s(t.snapshotFolder, "" + a, e.pMVersion + "_prefixPM.txt");
346
349
  }
347
350
 
348
351
  function a(t, a) {
349
- var t = t.fDMap, o = t[a];
350
- null != o && (e(o), delete t[a]);
352
+ var t = t.fDMap, e = t[a];
353
+ null != e && (o(e), delete t[a]);
351
354
  }
352
355
 
353
- let F = [ 0, 0 ], j = 3;
356
+ let N = [ 0, 0 ], V = 3;
354
357
 
355
- function L(t) {
356
- return t.substring(0, j);
358
+ function b(t) {
359
+ return t.substring(0, V);
357
360
  }
358
361
 
359
- function N(t) {
362
+ function B(t) {
360
363
  return !t.startsWith("c");
361
364
  }
362
365
 
363
- function V(t) {
366
+ function T(t) {
364
367
  var {
365
368
  outdatedCount: t,
366
369
  info: a
367
- } = t, o = a.totalCount, t = t + a.outdatedCount;
368
- return t == o ? 100 : Math.round(t / o * 100);
370
+ } = t, e = a.totalCount, t = t + a.outdatedCount;
371
+ return t == e ? 100 : Math.round(t / e * 100);
369
372
  }
370
373
 
371
374
  export {
@@ -1,32 +1,16 @@
1
- let t = new Error("No such dir");
1
+ let h = new Error("No such dir");
2
2
 
3
3
  module.exports = ({
4
4
  dirPath: e,
5
5
  dChangeId: a,
6
6
  fChangeId: d
7
7
  }) => {
8
- e = qyDB.dirP(e);
9
- if (!e) return t;
10
- var r = {};
11
- if (a || d || (r.fullPathHash = e.fullPathHash), a != e.dChangeId) {
12
- var s, a = e.sortedSubdirList, h = [];
13
- for ({
14
- name: s
15
- } of a) h.push(s);
16
- Object.assign(r, {
17
- subdirList: h,
18
- dChangeId: e.dChangeId
19
- });
20
- }
21
- if (d != e.fChangeId) {
22
- var i, a = e.sortedFileList, n = [];
23
- for ({
24
- name: i
25
- } of a) n.push(i);
26
- Object.assign(r, {
27
- fileList: n,
28
- fChangeId: e.fChangeId
29
- });
30
- }
31
- return r;
8
+ var s, e = qyDB.dirP(e);
9
+ return e ? (s = {}, a || d || (s.fullPathHash = e.fullPathHash), a != e.dChangeId && Object.assign(s, {
10
+ subdirList: e.sortedSubdirList.map(e => e.name),
11
+ dChangeId: e.dChangeId
12
+ }), d != e.fChangeId && Object.assign(s, {
13
+ fileList: e.sortedFileList.map(e => e.name),
14
+ fChangeId: e.fChangeId
15
+ }), s) : h;
32
16
  };
@@ -5,29 +5,6 @@ module.exports = queryText => {
5
5
  view,
6
6
  limit,
7
7
  cursor
8
- } = eval("((x)=>x)(" + queryText + ")"), fileList = qyDB.queryFiles(folder, value, limit, cursor), tree = {};
9
- for (var file of fileList) {
10
- let {
11
- parentList
12
- } = file, node = tree;
13
- for (var dir of parentList) {
14
- let {
15
- name,
16
- fullPathHash
17
- } = dir, subdirMap = node.subdirMap;
18
- subdirMap = subdirMap || (node.subdirMap = {}), node = subdirMap[name],
19
- node = node || (subdirMap[name] = {
20
- fullPathHash: fullPathHash
21
- });
22
- }
23
- let fileMap = node.fileMap;
24
- fileMap = fileMap || (node.fileMap = {}), fileMap[file.name] = {
25
- fileContent: file.view(view, !0),
26
- fileContentKey: file.fileContentKey
27
- };
28
- }
29
- return {
30
- tree: tree,
31
- count: fileList.length
32
- };
8
+ } = eval("((x)=>x)(" + queryText + ")");
9
+ return qyDB.fileListToTree(qyDB.queryFiles(folder, value, limit, cursor), view);
33
10
  };
@@ -49,7 +49,7 @@ customElements.define("query-editor", class extends HTMLElement {
49
49
  super();
50
50
  }
51
51
  compose() {
52
- this.append(h("div", {
52
+ this.append(this._createEditor(), h("div", {
53
53
  classList: "btn-toolbar",
54
54
  role: "toolbar",
55
55
  style: {
@@ -121,6 +121,11 @@ customElements.define("query-editor", class extends HTMLElement {
121
121
  }
122
122
  }) ]);
123
123
  }
124
+ _createEditor() {
125
+ return h("textarea", {
126
+ style: "height:50px;width:100%"
127
+ });
128
+ }
124
129
  _createDropDownButton() {
125
130
  return h("div", {
126
131
  classList: "btn-group btn-grou-sm"