@peerbit/document-interface 1.0.4 → 1.0.5-29dd1b8

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.
@@ -1,3 +1,4 @@
1
1
  export * from "./query.js";
2
2
  export * from "./store.js";
3
+ export * from "./request.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
package/dist/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./query.js";
2
2
  export * from "./store.js";
3
+ export * from "./request.js";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { Query, Sort } from "@peerbit/indexer-interface";
2
+ export declare abstract class AbstractSearchRequest {
3
+ }
4
+ export declare class SearchRequest extends AbstractSearchRequest {
5
+ id: Uint8Array;
6
+ query: Query[];
7
+ sort: Sort[];
8
+ fetch: number;
9
+ constructor(props?: {
10
+ query?: Query[] | Query | Record<string, string | number | bigint | Uint8Array | boolean | null | undefined>;
11
+ sort?: Sort[] | Sort;
12
+ fetch?: number;
13
+ });
14
+ private _idString;
15
+ get idString(): string;
16
+ }
17
+ /**
18
+ * Collect documents from peers using 'collect' session ids. This is used for distributed sorting internally
19
+ */
20
+ export declare class CollectNextRequest extends AbstractSearchRequest {
21
+ id: Uint8Array;
22
+ amount: number;
23
+ constructor(properties: {
24
+ id: Uint8Array;
25
+ amount: number;
26
+ });
27
+ private _idString;
28
+ get idString(): string;
29
+ }
30
+ export declare class CloseIteratorRequest extends AbstractSearchRequest {
31
+ id: Uint8Array;
32
+ constructor(properties: {
33
+ id: Uint8Array;
34
+ });
35
+ private _idString;
36
+ get idString(): string;
37
+ }
38
+ export declare abstract class AbstractDeleteRequest {
39
+ }
40
+ export declare class DeleteRequest extends AbstractDeleteRequest {
41
+ id: Uint8Array;
42
+ query: Query[];
43
+ constructor(props: {
44
+ query: Query[] | Query | Record<string, string | number | bigint | Uint8Array | boolean | null | undefined>;
45
+ });
46
+ }
47
+ export declare abstract class AbstractAggregationRequest {
48
+ }
49
+ export declare class SumRequest extends AbstractAggregationRequest {
50
+ id: Uint8Array;
51
+ query: Query[];
52
+ key: string[];
53
+ constructor(props: {
54
+ query?: Query[] | Query | Record<string, string | number | bigint | Uint8Array | boolean | null | undefined>;
55
+ key: string[] | string;
56
+ });
57
+ }
58
+ export declare abstract class AbstractCountRequest {
59
+ }
60
+ export declare class CountRequest extends AbstractCountRequest {
61
+ id: Uint8Array;
62
+ query: Query[];
63
+ constructor(props?: {
64
+ query: Query[] | Query | Record<string, string | number | bigint | Uint8Array | boolean | null | undefined>;
65
+ });
66
+ }
67
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAW,MAAM,4BAA4B,CAAC;AASlE,8BAAsB,qBAAqB;CAAG;AAE9C,qBACa,aAAc,SAAQ,qBAAqB;IAEvD,EAAE,EAAE,UAAU,CAAC;IAGf,KAAK,EAAE,KAAK,EAAE,CAAC;IAGf,IAAI,EAAE,IAAI,E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0BAA0B;IAEzD,EAAE,EAAE,UAAU,CAAC;IAGf,KAAK,EAAE,KAAK,EAAE,CAAC;IAGf,GAAG,EAAE,MAAM,EAAE,CAAC;gBAEF,KAAK,EAAE;QAClB,KAAK,CAAC,EACH,KAAK,EAAE,GACP,KAAK,GACL,MAAM,CACN,MAAM,EACN,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CACjE,CAAC;QACL,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;KACvB;CAMD;AAED,8BAAsB,oBAAoB;CAAG;AAE7C,qBACa,YAAa,SAAQ,oBAAoB;IAErD,EAAE,EAAE,UAAU,CAAC;IAGf,KAAK,EAAE,KAAK,EAAE,CAAC;gBAGd,KAAK,GAAE;QACN,KAAK,EACF,KAAK,EAAE,GACP,KAAK,GACL,MAAM,CACN,MAAM,EACN,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CACjE,CAAC;KACW;CAMlB"}
@@ -0,0 +1,184 @@
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, fixedArray, variant, vec } from "@dao-xyz/borsh";
11
+ import { randomBytes, sha256Base64Sync } from "@peerbit/crypto";
12
+ import { Query, Sort, toQuery } from "@peerbit/indexer-interface";
13
+ /**
14
+ * Search with query and collect with sort conditionss
15
+ */
16
+ const toArray = (arr) => (arr ? (Array.isArray(arr) ? arr : [arr]) : undefined) || [];
17
+ export class AbstractSearchRequest {
18
+ }
19
+ let SearchRequest = class SearchRequest extends AbstractSearchRequest {
20
+ id; // Session id
21
+ query;
22
+ sort;
23
+ fetch;
24
+ constructor(props) {
25
+ super();
26
+ this.id = randomBytes(32);
27
+ this.query = props?.query ? toQuery(props.query) : [];
28
+ this.sort = toArray(props?.sort);
29
+ this.fetch = props?.fetch ?? 10; // default fetch 10 documents
30
+ }
31
+ _idString;
32
+ get idString() {
33
+ return this._idString || (this._idString = sha256Base64Sync(this.id));
34
+ }
35
+ };
36
+ __decorate([
37
+ field({ type: fixedArray("u8", 32) }),
38
+ __metadata("design:type", Uint8Array)
39
+ ], SearchRequest.prototype, "id", void 0);
40
+ __decorate([
41
+ field({ type: vec(Query) }),
42
+ __metadata("design:type", Array)
43
+ ], SearchRequest.prototype, "query", void 0);
44
+ __decorate([
45
+ field({ type: vec(Sort) }),
46
+ __metadata("design:type", Array)
47
+ ], SearchRequest.prototype, "sort", void 0);
48
+ __decorate([
49
+ field({ type: "u32" }),
50
+ __metadata("design:type", Number)
51
+ ], SearchRequest.prototype, "fetch", void 0);
52
+ SearchRequest = __decorate([
53
+ variant(0),
54
+ __metadata("design:paramtypes", [Object])
55
+ ], SearchRequest);
56
+ export { SearchRequest };
57
+ /**
58
+ * Collect documents from peers using 'collect' session ids. This is used for distributed sorting internally
59
+ */
60
+ let CollectNextRequest = class CollectNextRequest extends AbstractSearchRequest {
61
+ id; // collect with id
62
+ amount; // number of documents to ask for
63
+ constructor(properties) {
64
+ super();
65
+ this.id = properties.id;
66
+ this.amount = properties.amount;
67
+ }
68
+ _idString;
69
+ get idString() {
70
+ return this._idString || (this._idString = sha256Base64Sync(this.id));
71
+ }
72
+ };
73
+ __decorate([
74
+ field({ type: fixedArray("u8", 32) }),
75
+ __metadata("design:type", Uint8Array)
76
+ ], CollectNextRequest.prototype, "id", void 0);
77
+ __decorate([
78
+ field({ type: "u32" }),
79
+ __metadata("design:type", Number)
80
+ ], CollectNextRequest.prototype, "amount", void 0);
81
+ CollectNextRequest = __decorate([
82
+ variant(2),
83
+ __metadata("design:paramtypes", [Object])
84
+ ], CollectNextRequest);
85
+ export { CollectNextRequest };
86
+ let CloseIteratorRequest = class CloseIteratorRequest extends AbstractSearchRequest {
87
+ id; // collect with id
88
+ constructor(properties) {
89
+ super();
90
+ this.id = properties.id;
91
+ }
92
+ _idString;
93
+ get idString() {
94
+ return this._idString || (this._idString = sha256Base64Sync(this.id));
95
+ }
96
+ };
97
+ __decorate([
98
+ field({ type: fixedArray("u8", 32) }),
99
+ __metadata("design:type", Uint8Array)
100
+ ], CloseIteratorRequest.prototype, "id", void 0);
101
+ CloseIteratorRequest = __decorate([
102
+ variant(3),
103
+ __metadata("design:paramtypes", [Object])
104
+ ], CloseIteratorRequest);
105
+ export { CloseIteratorRequest };
106
+ export class AbstractDeleteRequest {
107
+ }
108
+ let DeleteRequest = class DeleteRequest extends AbstractDeleteRequest {
109
+ id; // Session id
110
+ query;
111
+ constructor(props) {
112
+ super();
113
+ this.id = randomBytes(32);
114
+ this.query = toQuery(props.query);
115
+ }
116
+ };
117
+ __decorate([
118
+ field({ type: fixedArray("u8", 32) }),
119
+ __metadata("design:type", Uint8Array)
120
+ ], DeleteRequest.prototype, "id", void 0);
121
+ __decorate([
122
+ field({ type: vec(Query) }),
123
+ __metadata("design:type", Array)
124
+ ], DeleteRequest.prototype, "query", void 0);
125
+ DeleteRequest = __decorate([
126
+ variant(0),
127
+ __metadata("design:paramtypes", [Object])
128
+ ], DeleteRequest);
129
+ export { DeleteRequest };
130
+ export class AbstractAggregationRequest {
131
+ }
132
+ let SumRequest = class SumRequest extends AbstractAggregationRequest {
133
+ id;
134
+ query;
135
+ key;
136
+ constructor(props) {
137
+ super();
138
+ this.id = randomBytes(32);
139
+ this.query = props.query ? toQuery(props.query) : [];
140
+ this.key = Array.isArray(props.key) ? props.key : [props.key];
141
+ }
142
+ };
143
+ __decorate([
144
+ field({ type: fixedArray("u8", 32) }),
145
+ __metadata("design:type", Uint8Array)
146
+ ], SumRequest.prototype, "id", void 0);
147
+ __decorate([
148
+ field({ type: vec(Query) }),
149
+ __metadata("design:type", Array)
150
+ ], SumRequest.prototype, "query", void 0);
151
+ __decorate([
152
+ field({ type: vec("string") }),
153
+ __metadata("design:type", Array)
154
+ ], SumRequest.prototype, "key", void 0);
155
+ SumRequest = __decorate([
156
+ variant(0),
157
+ __metadata("design:paramtypes", [Object])
158
+ ], SumRequest);
159
+ export { SumRequest };
160
+ export class AbstractCountRequest {
161
+ }
162
+ let CountRequest = class CountRequest extends AbstractCountRequest {
163
+ id; // Session id
164
+ query;
165
+ constructor(props = { query: [] }) {
166
+ super();
167
+ this.id = randomBytes(32);
168
+ this.query = toQuery(props.query);
169
+ }
170
+ };
171
+ __decorate([
172
+ field({ type: fixedArray("u8", 32) }),
173
+ __metadata("design:type", Uint8Array)
174
+ ], CountRequest.prototype, "id", void 0);
175
+ __decorate([
176
+ field({ type: vec(Query) }),
177
+ __metadata("design:type", Array)
178
+ ], CountRequest.prototype, "query", void 0);
179
+ CountRequest = __decorate([
180
+ variant(0),
181
+ __metadata("design:paramtypes", [Object])
182
+ ], CountRequest);
183
+ export { CountRequest };
184
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAElE;;GAEG;AAEH,MAAM,OAAO,GAAG,CAAI,GAAwB,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CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/D,CAAC;CACD,CAAA;AAvBA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;8BAClC,UAAU;sCAAC;AAGf;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;;yCACb;AAGf;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;;uCACjB;AARF,UAAU;IADtB,OAAO,CAAC,CAAC,CAAC;;GACE,UAAU,CAyBtB;;AAED,MAAM,OAAgB,oBAAoB;CAAG;AAGtC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,oBAAoB;IAErD,EAAE,CAAa,CAAC,aAAa;IAG7B,KAAK,CAAU;IAEf,YACC,QAQI,EAAE,KAAK,EAAE,EAAE,EAAE;QAEjB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;CACD,CAAA;AApBA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;8BAClC,UAAU;wCAAC;AAGf;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;;2CACb;AALH,YAAY;IADxB,OAAO,CAAC,CAAC,CAAC;;GACE,YAAY,CAsBxB"}
package/package.json CHANGED
@@ -1,65 +1,65 @@
1
1
  {
2
- "name": "@peerbit/document-interface",
3
- "version": "1.0.4",
4
- "description": "Document store interface",
5
- "sideEffects": false,
6
- "type": "module",
7
- "types": "./dist/src/index.d.ts",
8
- "typesVersions": {
9
- "*": {
10
- "*": [
11
- "*",
12
- "dist/*",
13
- "dist/src/*",
14
- "dist/src/*/index"
15
- ],
16
- "src/*": [
17
- "*",
18
- "dist/*",
19
- "dist/src/*",
20
- "dist/src/*/index"
21
- ]
22
- }
23
- },
24
- "files": [
25
- "src",
26
- "dist",
27
- "!dist/e2e",
28
- "!dist/test",
29
- "!**/*.tsbuildinfo"
30
- ],
31
- "exports": {
32
- ".": {
33
- "types": "./dist/src/index.d.ts",
34
- "import": "./dist/src/index.js"
35
- }
36
- },
37
- "eslintConfig": {
38
- "extends": "peerbit",
39
- "parserOptions": {
40
- "project": true,
41
- "sourceType": "module"
42
- },
43
- "ignorePatterns": [
44
- "!.aegir.js",
45
- "test/ts-use",
46
- "*.d.ts"
47
- ]
48
- },
49
- "publishConfig": {
50
- "access": "public"
51
- },
52
- "scripts": {
53
- "clean": "aegir clean",
54
- "build": "aegir build --no-bundle",
55
- "test": "",
56
- "lint": "aegir lint"
57
- },
58
- "author": "dao.xyz",
59
- "license": "MIT",
60
- "dependencies": {
61
- "@dao-xyz/borsh": "^5.2.3",
62
- "@peerbit/crypto": "^2.3.1",
63
- "@peerbit/indexer-interface": "^1.0.3"
64
- }
2
+ "name": "@peerbit/document-interface",
3
+ "version": "1.0.5-29dd1b8",
4
+ "description": "Document store interface",
5
+ "sideEffects": false,
6
+ "type": "module",
7
+ "types": "./dist/src/index.d.ts",
8
+ "typesVersions": {
9
+ "*": {
10
+ "*": [
11
+ "*",
12
+ "dist/*",
13
+ "dist/src/*",
14
+ "dist/src/*/index"
15
+ ],
16
+ "src/*": [
17
+ "*",
18
+ "dist/*",
19
+ "dist/src/*",
20
+ "dist/src/*/index"
21
+ ]
22
+ }
23
+ },
24
+ "files": [
25
+ "src",
26
+ "dist",
27
+ "!dist/e2e",
28
+ "!dist/test",
29
+ "!**/*.tsbuildinfo"
30
+ ],
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/src/index.d.ts",
34
+ "import": "./dist/src/index.js"
35
+ }
36
+ },
37
+ "eslintConfig": {
38
+ "extends": "peerbit",
39
+ "parserOptions": {
40
+ "project": true,
41
+ "sourceType": "module"
42
+ },
43
+ "ignorePatterns": [
44
+ "!.aegir.js",
45
+ "test/ts-use",
46
+ "*.d.ts"
47
+ ]
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "scripts": {
53
+ "clean": "aegir clean",
54
+ "build": "aegir build --no-bundle",
55
+ "test": "",
56
+ "lint": "aegir lint"
57
+ },
58
+ "author": "dao.xyz",
59
+ "license": "MIT",
60
+ "dependencies": {
61
+ "@dao-xyz/borsh": "^5.2.3",
62
+ "@peerbit/crypto": "2.3.2-29dd1b8",
63
+ "@peerbit/indexer-interface": "1.1.0-29dd1b8"
64
+ }
65
65
  }
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./query.js";
2
2
  export * from "./store.js";
