New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@peerbit/document

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@peerbit/document - npm Package Compare versions

Comparing version

to
9.2.2-a1dd3d8

@@ -38,2 +38,3 @@ import { type AbstractType } from "@dao-xyz/borsh";

canPerform?: CanPerform<T>;
strictHistory?: boolean;
id?: (obj: any) => indexerTypes.IdPrimitive;

@@ -61,2 +62,3 @@ index?: {

private domain?;
private strictHistory;
canOpen?: (program: T) => Promise<boolean> | boolean;

@@ -98,4 +100,6 @@ compatibility: 6 | 7 | undefined;

}): Promise<void>;
count(_properties: {
approximate: true;
count(properties: {
approximate: true | {
eager?: boolean;
};
}): Promise<number>;

@@ -102,0 +106,0 @@ }

@@ -35,2 +35,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

domain;
strictHistory;
canOpen;

@@ -73,2 +74,3 @@ compatibility;

this.compatibility = options.compatibility;
this.strictHistory = options.strictHistory ?? false;
await this._index.open({

@@ -235,13 +237,19 @@ log: this.log,

else {
if (entry.meta.next.length !== 1) {
return false;
if (this.strictHistory) {
// make sure that the next pointer exist and points to the existing documents
if (entry.meta.next.length !== 1) {
return false;
}
const prevEntry = await this.log.log.entryIndex.get(existingDocument.context.head);
if (!prevEntry) {
logger.error("Failed to find previous entry for document edit: " +
entry.hash);
return false;
}
const referenceHistoryCorrectly = await pointsToHistory(prevEntry);
return referenceHistoryCorrectly ? putOperation : false;
}
const prevEntry = await this.log.log.entryIndex.get(existingDocument.context.head);
if (!prevEntry) {
logger.error("Failed to find previous entry for document edit: " +
entry.hash);
return false;
else {
return putOperation;
}
const referenceHistoryCorrectly = await pointsToHistory(prevEntry);
return referenceHistoryCorrectly ? putOperation : false;
}

@@ -484,3 +492,18 @@ }

// approximate the amount of documents that exists globally
async count(_properties) {
async count(properties) {
let isReplicating = await this.log.isReplicating();
if (!isReplicating) {
// fetch a subset of posts
const iterator = this.index.iterate({}, {
remote: {
eager: (typeof properties.approximate === "object" &&
properties.approximate.eager) ||
false,
},
});
const one = await iterator.next(1);
const left = iterator.pending() ?? 0;
await iterator.close();
return one.length + left;
}
let totalHeadCount = await this.log.countHeads({ approximate: true });

@@ -487,0 +510,0 @@ let totalAssignedHeads = await this.log.countAssignedHeads({

@@ -9,3 +9,3 @@ import { type AbstractType } from "@dao-xyz/borsh";

import { RPC, type RPCRequestAllOptions } from "@peerbit/rpc";
import { type ReplicationDomain, SharedLog } from "@peerbit/shared-log";
import { type CoverRange, type ReplicationDomain, SharedLog } from "@peerbit/shared-log";
import { type Operation } from "./operation.js";

@@ -17,3 +17,7 @@ import type { ExtractArgs } from "./program.js";

throwOnMissing?: boolean;
domain?: ExtractArgs<D>;
domain?: {
args: ExtractArgs<D>;
} | {
range: CoverRange<number | bigint>;
};
eager?: boolean;

@@ -33,2 +37,3 @@ };

all: () => Promise<T[]>;
pending: () => number | undefined;
};

@@ -35,0 +40,0 @@ type QueryLike = {

@@ -20,3 +20,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

import { MissingResponsesError, RPC, queryAll, } from "@peerbit/rpc";
import { SharedLog } from "@peerbit/shared-log";
import { SharedLog, } from "@peerbit/shared-log";
import { SilentDelivery } from "@peerbit/stream-interface";

@@ -619,3 +619,3 @@ import { AbortError, waitFor } from "@peerbit/time";

if (remote) {
const replicatorGroups = await this._log.getCover(remote.domain ?? undefined, {
const replicatorGroups = await this._log.getCover(remote.domain ?? { args: undefined }, {
roleAge: remote.minAge,

@@ -1014,2 +1014,9 @@ eager: remote.eager,

done: doneFn,
pending: () => {
let kept = 0;
for (const [_, buffer] of peerBufferMap) {
kept += buffer.kept;
}
return kept; // TODO this should be more accurate
},
all: async () => {

@@ -1016,0 +1023,0 @@ let result = [];

{
"name": "@peerbit/document",
"version": "9.2.1",
"description": "Document store implementation",
"type": "module",
"sideEffects": false,
"types": "./dist/src/index.d.ts",
"typesVersions": {
"*": {
"*": [
"*",
"dist/*",
"dist/src/*",
"dist/src/*/index"
],
"src/*": [
"*",
"dist/*",
"dist/src/*",
"dist/src/*/index"
]
}
},
"files": [
"src",
"dist",
"!dist/e2e",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
}
},
"eslintConfig": {
"extends": "peerbit",
"parserOptions": {
"project": true,
"sourceType": "module"
},
"ignorePatterns": [
"!.aegir.js",
"test/ts-use",
"*.d.ts"
]
},
"publishConfig": {
"access": "public"
},
"scripts": {
"clean": "aegir clean",
"build": "aegir build --no-bundle",
"test": "aegir test --target node",
"lint": "aegir lint"
},
"author": "dao.xyz",
"license": "MIT",
"dependencies": {
"@dao-xyz/borsh": "^5.2.3",
"@peerbit/program": "5.1.6",
"@peerbit/rpc": "5.0.39",
"@peerbit/shared-log": "10.4.1",
"@peerbit/indexer-interface": "^2.0.6",
"@peerbit/indexer-simple": "^1.1.10",
"@peerbit/indexer-sqlite3": "^1.2.13",
"@peerbit/document-interface": "^2.0.15"
},
"devDependencies": {
"@peerbit/test-utils": "2.1.29",
"@peerbit/time": "2.0.8",
"@types/pidusage": "^2.0.5",
"pidusage": "^3.0.2"
}
"name": "@peerbit/document",
"version": "9.2.2-a1dd3d8",
"description": "Document store implementation",
"type": "module",
"sideEffects": false,
"types": "./dist/src/index.d.ts",
"typesVersions": {
"*": {
"*": [
"*",
"dist/*",
"dist/src/*",
"dist/src/*/index"
],
"src/*": [
"*",
"dist/*",
"dist/src/*",
"dist/src/*/index"
]
}
},
"files": [
"src",
"dist",
"!dist/e2e",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
}
},
"eslintConfig": {
"extends": "peerbit",
"parserOptions": {
"project": true,
"sourceType": "module"
},
"ignorePatterns": [
"!.aegir.js",
"test/ts-use",
"*.d.ts"
]
},
"publishConfig": {
"access": "public"
},
"scripts": {
"clean": "aegir clean",
"build": "aegir build --no-bundle",
"test": "aegir test --target node",
"lint": "aegir lint"
},
"author": "dao.xyz",
"license": "MIT",
"dependencies": {
"@dao-xyz/borsh": "^5.2.3",
"@peerbit/program": "5.1.6-a1dd3d8",
"@peerbit/rpc": "5.0.39-a1dd3d8",
"@peerbit/shared-log": "10.4.2-a1dd3d8",
"@peerbit/indexer-interface": "2.0.6-a1dd3d8",
"@peerbit/indexer-simple": "1.1.10-a1dd3d8",
"@peerbit/indexer-sqlite3": "1.2.13-a1dd3d8",
"@peerbit/document-interface": "2.0.15-a1dd3d8"
},
"devDependencies": {
"@peerbit/test-utils": "2.1.29-a1dd3d8",
"@peerbit/time": "2.0.8-a1dd3d8",
"@types/pidusage": "^2.0.5",
"pidusage": "^3.0.2"
}
}

@@ -92,2 +92,3 @@ import {

canPerform?: CanPerform<T>;
strictHistory?: boolean;
id?: (obj: any) => indexerTypes.IdPrimitive;

@@ -130,3 +131,3 @@ index?: {

private domain?: CustomDocumentDomain<InferR<D>>;
private strictHistory: boolean;
canOpen?: (program: T) => Promise<boolean> | boolean;

@@ -186,2 +187,3 @@

this.compatibility = options.compatibility;
this.strictHistory = options.strictHistory ?? false;

@@ -383,18 +385,24 @@ await this._index.open({

} else {
if (entry.meta.next.length !== 1) {
return false;
}
if (this.strictHistory) {
// make sure that the next pointer exist and points to the existing documents
if (entry.meta.next.length !== 1) {
return false;
}
const prevEntry = await this.log.log.entryIndex.get(
existingDocument.context.head,
);
if (!prevEntry) {
logger.error(
"Failed to find previous entry for document edit: " +
entry.hash,
const prevEntry = await this.log.log.entryIndex.get(
existingDocument.context.head,
);
return false;
if (!prevEntry) {
logger.error(
"Failed to find previous entry for document edit: " +
entry.hash,
);
return false;
}
const referenceHistoryCorrectly =
await pointsToHistory(prevEntry);
return referenceHistoryCorrectly ? putOperation : false;
} else {
return putOperation;
}
const referenceHistoryCorrectly = await pointsToHistory(prevEntry);
return referenceHistoryCorrectly ? putOperation : false;
}

@@ -514,3 +522,2 @@ } else {

});
return appended;

@@ -697,3 +704,25 @@ }

// approximate the amount of documents that exists globally
async count(_properties: { approximate: true }): Promise<number> {
async count(properties: {
approximate: true | { eager?: boolean };
}): Promise<number> {
let isReplicating = await this.log.isReplicating();
if (!isReplicating) {
// fetch a subset of posts
const iterator = this.index.iterate(
{},
{
remote: {
eager:
(typeof properties.approximate === "object" &&
properties.approximate.eager) ||
false,
},
},
);
const one = await iterator.next(1);
const left = iterator.pending() ?? 0;
await iterator.close();
return one.length + left;
}
let totalHeadCount = await this.log.countHeads({ approximate: true });

@@ -700,0 +729,0 @@ let totalAssignedHeads = await this.log.countAssignedHeads({

@@ -23,3 +23,7 @@ import { type AbstractType, field, serialize, variant } from "@dao-xyz/borsh";

} from "@peerbit/rpc";
import { type ReplicationDomain, SharedLog } from "@peerbit/shared-log";
import {
type CoverRange,
type ReplicationDomain,
SharedLog,
} from "@peerbit/shared-log";
import { SilentDelivery } from "@peerbit/stream-interface";

@@ -47,3 +51,9 @@ import { AbortError, waitFor } from "@peerbit/time";

throwOnMissing?: boolean;
domain?: ExtractArgs<D>;
domain?:
| {
args: ExtractArgs<D>;
}
| {
range: CoverRange<number | bigint>;
};
eager?: boolean; // whether to query newly joined peers before they have matured

@@ -69,2 +79,3 @@ };

all: () => Promise<T[]>;
pending: () => number | undefined;
};

@@ -210,7 +221,2 @@

/*
if (!(await this.canRead(message.sender))) {
throw new AccessError();
} */
export type CanSearch = (

@@ -1036,3 +1042,3 @@ request: types.SearchRequest | types.CollectNextRequest,

const replicatorGroups = await this._log.getCover(
remote.domain ?? (undefined as any),
remote.domain ?? { args: undefined },
{

@@ -1623,2 +1629,9 @@ roleAge: remote.minAge,

done: doneFn,
pending: () => {
let kept = 0;
for (const [_, buffer] of peerBufferMap) {
kept += buffer.kept;
}
return kept; // TODO this should be more accurate
},
all: async () => {

@@ -1625,0 +1638,0 @@ let result: ValueTypeFromRequest<Resolve, T, I>[] = [];

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet