@@ -2,13 +2,18 @@ import { Flags } from "@oclif/core";
22
33import { ControlBaseCommand } from "../../../control-base-command.js" ;
44import { formatChannelRuleDetails } from "../../../utils/channel-rule-display.js" ;
5- import { formatSuccess } from "../../../utils/output.js" ;
5+ import {
6+ formatLabel ,
7+ formatSuccess ,
8+ formatWarning ,
9+ } from "../../../utils/output.js" ;
610
711export default class ChannelRulesCreateCommand extends ControlBaseCommand {
812 static description = "Create a channel rule" ;
913
1014 static examples = [
1115 '$ ably apps channel-rules create --name "chat" --persisted' ,
16+ '$ ably apps channel-rules create --name "chat" --mutable-messages' ,
1217 '$ ably apps channel-rules create --name "events" --push-enabled' ,
1318 '$ ably apps channel-rules create --name "notifications" --persisted --push-enabled --app "My App"' ,
1419 '$ ably apps channel-rules create --name "chat" --persisted --json' ,
@@ -55,6 +60,11 @@ export default class ChannelRulesCreateCommand extends ControlBaseCommand {
5560 "Whether to expose the time serial for messages on channels matching this rule" ,
5661 required : false ,
5762 } ) ,
63+ "mutable-messages" : Flags . boolean ( {
64+ description :
65+ "Whether messages on channels matching this rule can be updated or deleted after publishing. Automatically enables message persistence" ,
66+ required : false ,
67+ } ) ,
5868 name : Flags . string ( {
5969 description : "Name of the channel rule" ,
6070 required : true ,
@@ -94,6 +104,22 @@ export default class ChannelRulesCreateCommand extends ControlBaseCommand {
94104
95105 try {
96106 const controlApi = this . createControlApi ( flags ) ;
107+
108+ // When mutableMessages is enabled, persisted must also be enabled
109+ const mutableMessages = flags [ "mutable-messages" ] ;
110+ let persisted = flags . persisted ;
111+
112+ if ( mutableMessages ) {
113+ persisted = true ;
114+ if ( ! this . shouldOutputJson ( flags ) ) {
115+ this . logToStderr (
116+ formatWarning (
117+ "Message persistence is automatically enabled when mutable messages is enabled." ,
118+ ) ,
119+ ) ;
120+ }
121+ }
122+
97123 const namespaceData = {
98124 authenticated : flags . authenticated ,
99125 batchingEnabled : flags [ "batching-enabled" ] ,
@@ -103,8 +129,9 @@ export default class ChannelRulesCreateCommand extends ControlBaseCommand {
103129 conflationInterval : flags [ "conflation-interval" ] ,
104130 conflationKey : flags [ "conflation-key" ] ,
105131 exposeTimeSerial : flags [ "expose-time-serial" ] ,
132+ mutableMessages,
106133 persistLast : flags [ "persist-last" ] ,
107- persisted : flags . persisted ,
134+ persisted,
108135 populateChannelRegistry : flags [ "populate-channel-registry" ] ,
109136 pushEnabled : flags [ "push-enabled" ] ,
110137 tlsOnly : flags [ "tls-only" ] ,
@@ -129,6 +156,7 @@ export default class ChannelRulesCreateCommand extends ControlBaseCommand {
129156 created : new Date ( createdNamespace . created ) . toISOString ( ) ,
130157 exposeTimeSerial : createdNamespace . exposeTimeSerial ,
131158 id : createdNamespace . id ,
159+ mutableMessages : createdNamespace . mutableMessages ,
132160 name : flags . name ,
133161 persistLast : createdNamespace . persistLast ,
134162 persisted : createdNamespace . persisted ,
@@ -142,7 +170,7 @@ export default class ChannelRulesCreateCommand extends ControlBaseCommand {
142170 ) ;
143171 } else {
144172 this . log ( formatSuccess ( "Channel rule created." ) ) ;
145- this . log ( `ID: ${ createdNamespace . id } ` ) ;
173+ this . log ( `${ formatLabel ( "ID" ) } ${ createdNamespace . id } ` ) ;
146174 for ( const line of formatChannelRuleDetails ( createdNamespace , {
147175 formatDate : ( t ) => this . formatDate ( t ) ,
148176 } ) ) {
0 commit comments