@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
|
@@ -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,
|
|
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
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
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
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
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
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
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
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
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
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
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
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
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
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
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
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
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
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
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
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
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
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
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
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
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
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
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
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
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
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
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
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
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
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
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
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
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
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
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
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
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
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
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
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
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
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
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
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
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
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
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
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
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
|
})
|