@peerbit/indexer-tests 1.1.3 → 1.1.4-27dca31
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.
- package/dist/src/benchmarks.d.ts.map +1 -1
- package/dist/src/benchmarks.js +431 -203
- package/dist/src/benchmarks.js.map +1 -1
- package/dist/src/tests.d.ts.map +1 -1
- package/dist/src/tests.js +662 -65
- package/dist/src/tests.js.map +1 -1
- package/package.json +66 -66
- package/src/benchmarks.ts +512 -218
- package/src/tests.ts +780 -69
package/dist/src/tests.js
CHANGED
|
@@ -8,8 +8,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { deserialize, field, fixedArray, option, serialize, variant, vec, } from "@dao-xyz/borsh";
|
|
11
|
-
import { randomBytes } from "@peerbit/crypto";
|
|
12
|
-
import { And, BoolQuery, ByteMatchQuery, Compare, IntegerCompare, IsNull,
|
|
11
|
+
import { randomBytes, sha256Base64Sync } from "@peerbit/crypto";
|
|
12
|
+
import { And, BoolQuery, ByteMatchQuery, Compare, IntegerCompare, IsNull, Not, Or, Query, Sort, SortDirection, StringMatch, StringMatchMethod, extractFieldValue, getIdProperty, id, toId, } from "@peerbit/indexer-interface";
|
|
13
13
|
import {
|
|
14
14
|
/* delay, */
|
|
15
15
|
delay, waitForResolved, } from "@peerbit/time";
|
|
@@ -249,7 +249,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
249
249
|
};
|
|
250
250
|
afterEach(async () => {
|
|
251
251
|
defaultDocs = [];
|
|
252
|
-
await indices?.
|
|
252
|
+
await indices?.drop?.();
|
|
253
253
|
});
|
|
254
254
|
describe("indexBy", () => {
|
|
255
255
|
const testIndex = async (store, doc, idProperty = ["id"]) => {
|
|
@@ -435,24 +435,25 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
435
435
|
await testIndex(store, doc);
|
|
436
436
|
});
|
|
437
437
|
});
|
|
438
|
-
|
|
439
|
-
describe("bigint", () => {
|
|
438
|
+
describe("bigint", () => {
|
|
440
439
|
class DocumentBigintId {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
@field({ type: "u64" })
|
|
445
|
-
value: bigint;
|
|
446
|
-
|
|
447
|
-
constructor(properties: { id: bigint; value: bigint }) {
|
|
440
|
+
id;
|
|
441
|
+
value;
|
|
442
|
+
constructor(properties) {
|
|
448
443
|
this.id = properties.id;
|
|
449
444
|
this.value = properties.value;
|
|
450
445
|
}
|
|
451
446
|
}
|
|
452
|
-
|
|
447
|
+
__decorate([
|
|
448
|
+
field({ type: "u64" }),
|
|
449
|
+
__metadata("design:type", BigInt)
|
|
450
|
+
], DocumentBigintId.prototype, "id", void 0);
|
|
451
|
+
__decorate([
|
|
452
|
+
field({ type: "u64" }),
|
|
453
|
+
__metadata("design:type", BigInt)
|
|
454
|
+
], DocumentBigintId.prototype, "value", void 0);
|
|
453
455
|
it("index as bigint", async () => {
|
|
454
456
|
const { store } = await setup({ schema: DocumentBigintId });
|
|
455
|
-
|
|
456
457
|
// make the id less than 2^53, but greater than u32 max
|
|
457
458
|
const id = BigInt(2 ** 63 - 1);
|
|
458
459
|
const doc = new DocumentBigintId({
|
|
@@ -461,7 +462,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
461
462
|
});
|
|
462
463
|
await testIndex(store, doc);
|
|
463
464
|
});
|
|
464
|
-
});
|
|
465
|
+
});
|
|
465
466
|
describe("by decorator", () => {
|
|
466
467
|
class DocumentWithDecoratedId {
|
|
467
468
|
xyz;
|
|
@@ -838,28 +839,225 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
838
839
|
field({ type: vec(Document) }),
|
|
839
840
|
__metadata("design:type", Array)
|
|
840
841
|
], DocumentsVec.prototype, "documents", void 0);
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
842
|
+
class DocumentWithProperty {
|
|
843
|
+
property;
|
|
844
|
+
constructor(property) {
|
|
845
|
+
this.property = property;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
__decorate([
|
|
849
|
+
field({ type: "string" }),
|
|
850
|
+
__metadata("design:type", String)
|
|
851
|
+
], DocumentWithProperty.prototype, "property", void 0);
|
|
852
|
+
class DocumentsVecWithPropertyDocument {
|
|
853
|
+
id;
|
|
854
|
+
property;
|
|
855
|
+
documents;
|
|
856
|
+
constructor(properties) {
|
|
857
|
+
this.id = randomBytes(32);
|
|
858
|
+
this.property = properties.property;
|
|
859
|
+
this.documents = properties?.documents || [];
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
__decorate([
|
|
863
|
+
field({ type: Uint8Array }),
|
|
864
|
+
__metadata("design:type", Uint8Array)
|
|
865
|
+
], DocumentsVecWithPropertyDocument.prototype, "id", void 0);
|
|
866
|
+
__decorate([
|
|
867
|
+
field({ type: "string" }),
|
|
868
|
+
__metadata("design:type", String)
|
|
869
|
+
], DocumentsVecWithPropertyDocument.prototype, "property", void 0);
|
|
870
|
+
__decorate([
|
|
871
|
+
field({ type: vec(DocumentWithProperty) }),
|
|
872
|
+
__metadata("design:type", Array)
|
|
873
|
+
], DocumentsVecWithPropertyDocument.prototype, "documents", void 0);
|
|
874
|
+
describe("search", () => {
|
|
875
|
+
let d1;
|
|
876
|
+
let d2;
|
|
877
|
+
let d3;
|
|
878
|
+
beforeEach(async () => {
|
|
879
|
+
const out = await setup({ schema: DocumentsVec });
|
|
880
|
+
store = out.store;
|
|
881
|
+
d1 = new DocumentsVec({
|
|
882
|
+
id: new Uint8Array([0]),
|
|
883
|
+
documents: [
|
|
884
|
+
new Document({ id: uuid(), number: 123n, tags: [] }),
|
|
885
|
+
],
|
|
886
|
+
});
|
|
887
|
+
await store.put(d1);
|
|
888
|
+
d2 = new DocumentsVec({
|
|
889
|
+
id: new Uint8Array([1]),
|
|
890
|
+
documents: [
|
|
891
|
+
new Document({ id: uuid(), number: 124n, tags: [] }),
|
|
892
|
+
],
|
|
893
|
+
});
|
|
894
|
+
await store.put(d2);
|
|
895
|
+
d3 = new DocumentsVec({
|
|
896
|
+
id: new Uint8Array([2]),
|
|
897
|
+
documents: [
|
|
898
|
+
new Document({ id: uuid(), number: 122n, tags: [] }),
|
|
899
|
+
new Document({ id: uuid(), number: 125n, tags: [] }),
|
|
900
|
+
],
|
|
901
|
+
});
|
|
902
|
+
await store.put(d3);
|
|
848
903
|
});
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
new
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
904
|
+
it("match", async () => {
|
|
905
|
+
// equality
|
|
906
|
+
const results = await search(store, {
|
|
907
|
+
query: new IntegerCompare({
|
|
908
|
+
key: ["documents", "number"],
|
|
909
|
+
compare: Compare.Equal,
|
|
910
|
+
value: d1.documents[0].number,
|
|
911
|
+
}),
|
|
912
|
+
});
|
|
913
|
+
expect(results.map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
914
|
+
});
|
|
915
|
+
describe("logical", () => {
|
|
916
|
+
it("and", async () => {
|
|
917
|
+
// can not be equal to two different things at once
|
|
918
|
+
let results = await search(store, {
|
|
919
|
+
query: [
|
|
920
|
+
new And([
|
|
921
|
+
new IntegerCompare({
|
|
922
|
+
key: ["documents", "number"],
|
|
923
|
+
compare: Compare.Equal,
|
|
924
|
+
value: 123n,
|
|
925
|
+
}),
|
|
926
|
+
new IntegerCompare({
|
|
927
|
+
key: ["documents", "number"],
|
|
928
|
+
compare: Compare.Equal,
|
|
929
|
+
value: 124n,
|
|
930
|
+
}),
|
|
931
|
+
]),
|
|
932
|
+
],
|
|
933
|
+
});
|
|
934
|
+
expect(results).to.have.length(0);
|
|
935
|
+
// can not be between two different things at once
|
|
936
|
+
results = await search(store, {
|
|
937
|
+
query: [
|
|
938
|
+
new And([
|
|
939
|
+
new IntegerCompare({
|
|
940
|
+
key: ["documents", "number"],
|
|
941
|
+
compare: Compare.Less,
|
|
942
|
+
value: 1000n,
|
|
943
|
+
}),
|
|
944
|
+
new IntegerCompare({
|
|
945
|
+
key: ["documents", "number"],
|
|
946
|
+
compare: Compare.Greater,
|
|
947
|
+
value: 1000n,
|
|
948
|
+
}),
|
|
949
|
+
]),
|
|
950
|
+
],
|
|
951
|
+
});
|
|
952
|
+
expect(results).to.have.length(0);
|
|
953
|
+
// between one value matches
|
|
954
|
+
results = await search(store, {
|
|
955
|
+
query: [
|
|
956
|
+
new Or([
|
|
957
|
+
new IntegerCompare({
|
|
958
|
+
key: ["documents", "number"],
|
|
959
|
+
compare: Compare.Less,
|
|
960
|
+
value: 124n,
|
|
961
|
+
}),
|
|
962
|
+
new IntegerCompare({
|
|
963
|
+
key: ["documents", "number"],
|
|
964
|
+
compare: Compare.GreaterOrEqual,
|
|
965
|
+
value: 125n,
|
|
966
|
+
}),
|
|
967
|
+
]),
|
|
968
|
+
],
|
|
969
|
+
});
|
|
970
|
+
// because each query is applied separately
|
|
971
|
+
expect(results.map((x) => sha256Base64Sync(x.value.id))).to.have.members([d1.id, d3.id].map(sha256Base64Sync));
|
|
972
|
+
results = await search(store, {
|
|
973
|
+
query: [
|
|
974
|
+
new And([
|
|
975
|
+
new IntegerCompare({
|
|
976
|
+
key: ["documents", "number"],
|
|
977
|
+
compare: Compare.Less,
|
|
978
|
+
value: 124n,
|
|
979
|
+
}),
|
|
980
|
+
new IntegerCompare({
|
|
981
|
+
key: ["documents", "number"],
|
|
982
|
+
compare: Compare.GreaterOrEqual,
|
|
983
|
+
value: 123n,
|
|
984
|
+
}),
|
|
985
|
+
]),
|
|
986
|
+
],
|
|
987
|
+
});
|
|
988
|
+
expect(results.map((x) => x.value.id)).to.deep.eq([d1.id]);
|
|
989
|
+
});
|
|
990
|
+
it("or", async () => {
|
|
991
|
+
const results3 = await search(store, {
|
|
992
|
+
query: [
|
|
993
|
+
new Or([
|
|
994
|
+
new IntegerCompare({
|
|
995
|
+
key: ["documents", "number"],
|
|
996
|
+
compare: Compare.Equal,
|
|
997
|
+
value: 123n,
|
|
998
|
+
}),
|
|
999
|
+
new IntegerCompare({
|
|
1000
|
+
key: ["documents", "number"],
|
|
1001
|
+
compare: Compare.Equal,
|
|
1002
|
+
value: 124n,
|
|
1003
|
+
}),
|
|
1004
|
+
]),
|
|
1005
|
+
],
|
|
1006
|
+
});
|
|
1007
|
+
expect(results3.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1008
|
+
sha256Base64Sync(d1.id),
|
|
1009
|
+
sha256Base64Sync(d2.id),
|
|
1010
|
+
]);
|
|
1011
|
+
});
|
|
1012
|
+
it("many or", async () => {
|
|
1013
|
+
let conditions = [];
|
|
1014
|
+
for (let i = 0; i < 100; i++) {
|
|
1015
|
+
conditions.push(new IntegerCompare({
|
|
1016
|
+
key: ["documents", "number"],
|
|
1017
|
+
compare: Compare.Equal,
|
|
1018
|
+
value: 123n,
|
|
1019
|
+
}));
|
|
1020
|
+
conditions.push(new IntegerCompare({
|
|
1021
|
+
key: ["documents", "number"],
|
|
1022
|
+
compare: Compare.Equal,
|
|
1023
|
+
value: 124n,
|
|
1024
|
+
}));
|
|
1025
|
+
}
|
|
1026
|
+
const results3 = await search(store, {
|
|
1027
|
+
query: [new Or(conditions)],
|
|
1028
|
+
});
|
|
1029
|
+
expect(results3.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1030
|
+
sha256Base64Sync(d1.id),
|
|
1031
|
+
sha256Base64Sync(d2.id),
|
|
1032
|
+
]);
|
|
1033
|
+
});
|
|
1034
|
+
it("or arr, or field", async () => {
|
|
1035
|
+
const results3 = await search(store, {
|
|
1036
|
+
query: [
|
|
1037
|
+
new Or([
|
|
1038
|
+
new IntegerCompare({
|
|
1039
|
+
key: ["documents", "number"],
|
|
1040
|
+
compare: Compare.Equal,
|
|
1041
|
+
value: 123n,
|
|
1042
|
+
}),
|
|
1043
|
+
new IntegerCompare({
|
|
1044
|
+
key: ["documents", "number"],
|
|
1045
|
+
compare: Compare.Equal,
|
|
1046
|
+
value: 124n,
|
|
1047
|
+
}),
|
|
1048
|
+
new ByteMatchQuery({
|
|
1049
|
+
key: "id",
|
|
1050
|
+
value: new Uint8Array([1]),
|
|
1051
|
+
}),
|
|
1052
|
+
]),
|
|
1053
|
+
],
|
|
1054
|
+
});
|
|
1055
|
+
expect(results3.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1056
|
+
sha256Base64Sync(d1.id),
|
|
1057
|
+
sha256Base64Sync(d2.id),
|
|
1058
|
+
]);
|
|
1059
|
+
});
|
|
861
1060
|
});
|
|
862
|
-
expect(results.map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
863
1061
|
});
|
|
864
1062
|
it("update array", async () => {
|
|
865
1063
|
const out = await setup({ schema: DocumentsVec });
|
|
@@ -930,6 +1128,315 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
930
1128
|
}),
|
|
931
1129
|
})).length).to.equal(0);
|
|
932
1130
|
});
|
|
1131
|
+
it("can use re-use same property name", async () => {
|
|
1132
|
+
const out = await setup({
|
|
1133
|
+
schema: DocumentsVecWithPropertyDocument,
|
|
1134
|
+
});
|
|
1135
|
+
store = out.store;
|
|
1136
|
+
const d1 = new DocumentsVecWithPropertyDocument({
|
|
1137
|
+
property: "property 1",
|
|
1138
|
+
documents: [new DocumentWithProperty("nested property 1")],
|
|
1139
|
+
});
|
|
1140
|
+
const d2 = new DocumentsVecWithPropertyDocument({
|
|
1141
|
+
property: "property 2",
|
|
1142
|
+
documents: [new DocumentWithProperty("nested property 2")],
|
|
1143
|
+
});
|
|
1144
|
+
await store.put(d1);
|
|
1145
|
+
await store.put(d2);
|
|
1146
|
+
const results = await search(store, {
|
|
1147
|
+
query: new StringMatch({
|
|
1148
|
+
key: "property",
|
|
1149
|
+
value: "property 1",
|
|
1150
|
+
caseInsensitive: false,
|
|
1151
|
+
}),
|
|
1152
|
+
});
|
|
1153
|
+
expect(results).to.have.length(1);
|
|
1154
|
+
expect(results[0].value.property).to.equal("property 1");
|
|
1155
|
+
const resultsNested = await search(store, {
|
|
1156
|
+
query: new StringMatch({
|
|
1157
|
+
key: ["documents", "property"],
|
|
1158
|
+
value: "property 2",
|
|
1159
|
+
caseInsensitive: false,
|
|
1160
|
+
}),
|
|
1161
|
+
});
|
|
1162
|
+
expect(resultsNested).to.have.length(1);
|
|
1163
|
+
expect(resultsNested[0].value.property).to.equal("property 2");
|
|
1164
|
+
});
|
|
1165
|
+
});
|
|
1166
|
+
describe("simple value", () => {
|
|
1167
|
+
class ArrayDocument {
|
|
1168
|
+
id;
|
|
1169
|
+
array;
|
|
1170
|
+
constructor(properties) {
|
|
1171
|
+
this.id = properties.id || randomBytes(32);
|
|
1172
|
+
this.array = properties?.array || [];
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
__decorate([
|
|
1176
|
+
field({ type: Uint8Array }),
|
|
1177
|
+
__metadata("design:type", Uint8Array)
|
|
1178
|
+
], ArrayDocument.prototype, "id", void 0);
|
|
1179
|
+
__decorate([
|
|
1180
|
+
field({ type: vec("u32") }),
|
|
1181
|
+
__metadata("design:type", Array)
|
|
1182
|
+
], ArrayDocument.prototype, "array", void 0);
|
|
1183
|
+
describe("search", () => {
|
|
1184
|
+
let d1;
|
|
1185
|
+
let d2;
|
|
1186
|
+
let d3;
|
|
1187
|
+
beforeEach(async () => {
|
|
1188
|
+
const out = await setup({ schema: ArrayDocument });
|
|
1189
|
+
store = out.store;
|
|
1190
|
+
d1 = new ArrayDocument({
|
|
1191
|
+
id: new Uint8Array([0]),
|
|
1192
|
+
array: [1],
|
|
1193
|
+
});
|
|
1194
|
+
await store.put(d1);
|
|
1195
|
+
d2 = new ArrayDocument({
|
|
1196
|
+
id: new Uint8Array([1]),
|
|
1197
|
+
array: [2],
|
|
1198
|
+
});
|
|
1199
|
+
await store.put(d2);
|
|
1200
|
+
d3 = new ArrayDocument({
|
|
1201
|
+
id: new Uint8Array([2]),
|
|
1202
|
+
array: [0, 3],
|
|
1203
|
+
});
|
|
1204
|
+
await store.put(d3);
|
|
1205
|
+
});
|
|
1206
|
+
it("match", async () => {
|
|
1207
|
+
// equality
|
|
1208
|
+
const results = await search(store, {
|
|
1209
|
+
query: new IntegerCompare({
|
|
1210
|
+
key: ["array"],
|
|
1211
|
+
compare: Compare.Equal,
|
|
1212
|
+
value: d1.array[0],
|
|
1213
|
+
}),
|
|
1214
|
+
});
|
|
1215
|
+
expect(results.map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
1216
|
+
});
|
|
1217
|
+
describe("logical", () => {
|
|
1218
|
+
it("and", async () => {
|
|
1219
|
+
// can not be equal to two different things at once
|
|
1220
|
+
let results = await search(store, {
|
|
1221
|
+
query: [
|
|
1222
|
+
new And([
|
|
1223
|
+
new IntegerCompare({
|
|
1224
|
+
key: ["array"],
|
|
1225
|
+
compare: Compare.Equal,
|
|
1226
|
+
value: d1.array[0],
|
|
1227
|
+
}),
|
|
1228
|
+
new IntegerCompare({
|
|
1229
|
+
key: ["array"],
|
|
1230
|
+
compare: Compare.Equal,
|
|
1231
|
+
value: d2.array[0],
|
|
1232
|
+
}),
|
|
1233
|
+
]),
|
|
1234
|
+
],
|
|
1235
|
+
});
|
|
1236
|
+
expect(results).to.have.length(0);
|
|
1237
|
+
// can not be between two different things at once
|
|
1238
|
+
results = await search(store, {
|
|
1239
|
+
query: [
|
|
1240
|
+
new And([
|
|
1241
|
+
new IntegerCompare({
|
|
1242
|
+
key: ["array"],
|
|
1243
|
+
compare: Compare.Less,
|
|
1244
|
+
value: 1000,
|
|
1245
|
+
}),
|
|
1246
|
+
new IntegerCompare({
|
|
1247
|
+
key: ["array"],
|
|
1248
|
+
compare: Compare.Greater,
|
|
1249
|
+
value: 1000,
|
|
1250
|
+
}),
|
|
1251
|
+
]),
|
|
1252
|
+
],
|
|
1253
|
+
});
|
|
1254
|
+
expect(results).to.have.length(0);
|
|
1255
|
+
// between one value matches
|
|
1256
|
+
results = await search(store, {
|
|
1257
|
+
query: [
|
|
1258
|
+
new Or([
|
|
1259
|
+
new IntegerCompare({
|
|
1260
|
+
key: ["array"],
|
|
1261
|
+
compare: Compare.Less,
|
|
1262
|
+
value: 2,
|
|
1263
|
+
}),
|
|
1264
|
+
new IntegerCompare({
|
|
1265
|
+
key: ["array"],
|
|
1266
|
+
compare: Compare.GreaterOrEqual,
|
|
1267
|
+
value: 3,
|
|
1268
|
+
}),
|
|
1269
|
+
]),
|
|
1270
|
+
],
|
|
1271
|
+
});
|
|
1272
|
+
// because each query is applied separately
|
|
1273
|
+
expect(results.map((x) => sha256Base64Sync(x.value.id))).to.have.members([d1.id, d3.id].map(sha256Base64Sync));
|
|
1274
|
+
results = await search(store, {
|
|
1275
|
+
query: [
|
|
1276
|
+
new And([
|
|
1277
|
+
new IntegerCompare({
|
|
1278
|
+
key: ["array"],
|
|
1279
|
+
compare: Compare.Less,
|
|
1280
|
+
value: 2,
|
|
1281
|
+
}),
|
|
1282
|
+
new IntegerCompare({
|
|
1283
|
+
key: ["array"],
|
|
1284
|
+
compare: Compare.GreaterOrEqual,
|
|
1285
|
+
value: 1,
|
|
1286
|
+
}),
|
|
1287
|
+
]),
|
|
1288
|
+
],
|
|
1289
|
+
});
|
|
1290
|
+
// using nested path will apply the queries together
|
|
1291
|
+
expect(results.map((x) => sha256Base64Sync(x.value.id))).to.have.members([d1.id].map(sha256Base64Sync));
|
|
1292
|
+
});
|
|
1293
|
+
it("or", async () => {
|
|
1294
|
+
const results3 = await search(store, {
|
|
1295
|
+
query: [
|
|
1296
|
+
new Or([
|
|
1297
|
+
new IntegerCompare({
|
|
1298
|
+
key: ["array"],
|
|
1299
|
+
compare: Compare.Equal,
|
|
1300
|
+
value: d1.array[0],
|
|
1301
|
+
}),
|
|
1302
|
+
new IntegerCompare({
|
|
1303
|
+
key: ["array"],
|
|
1304
|
+
compare: Compare.Equal,
|
|
1305
|
+
value: d3.array[0],
|
|
1306
|
+
}),
|
|
1307
|
+
]),
|
|
1308
|
+
],
|
|
1309
|
+
});
|
|
1310
|
+
expect(results3.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1311
|
+
sha256Base64Sync(d1.id),
|
|
1312
|
+
sha256Base64Sync(d3.id),
|
|
1313
|
+
]);
|
|
1314
|
+
});
|
|
1315
|
+
it("or array, or field", async () => {
|
|
1316
|
+
const results3 = await search(store, {
|
|
1317
|
+
query: [
|
|
1318
|
+
new Or([
|
|
1319
|
+
new And([
|
|
1320
|
+
new IntegerCompare({
|
|
1321
|
+
key: ["array"],
|
|
1322
|
+
compare: Compare.LessOrEqual,
|
|
1323
|
+
value: 0,
|
|
1324
|
+
}),
|
|
1325
|
+
new IntegerCompare({
|
|
1326
|
+
key: ["array"],
|
|
1327
|
+
compare: Compare.LessOrEqual,
|
|
1328
|
+
value: 1,
|
|
1329
|
+
}),
|
|
1330
|
+
]),
|
|
1331
|
+
new ByteMatchQuery({
|
|
1332
|
+
key: "id",
|
|
1333
|
+
value: new Uint8Array([0]),
|
|
1334
|
+
}),
|
|
1335
|
+
]),
|
|
1336
|
+
],
|
|
1337
|
+
});
|
|
1338
|
+
expect(results3.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1339
|
+
sha256Base64Sync(d1.id),
|
|
1340
|
+
sha256Base64Sync(d3.id),
|
|
1341
|
+
]);
|
|
1342
|
+
});
|
|
1343
|
+
it("or all", async () => {
|
|
1344
|
+
const results = await search(store, {
|
|
1345
|
+
query: [
|
|
1346
|
+
new Or([
|
|
1347
|
+
new Or([
|
|
1348
|
+
new And([
|
|
1349
|
+
new IntegerCompare({
|
|
1350
|
+
key: ["array"],
|
|
1351
|
+
compare: Compare.GreaterOrEqual,
|
|
1352
|
+
value: 0,
|
|
1353
|
+
}),
|
|
1354
|
+
]),
|
|
1355
|
+
new And([
|
|
1356
|
+
new IntegerCompare({
|
|
1357
|
+
key: ["array"],
|
|
1358
|
+
compare: Compare.GreaterOrEqual,
|
|
1359
|
+
value: 0,
|
|
1360
|
+
}),
|
|
1361
|
+
]),
|
|
1362
|
+
]),
|
|
1363
|
+
new IntegerCompare({
|
|
1364
|
+
key: ["array"],
|
|
1365
|
+
compare: Compare.GreaterOrEqual,
|
|
1366
|
+
value: 0,
|
|
1367
|
+
}),
|
|
1368
|
+
]),
|
|
1369
|
+
],
|
|
1370
|
+
});
|
|
1371
|
+
expect(results.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1372
|
+
sha256Base64Sync(d1.id),
|
|
1373
|
+
sha256Base64Sync(d2.id),
|
|
1374
|
+
sha256Base64Sync(d3.id),
|
|
1375
|
+
]);
|
|
1376
|
+
});
|
|
1377
|
+
});
|
|
1378
|
+
});
|
|
1379
|
+
it("update array", async () => {
|
|
1380
|
+
const out = await setup({ schema: ArrayDocument });
|
|
1381
|
+
store = out.store;
|
|
1382
|
+
const d1 = new ArrayDocument({
|
|
1383
|
+
array: [123],
|
|
1384
|
+
});
|
|
1385
|
+
await store.put(d1);
|
|
1386
|
+
d1.array = [124];
|
|
1387
|
+
await store.put(d1);
|
|
1388
|
+
// should have update results
|
|
1389
|
+
expect((await search(store, {
|
|
1390
|
+
query: new IntegerCompare({
|
|
1391
|
+
key: ["array"],
|
|
1392
|
+
compare: Compare.Equal,
|
|
1393
|
+
value: 123,
|
|
1394
|
+
}),
|
|
1395
|
+
})).length).to.equal(0);
|
|
1396
|
+
expect((await search(store, {
|
|
1397
|
+
query: new IntegerCompare({
|
|
1398
|
+
key: ["array"],
|
|
1399
|
+
compare: Compare.Equal,
|
|
1400
|
+
value: 124,
|
|
1401
|
+
}),
|
|
1402
|
+
})).map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
1403
|
+
});
|
|
1404
|
+
it("put delete put", async () => {
|
|
1405
|
+
const { store } = await setup({ schema: ArrayDocument });
|
|
1406
|
+
const d1 = new ArrayDocument({
|
|
1407
|
+
array: [123],
|
|
1408
|
+
});
|
|
1409
|
+
await store.put(d1);
|
|
1410
|
+
const [deleted] = await store.del({
|
|
1411
|
+
query: {
|
|
1412
|
+
id: d1.id,
|
|
1413
|
+
},
|
|
1414
|
+
});
|
|
1415
|
+
expect(deleted.key).to.deep.equal(d1.id);
|
|
1416
|
+
expect((await search(store, {
|
|
1417
|
+
query: new IntegerCompare({
|
|
1418
|
+
key: ["array"],
|
|
1419
|
+
compare: Compare.Equal,
|
|
1420
|
+
value: 123,
|
|
1421
|
+
}),
|
|
1422
|
+
})).length).to.equal(0);
|
|
1423
|
+
d1.array = [124];
|
|
1424
|
+
await store.put(d1);
|
|
1425
|
+
expect((await search(store, {
|
|
1426
|
+
query: new IntegerCompare({
|
|
1427
|
+
key: ["array"],
|
|
1428
|
+
compare: Compare.Equal,
|
|
1429
|
+
value: 124,
|
|
1430
|
+
}),
|
|
1431
|
+
})).map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
1432
|
+
expect((await search(store, {
|
|
1433
|
+
query: new IntegerCompare({
|
|
1434
|
+
key: ["array"],
|
|
1435
|
+
compare: Compare.Equal,
|
|
1436
|
+
value: 123,
|
|
1437
|
+
}),
|
|
1438
|
+
})).length).to.equal(0);
|
|
1439
|
+
});
|
|
933
1440
|
});
|
|
934
1441
|
});
|
|
935
1442
|
describe("logical", () => {
|
|
@@ -1008,7 +1515,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1008
1515
|
new IntegerCompare({
|
|
1009
1516
|
key: "number",
|
|
1010
1517
|
compare: Compare.Equal,
|
|
1011
|
-
value:
|
|
1518
|
+
value: 2,
|
|
1012
1519
|
}),
|
|
1013
1520
|
],
|
|
1014
1521
|
});
|
|
@@ -1021,7 +1528,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1021
1528
|
new IntegerCompare({
|
|
1022
1529
|
key: "number",
|
|
1023
1530
|
compare: Compare.Greater,
|
|
1024
|
-
value:
|
|
1531
|
+
value: 2,
|
|
1025
1532
|
}),
|
|
1026
1533
|
],
|
|
1027
1534
|
});
|
|
@@ -1034,7 +1541,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1034
1541
|
new IntegerCompare({
|
|
1035
1542
|
key: "number",
|
|
1036
1543
|
compare: Compare.GreaterOrEqual,
|
|
1037
|
-
value:
|
|
1544
|
+
value: 2,
|
|
1038
1545
|
}),
|
|
1039
1546
|
],
|
|
1040
1547
|
});
|
|
@@ -1049,7 +1556,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1049
1556
|
new IntegerCompare({
|
|
1050
1557
|
key: "number",
|
|
1051
1558
|
compare: Compare.Less,
|
|
1052
|
-
value:
|
|
1559
|
+
value: 2,
|
|
1053
1560
|
}),
|
|
1054
1561
|
],
|
|
1055
1562
|
});
|
|
@@ -1071,6 +1578,19 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1071
1578
|
expect(response[0].value.number).to.be.oneOf([1n, 1]);
|
|
1072
1579
|
expect(response[1].value.number).to.be.oneOf([2n, 2]);
|
|
1073
1580
|
});
|
|
1581
|
+
it("bigint as compare value", async () => {
|
|
1582
|
+
const response = await search(store, {
|
|
1583
|
+
query: [
|
|
1584
|
+
new IntegerCompare({
|
|
1585
|
+
key: "number",
|
|
1586
|
+
compare: Compare.Less,
|
|
1587
|
+
value: 2n,
|
|
1588
|
+
}),
|
|
1589
|
+
],
|
|
1590
|
+
});
|
|
1591
|
+
expect(response).to.have.length(1);
|
|
1592
|
+
expect(response[0].value.number).to.be.oneOf([1n, 1]);
|
|
1593
|
+
});
|
|
1074
1594
|
});
|
|
1075
1595
|
describe("bigint", () => {
|
|
1076
1596
|
let BigInt = class BigInt {
|
|
@@ -1173,6 +1693,18 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1173
1693
|
expect(response[0].value.bigint).to.equal(first);
|
|
1174
1694
|
expect(response[1].value.bigint).to.equal(second);
|
|
1175
1695
|
});
|
|
1696
|
+
it("number as compare value", async () => {
|
|
1697
|
+
const response = await search(store, {
|
|
1698
|
+
query: [
|
|
1699
|
+
new IntegerCompare({
|
|
1700
|
+
key: "bigint",
|
|
1701
|
+
compare: Compare.Greater,
|
|
1702
|
+
value: 1,
|
|
1703
|
+
}),
|
|
1704
|
+
],
|
|
1705
|
+
});
|
|
1706
|
+
expect(response).to.have.length(3);
|
|
1707
|
+
});
|
|
1176
1708
|
});
|
|
1177
1709
|
describe("nested", () => {
|
|
1178
1710
|
describe("one level", () => {
|
|
@@ -1215,6 +1747,24 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1215
1747
|
beforeEach(async () => {
|
|
1216
1748
|
await setup({ schema: DocumentWithNesting });
|
|
1217
1749
|
});
|
|
1750
|
+
it("all", async () => {
|
|
1751
|
+
await store.put(new DocumentWithNesting({
|
|
1752
|
+
id: "1",
|
|
1753
|
+
nested: new Nested({ number: 1n, bool: false }),
|
|
1754
|
+
}));
|
|
1755
|
+
await store.put(new DocumentWithNesting({
|
|
1756
|
+
id: "2",
|
|
1757
|
+
nested: undefined,
|
|
1758
|
+
}));
|
|
1759
|
+
const all = await search(store, {});
|
|
1760
|
+
expect(all).to.have.length(2);
|
|
1761
|
+
expect(all.map((x) => x.id.primitive)).to.have.members([
|
|
1762
|
+
"1",
|
|
1763
|
+
"2",
|
|
1764
|
+
]);
|
|
1765
|
+
expect(all[0].value.nested).to.be.instanceOf(Nested);
|
|
1766
|
+
expect(all[1].value.nested).to.be.undefined;
|
|
1767
|
+
});
|
|
1218
1768
|
it("number", async () => {
|
|
1219
1769
|
await store.put(new DocumentWithNesting({
|
|
1220
1770
|
id: "1",
|
|
@@ -1994,21 +2544,16 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1994
2544
|
],
|
|
1995
2545
|
}));
|
|
1996
2546
|
const response = await search(store, {
|
|
1997
|
-
query: [
|
|
1998
|
-
new
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
new StringMatch({
|
|
2002
|
-
key: "a",
|
|
2003
|
-
value: "hello",
|
|
2004
|
-
}),
|
|
2005
|
-
new StringMatch({
|
|
2006
|
-
key: "b",
|
|
2007
|
-
value: "world",
|
|
2008
|
-
}),
|
|
2009
|
-
]),
|
|
2547
|
+
query: new And([
|
|
2548
|
+
new StringMatch({
|
|
2549
|
+
key: ["array", "a"],
|
|
2550
|
+
value: "hello",
|
|
2010
2551
|
}),
|
|
2011
|
-
|
|
2552
|
+
new StringMatch({
|
|
2553
|
+
key: ["array", "b"],
|
|
2554
|
+
value: "world",
|
|
2555
|
+
}),
|
|
2556
|
+
]),
|
|
2012
2557
|
});
|
|
2013
2558
|
expect(response).to.have.length(1);
|
|
2014
2559
|
expect(response[0].value.id).to.equal("1");
|
|
@@ -2025,8 +2570,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2025
2570
|
}),
|
|
2026
2571
|
],
|
|
2027
2572
|
});
|
|
2028
|
-
|
|
2029
|
-
await store.put(new NestedMultipleFieldsArrayDocument({
|
|
2573
|
+
const doc2 = new NestedMultipleFieldsArrayDocument({
|
|
2030
2574
|
id: "2",
|
|
2031
2575
|
array: [
|
|
2032
2576
|
new NestedMultipleFieldsDocument({
|
|
@@ -2038,8 +2582,25 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2038
2582
|
b: "world",
|
|
2039
2583
|
}),
|
|
2040
2584
|
],
|
|
2041
|
-
})
|
|
2042
|
-
const
|
|
2585
|
+
});
|
|
2586
|
+
const doc3 = new NestedMultipleFieldsArrayDocument({
|
|
2587
|
+
id: "3",
|
|
2588
|
+
array: [
|
|
2589
|
+
new NestedMultipleFieldsDocument({
|
|
2590
|
+
a: "_",
|
|
2591
|
+
b: "_",
|
|
2592
|
+
}),
|
|
2593
|
+
new NestedMultipleFieldsDocument({
|
|
2594
|
+
a: "_",
|
|
2595
|
+
b: "_",
|
|
2596
|
+
}),
|
|
2597
|
+
],
|
|
2598
|
+
});
|
|
2599
|
+
await store.put(doc1);
|
|
2600
|
+
await store.put(doc2);
|
|
2601
|
+
await store.put(doc3);
|
|
2602
|
+
// AND will only yield doc 1 since only doc 1 contains the combination below
|
|
2603
|
+
const responseAnd = await search(store, {
|
|
2043
2604
|
query: [
|
|
2044
2605
|
new StringMatch({
|
|
2045
2606
|
key: ["array", "a"],
|
|
@@ -2051,8 +2612,26 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2051
2612
|
}),
|
|
2052
2613
|
],
|
|
2053
2614
|
});
|
|
2615
|
+
expect(responseAnd).to.have.length(1);
|
|
2616
|
+
checkDocument(responseAnd[0].value, doc1);
|
|
2617
|
+
// OR will only yield doc 1 and doc 2 since both will fulfill one of two conditions
|
|
2618
|
+
const response = await search(store, {
|
|
2619
|
+
query: [
|
|
2620
|
+
new Or([
|
|
2621
|
+
new StringMatch({
|
|
2622
|
+
key: ["array", "a"],
|
|
2623
|
+
value: "hello",
|
|
2624
|
+
}),
|
|
2625
|
+
new StringMatch({
|
|
2626
|
+
key: ["array", "b"],
|
|
2627
|
+
value: "world",
|
|
2628
|
+
}),
|
|
2629
|
+
]),
|
|
2630
|
+
],
|
|
2631
|
+
});
|
|
2054
2632
|
expect(response).to.have.length(2);
|
|
2055
2633
|
checkDocument(response[0].value, doc1);
|
|
2634
|
+
checkDocument(response[1].value, doc2);
|
|
2056
2635
|
});
|
|
2057
2636
|
});
|
|
2058
2637
|
});
|
|
@@ -2480,11 +3059,11 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2480
3059
|
});
|
|
2481
3060
|
});
|
|
2482
3061
|
describe("sort", () => {
|
|
2483
|
-
const put = async (id,
|
|
3062
|
+
const put = async (id, options) => {
|
|
2484
3063
|
const doc = new Document({
|
|
2485
|
-
id:
|
|
2486
|
-
name: String(id),
|
|
2487
|
-
number: BigInt(id),
|
|
3064
|
+
id: String(id),
|
|
3065
|
+
name: options?.name ?? String(id),
|
|
3066
|
+
number: options?.number ?? BigInt(id),
|
|
2488
3067
|
tags: [],
|
|
2489
3068
|
});
|
|
2490
3069
|
const resp = await store.put(doc);
|
|
@@ -2639,12 +3218,12 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2639
3218
|
});
|
|
2640
3219
|
/* it("no sort is stable", async () => {
|
|
2641
3220
|
// TODO this test is actually not a good predictor of stability
|
|
2642
|
-
|
|
3221
|
+
|
|
2643
3222
|
const insertCount = 500;
|
|
2644
3223
|
for (let i = 0; i < insertCount; i++) {
|
|
2645
3224
|
await put(i, uuid());
|
|
2646
3225
|
}
|
|
2647
|
-
|
|
3226
|
+
|
|
2648
3227
|
const resolvedValues: Set<number> = new Set()
|
|
2649
3228
|
const batchSize = 123;
|
|
2650
3229
|
const iterator = store.iterate();
|
|
@@ -2667,6 +3246,21 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2667
3246
|
expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1", "2"]);
|
|
2668
3247
|
await assertIteratorIsDone(iterator);
|
|
2669
3248
|
});
|
|
3249
|
+
it("sort by multiple properties", async () => {
|
|
3250
|
+
await put(0, { name: "a", number: 2n });
|
|
3251
|
+
await put(1, { name: "a", number: 1n });
|
|
3252
|
+
await put(2, { name: "b", number: 2n });
|
|
3253
|
+
await put(3, { name: "b", number: 1n });
|
|
3254
|
+
const iterator = store.iterate({
|
|
3255
|
+
query: [],
|
|
3256
|
+
sort: [
|
|
3257
|
+
new Sort({ direction: SortDirection.DESC, key: "name" }),
|
|
3258
|
+
new Sort({ direction: SortDirection.ASC, key: "number" }),
|
|
3259
|
+
],
|
|
3260
|
+
});
|
|
3261
|
+
const out = await iterator.all();
|
|
3262
|
+
expect(out.map((x) => x.value.id)).to.deep.equal(["3", "2", "1", "0"]);
|
|
3263
|
+
});
|
|
2670
3264
|
describe("nested", () => {
|
|
2671
3265
|
it("variants", async () => {
|
|
2672
3266
|
const doc1 = new Document({
|
|
@@ -3138,6 +3732,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
3138
3732
|
expect(await store.getSize()).equal(0);
|
|
3139
3733
|
});
|
|
3140
3734
|
it("indices", async () => {
|
|
3735
|
+
// TODO make this test more clear and the purpose of each call
|
|
3141
3736
|
let { directory, indices } = await setupDefault();
|
|
3142
3737
|
let subindex = await indices.scope("x");
|
|
3143
3738
|
store = await subindex.init({ indexBy: ["id"], schema: Document });
|
|
@@ -3148,12 +3743,14 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
3148
3743
|
await store.start();
|
|
3149
3744
|
expect(await store.getSize()).equal(4);
|
|
3150
3745
|
await indices.drop();
|
|
3151
|
-
await
|
|
3746
|
+
const out = await setup({ schema: Document }, directory);
|
|
3747
|
+
indices = out.indices;
|
|
3748
|
+
await indices.start();
|
|
3749
|
+
store = out.store;
|
|
3152
3750
|
expect(await store.getSize()).equal(0);
|
|
3153
3751
|
await store.stop(); /// TODO why do w
|
|
3154
3752
|
await indices.stop();
|
|
3155
3753
|
store = (await setup({ schema: Document }, directory)).store;
|
|
3156
|
-
await store.start();
|
|
3157
3754
|
expect(await store.getSize()).equal(0);
|
|
3158
3755
|
});
|
|
3159
3756
|
});
|