@azure/eventhubs-checkpointstore-table 1.0.0-alpha.20240801.2 → 1.0.0-alpha.20240805.2

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.
Files changed (59) hide show
  1. package/dist/browser/index.d.ts +3 -0
  2. package/dist/browser/index.d.ts.map +1 -0
  3. package/dist/browser/index.js +5 -0
  4. package/dist/browser/index.js.map +1 -0
  5. package/dist/browser/log.d.ts +12 -0
  6. package/dist/browser/log.d.ts.map +1 -0
  7. package/dist/browser/package.json +3 -0
  8. package/dist/browser/tableCheckpointStore.d.ts +94 -0
  9. package/dist/browser/tableCheckpointStore.d.ts.map +1 -0
  10. package/{dist-esm/src → dist/browser}/tableCheckpointStore.js +2 -2
  11. package/dist/browser/tableCheckpointStore.js.map +1 -0
  12. package/dist/browser/util/error.d.ts +9 -0
  13. package/dist/browser/util/error.d.ts.map +1 -0
  14. package/{dist-esm/src → dist/browser}/util/error.js +1 -1
  15. package/dist/browser/util/error.js.map +1 -0
  16. package/dist/commonjs/index.d.ts +3 -0
  17. package/dist/commonjs/index.d.ts.map +1 -0
  18. package/dist/commonjs/index.js +10 -0
  19. package/dist/commonjs/index.js.map +1 -0
  20. package/dist/commonjs/log.d.ts +12 -0
  21. package/dist/commonjs/log.d.ts.map +1 -0
  22. package/dist/commonjs/log.js +23 -0
  23. package/dist/commonjs/log.js.map +1 -0
  24. package/dist/commonjs/package.json +3 -0
  25. package/dist/commonjs/tableCheckpointStore.d.ts +94 -0
  26. package/dist/commonjs/tableCheckpointStore.d.ts.map +1 -0
  27. package/dist/commonjs/tableCheckpointStore.js +219 -0
  28. package/dist/commonjs/tableCheckpointStore.js.map +1 -0
  29. package/dist/commonjs/tsdoc-metadata.json +11 -0
  30. package/dist/commonjs/util/error.d.ts +9 -0
  31. package/dist/commonjs/util/error.d.ts.map +1 -0
  32. package/dist/commonjs/util/error.js +22 -0
  33. package/dist/commonjs/util/error.js.map +1 -0
  34. package/dist/esm/index.d.ts +3 -0
  35. package/dist/esm/index.d.ts.map +1 -0
  36. package/dist/esm/index.js +5 -0
  37. package/dist/esm/index.js.map +1 -0
  38. package/dist/esm/log.d.ts +12 -0
  39. package/dist/esm/log.d.ts.map +1 -0
  40. package/dist/esm/log.js +19 -0
  41. package/dist/esm/log.js.map +1 -0
  42. package/dist/esm/package.json +3 -0
  43. package/dist/esm/tableCheckpointStore.d.ts +94 -0
  44. package/dist/esm/tableCheckpointStore.d.ts.map +1 -0
  45. package/dist/{index.js → esm/tableCheckpointStore.js} +10 -36
  46. package/dist/esm/tableCheckpointStore.js.map +1 -0
  47. package/dist/esm/util/error.d.ts +9 -0
  48. package/dist/esm/util/error.d.ts.map +1 -0
  49. package/dist/esm/util/error.js +19 -0
  50. package/dist/esm/util/error.js.map +1 -0
  51. package/package.json +73 -51
  52. package/dist/index.js.map +0 -1
  53. package/dist-esm/src/index.js +0 -6
  54. package/dist-esm/src/index.js.map +0 -1
  55. package/dist-esm/src/tableCheckpointStore.js.map +0 -1
  56. package/dist-esm/src/util/error.js.map +0 -1
  57. /package/{dist-esm/src → dist/browser}/log.js +0 -0
  58. /package/{dist-esm/src → dist/browser}/log.js.map +0 -0
  59. /package/{typings → dist}/eventhubs-checkpointstore-table.d.ts +0 -0
