@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.
Files changed (62) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/__test__/client-with-cursor-encryption.test.js +298 -183
  3. package/dist/cjs/__test__/client-with-cursor-encryption.test.js.map +1 -1
  4. package/dist/cjs/__test__/client.test.js +101 -0
  5. package/dist/cjs/__test__/client.test.js.map +1 -1
  6. package/dist/cjs/__test__/pagination.test.d.ts +1 -0
  7. package/dist/cjs/__test__/pagination.test.js +241 -0
  8. package/dist/cjs/__test__/pagination.test.js.map +1 -0
  9. package/dist/cjs/client.d.ts +6 -1
  10. package/dist/cjs/client.js +7 -2
  11. package/dist/cjs/client.js.map +1 -1
  12. package/dist/cjs/dynamodb-model.d.ts +33 -8
  13. package/dist/cjs/gsi.d.ts +4 -0
  14. package/dist/cjs/gsi.js +24 -0
  15. package/dist/cjs/gsi.js.map +1 -0
  16. package/dist/cjs/operations.d.ts +4 -8
  17. package/dist/cjs/operations.js.map +1 -1
  18. package/dist/cjs/pagination.d.ts +48 -59
  19. package/dist/cjs/pagination.js +16 -26
  20. package/dist/cjs/pagination.js.map +1 -1
  21. package/dist/cjs/provider.d.ts +135 -17
  22. package/dist/cjs/provider.js +5 -12
  23. package/dist/cjs/provider.js.map +1 -1
  24. package/dist/cjs/sandbox.js +10 -43
  25. package/dist/cjs/sandbox.js.map +1 -1
  26. package/dist/esm/__test__/client-with-cursor-encryption.test.js +298 -183
  27. package/dist/esm/__test__/client-with-cursor-encryption.test.js.map +1 -1
  28. package/dist/esm/__test__/client.test.js +101 -0
  29. package/dist/esm/__test__/client.test.js.map +1 -1
  30. package/dist/esm/__test__/pagination.test.d.ts +1 -0
  31. package/dist/esm/__test__/pagination.test.js +238 -0
  32. package/dist/esm/__test__/pagination.test.js.map +1 -0
  33. package/dist/esm/client.d.ts +6 -1
  34. package/dist/esm/client.js +7 -2
  35. package/dist/esm/client.js.map +1 -1
  36. package/dist/esm/dynamodb-model.d.ts +33 -8
  37. package/dist/esm/gsi.d.ts +4 -0
  38. package/dist/esm/gsi.js +21 -0
  39. package/dist/esm/gsi.js.map +1 -0
  40. package/dist/esm/operations.d.ts +4 -8
  41. package/dist/esm/operations.js.map +1 -1
  42. package/dist/esm/pagination.d.ts +48 -59
  43. package/dist/esm/pagination.js +17 -26
  44. package/dist/esm/pagination.js.map +1 -1
  45. package/dist/esm/provider.d.ts +135 -17
  46. package/dist/esm/provider.js +5 -12
  47. package/dist/esm/provider.js.map +1 -1
  48. package/dist/esm/sandbox.js +10 -43
  49. package/dist/esm/sandbox.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/__test__/client-with-cursor-encryption.test.ts +365 -183
  52. package/src/__test__/client.test.ts +168 -0
  53. package/src/__test__/pagination.test.ts +300 -0
  54. package/src/client.ts +20 -19
  55. package/src/dynamodb-model.ts +31 -9
  56. package/src/gsi.ts +25 -0
  57. package/src/operations.ts +4 -10
  58. package/src/pagination.ts +39 -52
  59. package/src/provider.ts +9 -9
  60. package/src/sandbox.ts +10 -43
  61. package/tsconfig.esm.json +14 -4
  62. 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,25 +1,27 @@
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1462
- "hasNextPage": true,
1463
- "hasPreviousPage": false,
1464
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1477
- "hasNextPage": true,
1478
- "hasPreviousPage": false,
1479
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
1492
- "hasNextPage": false,
1493
- "hasPreviousPage": false,
1494
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1508
- "hasNextPage": false,
1509
- "hasPreviousPage": true,
1510
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1523
- "hasNextPage": false,
1524
- "hasPreviousPage": false,
1525
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1545
- "hasNextPage": true,
1546
- "hasPreviousPage": false,
1547
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1560
- "hasNextPage": true,
1561
- "hasPreviousPage": false,
1562
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
1575
- "hasNextPage": false,
1576
- "hasPreviousPage": false,
1577
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1591
- "hasNextPage": false,
1592
- "hasPreviousPage": true,
1593
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1606
- "hasNextPage": false,
1607
- "hasPreviousPage": false,
1608
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
1626
- "hasNextPage": true,
1627
- "hasPreviousPage": false,
1628
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
1646
- "hasNextPage": true,
1647
- "hasPreviousPage": false,
1648
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1668
- "hasNextPage": true,
1669
- "hasPreviousPage": false,
1670
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1683
- "hasNextPage": true,
1684
- "hasPreviousPage": false,
1685
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
1698
- "hasNextPage": false,
1699
- "hasPreviousPage": false,
1700
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1714
- "hasNextPage": false,
1715
- "hasPreviousPage": true,
1716
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1729
- "hasNextPage": false,
1730
- "hasPreviousPage": false,
1731
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
1749
- "hasNextPage": true,
1750
- "hasPreviousPage": false,
1751
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
1769
- "hasNextPage": true,
1770
- "hasPreviousPage": false,
1771
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1793
- "hasNextPage": true,
1794
- "hasPreviousPage": false,
1795
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1808
- "hasNextPage": true,
1809
- "hasPreviousPage": false,
1810
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
1823
- "hasNextPage": false,
1824
- "hasPreviousPage": false,
1825
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1839
- "hasNextPage": false,
1840
- "hasPreviousPage": true,
1841
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1854
- "hasNextPage": false,
1855
- "hasPreviousPage": false,
1856
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
1876
- "hasNextPage": true,
1877
- "hasPreviousPage": false,
1878
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
1898
- "hasNextPage": true,
1899
- "hasPreviousPage": false,
1900
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
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