@peerbit/document-interface 6.0.7-a4f88b6

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.
@@ -0,0 +1,47 @@
1
+ export declare abstract class PrimitiveValue {
2
+ }
3
+ export declare class StringValue extends PrimitiveValue {
4
+ string: string;
5
+ constructor(string: string);
6
+ }
7
+ export declare abstract class NumberValue extends PrimitiveValue {
8
+ abstract get value(): number | bigint;
9
+ }
10
+ export declare abstract class IntegerValue extends NumberValue {
11
+ }
12
+ export declare class UnsignedIntegerValue extends IntegerValue {
13
+ number: number;
14
+ constructor(number: number);
15
+ get value(): number;
16
+ }
17
+ export declare class BigUnsignedIntegerValue extends IntegerValue {
18
+ number: bigint;
19
+ constructor(number: bigint);
20
+ get value(): bigint;
21
+ }
22
+ export type IdPrimitive = string | number | bigint;
23
+ export declare abstract class IdKey {
24
+ abstract get key(): string | bigint | number | Uint8Array;
25
+ abstract get primitive(): IdPrimitive;
26
+ }
27
+ export declare class StringKey extends IdKey {
28
+ key: string;
29
+ constructor(key: string);
30
+ get primitive(): string;
31
+ }
32
+ export declare class Uint8ArrayKey extends IdKey {
33
+ key: Uint8Array;
34
+ constructor(key: Uint8Array);
35
+ private _keyString;
36
+ get primitive(): string;
37
+ }
38
+ export declare class IntegerKey extends IdKey {
39
+ key: number;
40
+ constructor(key: number);
41
+ get primitive(): number;
42
+ }
43
+ export type Ideable = string | number | bigint | Uint8Array;
44
+ export declare const toId: (obj: Ideable) => IdKey;
45
+ export declare const toIdeable: (key: IdKey | Ideable) => string | number | bigint;
46
+ export declare const checkId: (obj: Ideable) => void;
47
+ //# sourceMappingURL=id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":"AAQA,8BAAsB,cAAc;CAAI;AAExC,qBACa,WAAY,SAAQ,cAAc;IAE9C,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MA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O,MAAM,OAAO,QAAS,OAAO,SAqBnC,CAAC"}
package/dist/src/id.js ADDED
@@ -0,0 +1,217 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { field, variant } from "@dao-xyz/borsh";
11
+ import { toBase64 } from "@peerbit/crypto";
12
+ import { decodeUint8Array, encodeUint8Array, encodingLength } from "uint8-varint";
13
+ export class PrimitiveValue {
14
+ }
15
+ let StringValue = class StringValue extends PrimitiveValue {
16
+ string;
17
+ constructor(string) {
18
+ super();
19
+ this.string = string;
20
+ }
21
+ };
22
+ __decorate([
23
+ field({ type: "string" }),
24
+ __metadata("design:type", String)
25
+ ], StringValue.prototype, "string", void 0);
26
+ StringValue = __decorate([
27
+ variant(0),
28
+ __metadata("design:paramtypes", [String])
29
+ ], StringValue);
30
+ export { StringValue };
31
+ let NumberValue = class NumberValue extends PrimitiveValue {
32
+ };
33
+ NumberValue = __decorate([
34
+ variant(1)
35
+ ], NumberValue);
36
+ export { NumberValue };
37
+ let IntegerValue = class IntegerValue extends NumberValue {
38
+ };
39
+ IntegerValue = __decorate([
40
+ variant(0)
41
+ ], IntegerValue);
42
+ export { IntegerValue };
43
+ let UnsignedIntegerValue = class UnsignedIntegerValue extends IntegerValue {
44
+ number;
45
+ constructor(number) {
46
+ super();
47
+ if (Number.isInteger(number) === false ||
48
+ number > 4294967295 ||
49
+ number < 0) {
50
+ throw new Error("Number is not u32");
51
+ }
52
+ this.number = number;
53
+ }
54
+ get value() {
55
+ return this.number;
56
+ }
57
+ };
58
+ __decorate([
59
+ field({ type: "u32" }),
60
+ __metadata("design:type", Number)
61
+ ], UnsignedIntegerValue.prototype, "number", void 0);
62
+ UnsignedIntegerValue = __decorate([
63
+ variant(0),
64
+ __metadata("design:paramtypes", [Number])
65
+ ], UnsignedIntegerValue);
66
+ export { UnsignedIntegerValue };
67
+ let BigUnsignedIntegerValue = class BigUnsignedIntegerValue extends IntegerValue {
68
+ number;
69
+ constructor(number) {
70
+ super();
71
+ if (number > 18446744073709551615n || number < 0) {
72
+ throw new Error("Number is not u32");
73
+ }
74
+ this.number = number;
75
+ }
76
+ get value() {
77
+ return this.number;
78
+ }
79
+ };
80
+ __decorate([
81
+ field({ type: "u64" }),
82
+ __metadata("design:type", BigInt)
83
+ ], BigUnsignedIntegerValue.prototype, "number", void 0);
84
+ BigUnsignedIntegerValue = __decorate([
85
+ variant(1),
86
+ __metadata("design:paramtypes", [BigInt])
87
+ ], BigUnsignedIntegerValue);
88
+ export { BigUnsignedIntegerValue };
89
+ export class IdKey {
90
+ }
91
+ let StringKey = class StringKey extends IdKey {
92
+ key;
93
+ constructor(key) {
94
+ super();
95
+ this.key = key;
96
+ }
97
+ get primitive() {
98
+ return this.key;
99
+ }
100
+ };
101
+ __decorate([
102
+ field({ type: "string" }),
103
+ __metadata("design:type", String)
104
+ ], StringKey.prototype, "key", void 0);
105
+ StringKey = __decorate([
106
+ variant(0),
107
+ __metadata("design:paramtypes", [String])
108
+ ], StringKey);
109
+ export { StringKey };
110
+ let Uint8ArrayKey = class Uint8ArrayKey extends IdKey {
111
+ key;
112
+ constructor(key) {
113
+ super();
114
+ this.key = key;
115
+ }
116
+ _keyString;
117
+ get primitive() {
118
+ return this._keyString || (this._keyString = toBase64(this.key));
119
+ }
120
+ };
121
+ __decorate([
122
+ field({ type: Uint8Array }),
123
+ __metadata("design:type", Uint8Array)
124
+ ], Uint8ArrayKey.prototype, "key", void 0);
125
+ Uint8ArrayKey = __decorate([
126
+ variant(1),
127
+ __metadata("design:paramtypes", [Uint8Array])
128
+ ], Uint8ArrayKey);
129
+ export { Uint8ArrayKey };
130
+ const varint53 = {
131
+ deserialize: (reader) => {
132
+ const number = decodeUint8Array(reader._buf, reader._offset);
133
+ const len = encodingLength(number);
134
+ reader._offset += len;
135
+ return number;
136
+ },
137
+ serialize: (value, writer) => {
138
+ const offset = writer.totalSize;
139
+ writer["_writes"] = writer["_writes"].next = () => encodeUint8Array(value, writer["_buf"], offset);
140
+ writer.totalSize += encodingLength(value);
141
+ }
142
+ };
143
+ let IntegerKey = class IntegerKey extends IdKey {
144
+ key;
145
+ constructor(key) {
146
+ super();
147
+ this.key = key;
148
+ }
149
+ get primitive() {
150
+ return this.key;
151
+ }
152
+ };
153
+ __decorate([
154
+ field(varint53) // max value is 2^53 - 1 (9007199254740991)
155
+ ,
156
+ __metadata("design:type", Number)
157
+ ], IntegerKey.prototype, "key", void 0);
158
+ IntegerKey = __decorate([
159
+ variant(2),
160
+ __metadata("design:paramtypes", [Number])
161
+ ], IntegerKey);
162
+ export { IntegerKey };
163
+ const idKeyTypes = new Set(["string", "number", "bigint"]);
164
+ export const toId = (obj) => {
165
+ if (typeof obj === "string") {
166
+ return new StringKey(obj);
167
+ }
168
+ if (typeof obj === "number") {
169
+ return new IntegerKey(obj);
170
+ }
171
+ if (typeof obj === "bigint") {
172
+ if (obj <= Number.MAX_SAFE_INTEGER && obj >= 0) {
173
+ return new IntegerKey(Number(obj));
174
+ }
175
+ throw new Error("BigInt is not less than 2^53. Max value is 9007199254740991");
176
+ }
177
+ if (obj instanceof Uint8Array) {
178
+ return new Uint8ArrayKey(obj);
179
+ }
180
+ throw new Error("Unexpected index key: " +
181
+ typeof obj +
182
+ ", expected: string, number, bigint or Uint8Array");
183
+ };
184
+ export const toIdeable = (key) => {
185
+ if (key instanceof IdKey) {
186
+ return key.primitive;
187
+ }
188
+ if (typeof key === "string") {
189
+ return key;
190
+ }
191
+ if (typeof key === "number") {
192
+ return key;
193
+ }
194
+ if (typeof key === "bigint") {
195
+ return key;
196
+ }
197
+ if (key instanceof Uint8Array) {
198
+ return toBase64(key);
199
+ }
200
+ throw new Error("Unexpected index key: " + typeof key);
201
+ };
202
+ export const checkId = (obj) => {
203
+ if (obj == null) {
204
+ throw new Error(`The provided key value is null or undefined, expecting string, number, bigint, or Uint8array`);
205
+ }
206
+ const type = typeof obj;
207
+ if (type === "number") {
208
+ if (Number.isInteger(obj) === false) {
209
+ throw new Error(`The provided key number value is not an integer`);
210
+ }
211
+ }
212
+ if (idKeyTypes.has(type) || obj instanceof Uint8Array) {
213
+ return;
214
+ }
215
+ throw new Error(`Key is not ${[...idKeyTypes]}, provided key value type: ${typeof obj}`);
216
+ };
217
+ //# sourceMappingURL=id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,MAAM,cAAc,CAAC;AAEtB,MAAM,OAAgB,cAAc;CAAI;AAGjC,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,cAAc;IAE9C,MAAM,CAAS;IAEf,YAAY,MAAc;QACzB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;CACD,CAAA;AANA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;2CACX;AAFH,WAAW;IADvB,OAAO,CAAC,CAAC,CAAC;;GACE,WAAW,CAQvB;;AAGM,IAAe,WAAW,GAA1B,MAAe,WAAY,SAAQ,cAAc;CAEvD,CAAA;AAFqB,WAA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M,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;IAED,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;QACvD,OAAO;IACR,CAAC;IAED,MAAM,IAAI,KAAK,CACd,cAAc,CAAC,GAAG,UAAU,CAAC,8BAA8B,OAAO,GAAG,EAAE,CACvE,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { PublicSignKey } from "@peerbit/crypto";
2
+ import { CloseIteratorRequest, CollectNextRequest, Context, SearchRequest } from "./query.js";
3
+ import { IdKey, type IdPrimitive } from "./id.js";
4
+ import { type Constructor } from "@dao-xyz/borsh";
5
+ export interface IndexedResult {
6
+ id: IdKey;
7
+ indexed: Record<string, any>;
8
+ context: Context;
9
+ }
10
+ export interface IndexedResults {
11
+ results: IndexedResult[];
12
+ kept: number;
13
+ }
14
+ export interface IndexedValue<T = Record<string, any>> {
15
+ id: IdKey;
16
+ indexed: T;
17
+ context: Context;
18
+ size: number;
19
+ }
20
+ export type NestedProperties<T> = {
21
+ match: (obj: any) => obj is T;
22
+ query: (nested: T, query: SearchRequest) => Promise<Record<string, any>[]>;
23
+ };
24
+ export type IndexEngineInitProperties<N> = {
25
+ indexBy: string | string[];
26
+ nested?: NestedProperties<N>;
27
+ maxBatchSize: number;
28
+ schema?: Constructor<any>;
29
+ };
30
+ export interface IndexEngine<N = any> {
31
+ init(properties: IndexEngineInitProperties<N>): Promise<void> | void;
32
+ start?(): Promise<void> | void;
33
+ stop?(): Promise<void> | void;
34
+ get(id: IdKey): Promise<IndexedResult | undefined> | IndexedResult | undefined;
35
+ put(value: IndexedValue): Promise<void> | void;
36
+ del(id: IdKey): Promise<void> | void;
37
+ query(query: SearchRequest, from: PublicSignKey): Promise<IndexedResults>;
38
+ next(query: CollectNextRequest, from: PublicSignKey): Promise<IndexedResults>;
39
+ close(query: CloseIteratorRequest, from: PublicSignKey): Promise<void> | void;
40
+ iterator(): IterableIterator<[IdPrimitive, IndexedValue]>;
41
+ getSize(): number | Promise<number>;
42
+ getPending(cursorId: string): number | undefined;
43
+ get cursorCount(): number;
44
+ }
45
+ //# sourceMappingURL=index-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-engine.d.ts","sourceRoot":"","sources":["../../src/index-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACN,oBAAoB,EACpB,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,KAAK,CAAC;IACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACpD,EAAE,EAAE,KAAK,CAAC;IACV,OAAO,EAAE,CAAC,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IACjC,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC;IAC9B,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;CAC3E,CAAC;AAEF,MAA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MAAM,CAAC,CAAC;IACpC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACjD,IAAI,WAAW,IAAI,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,5 @@
1
+ import { PublicSignKey } from "@peerbit/crypto";
2
+ import { CloseIteratorRequest, CollectNextRequest, Context, SearchRequest } from "./query.js";
3
+ import { IdKey } from "./id.js";
4
+ import {} from "@dao-xyz/borsh";
5
+ //# sourceMappingURL=index-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-engine.js","sourceRoot":"","sources":["../../src/index-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACN,oBAAoB,EACpB,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAoB,MAAM,SAAS,CAAC;AAClD,OAAO,EAAoB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./id.js";
2
+ export * from "./query.js";
3
+ export * from "./index-engine.js";
4
+ export * from "./store.js";
5
+ export * from "./utils.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./id.js";
2
+ export * from "./query.js";
3
+ export * from "./index-engine.js";
4
+ export * from "./store.js";
5
+ export * from "./utils.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,173 @@
1
+ import { type AbstractType } from "@dao-xyz/borsh";
2
+ import { IntegerValue } from "./id.js";
3
+ export declare enum Compare {
4
+ Equal = 0,
5
+ Greater = 1,
6
+ GreaterOrEqual = 2,
7
+ Less = 3,
8
+ LessOrEqual = 4
9
+ }
10
+ export declare const compare: (test: bigint | number, compare: Compare, value: bigint | number) => boolean;
11
+ export declare abstract class Query {
12
+ clone(): this;
13
+ }
14
+ export declare enum SortDirection {
15
+ ASC = 0,
16
+ DESC = 1
17
+ }
18
+ export declare class Sort {
19
+ key: string[];
20
+ direction: SortDirection;
21
+ constructor(properties: {
22
+ key: string[] | string;
23
+ direction?: SortDirection;
24
+ });
25
+ }
26
+ export declare abstract class AbstractSearchRequest {
27
+ }
28
+ export declare class SearchRequest extends AbstractSearchRequest {
29
+ id: Uint8Array;
30
+ query: Query[];
31
+ sort: Sort[];
32
+ fetch: number;
33
+ constructor(props?: {
34
+ query?: Query[] | Query;
35
+ sort?: Sort[] | Sort;
36
+ });
37
+ private _idString;
38
+ get idString(): string;
39
+ }
40
+ /**
41
+ * Collect documents from peers using 'collect' session ids. This is used for distributed sorting internally
42
+ */
43
+ export declare class CollectNextRequest extends AbstractSearchRequest {
44
+ id: Uint8Array;
45
+ amount: number;
46
+ constructor(properties: {
47
+ id: Uint8Array;
48
+ amount: number;
49
+ });
50
+ private _idString;
51
+ get idString(): string;
52
+ }
53
+ export declare class CloseIteratorRequest extends AbstractSearchRequest {
54
+ id: Uint8Array;
55
+ constructor(properties: {
56
+ id: Uint8Array;
57
+ });
58
+ private _idString;
59
+ get idString(): string;
60
+ }
61
+ export declare abstract class LogicalQuery extends Query {
62
+ }
63
+ export declare class And extends LogicalQuery {
64
+ and: Query[];
65
+ constructor(and: Query[]);
66
+ }
67
+ export declare class Or extends LogicalQuery {
68
+ or: Query[];
69
+ constructor(or: Query[]);
70
+ }
71
+ export declare abstract class StateQuery extends Query {
72
+ }
73
+ export declare class StateFieldQuery extends StateQuery {
74
+ key: string[];
75
+ constructor(props: {
76
+ key: string[] | string;
77
+ });
78
+ }
79
+ export declare class ByteMatchQuery extends StateFieldQuery {
80
+ value: Uint8Array;
81
+ private _reserved;
82
+ constructor(props: {
83
+ key: string[] | string;
84
+ value: Uint8Array;
85
+ });
86
+ _valueString: string;
87
+ /**
88
+ * value `asString`
89
+ */
90
+ get valueString(): string;
91
+ }
92
+ export declare enum StringMatchMethod {
93
+ "exact" = 0,
94
+ "prefix" = 1,
95
+ "contains" = 2
96
+ }
97
+ export declare class StringMatch extends StateFieldQuery {
98
+ value: string;
99
+ method: StringMatchMethod;
100
+ caseInsensitive: boolean;
101
+ constructor(props: {
102
+ key: string[] | string;
103
+ value: string;
104
+ method?: StringMatchMethod;
105
+ caseInsensitive?: boolean;
106
+ });
107
+ }
108
+ export declare class IntegerCompare extends StateFieldQuery {
109
+ compare: Compare;
110
+ value: IntegerValue;
111
+ constructor(props: {
112
+ key: string[] | string;
113
+ value: bigint | number | IntegerValue;
114
+ compare: Compare;
115
+ });
116
+ }
117
+ export declare class MissingField extends StateFieldQuery {
118
+ constructor(props: {
119
+ key: string[] | string;
120
+ });
121
+ }
122
+ export declare class BoolQuery extends StateFieldQuery {
123
+ value: boolean;
124
+ constructor(props: {
125
+ key: string[] | string;
126
+ value: boolean;
127
+ });
128
+ }
129
+ export declare abstract class Result {
130
+ }
131
+ export declare class Context {
132
+ created: bigint;
133
+ modified: bigint;
134
+ head: string;
135
+ gid: string;
136
+ constructor(properties: {
137
+ created: bigint;
138
+ modified: bigint;
139
+ head: string;
140
+ gid: string;
141
+ });
142
+ }
143
+ export declare class ResultWithSource<T> extends Result {
144
+ _source: Uint8Array;
145
+ context: Context;
146
+ _type: AbstractType<T>;
147
+ constructor(opts: {
148
+ source: Uint8Array;
149
+ context: Context;
150
+ value?: T;
151
+ indexed?: Record<string, any>;
152
+ });
153
+ init(type: AbstractType<T>): void;
154
+ _value?: T;
155
+ get value(): T;
156
+ indexed?: Record<string, any>;
157
+ }
158
+ export declare abstract class AbstractSearchResult<T> {
159
+ }
160
+ export declare class Results<T> extends AbstractSearchResult<T> {
161
+ results: ResultWithSource<T>[];
162
+ kept: bigint;
163
+ constructor(properties: {
164
+ results: ResultWithSource<T>[];
165
+ kept: bigint;
166
+ });
167
+ }
168
+ export declare class NoAccess extends AbstractSearchResult<any> {
169
+ }
170
+ /**
171
+ * Find logs that can be decrypted by certain keys
172
+ */
173
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAOjB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAEN,YAAY,EAEZ,MAAM,SAAS,CAAC;AAEjB,oBAAY,OAAO;IAClB,KAAK,IAAI;IACT,OAAO,IAAI;IACX,cAAc,IAAI;IAClB,IAAI,IAAI;IACR,WAAW,IAAI;CACf;AACD,eAAO,MAAM,OAAO,SACb,MAAM,GAAG,MAAM,WACZ,OAAO,SACT,MAAM,GAAG,MAAM,YAiBtB,CAAC;AAIF,8BAAsB,KAAK;IAC1B,KAAK;CAGL;AAED,oBAAY,aAAa;IACxB,GAAG,IAAI;IACP,IAAI,IAAI;CACR;AAED,qBACa,IAAI;IAEhB,GAAG,EAAE,MAAM,EAAE,CAAC;IAGd,SAAS,EAAE,aAAa,CAAC;gBAEb,UAAU,EAAE;QACvB,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QACvB,SAAS,CAAC,EAAE,aAAa,CAAC;KAC1B;CAMD;AAED,8BAAsB,qBAAqB;CAAI;AAS/C,qBACa,aAAc,SAAQ,qBAAqB;IAEvD,EAAE,EAAE,UAAU,CAAC;IAGf,KAAK,EAAE,KAAK,EAAE,CAAC;IAGf,IAAI,EAAE,IAAI,EAAE,CAAC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