@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
@@ -81,6 +81,12 @@ class MultiGSI extends model("MultiGSI", SIMPLE_CODEC, provider) {
81
81
  get GSI5SK() {
82
82
  return `GSI5SK#${this.bar}${this.bar}`
83
83
  }
84
+ get GSI19PK() {
85
+ return `GSI19PK#FIXED`
86
+ }
87
+ get GSI19SK() {
88
+ return `GSI19SK#${this.bar}${this.bar}`
89
+ }
84
90
  }
85
91
 
86
92
  class A extends model(
@@ -140,6 +146,10 @@ beforeEach(async () => {
140
146
  sandbox = await createSandbox(client)
141
147
  })
142
148
 
149
+ afterEach(async () => {
150
+ await sandbox.destroy()
151
+ })
152
+
143
153
  describe("put", () => {
144
154
  describe("via instance", () => {
145
155
  test("it inserts a simple model", async () => {
@@ -205,6 +215,8 @@ describe("put", () => {
205
215
  - Object {}
206
216
  + Object {
207
217
  + "PK#yes__SK#42": Object {
218
+ + "GSI19PK": "GSI19PK#FIXED",
219
+ + "GSI19SK": "GSI19SK#4242",
208
220
  + "GSI2PK": "GSI2PK#yesyes",
209
221
  + "GSI2SK": "GSI2SK#FIXED",
210
222
  + "GSI3PK": "GSI3PK#FIXED",
@@ -305,6 +317,8 @@ describe("put", () => {
305
317
  - Object {}
306
318
  + Object {
307
319
  + "PK#yes__SK#42": Object {
320
+ + "GSI19PK": "GSI19PK#FIXED",
321
+ + "GSI19SK": "GSI19SK#4242",
308
322
  + "GSI2PK": "GSI2PK#yesyes",
309
323
  + "GSI2SK": "GSI2SK#FIXED",
310
324
  + "GSI3PK": "GSI3PK#FIXED",
@@ -542,9 +556,11 @@ describe("softDelete", () => {
542
556
  - First value
543
557
  + Second value
544
558
 
545
- @@ -1,25 +1,27 @@
559
+ @@ -1,27 +1,29 @@
546
560
  Object {
547
561
  - "PK#hello__SK#42": Object {
562
+ - "GSI19PK": "GSI19PK#FIXED",
563
+ - "GSI19SK": "GSI19SK#4242",
548
564
  - "GSI2PK": "GSI2PK#hellohello",
549
565
  - "GSI2SK": "GSI2SK#FIXED",
550
566
  - "GSI3PK": "GSI3PK#FIXED",
@@ -556,6 +572,8 @@ describe("softDelete", () => {
556
572
  - "PK": "PK#hello",
557
573
  - "SK": "SK#42",
558
574
  + "$$DELETED$$PK#hello__$$DELETED$$SK#42": Object {
575
+ + "GSI19PK": "$$DELETED$$GSI19PK#FIXED",
576
+ + "GSI19SK": "$$DELETED$$GSI19SK#4242",
559
577
  + "GSI2PK": "$$DELETED$$GSI2PK#hellohello",
560
578
  + "GSI2SK": "$$DELETED$$GSI2SK#FIXED",
561
579
  + "GSI3PK": "$$DELETED$$GSI3PK#FIXED",
@@ -1842,13 +1860,13 @@ describe("paginate", () => {
1842
1860
  }
1843
1861
  )
1844
1862
  expect(page1.pageInfo).toMatchInlineSnapshot(`
1845
- Object {
1846
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1847
- "hasNextPage": true,
1848
- "hasPreviousPage": false,
1849
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
1850
- }
1851
- `)
1863
+ Object {
1864
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1865
+ "hasNextPage": true,
1866
+ "hasPreviousPage": false,
1867
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
1868
+ }
1869
+ `)
1852
1870
  expect(page1.edges.length).toBe(20)
1853
1871
  expect(page1.edges[0].node.c).toBe("0")
1854
1872
  expect(page1.edges[19].node.c).toBe("19")
@@ -1862,13 +1880,13 @@ Object {
1862
1880
  }
1863
1881
  )
1864
1882
  expect(page2.pageInfo).toMatchInlineSnapshot(`
1865
- Object {
1866
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1867
- "hasNextPage": true,
1868
- "hasPreviousPage": false,
1869
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
1870
- }
1871
- `)
1883
+ Object {
1884
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1885
+ "hasNextPage": true,
1886
+ "hasPreviousPage": false,
1887
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
1888
+ }
1889
+ `)
1872
1890
  expect(page2.edges.length).toBe(20)
1873
1891
  expect(page2.edges[0].node.c).toBe("20")
1874
1892
  expect(page2.edges[19].node.c).toBe("39")
@@ -1882,13 +1900,13 @@ Object {
1882
1900
  }
1883
1901
  )
1884
1902
  expect(page3.pageInfo).toMatchInlineSnapshot(`
1885
- Object {
1886
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
1887
- "hasNextPage": false,
1888
- "hasPreviousPage": false,
1889
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
1890
- }
1891
- `)
1903
+ Object {
1904
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
1905
+ "hasNextPage": false,
1906
+ "hasPreviousPage": false,
1907
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
1908
+ }
1909
+ `)
1892
1910
  expect(page3.edges.length).toBe(20)
1893
1911
  expect(page3.edges[0].node.c).toBe("40")
1894
1912
  expect(page3.edges[19].node.c).toBe("59")
@@ -1903,13 +1921,13 @@ Object {
1903
1921
  }
1904
1922
  )
1905
1923
  expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
1906
- Object {
1907
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1908
- "hasNextPage": false,
1909
- "hasPreviousPage": true,
1910
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
1911
- }
1912
- `)
1924
+ Object {
1925
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1926
+ "hasNextPage": false,
1927
+ "hasPreviousPage": true,
1928
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
1929
+ }
1930
+ `)
1913
1931
  expect(backwardsPage2.edges.length).toBe(20)
1914
1932
  expect(backwardsPage2.edges[0].node.c).toBe("20")
1915
1933
  expect(backwardsPage2.edges[19].node.c).toBe("39")
@@ -1923,13 +1941,13 @@ Object {
1923
1941
  }
1924
1942
  )
1925
1943
  expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
1926
- Object {
1927
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1928
- "hasNextPage": false,
1929
- "hasPreviousPage": false,
1930
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
1931
- }
1932
- `)
1944
+ Object {
1945
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1946
+ "hasNextPage": false,
1947
+ "hasPreviousPage": false,
1948
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
1949
+ }
1950
+ `)
1933
1951
  expect(backwardsPage1.edges.length).toBe(20)
1934
1952
  expect(backwardsPage1.edges[0].node.c).toBe("0")
1935
1953
  expect(backwardsPage1.edges[19].node.c).toBe("19")
@@ -1954,13 +1972,13 @@ Object {
1954
1972
  }
1955
1973
  )
1956
1974
  expect(page1.pageInfo).toMatchInlineSnapshot(`
1957
- Object {
1958
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1959
- "hasNextPage": true,
1960
- "hasPreviousPage": false,
1961
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
1962
- }
1963
- `)
1975
+ Object {
1976
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
1977
+ "hasNextPage": true,
1978
+ "hasPreviousPage": false,
1979
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
1980
+ }
1981
+ `)
1964
1982
  expect(page1.edges.length).toBe(20)
1965
1983
  expect(page1.edges[0].node.SK).toBe("000")
1966
1984
  expect(page1.edges[19].node.SK).toBe("019")
@@ -1974,13 +1992,13 @@ Object {
1974
1992
  }
1975
1993
  )
1976
1994
  expect(page2.pageInfo).toMatchInlineSnapshot(`
1977
- Object {
1978
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1979
- "hasNextPage": true,
1980
- "hasPreviousPage": false,
1981
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
1982
- }
1983
- `)
1995
+ Object {
1996
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
1997
+ "hasNextPage": true,
1998
+ "hasPreviousPage": false,
1999
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2000
+ }
2001
+ `)
1984
2002
  expect(page2.edges.length).toBe(20)
1985
2003
  expect(page2.edges[0].node.SK).toBe("020")
1986
2004
  expect(page2.edges[19].node.SK).toBe("039")
@@ -1994,13 +2012,13 @@ Object {
1994
2012
  }
1995
2013
  )
1996
2014
  expect(page3.pageInfo).toMatchInlineSnapshot(`
1997
- Object {
1998
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
1999
- "hasNextPage": false,
2000
- "hasPreviousPage": false,
2001
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
2002
- }
2003
- `)
2015
+ Object {
2016
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
2017
+ "hasNextPage": false,
2018
+ "hasPreviousPage": false,
2019
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
2020
+ }
2021
+ `)
2004
2022
  expect(page3.edges.length).toBe(20)
2005
2023
  expect(page3.edges[0].node.SK).toBe("040")
2006
2024
  expect(page3.edges[19].node.SK).toBe("059")
@@ -2015,13 +2033,13 @@ Object {
2015
2033
  }
2016
2034
  )
2017
2035
  expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
2018
- Object {
2019
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2020
- "hasNextPage": false,
2021
- "hasPreviousPage": true,
2022
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2023
- }
2024
- `)
2036
+ Object {
2037
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2038
+ "hasNextPage": false,
2039
+ "hasPreviousPage": true,
2040
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2041
+ }
2042
+ `)
2025
2043
  expect(backwardsPage2.edges.length).toBe(20)
2026
2044
  expect(backwardsPage2.edges[0].node.SK).toBe("020")
2027
2045
  expect(backwardsPage2.edges[19].node.SK).toBe("039")
@@ -2035,13 +2053,13 @@ Object {
2035
2053
  }
2036
2054
  )
2037
2055
  expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
2038
- Object {
2039
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2040
- "hasNextPage": false,
2041
- "hasPreviousPage": false,
2042
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2043
- }
2044
- `)
2056
+ Object {
2057
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2058
+ "hasNextPage": false,
2059
+ "hasPreviousPage": false,
2060
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2061
+ }
2062
+ `)
2045
2063
  expect(backwardsPage1.edges.length).toBe(20)
2046
2064
  expect(backwardsPage1.edges[0].node.SK).toBe("000")
2047
2065
  expect(backwardsPage1.edges[19].node.SK).toBe("019")
@@ -2065,13 +2083,13 @@ Object {
2065
2083
  }
2066
2084
  )
2067
2085
  expect(page.pageInfo).toMatchInlineSnapshot(`
2068
- Object {
2069
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
2070
- "hasNextPage": true,
2071
- "hasPreviousPage": false,
2072
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2073
- }
2074
- `)
2086
+ Object {
2087
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
2088
+ "hasNextPage": true,
2089
+ "hasPreviousPage": false,
2090
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2091
+ }
2092
+ `)
2075
2093
  expect(page.edges.length).toBe(10)
2076
2094
  expect(page.edges[0].node.c).toBe("0")
2077
2095
  expect(page.edges[9].node.c).toBe("9")
@@ -2095,17 +2113,67 @@ Object {
2095
2113
  }
2096
2114
  )
2097
2115
  expect(page1.pageInfo).toMatchInlineSnapshot(`
2098
- Object {
2099
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
2100
- "hasNextPage": true,
2101
- "hasPreviousPage": false,
2102
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2103
- }
2104
- `)
2116
+ Object {
2117
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
2118
+ "hasNextPage": true,
2119
+ "hasPreviousPage": false,
2120
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2121
+ }
2122
+ `)
2105
2123
  expect(page1.edges.length).toBe(50)
2106
2124
  expect(page1.edges[0].node.c).toBe("0")
2107
2125
  expect(page1.edges[49].node.c).toBe("49")
2108
2126
  })
2127
+
2128
+ test("it respects custom pagination default", async () => {
2129
+ client.paginationOptions = {
2130
+ default: 40
2131
+ }
2132
+
2133
+ const items = Array.from({ length: 50 }).map(
2134
+ (_, i) =>
2135
+ new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) })
2136
+ )
2137
+
2138
+ await sandbox.seed(...items)
2139
+
2140
+ const page = await client.paginate(
2141
+ C,
2142
+ {},
2143
+ {
2144
+ KeyConditionExpression: "PK = :pk",
2145
+ ExpressionAttributeValues: { ":pk": "PK" }
2146
+ }
2147
+ )
2148
+ expect(page.edges.length).toBe(40)
2149
+
2150
+ delete client.paginationOptions
2151
+ })
2152
+
2153
+ test("it respects custom pagination limit", async () => {
2154
+ client.paginationOptions = {
2155
+ limit: 100
2156
+ }
2157
+
2158
+ const items = Array.from({ length: 120 }).map(
2159
+ (_, i) =>
2160
+ new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) })
2161
+ )
2162
+
2163
+ await sandbox.seed(...items)
2164
+
2165
+ const page = await client.paginate(
2166
+ C,
2167
+ { first: 110 },
2168
+ {
2169
+ KeyConditionExpression: "PK = :pk",
2170
+ ExpressionAttributeValues: { ":pk": "PK" }
2171
+ }
2172
+ )
2173
+ expect(page.edges.length).toBe(100)
2174
+
2175
+ delete client.paginationOptions
2176
+ })
2109
2177
  })