@@ -0,0 +1,3 @@
1
+ export { TableCheckpointStore } from "./tableCheckpointStore.js";
2
+ export { logger } from "./log.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ export { TableCheckpointStore } from "./tableCheckpointStore.js";
4
+ export { logger } from "./log.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { TableCheckpointStore } from \"./tableCheckpointStore.js\";\nexport { logger } from \"./log.js\";\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The `@azure/logger` configuration for this package.
3
+ * This will output logs using the `azure:eventhubs-checkpointstore-table` namespace prefix.
4
+ */
5
+ export declare const logger: import("@azure/logger").AzureLogger;
6
+ /**
7
+ * Logs the error's stack trace to "verbose" if a stack trace is available.
8
+ * @param error - Error containing a stack trace.
9
+ * @internal
10
+ */
11
+ export declare function logErrorStackTrace(error: unknown): void;
12
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,eAAO,MAAM,MAAM,qCAAwD,CAAC;AAE5E;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAIvD"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,94 @@
1
+ import { Checkpoint, CheckpointStore, PartitionOwnership } from "@azure/event-hubs";
2
+ import { TableClient } from "@azure/data-tables";
3
+ /**
4
+ * A checkpoint entity of type CheckpointEntity to be stored in the table
5
+ * @internal
6
+ *
7
+ */
8
+ export interface CheckpointEntity {
9
+ /**
10
+ * The partitionKey is a composite key assembled in the following format:
11
+ * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`
12
+ */
13
+ partitionKey: string;
14
+ /**
15
+ * The rowKey is the partitionId
16
+ *
17
+ */
18
+ rowKey: string;
19
+ sequencenumber: string;
20
+ offset: string;
21
+ }
22
+ /**
23
+ * An ownership entity of type PartitionOwnership to be stored in the table
24
+ * @internal
25
+ */
26
+ export interface PartitionOwnershipEntity {
27
+ /**
28
+ * The partitionKey is a composite key assembled in the following format:
29
+ * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`
30
+ */
31
+ partitionKey: string;
32
+ /**
33
+ * The rowKey is the partitionId
34
+ *
35
+ */
36
+ rowKey: string;
37
+ ownerid: string;
38
+ }
39
+ /**
40
+ * An implementation of CheckpointStore that uses Azure Table Storage to persist checkpoint data.
41
+ */
42
+ export declare class TableCheckpointStore implements CheckpointStore {
43
+ private _tableClient;
44
+ constructor(tableClient: TableClient);
45
+ /**
46
+ * Get the list of all existing partition ownership from the underlying data store. May return empty
47
+ * results if there are is no existing ownership information.
48
+ * Partition Ownership contains the information on which `EventHubConsumerClient` subscribe call is currently processing the partition.
49
+ *
50
+ * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to
51
+ * <yournamespace>.servicebus.windows.net.
52
+ * @param eventHubName - The event hub name.
53
+ * @param consumerGroup - The consumer group name.
54
+ * @param options - A set of options that can be specified to influence the behavior of this method.
55
+ * - `abortSignal`: A signal used to request operation cancellation.
56
+ * - `tracingOptions`: Options for configuring tracing.
57
+ * @returns Partition ownership details of all the partitions that have had an owner.
58
+ */
59
+ listOwnership(fullyQualifiedNamespace: string, eventHubName: string, consumerGroup: string): Promise<PartitionOwnership[]>;
60
+ /**
61
+ * Claim ownership of a list of partitions. This will return the list of partitions that were
62
+ * successfully claimed.
63
+ *
64
+ * @param partitionOwnership - The list of partition ownership this instance is claiming to own.
65
+ * @param options - A set of options that can be specified to influence the behavior of this method.
66
+ * - `abortSignal`: A signal used to request operation cancellation.
67
+ * - `tracingOptions`: Options for configuring tracing.
68
+ * @returns A list partitions this instance successfully claimed ownership.
69
+ */
70
+ claimOwnership(partitionOwnership: PartitionOwnership[]): Promise<PartitionOwnership[]>;
71
+ /**
72
+ * Lists all the checkpoints in a data store for a given namespace, eventhub and consumer group.
73
+ *
74
+ * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to
75
+ * <yournamespace>.servicebus.windows.net.
76
+ * @param eventHubName - The event hub name.
77
+ * @param consumerGroup - The consumer group name.
78
+ * @param options - A set of options that can be specified to influence the behavior of this method.
79
+ * - `abortSignal`: A signal used to request operation cancellation.
80
+ * - `tracingOptions`: Options for configuring tracing.
81
+ */
82
+ listCheckpoints(fullyQualifiedNamespace: string, eventHubName: string, consumerGroup: string): Promise<Checkpoint[]>;
83
+ /**
84
+ * Updates the checkpoint in the data store for a partition.
85
+ *
86
+ * @param checkpoint - The checkpoint.
87
+ * @param options - A set of options that can be specified to influence the behavior of this method.
88
+ * - `abortSignal`: A signal used to request operation cancellation.
89
+ * - `tracingOptions`: Options for configuring tracing.
90
+ * @returns A promise that resolves when the checkpoint has been updated.
91
+ */
92
+ updateCheckpoint(checkpoint: Checkpoint): Promise<void>;
93
+ }
94
+ //# sourceMappingURL=tableCheckpointStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableCheckpointStore.d.ts","sourceRoot":"","sources":["../../src/tableCheckpointStore.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,WAAW,EAAmC,MAAM,oBAAoB,CAAC;AAalF;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,oBAAqB,YAAW,eAAe;IAC1D,OAAO,CAAC,YAAY,CAAc;gBAEtB,WAAW,EAAE,WAAW;IAIpC;;;;;;;;;;;;;OAaG;IACG,aAAa,CACjB,uBAAuB,EAAE,MAAM,EAC/B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAmChC;;;;;;;;;OASG;IACG,cAAc,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IA4E7F;;;;;;;;;;OAUG;IACG,eAAe,CACnB,uBAAuB,EAAE,MAAM,EAC/B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,UAAU,EAAE,CAAC;IAmBxB;;;;;;;;OAQG;IACG,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAoB9D"}
@@ -2,7 +2,7 @@
2
2
  // Licensed under the MIT license.
