@model-ts/dynamodb 2.0.0 → 3.0.1
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 +18 -0
- package/dist/cjs/__test__/client-with-cursor-encryption.test.js +298 -183
- package/dist/cjs/__test__/client-with-cursor-encryption.test.js.map +1 -1
- package/dist/cjs/__test__/client.test.js +101 -0
- package/dist/cjs/__test__/client.test.js.map +1 -1
- package/dist/cjs/__test__/pagination.test.d.ts +1 -0
- package/dist/cjs/__test__/pagination.test.js +241 -0
- package/dist/cjs/__test__/pagination.test.js.map +1 -0
- package/dist/cjs/client.d.ts +6 -1
- package/dist/cjs/client.js +7 -2
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/dynamodb-model.d.ts +33 -8
- package/dist/cjs/gsi.d.ts +4 -0
- package/dist/cjs/gsi.js +24 -0
- package/dist/cjs/gsi.js.map +1 -0
- package/dist/cjs/operations.d.ts +4 -8
- package/dist/cjs/operations.js.map +1 -1
- package/dist/cjs/pagination.d.ts +48 -59
- package/dist/cjs/pagination.js +16 -26
- package/dist/cjs/pagination.js.map +1 -1
- package/dist/cjs/provider.d.ts +135 -17
- package/dist/cjs/provider.js +5 -12
- package/dist/cjs/provider.js.map +1 -1
- package/dist/cjs/sandbox.js +10 -43
- package/dist/cjs/sandbox.js.map +1 -1
- package/dist/esm/__test__/client-with-cursor-encryption.test.js +298 -183
- package/dist/esm/__test__/client-with-cursor-encryption.test.js.map +1 -1
- package/dist/esm/__test__/client.test.js +101 -0
- package/dist/esm/__test__/client.test.js.map +1 -1
- package/dist/esm/__test__/pagination.test.d.ts +1 -0
- package/dist/esm/__test__/pagination.test.js +238 -0
- package/dist/esm/__test__/pagination.test.js.map +1 -0
- package/dist/esm/client.d.ts +6 -1
- package/dist/esm/client.js +7 -2
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/dynamodb-model.d.ts +33 -8
- package/dist/esm/gsi.d.ts +4 -0
- package/dist/esm/gsi.js +21 -0
- package/dist/esm/gsi.js.map +1 -0
- package/dist/esm/operations.d.ts +4 -8
- package/dist/esm/operations.js.map +1 -1
- package/dist/esm/pagination.d.ts +48 -59
- package/dist/esm/pagination.js +17 -26
- package/dist/esm/pagination.js.map +1 -1
- package/dist/esm/provider.d.ts +135 -17
- package/dist/esm/provider.js +5 -12
- package/dist/esm/provider.js.map +1 -1
- package/dist/esm/sandbox.js +10 -43
- package/dist/esm/sandbox.js.map +1 -1
- package/package.json +1 -1
- package/src/__test__/client-with-cursor-encryption.test.ts +365 -183
- package/src/__test__/client.test.ts +168 -0
- package/src/__test__/pagination.test.ts +300 -0
- package/src/client.ts +20 -19
- package/src/dynamodb-model.ts +31 -9
- package/src/gsi.ts +25 -0
- package/src/operations.ts +4 -10
- package/src/pagination.ts +39 -52
- package/src/provider.ts +9 -9
- package/src/sandbox.ts +10 -43
- package/tsconfig.esm.json +14 -4
- package/tsconfig.json +14 -4
|
@@ -67,6 +67,12 @@ class MultiGSI extends model("MultiGSI", SIMPLE_CODEC, provider) {
|
|
|
67
67
|
get GSI5SK() {
|
|
68
68
|
return `GSI5SK#${this.bar}${this.bar}`;
|
|
69
69
|
}
|
|
70
|
+
get GSI19PK() {
|
|
71
|
+
return `GSI19PK#FIXED`;
|
|
72
|
+
}
|
|
73
|
+
get GSI19SK() {
|
|
74
|
+
return `GSI19SK#${this.bar}${this.bar}`;
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
77
|
class A extends model("A", t.type({ pk: t.string, sk: t.string, a: t.number }), provider) {
|
|
72
78
|
get PK() {
|
|
@@ -106,6 +112,9 @@ let sandbox;
|
|
|
106
112
|
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
113
|
sandbox = yield createSandbox(client);
|
|
108
114
|
}));
|
|
115
|
+
afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
yield sandbox.destroy();
|
|
117
|
+
}));
|
|
109
118
|
describe("put", () => {
|
|
110
119
|
describe("via instance", () => {
|
|
111
120
|
test("it inserts a simple model", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -163,6 +172,8 @@ describe("put", () => {
|
|
|
163
172
|
- Object {}
|
|
164
173
|
+ Object {
|
|
165
174
|
+ "PK#yes__SK#42": Object {
|
|
175
|
+
+ "GSI19PK": "GSI19PK#FIXED",
|
|
176
|
+
+ "GSI19SK": "GSI19SK#4242",
|
|
166
177
|
+ "GSI2PK": "GSI2PK#yesyes",
|
|
167
178
|
+ "GSI2SK": "GSI2SK#FIXED",
|
|
168
179
|
+ "GSI3PK": "GSI3PK#FIXED",
|
|
@@ -246,6 +257,8 @@ describe("put", () => {
|
|
|
246
257
|
- Object {}
|
|
247
258
|
+ Object {
|
|
248
259
|
+ "PK#yes__SK#42": Object {
|
|
260
|
+
+ "GSI19PK": "GSI19PK#FIXED",
|
|
261
|
+
+ "GSI19SK": "GSI19SK#4242",
|
|
249
262
|
+ "GSI2PK": "GSI2PK#yesyes",
|
|
250
263
|
+ "GSI2SK": "GSI2SK#FIXED",
|
|
251
264
|
+ "GSI3PK": "GSI3PK#FIXED",
|
|
@@ -434,9 +447,11 @@ describe("softDelete", () => {
|
|
|
434
447
|
- First value
|
|
435
448
|
+ Second value
|
|
436
449
|
|
|
437
|
-
@@ -1,
|
|
450
|
+
@@ -1,27 +1,29 @@
|
|
438
451
|
Object {
|
|
439
452
|
- "PK#hello__SK#42": Object {
|
|
453
|
+
- "GSI19PK": "GSI19PK#FIXED",
|
|
454
|
+
- "GSI19SK": "GSI19SK#4242",
|
|
440
455
|
- "GSI2PK": "GSI2PK#hellohello",
|
|
441
456
|
- "GSI2SK": "GSI2SK#FIXED",
|
|
442
457
|
- "GSI3PK": "GSI3PK#FIXED",
|
|
@@ -448,6 +463,8 @@ describe("softDelete", () => {
|
|
|
448
463
|
- "PK": "PK#hello",
|
|
449
464
|
- "SK": "SK#42",
|
|
450
465
|
+ "$$DELETED$$PK#hello__$$DELETED$$SK#42": Object {
|
|
466
|
+
+ "GSI19PK": "$$DELETED$$GSI19PK#FIXED",
|
|
467
|
+
+ "GSI19SK": "$$DELETED$$GSI19SK#4242",
|
|
451
468
|
+ "GSI2PK": "$$DELETED$$GSI2PK#hellohello",
|
|
452
469
|
+ "GSI2SK": "$$DELETED$$GSI2SK#FIXED",
|
|
453
470
|
+ "GSI3PK": "$$DELETED$$GSI3PK#FIXED",
|
|
@@ -1457,13 +1474,13 @@ describe("paginate", () => {
|
|
|
1457
1474
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1458
1475
|
});
|
|
1459
1476
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
1460
|
-
Object {
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
}
|
|
1466
|
-
`);
|
|
1477
|
+
Object {
|
|
1478
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
|
|
1479
|
+
"hasNextPage": true,
|
|
1480
|
+
"hasPreviousPage": false,
|
|
1481
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1482
|
+
}
|
|
1483
|
+
`);
|
|
1467
1484
|
expect(page1.edges.length).toBe(20);
|
|
1468
1485
|
expect(page1.edges[0].node.c).toBe("0");
|
|
1469
1486
|
expect(page1.edges[19].node.c).toBe("19");
|
|
@@ -1472,13 +1489,13 @@ Object {
|
|
|
1472
1489
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1473
1490
|
});
|
|
1474
1491
|
expect(page2.pageInfo).toMatchInlineSnapshot(`
|
|
1475
|
-
Object {
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
}
|
|
1481
|
-
`);
|
|
1492
|
+
Object {
|
|
1493
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
|
|
1494
|
+
"hasNextPage": true,
|
|
1495
|
+
"hasPreviousPage": false,
|
|
1496
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
|
|
1497
|
+
}
|
|
1498
|
+
`);
|
|
1482
1499
|
expect(page2.edges.length).toBe(20);
|
|
1483
1500
|
expect(page2.edges[0].node.c).toBe("20");
|
|
1484
1501
|
expect(page2.edges[19].node.c).toBe("39");
|
|
@@ -1487,13 +1504,13 @@ Object {
|
|
|
1487
1504
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1488
1505
|
});
|
|
1489
1506
|
expect(page3.pageInfo).toMatchInlineSnapshot(`
|
|
1490
|
-
Object {
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
}
|
|
1496
|
-
`);
|
|
1507
|
+
Object {
|
|
1508
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
|
|
1509
|
+
"hasNextPage": false,
|
|
1510
|
+
"hasPreviousPage": false,
|
|
1511
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
|
|
1512
|
+
}
|
|
1513
|
+
`);
|
|
1497
1514
|
expect(page3.edges.length).toBe(20);
|
|
1498
1515
|
expect(page3.edges[0].node.c).toBe("40");
|
|
1499
1516
|
expect(page3.edges[19].node.c).toBe("59");
|
|
@@ -1503,13 +1520,13 @@ Object {
|
|
|
1503
1520
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1504
1521
|
});
|
|
1505
1522
|
expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
|
|
1506
|
-
Object {
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
}
|
|
1512
|
-
`);
|
|
1523
|
+
Object {
|
|
1524
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
|
|
1525
|
+
"hasNextPage": false,
|
|
1526
|
+
"hasPreviousPage": true,
|
|
1527
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
|
|
1528
|
+
}
|
|
1529
|
+
`);
|
|
1513
1530
|
expect(backwardsPage2.edges.length).toBe(20);
|
|
1514
1531
|
expect(backwardsPage2.edges[0].node.c).toBe("20");
|
|
1515
1532
|
expect(backwardsPage2.edges[19].node.c).toBe("39");
|
|
@@ -1518,13 +1535,13 @@ Object {
|
|
|
1518
1535
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1519
1536
|
});
|
|
1520
1537
|
expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
|
|
1521
|
-
Object {
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
}
|
|
1527
|
-
`);
|
|
1538
|
+
Object {
|
|
1539
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
|
|
1540
|
+
"hasNextPage": false,
|
|
1541
|
+
"hasPreviousPage": false,
|
|
1542
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1543
|
+
}
|
|
1544
|
+
`);
|
|
1528
1545
|
expect(backwardsPage1.edges.length).toBe(20);
|
|
1529
1546
|
expect(backwardsPage1.edges[0].node.c).toBe("0");
|
|
1530
1547
|
expect(backwardsPage1.edges[19].node.c).toBe("19");
|
|
@@ -1540,13 +1557,13 @@ Object {
|
|
|
1540
1557
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1541
1558
|
});
|
|
1542
1559
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
1543
|
-
Object {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
}
|
|
1549
|
-
`);
|
|
1560
|
+
Object {
|
|
1561
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
|
|
1562
|
+
"hasNextPage": true,
|
|
1563
|
+
"hasPreviousPage": false,
|
|
1564
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1565
|
+
}
|
|
1566
|
+
`);
|
|
1550
1567
|
expect(page1.edges.length).toBe(20);
|
|
1551
1568
|
expect(page1.edges[0].node.SK).toBe("000");
|
|
1552
1569
|
expect(page1.edges[19].node.SK).toBe("019");
|
|
@@ -1555,13 +1572,13 @@ Object {
|
|
|
1555
1572
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1556
1573
|
});
|
|
1557
1574
|
expect(page2.pageInfo).toMatchInlineSnapshot(`
|
|
1558
|
-
Object {
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
}
|
|
1564
|
-
`);
|
|
1575
|
+
Object {
|
|
1576
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
|
|
1577
|
+
"hasNextPage": true,
|
|
1578
|
+
"hasPreviousPage": false,
|
|
1579
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
|
|
1580
|
+
}
|
|
1581
|
+
`);
|
|
1565
1582
|
expect(page2.edges.length).toBe(20);
|
|
1566
1583
|
expect(page2.edges[0].node.SK).toBe("020");
|
|
1567
1584
|
expect(page2.edges[19].node.SK).toBe("039");
|
|
@@ -1570,13 +1587,13 @@ Object {
|
|
|
1570
1587
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1571
1588
|
});
|
|
1572
1589
|
expect(page3.pageInfo).toMatchInlineSnapshot(`
|
|
1573
|
-
Object {
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
}
|
|
1579
|
-
`);
|
|
1590
|
+
Object {
|
|
1591
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
|
|
1592
|
+
"hasNextPage": false,
|
|
1593
|
+
"hasPreviousPage": false,
|
|
1594
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
|
|
1595
|
+
}
|
|
1596
|
+
`);
|
|
1580
1597
|
expect(page3.edges.length).toBe(20);
|
|
1581
1598
|
expect(page3.edges[0].node.SK).toBe("040");
|
|
1582
1599
|
expect(page3.edges[19].node.SK).toBe("059");
|
|
@@ -1586,13 +1603,13 @@ Object {
|
|
|
1586
1603
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1587
1604
|
});
|
|
1588
1605
|
expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
|
|
1589
|
-
Object {
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
}
|
|
1595
|
-
`);
|
|
1606
|
+
Object {
|
|
1607
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
|
|
1608
|
+
"hasNextPage": false,
|
|
1609
|
+
"hasPreviousPage": true,
|
|
1610
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
|
|
1611
|
+
}
|
|
1612
|
+
`);
|
|
1596
1613
|
expect(backwardsPage2.edges.length).toBe(20);
|
|
1597
1614
|
expect(backwardsPage2.edges[0].node.SK).toBe("020");
|
|
1598
1615
|
expect(backwardsPage2.edges[19].node.SK).toBe("039");
|
|
@@ -1601,13 +1618,13 @@ Object {
|
|
|
1601
1618
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1602
1619
|
});
|
|
1603
1620
|
expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
|
|
1604
|
-
Object {
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
}
|
|
1610
|
-
`);
|
|
1621
|
+
Object {
|
|
1622
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
|
|
1623
|
+
"hasNextPage": false,
|
|
1624
|
+
"hasPreviousPage": false,
|
|
1625
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1626
|
+
}
|
|
1627
|
+
`);
|
|
1611
1628
|
expect(backwardsPage1.edges.length).toBe(20);
|
|
1612
1629
|
expect(backwardsPage1.edges[0].node.SK).toBe("000");
|
|
1613
1630
|
expect(backwardsPage1.edges[19].node.SK).toBe("019");
|
|
@@ -1621,13 +1638,13 @@ Object {
|
|
|
1621
1638
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1622
1639
|
});
|
|
1623
1640
|
expect(page.pageInfo).toMatchInlineSnapshot(`
|
|
1624
|
-
Object {
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
}
|
|
1630
|
-
`);
|
|
1641
|
+
Object {
|
|
1642
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
|
|
1643
|
+
"hasNextPage": true,
|
|
1644
|
+
"hasPreviousPage": false,
|
|
1645
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1646
|
+
}
|
|
1647
|
+
`);
|
|
1631
1648
|
expect(page.edges.length).toBe(10);
|
|
1632
1649
|
expect(page.edges[0].node.c).toBe("0");
|
|
1633
1650
|
expect(page.edges[9].node.c).toBe("9");
|
|
@@ -1641,17 +1658,43 @@ Object {
|
|
|
1641
1658
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1642
1659
|
});
|
|
1643
1660
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
1644
|
-
Object {
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
}
|
|
1650
|
-
`);
|
|
1661
|
+
Object {
|
|
1662
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
|
|
1663
|
+
"hasNextPage": true,
|
|
1664
|
+
"hasPreviousPage": false,
|
|
1665
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1666
|
+
}
|
|
1667
|
+
`);
|
|
1651
1668
|
expect(page1.edges.length).toBe(50);
|
|
1652
1669
|
expect(page1.edges[0].node.c).toBe("0");
|
|
1653
1670
|
expect(page1.edges[49].node.c).toBe("49");
|
|
1654
1671
|
}));
|
|
1672
|
+
test("it respects custom pagination default", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1673
|
+
client.paginationOptions = {
|
|
1674
|
+
default: 40
|
|
1675
|
+
};
|
|
1676
|
+
const items = Array.from({ length: 50 }).map((_, i) => new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) }));
|
|
1677
|
+
yield sandbox.seed(...items);
|
|
1678
|
+
const page = yield client.paginate(C, {}, {
|
|
1679
|
+
KeyConditionExpression: "PK = :pk",
|
|
1680
|
+
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1681
|
+
});
|
|
1682
|
+
expect(page.edges.length).toBe(40);
|
|
1683
|
+
delete client.paginationOptions;
|
|
1684
|
+
}));
|
|
1685
|
+
test("it respects custom pagination limit", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1686
|
+
client.paginationOptions = {
|
|
1687
|
+
limit: 100
|
|
1688
|
+
};
|
|
1689
|
+
const items = Array.from({ length: 120 }).map((_, i) => new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) }));
|
|
1690
|
+
yield sandbox.seed(...items);
|
|
1691
|
+
const page = yield client.paginate(C, { first: 110 }, {
|
|
1692
|
+
KeyConditionExpression: "PK = :pk",
|
|
1693
|
+
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1694
|
+
});
|
|
1695
|
+
expect(page.edges.length).toBe(100);
|
|
1696
|
+
delete client.paginationOptions;
|
|
1697
|
+
}));
|
|
1655
1698
|
});
|
|
1656
1699
|
describe("model", () => {
|
|
1657
1700
|
test("it paginates a regular model", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1663,13 +1706,13 @@ Object {
|
|
|
1663
1706
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1664
1707
|
});
|
|
1665
1708
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
1666
|
-
Object {
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
}
|
|
1672
|
-
`);
|
|
1709
|
+
Object {
|
|
1710
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
|
|
1711
|
+
"hasNextPage": true,
|
|
1712
|
+
"hasPreviousPage": false,
|
|
1713
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1714
|
+
}
|
|
1715
|
+
`);
|
|
1673
1716
|
expect(page1.edges.length).toBe(20);
|
|
1674
1717
|
expect(page1.edges[0].node.c).toBe("0");
|
|
1675
1718
|
expect(page1.edges[19].node.c).toBe("19");
|
|
@@ -1678,13 +1721,13 @@ Object {
|
|
|
1678
1721
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1679
1722
|
});
|
|
1680
1723
|
expect(page2.pageInfo).toMatchInlineSnapshot(`
|
|
1681
|
-
Object {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
}
|
|
1687
|
-
`);
|
|
1724
|
+
Object {
|
|
1725
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
|
|
1726
|
+
"hasNextPage": true,
|
|
1727
|
+
"hasPreviousPage": false,
|
|
1728
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
|
|
1729
|
+
}
|
|
1730
|
+
`);
|
|
1688
1731
|
expect(page2.edges.length).toBe(20);
|
|
1689
1732
|
expect(page2.edges[0].node.c).toBe("20");
|
|
1690
1733
|
expect(page2.edges[19].node.c).toBe("39");
|
|
@@ -1693,13 +1736,13 @@ Object {
|
|
|
1693
1736
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1694
1737
|
});
|
|
1695
1738
|
expect(page3.pageInfo).toMatchInlineSnapshot(`
|
|
1696
|
-
Object {
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
}
|
|
1702
|
-
`);
|
|
1739
|
+
Object {
|
|
1740
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
|
|
1741
|
+
"hasNextPage": false,
|
|
1742
|
+
"hasPreviousPage": false,
|
|
1743
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
|
|
1744
|
+
}
|
|
1745
|
+
`);
|
|
1703
1746
|
expect(page3.edges.length).toBe(20);
|
|
1704
1747
|
expect(page3.edges[0].node.c).toBe("40");
|
|
1705
1748
|
expect(page3.edges[19].node.c).toBe("59");
|
|
@@ -1709,13 +1752,13 @@ Object {
|
|
|
1709
1752
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1710
1753
|
});
|
|
1711
1754
|
expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
|
|
1712
|
-
Object {
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
}
|
|
1718
|
-
`);
|
|
1755
|
+
Object {
|
|
1756
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
|
|
1757
|
+
"hasNextPage": false,
|
|
1758
|
+
"hasPreviousPage": true,
|
|
1759
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
|
|
1760
|
+
}
|
|
1761
|
+
`);
|
|
1719
1762
|
expect(backwardsPage2.edges.length).toBe(20);
|
|
1720
1763
|
expect(backwardsPage2.edges[0].node.c).toBe("20");
|
|
1721
1764
|
expect(backwardsPage2.edges[19].node.c).toBe("39");
|
|
@@ -1724,13 +1767,13 @@ Object {
|
|
|
1724
1767
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1725
1768
|
});
|
|
1726
1769
|
expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
|
|
1727
|
-
Object {
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
}
|
|
1733
|
-
`);
|
|
1770
|
+
Object {
|
|
1771
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
|
|
1772
|
+
"hasNextPage": false,
|
|
1773
|
+
"hasPreviousPage": false,
|
|
1774
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1775
|
+
}
|
|
1776
|
+
`);
|
|
1734
1777
|
expect(backwardsPage1.edges.length).toBe(20);
|
|
1735
1778
|
expect(backwardsPage1.edges[0].node.c).toBe("0");
|
|
1736
1779
|
expect(backwardsPage1.edges[19].node.c).toBe("19");
|
|
@@ -1744,13 +1787,13 @@ Object {
|
|
|
1744
1787
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1745
1788
|
});
|
|
1746
1789
|
expect(page.pageInfo).toMatchInlineSnapshot(`
|
|
1747
|
-
Object {
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
}
|
|
1753
|
-
`);
|
|
1790
|
+
Object {
|
|
1791
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
|
|
1792
|
+
"hasNextPage": true,
|
|
1793
|
+
"hasPreviousPage": false,
|
|
1794
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1795
|
+
}
|
|
1796
|
+
`);
|
|
1754
1797
|
expect(page.edges.length).toBe(10);
|
|
1755
1798
|
expect(page.edges[0].node.c).toBe("0");
|
|
1756
1799
|
expect(page.edges[9].node.c).toBe("9");
|
|
@@ -1764,17 +1807,43 @@ Object {
|
|
|
1764
1807
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1765
1808
|
});
|
|
1766
1809
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
1767
|
-
Object {
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
}
|
|
1773
|
-
`);
|
|
1810
|
+
Object {
|
|
1811
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
|
|
1812
|
+
"hasNextPage": true,
|
|
1813
|
+
"hasPreviousPage": false,
|
|
1814
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1815
|
+
}
|
|
1816
|
+
`);
|
|
1774
1817
|
expect(page1.edges.length).toBe(50);
|
|
1775
1818
|
expect(page1.edges[0].node.c).toBe("0");
|
|
1776
1819
|
expect(page1.edges[49].node.c).toBe("49");
|
|
1777
1820
|
}));
|
|
1821
|
+
test("it respects custom pagination default", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1822
|
+
client.paginationOptions = {
|
|
1823
|
+
default: 40
|
|
1824
|
+
};
|
|
1825
|
+
const items = Array.from({ length: 50 }).map((_, i) => new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) }));
|
|
1826
|
+
yield sandbox.seed(...items);
|
|
1827
|
+
const page = yield C.paginate({}, {
|
|
1828
|
+
KeyConditionExpression: "PK = :pk",
|
|
1829
|
+
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1830
|
+
});
|
|
1831
|
+
expect(page.edges.length).toBe(40);
|
|
1832
|
+
delete client.paginationOptions;
|
|
1833
|
+
}));
|
|
1834
|
+
test("it respects custom pagination limit", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1835
|
+
client.paginationOptions = {
|
|
1836
|
+
limit: 100
|
|
1837
|
+
};
|
|
1838
|
+
const items = Array.from({ length: 120 }).map((_, i) => new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) }));
|
|
1839
|
+
yield sandbox.seed(...items);
|
|
1840
|
+
const page = yield C.paginate({ first: 110 }, {
|
|
1841
|
+
KeyConditionExpression: "PK = :pk",
|
|
1842
|
+
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1843
|
+
});
|
|
1844
|
+
expect(page.edges.length).toBe(100);
|
|
1845
|
+
delete client.paginationOptions;
|
|
1846
|
+
}));
|
|
1778
1847
|
});
|
|
1779
1848
|
describe("union", () => {
|
|
1780
1849
|
test("it paginates a union model", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1788,13 +1857,13 @@ Object {
|
|
|
1788
1857
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1789
1858
|
});
|
|
1790
1859
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
1791
|
-
Object {
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
}
|
|
1797
|
-
`);
|
|
1860
|
+
Object {
|
|
1861
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
|
|
1862
|
+
"hasNextPage": true,
|
|
1863
|
+
"hasPreviousPage": false,
|
|
1864
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1865
|
+
}
|
|
1866
|
+
`);
|
|
1798
1867
|
expect(page1.edges.length).toBe(20);
|
|
1799
1868
|
expect(page1.edges[0].node.SK).toBe("000");
|
|
1800
1869
|
expect(page1.edges[19].node.SK).toBe("019");
|
|
@@ -1803,13 +1872,13 @@ Object {
|
|
|
1803
1872
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1804
1873
|
});
|
|
1805
1874
|
expect(page2.pageInfo).toMatchInlineSnapshot(`
|
|
1806
|
-
Object {
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
}
|
|
1812
|
-
`);
|
|
1875
|
+
Object {
|
|
1876
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
|
|
1877
|
+
"hasNextPage": true,
|
|
1878
|
+
"hasPreviousPage": false,
|
|
1879
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
|
|
1880
|
+
}
|
|
1881
|
+
`);
|
|
1813
1882
|
expect(page2.edges.length).toBe(20);
|
|
1814
1883
|
expect(page2.edges[0].node.SK).toBe("020");
|
|
1815
1884
|
expect(page2.edges[19].node.SK).toBe("039");
|
|
@@ -1818,13 +1887,13 @@ Object {
|
|
|
1818
1887
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1819
1888
|
});
|
|
1820
1889
|
expect(page3.pageInfo).toMatchInlineSnapshot(`
|
|
1821
|
-
Object {
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
}
|
|
1827
|
-
`);
|
|
1890
|
+
Object {
|
|
1891
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
|
|
1892
|
+
"hasNextPage": false,
|
|
1893
|
+
"hasPreviousPage": false,
|
|
1894
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
|
|
1895
|
+
}
|
|
1896
|
+
`);
|
|
1828
1897
|
expect(page3.edges.length).toBe(20);
|
|
1829
1898
|
expect(page3.edges[0].node.SK).toBe("040");
|
|
1830
1899
|
expect(page3.edges[19].node.SK).toBe("059");
|
|
@@ -1834,13 +1903,13 @@ Object {
|
|
|
1834
1903
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1835
1904
|
});
|
|
1836
1905
|
expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
|
|
1837
|
-
Object {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
}
|
|
1843
|
-
`);
|
|
1906
|
+
Object {
|
|
1907
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
|
|
1908
|
+
"hasNextPage": false,
|
|
1909
|
+
"hasPreviousPage": true,
|
|
1910
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
|
|
1911
|
+
}
|
|
1912
|
+
`);
|
|
1844
1913
|
expect(backwardsPage2.edges.length).toBe(20);
|
|
1845
1914
|
expect(backwardsPage2.edges[0].node.SK).toBe("020");
|
|
1846
1915
|
expect(backwardsPage2.edges[19].node.SK).toBe("039");
|
|
@@ -1849,13 +1918,13 @@ Object {
|
|
|
1849
1918
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1850
1919
|
});
|
|
1851
1920
|
expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
|
|
1852
|
-
Object {
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
}
|
|
1858
|
-
`);
|
|
1921
|
+
Object {
|
|
1922
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
|
|
1923
|
+
"hasNextPage": false,
|
|
1924
|
+
"hasPreviousPage": false,
|
|
1925
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1926
|
+
}
|
|
1927
|
+
`);
|
|
1859
1928
|
expect(backwardsPage1.edges.length).toBe(20);
|
|
1860
1929
|
expect(backwardsPage1.edges[0].node.SK).toBe("000");
|
|
1861
1930
|
expect(backwardsPage1.edges[19].node.SK).toBe("019");
|
|
@@ -1871,13 +1940,13 @@ Object {
|
|
|
1871
1940
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1872
1941
|
});
|
|
1873
1942
|
expect(page.pageInfo).toMatchInlineSnapshot(`
|
|
1874
|
-
Object {
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
}
|
|
1880
|
-
`);
|
|
1943
|
+
Object {
|
|
1944
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
|
|
1945
|
+
"hasNextPage": true,
|
|
1946
|
+
"hasPreviousPage": false,
|
|
1947
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1948
|
+
}
|
|
1949
|
+
`);
|
|
1881
1950
|
expect(page.edges.length).toBe(10);
|
|
1882
1951
|
expect(page.edges[0].node.SK).toBe("000");
|
|
1883
1952
|
expect(page.edges[9].node.SK).toBe("009");
|
|
@@ -1893,17 +1962,63 @@ Object {
|
|
|
1893
1962
|
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1894
1963
|
});
|
|
1895
1964
|
expect(page1.pageInfo).toMatchInlineSnapshot(`
|
|
1896
|
-
Object {
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
}
|
|
1902
|
-
`);
|
|
1965
|
+
Object {
|
|
1966
|
+
"endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
|
|
1967
|
+
"hasNextPage": true,
|
|
1968
|
+
"hasPreviousPage": false,
|
|
1969
|
+
"startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
|
|
1970
|
+
}
|
|
1971
|
+
`);
|
|
1903
1972
|
expect(page1.edges.length).toBe(50);
|
|
1904
1973
|
expect(page1.edges[0].node.SK).toBe("000");
|
|
1905
1974
|
expect(page1.edges[49].node.SK).toBe("049");
|
|
1906
1975
|
}));
|
|
1976
|
+
test("it respects custom pagination default", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1977
|
+
client.paginationOptions = {
|
|
1978
|
+
default: 40
|
|
1979
|
+
};
|
|
1980
|
+
const items = Array.from({ length: 50 }).map((_, i) => i > 30
|
|
1981
|
+
? new C({
|
|
1982
|
+
pk: "PK",
|
|
1983
|
+
sk: String(i).padStart(3, "0"),
|
|
1984
|
+
c: String(i)
|
|
1985
|
+
})
|
|
1986
|
+
: new D({
|
|
1987
|
+
pk: "PK",
|
|
1988
|
+
sk: String(i).padStart(3, "0"),
|
|
1989
|
+
d: String(i)
|
|
1990
|
+
}));
|
|
1991
|
+
yield sandbox.seed(...items);
|
|
1992
|
+
const page = yield Union.paginate({}, {
|
|
1993
|
+
KeyConditionExpression: "PK = :pk",
|
|
1994
|
+
ExpressionAttributeValues: { ":pk": "PK" }
|
|
1995
|
+
});
|
|
1996
|
+
expect(page.edges.length).toBe(40);
|
|
1997
|
+
delete client.paginationOptions;
|
|
1998
|
+
}));
|
|
1999
|
+
test("it respects custom pagination limit", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
2000
|
+
client.paginationOptions = {
|
|
2001
|
+
limit: 100
|
|
2002
|
+
};
|
|
2003
|
+
const items = Array.from({ length: 110 }).map((_, i) => i > 30
|
|
2004
|
+
? new C({
|
|
2005
|
+
pk: "PK",
|
|
2006
|
+
sk: String(i).padStart(3, "0"),
|
|
2007
|
+
c: String(i)
|
|
2008
|
+
})
|
|
2009
|
+
: new D({
|
|
2010
|
+
pk: "PK",
|
|
2011
|
+
sk: String(i).padStart(3, "0"),
|
|
2012
|
+
d: String(i)
|
|
2013
|
+
}));
|
|
2014
|
+
yield sandbox.seed(...items);
|
|
2015
|
+
const page = yield Union.paginate({ first: 110 }, {
|
|
2016
|
+
KeyConditionExpression: "PK = :pk",
|
|
2017
|
+
ExpressionAttributeValues: { ":pk": "PK" }
|
|
2018
|
+
});
|
|
2019
|
+
expect(page.edges.length).toBe(100);
|
|
2020
|
+
delete client.paginationOptions;
|
|
2021
|
+
}));
|
|
1907
2022
|
});
|
|
1908
2023
|
});
|
|
1909
2024
|
//# sourceMappingURL=client-with-cursor-encryption.test.js.map
|