const { TableClient } =require('@azure/data-tables');constgetClient= (tableName) => {constclient=TableClient.fromConnectionString(process.env.AZURE_STORAGE_CONNECTION_STRING, tableName );return client;};constazureTableStorageService= {deleteEntityAsync:async (tableName, partitionKey, rowKey) => {constclient=getClient(tableName);awaitclient.deleteEntity(partitionKey, rowKey); },getEntityAsync:async (tableName, partitionKey, rowKey) => {constclient=getClient(tableName);returnclient.getEntity(partitionKey, rowKey); },listEntitiesAsync:async (tableName, options) => {constclient=getClient(tableName);var azureResponse =awaitclient.listEntities();let iterator =awaitazureResponse.byPage({ maxPageSize:options.pageSize, });for (let i =1; i <options.pageNumber; i++) iterator.next(); // Skip pageslet entities =awaititerator.next();let records =entities.value.filter((entity) =>entity.etag);// Load an extra page if we need to allow (Next Page)constentitiesNextPage=awaititerator.next();let nbNextPage =0;if (entitiesNextPage &&entitiesNextPage.value) { nbNextPage =entitiesNextPage.value.filter( (entity) =>entity.etag ).length; }// Azure Data Tables does not provide a row count.// We just inform the user there is a new page with at least x itemsconstminimumRowEstimated= (options.pageNumber -1) *options.pageSize +records.length+ nbNextPage;return { records, count: minimumRowEstimated }; },createEntityAsync:async (tableName, entity) => {constclient=getClient(tableName);delete entity['__meta__'];awaitclient.createEntity(entity);returnclient.getEntity(entity.partitionKey,entity.rowKey); },updateEntityAsync:async (tableName, entity) => {constclient=getClient(tableName);awaitclient.updateEntity(entity,'Replace');returnclient.getEntity(entity.partitionKey,entity.rowKey); },};module.exports= azureTableStorageService;