datafolder 1.0.11 → 1.0.13

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 (75) hide show
  1. package/README.md +16 -0
  2. package/package.json +1 -1
  3. package/scripts/airbnb.js +1 -1
  4. package/scripts/airbnb2.js +1 -1
  5. package/scripts/flights.js +2 -2
  6. package/scripts/flights2.js +4 -2
  7. package/src/QyAcl.d.ts +13 -7
  8. package/src/QyAcl.js +122 -138
  9. package/src/QyAclSaver.js +2 -2
  10. package/src/QyAclSaver_Worker.d.ts +2 -2
  11. package/src/QyBatch.d.ts +16 -12
  12. package/src/QyBatch.js +339 -228
  13. package/src/QyBinWriter.d.ts +1 -1
  14. package/src/QyBinWriter.js +15 -15
  15. package/src/QyCD.d.ts +2 -2
  16. package/src/QyCD.js +29 -29
  17. package/src/QyCache.d.ts +9 -1
  18. package/src/QyCache.js +110 -73
  19. package/src/QyCompressor.d.ts +2 -2
  20. package/src/QyCompressor.js +13 -13
  21. package/src/QyDB.d.ts +4 -22
  22. package/src/QyDB.js +49 -89
  23. package/src/QyDefaultOptions.js +2 -0
  24. package/src/QyDir.d.ts +1 -0
  25. package/src/QyDir.js +58 -30
  26. package/src/QyExpire.d.ts +15 -0
  27. package/src/QyExpire.js +105 -0
  28. package/src/QyExpireInfo.d.ts +10 -0
  29. package/src/QyExpireInfo.js +92 -0
  30. package/src/QyExpire_Worker.d.ts +19 -0
  31. package/src/QyExpire_Worker.js +112 -0
  32. package/src/QyFile.d.ts +1 -1
  33. package/src/QyFile.js +68 -42
  34. package/src/QyFileContentUtils.d.ts +1 -0
  35. package/src/QyFileContentUtils.js +108 -94
  36. package/src/QyItem.d.ts +7 -0
  37. package/src/QyItem.js +39 -15
  38. package/src/QyJsonSaver.d.ts +1 -1
  39. package/src/QyJsonSaver.js +1 -1
  40. package/src/QyKVData.d.ts +6 -1
  41. package/src/QyKVData.js +176 -157
  42. package/src/QyKVDataCleaner.js +2 -2
  43. package/src/QyKVDataSaver.js +2 -2
  44. package/src/QyKVDataSaver_Worker.d.ts +2 -2
  45. package/src/QyKVDataSaver_Worker.js +5 -5
  46. package/src/QyLogFileSaver.js +2 -2
  47. package/src/QyMessageWorker.d.ts +1 -1
  48. package/src/QyMessageWorker.js +10 -10
  49. package/src/QyMessager.d.ts +1 -1
  50. package/src/QyMessager.js +37 -36
  51. package/src/QyMessager_Run.js +9 -6
  52. package/src/QyQueue.js +8 -12
  53. package/src/QySaver.d.ts +1 -1
  54. package/src/QySaver.js +1 -1
  55. package/src/QySnapshotCompactor.js +2 -2
  56. package/src/QySnapshotCompactor_Worker.js +1 -1
  57. package/src/QySnapshotSaver.js +2 -2
  58. package/src/QySnapshotSaver_Worker.js +1 -1
  59. package/src/QyTrigger.d.ts +1 -1
  60. package/src/QyTrigger.js +20 -21
  61. package/src/QyUtils.d.ts +5 -2
  62. package/src/QyUtils.js +112 -98
  63. package/src/hackernews.js +1 -1
  64. package/src/simulate.js +6 -6
  65. package/src/simulate2.js +4 -4
  66. package/src/soc_pokec.js +1 -1
  67. package/static/codemirror.bundle/editor.bundle.js +49 -10
  68. package/static/datafolderui/QyUIFolderViewer.js +1 -5
  69. package/src/rpc/evalCode.js +0 -9
  70. package/src/rpc/getFileContent.js +0 -16
  71. package/src/rpc/getRpcFiles.js +0 -1
  72. package/src/rpc/getSubItems.js +0 -16
  73. package/src/rpc/getTriggerFiles.js +0 -1
  74. package/src/rpc/queryFiles.js +0 -10
  75. package/src/rpc/reloadRpc.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import {
2
- extname as t
2
+ extname as i
3
3
  } from "node:path";