2110
2178
 
2111
2179
  describe("model", () => {
@@ -2126,13 +2194,13 @@ Object {
2126
2194
  }
2127
2195
  )
2128
2196
  expect(page1.pageInfo).toMatchInlineSnapshot(`
2129
- Object {
2130
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2131
- "hasNextPage": true,
2132
- "hasPreviousPage": false,
2133
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2134
- }
2135
- `)
2197
+ Object {
2198
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2199
+ "hasNextPage": true,
2200
+ "hasPreviousPage": false,
2201
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2202
+ }
2203
+ `)
2136
2204
  expect(page1.edges.length).toBe(20)
2137
2205
  expect(page1.edges[0].node.c).toBe("0")
2138
2206
  expect(page1.edges[19].node.c).toBe("19")
@@ -2145,13 +2213,13 @@ Object {
2145
2213
  }
2146
2214
  )
2147
2215
  expect(page2.pageInfo).toMatchInlineSnapshot(`
2148
- Object {
2149
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2150
- "hasNextPage": true,
2151
- "hasPreviousPage": false,
2152
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2153
- }
2154
- `)
2216
+ Object {
2217
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2218
+ "hasNextPage": true,
2219
+ "hasPreviousPage": false,
2220
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2221
+ }
2222
+ `)
2155
2223
  expect(page2.edges.length).toBe(20)
