@peerbit/document
Advanced tools
@@ -97,2 +97,3 @@ import { type AbstractType } from "@dao-xyz/borsh"; | ||
operation: PutOperation; | ||
unique?: boolean; | ||
}): Promise<void>; | ||
@@ -99,0 +100,0 @@ count(properties: { |
@@ -415,2 +415,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
} | ||
// if no casual ordering is used, use timestamps to order docs | ||
let existing = reference?.unique | ||
? null | ||
: (await this._index.index.get(key)) || null; | ||
if (!this.strictHistory && existing) { | ||
// if immutable use oldest, else use newest | ||
let shouldIgnoreChange = this.immutable | ||
? existing.value.__context.modified < | ||
item.meta.clock.timestamp.wallTime | ||
: existing.value.__context.modified > | ||
item.meta.clock.timestamp.wallTime; | ||
if (shouldIgnoreChange) { | ||
continue; | ||
} | ||
} | ||
// Program specific | ||
@@ -421,3 +436,3 @@ if (value instanceof Program) { | ||
} | ||
const context = await this._index.put(value, key, item); | ||
const context = await this._index.put(value, key, item, existing); | ||
documentsChanged.added.push(coerceWithContext(value, context)); | ||
@@ -424,0 +439,0 @@ modified.add(key.primitive); |
@@ -105,3 +105,3 @@ import { type AbstractType } from "@dao-xyz/borsh"; | ||
getFromGid(gid: string): Promise<indexerTypes.IndexedResult<WithContext<I>>>; | ||
put(value: T, id: indexerTypes.IdKey, entry: Entry<Operation>): Promise<types.Context>; | ||
put(value: T, id: indexerTypes.IdKey, entry: Entry<Operation>, existing: indexerTypes.IndexedResult<WithContext<I>> | null | undefined): Promise<types.Context>; | ||
putWithContext(value: T, id: indexerTypes.IdKey, context: types.Context): Promise<types.Context>; | ||
@@ -108,0 +108,0 @@ del(key: indexerTypes.IdKey): indexerTypes.IdKey[] | Promise<indexerTypes.IdKey[]>; |
@@ -296,6 +296,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
} | ||
async put(value, id, entry) { | ||
const existing = await this.index.get(id); | ||
async put(value, id, entry, existing) { | ||
const existingDefined = existing === undefined ? await this.index.get(id) : existing; | ||
const context = new types.Context({ | ||
created: existing?.value.__context.created || | ||
created: existingDefined?.value.__context.created || | ||
entry.meta.clock.timestamp.wallTime, | ||
@@ -302,0 +302,0 @@ modified: entry.meta.clock.timestamp.wallTime, |
{ | ||
"name": "@peerbit/document", | ||
"version": "9.3.0", | ||
"version": "9.3.1", | ||
"description": "Document store implementation", | ||
@@ -62,12 +62,12 @@ "type": "module", | ||
"@dao-xyz/borsh": "^5.2.3", | ||
"@peerbit/program": "5.1.7", | ||
"@peerbit/rpc": "5.0.40", | ||
"@peerbit/shared-log": "10.4.3", | ||
"@peerbit/program": "5.1.8", | ||
"@peerbit/rpc": "5.0.41", | ||
"@peerbit/shared-log": "10.4.4", | ||
"@peerbit/indexer-interface": "^2.0.7", | ||
"@peerbit/indexer-simple": "^1.1.11", | ||
"@peerbit/indexer-sqlite3": "^1.2.14", | ||
"@peerbit/document-interface": "^2.0.16" | ||
"@peerbit/document-interface": "^2.0.17" | ||
}, | ||
"devDependencies": { | ||
"@peerbit/test-utils": "2.1.30", | ||
"@peerbit/test-utils": "2.1.31", | ||
"@peerbit/time": "2.0.8", | ||
@@ -74,0 +74,0 @@ "@types/pidusage": "^2.0.5", |
@@ -556,3 +556,3 @@ import { | ||
change: Change<Operation>, | ||
reference?: { document: T; operation: PutOperation }, | ||
reference?: { document: T; operation: PutOperation; unique?: boolean }, | ||
): Promise<void> { | ||
@@ -615,2 +615,18 @@ const isAppendOperation = | ||
// if no casual ordering is used, use timestamps to order docs | ||
let existing = reference?.unique | ||
? null | ||
: (await this._index.index.get(key)) || null; | ||
if (!this.strictHistory && existing) { | ||
// if immutable use oldest, else use newest | ||
let shouldIgnoreChange = this.immutable | ||
? existing.value.__context.modified < | ||
item.meta.clock.timestamp.wallTime | ||
: existing.value.__context.modified > | ||
item.meta.clock.timestamp.wallTime; | ||
if (shouldIgnoreChange) { | ||
continue; | ||
} | ||
} | ||
// Program specific | ||
@@ -621,3 +637,3 @@ if (value instanceof Program) { | ||
} | ||
const context = await this._index.put(value, key, item); | ||
const context = await this._index.put(value, key, item, existing); | ||
documentsChanged.added.push(coerceWithContext(value, context)); | ||
@@ -624,0 +640,0 @@ |
@@ -587,7 +587,13 @@ import { type AbstractType, field, serialize, variant } from "@dao-xyz/borsh"; | ||
} | ||
public async put(value: T, id: indexerTypes.IdKey, entry: Entry<Operation>) { | ||
const existing = await this.index.get(id); | ||
public async put( | ||
value: T, | ||
id: indexerTypes.IdKey, | ||
entry: Entry<Operation>, | ||
existing: indexerTypes.IndexedResult<WithContext<I>> | null | undefined, | ||
) { | ||
const existingDefined = | ||
existing === undefined ? await this.index.get(id) : existing; | ||
const context = new types.Context({ | ||
created: | ||
existing?.value.__context.created || | ||
existingDefined?.value.__context.created || | ||
entry.meta.clock.timestamp.wallTime, | ||
@@ -594,0 +600,0 @@ modified: entry.meta.clock.timestamp.wallTime, |
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
309122
0.8%5578
0.67%