@peerbit/document
Advanced tools
Comparing version 9.0.26-a70fbaa to 9.0.26-aea0cef
export * from "@peerbit/indexer-interface"; | ||
export * from "@peerbit/document-interface"; | ||
export * from "./program.js"; | ||
export type { CanRead, CanSearch, DocumentIndex, IDocumentWithContext, OpenOptions, QueryOptions, RemoteQueryOptions, ResultsIterator, SearchOptions, TransformOptions, TransformerAsConstructor, TransformerAsFunction, } from "./search.js"; | ||
export type { CanRead, CanSearch, DocumentIndex, WithIndexedContext, OpenOptions, QueryOptions, RemoteQueryOptions, ResultsIterator, SearchOptions, TransformOptions, TransformerAsConstructor, TransformerAsFunction, } from "./search.js"; | ||
export * from "./operation.js"; | ||
@@ -6,0 +6,0 @@ export { MAX_BATCH_SIZE as MAX_DOCUMENT_SIZE } from "./constants.js"; |
@@ -40,3 +40,3 @@ import { type AbstractType } from "@dao-xyz/borsh"; | ||
export type CanReadIndexed<I> = (result: I, from: PublicSignKey) => Promise<boolean> | boolean; | ||
type ValueTypeFromRequest<Resolve extends boolean | undefined, T, I> = Resolve extends false ? I : T; | ||
type ValueTypeFromRequest<Resolve extends boolean | undefined, T, I> = Resolve extends false ? WithContext<I> : WithContext<T>; | ||
export declare class IndexableContext implements types.Context { | ||
@@ -57,5 +57,8 @@ created: bigint; | ||
} | ||
export type IDocumentWithContext<I> = { | ||
export type WithIndexedContext<I> = { | ||
__context: IndexableContext; | ||
} & I; | ||
export type WithContext<I> = { | ||
__context: types.Context; | ||
} & I; | ||
export type TransformerAsConstructor<T, I> = { | ||
@@ -82,3 +85,3 @@ type?: new (arg: T, context: types.Context) => I; | ||
}; | ||
type IndexableClass<I> = new (value: I, context: IndexableContext) => IDocumentWithContext<I>; | ||
type IndexableClass<I> = new (value: I, context: IndexableContext) => WithIndexedContext<I>; | ||
export declare class DocumentIndex<T, I extends Record<string, any>, D extends ReplicationDomain<any, Operation, any>> extends Program<OpenOptions<T, I, D>> { | ||
@@ -94,3 +97,3 @@ _query: RPC<types.AbstractSearchRequest, types.AbstractSearchResult>; | ||
private indexByResolver; | ||
index: indexerTypes.Index<IDocumentWithContext<I>>; | ||
index: indexerTypes.Index<WithIndexedContext<I>>; | ||
private _resumableIterators; | ||
@@ -115,5 +118,5 @@ compatibility: 6 | 7 | 8 | undefined; | ||
drop(from?: Program): Promise<boolean>; | ||
get<Options extends QueryOptions<T, D, true | undefined>>(key: indexerTypes.Ideable | indexerTypes.IdKey, options?: Options): Promise<T>; | ||
get<Options extends QueryOptions<T, D, false>>(key: indexerTypes.Ideable | indexerTypes.IdKey, options?: Options): Promise<I>; | ||
getFromGid(gid: string): Promise<indexerTypes.IndexedResult<IDocumentWithContext<I>>>; | ||
get<Options extends QueryOptions<T, D, true | undefined>>(key: indexerTypes.Ideable | indexerTypes.IdKey, options?: Options): Promise<WithContext<T>>; | ||
get<Options extends QueryOptions<T, D, false>>(key: indexerTypes.Ideable | indexerTypes.IdKey, options?: Options): Promise<WithContext<I>>; | ||
getFromGid(gid: string): Promise<indexerTypes.IndexedResult<WithIndexedContext<I>>>; | ||
put(value: T, entry: Entry<Operation>, id: indexerTypes.IdKey): Promise<void>; | ||
@@ -120,0 +123,0 @@ del(key: indexerTypes.IdKey): indexerTypes.IdKey[] | Promise<indexerTypes.IdKey[]>; |
@@ -154,2 +154,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
}; | ||
const coerceWithContext = (properties) => { | ||
let valueWithContext = properties.value; | ||
valueWithContext.__context = properties.context; | ||
return valueWithContext; | ||
}; | ||
let DocumentIndex = class DocumentIndex extends Program { | ||
@@ -327,3 +332,6 @@ _query; | ||
async get(key, options) { | ||
return (await this.getDetailed(key instanceof indexerTypes.IdKey ? key : indexerTypes.toId(key), options))?.[0]?.results[0]?.value; | ||
const result = (await this.getDetailed(key instanceof indexerTypes.IdKey ? key : indexerTypes.toId(key), options))?.[0]?.results[0]; | ||
if (result) { | ||
return coerceWithContext(result); | ||
} | ||
} | ||
@@ -999,3 +1007,3 @@ async getFromGid(gid) { | ||
else { | ||
coercedBatch = batch.map((x) => x.value); | ||
coercedBatch = batch.map((x) => coerceWithContext(x)); | ||
} | ||
@@ -1002,0 +1010,0 @@ return dedup(coercedBatch, this.indexByResolver); |
{ | ||
"name": "@peerbit/document", | ||
"version": "9.0.26-a70fbaa", | ||
"version": "9.0.26-aea0cef", | ||
"description": "Document store implementation", | ||
@@ -62,13 +62,13 @@ "type": "module", | ||
"@dao-xyz/borsh": "^5.2.3", | ||
"@peerbit/program": "5.1.6-a70fbaa", | ||
"@peerbit/rpc": "5.0.36-a70fbaa", | ||
"@peerbit/shared-log": "10.3.21-a70fbaa", | ||
"@peerbit/indexer-interface": "2.0.6-a70fbaa", | ||
"@peerbit/indexer-simple": "1.1.9-a70fbaa", | ||
"@peerbit/indexer-sqlite3": "1.2.10-a70fbaa", | ||
"@peerbit/document-interface": "2.0.11-a70fbaa" | ||
"@peerbit/program": "5.1.6-aea0cef", | ||
"@peerbit/rpc": "5.0.36-aea0cef", | ||
"@peerbit/shared-log": "10.3.21-aea0cef", | ||
"@peerbit/indexer-interface": "2.0.6-aea0cef", | ||
"@peerbit/indexer-simple": "1.1.9-aea0cef", | ||
"@peerbit/indexer-sqlite3": "1.2.10-aea0cef", | ||
"@peerbit/document-interface": "2.0.11-aea0cef" | ||
}, | ||
"devDependencies": { | ||
"@peerbit/test-utils": "2.1.26-a70fbaa", | ||
"@peerbit/time": "2.0.8-a70fbaa", | ||
"@peerbit/test-utils": "2.1.26-aea0cef", | ||
"@peerbit/time": "2.0.8-aea0cef", | ||
"@types/pidusage": "^2.0.5", | ||
@@ -75,0 +75,0 @@ "pidusage": "^3.0.2" |
@@ -8,3 +8,3 @@ export * from "@peerbit/indexer-interface"; | ||
DocumentIndex, | ||
IDocumentWithContext, | ||
WithIndexedContext, | ||
OpenOptions, | ||
@@ -11,0 +11,0 @@ QueryOptions, |
@@ -237,3 +237,3 @@ import { type AbstractType, field, serialize, variant } from "@dao-xyz/borsh"; | ||
I, | ||
> = Resolve extends false ? I : T; | ||
> = Resolve extends false ? WithContext<I> : WithContext<T>; | ||
@@ -281,6 +281,10 @@ @variant(0) | ||
export type IDocumentWithContext<I> = { | ||
export type WithIndexedContext<I> = { | ||
__context: IndexableContext; | ||
} & I; | ||
export type WithContext<I> = { | ||
__context: types.Context; | ||
} & I; | ||
export type TransformerAsConstructor<T, I> = { | ||
@@ -332,4 +336,13 @@ type?: new (arg: T, context: types.Context) => I; | ||
context: IndexableContext, | ||
) => IDocumentWithContext<I>; | ||
) => WithIndexedContext<I>; | ||
const coerceWithContext = <T>(properties: { | ||
value: T; | ||
context: types.Context; | ||
}): WithContext<T> => { | ||
let valueWithContext: WithContext<T> = properties.value as any; | ||
valueWithContext.__context = properties.context; | ||
return valueWithContext; | ||
}; | ||
@variant("documents_index") | ||
@@ -361,4 +374,4 @@ export class DocumentIndex< | ||
private indexByResolver: (obj: any) => string | Uint8Array; | ||
index: indexerTypes.Index<IDocumentWithContext<I>>; | ||
private _resumableIterators: ResumableIterators<IDocumentWithContext<I>>; | ||
index: indexerTypes.Index<WithIndexedContext<I>>; | ||
private _resumableIterators: ResumableIterators<WithIndexedContext<I>>; | ||
@@ -390,3 +403,3 @@ compatibility: 6 | 7 | 8 | undefined; | ||
timeout: ReturnType<typeof setTimeout>; | ||
queue: indexerTypes.IndexedResult<IDocumentWithContext<I>>[]; | ||
queue: indexerTypes.IndexedResult<WithIndexedContext<I>>[]; | ||
fromQuery: types.SearchRequest | types.SearchRequestIndexed; | ||
@@ -435,3 +448,3 @@ } | ||
context: types.Context, | ||
) => IDocumentWithContext<I>; | ||
) => WithIndexedContext<I>; | ||
@@ -482,3 +495,3 @@ // if this.type is a class that extends Program we want to do special functionality | ||
/* maxBatchSize: MAX_BATCH_SIZE */ | ||
})) || new HashmapIndex<IDocumentWithContext<I>>(); | ||
})) || new HashmapIndex<WithIndexedContext<I>>(); | ||
@@ -594,3 +607,3 @@ this._resumableIterators = new ResumableIterators(this.index); | ||
options?: Options, | ||
): Promise<T>; | ||
): Promise<WithContext<T>>; | ||
@@ -600,3 +613,3 @@ public async get<Options extends QueryOptions<T, D, false>>( | ||
options?: Options, | ||
): Promise<I>; | ||
): Promise<WithContext<I>>; | ||
@@ -607,3 +620,3 @@ public async get< | ||
>(key: indexerTypes.Ideable | indexerTypes.IdKey, options?: Options) { | ||
return ( | ||
const result = ( | ||
await this.getDetailed( | ||
@@ -613,3 +626,8 @@ key instanceof indexerTypes.IdKey ? key : indexerTypes.toId(key), | ||
) | ||
)?.[0]?.results[0]?.value; | ||
)?.[0]?.results[0]; | ||
if (result) { | ||
return coerceWithContext( | ||
result as { value: unknown; context: types.Context }, | ||
); | ||
} | ||
} | ||
@@ -847,3 +865,3 @@ | ||
let indexedResult: | ||
| indexerTypes.IndexedResults<IDocumentWithContext<I>> | ||
| indexerTypes.IndexedResults<WithIndexedContext<I>> | ||
| undefined = undefined; | ||
@@ -1584,7 +1602,5 @@ | ||
} else { | ||
coercedBatch = batch.map((x) => x.value) as ValueTypeFromRequest< | ||
Resolve, | ||
T, | ||
I | ||
>[]; | ||
coercedBatch = batch.map((x) => | ||
coerceWithContext(x as { value: unknown; context: types.Context }), | ||
) as ValueTypeFromRequest<Resolve, T, I>[]; | ||
} | ||
@@ -1591,0 +1607,0 @@ |
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
300822
5460
+ Added@peerbit/any-store@2.1.6-aea0cef(transitive)
+ Added@peerbit/any-store-interface@1.0.0-aea0cef(transitive)
+ Added@peerbit/any-store-opfs@1.0.6-aea0cef(transitive)
+ Added@peerbit/blocks-interface@1.3.12-aea0cef(transitive)
+ Added@peerbit/cache@2.1.2-aea0cef(transitive)
+ Added@peerbit/crypto@2.3.5-aea0cef(transitive)
+ Added@peerbit/document-interface@2.0.11-aea0cef(transitive)
+ Added@peerbit/indexer-interface@2.0.6-aea0cef(transitive)
+ Added@peerbit/indexer-simple@1.1.9-aea0cef(transitive)
+ Added@peerbit/indexer-sqlite3@1.2.10-aea0cef(transitive)
+ Added@peerbit/keychain@1.0.24-aea0cef(transitive)
+ Added@peerbit/log@4.0.38-aea0cef(transitive)
+ Added@peerbit/logger@1.0.3-aea0cef(transitive)
+ Added@peerbit/program@5.1.6-aea0cef(transitive)
+ Added@peerbit/pubsub-interface@3.1.4-aea0cef(transitive)
+ Added@peerbit/riblt@1.0.6-aea0cef(transitive)
+ Added@peerbit/rpc@5.0.36-aea0cef(transitive)
+ Added@peerbit/shared-log@10.3.21-aea0cef(transitive)
+ Added@peerbit/stream-interface@5.1.4-aea0cef(transitive)
+ Added@peerbit/time@2.0.8-aea0cef(transitive)
- Removed@peerbit/any-store@2.1.6-a70fbaa(transitive)
- Removed@peerbit/any-store-interface@1.0.0-a70fbaa(transitive)
- Removed@peerbit/any-store-opfs@1.0.6-a70fbaa(transitive)
- Removed@peerbit/blocks-interface@1.3.12-a70fbaa(transitive)
- Removed@peerbit/cache@2.1.2-a70fbaa(transitive)
- Removed@peerbit/crypto@2.3.5-a70fbaa(transitive)
- Removed@peerbit/document-interface@2.0.11-a70fbaa(transitive)
- Removed@peerbit/indexer-interface@2.0.6-a70fbaa(transitive)
- Removed@peerbit/indexer-simple@1.1.9-a70fbaa(transitive)
- Removed@peerbit/indexer-sqlite3@1.2.10-a70fbaa(transitive)
- Removed@peerbit/keychain@1.0.24-a70fbaa(transitive)
- Removed@peerbit/log@4.0.38-a70fbaa(transitive)
- Removed@peerbit/logger@1.0.3-a70fbaa(transitive)
- Removed@peerbit/program@5.1.6-a70fbaa(transitive)
- Removed@peerbit/pubsub-interface@3.1.4-a70fbaa(transitive)
- Removed@peerbit/riblt@1.0.6-a70fbaa(transitive)
- Removed@peerbit/rpc@5.0.36-a70fbaa(transitive)
- Removed@peerbit/shared-log@10.3.21-a70fbaa(transitive)
- Removed@peerbit/stream-interface@5.1.4-a70fbaa(transitive)
- Removed@peerbit/time@2.0.8-a70fbaa(transitive)
Updated@peerbit/rpc@5.0.36-aea0cef