2156
2224
  expect(page2.edges[0].node.c).toBe("20")
2157
2225
  expect(page2.edges[19].node.c).toBe("39")
@@ -2164,13 +2232,13 @@ Object {
2164
2232
  }
2165
2233
  )
2166
2234
  expect(page3.pageInfo).toMatchInlineSnapshot(`
2167
- Object {
2168
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
2169
- "hasNextPage": false,
2170
- "hasPreviousPage": false,
2171
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
2172
- }
2173
- `)
2235
+ Object {
2236
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
2237
+ "hasNextPage": false,
2238
+ "hasPreviousPage": false,
2239
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
2240
+ }
2241
+ `)
2174
2242
  expect(page3.edges.length).toBe(20)
2175
2243
  expect(page3.edges[0].node.c).toBe("40")
2176
2244
  expect(page3.edges[19].node.c).toBe("59")
@@ -2184,13 +2252,13 @@ Object {
2184
2252
  }
2185
2253
  )
2186
2254
  expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
2187
- Object {
2188
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2189
- "hasNextPage": false,
2190
- "hasPreviousPage": true,
2191
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2192
- }
2193
- `)
2255
+ Object {
2256
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2257
+ "hasNextPage": false,
2258
+ "hasPreviousPage": true,
2259
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2260
+ }
2261
+ `)
2194
2262
  expect(backwardsPage2.edges.length).toBe(20)
2195
2263
  expect(backwardsPage2.edges[0].node.c).toBe("20")
2196
2264
  expect(backwardsPage2.edges[19].node.c).toBe("39")
@@ -2203,13 +2271,13 @@ Object {
2203
2271
  }
2204
2272
  )
2205
2273
  expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
2206
- Object {
2207
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2208
- "hasNextPage": false,
2209
- "hasPreviousPage": false,
2210
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2211
- }
2212
- `)
2274
+ Object {
2275
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2276
+ "hasNextPage": false,
2277
+ "hasPreviousPage": false,
2278
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2279
+ }
2280
+ `)
2213
2281
  expect(backwardsPage1.edges.length).toBe(20)
2214
2282
  expect(backwardsPage1.edges[0].node.c).toBe("0")
2215
2283
  expect(backwardsPage1.edges[19].node.c).toBe("19")
@@ -2232,13 +2300,13 @@ Object {
2232
2300
  }
2233
2301
  )
2234
2302
  expect(page.pageInfo).toMatchInlineSnapshot(`
