@@ -1011,6 +1011,7 @@ describe("r2", () => {
10111011 wrangler r2 bucket catalog disable <bucket> Disable the data catalog for an R2 bucket [open-beta]
10121012 wrangler r2 bucket catalog get <bucket> Get the status of the data catalog for an R2 bucket [open-beta]
10131013 wrangler r2 bucket catalog compaction Control settings for automatic file compaction maintenance jobs for your R2 data catalog [open-beta]
1014+ wrangler r2 bucket catalog table Manage table-level maintenance for your R2 data catalog [open-beta]
10141015
10151016 GLOBAL FLAGS
10161017 -c, --config Path to Wrangler configuration file [string]
@@ -1505,6 +1506,194 @@ describe("r2", () => {
15051506 } ) ;
15061507 } ) ;
15071508 } ) ;
1509+
1510+ describe ( "table" , ( ) => {
1511+ describe ( "compaction" , ( ) => {
1512+ const { setIsTTY } = useMockIsTTY ( ) ;
1513+
1514+ it ( "should show the correct help when an invalid command is passed" , async ( ) => {
1515+ await expect ( ( ) =>
1516+ runWrangler ( "r2 bucket catalog table compaction foo" )
1517+ ) . rejects . toThrowErrorMatchingInlineSnapshot (
1518+ `[Error: Unknown argument: foo]`
1519+ ) ;
1520+ expect ( std . err ) . toMatchInlineSnapshot ( `
1521+ "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown argument: foo[0m
1522+
1523+ "
1524+ ` ) ;
1525+ expect ( std . out ) . toMatchInlineSnapshot ( `
1526+ "
1527+ wrangler r2 bucket catalog table compaction
1528+
1529+ Control table-level automatic file compaction for your R2 data catalog [open-beta]
1530+
1531+ COMMANDS
1532+ wrangler r2 bucket catalog table compaction enable <bucket> <namespace> <table> Enable automatic file compaction for a specific R2 data catalog table [open-beta]
1533+ wrangler r2 bucket catalog table compaction disable <bucket> <namespace> <table> Disable automatic file compaction for a specific R2 data catalog table [open-beta]
1534+
1535+ GLOBAL FLAGS
1536+ -c, --config Path to Wrangler configuration file [string]
1537+ --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
1538+ -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
1539+ --env-file Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files [array]
1540+ -h, --help Show help [boolean]
1541+ -v, --version Show version number [boolean]"
1542+ ` ) ;
1543+ } ) ;
1544+
1545+ describe ( "enable" , ( ) => {
1546+ it ( "should enable table compaction with default target size" , async ( ) => {
1547+ msw . use (
1548+ http . post (
1549+ "*/accounts/some-account-id/r2-catalog/testBucket/namespaces/testNamespace/tables/testTable/maintenance-configs" ,
1550+ async ( { request } ) => {
1551+ const body = await request . json ( ) ;
1552+ expect ( request . method ) . toEqual ( "POST" ) ;
1553+ expect ( body ) . toEqual ( {
1554+ compaction : {
1555+ state : "enabled" ,
1556+ } ,
1557+ } ) ;
1558+ return HttpResponse . json (
1559+ createFetchResult ( { success : true } , true )
1560+ ) ;
1561+ } ,
1562+ { once : true }
1563+ )
1564+ ) ;
1565+ await runWrangler (
1566+ "r2 bucket catalog table compaction enable testBucket testNamespace testTable"
1567+ ) ;
1568+ expect ( std . out ) . toMatchInlineSnapshot (
1569+ `
1570+ "
1571+ ⛅️ wrangler x.x.x
1572+ ──────────────────
1573+ ✨ Successfully enabled file compaction for table 'testNamespace.testTable' in bucket 'testBucket'."
1574+ `
1575+ ) ;
1576+ } ) ;
1577+
1578+ it ( "should enable table compaction with custom target size" , async ( ) => {
1579+ msw . use (
1580+ http . post (
1581+ "*/accounts/some-account-id/r2-catalog/testBucket/namespaces/testNamespace/tables/testTable/maintenance-configs" ,
1582+ async ( { request } ) => {
1583+ const body = await request . json ( ) ;
1584+ expect ( request . method ) . toEqual ( "POST" ) ;
1585+ expect ( body ) . toEqual ( {
1586+ compaction : {
1587+ state : "enabled" ,
1588+ target_size_mb : 256 ,
1589+ } ,
1590+ } ) ;
1591+ return HttpResponse . json (
1592+ createFetchResult ( { success : true } , true )
1593+ ) ;
1594+ } ,
1595+ { once : true }
1596+ )
1597+ ) ;
1598+ await runWrangler (
1599+ "r2 bucket catalog table compaction enable testBucket testNamespace testTable --target-size 256"
1600+ ) ;
1601+ expect ( std . out ) . toMatchInlineSnapshot (
1602+ `
1603+ "
1604+ ⛅️ wrangler x.x.x
1605+ ──────────────────
1606+ ✨ Successfully enabled file compaction for table 'testNamespace.testTable' in bucket 'testBucket'."
1607+ `
1608+ ) ;
1609+ } ) ;
1610+
1611+ it ( "should error if no bucket name is given" , async ( ) => {
1612+ await expect (
1613+ runWrangler ( "r2 bucket catalog table compaction enable" )
1614+ ) . rejects . toThrowErrorMatchingInlineSnapshot (
1615+ `[Error: Not enough non-option arguments: got 0, need at least 3]`
1616+ ) ;
1617+ } ) ;
1618+
1619+ it ( "should error if namespace is missing" , async ( ) => {
1620+ await expect (
1621+ runWrangler (
1622+ "r2 bucket catalog table compaction enable testBucket"
1623+ )
1624+ ) . rejects . toThrowErrorMatchingInlineSnapshot (
1625+ `[Error: Not enough non-option arguments: got 1, need at least 3]`
1626+ ) ;
1627+ } ) ;
1628+
1629+ it ( "should error if table name is missing" , async ( ) => {
1630+ await expect (
1631+ runWrangler (
1632+ "r2 bucket catalog table compaction enable testBucket testNamespace"
1633+ )
1634+ ) . rejects . toThrowErrorMatchingInlineSnapshot (
1635+ `[Error: Not enough non-option arguments: got 2, need at least 3]`
1636+ ) ;
1637+ } ) ;
1638+ } ) ;
1639+
1640+ describe ( "disable" , ( ) => {
1641+ it ( "should disable table compaction when confirmation is accepted" , async ( ) => {
1642+ setIsTTY ( true ) ;
1643+ mockConfirm ( {
1644+ text : "Are you sure you want to disable file compaction for table 'testNamespace.testTable' in bucket 'testBucket'?" ,
1645+ result : true ,
1646+ } ) ;
1647+ msw . use (
1648+ http . post (
1649+ "*/accounts/some-account-id/r2-catalog/testBucket/namespaces/testNamespace/tables/testTable/maintenance-configs" ,
1650+ async ( { request } ) => {
1651+ const body = await request . json ( ) ;
1652+ expect ( request . method ) . toEqual ( "POST" ) ;
1653+ expect ( body ) . toEqual ( {
1654+ compaction : {
1655+ state : "disabled" ,
1656+ } ,
1657+ } ) ;
1658+ return HttpResponse . json (
1659+ createFetchResult ( { success : true } , true )
1660+ ) ;
1661+ } ,
1662+ { once : true }
1663+ )
1664+ ) ;
1665+ await runWrangler (
1666+ "r2 bucket catalog table compaction disable testBucket testNamespace testTable"
1667+ ) ;
1668+ expect ( std . out ) . toMatchInlineSnapshot (
1669+ `
1670+ "
1671+ ⛅️ wrangler x.x.x
1672+ ──────────────────
1673+ Successfully disabled file compaction for table 'testNamespace.testTable' in bucket 'testBucket'."
1674+ `
1675+ ) ;
1676+ } ) ;
1677+
1678+ it ( "should cancel disable when confirmation is rejected" , async ( ) => {
1679+ setIsTTY ( true ) ;
1680+ mockConfirm ( {
1681+ text : "Are you sure you want to disable file compaction for table 'testNamespace.testTable' in bucket 'testBucket'?" ,
1682+ result : false ,
1683+ } ) ;
1684+ await runWrangler (
1685+ "r2 bucket catalog table compaction disable testBucket testNamespace testTable"
1686+ ) ;
1687+ expect ( std . out ) . toMatchInlineSnapshot ( `
1688+ "
1689+ ⛅️ wrangler x.x.x
1690+ ──────────────────
1691+ Disable cancelled."
1692+ ` ) ;
1693+ } ) ;
1694+ } ) ;
1695+ } ) ;
1696+ } ) ;
15081697 } ) ;
15091698
15101699 describe ( "notification" , ( ) => {
0 commit comments