@peerbit/document 15.0.14 → 15.0.15

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.
@@ -41,7 +41,7 @@ import { Entry, EntryType, LamportClock, ShallowEntry, ShallowMeta, Timestamp, e
41
41
  import { logger as loggerFn } from "@peerbit/logger";
42
42
  import { Program } from "@peerbit/program";
43
43
  import { SharedLog, } from "@peerbit/shared-log";
44
- import { detachCanPerformCallbackProperties, detachEntryPayloadForCallback, } from "./callback-detachment.js";
44
+ import { detachCanPerformCallbackProperties, detachEntryForCallback, detachEntryPayloadForCallback, } from "./callback-detachment.js";
45
45
  import { MAX_BATCH_SIZE } from "./constants.js";
46
46
  import { BORSH_ENCODING_OPERATION, DeleteOperation, PutOperation, PutWithKeyOperation, coerceDeleteOperation, isDeleteOperation, isPutOperation, } from "./operation.js";
47
47
  import { createCanPerformPolicyEvaluator, createCanPerformDeletePolicyEvaluator, getCanPerformPolicyDescriptor, canPerformPolicyDeleteFieldPaths, canPerformPolicyNeedsDeleteValue, canPerformPolicyNeedsPreviousEntries, canPerformPolicyPutNeedsEntryPublicKeys, canPerformPolicySignedByFieldPaths, } from "./policy.js";
@@ -430,11 +430,7 @@ let Documents = (() => {
430
430
  const boundMethods = new Map();
431
431
  const detachedFromEntry = (entry) => {
432
432
  const fromEntry = Reflect.get(domain, "fromEntry", domain);
433
- return Reflect.apply(fromEntry, domain, [
434
- entry instanceof Entry
435
- ? detachEntryPayloadForCallback(entry)
436
- : entry,
437
- ]);
433
+ return Reflect.apply(fromEntry, domain, [detachEntryForCallback(entry)]);
438
434
  };
439
435
  const facade = Object.create(Object.getPrototypeOf(domain));
440
436
  let callbackDomain;
@@ -490,6 +486,22 @@ let Documents = (() => {
490
486
  });
491
487
  return callbackDomain;
492
488
  }
489
+ detachTrimEntryCallback(option) {
490
+ const filter = option?.filter;
491
+ if (!option || !filter?.canTrim) {
492
+ return option;
493
+ }
494
+ const canTrim = filter.canTrim;
495
+ return {
496
+ ...option,
497
+ filter: {
498
+ ...filter,
499
+ canTrim: function (entry) {
500
+ return Reflect.apply(canTrim, this, [detachEntryForCallback(entry)]);
501
+ },
502
+ },
503
+ };
504
+ }
493
505
  createNativeDocumentBackendContext() {
494
506
  return {
495
507
  assertPlainPutSupported: (doc, options) => {
@@ -1371,11 +1383,7 @@ let Documents = (() => {
1371
1383
  const keep = options?.keep;
1372
1384
  keepFunction = keep
1373
1385
  ? function (entry) {
1374
- return Reflect.apply(keep, this, [
1375
- entry instanceof Entry
1376
- ? detachEntryPayloadForCallback(entry)
1377
- : entry,
1378
- ]);
1386
+ return Reflect.apply(keep, this, [detachEntryForCallback(entry)]);
1379
1387
  }
1380
1388
  : undefined;
1381
1389
  }
@@ -1384,7 +1392,7 @@ let Documents = (() => {
1384
1392
  canReplicate: options?.canReplicate,
1385
1393
  canAppend: this.canAppend.bind(this),
1386
1394
  onChange: this.handleChanges.bind(this),
1387
- trim: options?.log?.trim,
1395
+ trim: this.detachTrimEntryCallback(options?.log?.trim),
1388
1396
  appendDurability: options?.appendDurability,
1389
1397
  nativeBackbone: options?.nativeBackbone,
1390
1398
  nativeGraph: options?.nativeGraph,