2235
- Object {
2236
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
2237
- "hasNextPage": true,
2238
- "hasPreviousPage": false,
2239
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2240
- }
2241
- `)
2303
+ Object {
2304
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
2305
+ "hasNextPage": true,
2306
+ "hasPreviousPage": false,
2307
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2308
+ }
2309
+ `)
2242
2310
  expect(page.edges.length).toBe(10)
2243
2311
  expect(page.edges[0].node.c).toBe("0")
2244
2312
  expect(page.edges[9].node.c).toBe("9")
@@ -2261,17 +2329,65 @@ Object {
2261
2329
  }
2262
2330
  )
2263
2331
  expect(page1.pageInfo).toMatchInlineSnapshot(`
2264
- Object {
2265
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
2266
- "hasNextPage": true,
2267
- "hasPreviousPage": false,
2268
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2269
- }
2270
- `)
2332
+ Object {
2333
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
2334
+ "hasNextPage": true,
2335
+ "hasPreviousPage": false,
2336
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2337
+ }
2338
+ `)
2271
2339
  expect(page1.edges.length).toBe(50)
2272
2340
  expect(page1.edges[0].node.c).toBe("0")
2273
2341
  expect(page1.edges[49].node.c).toBe("49")
2274
2342
  })
2343
+
2344
+ test("it respects custom pagination default", async () => {
2345
+ client.paginationOptions = {
2346
+ default: 40
2347
+ }
2348
+
2349
+ const items = Array.from({ length: 50 }).map(
2350
+ (_, i) =>
2351
+ new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) })
2352
+ )
2353
+
2354
+ await sandbox.seed(...items)
2355
+
2356
+ const page = await C.paginate(
2357
+ {},
2358
+ {
2359
+ KeyConditionExpression: "PK = :pk",
2360
+ ExpressionAttributeValues: { ":pk": "PK" }
2361
+ }
2362
+ )
2363
+ expect(page.edges.length).toBe(40)
2364
+
2365
+ delete client.paginationOptions
2366
+ })
2367
+
2368
+ test("it respects custom pagination limit", async () => {
2369
+ client.paginationOptions = {
2370
+ limit: 100
2371
+ }
2372
+
2373
+ const items = Array.from({ length: 120 }).map(
2374
+ (_, i) =>
2375
+ new C({ pk: "PK", sk: String(i).padStart(3, "0"), c: String(i) })
2376
+ )
2377
+
2378
+ await sandbox.seed(...items)
2379
+
2380
+ const page = await C.paginate(
2381
+ { first: 110 },
2382
+ {
2383
+ KeyConditionExpression: "PK = :pk",
2384
+ ExpressionAttributeValues: { ":pk": "PK" }
2385
+ }
2386
+ )
2387
+ expect(page.edges.length).toBe(100)
2388
+
2389
+ delete client.paginationOptions
2390
+ })
2275
2391
  })
2276
2392
 
2277
2393
  describe("union", () => {
@@ -2293,13 +2409,13 @@ Object {
2293
2409
  }
2294
2410
  )
2295
2411
  expect(page1.pageInfo).toMatchInlineSnapshot(`
