diff --git a/ably.d.ts b/ably.d.ts index 8c7a5368b..b6677161e 100644 --- a/ably.d.ts +++ b/ably.d.ts @@ -2428,96 +2428,143 @@ export declare interface RealtimePresence { */ export declare interface RealtimeAnnotations { /** - * Registers a listener that is called each time an {@link Annotation} matching a given type is received on the channel. - * Note that if you want to receive individual realtime annotations (instead of just the rolled-up summaries), you will need to request the annotation_subscribe ChannelMode in ChannelOptions, since they are not delivered by default. In general, most clients will not bother with subscribing to individual annotations, and will instead just look at the summary updates. + * Registers a listener that is called each time an {@link Annotation} matching a given type is received on the channel. Individual annotations are not delivered by default, since most clients can rely on the rolled-up summary updates instead. Receiving individual annotations requires the `annotation_subscribe` channel mode, requested via {@link ChannelOptions.modes}. The server grants the mode only when message annotations are enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token has the `annotation-subscribe` capability; without the rule the attach rejects with an {@link ErrorInfo}, and without the capability the mode is silently not granted. Implicitly attaches the channel unless {@link ChannelOptions.attachOnSubscribe} is `false`. Rejects with an {@link ErrorInfo} if the channel is `failed`, and rejects, deregistering the listener, if the channel is attached without the mode; when {@link ChannelOptions.attachOnSubscribe} is `false` and the channel is not yet attached, the call resolves and a listener missing the mode silently never fires. * * @param type - A specific type string or an array of them to register the listener for. * @param listener - An event listener function. - * @returns A promise which resolves upon success of the channel {@link RealtimeChannel.attach | `attach()`} operation and rejects with an {@link ErrorInfo} object upon its failure. + * @returns A promise which resolves upon success of the channel {@link RealtimeChannel.attach | `attach()`} operation and rejects with an {@link ErrorInfo} object upon its failure. When {@link ChannelOptions.attachOnSubscribe} is `false`, no attach is performed. + * @example + * ```ts + * await channel.annotations.subscribe('emoji:distinct.v1', (annotation) => console.log(annotation.name)); + * ``` + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-subscribe */ subscribe(type: string | Array, listener?: messageCallback): Promise; /** - * Registers a listener that is called each time an {@link Annotation} is received on the channel. - * Note that if you want to receive individual realtime annotations (instead of just the rolled-up summaries), you will need to request the annotation_subscribe ChannelMode in ChannelOptions, since they are not delivered by default. In general, most clients will not bother with subscribing to individual annotations, and will instead just look at the summary updates. + * Registers a listener that is called each time an {@link Annotation} is received on the channel. Individual annotations are not delivered by default, since most clients can rely on the rolled-up summary updates instead. Receiving individual annotations requires the `annotation_subscribe` channel mode, requested via {@link ChannelOptions.modes}. The server grants the mode only when message annotations are enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token has the `annotation-subscribe` capability; without the rule the attach rejects with an {@link ErrorInfo}, and without the capability the mode is silently not granted. Implicitly attaches the channel unless {@link ChannelOptions.attachOnSubscribe} is `false`. Rejects with an {@link ErrorInfo} if the channel is `failed`, and rejects, deregistering the listener, if the channel is attached without the mode; when {@link ChannelOptions.attachOnSubscribe} is `false` and the channel is not yet attached, the call resolves and a listener missing the mode silently never fires. * * @param listener - An event listener function. - * @returns A promise which resolves upon success of the channel {@link RealtimeChannel.attach | `attach()`} operation and rejects with an {@link ErrorInfo} object upon its failure. + * @returns A promise which resolves upon success of the channel {@link RealtimeChannel.attach | `attach()`} operation and rejects with an {@link ErrorInfo} object upon its failure. When {@link ChannelOptions.attachOnSubscribe} is `false`, no attach is performed. + * @example + * ```ts + * await channel.annotations.subscribe((annotation) => console.log(annotation.name)); + * ``` + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-subscribe */ subscribe(listener?: messageCallback): Promise; /** - * Deregisters a specific listener that is registered to receive {@link Annotation} on the channel for a given type. + * Deregisters a specific listener that is registered to receive {@link Annotation} on the channel for a given type. This only removes the local listener; it does not detach the channel, and annotations may continue to arrive for any other registered listeners. * * @param type - A specific annotation type (or array of types) to deregister the listener for. * @param listener - An event listener function. + * @example + * ```ts + * channel.annotations.unsubscribe('emoji:distinct.v1', listener); + * ``` + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-unsubscribe */ unsubscribe(type: string | Array, listener: messageCallback): void; /** - * Deregisters any listener that is registered to receive {@link Annotation} on the channel for a specific type. + * Deregisters any listener that is registered to receive {@link Annotation} on the channel for a specific type. This only removes the local listeners and does not detach the channel. * * @param type - A specific annotation type (or array of types) to deregister the listeners for. + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-unsubscribe */ unsubscribe(type: string | Array): void; /** - * Deregisters a specific listener that is registered to receive {@link Annotation} on the channel. + * Deregisters a specific listener that is registered to receive {@link Annotation} on the channel. This only removes the local listener and does not detach the channel. * * @param listener - An event listener function. + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-unsubscribe */ unsubscribe(listener: messageCallback): void; /** - * Deregisters all listeners currently receiving {@link Annotation} for the channel. + * Deregisters all listeners currently receiving {@link Annotation} for the channel. This only removes the local listeners; it does not detach the channel or change the channel's granted modes. + * + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-unsubscribe */ unsubscribe(): void; /** - * Publish a new annotation for a message. + * Publish a new annotation for a message. If the annotation specifies no `action`, it defaults to `annotation.create`. Annotation data is never encrypted, even when {@link ChannelOptions.cipher} is set, because the server must be able to read it to build summaries. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token must have the `annotation-publish` capability; without these the server rejects the operation and the call rejects with an {@link ErrorInfo}. Does not implicitly attach the channel, but rejects with an {@link ErrorInfo} when the channel is `failed` or `suspended` or when the connection is unusable. Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. * * @param message - The message to annotate. * @param annotation - The annotation to publish. (Must include at least the `type`; * other required fields depend on the annotation type). + * @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure. + * @example + * ```ts + * await channel.annotations.publish(message, { type: 'emoji:distinct.v1', name: '👍' }); + * ``` + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-publish */ publish(message: Message, annotation: OutboundAnnotation): Promise; /** - * Publish a new annotation for a message (alternative form where you only have the - * serial of the message, not a complete Message object) + * Publish a new annotation for a message (alternative form where you only have the serial of the message, not a complete {@link Message} object). If the annotation specifies no `action`, it defaults to `annotation.create`. Annotation data is never encrypted, even when {@link ChannelOptions.cipher} is set, because the server must be able to read it to build summaries. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token must have the `annotation-publish` capability; without these the server rejects the operation and the call rejects with an {@link ErrorInfo}. Does not implicitly attach the channel, but rejects with an {@link ErrorInfo} when the channel is `failed` or `suspended` or when the connection is unusable. Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. * * @param messageSerial - The serial field of the message to annotate. * @param annotation - The annotation to publish. (Must include at least the `type`; * other required fields depend on the annotation type). + * @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure. + * @example + * ```ts + * await channel.annotations.publish(message.serial, { type: 'emoji:distinct.v1', name: '👍' }); + * ``` + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-publish */ publish(messageSerial: string, annotation: OutboundAnnotation): Promise; /** - * Publish an annotation removal request for a message, to remove it from the summary - * summaries. The semantics of the delete (and what fields are required) are different - * for each annotation type; see annotation types documentation for more details. + * Publish an annotation removal request for a message, to remove it from the message's annotation summary. The semantics of the delete (and what fields are required) are different for each annotation type; see annotation types documentation for more details. This is a {@link RealtimeAnnotations.publish | `publish()`} with the `action` set to `annotation.delete`, and it mutates the passed annotation object to carry that action, overwriting any `action` you set. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token must have the `annotation-publish` capability; without these the server rejects the operation and the call rejects with an {@link ErrorInfo}. Does not implicitly attach the channel, but rejects with an {@link ErrorInfo} when the channel is `failed` or `suspended` or when the connection is unusable. Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. * * @param message - The message which has an annotation that you want to delete. * @param annotation - The annotation deletion request. (Must include at least the * `type`, other required fields depend on the type). + * @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure. + * @example + * ```ts + * await channel.annotations.delete(message, { type: 'emoji:distinct.v1', name: '👍' }); + * ``` + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-delete */ delete(message: Message, annotation: OutboundAnnotation): Promise; /** - * Publish an annotation removal request for a message, to remove it from the summary - * summaries. The semantics of the delete (and what fields are required) are different - * for each annotation type; see annotation types documentation for more details. + * Publish an annotation removal request for a message, to remove it from the message's annotation summary (alternative form where you only have the serial of the message, not a complete {@link Message} object). The semantics of the delete (and what fields are required) are different for each annotation type; see annotation types documentation for more details. This is a {@link RealtimeAnnotations.publish | `publish()`} with the `action` set to `annotation.delete`, and it mutates the passed annotation object to carry that action, overwriting any `action` you set. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token must have the `annotation-publish` capability; without these the server rejects the operation and the call rejects with an {@link ErrorInfo}. Does not implicitly attach the channel, but rejects with an {@link ErrorInfo} when the channel is `failed` or `suspended` or when the connection is unusable. Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. * * @param messageSerial - The serial field of the message which has an annotation that * you want to delete. * @param annotation - The annotation deletion request. (Must include at least the * `type`, other required fields depend on the type). + * @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure. + * @example + * ```ts + * await channel.annotations.delete(message.serial, { type: 'emoji:distinct.v1', name: '👍' }); + * ``` + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-delete */ delete(messageSerial: string, annotation: OutboundAnnotation): Promise; /** - * Get all annotations for a given message (as a paginated result) + * Get all annotations for a given message (as a paginated result). This is a REST request even on a realtime client: it does not implicitly attach the channel, can be called regardless of channel or connection state, and does not require the `annotation_subscribe` mode. Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations); without it the call rejects with an {@link ErrorInfo}. * * @param message - The message to get annotations for. * @param params - Restrictions on which annotations to get (in particular a limit) + * @returns A promise which, upon success, will be fulfilled with a {@link PaginatedResult} object containing an array of {@link Annotation} objects. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error. + * @example + * ```ts + * const result = await channel.annotations.get(message, null); + * ``` + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-get */ get(message: Message, params: GetAnnotationsParams | null): Promise>; /** - * Get all annotations for a given message (as a paginated result) (alternative form - * where you only have the serial of the message, not a complete Message object) + * Get all annotations for a given message (as a paginated result) (alternative form where you only have the serial of the message, not a complete {@link Message} object). This is a REST request even on a realtime client: it does not implicitly attach the channel, can be called regardless of channel or connection state, and does not require the `annotation_subscribe` mode. Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations); without it the call rejects with an {@link ErrorInfo}. * * @param messageSerial - The `serial` of the message to get annotations for. * @param params - Restrictions on which annotations to get (in particular a limit) + * @returns A promise which, upon success, will be fulfilled with a {@link PaginatedResult} object containing an array of {@link Annotation} objects. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error. + * @example + * ```ts + * const result = await channel.annotations.get(message.serial, null); + * ``` + * @see https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-annotations#annotations-get */ get(messageSerial: string, params: GetAnnotationsParams | null): Promise>; } @@ -2709,56 +2756,80 @@ export declare interface Channel { */ export declare interface RestAnnotations { /** - * Publish a new annotation for a message. + * Publish a new annotation for a message. Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token must have the `annotation-publish` capability; without these the server rejects the operation and the call rejects with an {@link ErrorInfo}. Annotation data is never encrypted, even when {@link ChannelOptions.cipher} is set, because the server must be able to read it to build summaries. * * @param message - The message to annotate. * @param annotation - The annotation to publish. (Must include at least the `type`. * Assumed to be an annotation.create if no action is specified) + * @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure. + * @example + * ```ts + * await channel.annotations.publish(message, { type: 'emoji:distinct.v1', name: '👍' }); + * ``` */ publish(message: Message, annotation: OutboundAnnotation): Promise; /** - * Publish a new annotation for a message (alternative form where you only have the - * serial of the message, not a complete Message object) + * Publish a new annotation for a message (alternative form where you only have the serial of the message, not a complete Message object). Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token must have the `annotation-publish` capability; without these the server rejects the operation and the call rejects with an {@link ErrorInfo}. Annotation data is never encrypted, even when {@link ChannelOptions.cipher} is set, because the server must be able to read it to build summaries. * * @param messageSerial - The serial field of the message to annotate. * @param annotation - The annotation to publish. (Must include at least the `type`. * Assumed to be an annotation.create if no action is specified) + * @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure. + * @example + * ```ts + * await channel.annotations.publish(messageSerial, { type: 'emoji:distinct.v1', name: '👍' }); + * ``` */ publish(messageSerial: string, annotation: OutboundAnnotation): Promise; /** - * Publish an annotation removal request for a message, to remove it from the summary - * summaries. The semantics of the delete (and what fields are required) are different - * for each annotation type; see annotation types documentation for more details. + * Publish an annotation removal request for a message, to remove it from the message's annotation summary. The semantics of the delete (and what fields are required) are different for each annotation type; see annotation types documentation for more details. This is a {@link RestAnnotations.publish | `publish()`} with the `action` set to `annotation.delete`, and it mutates the passed annotation object to carry that action, overwriting any `action` you set. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token must have the `annotation-publish` capability; without these the server rejects the operation and the call rejects with an {@link ErrorInfo}. Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. * * @param message - The message which has an annotation that you want to delete. * @param annotation - The annotation deletion request. (Must include at least the * `type`, other required fields depend on the type). + * @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure. + * @example + * ```ts + * await channel.annotations.delete(message, { type: 'emoji:distinct.v1', name: '👍' }); + * ``` */ delete(message: Message, annotation: OutboundAnnotation): Promise; /** - * Publish an annotation removal request for a message, to remove it from the summary - * summaries. The semantics of the delete (and what fields are required) are different - * for each annotation type; see annotation types documentation for more details. + * Publish an annotation removal request for a message, to remove it from the message's annotation summary (alternative form where you only have the serial of the message, not a complete Message object). The semantics of the delete (and what fields are required) are different for each annotation type; see annotation types documentation for more details. This is a {@link RestAnnotations.publish | `publish()`} with the `action` set to `annotation.delete`, and it mutates the passed annotation object to carry that action, overwriting any `action` you set. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations) and the key or token must have the `annotation-publish` capability; without these the server rejects the operation and the call rejects with an {@link ErrorInfo}. Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. * * @param messageSerial - The serial field of the message which has an annotation that * you want to delete. * @param annotation - The annotation deletion request. (Must include at least the * `type`, other required fields depend on the type). + * @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure. + * @example + * ```ts + * await channel.annotations.delete(messageSerial, { type: 'emoji:distinct.v1', name: '👍' }); + * ``` */ delete(messageSerial: string, annotation: OutboundAnnotation): Promise; /** - * Get all annotations for a given message (as a paginated result) + * Get all annotations for a given message (as a paginated result). Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations); without it the call rejects with an {@link ErrorInfo}. * * @param message - The message to get annotations for. * @param params - Restrictions on which annotations to get (in particular a limit) + * @returns A promise which, upon success, will be fulfilled with a {@link PaginatedResult} object containing an array of {@link Annotation} objects. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error. + * @example + * ```ts + * const result = await channel.annotations.get(message, null); + * ``` */ get(message: Message, params: GetAnnotationsParams | null): Promise>; /** - * Get all annotations for a given message (as a paginated result) (alternative form - * where you only have the serial of the message, not a complete Message object) + * Get all annotations for a given message (as a paginated result) (alternative form where you only have the serial of the message, not a complete Message object). Rejects with a hinted {@link ErrorInfo} unless the first argument is a message serial string or a {@link Message} carrying a `serial`, such as one received from a subscription or history; newly constructed `Message` objects have no serial. Message annotations must be enabled for the channel's namespace by a [rule](https://ably.com/docs/messages/annotations); without it the call rejects with an {@link ErrorInfo}. * * @param messageSerial - The `serial` of the message to get annotations for. * @param params - Restrictions on which annotations to get (in particular a limit) + * @returns A promise which, upon success, will be fulfilled with a {@link PaginatedResult} object containing an array of {@link Annotation} objects. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error. + * @example + * ```ts + * const result = await channel.annotations.get(messageSerial, null); + * ``` */ get(messageSerial: string, params: GetAnnotationsParams | null): Promise>; } diff --git a/src/common/lib/client/realtimeannotations.ts b/src/common/lib/client/realtimeannotations.ts index 39fdbf6bd..02567aaa9 100644 --- a/src/common/lib/client/realtimeannotations.ts +++ b/src/common/lib/client/realtimeannotations.ts @@ -23,7 +23,7 @@ class RealtimeAnnotations { async publish(msgOrSerial: string | Message, annotationValues: Partial>): Promise { const channelName = this.channel.name; - const annotation = constructValidateAnnotation(msgOrSerial, annotationValues); + const annotation = constructValidateAnnotation(msgOrSerial, annotationValues, 'publish'); const wireAnnotation = await annotation.encode(); this.channel.throwIfUnpublishableState(); diff --git a/src/common/lib/client/restannotations.ts b/src/common/lib/client/restannotations.ts index fdaa04461..ce08ea642 100644 --- a/src/common/lib/client/restannotations.ts +++ b/src/common/lib/client/restannotations.ts @@ -13,7 +13,7 @@ export interface RestGetAnnotationsParams { limit?: number; } -export function serialFromMsgOrSerial(msgOrSerial: string | Message): string { +export function serialFromMsgOrSerial(msgOrSerial: string | Message, methodName: string): string { let messageSerial: string | undefined; switch (typeof msgOrSerial) { case 'string': @@ -26,7 +26,9 @@ export function serialFromMsgOrSerial(msgOrSerial: string | Message): string { if (!messageSerial || typeof messageSerial !== 'string') { throw new ErrorInfo({ message: - 'The message argument of annotations.publish()/delete()/get() must be either a Message (or at least an object with a non-empty string `serial` property) or a message serial (non-empty string)', + 'The message argument of annotations.' + + methodName + + '() must be either a Message or other object carrying a non-empty string `serial` property, or a message serial as a non-empty string', code: 40003, statusCode: 400, hint: 'Pass the Message received from a subscribe callback (which carries .serial), or its serial string. Newly constructed Message objects do not have a serial.', @@ -38,12 +40,14 @@ export function serialFromMsgOrSerial(msgOrSerial: string | Message): string { export function constructValidateAnnotation( msgOrSerial: string | Message, annotationValues: Partial>, + methodName: string, ): Annotation { - const messageSerial = serialFromMsgOrSerial(msgOrSerial); + const messageSerial = serialFromMsgOrSerial(msgOrSerial, methodName); if (!annotationValues || typeof annotationValues !== 'object') { throw new ErrorInfo({ - message: 'Second argument of annotations.publish() must be an object (the intended annotation to publish)', + message: + 'Second argument of annotations.' + methodName + '() must be an object (the intended annotation to publish)', code: 40003, statusCode: 400, hint: 'Pass an Annotation-shaped object as the second argument, e.g. { type: "reaction:unique.v1", name: "👍" }.', @@ -72,7 +76,20 @@ class RestAnnotations { } async publish(msgOrSerial: string | Message, annotationValues: Partial>): Promise { - const annotation = constructValidateAnnotation(msgOrSerial, annotationValues); + return this._publish(msgOrSerial, annotationValues, 'publish'); + } + + async delete(msgOrSerial: string | Message, annotationValues: Partial>): Promise { + annotationValues.action = 'annotation.delete'; + return this._publish(msgOrSerial, annotationValues, 'delete'); + } + + private async _publish( + msgOrSerial: string | Message, + annotationValues: Partial>, + methodName: string, + ): Promise { + const annotation = constructValidateAnnotation(msgOrSerial, annotationValues, methodName); const wireAnnotation = await annotation.encode(); const client = this.channel.client, @@ -96,17 +113,12 @@ class RestAnnotations { ); } - async delete(msgOrSerial: string | Message, annotationValues: Partial>): Promise { - annotationValues.action = 'annotation.delete'; - return this.publish(msgOrSerial, annotationValues); - } - async get( msgOrSerial: string | Message, params: RestGetAnnotationsParams | null, ): Promise> { const client = this.channel.client, - messageSerial = serialFromMsgOrSerial(msgOrSerial), + messageSerial = serialFromMsgOrSerial(msgOrSerial, 'get'), format = client.options.useBinaryProtocol ? Utils.Format.msgpack : Utils.Format.json, envelope = client.http.supportsLinkHeaders ? undefined : format, headers = Defaults.defaultGetHeaders(client.options);