3
3
  import { __asyncValues } from "tslib";
4
4
  import { odata } from "@azure/data-tables";
5
- import { logErrorStackTrace, logger } from "./log";
5
+ import { logErrorStackTrace, logger } from "./log.js";
6
6
  /**
7
7
  *
8
8
  * Checks if the value contains a `Timestamp` field of type `string`.
@@ -207,7 +207,7 @@ export class TableCheckpointStore {
207
207
  return;
208
208
  }
209
209
  catch (err) {
210
- logger.verbose(`Error occurred while upating the checkpoint for partition: ${checkpoint.partitionId}.`, err.message);
210
+ logger.verbose(`Error occurred while updating the checkpoint for partition: ${checkpoint.partitionId}.`, err.message);
211
211
  throw err;
212
212
  }
213
213
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableCheckpointStore.js","sourceRoot":"","sources":["../../src/tableCheckpointStore.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAyC,K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;IACH,KAAK,CAAC,gBAAgB,CAAC,UAAsB;QAC3C,MAAM,YAAY,GAAG,GAAG,UAAU,CAAC,uBAAuB,IAAI,UAAU,CAAC,YAAY,IAAI,UAAU,CAAC,aAAa,aAAa,CAAC;QAC/H,MAAM,gBAAgB,GAAqB;YACzC,YAAY,EAAE,YAAY;YAC1B,MAAM,EAAE,UAAU,CAAC,WAAW;YAC9B,cAAc,EAAE,UAAU,CAAC,cAAc,CAAC,QAAQ,EAAE;YACpD,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;SACrC,CAAC;QACF,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO,CAAC,kDAAkD,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;YAC3F,OAAO;QACT,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,CAAC,OAAO,CACZ,+DAA+D,UAAU,CAAC,WAAW,GAAG,EACxF,GAAG,CAAC,OAAO,CACZ,CAAC;YACF,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Checkpoint, CheckpointStore, PartitionOwnership } from \"@azure/event-hubs\";\nimport { TableClient, TableInsertEntityHeaders, odata } from \"@azure/data-tables\";\nimport { logErrorStackTrace, logger } from \"./log.js\";\n\n/**\n *\n * Checks if the value contains a `Timestamp` field of type `string`.\n */\nfunction _hasTimestamp<T extends TableInsertEntityHeaders>(\n value: T,\n): value is T & { Timestamp: string } {\n return typeof (value as any).Timestamp === \"string\";\n}\n\n/**\n * A checkpoint entity of type CheckpointEntity to be stored in the table\n * @internal\n *\n */\nexport interface CheckpointEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n sequencenumber: string;\n offset: string;\n}\n\n/**\n * An ownership entity of type PartitionOwnership to be stored in the table\n * @internal\n */\nexport interface PartitionOwnershipEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n ownerid: string;\n}\n\n/**\n * An implementation of CheckpointStore that uses Azure Table Storage to persist checkpoint data.\n */\nexport class TableCheckpointStore implements CheckpointStore {\n private _tableClient: TableClient;\n\n constructor(tableClient: TableClient) {\n this._tableClient = tableClient;\n }\n\n /**\n * Get the list of all existing partition ownership from the underlying data store. May return empty\n * results if there are is no existing ownership information.\n * Partition Ownership contains the information on which `EventHubConsumerClient` subscribe call is currently processing the partition.\n *\n * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to\n * <yournamespace>.servicebus.windows.net.\n * @param eventHubName - The event hub name.\n * @param consumerGroup - The consumer group name.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns Partition ownership details of all the partitions that have had an owner.\n */\n async listOwnership(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n consumerGroup: string,\n ): Promise<PartitionOwnership[]> {\n const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`;\n const partitionOwnershipArray: PartitionOwnership[] = [];\n const entitiesIter = this._tableClient.listEntities<PartitionOwnershipEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n try {\n for await (const entity of entitiesIter) {\n if (!entity.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entity.rowKey}\"`,\n );\n }\n\n const partitionOwnership: PartitionOwnership = {\n fullyQualifiedNamespace,\n eventHubName,\n consumerGroup,\n ownerId: entity.ownerid,\n partitionId: entity.rowKey,\n lastModifiedTimeInMs: new Date(entity.timestamp).getTime(),\n etag: entity.etag,\n };\n partitionOwnershipArray.push(partitionOwnership);\n }\n return partitionOwnershipArray;\n } catch (err: any) {\n logger.warning(`Error occurred while fetching the list of entities`, err.message);\n logErrorStackTrace(err);\n if (err?.name === \"AbortError\") throw err;\n\n throw new Error(`Error occurred while fetching the list of entities. \\n${err}`);\n }\n }\n\n /**\n * Claim ownership of a list of partitions. This will return the list of partitions that were\n * successfully claimed.\n *\n * @param partitionOwnership - The list of partition ownership this instance is claiming to own.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A list partitions this instance successfully claimed ownership.\n */\n async claimOwnership(partitionOwnership: PartitionOwnership[]): Promise<PartitionOwnership[]> {\n const partitionOwnershipArray: PartitionOwnership[] = [];\n\n for (const ownership of partitionOwnership) {\n const updatedOwnership = { ...ownership };\n const partitionKey = `${ownership.fullyQualifiedNamespace} ${ownership.eventHubName} ${ownership.consumerGroup} Ownership`;\n const ownershipEntity: PartitionOwnershipEntity = {\n partitionKey: partitionKey,\n rowKey: ownership.partitionId,\n ownerid: ownership.ownerId,\n };\n\n // When we have an etag, we know the entity existed.\n // If we encounter an error we should fail.\n try {\n if (ownership.etag) {\n const updatedMetadata = await this._tableClient.updateEntity(ownershipEntity, \"Replace\", {\n etag: ownership.etag,\n });\n const entityRetrieved = await this._tableClient.getEntity(\n ownershipEntity.partitionKey,\n ownershipEntity.rowKey,\n );\n if (!entityRetrieved.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entityRetrieved.rowKey}\"`,\n );\n }\n updatedOwnership.lastModifiedTimeInMs = new Date(entityRetrieved.timestamp).getTime();\n updatedOwnership.etag = updatedMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n logger.info(\n `[${ownership.ownerId}] Claimed ownership successfully for partition: ${ownership.partitionId}`,\n `LastModifiedTime: ${ownership.lastModifiedTimeInMs}, ETag: ${ownership.etag}`,\n );\n } else {\n const newOwnershipMetadata = await this._tableClient.createEntity(ownershipEntity, {\n requestOptions: {\n customHeaders: {\n Prefer: \"return-content\",\n },\n },\n });\n\n if (!_hasTimestamp(newOwnershipMetadata)) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${ownershipEntity.rowKey}\"`,\n );\n }\n\n updatedOwnership.lastModifiedTimeInMs = new Date(\n newOwnershipMetadata.Timestamp,\n ).getTime();\n updatedOwnership.etag = newOwnershipMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n }\n } catch (err: any) {\n if (err.statusCode === 412) {\n // etag failures (precondition not met) aren't fatal errors. They happen\n // as multiple consumers attempt to claim the same partition (first one wins)\n // and losers get this error.\n logger.verbose(\n `[${ownership.ownerId}] Did not claim partition ${ownership.partitionId}. Another processor has already claimed it.`,\n );\n continue;\n }\n logger.warning(\n `Error occurred while claiming ownership for partition: ${ownership.partitionId}`,\n err.message,\n );\n logErrorStackTrace(err);\n }\n }\n return partitionOwnershipArray;\n }\n\n /**\n * Lists all the checkpoints in a data store for a given namespace, eventhub and consumer group.\n *\n * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to\n * <yournamespace>.servicebus.windows.net.\n * @param eventHubName - The event hub name.\n * @param consumerGroup - The consumer group name.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n */\n async listCheckpoints(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n consumerGroup: string,\n ): Promise<Checkpoint[]> {\n const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`;\n const checkpoints: Checkpoint[] = [];\n const entitiesIter = this._tableClient.listEntities<CheckpointEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n for await (const entity of entitiesIter) {\n checkpoints.push({\n consumerGroup,\n eventHubName,\n fullyQualifiedNamespace,\n partitionId: entity.rowKey,\n offset: parseInt(entity.offset, 10),\n sequenceNumber: parseInt(entity.sequencenumber, 10),\n });\n }\n return checkpoints;\n }\n\n /**\n * Updates the checkpoint in the data store for a partition.\n *\n * @param checkpoint - The checkpoint.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A promise that resolves when the checkpoint has been updated.\n */\n async updateCheckpoint(checkpoint: Checkpoint): Promise<void> {\n const partitionKey = `${checkpoint.fullyQualifiedNamespace} ${checkpoint.eventHubName} ${checkpoint.consumerGroup} Checkpoint`;\n const checkpointEntity: CheckpointEntity = {\n partitionKey: partitionKey,\n rowKey: checkpoint.partitionId,\n sequencenumber: checkpoint.sequenceNumber.toString(),\n offset: checkpoint.offset.toString(),\n };\n try {\n await this._tableClient.upsertEntity(checkpointEntity);\n logger.verbose(`Updated checkpoint successfully for partition: ${checkpoint.partitionId}`);\n return;\n } catch (err: any) {\n logger.verbose(\n `Error occurred while updating the checkpoint for partition: ${checkpoint.partitionId}.`,\n err.message,\n );\n throw err;\n }\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @internal
3
+ * Logs and Throws TypeError if given parameter is undefined or null
4
+ * @param methodName - Name of the method that was passed the parameter
5
+ * @param parameterName - Name of the parameter to check
6
+ * @param parameterValue - Value of the parameter to check
7
+ */
8
+ export declare function throwTypeErrorIfParameterMissing(methodName: string, parameterName: string, parameterValue: unknown): void;
9
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/util/error.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,OAAO,GACtB,IAAI,CASN"}
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { logErrorStackTrace, logger } from "../log";
3
+ import { logErrorStackTrace, logger } from "../log.js";
4
4
  /**
5
5
  * @internal
6
6
  * Logs and Throws TypeError if given parameter is undefined or null
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/util/error.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAC9C,UAAkB,EAClB,aAAqB,EACrB,cAAuB;IAEvB,IAAI,cAAc,KAAK,SAAS,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;QAC5D,MAAM,KAAK,GAAG,IAAI,SAAS,CACzB,GAAG,UAAU,sCAAsC,aAAa,GAAG,CACpE,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { logErrorStackTrace, logger } from \"../log.js\";\n\n/**\n * @internal\n * Logs and Throws TypeError if given parameter is undefined or null\n * @param methodName - Name of the method that was passed the parameter\n * @param parameterName - Name of the parameter to check\n * @param parameterValue - Value of the parameter to check\n */\nexport function throwTypeErrorIfParameterMissing(\n methodName: string,\n parameterName: string,\n parameterValue: unknown,\n): void {\n if (parameterValue === undefined || parameterValue === null) {\n const error = new TypeError(\n `${methodName} called without required argument \"${parameterName}\"`,\n );\n logger.warning(error.message);\n logErrorStackTrace(error);\n throw error;\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export { TableCheckpointStore } from "./tableCheckpointStore.js";
2
+ export { logger } from "./log.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT license.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.logger = exports.TableCheckpointStore = void 0;
6
+ var tableCheckpointStore_js_1 = require("./tableCheckpointStore.js");
7
+ Object.defineProperty(exports, "TableCheckpointStore", { enumerable: true, get: function () { return tableCheckpointStore_js_1.TableCheckpointStore; } });
8
+ var log_js_1 = require("./log.js");
9
+ Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return log_js_1.logger; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,qEAAiE;AAAxD,+HAAA,oBAAoB,OAAA;AAC7B,mCAAkC;AAAzB,gGAAA,MAAM,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { TableCheckpointStore } from \"./tableCheckpointStore.js\";\nexport { logger } from \"./log.js\";\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The `@azure/logger` configuration for this package.
3
+ * This will output logs using the `azure:eventhubs-checkpointstore-table` namespace prefix.
4
+ */
5
+ export declare const logger: import("@azure/logger").AzureLogger;
6
+ /**
7
+ * Logs the error's stack trace to "verbose" if a stack trace is available.
8
+ * @param error - Error containing a stack trace.
9
+ * @internal
10
+ */
11
+ export declare function logErrorStackTrace(error: unknown): void;
12
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,eAAO,MAAM,MAAM,qCAAwD,CAAC;AAE5E;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAIvD"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT license.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.logger = void 0;
6
+ exports.logErrorStackTrace = logErrorStackTrace;
7
+ const logger_1 = require("@azure/logger");
8
+ /**
9
+ * The `@azure/logger` configuration for this package.
10
+ * This will output logs using the `azure:eventhubs-checkpointstore-table` namespace prefix.
11
+ */
12
+ exports.logger = (0, logger_1.createClientLogger)("eventhubs-checkpointstore-table");
13
+ /**
14
+ * Logs the error's stack trace to "verbose" if a stack trace is available.
15
+ * @param error - Error containing a stack trace.
16
+ * @internal
17
+ */
18
+ function logErrorStackTrace(error) {
19
+ if (error && typeof error === "object" && "stack" in error) {
20
+ exports.logger.verbose(error.stack);
21
+ }
22
+ }
23
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAelC,gDAIC;AAjBD,0CAAmD;AAEnD;;;GAGG;AACU,QAAA,MAAM,GAAG,IAAA,2BAAkB,EAAC,iCAAiC,CAAC,CAAC;AAE5E;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;QAC3D,cAAM,CAAC,OAAO,CAAE,KAAa,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The `@azure/logger` configuration for this package.\n * This will output logs using the `azure:eventhubs-checkpointstore-table` namespace prefix.\n */\nexport const logger = createClientLogger(\"eventhubs-checkpointstore-table\");\n\n/**\n * Logs the error's stack trace to \"verbose\" if a stack trace is available.\n * @param error - Error containing a stack trace.\n * @internal\n */\nexport function logErrorStackTrace(error: unknown): void {\n if (error && typeof error === \"object\" && \"stack\" in error) {\n logger.verbose((error as any).stack);\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,94 @@
1
+ import { Checkpoint, CheckpointStore, PartitionOwnership } from "@azure/event-hubs";
2
+ import { TableClient } from "@azure/data-tables";
3
+ /**
4
+ * A checkpoint entity of type CheckpointEntity to be stored in the table
5
+ * @internal
6
+ *
7
+ */
8
+ export interface CheckpointEntity {
9
+ /**
10
+ * The partitionKey is a composite key assembled in the following format:
11
+ * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`
12
+ */
13
+ partitionKey: string;
14
+ /**
15
+ * The rowKey is the partitionId
16
+ *
17
+ */
18
+ rowKey: string;
19
+ sequencenumber: string;
20
+ offset: string;
21
+ }
22
+ /**
23
+ * An ownership entity of type PartitionOwnership to be stored in the table
24
+ * @internal
25
+ */
26
+ export interface PartitionOwnershipEntity {
27
+ /**
28
+ * The partitionKey is a composite key assembled in the following format:
29
+ * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`
30
+ */
31
+ partitionKey: string;
32
+ /**
33
+ * The rowKey is the partitionId
34
+ *
35
+ */
36
+ rowKey: string;
37
+ ownerid: string;
38
+ }
39
+ /**
40
+ * An implementation of CheckpointStore that uses Azure Table Storage to persist checkpoint data.
41
+ */
42
+ export declare class TableCheckpointStore implements CheckpointStore {
43
+ private _tableClient;
44
+ constructor(tableClient: TableClient);
45
+ /**
46
+ * Get the list of all existing partition ownership from the underlying data store. May return empty
47
+ * results if there are is no existing ownership information.
48
+ * Partition Ownership contains the information on which `EventHubConsumerClient` subscribe call is currently processing the partition.
49
+ *
50
+ * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to
51
+ * <yournamespace>.servicebus.windows.net.
52
+ * @param eventHubName - The event hub name.
53
+ * @param consumerGroup - The consumer group name.
54
+ * @param options - A set of options that can be specified to influence the behavior of this method.
55
+ * - `abortSignal`: A signal used to request operation cancellation.
56
+ * - `tracingOptions`: Options for configuring tracing.
57
+ * @returns Partition ownership details of all the partitions that have had an owner.
58
+ */
59
+ listOwnership(fullyQualifiedNamespace: string, eventHubName: string, consumerGroup: string): Promise<PartitionOwnership[]>;
60
+ /**
61
+ * Claim ownership of a list of partitions. This will return the list of partitions that were
62
+ * successfully claimed.
63
+ *
64
+ * @param partitionOwnership - The list of partition ownership this instance is claiming to own.
65
+ * @param options - A set of options that can be specified to influence the behavior of this method.
66
+ * - `abortSignal`: A signal used to request operation cancellation.
67
+ * - `tracingOptions`: Options for configuring tracing.
68
+ * @returns A list partitions this instance successfully claimed ownership.
69
+ */
70
+ claimOwnership(partitionOwnership: PartitionOwnership[]): Promise<PartitionOwnership[]>;
71
+ /**
72
+ * Lists all the checkpoints in a data store for a given namespace, eventhub and consumer group.
73
+ *
74
+ * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to
75
+ * <yournamespace>.servicebus.windows.net.
76
+ * @param eventHubName - The event hub name.
77
+ * @param consumerGroup - The consumer group name.
78
+ * @param options - A set of options that can be specified to influence the behavior of this method.
79
+ * - `abortSignal`: A signal used to request operation cancellation.
80
+ * - `tracingOptions`: Options for configuring tracing.
81
+ */
82
+ listCheckpoints(fullyQualifiedNamespace: string, eventHubName: string, consumerGroup: string): Promise<Checkpoint[]>;
83
+ /**
84
+ * Updates the checkpoint in the data store for a partition.
85
+ *
86
+ * @param checkpoint - The checkpoint.
87
+ * @param options - A set of options that can be specified to influence the behavior of this method.
88
+ * - `abortSignal`: A signal used to request operation cancellation.
89
+ * - `tracingOptions`: Options for configuring tracing.
90
+ * @returns A promise that resolves when the checkpoint has been updated.
91
+ */
92
+ updateCheckpoint(checkpoint: Checkpoint): Promise<void>;
93
+ }
94
+ //# sourceMappingURL=tableCheckpointStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableCheckpointStore.d.ts","sourceRoot":"","sources":["../../src/tableCheckpointStore.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,WAAW,EAAmC,MAAM,oBAAoB,CAAC;AAalF;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,oBAAqB,YAAW,eAAe;IAC1D,OAAO,CAAC,YAAY,CAAc;gBAEtB,WAAW,EAAE,WAAW;IAIpC;;;;;;;;;;;;;OAaG;IACG,aAAa,CACjB,uBAAuB,EAAE,MAAM,EAC/B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAmChC;;;;;;;;;OASG;IACG,cAAc,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IA4E7F;;;;;;;;;;OAUG;IACG,eAAe,CACnB,uBAAuB,EAAE,MAAM,EAC/B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,UAAU,EAAE,CAAC;IAmBxB;;;;;;;;OAQG;IACG,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAoB9D"}
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT license.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.TableCheckpointStore = void 0;
6
+ const tslib_1 = require("tslib");
7
+ const data_tables_1 = require("@azure/data-tables");
8
+ const log_js_1 = require("./log.js");
9
+ /**
10
+ *
11
+ * Checks if the value contains a `Timestamp` field of type `string`.
12
+ */
13
+ function _hasTimestamp(value) {
14
+ return typeof value.Timestamp === "string";
15
+ }
16
+ /**
17
+ * An implementation of CheckpointStore that uses Azure Table Storage to persist checkpoint data.
18
+ */
19
+ class TableCheckpointStore {
20
+ constructor(tableClient) {
21
+ this._tableClient = tableClient;
22
+ }
23
+ /**
24
+ * Get the list of all existing partition ownership from the underlying data store. May return empty
25
+ * results if there are is no existing ownership information.
26
+ * Partition Ownership contains the information on which `EventHubConsumerClient` subscribe call is currently processing the partition.
27
+ *
28
+ * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to
29
+ * <yournamespace>.servicebus.windows.net.
30
+ * @param eventHubName - The event hub name.
31
+ * @param consumerGroup - The consumer group name.
32
+ * @param options - A set of options that can be specified to influence the behavior of this method.
33
+ * - `abortSignal`: A signal used to request operation cancellation.
34
+ * - `tracingOptions`: Options for configuring tracing.
35
+ * @returns Partition ownership details of all the partitions that have had an owner.
36
+ */
37
+ async listOwnership(fullyQualifiedNamespace, eventHubName, consumerGroup) {
38
+ var _a, e_1, _b, _c;
39
+ const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`;
40
+ const partitionOwnershipArray = [];
41
+ const entitiesIter = this._tableClient.listEntities({
42
+ queryOptions: { filter: (0, data_tables_1.odata) `PartitionKey eq ${partitionKey}` },
43
+ });
44
+ try {
45
+ try {
46
+ for (var _d = true, entitiesIter_1 = tslib_1.__asyncValues(entitiesIter), entitiesIter_1_1; entitiesIter_1_1 = await entitiesIter_1.next(), _a = entitiesIter_1_1.done, !_a; _d = true) {
47
+ _c = entitiesIter_1_1.value;
48
+ _d = false;
49
+ const entity = _c;
50
+ if (!entity.timestamp) {
51
+ throw new Error(`Unable to retrieve timestamp from partitionKey "${partitionKey}", rowKey "${entity.rowKey}"`);
52
+ }
53
+ const partitionOwnership = {
54
+ fullyQualifiedNamespace,
55
+ eventHubName,
56
+ consumerGroup,
57
+ ownerId: entity.ownerid,
58
+ partitionId: entity.rowKey,
59
+ lastModifiedTimeInMs: new Date(entity.timestamp).getTime(),
60
+ etag: entity.etag,
61
+ };
62
+ partitionOwnershipArray.push(partitionOwnership);
63
+ }
64
+ }
65
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
66
+ finally {
67
+ try {
68
+ if (!_d && !_a && (_b = entitiesIter_1.return)) await _b.call(entitiesIter_1);
69
+ }
70
+ finally { if (e_1) throw e_1.error; }
71
+ }
72
+ return partitionOwnershipArray;
73
+ }
74
+ catch (err) {
75
+ log_js_1.logger.warning(`Error occurred while fetching the list of entities`, err.message);
76
+ (0, log_js_1.logErrorStackTrace)(err);
77
+ if ((err === null || err === void 0 ? void 0 : err.name) === "AbortError")
78
+ throw err;
79
+ throw new Error(`Error occurred while fetching the list of entities. \n${err}`);
80
+ }
81
+ }
82
+ /**
83
+ * Claim ownership of a list of partitions. This will return the list of partitions that were
84
+ * successfully claimed.
85
+ *
86
+ * @param partitionOwnership - The list of partition ownership this instance is claiming to own.
87
+ * @param options - A set of options that can be specified to influence the behavior of this method.
88
+ * - `abortSignal`: A signal used to request operation cancellation.
89
+ * - `tracingOptions`: Options for configuring tracing.
90
+ * @returns A list partitions this instance successfully claimed ownership.
91
+ */
92
+ async claimOwnership(partitionOwnership) {
93
+ const partitionOwnershipArray = [];
94
+ for (const ownership of partitionOwnership) {
95
+ const updatedOwnership = Object.assign({}, ownership);
96
+ const partitionKey = `${ownership.fullyQualifiedNamespace} ${ownership.eventHubName} ${ownership.consumerGroup} Ownership`;
97
+ const ownershipEntity = {
98
+ partitionKey: partitionKey,
99
+ rowKey: ownership.partitionId,
100
+ ownerid: ownership.ownerId,
101
+ };
102
+ // When we have an etag, we know the entity existed.
103
+ // If we encounter an error we should fail.
104
+ try {
105
+ if (ownership.etag) {
106
+ const updatedMetadata = await this._tableClient.updateEntity(ownershipEntity, "Replace", {
107
+ etag: ownership.etag,
108
+ });
109
+ const entityRetrieved = await this._tableClient.getEntity(ownershipEntity.partitionKey, ownershipEntity.rowKey);
110
+ if (!entityRetrieved.timestamp) {
111
+ throw new Error(`Unable to retrieve timestamp from partitionKey "${partitionKey}", rowKey "${entityRetrieved.rowKey}"`);
112
+ }
113
+ updatedOwnership.lastModifiedTimeInMs = new Date(entityRetrieved.timestamp).getTime();
114
+ updatedOwnership.etag = updatedMetadata.etag;
115
+ partitionOwnershipArray.push(updatedOwnership);
116
+ log_js_1.logger.info(`[${ownership.ownerId}] Claimed ownership successfully for partition: ${ownership.partitionId}`, `LastModifiedTime: ${ownership.lastModifiedTimeInMs}, ETag: ${ownership.etag}`);
117
+ }
118
+ else {
119
+ const newOwnershipMetadata = await this._tableClient.createEntity(ownershipEntity, {
120
+ requestOptions: {
121
+ customHeaders: {
122
+ Prefer: "return-content",
123
+ },
124
+ },
125
+ });
126
+ if (!_hasTimestamp(newOwnershipMetadata)) {
127
+ throw new Error(`Unable to retrieve timestamp from partitionKey "${partitionKey}", rowKey "${ownershipEntity.rowKey}"`);
128
+ }
129
+ updatedOwnership.lastModifiedTimeInMs = new Date(newOwnershipMetadata.Timestamp).getTime();
130
+ updatedOwnership.etag = newOwnershipMetadata.etag;
131
+ partitionOwnershipArray.push(updatedOwnership);
132
+ }
133
+ }
134
+ catch (err) {
135
+ if (err.statusCode === 412) {
136
+ // etag failures (precondition not met) aren't fatal errors. They happen
137
+ // as multiple consumers attempt to claim the same partition (first one wins)
138
+ // and losers get this error.
139
+ log_js_1.logger.verbose(`[${ownership.ownerId}] Did not claim partition ${ownership.partitionId}. Another processor has already claimed it.`);
140
+ continue;
141
+ }
142
+ log_js_1.logger.warning(`Error occurred while claiming ownership for partition: ${ownership.partitionId}`, err.message);
143
+ (0, log_js_1.logErrorStackTrace)(err);
144
+ }
145
+ }
146
+ return partitionOwnershipArray;
147
+ }
148
+ /**
149
+ * Lists all the checkpoints in a data store for a given namespace, eventhub and consumer group.
150
+ *
151
+ * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to
152
+ * <yournamespace>.servicebus.windows.net.
153
+ * @param eventHubName - The event hub name.
154
+ * @param consumerGroup - The consumer group name.
155
+ * @param options - A set of options that can be specified to influence the behavior of this method.
156
+ * - `abortSignal`: A signal used to request operation cancellation.
157
+ * - `tracingOptions`: Options for configuring tracing.
158
+ */
159
+ async listCheckpoints(fullyQualifiedNamespace, eventHubName, consumerGroup) {
160
+ var _a, e_2, _b, _c;
161
+ const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`;
162
+ const checkpoints = [];
163
+ const entitiesIter = this._tableClient.listEntities({
164
+ queryOptions: { filter: (0, data_tables_1.odata) `PartitionKey eq ${partitionKey}` },
165
+ });
166
+ try {
167
+ for (var _d = true, entitiesIter_2 = tslib_1.__asyncValues(entitiesIter), entitiesIter_2_1; entitiesIter_2_1 = await entitiesIter_2.next(), _a = entitiesIter_2_1.done, !_a; _d = true) {
168
+ _c = entitiesIter_2_1.value;
169
+ _d = false;
170
+ const entity = _c;
171
+ checkpoints.push({
172
+ consumerGroup,
173
+ eventHubName,
174
+ fullyQualifiedNamespace,
175
+ partitionId: entity.rowKey,
176
+ offset: parseInt(entity.offset, 10),
177
+ sequenceNumber: parseInt(entity.sequencenumber, 10),
178
+ });
179
+ }
180
+ }
181
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
182
+ finally {
183
+ try {
184
+ if (!_d && !_a && (_b = entitiesIter_2.return)) await _b.call(entitiesIter_2);
185
+ }
186
+ finally { if (e_2) throw e_2.error; }
187
+ }
188
+ return checkpoints;
189
+ }
190
+ /**
191
+ * Updates the checkpoint in the data store for a partition.
192
+ *
193
+ * @param checkpoint - The checkpoint.
194
+ * @param options - A set of options that can be specified to influence the behavior of this method.
195
+ * - `abortSignal`: A signal used to request operation cancellation.
196
+ * - `tracingOptions`: Options for configuring tracing.
197
+ * @returns A promise that resolves when the checkpoint has been updated.
198
+ */
199
+ async updateCheckpoint(checkpoint) {
200
+ const partitionKey = `${checkpoint.fullyQualifiedNamespace} ${checkpoint.eventHubName} ${checkpoint.consumerGroup} Checkpoint`;
201
+ const checkpointEntity = {
202
+ partitionKey: partitionKey,
203
+ rowKey: checkpoint.partitionId,
204
+ sequencenumber: checkpoint.sequenceNumber.toString(),
205
+ offset: checkpoint.offset.toString(),
206
+ };
207
+ try {
208
+ await this._tableClient.upsertEntity(checkpointEntity);
209
+ log_js_1.logger.verbose(`Updated checkpoint successfully for partition: ${checkpoint.partitionId}`);
210
+ return;
211
+ }
212
+ catch (err) {
213
+ log_js_1.logger.verbose(`Error occurred while updating the checkpoint for partition: ${checkpoint.partitionId}.`, err.message);
214
+ throw err;
215
+ }
216
+ }
217
+ }
218
+ exports.TableCheckpointStore = TableCheckpointStore;
219
+ //# sourceMappingURL=tableCheckpointStore.js.map