UNPKG

botbuilder-core

Version:

Core components for Microsoft Bot Builder. Components in this library can run either in a browser or on the server.

72 lines 2.3 kB
"use strict"; /** * @module botbuilder */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateChangeHash = exports.assertStoreItems = void 0; const z = __importStar(require("zod")); const storeItems = z.record(z.unknown()); /** * @internal * * @deprecated Use `zod.record(zod.unknown())` instead. */ function assertStoreItems(val, ..._args) { storeItems.parse(val); } exports.assertStoreItems = assertStoreItems; /** * Utility function to calculate a change hash for a `StoreItem`. * * @remarks * This example calculates a change hash for an object that's been read in and then only writes it * back out if it's been modified: * * ```JavaScript * // Calculate state objects initial hash * const hash = calculateChangeHash(state); * * // Process the received activity * await processActivity(context, state); * * // Save state if changed * if (calculateChangeHash(state) !== hash) { * await storage.write({ 'botState': state }); * } * ``` * * @param item Item to calculate the change hash for. * @returns change hash string */ function calculateChangeHash(item) { const cpy = Object.assign({}, item); if (cpy.eTag) { delete cpy.eTag; } return JSON.stringify(cpy); } exports.calculateChangeHash = calculateChangeHash; //# sourceMappingURL=storage.js.map