@model-ts/dynamodb 3.0.4 → 3.1.0
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/CHANGELOG.md +6 -0
- package/dist/cjs/__test__/client.test.js +261 -129
- package/dist/cjs/__test__/client.test.js.map +1 -1
- package/dist/cjs/provider.d.ts +149 -19
- package/dist/cjs/provider.js +131 -1
- package/dist/cjs/provider.js.map +1 -1
- package/dist/esm/__test__/client.test.js +262 -130
- package/dist/esm/__test__/client.test.js.map +1 -1
- package/dist/esm/provider.d.ts +149 -19
- package/dist/esm/provider.js +131 -1
- package/dist/esm/provider.js.map +1 -1
- package/package.json +1 -1
- package/src/__test__/client.test.ts +367 -163
- package/src/provider.ts +147 -3
|
@@ -11,7 +11,7 @@ const client = new client_1.Client({ tableName: "table" });
|
|
|
11
11
|
const provider = provider_1.getProvider(client);
|
|
12
12
|
const SIMPLE_CODEC = t.type({
|
|
13
13
|
foo: t.string,
|
|
14
|
-
bar: t.number
|
|
14
|
+
bar: t.number,
|
|
15
15
|
});
|
|
16
16
|
class Simple extends core_1.model("Simple", SIMPLE_CODEC, provider) {
|
|
17
17
|
get PK() {
|
|
@@ -273,7 +273,7 @@ describe("put", () => {
|
|
|
273
273
|
test("it overwrites item if `ignoreExistence` is set", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
274
274
|
yield MultiGSI.put(new MultiGSI({ foo: "yes", bar: 42 }));
|
|
275
275
|
yield expect(MultiGSI.put(new MultiGSI({ foo: "yes", bar: 42 }), {
|
|
276
|
-
IgnoreExistence: true
|
|
276
|
+
IgnoreExistence: true,
|
|
277
277
|
})).resolves.toBeInstanceOf(MultiGSI);
|
|
278
278
|
}));
|
|
279
279
|
});
|
|
@@ -287,7 +287,7 @@ describe("get", () => {
|
|
|
287
287
|
const item = yield new Simple({ foo: "hi", bar: 432 }).put();
|
|
288
288
|
const result = yield Simple.get({
|
|
289
289
|
PK: item.keys().PK,
|
|
290
|
-
SK: item.keys().SK
|
|
290
|
+
SK: item.keys().SK,
|
|
291
291
|
});
|
|
292
292
|
expect(result.values()).toMatchInlineSnapshot(`
|
|
293
293
|
Object {
|
|
@@ -334,8 +334,8 @@ describe("delete", () => {
|
|
|
334
334
|
_model: Simple,
|
|
335
335
|
key: {
|
|
336
336
|
PK: item.keys().PK,
|
|
337
|
-
SK: item.keys().SK
|
|
338
|
-
}
|
|
337
|
+
SK: item.keys().SK,
|
|
338
|
+
},
|
|
339
339
|
});
|
|
340
340
|
expect(result).toBeNull();
|
|
341
341
|
expect(yield sandbox.diff(before)).toMatchInlineSnapshot(`
|
|
@@ -363,7 +363,7 @@ describe("delete", () => {
|
|
|
363
363
|
const before = yield sandbox.snapshot();
|
|
364
364
|
const result = yield Simple.delete({
|
|
365
365
|
PK: item.keys().PK,
|
|
366
|
-
SK: item.keys().SK
|
|
366
|
+
SK: item.keys().SK,
|
|
367
367
|
});
|
|
368
368
|
expect(result).toBeNull();
|
|
369
369
|
expect(yield sandbox.diff(before)).toMatchInlineSnapshot(`
|
|
@@ -672,11 +672,12 @@ describe("applyUpdate", () => {
|
|
|
672
672
|
}));
|
|
673
673
|
});
|
|
674
674
|
describe("query", () => {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
675
|
+
describe("via client", () => {
|
|
676
|
+
test("it returns empty results", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
677
|
+
expect(yield client.query({
|
|
678
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
679
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT" },
|
|
680
|
+
}, { a: A, b: B, union: Union })).toMatchInlineSnapshot(`
|
|
680
681
|
Object {
|
|
681
682
|
"_unknown": Array [],
|
|
682
683
|
"a": Array [],
|
|
@@ -687,13 +688,13 @@ describe("query", () => {
|
|
|
687
688
|
"union": Array [],
|
|
688
689
|
}
|
|
689
690
|
`);
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
691
|
+
}));
|
|
692
|
+
test("it returns unknown results", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
693
|
+
yield sandbox.seed({ PK: "abc", SK: "SORT#1", doesnt: "match" });
|
|
694
|
+
expect(yield client.query({
|
|
695
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
696
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
697
|
+
}, { a: A, b: B, union: Union })).toMatchInlineSnapshot(`
|
|
697
698
|
Object {
|
|
698
699
|
"_unknown": Array [
|
|
699
700
|
Object {
|
|
@@ -710,20 +711,20 @@ describe("query", () => {
|
|
|
710
711
|
"union": Array [],
|
|
711
712
|
}
|
|
712
713
|
`);
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
714
|
+
}));
|
|
715
|
+
test("it returns results", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
716
|
+
yield sandbox.seed(new A({ pk: "abc", sk: "SORT#1", a: 1 }), new A({ pk: "abc", sk: "SORT#2", a: 2 }), new B({ pk: "abc", sk: "SORT#3", b: "hi" }), { PK: "abc", SK: "SORT#4", probably: "unknown" }, new C({ pk: "abc", sk: "SORT#5", c: "hi" }), new D({ pk: "abc", sk: "SORT#6", d: "hi" }));
|
|
717
|
+
const { a, b, union, _unknown, meta } = yield client.query({
|
|
718
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
719
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
720
|
+
}, { a: A, b: B, union: Union });
|
|
721
|
+
expect({
|
|
722
|
+
meta: meta,
|
|
723
|
+
_unknown: _unknown,
|
|
724
|
+
a: a.map((item) => item.values()),
|
|
725
|
+
b: b.map((item) => item.values()),
|
|
726
|
+
union: union.map((item) => item.values()),
|
|
727
|
+
}).toMatchInlineSnapshot(`
|
|
727
728
|
Object {
|
|
728
729
|
"_unknown": Array [
|
|
729
730
|
Object {
|
|
@@ -768,43 +769,174 @@ describe("query", () => {
|
|
|
768
769
|
],
|
|
769
770
|
}
|
|
770
771
|
`);
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
772
|
+
}));
|
|
773
|
+
test("it paginates", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
774
|
+
yield sandbox.seed(...Array.from({ length: 20 }).map((_, i) => new A({ pk: "abc", sk: `SORT#${String(i).padStart(2, "0")}`, a: i })), ...Array.from({ length: 20 }).map((_, i) => new B({ pk: "abc", sk: `SORT#${i + 20}`, b: "bar" })));
|
|
775
|
+
const firstPage = yield client.query({
|
|
776
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
777
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
778
|
+
Limit: 30,
|
|
779
|
+
}, { a: A, b: B });
|
|
780
|
+
expect(firstPage.a.length).toBe(20);
|
|
781
|
+
expect(firstPage.b.length).toBe(10);
|
|
782
|
+
expect(firstPage._unknown.length).toBe(0);
|
|
783
|
+
expect(firstPage.meta.lastEvaluatedKey).not.toBeUndefined();
|
|
784
|
+
const secondPage = yield client.query({
|
|
785
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
786
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
787
|
+
Limit: 30,
|
|
788
|
+
ExclusiveStartKey: firstPage.meta.lastEvaluatedKey,
|
|
789
|
+
}, { a: A, b: B });
|
|
790
|
+
expect(secondPage.a.length).toBe(0);
|
|
791
|
+
expect(secondPage.b.length).toBe(10);
|
|
792
|
+
expect(secondPage._unknown.length).toBe(0);
|
|
793
|
+
expect(secondPage.meta.lastEvaluatedKey).toBeUndefined();
|
|
794
|
+
}));
|
|
795
|
+
test("it fetches all pages automatically", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
796
|
+
yield sandbox.seed(...Array.from({ length: 20 }).map((_, i) => new A({ pk: "abc", sk: `SORT#${String(i).padStart(2, "0")}`, a: i })), ...Array.from({ length: 20 }).map((_, i) => new B({ pk: "abc", sk: `SORT#${i + 20}`, b: "bar" })));
|
|
797
|
+
const { a, b, meta, _unknown } = yield client.query({
|
|
798
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
799
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
800
|
+
FetchAllPages: true,
|
|
801
|
+
// You wouldn't set a limit in a real-world use case here to optimize fetching all items.
|
|
802
|
+
Limit: 10,
|
|
803
|
+
}, { a: A, b: B });
|
|
804
|
+
expect(a.length).toBe(20);
|
|
805
|
+
expect(b.length).toBe(20);
|
|
806
|
+
expect(_unknown.length).toBe(0);
|
|
807
|
+
expect(meta.lastEvaluatedKey).toBeUndefined();
|
|
808
|
+
}));
|
|
809
|
+
});
|
|
810
|
+
describe("via model", () => {
|
|
811
|
+
test("it returns empty results for specific model", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
812
|
+
const result = yield A.query({
|
|
813
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
814
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT" },
|
|
815
|
+
});
|
|
816
|
+
expect(result.length).toBe(0);
|
|
817
|
+
expect(result.meta).toEqual({ lastEvaluatedKey: undefined });
|
|
818
|
+
}));
|
|
819
|
+
test("it returns only matching model items", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
820
|
+
yield sandbox.seed(new A({ pk: "abc", sk: "SORT#1", a: 1 }), new A({ pk: "abc", sk: "SORT#2", a: 2 }), new B({ pk: "abc", sk: "SORT#3", b: "hi" }), { PK: "abc", SK: "SORT#4", probably: "unknown" }, new C({ pk: "abc", sk: "SORT#5", c: "hi" }));
|
|
821
|
+
const result = yield A.query({
|
|
822
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
823
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
824
|
+
});
|
|
825
|
+
expect(result.length).toBe(2);
|
|
826
|
+
expect(result.map((item) => item.values())).toMatchInlineSnapshot(`
|
|
827
|
+
Array [
|
|
828
|
+
Object {
|
|
829
|
+
"a": 1,
|
|
830
|
+
"pk": "abc",
|
|
831
|
+
"sk": "SORT#1",
|
|
832
|
+
},
|
|
833
|
+
Object {
|
|
834
|
+
"a": 2,
|
|
835
|
+
"pk": "abc",
|
|
836
|
+
"sk": "SORT#2",
|
|
837
|
+
},
|
|
838
|
+
]
|
|
839
|
+
`);
|
|
840
|
+
expect(result.meta).toEqual({ lastEvaluatedKey: undefined });
|
|
841
|
+
}));
|
|
842
|
+
test("it respects query parameters", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
843
|
+
yield sandbox.seed(new A({ pk: "abc", sk: "SORT#1", a: 1 }), new A({ pk: "abc", sk: "SORT#2", a: 2 }), new A({ pk: "abc", sk: "SORT#3", a: 3 }), new A({ pk: "abc", sk: "SORT#4", a: 4 }));
|
|
844
|
+
const result = yield A.query({
|
|
845
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
846
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
847
|
+
Limit: 2,
|
|
848
|
+
});
|
|
849
|
+
expect(result.length).toBe(2);
|
|
850
|
+
expect(result[0].a).toBe(1);
|
|
851
|
+
expect(result[1].a).toBe(2);
|
|
852
|
+
expect(result.meta.lastEvaluatedKey).toBeDefined();
|
|
853
|
+
}));
|
|
854
|
+
test("it fetches all pages when FetchAllPages is true", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
855
|
+
yield sandbox.seed(...Array.from({ length: 15 }).map((_, i) => new A({ pk: "abc", sk: `SORT#${String(i).padStart(2, "0")}`, a: i })),
|
|
856
|
+
// Add some B items that should be ignored
|
|
857
|
+
new B({ pk: "abc", sk: "SORT#20", b: "ignored" }), new B({ pk: "abc", sk: "SORT#21", b: "ignored" }));
|
|
858
|
+
const result = yield A.query({
|
|
859
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
860
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
861
|
+
FetchAllPages: true,
|
|
862
|
+
Limit: 5, // Force pagination
|
|
863
|
+
});
|
|
864
|
+
expect(result.length).toBe(15); // Only A items
|
|
865
|
+
expect(result.map((item) => item.a)).toEqual(Array.from({ length: 15 }, (_, i) => i));
|
|
866
|
+
expect(result.meta.lastEvaluatedKey).toBeUndefined();
|
|
867
|
+
}));
|
|
868
|
+
test("it works with different query conditions", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
869
|
+
yield sandbox.seed(new A({ pk: "user1", sk: "post#1", a: 1 }), new A({ pk: "user1", sk: "post#2", a: 2 }), new A({ pk: "user1", sk: "comment#1", a: 3 }), new A({ pk: "user2", sk: "post#1", a: 4 }));
|
|
870
|
+
// Query for posts only
|
|
871
|
+
const posts = yield A.query({
|
|
872
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
873
|
+
ExpressionAttributeValues: { ":pk": "user1", ":sk": "post#" },
|
|
874
|
+
});
|
|
875
|
+
expect(posts.length).toBe(2);
|
|
876
|
+
expect(posts.map((item) => item.a).sort()).toEqual([1, 2]);
|
|
877
|
+
// Query for all user1 items
|
|
878
|
+
const allUser1 = yield A.query({
|
|
879
|
+
KeyConditionExpression: `PK = :pk`,
|
|
880
|
+
ExpressionAttributeValues: { ":pk": "user1" },
|
|
881
|
+
});
|
|
882
|
+
expect(allUser1.length).toBe(3);
|
|
883
|
+
expect(allUser1.map((item) => item.a).sort()).toEqual([1, 2, 3]);
|
|
884
|
+
}));
|
|
885
|
+
test("it works with FilterExpression", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
886
|
+
yield sandbox.seed(new A({ pk: "test", sk: "item#1", a: 1 }), new A({ pk: "test", sk: "item#2", a: 2 }), new A({ pk: "test", sk: "item#3", a: 3 }), new A({ pk: "test", sk: "item#4", a: 4 }));
|
|
887
|
+
const result = yield A.query({
|
|
888
|
+
KeyConditionExpression: `PK = :pk`,
|
|
889
|
+
FilterExpression: `a > :min`,
|
|
890
|
+
ExpressionAttributeValues: { ":pk": "test", ":min": 2 },
|
|
891
|
+
});
|
|
892
|
+
expect(result.length).toBe(2);
|
|
893
|
+
expect(result.map((item) => item.a).sort()).toEqual([3, 4]);
|
|
894
|
+
}));
|
|
895
|
+
});
|
|
896
|
+
describe("via union", () => {
|
|
897
|
+
test("it returns empty results for union", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
898
|
+
const result = yield Union.query({
|
|
899
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
900
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT" },
|
|
901
|
+
});
|
|
902
|
+
expect(result.length).toBe(0);
|
|
903
|
+
expect(result.meta).toEqual({ lastEvaluatedKey: undefined });
|
|
904
|
+
}));
|
|
905
|
+
test("it returns only union model items", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
906
|
+
yield sandbox.seed(new A({ pk: "abc", sk: "SORT#1", a: 1 }), new B({ pk: "abc", sk: "SORT#2", b: "hi" }), new C({ pk: "abc", sk: "SORT#3", c: "c1" }), new D({ pk: "abc", sk: "SORT#4", d: "d1" }), { PK: "abc", SK: "SORT#5", unknown: "data" });
|
|
907
|
+
const result = yield Union.query({
|
|
908
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
909
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
910
|
+
});
|
|
911
|
+
expect(result.length).toBe(2); // Only C and D items (union members)
|
|
912
|
+
expect(result[0]).toBeInstanceOf(C);
|
|
913
|
+
expect(result[1]).toBeInstanceOf(D);
|
|
914
|
+
expect(result.meta).toEqual({ lastEvaluatedKey: undefined });
|
|
915
|
+
}));
|
|
916
|
+
test("it fetches all pages for union when FetchAllPages is true", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
917
|
+
yield sandbox.seed(...Array.from({ length: 10 }).map((_, i) => new C({
|
|
918
|
+
pk: "abc",
|
|
919
|
+
sk: `SORT#${String(i).padStart(2, "0")}`,
|
|
920
|
+
c: `c${i}`,
|
|
921
|
+
})), ...Array.from({ length: 10 }).map((_, i) => new D({
|
|
922
|
+
pk: "abc",
|
|
923
|
+
sk: `SORT#${String(i + 10).padStart(2, "0")}`,
|
|
924
|
+
d: `d${i}`,
|
|
925
|
+
})),
|
|
926
|
+
// Add some non-union items that should be ignored
|
|
927
|
+
new A({ pk: "abc", sk: "SORT#30", a: 1 }), new B({ pk: "abc", sk: "SORT#31", b: "ignored" }));
|
|
928
|
+
const result = yield Union.query({
|
|
929
|
+
KeyConditionExpression: `PK = :pk and begins_with(SK, :sk)`,
|
|
930
|
+
ExpressionAttributeValues: { ":pk": "abc", ":sk": "SORT#" },
|
|
931
|
+
FetchAllPages: true,
|
|
932
|
+
Limit: 5, // Force pagination
|
|
933
|
+
});
|
|
934
|
+
expect(result.length).toBe(20); // Only union items (C and D)
|
|
935
|
+
expect(result.filter((item) => item instanceof C).length).toBe(10);
|
|
936
|
+
expect(result.filter((item) => item instanceof D).length).toBe(10);
|
|
937
|
+
expect(result.meta.lastEvaluatedKey).toBeUndefined();
|
|
938
|
+
}));
|
|
939
|
+
});
|
|
808
940
|
});
|
|
809
941
|
describe("bulk", () => {
|
|
810
942
|
describe("< 100 elements (true transaction)", () => {
|
|
@@ -822,16 +954,16 @@ describe("bulk", () => {
|
|
|
822
954
|
new B({
|
|
823
955
|
pk: "PK#UPDATE",
|
|
824
956
|
sk: "SK#UPDATE",
|
|
825
|
-
b: "bar"
|
|
957
|
+
b: "bar",
|
|
826
958
|
}).operation("update", { b: "baz" }),
|
|
827
959
|
new B({
|
|
828
960
|
pk: "PK#COND",
|
|
829
961
|
sk: "SK#COND",
|
|
830
|
-
b: "cond"
|
|
962
|
+
b: "cond",
|
|
831
963
|
}).operation("condition", {
|
|
832
964
|
ConditionExpression: "b = :cond",
|
|
833
|
-
ExpressionAttributeValues: { ":cond": "cond" }
|
|
834
|
-
})
|
|
965
|
+
ExpressionAttributeValues: { ":cond": "cond" },
|
|
966
|
+
}),
|
|
835
967
|
]);
|
|
836
968
|
expect(yield sandbox.diff(before)).toMatchInlineSnapshot(`
|
|
837
969
|
Snapshot Diff:
|
|
@@ -935,7 +1067,7 @@ describe("bulk", () => {
|
|
|
935
1067
|
A.operation("put", new A({ pk: "PK5", sk: "PK5", a: 5 })),
|
|
936
1068
|
new B({ pk: "PK#6", sk: "SK#6", b: "baz" }).operation("put"),
|
|
937
1069
|
// Fails
|
|
938
|
-
A.operation("updateRaw", { PK: "PK#nicetry", SK: "SK#nope" }, { a: 234 })
|
|
1070
|
+
A.operation("updateRaw", { PK: "PK#nicetry", SK: "SK#nope" }, { a: 234 }),
|
|
939
1071
|
])).rejects.toBeInstanceOf(errors_1.BulkWriteTransactionError);
|
|
940
1072
|
expect(yield sandbox.snapshot()).toEqual(before);
|
|
941
1073
|
}));
|
|
@@ -954,9 +1086,9 @@ describe("bulk", () => {
|
|
|
954
1086
|
new B({
|
|
955
1087
|
pk: "PK#UPDATE",
|
|
956
1088
|
sk: "SK#UPDATE",
|
|
957
|
-
b: "bar"
|
|
1089
|
+
b: "bar",
|
|
958
1090
|
}).operation("update", { b: "baz" }),
|
|
959
|
-
...Array.from({ length: 100 }).map((_, i) => new A({ pk: `PK#A${i}`, sk: `SK#A${i}`, a: i }).operation("put"))
|
|
1091
|
+
...Array.from({ length: 100 }).map((_, i) => new A({ pk: `PK#A${i}`, sk: `SK#A${i}`, a: i }).operation("put")),
|
|
960
1092
|
]);
|
|
961
1093
|
//#region snapshot
|
|
962
1094
|
expect(yield sandbox.diff(before)).toMatchInlineSnapshot(`
|
|
@@ -1932,7 +2064,7 @@ describe("bulk", () => {
|
|
|
1932
2064
|
// Succeeds
|
|
1933
2065
|
...Array.from({ length: 110 }).map((_, i) => new A({ pk: `PK#${i}`, sk: `SK#${i}`, a: i }).operation("put")),
|
|
1934
2066
|
// Fails
|
|
1935
|
-
A.operation("condition", { PK: "nicetry", SK: "nope" }, { ConditionExpression: "attribute_exists(PK)" })
|
|
2067
|
+
A.operation("condition", { PK: "nicetry", SK: "nope" }, { ConditionExpression: "attribute_exists(PK)" }),
|
|
1936
2068
|
])).rejects.toBeInstanceOf(errors_1.BulkWriteTransactionError);
|
|
1937
2069
|
expect(yield sandbox.snapshot()).toEqual(before);
|
|
1938
2070
|
}));
|
|
@@ -1956,7 +2088,7 @@ describe("batchGet", () => {
|
|
|
1956
2088
|
two: A.operation("get", { PK: "PK#2", SK: "SK#2" }),
|
|
1957
2089
|
three: A.operation("get", { PK: "PK#3", SK: "SK#3" }),
|
|
1958
2090
|
four: A.operation("get", { PK: "PK#4", SK: "SK#4" }),
|
|
1959
|
-
duplicate: A.operation("get", { PK: "PK#1", SK: "SK#1" })
|
|
2091
|
+
duplicate: A.operation("get", { PK: "PK#1", SK: "SK#1" }),
|
|
1960
2092
|
})).rejects.toBeInstanceOf(errors_1.ItemNotFoundError);
|
|
1961
2093
|
}));
|
|
1962
2094
|
test("it returns individual errors", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1966,7 +2098,7 @@ describe("batchGet", () => {
|
|
|
1966
2098
|
two: A.operation("get", { PK: "PK#2", SK: "SK#2" }),
|
|
1967
2099
|
duplicate: A.operation("get", { PK: "PK#1", SK: "SK#1" }),
|
|
1968
2100
|
error: A.operation("get", { PK: "PK#error", SK: "SK#error" }),
|
|
1969
|
-
error2: A.operation("get", { PK: "PK#error2", SK: "SK#error2" })
|
|
2101
|
+
error2: A.operation("get", { PK: "PK#error2", SK: "SK#error2" }),
|
|
1970
2102
|
}, { individualErrors: true });
|
|
1971
2103
|
expect(result.one).toBeInstanceOf(A);
|
|
1972
2104
|
expect(result.two).toBeInstanceOf(A);
|
|
@@ -1980,7 +2112,7 @@ describe("batchGet", () => {
|
|
|
1980
2112
|
two: A.operation("get", { PK: "PK#2", SK: "SK#2" }),
|
|
1981
2113
|
three: A.operation("get", { PK: "PK#3", SK: "SK#3" }),
|
|
1982
2114
|
four: A.operation("get", { PK: "PK#4", SK: "SK#4" }),
|
|
1983
|
-
duplicate: A.operation("get", { PK: "PK#1", SK: "SK#1" })
|
|
2115
|
+
duplicate: A.operation("get", { PK: "PK#1", SK: "SK#1" }),
|
|
1984
2116
|
});
|
|
1985
2117
|
expect(Object.fromEntries(Object.entries(results).map(([key, val]) => [key, val.values()]))).toMatchInlineSnapshot(`
|
|
1986
2118
|
Object {
|
|
@@ -2026,20 +2158,20 @@ describe("load", () => {
|
|
|
2026
2158
|
yield sandbox.seed(item);
|
|
2027
2159
|
yield item.softDelete();
|
|
2028
2160
|
const recovered = yield client.load(A.operation("get", { PK: "PK#1", SK: "SK#1" }), {
|
|
2029
|
-
recover: true
|
|
2161
|
+
recover: true,
|
|
2030
2162
|
});
|
|
2031
2163
|
expect(recovered).toBeInstanceOf(A);
|
|
2032
2164
|
expect(recovered.isDeleted).toBe(true);
|
|
2033
2165
|
}));
|
|
2034
2166
|
test("it throws if no item or soft deleted item exists", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
2035
2167
|
yield expect(client.load(A.operation("get", { PK: "PK", SK: "SK" }), {
|
|
2036
|
-
recover: true
|
|
2168
|
+
recover: true,
|
|
2037
2169
|
})).rejects.toBeInstanceOf(errors_1.ItemNotFoundError);
|
|
2038
2170
|
}));
|
|
2039
2171
|
test("it returns null instead of throwing if no item or soft deleted item exists", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
2040
2172
|
yield expect(client.load(A.operation("get", { PK: "PK", SK: "SK" }), {
|
|
2041
2173
|
recover: true,
|
|
2042
|
-
null: true
|
|
2174
|
+
null: true,
|
|
2043
2175
|
})).resolves.toBeNull();
|
|
2044
2176
|
}));
|
|
2045
2177
|
test("it fetches >100 items", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -2090,8 +2222,8 @@ describe("load", () => {
|
|
|
2090
2222
|
yield sandbox.seed(...items);
|
|
2091
2223
|
const results = yield Promise.all(items.map(({ PK, SK }, i) => Union.load({ PK, SK })));
|
|
2092
2224
|
expect(results.length).toBe(234);
|
|
2093
|
-
expect(results.filter(item => item instanceof C).length).toBe(123);
|
|
2094
|
-
expect(results.filter(item => item instanceof D).length).toBe(111);
|
|
2225
|
+
expect(results.filter((item) => item instanceof C).length).toBe(123);
|
|
2226
|
+
expect(results.filter((item) => item instanceof D).length).toBe(111);
|
|
2095
2227
|
expect(spy).toHaveBeenCalledTimes(3);
|
|
2096
2228
|
spy.mockReset();
|
|
2097
2229
|
spy.mockRestore();
|
|
@@ -2136,8 +2268,8 @@ describe("loadMany", () => {
|
|
|
2136
2268
|
yield sandbox.seed(...items);
|
|
2137
2269
|
const results = yield Union.loadMany(items.map(({ PK, SK }) => ({ PK, SK })));
|
|
2138
2270
|
expect(results.length).toBe(234);
|
|
2139
|
-
expect(results.filter(item => item instanceof C).length).toBe(123);
|
|
2140
|
-
expect(results.filter(item => item instanceof D).length).toBe(111);
|
|
2271
|
+
expect(results.filter((item) => item instanceof C).length).toBe(123);
|
|
2272
|
+
expect(results.filter((item) => item instanceof D).length).toBe(111);
|
|
2141
2273
|
expect(spy).toHaveBeenCalledTimes(3);
|
|
2142
2274
|
spy.mockReset();
|
|
2143
2275
|
spy.mockRestore();
|
|
@@ -2152,7 +2284,7 @@ describe("paginate", () => {
|
|
|
2152
2284
|
// Forwards
|
|
2153
2285
|
const page1 = yield client.paginate(C, {}, {
|
|
2154
2286
|
KeyConditionExpression: "PK = :pk",
|
|
2155
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2287
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2156
2288
|
});
|
|
2157
2289
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
2158
2290
|
Object {
|
|
@@ -2167,7 +2299,7 @@ describe("paginate", () => {
|
|
|
2167
2299
|
expect(page1.edges[19].node.c).toBe("19");
|
|
2168
2300
|
const page2 = yield client.paginate(C, { after: page1.pageInfo.endCursor }, {
|
|
2169
2301
|
KeyConditionExpression: "PK = :pk",
|
|
2170
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2302
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2171
2303
|
});
|
|
2172
2304
|
expect(page2.pageInfo).toMatchInlineSnapshot(`
|
|
2173
2305
|
Object {
|
|
@@ -2182,7 +2314,7 @@ describe("paginate", () => {
|
|
|
2182
2314
|
expect(page2.edges[19].node.c).toBe("39");
|
|
2183
2315
|
const page3 = yield client.paginate(C, { after: page2.pageInfo.endCursor }, {
|
|
2184
2316
|
KeyConditionExpression: "PK = :pk",
|
|
2185
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2317
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2186
2318
|
});
|
|
2187
2319
|
expect(page3.pageInfo).toMatchInlineSnapshot(`
|
|
2188
2320
|
Object {
|
|
@@ -2198,7 +2330,7 @@ describe("paginate", () => {
|
|
|
2198
2330
|
// Backwards
|
|
2199
2331
|
const backwardsPage2 = yield client.paginate(C, { before: page3.pageInfo.startCursor }, {
|
|
2200
2332
|
KeyConditionExpression: "PK = :pk",
|
|
2201
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2333
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2202
2334
|
});
|
|
2203
2335
|
expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
|
|
2204
2336
|
Object {
|
|
@@ -2213,7 +2345,7 @@ describe("paginate", () => {
|
|
|
2213
2345
|
expect(backwardsPage2.edges[19].node.c).toBe("39");
|
|
2214
2346
|
const backwardsPage1 = yield client.paginate(C, { before: backwardsPage2.pageInfo.startCursor }, {
|
|
2215
2347
|
KeyConditionExpression: "PK = :pk",
|
|
2216
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2348
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2217
2349
|
});
|
|
2218
2350
|
expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
|
|
2219
2351
|
Object {
|
|
@@ -2235,7 +2367,7 @@ describe("paginate", () => {
|
|
|
2235
2367
|
// Forwards
|
|
2236
2368
|
const page1 = yield client.paginate(Union, {}, {
|
|
2237
2369
|
KeyConditionExpression: "PK = :pk",
|
|
2238
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2370
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2239
2371
|
});
|
|
2240
2372
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
2241
2373
|
Object {
|
|
@@ -2250,7 +2382,7 @@ describe("paginate", () => {
|
|
|
2250
2382
|
expect(page1.edges[19].node.SK).toBe("019");
|
|
2251
2383
|
const page2 = yield client.paginate(Union, { after: page1.pageInfo.endCursor }, {
|
|
2252
2384
|
KeyConditionExpression: "PK = :pk",
|
|
2253
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2385
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2254
2386
|
});
|
|
2255
2387
|
expect(page2.pageInfo).toMatchInlineSnapshot(`
|
|
2256
2388
|
Object {
|
|
@@ -2265,7 +2397,7 @@ describe("paginate", () => {
|
|
|
2265
2397
|
expect(page2.edges[19].node.SK).toBe("039");
|
|
2266
2398
|
const page3 = yield client.paginate(Union, { after: page2.pageInfo.endCursor }, {
|
|
2267
2399
|
KeyConditionExpression: "PK = :pk",
|
|
2268
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2400
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2269
2401
|
});
|
|
2270
2402
|
expect(page3.pageInfo).toMatchInlineSnapshot(`
|
|
2271
2403
|
Object {
|
|
@@ -2281,7 +2413,7 @@ describe("paginate", () => {
|
|
|
2281
2413
|
// Backwards
|
|
2282
2414
|
const backwardsPage2 = yield client.paginate(Union, { before: page3.pageInfo.startCursor }, {
|
|
2283
2415
|
KeyConditionExpression: "PK = :pk",
|
|
2284
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2416
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2285
2417
|
});
|
|
2286
2418
|
expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
|
|
2287
2419
|
Object {
|
|
@@ -2296,7 +2428,7 @@ describe("paginate", () => {
|
|
|
2296
2428
|
expect(backwardsPage2.edges[19].node.SK).toBe("039");
|
|
2297
2429
|
const backwardsPage1 = yield client.paginate(Union, { before: backwardsPage2.pageInfo.startCursor }, {
|
|
2298
2430
|
KeyConditionExpression: "PK = :pk",
|
|
2299
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2431
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2300
2432
|
});
|
|
2301
2433
|
expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
|
|
2302
2434
|
Object {
|
|
@@ -2316,7 +2448,7 @@ describe("paginate", () => {
|
|
|
2316
2448
|
// Forwards
|
|
2317
2449
|
const page = yield client.paginate(C, { first: 10 }, {
|
|
2318
2450
|
KeyConditionExpression: "PK = :pk",
|
|
2319
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2451
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2320
2452
|
});
|
|
2321
2453
|
expect(page.pageInfo).toMatchInlineSnapshot(`
|
|
2322
2454
|
Object {
|
|
@@ -2336,7 +2468,7 @@ describe("paginate", () => {
|
|
|
2336
2468
|
// Forwards
|
|
2337
2469
|
const page1 = yield client.paginate(C, { first: 60 }, {
|
|
2338
2470
|
KeyConditionExpression: "PK = :pk",
|
|
2339
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2471
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2340
2472
|
});
|
|
2341
2473
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
2342
2474
|
Object {
|
|
@@ -2352,26 +2484,26 @@ describe("paginate", () => {
|
|
|
2352
2484
|
}));
|
|
2353
2485
|
test("it respects custom pagination default", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
2354
2486
|
client.paginationOptions = {
|
|
2355
|
-
default: 40
|
|
2487
|
+
default: 40,
|
|
2356
2488
|
};
|
|
2357
2489
|
const items = Array.from({ length: 50 }).map((_, i) => new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) }));
|
|
2358
2490
|
yield sandbox.seed(...items);
|
|
2359
2491
|
const page = yield client.paginate(C, {}, {
|
|
2360
2492
|
KeyConditionExpression: "PK = :pk",
|
|
2361
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2493
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2362
2494
|
});
|
|
2363
2495
|
expect(page.edges.length).toBe(40);
|
|
2364
2496
|
delete client.paginationOptions;
|
|
2365
2497
|
}));
|
|
2366
2498
|
test("it respects custom pagination limit", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
2367
2499
|
client.paginationOptions = {
|
|
2368
|
-
limit: 100
|
|
2500
|
+
limit: 100,
|
|
2369
2501
|
};
|
|
2370
2502
|
const items = Array.from({ length: 120 }).map((_, i) => new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) }));
|
|
2371
2503
|
yield sandbox.seed(...items);
|
|
2372
2504
|
const page = yield client.paginate(C, { first: 110 }, {
|
|
2373
2505
|
KeyConditionExpression: "PK = :pk",
|
|
2374
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2506
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2375
2507
|
});
|
|
2376
2508
|
expect(page.edges.length).toBe(100);
|
|
2377
2509
|
delete client.paginationOptions;
|
|
@@ -2384,7 +2516,7 @@ describe("paginate", () => {
|
|
|
2384
2516
|
// Forwards
|
|
2385
2517
|
const page1 = yield C.paginate({}, {
|
|
2386
2518
|
KeyConditionExpression: "PK = :pk",
|
|
2387
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2519
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2388
2520
|
});
|
|
2389
2521
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
2390
2522
|
Object {
|
|
@@ -2399,7 +2531,7 @@ describe("paginate", () => {
|
|
|
2399
2531
|
expect(page1.edges[19].node.c).toBe("19");
|
|
2400
2532
|
const page2 = yield C.paginate({ after: page1.pageInfo.endCursor }, {
|
|
2401
2533
|
KeyConditionExpression: "PK = :pk",
|
|
2402
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2534
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2403
2535
|
});
|
|
2404
2536
|
expect(page2.pageInfo).toMatchInlineSnapshot(`
|
|
2405
2537
|
Object {
|
|
@@ -2414,7 +2546,7 @@ describe("paginate", () => {
|
|
|
2414
2546
|
expect(page2.edges[19].node.c).toBe("39");
|
|
2415
2547
|
const page3 = yield C.paginate({ after: page2.pageInfo.endCursor }, {
|
|
2416
2548
|
KeyConditionExpression: "PK = :pk",
|
|
2417
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2549
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2418
2550
|
});
|
|
2419
2551
|
expect(page3.pageInfo).toMatchInlineSnapshot(`
|
|
2420
2552
|
Object {
|
|
@@ -2430,7 +2562,7 @@ describe("paginate", () => {
|
|
|
2430
2562
|
// Backwards
|
|
2431
2563
|
const backwardsPage2 = yield C.paginate({ before: page3.pageInfo.startCursor }, {
|
|
2432
2564
|
KeyConditionExpression: "PK = :pk",
|
|
2433
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2565
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2434
2566
|
});
|
|
2435
2567
|
expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
|
|
2436
2568
|
Object {
|
|
@@ -2445,7 +2577,7 @@ describe("paginate", () => {
|
|
|
2445
2577
|
expect(backwardsPage2.edges[19].node.c).toBe("39");
|
|
2446
2578
|
const backwardsPage1 = yield C.paginate({ before: backwardsPage2.pageInfo.startCursor }, {
|
|
2447
2579
|
KeyConditionExpression: "PK = :pk",
|
|
2448
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2580
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2449
2581
|
});
|
|
2450
2582
|
expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
|
|
2451
2583
|
Object {
|
|
@@ -2465,7 +2597,7 @@ describe("paginate", () => {
|
|
|
2465
2597
|
// Forwards
|
|
2466
2598
|
const page = yield C.paginate({ first: 10 }, {
|
|
2467
2599
|
KeyConditionExpression: "PK = :pk",
|
|
2468
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2600
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2469
2601
|
});
|
|
2470
2602
|
expect(page.pageInfo).toMatchInlineSnapshot(`
|
|
2471
2603
|
Object {
|
|
@@ -2485,7 +2617,7 @@ describe("paginate", () => {
|
|
|
2485
2617
|
// Forwards
|
|
2486
2618
|
const page1 = yield C.paginate({ first: 60 }, {
|
|
2487
2619
|
KeyConditionExpression: "PK = :pk",
|
|
2488
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2620
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2489
2621
|
});
|
|
2490
2622
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
2491
2623
|
Object {
|
|
@@ -2501,26 +2633,26 @@ describe("paginate", () => {
|
|
|
2501
2633
|
}));
|
|
2502
2634
|
test("it respects custom pagination default", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
2503
2635
|
client.paginationOptions = {
|
|
2504
|
-
default: 40
|
|
2636
|
+
default: 40,
|
|
2505
2637
|
};
|
|
2506
2638
|
const items = Array.from({ length: 50 }).map((_, i) => new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) }));
|
|
2507
2639
|
yield sandbox.seed(...items);
|
|
2508
2640
|
const page = yield C.paginate({}, {
|
|
2509
2641
|
KeyConditionExpression: "PK = :pk",
|
|
2510
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2642
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2511
2643
|
});
|
|
2512
2644
|
expect(page.edges.length).toBe(40);
|
|
2513
2645
|
delete client.paginationOptions;
|
|
2514
2646
|
}));
|
|
2515
2647
|
test("it respects custom pagination limit", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
2516
2648
|
client.paginationOptions = {
|
|
2517
|
-
limit: 100
|
|
2649
|
+
limit: 100,
|
|
2518
2650
|
};
|
|
2519
2651
|
const items = Array.from({ length: 120 }).map((_, i) => new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) }));
|
|
2520
2652
|
yield sandbox.seed(...items);
|
|
2521
2653
|
const page = yield C.paginate({ first: 110 }, {
|
|
2522
2654
|
KeyConditionExpression: "PK = :pk",
|
|
2523
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2655
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2524
2656
|
});
|
|
2525
2657
|
expect(page.edges.length).toBe(100);
|
|
2526
2658
|
delete client.paginationOptions;
|
|
@@ -2535,7 +2667,7 @@ describe("paginate", () => {
|
|
|
2535
2667
|
// Forwards
|
|
2536
2668
|
const page1 = yield Union.paginate({}, {
|
|
2537
2669
|
KeyConditionExpression: "PK = :pk",
|
|
2538
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2670
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2539
2671
|
});
|
|
2540
2672
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
2541
2673
|
Object {
|
|
@@ -2550,7 +2682,7 @@ describe("paginate", () => {
|
|
|
2550
2682
|
expect(page1.edges[19].node.SK).toBe("019");
|
|
2551
2683
|
const page2 = yield Union.paginate({ after: page1.pageInfo.endCursor }, {
|
|
2552
2684
|
KeyConditionExpression: "PK = :pk",
|
|
2553
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2685
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2554
2686
|
});
|
|
2555
2687
|
expect(page2.pageInfo).toMatchInlineSnapshot(`
|
|
2556
2688
|
Object {
|
|
@@ -2565,7 +2697,7 @@ describe("paginate", () => {
|
|
|
2565
2697
|
expect(page2.edges[19].node.SK).toBe("039");
|
|
2566
2698
|
const page3 = yield Union.paginate({ after: page2.pageInfo.endCursor }, {
|
|
2567
2699
|
KeyConditionExpression: "PK = :pk",
|
|
2568
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2700
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2569
2701
|
});
|
|
2570
2702
|
expect(page3.pageInfo).toMatchInlineSnapshot(`
|
|
2571
2703
|
Object {
|
|
@@ -2581,7 +2713,7 @@ describe("paginate", () => {
|
|
|
2581
2713
|
// Backwards
|
|
2582
2714
|
const backwardsPage2 = yield Union.paginate({ before: page3.pageInfo.startCursor }, {
|
|
2583
2715
|
KeyConditionExpression: "PK = :pk",
|
|
2584
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2716
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2585
2717
|
});
|
|
2586
2718
|
expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
|
|
2587
2719
|
Object {
|
|
@@ -2596,7 +2728,7 @@ describe("paginate", () => {
|
|
|
2596
2728
|
expect(backwardsPage2.edges[19].node.SK).toBe("039");
|
|
2597
2729
|
const backwardsPage1 = yield Union.paginate({ before: backwardsPage2.pageInfo.startCursor }, {
|
|
2598
2730
|
KeyConditionExpression: "PK = :pk",
|
|
2599
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2731
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2600
2732
|
});
|
|
2601
2733
|
expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
|
|
2602
2734
|
Object {
|
|
@@ -2618,7 +2750,7 @@ describe("paginate", () => {
|
|
|
2618
2750
|
// Forwards
|
|
2619
2751
|
const page = yield Union.paginate({ first: 10 }, {
|
|
2620
2752
|
KeyConditionExpression: "PK = :pk",
|
|
2621
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2753
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2622
2754
|
});
|
|
2623
2755
|
expect(page.pageInfo).toMatchInlineSnapshot(`
|
|
2624
2756
|
Object {
|
|
@@ -2640,7 +2772,7 @@ describe("paginate", () => {
|
|
|
2640
2772
|
// Forwards
|
|
2641
2773
|
const page1 = yield Union.paginate({ first: 60 }, {
|
|
2642
2774
|
KeyConditionExpression: "PK = :pk",
|
|
2643
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2775
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2644
2776
|
});
|
|
2645
2777
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
2646
2778
|
Object {
|
|
@@ -2656,46 +2788,46 @@ describe("paginate", () => {
|
|
|
2656
2788
|
}));
|
|
2657
2789
|
test("it respects custom pagination default", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
2658
2790
|
client.paginationOptions = {
|
|
2659
|
-
default: 40
|
|
2791
|
+
default: 40,
|
|
2660
2792
|
};
|
|
2661
2793
|
const items = Array.from({ length: 50 }).map((_, i) => i > 30
|
|
2662
2794
|
? new C({
|
|
2663
2795
|
pk: "PK",
|
|
2664
2796
|
sk: String(i).padStart(3, "0"),
|
|
2665
|
-
c: String(i)
|
|
2797
|
+
c: String(i),
|
|
2666
2798
|
})
|
|
2667
2799
|
: new D({
|
|
2668
2800
|
pk: "PK",
|
|
2669
2801
|
sk: String(i).padStart(3, "0"),
|
|
2670
|
-
d: String(i)
|
|
2802
|
+
d: String(i),
|
|
2671
2803
|
}));
|
|
2672
2804
|
yield sandbox.seed(...items);
|
|
2673
2805
|
const page = yield Union.paginate({}, {
|
|
2674
2806
|
KeyConditionExpression: "PK = :pk",
|
|
2675
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2807
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2676
2808
|
});
|
|
2677
2809
|
expect(page.edges.length).toBe(40);
|
|
2678
2810
|
delete client.paginationOptions;
|
|
2679
2811
|
}));
|
|
2680
2812
|
test("it respects custom pagination limit", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
2681
2813
|
client.paginationOptions = {
|
|
2682
|
-
limit: 100
|
|
2814
|
+
limit: 100,
|
|
2683
2815
|
};
|
|
2684
2816
|
const items = Array.from({ length: 110 }).map((_, i) => i > 30
|
|
2685
2817
|
? new C({
|
|
2686
2818
|
pk: "PK",
|
|
2687
2819
|
sk: String(i).padStart(3, "0"),
|
|
2688
|
-
c: String(i)
|
|
2820
|
+
c: String(i),
|
|
2689
2821
|
})
|
|
2690
2822
|
: new D({
|
|
2691
2823
|
pk: "PK",
|
|
2692
2824
|
sk: String(i).padStart(3, "0"),
|
|
2693
|
-
d: String(i)
|
|
2825
|
+
d: String(i),
|
|
2694
2826
|
}));
|
|
2695
2827
|
yield sandbox.seed(...items);
|
|
2696
2828
|
const page = yield Union.paginate({ first: 110 }, {
|
|
2697
2829
|
KeyConditionExpression: "PK = :pk",
|
|
2698
|
-
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2830
|
+
ExpressionAttributeValues: { ":pk": "PK" },
|
|
2699
2831
|
});
|
|
2700
2832
|
expect(page.edges.length).toBe(100);
|
|
2701
2833
|
delete client.paginationOptions;
|