@vrtmrz/livesync-commonlib 0.1.44 → 0.2.1

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 (92) hide show
  1. package/README.md +80 -4
  2. package/dist/API/DirectFileManipulatorV2.d.ts +2 -0
  3. package/dist/API/DirectFileManipulatorV2.js +3 -0
  4. package/dist/API/processSetting.d.ts +1 -0
  5. package/dist/common/configForDoc.d.ts +1 -0
  6. package/dist/common/configForDoc.js +11 -1
  7. package/dist/common/models/db.definition.d.ts +1 -0
  8. package/dist/common/models/setting.const.defaults.js +1 -0
  9. package/dist/common/models/setting.const.preferred.js +1 -3
  10. package/dist/common/models/setting.const.qr.js +1 -0
  11. package/dist/common/models/setting.policy.d.ts +4 -0
  12. package/dist/common/models/setting.policy.js +1 -0
  13. package/dist/common/models/setting.type.d.ts +2 -0
  14. package/dist/common/models/shared.definition.d.ts +20 -0
  15. package/dist/common/models/tweak.definition.d.ts +1 -0
  16. package/dist/common/settingConstants.d.ts +1 -0
  17. package/dist/common/settingConstants.js +6 -2
  18. package/dist/interfaces/FileHandler.d.ts +5 -1
  19. package/dist/interfaces/StorageEventManager.d.ts +5 -0
  20. package/dist/interfaces/StorageEventManager.js +7 -0
  21. package/dist/managers/EntryManager/EntryManagerImpls.js +3 -2
  22. package/dist/managers/StorageEventManager.d.ts +19 -10
  23. package/dist/managers/StorageEventManager.js +259 -189
  24. package/dist/pouchdb/LiveSyncDBFunctions.js +4 -0
  25. package/dist/pouchdb/StreamingFetch.d.ts +5 -1
  26. package/dist/pouchdb/StreamingFetch.js +529 -65
  27. package/dist/replication/LiveSyncAbstractReplicator.d.ts +2 -0
  28. package/dist/replication/LiveSyncAbstractReplicator.js +5 -2
  29. package/dist/replication/RemoteResource.d.ts +23 -2
  30. package/dist/replication/RemoteResource.js +6 -2
  31. package/dist/replication/couchdb/LiveSyncReplicator.d.ts +14 -0
  32. package/dist/replication/couchdb/LiveSyncReplicator.js +171 -3
  33. package/dist/replication/couchdb/fastForward.d.ts +19 -0
  34. package/dist/replication/couchdb/fastForward.js +119 -0
  35. package/dist/replication/couchdb/replicationProgress.d.ts +6 -0
  36. package/dist/replication/couchdb/replicationProgress.js +105 -0
  37. package/dist/replication/index.d.ts +4 -1
  38. package/dist/replication/joinedDevices.d.ts +25 -0
  39. package/dist/replication/joinedDevices.js +123 -0
  40. package/dist/replication/journal/JournalSyncCore.d.ts +2 -1
  41. package/dist/replication/journal/JournalSyncCore.js +11 -1
  42. package/dist/replication/journal/LiveSyncJournalReplicator.d.ts +4 -0
  43. package/dist/replication/journal/LiveSyncJournalReplicator.js +56 -1
  44. package/dist/replication/journal/objectstore/JournalStorageAdapter.d.ts +3 -0
  45. package/dist/replication/journal/objectstore/MinioStorageAdapter.d.ts +2 -1
  46. package/dist/replication/journal/objectstore/MinioStorageAdapter.js +27 -1
  47. package/dist/replication/trystero/P2PRoomSessionOwner.d.ts +1 -1
  48. package/dist/replication/trystero/P2PRoomSessionOwner.js +27 -14
  49. package/dist/replication/trystero/TrysteroReplicator.d.ts +2 -0
  50. package/dist/serviceFeatures/offlineScanner.js +19 -7
  51. package/dist/serviceModules/Rebuilder.js +41 -15
  52. package/dist/serviceModules/ServiceFileAccessBase.js +5 -0
  53. package/dist/serviceModules/ServiceFileHandlerBase.d.ts +8 -5
  54. package/dist/serviceModules/ServiceFileHandlerBase.js +75 -38
  55. package/dist/services/BrowserServices.d.ts +4 -2
  56. package/dist/services/BrowserServices.js +2 -5
  57. package/dist/services/HeadlessServices.d.ts +3 -0
  58. package/dist/services/HeadlessServices.js +2 -5
  59. package/dist/services/ServiceHub.d.ts +4 -4
  60. package/dist/services/base/AppLifecycleService.js +1 -1
  61. package/dist/services/base/ControlService.js +6 -2
  62. package/dist/services/base/FileProcessingService.d.ts +7 -1
  63. package/dist/services/base/FileProcessingService.js +9 -1
  64. package/dist/services/base/IService.d.ts +19 -19
  65. package/dist/services/base/ReplicatorService.d.ts +1 -0
  66. package/dist/services/base/ReplicatorService.remoteResourceResolver.js +1 -1
  67. package/dist/services/base/SettingService.d.ts +8 -18
  68. package/dist/services/base/SettingService.js +28 -46
  69. package/dist/services/implements/base/SvelteDialog.d.ts +2 -2
  70. package/dist/services/implements/base/UIService.d.ts +2 -0
  71. package/dist/services/implements/base/UIService.js +5 -0
  72. package/dist/services/implements/injectable/InjectableServiceHub.d.ts +4 -4
  73. package/dist/services/implements/injectable/InjectableServices.d.ts +2 -2
  74. package/dist/services/implements/injectable/InjectableSettingService.d.ts +0 -3
  75. package/dist/services/implements/injectable/InjectableSettingService.js +0 -11
  76. package/dist/services/lib/HandlerUtils.d.ts +60 -0
  77. package/dist/services/lib/HandlerUtils.js +46 -0
  78. package/dist/string_and_binary/chunks.js +7 -5
  79. package/dist/uiCommands.d.ts +26 -0
  80. package/dist/uiCommands.js +57 -0
  81. package/dist/worker/bgWorker.js +1 -1
  82. package/docs/development.md +15 -3
  83. package/docs/offline-scanner.md +15 -13
  84. package/docs/proven-in-use.md +38 -4
  85. package/docs/releasing.md +20 -13
  86. package/docs/settings-lifecycle.md +39 -5
  87. package/docs/storage-events-and-reflection.md +109 -10
  88. package/package.json +13 -18
  89. package/dist/services/base/ConfigService.d.ts +0 -7
  90. package/dist/services/base/ConfigService.js +0 -6
  91. package/dist/services/implements/browser/ConfigServiceBrowserCompat.d.ts +0 -16
  92. package/dist/services/implements/browser/ConfigServiceBrowserCompat.js +0 -23