2296
- Object {
2297
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2298
- "hasNextPage": true,
2299
- "hasPreviousPage": false,
2300
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2301
- }
2302
- `)
2412
+ Object {
2413
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2414
+ "hasNextPage": true,
2415
+ "hasPreviousPage": false,
2416
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2417
+ }
2418
+ `)
2303
2419
  expect(page1.edges.length).toBe(20)
2304
2420
  expect(page1.edges[0].node.SK).toBe("000")
2305
2421
  expect(page1.edges[19].node.SK).toBe("019")
@@ -2312,13 +2428,13 @@ Object {
2312
2428
  }
2313
2429
  )
2314
2430
  expect(page2.pageInfo).toMatchInlineSnapshot(`
2315
- Object {
2316
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2317
- "hasNextPage": true,
2318
- "hasPreviousPage": false,
2319
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2320
- }
2321
- `)
2431
+ Object {
2432
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2433
+ "hasNextPage": true,
2434
+ "hasPreviousPage": false,
2435
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2436
+ }
2437
+ `)
2322
2438
  expect(page2.edges.length).toBe(20)
2323
2439
  expect(page2.edges[0].node.SK).toBe("020")
2324
2440
  expect(page2.edges[19].node.SK).toBe("039")
@@ -2331,13 +2447,13 @@ Object {
2331
2447
  }
2332
2448
  )
2333
2449
  expect(page3.pageInfo).toMatchInlineSnapshot(`
