/
topicResourceSerializer.ts
447 lines (392 loc) · 13.9 KB
/
topicResourceSerializer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { HttpOperationResponse, OperationOptions } from "@azure/core-http";
import {
AtomXmlSerializer,
deserializeAtomXmlResponse,
serializeToAtomXmlRequest
} from "../util/atomXmlHelper";
import * as Constants from "../util/constants";
import {
AuthorizationRule,
EntityStatus,
getAuthorizationRulesOrUndefined,
getBoolean,
getInteger,
getIntegerOrUndefined,
getRawAuthorizationRules,
getString,
getStringOrUndefined,
getDate,
getMessageCountDetails
} from "../util/utils";
/**
* @internal
* @ignore
* Builds the topic options object from the user provided options.
* Handles the differences in casing for the property names,
* converts values to string and ensures the right order as expected by the service
* @param topic
*/
export function buildTopicOptions(topic: CreateTopicOptions): InternalTopicOptions {
return {
DefaultMessageTimeToLive: topic.defaultMessageTimeToLive,
MaxSizeInMegabytes: getStringOrUndefined(topic.maxSizeInMegabytes),
RequiresDuplicateDetection: getStringOrUndefined(topic.requiresDuplicateDetection),
DuplicateDetectionHistoryTimeWindow: topic.duplicateDetectionHistoryTimeWindow,
EnableBatchedOperations: getStringOrUndefined(topic.enableBatchedOperations),
AuthorizationRules: getRawAuthorizationRules(topic.authorizationRules),
Status: getStringOrUndefined(topic.status),
UserMetadata: getStringOrUndefined(topic.userMetadata),
SupportOrdering: getStringOrUndefined(topic.supportOrdering),
AutoDeleteOnIdle: getStringOrUndefined(topic.autoDeleteOnIdle),
EnablePartitioning: getStringOrUndefined(topic.enablePartitioning),
EnableExpress: getStringOrUndefined(topic.enableExpress)
};
}
/**
* @internal
* @ignore
* Builds the topic object from the raw json object gotten after deserializing the
* response from the service
* @param rawTopic
*/
export function buildTopic(rawTopic: any): TopicProperties {
return {
name: getString(rawTopic[Constants.TOPIC_NAME], "topicName"),
maxSizeInMegabytes: getInteger(rawTopic[Constants.MAX_SIZE_IN_MEGABYTES], "maxSizeInMegabytes"),
enablePartitioning: getBoolean(rawTopic[Constants.ENABLE_PARTITIONING], "enablePartitioning"),
supportOrdering: getBoolean(rawTopic[Constants.SUPPORT_ORDERING], "supportOrdering"),
enableBatchedOperations: getBoolean(
rawTopic[Constants.ENABLE_BATCHED_OPERATIONS],
"enableBatchedOperations"
),
defaultMessageTimeToLive: getString(
rawTopic[Constants.DEFAULT_MESSAGE_TIME_TO_LIVE],
"defaultMessageTimeToLive"
),
autoDeleteOnIdle: rawTopic[Constants.AUTO_DELETE_ON_IDLE],
requiresDuplicateDetection: getBoolean(
rawTopic[Constants.REQUIRES_DUPLICATE_DETECTION],
"requiresDuplicateDetection"
),
duplicateDetectionHistoryTimeWindow: getString(
rawTopic[Constants.DUPLICATE_DETECTION_HISTORY_TIME_WINDOW],
"duplicateDetectionHistoryTimeWindow"
),
authorizationRules: getAuthorizationRulesOrUndefined(rawTopic[Constants.AUTHORIZATION_RULES]),
userMetadata: rawTopic[Constants.USER_METADATA],
status: rawTopic[Constants.STATUS],
enableExpress: getBoolean(rawTopic[Constants.ENABLE_EXPRESS], "enableExpress")
};
}
/**
* @internal
* @ignore
* Builds the topic runtime info object from the raw json object gotten after deserializing the
* response from the service
* @param rawTopic
*/
export function buildTopicRuntimeProperties(rawTopic: any): TopicRuntimeProperties {
return {
name: getString(rawTopic[Constants.TOPIC_NAME], "topicName"),
sizeInBytes: getIntegerOrUndefined(rawTopic[Constants.SIZE_IN_BYTES]),
subscriptionCount: getIntegerOrUndefined(rawTopic[Constants.SUBSCRIPTION_COUNT]),
createdAt: getDate(rawTopic[Constants.CREATED_AT], "createdAt"),
scheduledMessageCount: getMessageCountDetails(rawTopic[Constants.COUNT_DETAILS])
.scheduledMessageCount,
modifiedAt: getDate(rawTopic[Constants.UPDATED_AT], "modifiedAt"),
accessedAt: getDate(rawTopic[Constants.ACCESSED_AT], "accessedAt")
};
}
/**
* Represents settable options on a topic
*/
export interface CreateTopicOptions extends OperationOptions {
/**
* Determines how long a message lives in the associated subscriptions.
* Subscriptions inherit the TTL from the topic unless they are created explicitly
* with a smaller TTL. Based on whether dead-lettering is enabled, a message whose
* TTL has expired will either be moved to the subscription’s associated dead-letter
* sub-queue or will be permanently deleted.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
defaultMessageTimeToLive?: string;
/**
* Specifies the maximum topic size in megabytes. Any attempt to enqueue a message
* that will cause the topic to exceed this value will fail. All messages that are
* stored in the topic or any of its subscriptions count towards this value.
* Multiple copies of a message that reside in one or multiple subscriptions count
* as a single messages. For example, if message m exists once in subscription s1
* and twice in subscription s2, m is counted as a single message.
*/
maxSizeInMegabytes?: number;
/**
* If enabled, the topic will detect duplicate messages within the time span
* specified by the DuplicateDetectionHistoryTimeWindow property.
* Settable only at topic creation time.
*/
requiresDuplicateDetection?: boolean;
/**
* Specifies the time span during which the Service Bus will detect message duplication.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
duplicateDetectionHistoryTimeWindow?: string;
/**
* Specifies if batched operations should be allowed.
*/
enableBatchedOperations?: boolean;
/**
* Authorization rules on the topic
*/
authorizationRules?: AuthorizationRule[];
/**
* Status of the messaging entity.
*/
status?: EntityStatus;
/**
* The user provided metadata information associated with the topic.
* Used to specify textual content such as tags, labels, etc.
* Value must not exceed 1024 bytes encoded in utf-8.
*/
userMetadata?: string;
/**
* Specifies whether the topic supports message ordering.
*/
supportOrdering?: boolean;
/**
* Max idle time before entity is deleted.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
autoDeleteOnIdle?: string;
/**
* Specifies whether the topic should be partitioned
*/
enablePartitioning?: boolean;
/**
* Specifies whether express entities are enabled on topic.
*/
enableExpress?: boolean;
}
/**
* Represents the input for updateTopic.
*
* @export
* @interface TopicProperties
*/
export interface TopicProperties {
/**
* Name of the topic
*/
readonly name: string;
/**
* Determines how long a message lives in the associated subscriptions.
* Subscriptions inherit the TTL from the topic unless they are created explicitly
* with a smaller TTL. Based on whether dead-lettering is enabled, a message whose
* TTL has expired will either be moved to the subscription’s associated dead-letter
* sub-queue or will be permanently deleted.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
defaultMessageTimeToLive: string;
/**
* Specifies the maximum topic size in megabytes. Any attempt to enqueue a message
* that will cause the topic to exceed this value will fail. All messages that are
* stored in the topic or any of its subscriptions count towards this value.
* Multiple copies of a message that reside in one or multiple subscriptions count
* as a single messages. For example, if message m exists once in subscription s1
* and twice in subscription s2, m is counted as a single message.
*/
maxSizeInMegabytes: number;
/**
* If enabled, the topic will detect duplicate messages within the time span
* specified by the DuplicateDetectionHistoryTimeWindow property.
* Settable only at topic creation time.
*/
readonly requiresDuplicateDetection: boolean;
/**
* Specifies the time span during which the Service Bus will detect message duplication.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
duplicateDetectionHistoryTimeWindow: string;
/**
* Specifies if batched operations should be allowed.
*/
enableBatchedOperations: boolean;
/**
* Authorization rules on the topic
*/
authorizationRules?: AuthorizationRule[];
/**
* Status of the messaging entity.
*/
status: EntityStatus;
/**
* The user provided metadata information associated with the topic.
* Used to specify textual content such as tags, labels, etc.
* Value must not exceed 1024 bytes encoded in utf-8.
*/
userMetadata: string;
/**
* Specifies whether the topic supports message ordering.
*/
supportOrdering: boolean;
/**
* Max idle time before entity is deleted.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
autoDeleteOnIdle: string;
/**
* Specifies whether the topic should be partitioned
*/
readonly enablePartitioning: boolean;
/**
* Specifies whether express entities are enabled on topic.
*/
readonly enableExpress: boolean;
}
/**
* @internal
* @ignore
* Internal representation of settable options on a topic
*/
export interface InternalTopicOptions {
/**
* Determines how long a message lives in the associated subscriptions. Subscriptions
* inherit the TTL from the topic unless they are created explicitly with a smaller TTL.
* Based on whether dead-lettering is enabled, a message whose TTL has expired will
* either be moved to the subscription’s associated DeadLtterQueue or will be
* permanently deleted.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
DefaultMessageTimeToLive?: string;
/**
* Specifies the maximum topic size in megabytes. Any attempt to enqueue a message
* that will cause the topic to exceed this value will fail. All messages that are
* stored in the topic or any of its subscriptions count towards this value.
* Multiple copies of a message that reside in one or multiple subscriptions count
* as a single messages. For example, if message m exists once in subscription s1
* and twice in subscription s2, m is counted as a single message.
*/
MaxSizeInMegabytes?: string;
/**
* If enabled, the topic will detect duplicate messages within the time span
* specified by the DuplicateDetectionHistoryTimeWindow property.
* Settable only at topic creation time.
*/
RequiresDuplicateDetection?: string;
/**
* Specifies the time span during which the Service Bus will detect message
* duplication.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
DuplicateDetectionHistoryTimeWindow?: string;
/**
* Specifies if batched operations should be allowed.
*/
EnableBatchedOperations?: string;
/**
* Authorization rules on the topic
*/
AuthorizationRules?: any;
/**
* Status of the messaging entity.
*/
Status?: string;
/**
* The user provided metadata information associated with the topic.
* Used to specify textual content such as tags, labels, etc.
* Value must not exceed 1024 bytes encoded in utf-8.
*/
UserMetadata?: string;
/**
* Specifies whether the topic supports message ordering.
*/
SupportOrdering?: string;
/**
* Max idle time before entity is deleted.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
AutoDeleteOnIdle?: string;
/**
* Specifies whether the topic should be partitioned
*/
EnablePartitioning?: string;
/**
* Specifies whether express entities are enabled on queue.
*/
EnableExpress?: string;
}
/**
* Represents runtime info attributes of a topic entity
*/
export interface TopicRuntimeProperties {
/**
* Name of the topic
*/
name: string;
/**
* Specifies the topic size in bytes.
*/
sizeInBytes?: number;
/**
* The subscription count on given topic.
*
*/
subscriptionCount?: number;
/**
* The number of scheduled messages.
*/
scheduledMessageCount: number;
/**
* Created at timestamp
*/
createdAt: Date;
/**
* Updated at timestamp
*/
modifiedAt: Date;
/**
* Accessed at timestamp
*/
accessedAt: Date;
}
/**
* @internal
* @ignore
* TopicResourceSerializer for serializing / deserializing Topic entities
*/
export class TopicResourceSerializer implements AtomXmlSerializer {
serialize(resource: InternalTopicOptions): object {
return serializeToAtomXmlRequest("TopicDescription", resource);
}
async deserialize(response: HttpOperationResponse): Promise<HttpOperationResponse> {
return deserializeAtomXmlResponse(["TopicName"], response);
}
}