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