2334
- Object {
2335
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
2336
- "hasNextPage": false,
2337
- "hasPreviousPage": false,
2338
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
2339
- }
2340
- `)
2450
+ Object {
2451
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoLvfn9aOeA8=",
2452
+ "hasNextPage": false,
2453
+ "hasPreviousPage": false,
2454
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKv1n9aOeA8=",
2455
+ }
2456
+ `)
2341
2457
  expect(page3.edges.length).toBe(20)
2342
2458
  expect(page3.edges[0].node.SK).toBe("040")
2343
2459
  expect(page3.edges[19].node.SK).toBe("059")
@@ -2351,13 +2467,13 @@ Object {
2351
2467
  }
2352
2468
  )
2353
2469
  expect(backwardsPage2.pageInfo).toMatchInlineSnapshot(`
2354
- Object {
2355
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2356
- "hasNextPage": false,
2357
- "hasPreviousPage": true,
2358
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2359
- }
2360
- `)
2470
+ Object {
2471
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo5Xfn9aOeA8=",
2472
+ "hasNextPage": false,
2473
+ "hasPreviousPage": true,
2474
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo4X1n9aOeA8=",
2475
+ }
2476
+ `)
2361
2477
  expect(backwardsPage2.edges.length).toBe(20)
2362
2478
  expect(backwardsPage2.edges[0].node.SK).toBe("020")
2363
2479
  expect(backwardsPage2.edges[19].node.SK).toBe("039")
@@ -2370,13 +2486,13 @@ Object {
2370
2486
  }
2371
2487
  )
2372
2488
  expect(backwardsPage1.pageInfo).toMatchInlineSnapshot(`
2373
- Object {
2374
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2375
- "hasNextPage": false,
2376
- "hasPreviousPage": false,
2377
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2378
- }
2379
- `)
2489
+ Object {
2490
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo7vfn9aOeA8=",
2491
+ "hasNextPage": false,
2492
+ "hasPreviousPage": false,
2493
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2494
+ }
2495
+ `)
2380
2496
  expect(backwardsPage1.edges.length).toBe(20)
