UNPKG

@azure-utils/storybooks

Version:

Utils to upload and manage Storybooks via Azure Functions and storage.

42 lines (40 loc) 1.5 kB
import { DEFAULT_SERVICE_NAME } from "./constants-CsV1N9r4.mjs"; //#region src/utils/azure-data-tables.ts function generateProjectAzureTableName(projectId, tableSuffix) { return `${DEFAULT_SERVICE_NAME}${projectId.replace(/\W+/g, "").toUpperCase()}${tableSuffix}`; } async function listAzureTableEntities(context, tableClient, queryOptions) { const { limit, filter, select, sort = "latest" } = queryOptions || {}; try { await tableClient.createTable(); const iterator = tableClient.listEntities({ queryOptions: { filter: typeof filter === "string" ? filter : void 0, select } }); let entities = []; if (limit) for await (const page of iterator.byPage({ maxPageSize: limit })) { entities = page; break; } else for await (const page of iterator.byPage()) entities.push(...page); if (typeof filter === "function") entities = entities.filter(filter); if (sort) if (typeof sort === "function") entities.sort(sort); else switch (sort) { case "latest": entities.sort((a, b) => { if (!a.timestamp || !b.timestamp) return 0; const aDate = new Date(a.timestamp); const bDate = new Date(b.timestamp); return bDate.getTime() - aDate.getTime(); }); break; } return entities; } catch (error) { context.error(`Error listing Azure Table '${tableClient.tableName}' entities:`, error); return []; } } //#endregion export { generateProjectAzureTableName, listAzureTableEntities }; //# sourceMappingURL=azure-data-tables-MtZoiS66.mjs.map