3
+ export * from "./request.js";
package/src/request.ts ADDED
@@ -0,0 +1,172 @@
1
+ import { field, fixedArray, variant, vec } from "@dao-xyz/borsh";
2
+ import { randomBytes, sha256Base64Sync } from "@peerbit/crypto";
3
+ import { Query, Sort, toQuery } from "@peerbit/indexer-interface";
4
+
5
+ /**
6
+ * Search with query and collect with sort conditionss
7
+ */
8
+
9
+ const toArray = <T>(arr: T | T[] | undefined) =>
10
+ (arr ? (Array.isArray(arr) ? arr : [arr]) : undefined) || [];
11
+
12
+ export abstract class AbstractSearchRequest {}
13
+
14
+ @variant(0)
15
+ export class SearchRequest extends AbstractSearchRequest {
16
+ @field({ type: fixedArray("u8", 32) })
17
+ id: Uint8Array; // Session id
18
+
19
+ @field({ type: vec(Query) })
20
+ query: Query[];
21
+
22
+ @field({ type: vec(Sort) })
23
+ sort: Sort[];
24
+
25
+ @field({ type: "u32" })
26
+ fetch: number;
27
+
28
+ constructor(props?: {
29
+ query?:
30
+ | Query[]
31
+ | Query
32
+ | Record<
33
+ string,
34
+ string | number | bigint | Uint8Array | boolean | null | undefined
35
+ >;
36
+ sort?: Sort[] | Sort;
37
+ fetch?: number;
38
+ }) {
39
+ super();
40
+ this.id = randomBytes(32);
41
+ this.query = props?.query ? toQuery(props.query) : [];
42
+ this.sort = toArray(props?.sort);
43
+ this.fetch = props?.fetch ?? 10; // default fetch 10 documents
44
+ }
45
+
46
+ private _idString: string;
47
+ get idString(): string {
48
+ return this._idString || (this._idString = sha256Base64Sync(this.id));
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Collect documents from peers using 'collect' session ids. This is used for distributed sorting internally
54
+ */
55
+
56
+ @variant(2)
57
+ export class CollectNextRequest extends AbstractSearchRequest {
58
+ @field({ type: fixedArray("u8", 32) })
59
+ id: Uint8Array; // collect with id
60
+
61
+ @field({ type: "u32" })
62
+ amount: number; // number of documents to ask for
63
+
64
+ constructor(properties: { id: Uint8Array; amount: number }) {
65
+ super();
66
+ this.id = properties.id;
67
+ this.amount = properties.amount;
68
+ }
69
+
70
+ private _idString: string;
71
+ get idString(): string {
72
+ return this._idString || (this._idString = sha256Base64Sync(this.id));
73
+ }
74
+ }
75
+
76
+ @variant(3)
77
+ export class CloseIteratorRequest extends AbstractSearchRequest {
78
+ @field({ type: fixedArray("u8", 32) })
79
+ id: Uint8Array; // collect with id
80
+
81
+ constructor(properties: { id: Uint8Array }) {
82
+ super();
83
+ this.id = properties.id;
84
+ }
85
+
86
+ private _idString: string;
87
+ get idString(): string {
88
+ return this._idString || (this._idString = sha256Base64Sync(this.id));
89
+ }
90
+ }
91
+
92
+ export abstract class AbstractDeleteRequest {}
93
+
94
+ @variant(0)
95
+ export class DeleteRequest extends AbstractDeleteRequest {
96
+ @field({ type: fixedArray("u8", 32) })
97
+ id: Uint8Array; // Session id
98
+
99
+ @field({ type: vec(Query) })
100
+ query: Query[];
101
+
102
+ constructor(props: {
103
+ query:
104
+ | Query[]
105
+ | Query
106
+ | Record<
107
+ string,
108
+ string | number | bigint | Uint8Array | boolean | null | undefined
109
+ >;
110
+ }) {
111
+ super();
112
+ this.id = randomBytes(32);
113
+ this.query = toQuery(props.query);
114
+ }
115
+ }
116
+
117
+ export abstract class AbstractAggregationRequest {}
118
+
119
+ @variant(0)
120
+ export class SumRequest extends AbstractAggregationRequest {
121
+ @field({ type: fixedArray("u8", 32) })
122
+ id: Uint8Array;
123
+
124
+ @field({ type: vec(Query) })
125
+ query: Query[];
126
+
127
+ @field({ type: vec("string") })
128
+ key: string[];
129
+
130
+ constructor(props: {
131
+ query?:
132
+ | Query[]
133
+ | Query
134
+ | Record<
135
+ string,
136
+ string | number | bigint | Uint8Array | boolean | null | undefined
137
+ >;
138
+ key: string[] | string;
139
+ }) {
140
+ super();
141
+ this.id = randomBytes(32);
142
+ this.query = props.query ? toQuery(props.query) : [];
143
+ this.key = Array.isArray(props.key) ? props.key : [props.key];
144
+ }
145
+ }
146
+
147
+ export abstract class AbstractCountRequest {}
148
+
149
+ @variant(0)
150
+ export class CountRequest extends AbstractCountRequest {
151
+ @field({ type: fixedArray("u8", 32) })
152
+ id: Uint8Array; // Session id
153
+
154
+ @field({ type: vec(Query) })
155
+ query: Query[];
156
+
157
+ constructor(
158
+ props: {
159
+ query:
160
+ | Query[]
161
+ | Query
162
+ | Record<
163
+ string,
164
+ string | number | bigint | Uint8Array | boolean | null | undefined
165
+ >;
166
+ } = { query: [] },
167
+ ) {
168
+ super();
169
+ this.id = randomBytes(32);
170
+ this.query = toQuery(props.query);
171
+ }
172
+ }