2381
2497
  expect(backwardsPage1.edges[0].node.SK).toBe("000")
2382
2498
  expect(backwardsPage1.edges[19].node.SK).toBe("019")
@@ -2400,13 +2516,13 @@ Object {
2400
2516
  }
2401
2517
  )
2402
2518
  expect(page.pageInfo).toMatchInlineSnapshot(`
2403
- Object {
2404
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
2405
- "hasNextPage": true,
2406
- "hasPreviousPage": false,
2407
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2408
- }
2409
- `)
2519
+ Object {
2520
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6vfn9aOeA8=",
2521
+ "hasNextPage": true,
2522
+ "hasPreviousPage": false,
2523
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2524
+ }
2525
+ `)
2410
2526
  expect(page.edges.length).toBe(10)
2411
2527
  expect(page.edges[0].node.SK).toBe("000")
2412
2528
  expect(page.edges[9].node.SK).toBe("009")
@@ -2430,16 +2546,82 @@ Object {
2430
2546
  }
2431
2547
  )
2432
2548
  expect(page1.pageInfo).toMatchInlineSnapshot(`
2433
- Object {
2434
- "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
2435
- "hasNextPage": true,
2436
- "hasPreviousPage": false,
2437
- "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2438
- }
2439
- `)
2549
+ Object {
2550
+ "endCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOoKvfn9aOeA8=",
2551
+ "hasNextPage": true,
2552
+ "hasPreviousPage": false,
2553
+ "startCursor": "cC4wNVXawu0oBvB8vqW4J/RG6hbr3ndOo6v1n9aOeA8=",
2554
+ }
2555
+ `)
2440
2556
  expect(page1.edges.length).toBe(50)
2441
2557
  expect(page1.edges[0].node.SK).toBe("000")
2442
2558
  expect(page1.edges[49].node.SK).toBe("049")
2443
2559
  })
2560
+
2561
+ test("it respects custom pagination default", async () => {
2562
+ client.paginationOptions = {
2563
+ default: 40
2564
+ }
2565
+
2566
+ const items = Array.from({ length: 50 }).map((_, i) =>
2567
+ i > 30
2568
+ ? new C({
2569
+ pk: "PK",
2570
+ sk: String(i).padStart(3, "0"),
2571
+ c: String(i)
2572
+ })
2573
+ : new D({
2574
+ pk: "PK",
2575
+ sk: String(i).padStart(3, "0"),
2576
+ d: String(i)
2577
+ })
2578
+ )
2579
+
2580
+ await sandbox.seed(...items)
2581
+
2582
+ const page = await Union.paginate(
2583
+ {},
2584
+ {
2585
+ KeyConditionExpression: "PK = :pk",
2586
+ ExpressionAttributeValues: { ":pk": "PK" }
2587
+ }
2588
+ )
2589
+ expect(page.edges.length).toBe(40)
2590
+
2591
+ delete client.paginationOptions
2592
+ })
2593
+
2594
+ test("it respects custom pagination limit", async () => {
2595
+ client.paginationOptions = {
2596
+ limit: 100
2597
+ }
2598
+
2599
+ const items = Array.from({ length: 110 }).map((_, i) =>
2600
+ i > 30
2601
+ ? new C({
2602
+ pk: "PK",
2603
+ sk: String(i).padStart(3, "0"),
2604
+ c: String(i)
2605
+ })
2606
+ : new D({
2607
+ pk: "PK",
2608
+ sk: String(i).padStart(3, "0"),
2609
+ d: String(i)
2610
+ })
2611
+ )
2612
+
2613
+ await sandbox.seed(...items)
2614
+
2615
+ const page = await Union.paginate(
2616
+ { first: 110 },
2617
+ {
2618
+ KeyConditionExpression: "PK = :pk",
2619
+ ExpressionAttributeValues: { ":pk": "PK" }
2620
+ }
2621
+ )
2622
+ expect(page.edges.length).toBe(100)
2623
+
2624
+ delete client.paginationOptions
2625
+ })
2444
2626
  })
2445
2627
  })