4
4
 
5
5
  import {
@@ -27,7 +27,7 @@ import {
27
27
  } from "./QyLogger.js";
28
28
 
29
29
  import {
30
- isNotNullObj as i,
30
+ isNotNullObj as t,
31
31
  folderOrFileExists as l,
32
32
  ensureParentDir as f
33
33
  } from "./QyUtils.js";
@@ -38,8 +38,8 @@ import {
38
38
 
39
39
  let g = r(e), o = ".gz", h = "QyCompressor_Worker.ts";
40
40
 
41
- function w(e, r, o) {
42
- return i(r) && (o = r, r = void 0), r = r || e + ".gz", o = o || {}, e.endsWith(".gz") ? (p.log(e + " already ends with .gz."),
41
+ function w(e, r = void 0, o = void 0) {
42
+ return t(r) && (o = r, r = void 0), r = r || e + ".gz", o = o || {}, e.endsWith(".gz") ? (p.log(e + " already ends with .gz."),
43
43
  !1) : r.endsWith(".gz") ? c(h, {
44
44
  operation: "compress",
45
45
  srcFilePath: e,
@@ -48,9 +48,9 @@ function w(e, r, o) {
48
48
  }).promise : (p.log(r + " doesn't end with .gz."), !1);
49
49
  }
50
50
 
51
- function z(e, r, o) {
52
- return e.endsWith(".gz") ? (i(r) && (o = r, r = void 0), r = r || e.replace(new RegExp(".gz$"), ""),
53
- o = o || {}, ".gz" == t(r) ? (p.log(r + " already ends with .gz."), !1) : c(h, {
51
+ function z(e, r = void 0, o = void 0) {
52
+ return e.endsWith(".gz") ? (t(r) && (o = r, r = void 0), r = r || e.replace(new RegExp(".gz$"), ""),
53
+ o = o || {}, ".gz" == i(r) ? (p.log(r + " already ends with .gz."), !1) : c(h, {
54
54
  operation: "decompress",
55
55
  srcFilePath: e,
56
56
  destFilePath: r,
@@ -62,16 +62,16 @@ async function u({
62
62
  operation: e,
63
63
  srcFilePath: r,
64
64
  destFilePath: o,
65
- options: t
65
+ options: i
66
66
  }) {
67
67
  var {
68
- removeSrcAfterSuccess: t,
69
- override: i
70
- } = t;
68
+ removeSrcAfterSuccess: i,
69
+ override: t
70
+ } = i;
71
71
  if (!await l(r)) throw new Error(r + " doesn't exist.");
72
- if (!i && await l(o)) throw new Error(o + " already exists.");
72
+ if (!t && await l(o)) throw new Error(o + " already exists.");
73
73
  if (await f(o), await g(n(r), ("compress" == e ? s : a)(), d(o)), p.info(e + `ed ${r} to ${o}.`),
74
- t) try {
74
+ i) try {
75
75
  await m.unlink(r), p.info("Unlinked " + r);
76
76
  } catch (e) {
77
77
  p.error(`Failed to unlink ${r}:`, e);
package/src/QyDB.d.ts CHANGED
@@ -7,33 +7,15 @@ export declare class QyDB extends QyCD {
7
7
  fetch: any;
8
8
  batch: any;
9
9
  _immediate: any;
10
+ creationTime: any;
10
11
  constructor(rootFolder?: string, options?: {});
11
12
  start(options?: {}): Promise<this>;
12
13
  stop(): Promise<void>;
14
+ get age(): number;
15
+ get ageSecond(): number;
16
+ get currentBatch(): any;
13
17
  createDir(namePath: string | string[]): QyDir;
14
- createDirP(namePath: string | string[]): QyDir;
15
18
  createFile(namePath: string | string[]): QyFile;
16
- createFileP(namePath: string | string[]): QyFile;
17
- createIndex(indexHostDirNamePath: string | string[] | QyDir, indexPropPathList: string[] | string[][]): any;
18
- createIndexP(indexHostDirNamePath: string | string[] | QyDir, indexPropPathList: string[][]): any;
19
- delIndex(indexHostDirNamePath: string | string[] | QyDir, indexPropPath: string | string[]): any;
20
- delIndexP(indexHostDirNamePath: any, indexPropPath: any): any;
21
- insert(namePath: any, content: any): any;
22
- insertP(namePath: any, content: any): any;
23
- remove(namePath: any, content: any): any;
24
- removeP(namePath: any, content: any): any;
25
- replace(namePath: any, content: any): any;
26
- replaceP(namePath: any, content: any): any;
27
- delDir(namePath: any): any;
28
- delDirP(namePath: any): any;
29
- delFile(namePath: any): any;
30
- delFileP(namePath: any): any;
31
- delContent(namePath: any): any;
32
- delContentP(namePath: any): any;
33
- insertTrigger(triggerName: any, fileNamePath: any, propNamePathList: any, modCode: any): any;
34
- removeTrigger(triggerName: any): any;
35
- insertRpc(rpcFunName: any, modCode: any): any;
36
- removeRpc(rpcFunName: any): any;
37
19
  on(eventName: any, listener: any): any;
38
20
  callRpc(rpcFunName: any, args: any, body?: undefined): any;
39
21
  }
package/src/QyDB.js CHANGED
@@ -3,19 +3,19 @@ import {
3
3
  } from "node:path";
4
4
 
5
5
  import {
6
- QyFetch as r
6
+ QyFetch as i
7
7
  } from "./QyFetch.js";
8
8
 
9
9
  import {
10
- QyBatch as i
10
+ QyBatch as r
11
11
  } from "./QyBatch.js";
12
12
 
13
13
  import {
14
- QyCache as n
14
+ QyCache as a
15
15
  } from "./QyCache.js";
16
16
 
17
17
  import {
18
- getDefaultOptions as a
18
+ getDefaultOptions as o
19
19
  } from "./QyDefaultOptions.js";
20
20
 
21
21
  import {
@@ -24,130 +24,90 @@ import {
24
24
 
25
25
  import {
26
26
  isNotNullObj as s,
27
- __dirname as m
27
+ __dirname as n,
28
+ getNowTime as c,
29
+ getNowRounded as h
28
30
  } from "./QyUtils.js";
29
31
 
30
- let d = e(m, "../data/sampleDataFolder");
32
+ import {
33
+ logger as m
34
+ } from "./QyLogger.js";
35
+
36
+ let l = e(n, "../data/sampleDataFolder");
31
37
 
32
- class h extends t {
38
+ class d extends t {
33
39
  rootFolder;
34
40
  options;
35
41
  fetch;
36
42
  batch;
37
43
  _immediate;
38
- constructor(e = d, t) {
39
- s(e) && (t = e, e = d), super(), this.options = {
40
- ...a("QyDB"),
44
+ creationTime;
45
+ constructor(e = l, t) {
46
+ s(e) && (t = e, e = l), super(), this.options = {
47
+ ...o("QyDB"),
41
48
  ...t
42
49
  }, this.rootFolder = e;
50
+ for (let i of [ "createIndex", "delIndex", "insert", "put", "remove", "delDir", "delFile", "delContent", "insertTrigger", "removeTrigger", "insertRpc", "removeRpc", "expireFile", "expireDir", "expireContent", "removeFileExpire", "removeDirExpire", "removeContentExpire" ]) this[i] = (...e) => {
51
+ var t = this.currentBatch;
52
+ return t[i].apply(t, e).run();
53
+ };
43
54
  }
44
55
  async start(e) {
45
56
  var t;
46
57
  return this.qyCache || (e = {
47
58
  ...this.options,
48
59
  ...e
49
- }, t = new n(this.rootFolder, e, this), Object.assign(this, {
60
+ }, t = new a(this.rootFolder, e, this), e = (Object.assign(this, {
50
61
  qyCache: t,
51
- fetch: new r(t),
52
- batch: new i(t, e),
53
- _immediate: new i(t, e)
54
- }), await t.start()), this;
62
+ fetch: new i(t),
63
+ batch: new r(t, e),
64
+ _immediate: new r(t, e)
65
+ }), await t.start(), t).metaFile, e.created ? this.creationTime = e.fileContent.creationTime : this.insert(e, {
66
+ creationTime: this.creationTime = h()
67
+ }, !0), m.log("CreationTime:" + new Date(this.creationTime))), this;
55
68
  }
56
69
  async stop() {
57
70
  var {
58
71
  qyCache: e,
59
72
  fetch: t,
60
- batch: r,
61
- _immediate: i
73
+ batch: i,
74
+ _immediate: r
62
75
  } = this;
63
- e && (await e.stop(), t && (t.qyCache = void 0), r && (r.qyCache = void 0),
64
- i && (i.qyCache = void 0), Object.assign(this, {
76
+ e && (await e.stop(), t && (t.qyCache = void 0), i && (i.qyCache = void 0),
77
+ r && (r.qyCache = void 0), Object.assign(this, {
65
78
  qyCache: void 0,
66
79
  fetch: void 0,
67
80
  batch: void 0,
68
81
  _immediate: void 0
69
82
  }));
70
83
  }
71
- createDir(e) {
72
- return this._immediate.createDir(e).run(), this.dir(e);
73
- }
74
- createDirP(e) {
75
- return this._immediate.createDirP(e).run(), this.dirP(e);
76
- }
77
- createFile(e) {
78
- return this._immediate.createFile(e).run(), this.file(e);
79
- }
80
- createFileP(e) {
81
- return this._immediate.createFileP(e).run(), this.fileP(e);
82
- }
83
- createIndex(e, t) {
84
- return this._immediate.createIndex(e, t).run();
85
- }
86
- createIndexP(e, t) {
87
- return this._immediate.createIndexP(e, t).run();
88
- }
89
- delIndex(e, t) {
90
- return this._immediate.delIndex(e, t).run();
91
- }
92
- delIndexP(e, t) {
93
- return this._immediate.delIndexP(e, t).run();
94
- }
95
- insert(e, t) {
96
- return this._immediate.insert(e, t).run();
97
- }
98
- insertP(e, t) {
99
- return this._immediate.insertP(e, t).run();
100
- }
101
- remove(e, t) {
102
- return this._immediate.remove(e, t).run();
84
+ get age() {
85
+ return c() - this.creationTime;
103
86
  }
104
- removeP(e, t) {
105
- return this._immediate.removeP(e, t).run();
87
+ get ageSecond() {
88
+ return Math.floor(this.age / 1e3);
106
89
  }
107
- replace(e, t) {
108
- return this._immediate.replace(e, t).run();
109
- }
110
- replaceP(e, t) {
111
- return this._immediate.replaceP(e, t).run();
112
- }
113
- delDir(e) {
114
- return this._immediate.delDir(e).run();
115
- }
116
- delDirP(e) {
117
- return this._immediate.delDirP(e).run();
118
- }
119
- delFile(e) {
120
- return this._immediate.delFile(e).run();
121
- }
122
- delFileP(e) {
123
- return this._immediate.delFileP(e).run();
124
- }
125
- delContent(e) {
126
- return this._immediate.delContent(e).run();
127
- }
128
- delContentP(e) {
129
- return this._immediate.delContentP(e).run();
130
- }
131
- insertTrigger(e, t, r, i) {
132
- return this._immediate.insertTrigger(e, t, r, i).run();
133
- }
134
- removeTrigger(e) {
135
- return this._immediate.removeTrigger(e).run();
90
+ get currentBatch() {
91
+ var {
92
+ batch: e,
93
+ _immediate: t
94
+ } = this;
95
+ return e.running ? e : t;
136
96
  }
137
- insertRpc(e, t) {
138
- return this._immediate.insertRpc(e, t).run();
97
+ createDir(e) {
98
+ return this.currentBatch.createDir(e).run(), this.dir(e);
139
99
  }
140
- removeRpc(e) {
141
- return this._immediate.removeRpc(e).run();
100
+ createFile(e) {
101
+ return this.currentBatch.createFile(e).run(), this.file(e);
142
102
  }
143
103
  on(e, t) {
144
104
  return this.qyCache?.on(e, t);
145
105
  }
146
- callRpc(e, t, r = void 0) {
147
- return this.qyCache?.callRpc(e, t, r);
106
+ callRpc(e, t, i = void 0) {
107
+ return this.qyCache?.callRpc(e, t, i);
148
108
  }
149
109
  }
150
110
 
151
111
  export {
152
- h as QyDB
112
+ d as QyDB
153
113
  };
@@ -1,3 +1,5 @@
1
+ import "./QyExpire.js";
2
+
1
3
  var e = {
2
4
  append: !1,
3
5
  retryIntervalFactor: 2,
package/src/QyDir.d.ts CHANGED
@@ -45,4 +45,5 @@ export declare class QyDir extends QyItem {
45
45
  filterSubdirNames(filterFun: any): Generator<QyDir, void, unknown>;
46
46
  compareSubdirRangeL2H(cmpFun: any): Generator<QyDir, void, unknown>;
47
47
  compareSubdirRangeH2L(cmpFun: any): Generator<QyDir | undefined, void, unknown>;
48
+ ensureAllLoaded(): this;
48
49
  }
package/src/QyDir.js CHANGED
@@ -6,17 +6,21 @@ import {
6
6
  getSubdirMapKey as i,
7
7
  getFileMapKey as t,
8
8
  SpecialFilePaths as r,
9
- arrayLast as s,
10
- isString as d
9
+ isString as d,
10
+ getNowTime as l
11
11
  } from "./QyUtils.js";
12
12
 
13
13
  import {
14
14
  QyFile as a
15
15
  } from "./QyFile.js";
16
16
 
17
- let u = r.HiddenFolderName;
17
+ import {
18
+ handleExpiredItem as o
19
+ } from "./QyExpire.js";
20
+
21
+ let s = r.HiddenFolderName;
18
22
 
19
- class h extends e {
23
+ class u extends e {
20
24
  _subdirCount = 0;
21
25
  _fileCount = 0;
22
26
  subdirMapChangeCount = 0;
@@ -36,7 +40,7 @@ class h extends e {
36
40
  ++i.subdirMapChangeCount);
37
41
  }
38
42
  get fileCount() {
39
- return o(this), this._fileCount;
43
+ return f(this), this._fileCount;
40
44
  }
41
45
  get subdirCount() {
42
46
  return n(this), this._subdirCount;
@@ -48,7 +52,7 @@ class h extends e {
48
52
  return 0 == this.fileCount && 0 == this.subdirCount;
49
53
  }
50
54
  get isHiddenFolder() {
51
- return this.name == u;
55
+ return this.name == s;
52
56
  }
53
57
  get subdirMapKey() {
54
58
  return this._subdirMapKey || (this._subdirMapKey = i(this.fullPathHash));
@@ -60,7 +64,7 @@ class h extends e {
60
64
  return n(this), this._subdirMap;
61
65
  }
62
66
  get fileMap() {
63
- return o(this), this._fileMap;
67
+ return f(this), this._fileMap;
64
68
  }
65
69
  getSubdir(e) {
66
70
  var i;
@@ -80,7 +84,7 @@ class h extends e {
80
84
  if ("/" === e) return this.qyCache?.rootDir || this;
81
85
  let t = this.subdirMap;
82
86
  var r = (t = t || (this._subdirMap = {}))[e];
83
- return r || (r = t[e] = new h(e, i, this), this.setChildTriggerNodes(r)),
87
+ return r || (r = t[e] = new u(e, i, this), this.setChildTriggerNodes(r)),
84
88
  r;
85
89
  }
86
90
  getOrCreateFile(e, i = !1) {
@@ -107,34 +111,34 @@ class h extends e {
107
111
  }
108
112
  searchFile(e) {
109
113
  var i = this.searchSubdir(e, e.length - 1);
110
- if (i) return i.getFile(s(e));
114
+ if (i) return i.getFile(e.at(-1));
111
115
  }
112
116
  searchOrCreateFile(e, i = !1) {
113
- return this.searchOrCreateSubdir(e, i, e.length - 1).getOrCreateFile(s(e), i);
117
+ return this.searchOrCreateSubdir(e, i, e.length - 1).getOrCreateFile(e.at(-1), i);
114
118
  }
115
119
  get subdirList() {
116
- return l(this, "_subdirList", this.subdirMapChangeCount, () => this.created && this.subdirMap ? Object.values(this.subdirMap).filter(e => e.created) : []);
120
+ return h(this, "_subdirList", this.subdirMapChangeCount, () => this.created && this.subdirMap ? Object.values(this.subdirMap).filter(e => e.created) : []);
117
121
  }
118
122
  get subdirNameList() {
119
- return l(this, "_subdirNameList", this.subdirMapChangeCount, () => this.subdirList.map(e => e.name));
123
+ return h(this, "_subdirNameList", this.subdirMapChangeCount, () => this.subdirList.map(e => e.name));
120
124
  }
121
125
  get sortedSubdirList() {
122
- return l(this, "_sortedSubdirList", this.subdirMapChangeCount, () => this.subdirList.sort((e, i) => e.cmp(i)));
126
+ return h(this, "_sortedSubdirList", this.subdirMapChangeCount, () => this.subdirList.sort((e, i) => e.cmp(i)));
123
127
  }
124
128
  get sortedSubdirNameList() {
125
- return l(this, "_sortedSubdirNameList", this.subdirMapChangeCount, () => this.sortedSubdirList.map(e => e.nameNum));
129
+ return h(this, "_sortedSubdirNameList", this.subdirMapChangeCount, () => this.sortedSubdirList.map(e => e.nameNum));
126
130
  }
127
131
  get fileList() {
128
- return l(this, "_fileList", this.fileMapChangeCount, () => this.created && this.fileMap ? Object.values(this.fileMap).filter(e => e.created) : []);
132
+ return h(this, "_fileList", this.fileMapChangeCount, () => this.created && this.fileMap ? Object.values(this.fileMap).filter(e => e.created) : []);
129
133
  }
130
134
  get fileNameList() {
131
- return l(this, "_fileNameList", this.fileMapChangeCount, () => this.fileList.map(e => e.name));
135
+ return h(this, "_fileNameList", this.fileMapChangeCount, () => this.fileList.map(e => e.name));
132
136
  }
133
137
  get sortedFileList() {
134
- return l(this, "_sortedFileList", this.fileMapChangeCount, () => this.fileList.sort((e, i) => e.cmp(i)));
138
+ return h(this, "_sortedFileList", this.fileMapChangeCount, () => this.fileList.sort((e, i) => e.cmp(i)));
135
139
  }
136
140
  get sortedFileNameList() {
137
- return l(this, "_sortedFileNameList", this.fileMapChangeCount, () => this.sortedFileList.map(e => e.nameNum));
141
+ return h(this, "_sortedFileNameList", this.fileMapChangeCount, () => this.sortedFileList.map(e => e.nameNum));
138
142
  }
139
143
  *allSubdirs() {
140
144
  var e, i, t = this.subdirList;
@@ -188,41 +192,65 @@ class h extends e {
188
192
  } else if (i(a)) yield s, r = !0; else if (r) return;
189
193
  }
190
194
  }
195
+ ensureAllLoaded() {
196
+ for (var e of this.allFiles()) e.ensureLoaded();
197
+ return this;
198
+ }
191
199
  }
192
200
 
193
- function l(e, i, t, r) {
201
+ function h(e, i, t, r) {
194
202
  var e = e.cache, s = i + "ChangeCount";
195
203
  return e[i] && e[s] == t || (e[i] = r(), e[s] = t), e[i];
196
204
  }
197
205
 
198
206
  function n(e) {
199
- if (e.created && !e._subdirMap && !e.subdirMapLoaded) {
207
+ if (e.created && !e.subdirMapLoaded) {
200
208
  e.subdirMapLoaded = !0;
201
209
  var i = e.qyCache;
202
210
  if (i) {
203
- i = i.qyKVData.getValueSync(e.subdirMapKey);
204
- if (i) {
205
- var t, r = e._subdirMap = {};
206
- for (t in i) r[t] = new h(t, !0, e);
211
+ var t = i.qyKVData.getValueSync(e.subdirMapKey);
212
+ if (t) {
213
+ var r, s = e._subdirMap || (e._subdirMap = {});
214
+ for (r in t) r in s || (s[r] = new u(r, !0, e));
215
+ e.underHiddenFolder || p(e, i, "d");
207
216
  }
208
217
  }
209
218
  }
210
219
  }
211
220
 
212
- function o(e) {
221
+ function f(e) {
213
222
  if (e.created && !e._fileMap && !e.fileMapLoaded) {
214
223
  e.fileMapLoaded = !0;
215
224
  var i = e.qyCache;
216
225
  if (i) {
217
- i = i.qyKVData.getValueSync(e.fileMapKey);
218
- if (i) {
219
- var t, r = e._fileMap = {};
220
- for (t in i) r[t] = new a(t, !0, e);
226
+ var t = i.qyKVData.getValueSync(e.fileMapKey);
227
+ if (t) {
228
+ var r, s = e._fileMap = {};
229
+ for (r in t) s[r] = new a(r, !0, e);
230
+ e.underHiddenFolder || p(e, i, "f");
221
231
  }
222
232
  }
223
233
  }
224
234
  }
225
235
 
236
+ function p(e, i, t) {
237
+ if ("d" == t) {
238
+ if (e.dExpireChecked) return;
239
+ e.dExpireChecked = !0;
240
+ } else {
241
+ if (e.fExpireChecked) return;
242
+ e.fExpireChecked = !0;
243
+ }
244
+ var r = i.getExpireInfoFile(e.fullPathHash, t);
245
+ if (r) {
246
+ var s, a = r.fileContent, d = l(), u = i.qyDB;
247
+ for (s in a) {
248
+ var h = "d" == t ? e.getOrCreateSubdir(s) : e.getOrCreateFile(s), n = a[s];
249
+ n <= d ? o(u, h) : i.monitorItemExpire(h, n);
250
+ }
251
+ }
252
+ }
253
+
226
254
  export {
227
- h as QyDir
255
+ u as QyDir
228
256
  };
@@ -0,0 +1,15 @@
1
+ import { QyMessager } from "./QyMessager.ts";
2
+ export declare class QyExpire extends QyMessager {
3
+ qyCache: any;
4
+ expireMap: {};
5
+ roundedStartTime: any;
6
+ constructor(qyCache: any, options?: any);
7
+ monitorItemExpire(item: any, expireAbsTime: any): void;
8
+ unmonitorItemExpire(item: any): void;
9
+ monitorContentExpire(file: any, flattedAbsTimeObj: any): void;
10
+ unmonitorContentExpire(file: any, flattedDelObj: any): void;
11
+ onEmptyHashList(emptyHashList: any): void;
12
+ onExpired(hashExpiredInfoMap: any): void;
13
+ }
14
+ export declare function handleExpiredItem(qyDB: any, item: any): void;
15
+ export declare function handleExpiredProps(qyDB: any, file: any, expiredProps: any): void;
@@ -0,0 +1,105 @@
1
+ import {
2
+ QyMessager as e
3
+ } from "./QyMessager.js";
4
+
5
+ import {
6
+ getDefaultOptions as r
7
+ } from "./QyDefaultOptions.js";
8
+
9
+ import {
10
+ getNowRounded as t,
11
+ isEmptyObj as i
12
+ } from "./QyUtils.js";
13
+
14
+ import {
15
+ setValByNamePath as o
16
+ } from "./QyFileContentUtils.js";
17
+
18
+ import {
19
+ SpecialOperators as s
20
+ } from "./QyUtils.js";
21
+
22
+ let n = s.$del;
23
+
24
+ class a extends e {
25
+ qyCache;
26
+ expireMap = {};
27
+ roundedStartTime;
28
+ constructor(e, t = void 0) {
29
+ super("QyExpire_Worker", t = {
30
+ ...r("QyExpire"),
31
+ ...t
32
+ }, t, [], [ "setRoundedStartTime", "setContentExpire", "removeContentExpire", "setItemExpire", "removeItemExpire" ]),
33
+ Object.assign(this, {
34
+ qyCache: e
35
+ });
36
+ }
37
+ monitorItemExpire(e, t) {
38
+ d(this);
39
+ var {
40
+ roundedStartTime: r,
41
+ expireMap: i
42
+ } = this, t = t - r, r = x(e);
43
+ i[r] = e, this.setItemExpire(r, t);
44
+ }
45
+ unmonitorItemExpire(e) {
46
+ var {
47
+ roundedStartTime: t,
48
+ expireMap: r
49
+ } = this;
50
+ t && (t = x(e), this.removeItemExpire(t), delete r[t]);
51
+ }
52
+ monitorContentExpire(e, t) {
53
+ d(this);
54
+ var r, {
55
+ roundedStartTime: i,
56
+ expireMap: o
57
+ } = this, s = {};
58
+ for (r in t) s[r] = t[r] - i;
59
+ var n = e.fileContentKey;
60
+ o[n] = e, this.setContentExpire(n, s);
61
+ }
62
+ unmonitorContentExpire(e, t) {
63
+ this.roundedStartTime && this.removeContentExpire(e.fileContentKey, Object.keys(t));
64
+ }
65
+ onEmptyHashList(e) {
66
+ var t, r = this.expireMap;
67
+ for (t of e) delete r[t];
68
+ i(r) && Object.assign(this, {
69
+ roundedStartTime: void 0
70
+ });
71
+ }
72
+ onExpired(e) {
73
+ var t, {
74
+ qyCache: r,
75
+ expireMap: i
76
+ } = this, o = r.qyDB;
77
+ for (t in e) {
78
+ var s = i[t];
79
+ s && (t.startsWith("c") ? m(o, s, e[t]) : (p(o, s), delete i[t]));
80
+ }
81
+ }
82
+ }
83
+
84
+ function p(e, t) {
85
+ t.isFile ? (e.delFile(t), e.removeFileExpire(t, !0)) : (e.delDir(t), e.removeDirExpire(t, !0));
86
+ }
87
+
88
+ function m(e, t, r) {
89
+ t.created && e.insert(t, r.reduce((e, t) => o(e, JSON.parse(t), n), {}), !0),
90
+ e.removeContentExpire(t, r, !0);
91
+ }
92
+
93
+ function d(e) {
94
+ e.roundedStartTime || e.setRoundedStartTime(e.roundedStartTime = t());
95
+ }
96
+
97
+ function x(e) {
98
+ return (e.isFile ? "f" : "d") + e.fullPathHash;
99
+ }
100
+
101
+ export {
102
+ a as QyExpire,
103
+ p as handleExpiredItem,
104
+ m as handleExpiredProps
105
+ };
@@ -0,0 +1,10 @@
1
+ export declare class QyExpireInfo {
2
+ hashPropTimeMap: {};
3
+ secondTimeHashPropMap: {};
4
+ get isEmpty(): boolean;
5
+ setExpireInfo(hashKey: any, expireTime: any, prop?: any): void;
6
+ removeExpireInfo(hashKey: any, prop?: any): void;
7
+ processExpired(currentSecondTime: any, checkedSecondTime: any, hashExpiredInfoMap: any, emptyHashList: any): void;
8
+ }
9
+ export declare function getSecond(expireTime: any): number;
10
+ export declare function getSecondM(expireTime: any): number;