@@ -326,6 +326,30 @@ class FirstResultHandler extends MultiBinder {
326
326
  return false;
327
327
  }
328
328
  }
329
+ class FirstHandledHandler extends MultiBinder {
330
+ /**
331
+ * Whether at least one callback is currently registered.
332
+ */
333
+ get hasHandlers() {
334
+ return this._callbackMap.size > 0;
335
+ }
336
+ /**
337
+ * Invokes handlers until one returns a completed or veto outcome.
338
+ * @param args The arguments to pass to the handlers.
339
+ * @returns The first handled outcome, or a not-applicable outcome when no handler applies.
340
+ * @throws Any synchronous callback error or rejected callback value, unchanged.
341
+ */
342
+ async invoke(...args) {
343
+ const callbacks = [...this._callbacks];
344
+ for (const callback of callbacks) {
345
+ const outcome = await Promise.resolve(callback(...args));
346
+ if (outcome.kind !== "not-applicable") {
347
+ return outcome;
348
+ }
349
+ }
350
+ return { kind: "not-applicable" };
351
+ }
352
+ }
329
353
  function getMultipleBound(handler) {
330
354
  const _handler = "invoke" in handler ? handler.invoke : handler.dispatch;
331
355
  const __handler = _handler.bind(handler);
@@ -367,6 +391,17 @@ function firstResultFunction(name) {
367
391
  const handler = new FirstResultHandler(name ?? "firstResultFunction");
368
392
  return getMultipleBound(handler);
369
393
  }
394
+ function firstHandledFunction(name) {
395
+ const handler = new FirstHandledHandler(
396
+ name ?? "firstHandledFunction"
397
+ );
398
+ const toHandlerCallback = (callback) => callback;
399
+ const bound = (...args) => handler.invoke(...args);
400
+ bound.addHandler = (callback, priority) => handler.addHandler(toHandlerCallback(callback), priority);
401
+ bound.removeHandler = (callback) => handler.removeHandler(toHandlerCallback(callback));
402
+ Object.defineProperty(bound, "hasHandlers", { get: () => handler.hasHandlers });
403
+ return bound;
404
+ }
370
405
  function dispatchParallelFunction(name) {
371
406
  const handler = new DispatchParallel(
372
407
  name ?? "dispatchParallelFunction"
@@ -452,6 +487,15 @@ function handlers() {
452
487
  firstResult(name) {
453
488
  return firstResultFunction(String(name));
454
489
  },
490
+ /**
491
+ * Create a handler that invokes registered handlers until one completes or vetoes.
492
+ * Callback errors and rejections propagate unchanged.
493
+ * @param name The name of the callback on `T`.
494
+ * @returns A bound handler with a live `hasHandlers` property.
495
+ */
496
+ firstHandled(name) {
497
+ return firstHandledFunction(String(name));
498
+ },
455
499
  /**
456
500
  * Create a handler that invokes all added handler functions in parallel.
457
501
  * @param name
@@ -481,6 +525,7 @@ export {
481
525
  BooleanHandlerBase,
482
526
  Dispatch,
483
527
  DispatchParallel,
528
+ FirstHandledHandler,
484
529
  FirstResultHandler,
485
530
  LazyBinder,
486
531
  MultiBinder,
@@ -494,6 +539,7 @@ export {
494
539
  bailFirstFailureWithResultFunction,
495
540
  bindableFunction,
496
541
  dispatchParallelFunction,
542
+ firstHandledFunction,
497
543
  firstResultFunction,
498
544
  handlers,
499
545
  lazyBindableFunction
@@ -404,14 +404,16 @@ async function splitPiecesRabinKarp(dataSrc, absoluteMaxPieceSize, doPlainSplit,
404
404
  }
405
405
  }
406
406
  const chunkUnitBinary = 256 * 1024;
407
- const fixedAvgChunkSize = plainSplit ? chunkUnitPlain * 4 : chunkUnitBinary * 4;
408
407
  const fixedMaxChunkSize = plainSplit ? chunkUnitPlain * 16 : chunkUnitBinary * 16;
409
- const fixedMinChunkSize = plainSplit ? chunkUnitPlain * 2 : chunkUnitBinary;
410
408
  const rkAbsoluteMaxPieceSizeFloor = 30 * 1024;
411
409
  const effectiveAbsoluteMaxPieceSize = Math.max(absoluteMaxPieceSize, rkAbsoluteMaxPieceSizeFloor);
412
410
  const maxChunkSize = Math.min(fixedMaxChunkSize, effectiveAbsoluteMaxPieceSize);
413
- const minChunkSize = Math.min(Math.max(fixedMinChunkSize, minimumChunkSize), maxChunkSize);
414
- const avgChunkSize = Math.min(Math.max(fixedAvgChunkSize, minChunkSize), maxChunkSize);
411
+ const proportionalGap = Math.max(1, Math.floor(maxChunkSize / 4));
412
+ const minChunkSize = Math.min(
413
+ Math.max(plainSplit ? chunkUnitPlain * 2 : proportionalGap, minimumChunkSize),
414
+ maxChunkSize
415
+ );
416
+ const avgChunkSize = plainSplit ? Math.min(Math.max(chunkUnitPlain * 4, minChunkSize), maxChunkSize) : proportionalGap;
415
417
  const windowSize = 48;
416
418
  const hashModulus = avgChunkSize;
417
419
  const boundaryPattern = 1;
@@ -429,7 +431,7 @@ async function splitPiecesRabinKarp(dataSrc, absoluteMaxPieceSize, doPlainSplit,
429
431
  return async function* piecesBlob() {
430
432
  while (pos < length) {
431
433
  const byte = buffer[pos];
432
- if (pos >= start + windowSize) {
434
+ if (pos >= windowSize) {
433
435
  const oldByte = buffer[pos - windowSize];
434
436
  const oldByteTerm = Math.imul(oldByte, P_pow_w);
435
437
  hash = hash - oldByteTerm | 0;
@@ -0,0 +1,26 @@
1
+ declare const commandTypes: unique symbol;
2
+ /** An immutable declaration which associates a stable name with request and result types. */
3
+ export interface UICommand<Request, Result> {
4
+ readonly id: string;
5
+ readonly [commandTypes]?: {
6
+ readonly request: (value: Request) => Request;
7
+ readonly result: (value: Result) => Result;
8
+ };
9
+ }
10
+ /** Declare a command without registering it in any global state. */
11
+ export declare function declareUICommand<Request, Result>(id: string): UICommand<Request, Result>;
12
+ /** Instance-owned command handlers for one host or service composition. */
13
+ export declare class UICommandRegistry {
14
+ private readonly definitions;
15
+ private readonly handlers;
16
+ private disposed;
17
+ register<Request, Result>(command: UICommand<Request, Result>, handler: (request: NoInfer<Request>) => NoInfer<Result> | Promise<NoInfer<Result>>): () => void;
18
+ invoke<Request, Result>(command: UICommand<Request, Result>, input: NoInfer<Request>): Promise<{
19
+ status: "handled";
20
+ value: Result;
21
+ } | {
22
+ status: "unavailable";
23
+ }>;
24
+ dispose(): void;
25
+ }
26
+ export {};
@@ -0,0 +1,57 @@
1
+ function declareUICommand(id) {
2
+ return Object.freeze({ id });
3
+ }
4
+ class UICommandRegistry {
5
+ definitions = /* @__PURE__ */ new Map();
6
+ handlers = /* @__PURE__ */ new Map();
7
+ disposed = false;
8
+ register(command, handler) {
9
+ if (this.disposed) {
10
+ throw new Error("Cannot register a UI command on a disposed registry");
11
+ }
12
+ const knownDefinition = this.definitions.get(command.id);
13
+ if (knownDefinition !== void 0 && knownDefinition !== command) {
14
+ throw new Error(`A conflicting command definition is already known for '${command.id}'`);
15
+ }
16
+ if (this.handlers.has(command.id)) {
17
+ throw new Error(`A handler is already registered for '${command.id}'`);
18
+ }
19
+ this.definitions.set(command.id, command);
20
+ const entry = {
21
+ command,
22
+ handler: (input) => handler(input)
23
+ };
24
+ this.handlers.set(command.id, entry);
25
+ let active = true;
26
+ return () => {
27
+ if (!active) return;
28
+ active = false;
29
+ if (this.handlers.get(command.id) === entry) {
30
+ this.handlers.delete(command.id);
31
+ }
32
+ };
33
+ }
34
+ async invoke(command, input) {
35
+ if (this.disposed) {
36
+ return { status: "unavailable" };
37
+ }
38
+ const entry = this.handlers.get(command.id);
39
+ if (entry === void 0 || entry.command !== command) {
40
+ return { status: "unavailable" };
41
+ }
42
+ return {
43
+ status: "handled",
44
+ value: await entry.handler(input)
45
+ };
46
+ }
47
+ dispose() {
48
+ if (this.disposed) return;
49
+ this.disposed = true;
50
+ this.handlers.clear();
51
+ this.definitions.clear();
52
+ }
53
+ }
54
+ export {
55
+ UICommandRegistry,
56
+ declareUICommand
57
+ };