datafolder 1.0.38 → 1.0.39

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/QyBatch.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import {
2
- isDeepStrictEqual as c
2
+ isDeepStrictEqual as d
3
3
  } from "node:util";
4
4
 
5
5
  import {
@@ -9,23 +9,23 @@ import {
9
9
  import {
10
10
  pathSplit as o,
11
11
  ensurePropNamePathList as n,
12
- isString as d,
13
- getSuffix as g,
12
+ isString as h,
13
+ getSuffix as m,
14
14
  SpecialFilePaths as e,
15
- isSimpleType as h,
16
- isEmptyObj as u,
15
+ isSimpleType as l,
16
+ isEmptyObj as f,
17
17
  isNumber as r,
18
- getNowRounded as l,
18
+ getNowRounded as c,
19
19
  isDate as a,
20
- isArray as m,
21
- isFloat32Array as f
20
+ isArray as u,
21
+ isFloat32Array as g
22
22
  } from "./QyUtils.js";
23
23
 
24
24
  import {
25
25
  CmdName_A as _,
26
26
  CmdName_D as C,
27
- CmdName_M as p,
28
- CmdName_R as v,
27
+ CmdName_M as v,
28
+ CmdName_R as p,
29
29
  QyAclCmdGenerator as t
30
30
  } from "./QyAcl.js";
31
31
 
@@ -45,19 +45,20 @@ import {
45
45
  logger as D
46
46
  } from "./QyLogger.js";
47
47
 
48
- let F = e.IndexPropPathsFileName, O = {
48
+ let F = e.IndexPropPathsFileName, q = {
49
49
  none: 0,
50
50
  basic: 1,
51
51
  delta: 2,
52
52
  all: 3
53
53
  };
54
54
 
55
- class P extends x {
55
+ class j extends x {
56
56
  fileLogLevel;
57
57
  changeId;
58
58
  actionQueue = [];
59
- changeList = [];
59
+ fileDeltaList = [];
60
60
  syncList = [];
61
+ logList = [];
61
62
  qyCmdObjHistory;
62
63
  running;
63
64
  options;
@@ -67,611 +68,438 @@ class P extends x {
67
68
  ...i("QyBatch"),
68
69
  ...t
69
70
  };
70
- e = O[t.fileLogLevel.toLowerCase()];
71
- this.options = t, this.fileLogLevel = e ?? 1, this.qyCmdObjHistory = new E(t.maxHistoryCmdObjCount);
71
+ e = q[t.fileLogLevel.toLowerCase()];
72
+ this.options = t, this.fileLogLevel = e ?? 1, this.qyCmdObjHistory = new H(t.maxHistoryCmdObjCount);
72
73
  }
73
- createDir(e, t = this.currentDir) {
74
- return d(e) && (e = o(e)), N(this, this._action_createDir, {
75
- item: this.qyCache.getOrCreateDir(e, t)
76
- });
74
+ createDir(e) {
75
+ h(e) && (e = o(e));
76
+ e = this.qyCache.getOrCreateDir(e, this.currentDir);
77
+ return P(this, this._action_createDir, e);
77
78
  }
78
- delDir(e, t = this.currentDir) {
79
- return d(e) && (e = o(e)), N(this, this._action_delDir, {
80
- item: this.qyCache.getOrCreateDir(e, t).ensureAllLoaded()
81
- });
79
+ delDir(e) {
80
+ h(e) && (e = o(e));
81
+ e = this.qyCache.getOrCreateDir(e, this.currentDir).ensureAllLoaded();
82
+ return P(this, this._action_delDir, e);
82
83
  }
83
- createFile(e, t = this.currentDir) {
84
- return d(e) && (e = o(e)), N(this, this._action_createFile, {
85
- item: this.qyCache.getOrCreateFile(e, t).ensureLoaded()
86
- });
84
+ createFile(e) {
85
+ h(e) && (e = o(e));
86
+ e = this.qyCache.getOrCreateFile(e, this.currentDir).ensureLoaded();
87
+ return P(this, this._action_createFile, e);
87
88
  }
88
- delFile(e, t = this.currentDir) {
89
- return d(e) && (e = o(e)), N(this, this._action_delFile, {
90
- item: this.qyCache.getOrCreateFile(e, t).ensureLoaded()
91
- });
89
+ delFile(e) {
90
+ h(e) && (e = o(e));
91
+ e = this.qyCache.getOrCreateFile(e, this.currentDir).ensureLoaded();
92
+ return P(this, this._action_delFile, e);
92
93
  }
93
- expireFile(e, t, i = this.currentDir) {
94
- return this.expireFileM(e, 1e3 * t, i);
94
+ expireFile(e, t) {
95
+ return this.expireFileM(e, 1e3 * t);
95
96
  }
96
- expireFileM(e, t, i = this.currentDir) {
97
- return j(this, e, t, "f", i);
97
+ expireFileM(e, t) {
98
+ return Q(this, e, t, "f");
98
99
  }
99
- expireDir(e, t, i = this.currentDir) {
100
- return this.expireDirM(e, 1e3 * t, i);
100
+ expireDir(e, t) {
101
+ return this.expireDirM(e, 1e3 * t);
101
102
  }
102
- expireDirM(e, t, i = this.currentDir) {
103
- return j(this, e, t, "d", i);
103
+ expireDirM(e, t) {
104
+ return Q(this, e, t, "d");
104
105
  }
105
- expireContent(e, t, i, r = this.currentDir) {
106
- d(e) && (e = o(e));
107
- e = this.qyCache.getOrCreateFile(e, r).ensureLoaded();
108
- return N(this, this._action_expireContent, {
109
- item: e,
110
- expireInfoObj: t,
111
- isMilliSecond: i
112
- });
106
+ expireContent(e, t, i) {
107
+ h(e) && (e = o(e));
108
+ e = this.qyCache.getOrCreateFile(e, this.currentDir).ensureLoaded();
109
+ return P(this, this._action_expireContent, e, t, i);
113
110
  }
114
- expireContentM(e, t, i = this.currentDir) {
115
- return this.expireContent(e, t, !0, i);
111
+ expireContentM(e, t) {
112
+ return this.expireContent(e, t, !0);
116
113
  }
117
- removeFileExpire(e, t = !1, i = this.currentDir) {
118
- return M(this, e, "f", t, i);
114
+ removeFileExpire(e, t = !1) {
115
+ return S(this, e, "f", t);
119
116
  }
120
- removeDirExpire(e, t = !1, i = this.currentDir) {
121
- return M(this, e, "d", t, i);
117
+ removeDirExpire(e, t = !1) {
118
+ return S(this, e, "d", t);
122
119
  }
123
- removeContentExpire(e, t, i = !1, r = this.currentDir) {
124
- d(e) && (e = o(e));
125
- e = this.qyCache.getOrCreateFile(e, r).ensureLoaded();
126
- return N(this, this._action_removeContentExpire, {
127
- item: e,
128
- expireInfoObj: t,
129
- infoFileOnly: i
130
- });
120
+ removeContentExpire(e, t, i = !1) {
121
+ h(e) && (e = o(e));
122
+ e = this.qyCache.getOrCreateFile(e, this.currentDir).ensureLoaded();
123
+ return P(this, this._action_removeContentExpire, e, t, i);
131
124
  }
132
- createIndex(e, t, i = this.currentDir) {
133
- d(e) && (e = o(e)), m(t) || (t = [ t ]);
134
- e = this.qyCache.getOrCreateDir(e, i);
135
- return N(this, this._action_createIndex, {
136
- item: e,
137
- indexPropPathList: t
138
- });
125
+ createIndex(e, t) {
126
+ h(e) && (e = o(e)), u(t) || (t = [ t ]);
127
+ e = this.qyCache.getOrCreateDir(e, this.currentDir);
128
+ return P(this, this._action_createIndex, e, t);
139
129
  }
140
- createIndexFromQuery(e, t, i = this.currentDir) {
141
- d(e) && (e = o(e));
142
- e = this.qyCache.getOrCreateDir(e, i);
143
- return N(this, this._action_createIndex, {
144
- item: e,
145
- queryObj: t
146
- });
130
+ createIndexByQuery(e, t) {
131
+ h(e) && (e = o(e));
132
+ e = this.qyCache.getOrCreateDir(e, this.currentDir);
133
+ return P(this, this._action_createIndexByQuery, e, t);
147
134
  }
148
- delIndex(e, t, i = this.currentDir) {
149
- d(e) && (e = o(e));
150
- e = this.qyCache.getOrCreateDir(e, i);
151
- return N(this, this._action_delIndex, {
152
- item: e,
153
- indexPropPath: t
154
- });
135
+ delIndex(e, t) {
136
+ h(e) && (e = o(e));
137
+ e = this.qyCache.getOrCreateDir(e, this.currentDir);
138
+ return P(this, this._action_delIndex, e, t);
155
139
  }
156
- insert(e, t, i = !0, r = !1, n = this.currentDir) {
157
- d(e) && (e = o(e));
158
- e = this.qyCache.getOrCreateFile(e, n).ensureLoaded();
159
- return t = i || h(t) ? t : structuredClone(t), N(this, this._action_insert, {
160
- item: e,
161
- content: t,
162
- noCreate: r
163
- });
140
+ insert(e, t) {
141
+ h(e) && (e = o(e));
142
+ e = this.qyCache.getOrCreateFile(e, this.currentDir).ensureLoaded();
143
+ return P(this, this._action_insert, e, t);
164
144
  }
165
- insertEmbedding(e, t, i = this.currentDir) {
166
- var r = this.qyCache, r = (f(t) || (t = new Float32Array(t)), d(e) && (e = o(e)),
167
- r.getOrCreateFile(e, i));
168
- return N(this, this._action_insertEmbedding, {
169
- item: r,
170
- embedding: t
171
- });
145
+ insertEmbedding(e, t) {
146
+ var i = this.qyCache, i = (g(t) || (t = new Float32Array(t)), h(e) && (e = o(e)),
147
+ i.getOrCreateFile(e, this.currentDir));
148
+ return P(this, this._action_insertEmbedding, i, t);
172
149
  }
173
- delEmbedding(e, t = this.currentDir) {
174
- var i = this.qyCache, i = (d(e) && (e = o(e)), i.getOrCreateFile(e, t));
175
- return N(this, this._action_delEmbedding, {
176
- item: i
177
- });
150
+ delEmbedding(e) {
151
+ var t = this.qyCache, t = (h(e) && (e = o(e)), t.getOrCreateFile(e, this.currentDir));
152
+ return P(this, this._action_delEmbedding, t);
178
153
  }
179
- insertWithEmbedding(e, t, i, r = !0, n = !1, a = this.currentDir) {
180
- return this.insert(e, t, r, n, a), this.insertEmbedding(e, i, a);
154
+ insertWithEmbedding(e, t, i) {
155
+ return this.insert(e, t), this.insertEmbedding(e, i);
181
156
  }
182
- delContent(e, t = this.currentDir) {
183
- d(e) && (e = o(e));
184
- e = this.qyCache.getOrCreateFile(e, t).ensureLoaded();
185
- return N(this, this._action_delContent, {
186
- item: e
187
- });
157
+ delContent(e) {
158
+ h(e) && (e = o(e));
159
+ e = this.qyCache.getOrCreateFile(e, this.currentDir).ensureLoaded();
160
+ return P(this, this._action_delContent, e);
188
161
  }
189
162
  insertTrigger(e, t, i, r) {
190
- d(t) && (t = o(t)), i = n(i);
163
+ h(t) && (t = o(t)), i = n(i);
191
164
  e = this.qyCache.getOrCreateTriggerFile(e);
192
- return N(this, this._action_insertTrigger, {
193
- item: e,
194
- fileNamePath: t,
195
- propNamePathList: i,
196
- modCode: r
197
- });
165
+ return P(this, this._action_insertTrigger, e, t, i, r);
198
166
  }
199
167
  removeTrigger(e) {
200
- return N(this, this._action_removeTrigger, {
201
- item: this.qyCache.getOrCreateTriggerFile(e)
202
- });
168
+ return P(this, this._action_removeTrigger, this.qyCache.getOrCreateTriggerFile(e));
203
169
  }
204
170
  insertRpc(e, t) {
205
171
  e = this.qyCache.getOrCreateRpcFile(e);
206
- return N(this, this._action_insertRpc, {
207
- item: e,
208
- modCode: t
209
- });
172
+ return P(this, this._action_insertRpc, e, t);
210
173
  }
211
174
  removeRpc(e) {
212
- return N(this, this._action_removeRpc, {
213
- item: this.qyCache.getOrCreateRpcFile(e)
214
- });
175
+ return P(this, this._action_removeRpc, this.qyCache.getOrCreateRpcFile(e));
215
176
  }
216
177
  run(e = !1) {
217
178
  var {
218
179
  running: t,
219
- actionQueue: i,
220
- fileLogLevel: r,
221
- qyCache: n
180
+ actionQueue: i
222
181
  } = this;
223
182
  if (t || 0 === i.length) return 0;
224
183
  this.running = !0;
225
- var a, t = this.changeId = n.increaseChangeId();
226
- for (a of i) a.actionFun.call(this, a);
184
+ var r, n, {
185
+ qyCache: t,
186
+ qyAclCmdGenerator: a
187
+ } = this, s = this.changeId = t.increaseChangeId();
188
+ for ([ r, n ] of i) r.apply(this, n);
227
189
  i.length = 0, this.running = !1, this.resetCurrentDir();
190
+ i = a.cmdCount;
191
+ if (0 === i) return t.decreaseChangeId(), 0;
228
192
  var {
229
- changeList: i,
230
- qyAclCmdGenerator: o,
231
- qyCmdObjHistory: s,
232
- syncList: d
233
- } = this, h = i.length;
234
- if (0 === h) return n.decreaseChangeId(), 0;
235
- var c = g(h), o = o.takeCmdArgAsListArray();
236
- let l;
237
- 0 < r && (r = i.map(({
238
- logStr: e
239
- }) => e).join("\n"), l = new Date().toISOString() + `: ${h} change${c}:
240
- ${r}
241
- `);
242
- var m, u, h = n.save(t, o, l, (e => {
193
+ fileLogLevel: o,
194
+ logList: h,
195
+ qyCmdObjHistory: d,
196
+ syncList: l
197
+ } = this, c = m(i), a = a.takeCmdArgAsListArray(), o = 0 < o ? "" + new Date().toISOString() + `: ${i} change${c}:
198
+ ${h.join("\n")}
199
+ ` : void 0, i = (h.length = 0, t.save(s, a, o, (e => {
243
200
  var t = e.syncList, i = t.length;
244
201
  for (let e = 0; e < i; e += 2) {
245
- var r, n = e + 1, a = t[e], o = t[n];
246
- a.startsWith("d") ? (r = o.subdirNameList, t[n] = 0 < r.length ? r : void 0) : a.startsWith("f") ? (r = o.fileNameList,
247
- t[n] = 0 < r.length ? r : void 0) : t[n] = o.fileContent;
202
+ var r, n = e + 1, a = t[e], s = t[n];
203
+ a.startsWith("d") ? (r = s.subdirNameList, t[n] = 0 < r.length ? r : void 0) : a.startsWith("f") ? (r = s.fileNameList,
204
+ t[n] = 0 < r.length ? r : void 0) : t[n] = s.fileContent;
248
205
  }
249
206
  if (0 < i) return t;
250
- })(this), e), c = (d.length = 0, s.push(o), i.filter(({
251
- item: e,
252
- delta: t
253
- }) => void 0 !== t && 0 < e.triggerNodes?.length));
254
- i.length = 0;
255
- for ({
256
- item: m,
257
- delta: u
258
- } of c) for (var f of m.triggerNodes) f.checkTrigger(m, u);
259
- return e ? h : t;
207
+ })(this), e));
208
+ l.length = 0, d.push(a);
209
+ var u = this.fileDeltaList, f = u.length;
210
+ if (0 < f) {
211
+ var g = [];
212
+ for (let e = 0; e < f; e += 2) {
213
+ var _ = u[e];
214
+ 0 < _.triggerNodes?.length && g.push(_, u[e + 1]);
215
+ }
216
+ for (let e = u.length = 0; e < g.length; e += 2) {
217
+ var C, v = g[e], p = g[e + 1];
218
+ for (C of v.triggerNodes) C.checkTrigger(v, p);
219
+ }
220
+ }
221
+ return e ? i : s;
260
222
  }
261
223
  getTopHistoryCmdObj() {
262
224
  return this.qyCmdObjHistory.top();
263
225
  }
264
- _action_insertTrigger(e) {
265
- e.actionName = "insertTrigger";
226
+ _action_insertTrigger(e, t, i, r) {
266
227
  var {
267
- item: e,
268
- fileNamePath: t,
269
- propNamePathList: i,
270
- modCode: r
271
- } = e, {
272
228
  name: n,
273
229
  fileContent: a
274
- } = e, a = a && a[0], o = [ t, i ], e = (r && o.push(r), this._action_insert({
275
- item: e,
276
- content: o
277
- }));
278
- return e && (o = this.qyCache, a && !c(a, t) && o.removeTriggerFromTree(n, a),
279
- o.insertTriggerToTree(n, t, i, r)), e;
230
+ } = e, a = a && a[0], s = [ t, i ], e = (r && s.push(r), this._action_insert(e, s));
231
+ return e && (s = this.qyCache, a && !d(a, t) && s.removeTriggerFromTree(n, a),
232
+ s.insertTriggerToTree(n, t, i, r)), e;
280
233
  }
281
234
  _action_removeTrigger(e) {
282
- e.actionName = "removeTrigger";
283
- var e = e.item, {
235
+ var {
284
236
  fileContent: t,
285
237
  name: i
286
- } = e, e = this._action_delFile({
287
- item: e
288
- });
238
+ } = e, e = this._action_delFile(e);
289
239
  return e && this.qyCache.removeTriggerFromTree(i, t[0]), e;
290
240
  }
291
- _action_insertRpc(e) {
292
- e.actionName = "insertRpc";
293
- var {
294
- item: e,
295
- modCode: t
296
- } = e, i = this._action_insert({
297
- item: e,
298
- content: t
299
- });
241
+ _action_insertRpc(e, t) {
242
+ var i = this._action_insert(e, t);
300
243
  return i && this.qyCache.insertRpc(e.name, t), i;
301
244
  }
302
245
  _action_removeRpc(e) {
303
- e.actionName = "removeRpc";
304
- e = e.item;
305
- return !!this._action_delFile({
306
- item: e
307
- }) && (this.qyCache.removeRpc(e.name), !0);
308
- }
309
- _action_createIndex(t) {
310
- t.actionName = "createIndex";
311
- var {
312
- item: t,
313
- indexPropPathList: e,
314
- queryObj: i
315
- } = t, r = this.qyCache.getOrCreateIndexDir(t), r = r.getOrCreateFile(F), n = (r.created || this._action_createFile({
316
- item: r
317
- }), r).qyIndexPropTree, i = void 0 !== i ? n.insertFromQueryObj(i) : n.insertPropPathList(e);
318
- if (0 !== i.length) {
319
- var a, o = {};
320
- for (a of i) o[JSON.stringify(a.indexPropPath)] = 1;
321
- D.log(`Creating index ${JSON.stringify(o)} for ` + t.fullPath), this._action_insert({
322
- item: r,
323
- content: o
324
- });
325
- {
326
- var s, d = this, h = t;
327
- let e;
328
- for (s of i) {
329
- var {
330
- indexPropPath: c,
331
- indexPropDir: l
332
- } = s;
333
- if (!l.created) {
334
- d._action_createDir({
335
- item: l
336
- });
337
- for (var m of e = void 0 === e ? h.fileList : e) {
338
- var {
339
- fileContent: m,
340
- name: u
341
- } = m;
342
- void 0 !== m && b(d, l, c, u, void 0, m);
343
- }
344
- }
345
- }
346
- }
347
- }
246
+ return !!this._action_delFile(e) && (this.qyCache.removeRpc(e.name), !0);
247
+ }
248
+ _action_createIndex(e, t) {
249
+ var i = this.qyCache.getOrCreateIndexDir(e), r = O(this, i), t = r.qyIndexPropTree.insertPropPathList(t);
250
+ 0 < t.length && L(this, e, 0, r, t);
348
251
  }
349
- _action_delIndex(e) {
350
- e.actionName = "delIndex";
351
- var t, {
352
- item: e,
353
- indexPropPath: i
354
- } = e, e = this.qyCache.getIndexDir(e);
355
- void 0 !== e && (void 0 === (t = e.getFile(F)) ? this._action_delDir({
356
- item: e
357
- }) : (e = t.qyIndexPropTree, [ t, e, i ] = (this._action_setProp(t, JSON.stringify(i), null),
358
- e.removePropPath(i)), t && !e && void 0 !== i && (t = i.indexPropDir, void 0 !== t) && this._action_delDir({
359
- item: t
360
- })));
252
+ _action_createIndexByQuery(e, t) {
253
+ var i = this.qyCache.getOrCreateIndexDir(e), r = O(this, i), t = r.qyIndexPropTree.insertQueryObj(t);
254
+ 0 < t.length && L(this, e, 0, r, t);
255
+ }
256
+ _action_delIndex(e, t) {
257
+ var i, e = this.qyCache.getIndexDir(e);
258
+ void 0 !== e && (void 0 === (i = e.getFile(F)) ? this._action_delDir(e) : (e = i.qyIndexPropTree,
259
+ [ i, e, t ] = (this._action_setProp(i, JSON.stringify(t), null), e.removePropPath(t)),
260
+ i && !e && void 0 !== t && (i = t.indexPropDir, void 0 !== i) && this._action_delDir(i)));
361
261
  }
362
262
  _action_delFile(e, t = !1) {
363
- e.actionName = "delFile";
364
- var i = e.item;
365
- if (!i.created) return !1;
366
- void 0 !== i.fileContent && this._action_delContent({
367
- item: i
368
- });
369
- var {
370
- parentDir: r,
371
- name: n
372
- } = i;
373
- return i.created = !1, q(this, e), t || L(this, r, v, r.fileMapKey, n),
374
- !0;
263
+ var i;
264
+ return !!e.created && (void 0 !== e.fileContent && this._action_delContent(e),
265
+ e.created = !1, t || ({
266
+ parentDir: t,
267
+ name: i
268
+ } = e, b(this, t, p, t.fileMapKey, i)), I(this, "delFile", e), !0);
375
269
  }
376
270
  _action_delDir(e) {
377
- e.actionName = "delDir";
378
- var t = e.item;
379
- if (!t.created) return !1;
271
+ if (!e.created) return !1;
380
272
  let {
381
- parentDir: i,
382
- name: r,
383
- subdirMap: n,
384
- fileMap: a,
385
- subdirMapKey: o,
273
+ parentDir: t,
274
+ name: i,
275
+ subdirMap: r,
276
+ fileMap: n,
277
+ subdirMapKey: a,
386
278
  fileMapKey: s
387
- } = t;
388
- if (a) {
389
- L(this, t, C, s);
390
- for (var d of t.fileList) this._action_delFile({
391
- item: d
392
- }, !0);
393
- }
279
+ } = e;
394
280
  if (n) {
395
- L(this, t, C, o);
396
- for (var h of t.allSubdirs()) {
281
+ b(this, e, C, s);
282
+ for (var o of e.fileList) this._action_delFile(o, !0);
283
+ }
284
+ if (r) {
285
+ b(this, e, C, a);
286
+ for (var h of e.allSubdirs()) {
397
287
  let {
398
288
  subdirMap: e,
399
289
  fileMap: t,
400
290
  subdirMapKey: i,
401
291
  fileMapKey: r
402
292
  } = h;
403
- if (e && L(this, h, C, i), t) {
404
- L(this, h, C, r);
405
- for (var c of h.fileList) this._action_delFile({
406
- item: c
407
- }, !0);
293
+ if (e && b(this, h, C, i), t) {
294
+ b(this, h, C, r);
295
+ for (var d of h.fileList) this._action_delFile(d, !0);
408
296
  }
409
- q(this, {
410
- actionName: "delDir",
411
- item: h
412
- }), h.created = !1;
297
+ I(this, "delDir", h), h.created = !1;
413
298
  }
414
299
  }
415
- return void 0 !== i && (t.created = !1, q(this, e), L(this, i, v, i.subdirMapKey, r),
416
- !0);
300
+ return void 0 !== t && (e.created = !1, b(this, t, p, t.subdirMapKey, i),
301
+ I(this, "delDir", e), !0);
417
302
  }
418
303
  _action_delContent(e) {
419
- e.actionName = "delContent";
420
- var t = e.item, i = t.fileContent;
421
- return void 0 !== i && (t.fileContent = void 0, e.content = i, e.delta = [ i, null ],
422
- q(this, e), L(this, t, C, t.fileContentKey), I(this, t, i), !0);
423
- }
424
- _action_insertEmbedding(e) {
425
- e.actionName = "insertEmbedding";
426
- var t, i, r = this.qyCache, n = r.qyEmbeddings, {
427
- item: a,
428
- embedding: o
429
- } = e, s = o.length, r = r.getOrCreateInfoFile(a), d = r.fileContent;
304
+ var t = e.fileContent;
305
+ return void 0 !== t && (e.fileContent = void 0, b(this, e, C, e.fileContentKey),
306
+ I(this, "delContent", e, t, [ t, null ]), E(this, e, t), !0);
307
+ }
308
+ _action_insertEmbedding(e, t) {
309
+ var i, r, n = this.qyCache, a = n.qyEmbeddings, s = t.length, n = n.getOrCreateInfoFile(e), o = n.fileContent;
430
310
  let h = !1;
431
- return r.created && d.length === s ? (t = a.fullPathHash, d = d.idx, i = n.getEmbedding(t, s, d),
432
- c(o, i) || ((i = n.updateEmbedding(t, o, d)) !== d && this._action_setProp(r, "idx", i),
311
+ return n.created && o.length === s ? (i = e.fullPathHash, o = o.idx, r = a.getEmbedding(i, s, o),
312
+ d(t, r) || ((r = a.updateEmbedding(i, t, o)) !== o && this._action_setProp(n, "idx", r),
433
313
  h = !0)) : ({
434
- fullPathHash: t,
435
- namePath: d
436
- } = a, i = n.addEmbedding(t, o), this._action_insert({
437
- item: r,
438
- content: {
439
- length: s,
440
- idx: i,
441
- namePath: r.created ? void 0 : d
442
- }
443
- }), h = !0), h && q(this, e), h;
314
+ fullPathHash: i,
315
+ namePath: o
316
+ } = e, r = a.addEmbedding(i, t), this._action_insert(n, {
317
+ length: s,
318
+ idx: r,
319
+ namePath: n.created ? void 0 : o
320
+ }), h = !0), h && I(this, "insertEmbedding", e), h;
444
321
  }
445
322
  _action_delEmbedding(e) {
446
- e.actionName = "delEmbedding";
447
- var t = this.qyCache, i = t.qyEmbeddings, r = e.item;
448
- let n, a;
449
- var o, t = t.getInfoFile(r);
450
- if (t && (o = t.fileContent, o) && (n = o.length, a = o.idx), i.delEmbedding(r.fullPathHash, n, a),
451
- t) return this._action_delFile({
452
- item: t
453
- }), q(this, e), !0;
454
- }
455
- _action_put(e) {
456
- e.actionName = "put";
457
- var {
458
- item: t,
459
- content: i
460
- } = e;
461
- if (void 0 === i) return D.warn(`Saving undefined to ${t.fullPath}. Not making any change.`),
462
- !1;
463
- t.created || this._action_createFile({
464
- item: t
465
- });
466
- var r = t.fileContentKey;
467
- return i.$rpl = 1, L(this, t, p, r, i), q(this, e), t.fileContent = i, !0;
323
+ var t = this.qyCache, i = t.qyEmbeddings;
324
+ let r, n;
325
+ var a, t = t.getInfoFile(e);
326
+ if (t && (a = t.fileContent, a) && (r = a.length, n = a.idx), i.delEmbedding(e.fullPathHash, r, n),
327
+ t) return this._action_delFile(t), I(this, "delEmbedding", e), !0;
468
328
  }
469
329
  _action_setProp(e, t, i) {
470
330
  var {
471
331
  created: r,
472
332
  fileContentKey: n,
473
333
  fileContent: a
474
- } = e, r = (r || this._action_createFile({
475
- item: e
476
- }), a ? a[t] : void 0);
334
+ } = e, r = (r || this._action_createFile(e), a ? a[t] : void 0);
477
335
  return null === i ? void 0 !== a && delete a[t] : void 0 !== a ? a[t] = i : e.fileContent = {
478
336
  [t]: i
479
- }, L(this, e, p, n, t, i), r;
480
- }
481
- _action_insert(e) {
482
- e.actionName = "insert";
483
- var t, {
484
- item: i,
485
- content: r,
486
- noCreate: n
487
- } = e;
488
- let {
489
- merged: a,
490
- delta: o
491
- } = e;
492
- if (void 0 === o && void 0 === r) return D.warn(`Saving undefined to ${i.fullPath}. Not making any change.`),
337
+ }, b(this, e, v, n, t, i), r;
338
+ }
339
+ _action_insert(e, t) {
340
+ if (void 0 === t) return D.warn(`Saving undefined to ${e.fullPath}. Not making any change.`),
493
341
  !1;
494
- if (!i.created) {
495
- if (n) return !1;
496
- this._action_createFile({
497
- item: i
498
- });
499
- }
500
- return void 0 === a && void 0 === o && ([ a, o ] = s(i.fileContent, r)),
501
- void 0 !== o && ([ n, r ] = o, t = i.fileContentKey, void 0 === a ? L(this, i, C, t) : L(this, i, p, t, r),
502
- e.merged = a, e.delta = o, q(this, e), i.fileContent = a, I(this, i, n, r, a),
503
- !0);
342
+ e.created || this._action_createFile(e);
343
+ var [ t, i ] = s(e.fileContent, t);
344
+ if (void 0 === i) return !1;
345
+ e.fileContent = t;
346
+ var [ r, n ] = i, a = e.fileContentKey;
347
+ return void 0 === t ? b(this, e, C, a) : b(this, e, v, a, n), I(this, "insert", e, t, i),
348
+ E(this, e, r, n, t), !0;
504
349
  }
505
350
  _action_createFile(e) {
506
- e.actionName = "createFile";
507
- var t, i = e.item;
508
- return !i.created && (t = i.parentDir, this._action_createDir({
509
- item: t
510
- }), i.created = !0, i.fileContentLoaded = !0, q(this, e), L(this, t, _, t.fileMapKey, i.name),
511
- !0);
351
+ var t;
352
+ return !e.created && (t = e.parentDir, t.created || this._action_createDir(t),
353
+ e.created = !0, e.fileContentLoaded = !0, b(this, t, _, t.fileMapKey, e.name),
354
+ I(this, "createFile", e), !0);
512
355
  }
513
356
  _action_createDir(e) {
514
- e.actionName = "createDir";
515
- let t = e.item;
516
- if (t.created) return !1;
517
- for (var i = []; !t.created; ) i.push(t), t = t.parentDir;
518
- for (let e of i.reverse()) {
519
- e.created = !0, e.subdirMapLoaded = !0, e.fileMapLoaded = !0, q(this, {
520
- actionName: "createDir",
521
- item: e
522
- });
523
- var r = e.parentDir;
524
- L(this, r, _, r.subdirMapKey, e.name);
357
+ if (e.created) return !1;
358
+ for (var t = []; !e.created; ) t.push(e), e = e.parentDir;
359
+ for (let e of t.reverse()) {
360
+ e.created = !0, e.subdirMapLoaded = !0, e.fileMapLoaded = !0;
361
+ var i = e.parentDir;
362
+ b(this, i, _, i.subdirMapKey, e.name), I(this, "createDir", e);
525
363
  }
526
364
  return !0;
527
365
  }
528
- _action_expireItem(e) {
529
- e.actionName = "expireItem";
530
- var t, {
531
- item: e,
532
- milliSecond: i
533
- } = e, {
366
+ _action_expireItem(e, t) {
367
+ var i, {
534
368
  parentDir: r,
535
369
  name: n
536
370
  } = e;
537
- return void 0 !== r && void 0 !== (i = T(i, !0, l())) && (t = this.qyCache,
538
- r = t.getOrCreateExpireInfoFile(r.fullPathHash, e.isFile ? "f" : "d"), (r = this._action_insert({
539
- item: r,
540
- content: {
541
- [n]: i
542
- }
543
- })) && t.monitorItemExpire(e, i), r);
544
- }
545
- _action_removeItemExpire(e) {
546
- e.actionName = "removeItemExpire";
547
- var t, {
548
- item: e,
549
- infoFileOnly: i
550
- } = e, {
371
+ return void 0 !== r && void 0 !== (t = M(t, !0, c())) && (i = this.qyCache,
372
+ r = i.getOrCreateExpireInfoFile(r.fullPathHash, e.isFile ? "f" : "d"), (r = this._action_insert(r, {
373
+ [n]: t
374
+ })) && i.monitorItemExpire(e, t), r);
375
+ }
376
+ _action_removeItemExpire(e, t) {
377
+ var i, {
551
378
  parentDir: r,
552
379
  name: n
553
380
  } = e;
554
- return void 0 !== r && (t = this.qyCache, void 0 !== (r = t.getExpireInfoFile(r.fullPathHash, e.isFile ? "f" : "d"))) && ((n = this._action_insert({
555
- item: r,
556
- content: {
557
- [n]: null
558
- }
559
- })) && (u(r.fileContent) && this._action_delFile({
560
- item: r
561
- }), void 0 === i) && t.unmonitorItemExpire(e), n);
381
+ return void 0 !== r && (i = this.qyCache, void 0 !== (r = i.getExpireInfoFile(r.fullPathHash, e.isFile ? "f" : "d"))) && ((n = this._action_insert(r, {
382
+ [n]: null
383
+ })) && (f(r.fileContent) && this._action_delFile(r), void 0 === t) && i.unmonitorItemExpire(e),
384
+ n);
385
+ }
386
+ _action_expireContent(e, t, i) {
387
+ let r = c();
388
+ var t = T(t, e => M(e, i, r)), n = this.qyCache, a = n.getOrCreateExpireInfoFile(e.fullPathHash, "c"), a = this._action_insert(a, {
389
+ ...t
390
+ });
391
+ return a && n.monitorContentExpire(e, t), a;
562
392
  }
563
- _action_expireContent(e) {
564
- e.actionName = "expireContent";
565
- let {
566
- item: t,
567
- expireInfoObj: i,
568
- isMilliSecond: r
569
- } = e, n = l();
570
- var e = S(i, e => T(e, r, n)), a = this.qyCache, o = a.getOrCreateExpireInfoFile(t.fullPathHash, "c"), o = this._action_insert({
571
- item: o,
572
- content: {
573
- ...e
393
+ _action_removeContentExpire(e, t, i) {
394
+ var r, n = this.qyCache, a = n.getExpireInfoFile(e.fullPathHash, "c");
395
+ return void 0 !== a && (t = u(t) ? Object.fromEntries(t.map(e => [ e, null ])) : T(t, e => e ? null : void 0),
396
+ (r = this._action_insert(a, t)) && (f(a.fileContent, !0) && this._action_delFile(a),
397
+ i || n.unmonitorContentExpire(e, t)), r);
398
+ }
399
+ }
400
+
401
+ function O(e, t) {
402
+ t = t.getOrCreateFile(F);
403
+ return t.created || e._action_createFile(t), t;
404
+ }
405
+
406
+ function L(t, i, e, r, n) {
407
+ var a, s = {};
408
+ for (a of n) s[JSON.stringify(a.indexPropPath)] = 1;
409
+ D.log(`Creating index ${JSON.stringify(s)} for ` + i.fullPath), t._action_insert(r, s);
410
+ {
411
+ var o = t, h = i, d;
412
+ let e;
413
+ for (d of r = n) {
414
+ var {
415
+ indexPropPath: l,
416
+ indexPropDir: c
417
+ } = d;
418
+ if (!c.created) {
419
+ o._action_createDir(c);
420
+ for (var u of e = void 0 === e ? h.fileList : e) {
421
+ var {
422
+ fileContent: u,
423
+ name: f
424
+ } = u;
425
+ void 0 !== u && N(o, c, l, f, void 0, u);
426
+ }
574
427
  }
575
- });
576
- return o && a.monitorContentExpire(t, e), o;
577
- }
578
- _action_removeContentExpire(e) {
579
- e.actionName = "removeContentExpire";
580
- var t, {
581
- item: e,
582
- expireInfoObj: i,
583
- infoFileOnly: r
584
- } = e, n = this.qyCache, a = n.getExpireInfoFile(e.fullPathHash, "c");
585
- return void 0 !== a && (i = m(i) ? Object.fromEntries(i.map(e => [ e, null ])) : S(i, e => e ? null : void 0),
586
- (t = this._action_insert({
587
- item: a,
588
- content: i
589
- })) && (u(a.fileContent, !0) && this._action_delFile({
590
- item: a
591
- }), r || n.unmonitorContentExpire(e, i)), t);
428
+ }
592
429
  }
593
430
  }
594
431
 
595
- function N(e, t, i) {
596
- return e.running ? t.call(e, i) : (i.actionFun = t, e.actionQueue.push(i)),
597
- e;
432
+ function P(e, t, ...i) {
433
+ return e.running ? t.apply(e, i) : e.actionQueue.push([ t, i ]), e;
598
434
  }
599
435
 
600
- function q(e, t) {
436
+ function I(t, i, r, n = void 0, a = void 0) {
601
437
  var {
602
- changeList: e,
603
- fileLogLevel: i
604
- } = e;
605
- 0 < i && (t.logStr = ((e, t) => {
606
- var {
607
- actionName: e,
608
- item: i,
609
- content: r,
610
- merged: n,
611
- delta: a
612
- } = e, i = e + ` "${i.fullPath ?? i}"`;
613
- if ("delContent" === e) {
614
- if (3 === t) return i + " " + JSON.stringify(r);
615
- } else if ("insert" === e && 2 <= t) return [ r, e ] = a, a = `${void 0 === r ? "" : "delta:"} ${JSON.stringify(r)} -> ` + JSON.stringify(e),
616
- 2 === t ? i + " " + a : i + ` ${a}. ` + (void 0 !== r ? "new: " + JSON.stringify(n) : "");
617
- return i;
618
- })(t, i)), e.push(t);
438
+ fileLogLevel: t,
439
+ logList: s,
440
+ fileDeltaList: o
441
+ } = t;
442
+ if (void 0 !== a && o.push(r, a), !(t <= 0)) {
443
+ o = i + ` "${r.fullPath ?? r}"`;
444
+ let e = o;
445
+ "delContent" === i ? 3 === t && (e = o + " " + JSON.stringify(n)) : "insert" === i && 2 <= t && ([ r, i ] = a,
446
+ a = `${void 0 === r ? "" : "delta:"} ${JSON.stringify(r)} -> ` + JSON.stringify(i),
447
+ 2 === t && (e = o + " " + a), i = void 0 !== r ? "new: " + JSON.stringify(n) : "",
448
+ e = o + ` ${a}. ` + i), s.push(e);
449
+ }
619
450
  }
620
451
 
621
- function L(e, t, i, r, n = void 0, a = void 0) {
452
+ function b(e, t, i, r, n = void 0, a = void 0) {
622
453
  var {
623
454
  qyAclCmdGenerator: e,
624
- qyCache: o,
625
- syncList: s,
626
- changeId: d
455
+ qyCache: s,
456
+ syncList: o,
457
+ changeId: h
627
458
  } = e;
628
- e.pushCmd(i, r, n, a), r.startsWith("d") ? t.dChangeId = d : r.startsWith("f") ? t.fChangeId = d : t.cChangeId = d,
629
- void 0 !== o && o.qyKVData.removeKey(r) && s.push(r, t);
459
+ e.pushCmd(i, r, n, a), r.startsWith("d") ? t.dChangeId = h : r.startsWith("f") ? t.fChangeId = h : t.cChangeId = h,
460
+ void 0 !== s && s.qyKVData.removeKey(r) && o.push(r, t);
630
461
  }
631
462
 
632
- function I(e, t, i, r = void 0, n = void 0) {
463
+ function E(e, t, i, r = void 0, n = void 0) {
633
464
  if (!t.underHiddenFolder) {
634
465
  var a = e.qyCache.getIndexDir(t.parentDir);
635
466
  if (void 0 !== a) {
636
467
  a = a.getFile(F);
637
468
  if (void 0 !== a) {
638
- var o, s, d = t.name;
469
+ var s, o, h = t.name;
639
470
  for ({
640
- indexPropDir: o,
641
- indexPropPath: s
642
- } of a.qyIndexPropTree.allLeafNodes) b(e, o, s, d, i, r, n);
471
+ indexPropDir: s,
472
+ indexPropPath: o
473
+ } of a.qyIndexPropTree.allLeafNodes) N(e, s, o, h, i, r, n);
643
474
  }
644
475
  }
645
476
  }
646
477
  }
647
478
 
648
- function b(t, e, i, r, n, a, o = void 0) {
649
- e = y(e, i, n, a, o);
479
+ function N(t, e, i, r, n, a, s = void 0) {
480
+ e = y(e, i, n, a, s);
650
481
  if (void 0 !== e) {
651
- var s, d, [ i, n ] = e;
652
- for (s of i) {
482
+ var o, h, [ i, n ] = e;
483
+ for (o of i) {
653
484
  var {
654
- fileContent: h,
655
- indexCount: c
656
- } = s, l = t._action_setProp(s, r, null);
657
- if (void 0 === h || u(h)) {
658
- t._action_delFile({
659
- item: s
660
- });
661
- let e = s.parentDir;
662
- for (;e.created && !e.isHiddenFolder && e.isEmpty; ) t._action_delDir({
663
- item: e
664
- }), e = e.parentDir;
665
- } else void 0 !== l && (s.indexCount = c - 1);
485
+ fileContent: d,
486
+ indexCount: l
487
+ } = o, c = t._action_setProp(o, r, null);
488
+ if (void 0 === d || f(d)) {
489
+ t._action_delFile(o);
490
+ let e = o.parentDir;
491
+ for (;e.created && !e.isHiddenFolder && e.isEmpty; ) t._action_delDir(e),
492
+ e = e.parentDir;
493
+ } else void 0 !== c && (o.indexCount = l - 1);
666
494
  }
667
- for (d of n) {
668
- var m = d.indexCount;
669
- 1 !== t._action_setProp(d, r, 1) && (d.indexCount = m + 1);
495
+ for (h of n) {
496
+ var u = h.indexCount;
497
+ 1 !== t._action_setProp(h, r, 1) && (h.indexCount = u + 1);
670
498
  }
671
499
  }
672
500
  }
673
501
 
674
- class E {
502
+ class H {
675
503
  maxLength;
676
504
  actionQueue = [];
677
505
  nextPos = 0;
@@ -695,37 +523,37 @@ class E {
695
523
  }
696
524
  }
697
525
 
698
- function S(e, t = void 0, i = [], r = {}) {
699
- if (h(e)) {
526
+ function T(e, t = void 0, i = [], r = {}) {
527
+ if (l(e)) {
700
528
  var n = t ? t(e) : e;
701
529
  void 0 !== n && (r[JSON.stringify(i)] = n);
702
530
  } else {
703
- var a, o = i.length;
704
- for (a in e) i.push(a), S(e[a], t, i, r), i.length = o;
531
+ var a, s = i.length;
532
+ for (a in e) i.push(a), T(e[a], t, i, r), i.length = s;
705
533
  }
706
534
  return r;
707
535
  }
708
536
 
709
- function T(e, t, i) {
710
- return r(e) ? (t ? e : 1e3 * e) + i : d(e) ? (t = new Date(e).getTime(), isNaN(t) || t <= i ? void 0 : t) : !a(e) || (t = e.getTime()) <= i ? void 0 : t;
537
+ function M(e, t, i) {
538
+ return r(e) ? (t ? e : 1e3 * e) + i : h(e) ? (t = new Date(e).getTime(), isNaN(t) || t <= i ? void 0 : t) : !a(e) || (t = e.getTime()) <= i ? void 0 : t;
711
539
  }
712
540
 
713
- function j(e, t, i, r, n) {
714
- var a = e.qyCache, r = (d(t) && (t = o(t)), "f" === r ? a.getOrCreateFile(t, n) : a.getOrCreateDir(t, n));
715
- return N(e, e._action_expireItem, {
716
- item: r,
717
- milliSecond: i
718
- });
541
+ function Q(e, t, i, r) {
542
+ var {
543
+ qyCache: n,
544
+ currentDir: a
545
+ } = e, r = (h(t) && (t = o(t)), "f" === r ? n.getOrCreateFile(t, a) : n.getOrCreateDir(t, a));
546
+ return P(e, e._action_expireItem, r, i);
719
547
  }
720
548
 
721
- function M(e, t, i, r, n) {
722
- var a = e.qyCache, i = (d(t) && (t = o(t)), "f" === i ? a.getOrCreateFile(t, n) : a.getOrCreateDir(t, n));
723
- return N(e, e._action_removeItemExpire, {
724
- item: i,
725
- infoFileOnly: r
726
- });
549
+ function S(e, t, i, r) {
550
+ var {
551
+ qyCache: n,
552
+ currentDir: a
553
+ } = e, i = (h(t) && (t = o(t)), "f" === i ? n.getOrCreateFile(t, a) : n.getOrCreateDir(t, a));
554
+ return P(e, e._action_removeItemExpire, i, r);
727
555
  }
728
556
 
729
557
  export {
730
- P as QyBatch
558
+ j as QyBatch
731
559
  };