@peerbit/indexer-tests 1.1.2 → 1.1.3-5cf61cb
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 +562 -54
- package/dist/src/tests.js.map +1 -1
- package/package.json +66 -66
- package/src/benchmarks.ts +512 -218
- package/src/tests.ts +678 -67
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"]) => {
|
|
@@ -770,7 +770,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
770
770
|
});
|
|
771
771
|
});
|
|
772
772
|
});
|
|
773
|
-
|
|
773
|
+
it("bool", async () => {
|
|
774
774
|
await setupDefault();
|
|
775
775
|
const responses = await search(store, {
|
|
776
776
|
query: [
|
|
@@ -839,28 +839,171 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
839
839
|
field({ type: vec(Document) }),
|
|
840
840
|
__metadata("design:type", Array)
|
|
841
841
|
], DocumentsVec.prototype, "documents", void 0);
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
842
|
+
describe("search", () => {
|
|
843
|
+
let d1;
|
|
844
|
+
let d2;
|
|
845
|
+
let d3;
|
|
846
|
+
beforeEach(async () => {
|
|
847
|
+
const out = await setup({ schema: DocumentsVec });
|
|
848
|
+
store = out.store;
|
|
849
|
+
d1 = new DocumentsVec({
|
|
850
|
+
id: new Uint8Array([0]),
|
|
851
|
+
documents: [
|
|
852
|
+
new Document({ id: uuid(), number: 123n, tags: [] }),
|
|
853
|
+
],
|
|
854
|
+
});
|
|
855
|
+
await store.put(d1);
|
|
856
|
+
d2 = new DocumentsVec({
|
|
857
|
+
id: new Uint8Array([1]),
|
|
858
|
+
documents: [
|
|
859
|
+
new Document({ id: uuid(), number: 124n, tags: [] }),
|
|
860
|
+
],
|
|
861
|
+
});
|
|
862
|
+
await store.put(d2);
|
|
863
|
+
d3 = new DocumentsVec({
|
|
864
|
+
id: new Uint8Array([2]),
|
|
865
|
+
documents: [
|
|
866
|
+
new Document({ id: uuid(), number: 122n, tags: [] }),
|
|
867
|
+
new Document({ id: uuid(), number: 125n, tags: [] }),
|
|
868
|
+
],
|
|
869
|
+
});
|
|
870
|
+
await store.put(d3);
|
|
849
871
|
});
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
new
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
872
|
+
it("match", async () => {
|
|
873
|
+
// equality
|
|
874
|
+
const results = await search(store, {
|
|
875
|
+
query: new IntegerCompare({
|
|
876
|
+
key: ["documents", "number"],
|
|
877
|
+
compare: Compare.Equal,
|
|
878
|
+
value: d1.documents[0].number,
|
|
879
|
+
}),
|
|
880
|
+
});
|
|
881
|
+
expect(results.map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
882
|
+
});
|
|
883
|
+
describe("logical", () => {
|
|
884
|
+
it("and", async () => {
|
|
885
|
+
// can not be equal to two different things at once
|
|
886
|
+
let results = await search(store, {
|
|
887
|
+
query: [
|
|
888
|
+
new And([
|
|
889
|
+
new IntegerCompare({
|
|
890
|
+
key: ["documents", "number"],
|
|
891
|
+
compare: Compare.Equal,
|
|
892
|
+
value: 123n,
|
|
893
|
+
}),
|
|
894
|
+
new IntegerCompare({
|
|
895
|
+
key: ["documents", "number"],
|
|
896
|
+
compare: Compare.Equal,
|
|
897
|
+
value: 124n,
|
|
898
|
+
}),
|
|
899
|
+
]),
|
|
900
|
+
],
|
|
901
|
+
});
|
|
902
|
+
expect(results).to.have.length(0);
|
|
903
|
+
// can not be between two different things at once
|
|
904
|
+
results = await search(store, {
|
|
905
|
+
query: [
|
|
906
|
+
new And([
|
|
907
|
+
new IntegerCompare({
|
|
908
|
+
key: ["documents", "number"],
|
|
909
|
+
compare: Compare.Less,
|
|
910
|
+
value: 1000n,
|
|
911
|
+
}),
|
|
912
|
+
new IntegerCompare({
|
|
913
|
+
key: ["documents", "number"],
|
|
914
|
+
compare: Compare.Greater,
|
|
915
|
+
value: 1000n,
|
|
916
|
+
}),
|
|
917
|
+
]),
|
|
918
|
+
],
|
|
919
|
+
});
|
|
920
|
+
expect(results).to.have.length(0);
|
|
921
|
+
// between one value matches
|
|
922
|
+
results = await search(store, {
|
|
923
|
+
query: [
|
|
924
|
+
new Or([
|
|
925
|
+
new IntegerCompare({
|
|
926
|
+
key: ["documents", "number"],
|
|
927
|
+
compare: Compare.Less,
|
|
928
|
+
value: 124n,
|
|
929
|
+
}),
|
|
930
|
+
new IntegerCompare({
|
|
931
|
+
key: ["documents", "number"],
|
|
932
|
+
compare: Compare.GreaterOrEqual,
|
|
933
|
+
value: 125n,
|
|
934
|
+
}),
|
|
935
|
+
]),
|
|
936
|
+
],
|
|
937
|
+
});
|
|
938
|
+
// because each query is applied separately
|
|
939
|
+
expect(results.map((x) => sha256Base64Sync(x.value.id))).to.have.members([d1.id, d3.id].map(sha256Base64Sync));
|
|
940
|
+
results = await search(store, {
|
|
941
|
+
query: [
|
|
942
|
+
new And([
|
|
943
|
+
new IntegerCompare({
|
|
944
|
+
key: ["documents", "number"],
|
|
945
|
+
compare: Compare.Less,
|
|
946
|
+
value: 124n,
|
|
947
|
+
}),
|
|
948
|
+
new IntegerCompare({
|
|
949
|
+
key: ["documents", "number"],
|
|
950
|
+
compare: Compare.GreaterOrEqual,
|
|
951
|
+
value: 123n,
|
|
952
|
+
}),
|
|
953
|
+
]),
|
|
954
|
+
],
|
|
955
|
+
});
|
|
956
|
+
expect(results.map((x) => x.value.id)).to.deep.eq([d1.id]);
|
|
957
|
+
});
|
|
958
|
+
it("or", async () => {
|
|
959
|
+
const results3 = await search(store, {
|
|
960
|
+
query: [
|
|
961
|
+
new Or([
|
|
962
|
+
new IntegerCompare({
|
|
963
|
+
key: ["documents", "number"],
|
|
964
|
+
compare: Compare.Equal,
|
|
965
|
+
value: 123n,
|
|
966
|
+
}),
|
|
967
|
+
new IntegerCompare({
|
|
968
|
+
key: ["documents", "number"],
|
|
969
|
+
compare: Compare.Equal,
|
|
970
|
+
value: 124n,
|
|
971
|
+
}),
|
|
972
|
+
]),
|
|
973
|
+
],
|
|
974
|
+
});
|
|
975
|
+
expect(results3.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
976
|
+
sha256Base64Sync(d1.id),
|
|
977
|
+
sha256Base64Sync(d2.id),
|
|
978
|
+
]);
|
|
979
|
+
});
|
|
980
|
+
it("or arr, or field", async () => {
|
|
981
|
+
const results3 = await search(store, {
|
|
982
|
+
query: [
|
|
983
|
+
new Or([
|
|
984
|
+
new IntegerCompare({
|
|
985
|
+
key: ["documents", "number"],
|
|
986
|
+
compare: Compare.Equal,
|
|
987
|
+
value: 123n,
|
|
988
|
+
}),
|
|
989
|
+
new IntegerCompare({
|
|
990
|
+
key: ["documents", "number"],
|
|
991
|
+
compare: Compare.Equal,
|
|
992
|
+
value: 124n,
|
|
993
|
+
}),
|
|
994
|
+
new ByteMatchQuery({
|
|
995
|
+
key: "id",
|
|
996
|
+
value: new Uint8Array([1]),
|
|
997
|
+
}),
|
|
998
|
+
]),
|
|
999
|
+
],
|
|
1000
|
+
});
|
|
1001
|
+
expect(results3.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1002
|
+
sha256Base64Sync(d1.id),
|
|
1003
|
+
sha256Base64Sync(d2.id),
|
|
1004
|
+
]);
|
|
1005
|
+
});
|
|
862
1006
|
});
|
|
863
|
-
expect(results.map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
864
1007
|
});
|
|
865
1008
|
it("update array", async () => {
|
|
866
1009
|
const out = await setup({ schema: DocumentsVec });
|
|
@@ -932,6 +1075,281 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
932
1075
|
})).length).to.equal(0);
|
|
933
1076
|
});
|
|
934
1077
|
});
|
|
1078
|
+
describe("simple value", () => {
|
|
1079
|
+
class ArrayDocument {
|
|
1080
|
+
id;
|
|
1081
|
+
array;
|
|
1082
|
+
constructor(properties) {
|
|
1083
|
+
this.id = properties.id || randomBytes(32);
|
|
1084
|
+
this.array = properties?.array || [];
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
__decorate([
|
|
1088
|
+
field({ type: Uint8Array }),
|
|
1089
|
+
__metadata("design:type", Uint8Array)
|
|
1090
|
+
], ArrayDocument.prototype, "id", void 0);
|
|
1091
|
+
__decorate([
|
|
1092
|
+
field({ type: vec("u32") }),
|
|
1093
|
+
__metadata("design:type", Array)
|
|
1094
|
+
], ArrayDocument.prototype, "array", void 0);
|
|
1095
|
+
describe("search", () => {
|
|
1096
|
+
let d1;
|
|
1097
|
+
let d2;
|
|
1098
|
+
let d3;
|
|
1099
|
+
beforeEach(async () => {
|
|
1100
|
+
const out = await setup({ schema: ArrayDocument });
|
|
1101
|
+
store = out.store;
|
|
1102
|
+
d1 = new ArrayDocument({
|
|
1103
|
+
id: new Uint8Array([0]),
|
|
1104
|
+
array: [1],
|
|
1105
|
+
});
|
|
1106
|
+
await store.put(d1);
|
|
1107
|
+
d2 = new ArrayDocument({
|
|
1108
|
+
id: new Uint8Array([1]),
|
|
1109
|
+
array: [2],
|
|
1110
|
+
});
|
|
1111
|
+
await store.put(d2);
|
|
1112
|
+
d3 = new ArrayDocument({
|
|
1113
|
+
id: new Uint8Array([2]),
|
|
1114
|
+
array: [0, 3],
|
|
1115
|
+
});
|
|
1116
|
+
await store.put(d3);
|
|
1117
|
+
});
|
|
1118
|
+
it("match", async () => {
|
|
1119
|
+
// equality
|
|
1120
|
+
const results = await search(store, {
|
|
1121
|
+
query: new IntegerCompare({
|
|
1122
|
+
key: ["array"],
|
|
1123
|
+
compare: Compare.Equal,
|
|
1124
|
+
value: d1.array[0],
|
|
1125
|
+
}),
|
|
1126
|
+
});
|
|
1127
|
+
expect(results.map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
1128
|
+
});
|
|
1129
|
+
describe("logical", () => {
|
|
1130
|
+
it("and", async () => {
|
|
1131
|
+
// can not be equal to two different things at once
|
|
1132
|
+
let results = await search(store, {
|
|
1133
|
+
query: [
|
|
1134
|
+
new And([
|
|
1135
|
+
new IntegerCompare({
|
|
1136
|
+
key: ["array"],
|
|
1137
|
+
compare: Compare.Equal,
|
|
1138
|
+
value: d1.array[0],
|
|
1139
|
+
}),
|
|
1140
|
+
new IntegerCompare({
|
|
1141
|
+
key: ["array"],
|
|
1142
|
+
compare: Compare.Equal,
|
|
1143
|
+
value: d2.array[0],
|
|
1144
|
+
}),
|
|
1145
|
+
]),
|
|
1146
|
+
],
|
|
1147
|
+
});
|
|
1148
|
+
expect(results).to.have.length(0);
|
|
1149
|
+
// can not be between two different things at once
|
|
1150
|
+
results = await search(store, {
|
|
1151
|
+
query: [
|
|
1152
|
+
new And([
|
|
1153
|
+
new IntegerCompare({
|
|
1154
|
+
key: ["array"],
|
|
1155
|
+
compare: Compare.Less,
|
|
1156
|
+
value: 1000,
|
|
1157
|
+
}),
|
|
1158
|
+
new IntegerCompare({
|
|
1159
|
+
key: ["array"],
|
|
1160
|
+
compare: Compare.Greater,
|
|
1161
|
+
value: 1000,
|
|
1162
|
+
}),
|
|
1163
|
+
]),
|
|
1164
|
+
],
|
|
1165
|
+
});
|
|
1166
|
+
expect(results).to.have.length(0);
|
|
1167
|
+
// between one value matches
|
|
1168
|
+
results = await search(store, {
|
|
1169
|
+
query: [
|
|
1170
|
+
new Or([
|
|
1171
|
+
new IntegerCompare({
|
|
1172
|
+
key: ["array"],
|
|
1173
|
+
compare: Compare.Less,
|
|
1174
|
+
value: 2,
|
|
1175
|
+
}),
|
|
1176
|
+
new IntegerCompare({
|
|
1177
|
+
key: ["array"],
|
|
1178
|
+
compare: Compare.GreaterOrEqual,
|
|
1179
|
+
value: 3,
|
|
1180
|
+
}),
|
|
1181
|
+
]),
|
|
1182
|
+
],
|
|
1183
|
+
});
|
|
1184
|
+
// because each query is applied separately
|
|
1185
|
+
expect(results.map((x) => sha256Base64Sync(x.value.id))).to.have.members([d1.id, d3.id].map(sha256Base64Sync));
|
|
1186
|
+
results = await search(store, {
|
|
1187
|
+
query: [
|
|
1188
|
+
new And([
|
|
1189
|
+
new IntegerCompare({
|
|
1190
|
+
key: ["array"],
|
|
1191
|
+
compare: Compare.Less,
|
|
1192
|
+
value: 2,
|
|
1193
|
+
}),
|
|
1194
|
+
new IntegerCompare({
|
|
1195
|
+
key: ["array"],
|
|
1196
|
+
compare: Compare.GreaterOrEqual,
|
|
1197
|
+
value: 1,
|
|
1198
|
+
}),
|
|
1199
|
+
]),
|
|
1200
|
+
],
|
|
1201
|
+
});
|
|
1202
|
+
// using nested path will apply the queries together
|
|
1203
|
+
expect(results.map((x) => sha256Base64Sync(x.value.id))).to.have.members([d1.id].map(sha256Base64Sync));
|
|
1204
|
+
});
|
|
1205
|
+
it("or", async () => {
|
|
1206
|
+
const results3 = await search(store, {
|
|
1207
|
+
query: [
|
|
1208
|
+
new Or([
|
|
1209
|
+
new IntegerCompare({
|
|
1210
|
+
key: ["array"],
|
|
1211
|
+
compare: Compare.Equal,
|
|
1212
|
+
value: d1.array[0],
|
|
1213
|
+
}),
|
|
1214
|
+
new IntegerCompare({
|
|
1215
|
+
key: ["array"],
|
|
1216
|
+
compare: Compare.Equal,
|
|
1217
|
+
value: d3.array[0],
|
|
1218
|
+
}),
|
|
1219
|
+
]),
|
|
1220
|
+
],
|
|
1221
|
+
});
|
|
1222
|
+
expect(results3.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1223
|
+
sha256Base64Sync(d1.id),
|
|
1224
|
+
sha256Base64Sync(d3.id),
|
|
1225
|
+
]);
|
|
1226
|
+
});
|
|
1227
|
+
it("or array, or field", async () => {
|
|
1228
|
+
const results3 = await search(store, {
|
|
1229
|
+
query: [
|
|
1230
|
+
new Or([
|
|
1231
|
+
new And([
|
|
1232
|
+
new IntegerCompare({
|
|
1233
|
+
key: ["array"],
|
|
1234
|
+
compare: Compare.LessOrEqual,
|
|
1235
|
+
value: 0,
|
|
1236
|
+
}),
|
|
1237
|
+
new IntegerCompare({
|
|
1238
|
+
key: ["array"],
|
|
1239
|
+
compare: Compare.LessOrEqual,
|
|
1240
|
+
value: 1,
|
|
1241
|
+
}),
|
|
1242
|
+
]),
|
|
1243
|
+
new ByteMatchQuery({
|
|
1244
|
+
key: "id",
|
|
1245
|
+
value: new Uint8Array([0]),
|
|
1246
|
+
}),
|
|
1247
|
+
]),
|
|
1248
|
+
],
|
|
1249
|
+
});
|
|
1250
|
+
expect(results3.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1251
|
+
sha256Base64Sync(d1.id),
|
|
1252
|
+
sha256Base64Sync(d3.id),
|
|
1253
|
+
]);
|
|
1254
|
+
});
|
|
1255
|
+
it("or all", async () => {
|
|
1256
|
+
const results = await search(store, {
|
|
1257
|
+
query: [
|
|
1258
|
+
new Or([
|
|
1259
|
+
new Or([
|
|
1260
|
+
new And([
|
|
1261
|
+
new IntegerCompare({
|
|
1262
|
+
key: ["array"],
|
|
1263
|
+
compare: Compare.GreaterOrEqual,
|
|
1264
|
+
value: 0,
|
|
1265
|
+
}),
|
|
1266
|
+
]),
|
|
1267
|
+
new And([
|
|
1268
|
+
new IntegerCompare({
|
|
1269
|
+
key: ["array"],
|
|
1270
|
+
compare: Compare.GreaterOrEqual,
|
|
1271
|
+
value: 0,
|
|
1272
|
+
}),
|
|
1273
|
+
]),
|
|
1274
|
+
]),
|
|
1275
|
+
new IntegerCompare({
|
|
1276
|
+
key: ["array"],
|
|
1277
|
+
compare: Compare.GreaterOrEqual,
|
|
1278
|
+
value: 0,
|
|
1279
|
+
}),
|
|
1280
|
+
]),
|
|
1281
|
+
],
|
|
1282
|
+
});
|
|
1283
|
+
expect(results.map((x) => sha256Base64Sync(x.value.id))).to.have.members([
|
|
1284
|
+
sha256Base64Sync(d1.id),
|
|
1285
|
+
sha256Base64Sync(d2.id),
|
|
1286
|
+
sha256Base64Sync(d3.id),
|
|
1287
|
+
]);
|
|
1288
|
+
});
|
|
1289
|
+
});
|
|
1290
|
+
});
|
|
1291
|
+
it("update array", async () => {
|
|
1292
|
+
const out = await setup({ schema: ArrayDocument });
|
|
1293
|
+
store = out.store;
|
|
1294
|
+
const d1 = new ArrayDocument({
|
|
1295
|
+
array: [123],
|
|
1296
|
+
});
|
|
1297
|
+
await store.put(d1);
|
|
1298
|
+
d1.array = [124];
|
|
1299
|
+
await store.put(d1);
|
|
1300
|
+
// should have update results
|
|
1301
|
+
expect((await search(store, {
|
|
1302
|
+
query: new IntegerCompare({
|
|
1303
|
+
key: ["array"],
|
|
1304
|
+
compare: Compare.Equal,
|
|
1305
|
+
value: 123,
|
|
1306
|
+
}),
|
|
1307
|
+
})).length).to.equal(0);
|
|
1308
|
+
expect((await search(store, {
|
|
1309
|
+
query: new IntegerCompare({
|
|
1310
|
+
key: ["array"],
|
|
1311
|
+
compare: Compare.Equal,
|
|
1312
|
+
value: 124,
|
|
1313
|
+
}),
|
|
1314
|
+
})).map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
1315
|
+
});
|
|
1316
|
+
it("put delete put", async () => {
|
|
1317
|
+
const { store } = await setup({ schema: ArrayDocument });
|
|
1318
|
+
const d1 = new ArrayDocument({
|
|
1319
|
+
array: [123],
|
|
1320
|
+
});
|
|
1321
|
+
await store.put(d1);
|
|
1322
|
+
const [deleted] = await store.del({
|
|
1323
|
+
query: {
|
|
1324
|
+
id: d1.id,
|
|
1325
|
+
},
|
|
1326
|
+
});
|
|
1327
|
+
expect(deleted.key).to.deep.equal(d1.id);
|
|
1328
|
+
expect((await search(store, {
|
|
1329
|
+
query: new IntegerCompare({
|
|
1330
|
+
key: ["array"],
|
|
1331
|
+
compare: Compare.Equal,
|
|
1332
|
+
value: 123,
|
|
1333
|
+
}),
|
|
1334
|
+
})).length).to.equal(0);
|
|
1335
|
+
d1.array = [124];
|
|
1336
|
+
await store.put(d1);
|
|
1337
|
+
expect((await search(store, {
|
|
1338
|
+
query: new IntegerCompare({
|
|
1339
|
+
key: ["array"],
|
|
1340
|
+
compare: Compare.Equal,
|
|
1341
|
+
value: 124,
|
|
1342
|
+
}),
|
|
1343
|
+
})).map((x) => x.value.id)).to.deep.equal([d1.id]);
|
|
1344
|
+
expect((await search(store, {
|
|
1345
|
+
query: new IntegerCompare({
|
|
1346
|
+
key: ["array"],
|
|
1347
|
+
compare: Compare.Equal,
|
|
1348
|
+
value: 123,
|
|
1349
|
+
}),
|
|
1350
|
+
})).length).to.equal(0);
|
|
1351
|
+
});
|
|
1352
|
+
});
|
|
935
1353
|
});
|
|
936
1354
|
describe("logical", () => {
|
|
937
1355
|
beforeEach(async () => {
|
|
@@ -1009,7 +1427,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1009
1427
|
new IntegerCompare({
|
|
1010
1428
|
key: "number",
|
|
1011
1429
|
compare: Compare.Equal,
|
|
1012
|
-
value:
|
|
1430
|
+
value: 2,
|
|
1013
1431
|
}),
|
|
1014
1432
|
],
|
|
1015
1433
|
});
|
|
@@ -1022,7 +1440,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1022
1440
|
new IntegerCompare({
|
|
1023
1441
|
key: "number",
|
|
1024
1442
|
compare: Compare.Greater,
|
|
1025
|
-
value:
|
|
1443
|
+
value: 2,
|
|
1026
1444
|
}),
|
|
1027
1445
|
],
|
|
1028
1446
|
});
|
|
@@ -1035,7 +1453,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1035
1453
|
new IntegerCompare({
|
|
1036
1454
|
key: "number",
|
|
1037
1455
|
compare: Compare.GreaterOrEqual,
|
|
1038
|
-
value:
|
|
1456
|
+
value: 2,
|
|
1039
1457
|
}),
|
|
1040
1458
|
],
|
|
1041
1459
|
});
|
|
@@ -1050,7 +1468,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1050
1468
|
new IntegerCompare({
|
|
1051
1469
|
key: "number",
|
|
1052
1470
|
compare: Compare.Less,
|
|
1053
|
-
value:
|
|
1471
|
+
value: 2,
|
|
1054
1472
|
}),
|
|
1055
1473
|
],
|
|
1056
1474
|
});
|
|
@@ -1072,6 +1490,19 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1072
1490
|
expect(response[0].value.number).to.be.oneOf([1n, 1]);
|
|
1073
1491
|
expect(response[1].value.number).to.be.oneOf([2n, 2]);
|
|
1074
1492
|
});
|
|
1493
|
+
it("bigint as compare value", async () => {
|
|
1494
|
+
const response = await search(store, {
|
|
1495
|
+
query: [
|
|
1496
|
+
new IntegerCompare({
|
|
1497
|
+
key: "number",
|
|
1498
|
+
compare: Compare.Less,
|
|
1499
|
+
value: 2n,
|
|
1500
|
+
}),
|
|
1501
|
+
],
|
|
1502
|
+
});
|
|
1503
|
+
expect(response).to.have.length(1);
|
|
1504
|
+
expect(response[0].value.number).to.be.oneOf([1n, 1]);
|
|
1505
|
+
});
|
|
1075
1506
|
});
|
|
1076
1507
|
describe("bigint", () => {
|
|
1077
1508
|
let BigInt = class BigInt {
|
|
@@ -1174,6 +1605,18 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1174
1605
|
expect(response[0].value.bigint).to.equal(first);
|
|
1175
1606
|
expect(response[1].value.bigint).to.equal(second);
|
|
1176
1607
|
});
|
|
1608
|
+
it("number as compare value", async () => {
|
|
1609
|
+
const response = await search(store, {
|
|
1610
|
+
query: [
|
|
1611
|
+
new IntegerCompare({
|
|
1612
|
+
key: "bigint",
|
|
1613
|
+
compare: Compare.Greater,
|
|
1614
|
+
value: 1,
|
|
1615
|
+
}),
|
|
1616
|
+
],
|
|
1617
|
+
});
|
|
1618
|
+
expect(response).to.have.length(3);
|
|
1619
|
+
});
|
|
1177
1620
|
});
|
|
1178
1621
|
describe("nested", () => {
|
|
1179
1622
|
describe("one level", () => {
|
|
@@ -1216,6 +1659,24 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1216
1659
|
beforeEach(async () => {
|
|
1217
1660
|
await setup({ schema: DocumentWithNesting });
|
|
1218
1661
|
});
|
|
1662
|
+
it("all", async () => {
|
|
1663
|
+
await store.put(new DocumentWithNesting({
|
|
1664
|
+
id: "1",
|
|
1665
|
+
nested: new Nested({ number: 1n, bool: false }),
|
|
1666
|
+
}));
|
|
1667
|
+
await store.put(new DocumentWithNesting({
|
|
1668
|
+
id: "2",
|
|
1669
|
+
nested: undefined,
|
|
1670
|
+
}));
|
|
1671
|
+
const all = await search(store, {});
|
|
1672
|
+
expect(all).to.have.length(2);
|
|
1673
|
+
expect(all.map((x) => x.id.primitive)).to.have.members([
|
|
1674
|
+
"1",
|
|
1675
|
+
"2",
|
|
1676
|
+
]);
|
|
1677
|
+
expect(all[0].value.nested).to.be.instanceOf(Nested);
|
|
1678
|
+
expect(all[1].value.nested).to.be.undefined;
|
|
1679
|
+
});
|
|
1219
1680
|
it("number", async () => {
|
|
1220
1681
|
await store.put(new DocumentWithNesting({
|
|
1221
1682
|
id: "1",
|
|
@@ -1995,21 +2456,16 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
1995
2456
|
],
|
|
1996
2457
|
}));
|
|
1997
2458
|
const response = await search(store, {
|
|
1998
|
-
query: [
|
|
1999
|
-
new
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
new StringMatch({
|
|
2003
|
-
key: "a",
|
|
2004
|
-
value: "hello",
|
|
2005
|
-
}),
|
|
2006
|
-
new StringMatch({
|
|
2007
|
-
key: "b",
|
|
2008
|
-
value: "world",
|
|
2009
|
-
}),
|
|
2010
|
-
]),
|
|
2459
|
+
query: new And([
|
|
2460
|
+
new StringMatch({
|
|
2461
|
+
key: ["array", "a"],
|
|
2462
|
+
value: "hello",
|
|
2011
2463
|
}),
|
|
2012
|
-
|
|
2464
|
+
new StringMatch({
|
|
2465
|
+
key: ["array", "b"],
|
|
2466
|
+
value: "world",
|
|
2467
|
+
}),
|
|
2468
|
+
]),
|
|
2013
2469
|
});
|
|
2014
2470
|
expect(response).to.have.length(1);
|
|
2015
2471
|
expect(response[0].value.id).to.equal("1");
|
|
@@ -2026,8 +2482,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2026
2482
|
}),
|
|
2027
2483
|
],
|
|
2028
2484
|
});
|
|
2029
|
-
|
|
2030
|
-
await store.put(new NestedMultipleFieldsArrayDocument({
|
|
2485
|
+
const doc2 = new NestedMultipleFieldsArrayDocument({
|
|
2031
2486
|
id: "2",
|
|
2032
2487
|
array: [
|
|
2033
2488
|
new NestedMultipleFieldsDocument({
|
|
@@ -2039,8 +2494,25 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2039
2494
|
b: "world",
|
|
2040
2495
|
}),
|
|
2041
2496
|
],
|
|
2042
|
-
})
|
|
2043
|
-
const
|
|
2497
|
+
});
|
|
2498
|
+
const doc3 = new NestedMultipleFieldsArrayDocument({
|
|
2499
|
+
id: "3",
|
|
2500
|
+
array: [
|
|
2501
|
+
new NestedMultipleFieldsDocument({
|
|
2502
|
+
a: "_",
|
|
2503
|
+
b: "_",
|
|
2504
|
+
}),
|
|
2505
|
+
new NestedMultipleFieldsDocument({
|
|
2506
|
+
a: "_",
|
|
2507
|
+
b: "_",
|
|
2508
|
+
}),
|
|
2509
|
+
],
|
|
2510
|
+
});
|
|
2511
|
+
await store.put(doc1);
|
|
2512
|
+
await store.put(doc2);
|
|
2513
|
+
await store.put(doc3);
|
|
2514
|
+
// AND will only yield doc 1 since only doc 1 contains the combination below
|
|
2515
|
+
const responseAnd = await search(store, {
|
|
2044
2516
|
query: [
|
|
2045
2517
|
new StringMatch({
|
|
2046
2518
|
key: ["array", "a"],
|
|
@@ -2052,8 +2524,26 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2052
2524
|
}),
|
|
2053
2525
|
],
|
|
2054
2526
|
});
|
|
2527
|
+
expect(responseAnd).to.have.length(1);
|
|
2528
|
+
checkDocument(responseAnd[0].value, doc1);
|
|
2529
|
+
// OR will only yield doc 1 and doc 2 since both will fulfill one of two conditions
|
|
2530
|
+
const response = await search(store, {
|
|
2531
|
+
query: [
|
|
2532
|
+
new Or([
|
|
2533
|
+
new StringMatch({
|
|
2534
|
+
key: ["array", "a"],
|
|
2535
|
+
value: "hello",
|
|
2536
|
+
}),
|
|
2537
|
+
new StringMatch({
|
|
2538
|
+
key: ["array", "b"],
|
|
2539
|
+
value: "world",
|
|
2540
|
+
}),
|
|
2541
|
+
]),
|
|
2542
|
+
],
|
|
2543
|
+
});
|
|
2055
2544
|
expect(response).to.have.length(2);
|
|
2056
2545
|
checkDocument(response[0].value, doc1);
|
|
2546
|
+
checkDocument(response[1].value, doc2);
|
|
2057
2547
|
});
|
|
2058
2548
|
});
|
|
2059
2549
|
});
|
|
@@ -2481,11 +2971,11 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2481
2971
|
});
|
|
2482
2972
|
});
|
|
2483
2973
|
describe("sort", () => {
|
|
2484
|
-
const put = async (id,
|
|
2974
|
+
const put = async (id, options) => {
|
|
2485
2975
|
const doc = new Document({
|
|
2486
|
-
id:
|
|
2487
|
-
name: String(id),
|
|
2488
|
-
number: BigInt(id),
|
|
2976
|
+
id: String(id),
|
|
2977
|
+
name: options?.name ?? String(id),
|
|
2978
|
+
number: options?.number ?? BigInt(id),
|
|
2489
2979
|
tags: [],
|
|
2490
2980
|
});
|
|
2491
2981
|
const resp = await store.put(doc);
|
|
@@ -2640,12 +3130,12 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2640
3130
|
});
|
|
2641
3131
|
/* it("no sort is stable", async () => {
|
|
2642
3132
|
// TODO this test is actually not a good predictor of stability
|
|
2643
|
-
|
|
3133
|
+
|
|
2644
3134
|
const insertCount = 500;
|
|
2645
3135
|
for (let i = 0; i < insertCount; i++) {
|
|
2646
3136
|
await put(i, uuid());
|
|
2647
3137
|
}
|
|
2648
|
-
|
|
3138
|
+
|
|
2649
3139
|
const resolvedValues: Set<number> = new Set()
|
|
2650
3140
|
const batchSize = 123;
|
|
2651
3141
|
const iterator = store.iterate();
|
|
@@ -2668,6 +3158,21 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
2668
3158
|
expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1", "2"]);
|
|
2669
3159
|
await assertIteratorIsDone(iterator);
|
|
2670
3160
|
});
|
|
3161
|
+
it("sort by multiple properties", async () => {
|
|
3162
|
+
await put(0, { name: "a", number: 2n });
|
|
3163
|
+
await put(1, { name: "a", number: 1n });
|
|
3164
|
+
await put(2, { name: "b", number: 2n });
|
|
3165
|
+
await put(3, { name: "b", number: 1n });
|
|
3166
|
+
const iterator = store.iterate({
|
|
3167
|
+
query: [],
|
|
3168
|
+
sort: [
|
|
3169
|
+
new Sort({ direction: SortDirection.DESC, key: "name" }),
|
|
3170
|
+
new Sort({ direction: SortDirection.ASC, key: "number" }),
|
|
3171
|
+
],
|
|
3172
|
+
});
|
|
3173
|
+
const out = await iterator.all();
|
|
3174
|
+
expect(out.map((x) => x.value.id)).to.deep.equal(["3", "2", "1", "0"]);
|
|
3175
|
+
});
|
|
2671
3176
|
describe("nested", () => {
|
|
2672
3177
|
it("variants", async () => {
|
|
2673
3178
|
const doc1 = new Document({
|
|
@@ -3139,6 +3644,7 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
3139
3644
|
expect(await store.getSize()).equal(0);
|
|
3140
3645
|
});
|
|
3141
3646
|
it("indices", async () => {
|
|
3647
|
+
// TODO make this test more clear and the purpose of each call
|
|
3142
3648
|
let { directory, indices } = await setupDefault();
|
|
3143
3649
|
let subindex = await indices.scope("x");
|
|
3144
3650
|
store = await subindex.init({ indexBy: ["id"], schema: Document });
|
|
@@ -3149,12 +3655,14 @@ export const tests = (createIndicies, type = "transient", properties) => {
|
|
|
3149
3655
|
await store.start();
|
|
3150
3656
|
expect(await store.getSize()).equal(4);
|
|
3151
3657
|
await indices.drop();
|
|
3152
|
-
await
|
|
3658
|
+
const out = await setup({ schema: Document }, directory);
|
|
3659
|
+
indices = out.indices;
|
|
3660
|
+
await indices.start();
|
|
3661
|
+
store = out.store;
|
|
3153
3662
|
expect(await store.getSize()).equal(0);
|
|
3154
3663
|
await store.stop(); /// TODO why do w
|
|
3155
3664
|
await indices.stop();
|
|
3156
3665
|
store = (await setup({ schema: Document }, directory)).store;
|
|
3157
|
-
await store.start();
|
|
3158
3666
|
expect(await store.getSize()).equal(0);
|
|
3159
3667
|
});
|
|
3160
3668
|
});
|