@verdant-web/store 3.12.0 → 3.12.1
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.
package/dist/bundle/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/pad.js", "../../../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/fingerprint.browser.js", "../../../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/getRandomValue.browser.js", "../../../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/index.js", "../../../../node_modules/.pnpm/object-hash@3.0.0/node_modules/object-hash/dist/object_hash.js", "../../../../node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.es6.mjs", "../../../../node_modules/.pnpm/weak-event@2.0.5/node_modules/weak-event/dist/typed-event-interfaces.js", "../../../../node_modules/.pnpm/weak-event@2.0.5/node_modules/weak-event/src/base-event/typed-event-functional.ts", "../../../../node_modules/.pnpm/weak-event@2.0.5/node_modules/weak-event/src/base-event/base-typed-event.ts", "../../../../node_modules/.pnpm/weak-event@2.0.5/node_modules/weak-event/src/base-event/index.ts", "../../../../node_modules/.pnpm/weak-event@2.0.5/node_modules/weak-event/src/weak-event/errors.ts", "../../../../node_modules/.pnpm/weak-event@2.0.5/node_modules/weak-event/src/weak-event/weak-event-finalization.ts", "../../../../node_modules/.pnpm/weak-event@2.0.5/node_modules/weak-event/src/weak-event/weak-event.ts", "../../../../node_modules/.pnpm/weak-event@2.0.5/node_modules/weak-event/src/weak-event/index.ts", "../../../../node_modules/.pnpm/weak-event@2.0.5/node_modules/weak-event/src/index.ts", "../../src/index.ts", "../../../common/src/timestamp.ts", "../../../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/rng.js", "../../../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/regex.js", "../../../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/validate.js", "../../../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/stringify.js", "../../../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/v4.js", "../../../common/src/refs.ts", "../../../common/src/oids.ts", "../../../common/src/utils.ts", "../../../common/src/files.ts", "../../../common/src/oidsLegacy.ts", "../../../common/src/operation.ts", "../../../common/src/replica.ts", "../../../common/src/schema/fieldHelpers.ts", "../../../common/src/schema/index.ts", "../../../common/src/schema/indexFilters.ts", "../../../common/src/schema/fields.ts", "../../../common/src/schema/validation.ts", "../../../common/src/schema/children.ts", "../../../common/src/indexes.ts", "../../../common/src/migration.ts", "../../../common/src/presence.ts", "../../../common/src/patch.ts", "../../../common/src/EventSubscriber.ts", "../../../common/src/undo.ts", "../../../common/src/batching.ts", "../../../common/src/memo.ts", "../../../common/src/error.ts", "../../../common/src/authz.ts", "../../src/idb.ts", "../../src/utils/Disposable.ts", "../../src/IDBService.ts", "../../src/metadata/AckInfoStore.ts", "../../src/metadata/BaselinesStore.ts", "../../src/metadata/LocalReplicaStore.ts", "../../src/metadata/MessageCreator.ts", "../../src/metadata/OperationsStore.ts", "../../src/metadata/SchemaStore.ts", "../../src/metadata/Metadata.ts", "../../src/metadata/openMetadataDatabase.ts", "../../src/migration/db.ts", "../../src/queries/ranges.ts", "../../src/queries/dbQueries.ts", "../../src/migration/engine.ts", "../../src/migration/migrations.ts", "../../src/migration/errors.ts", "../../src/migration/paths.ts", "../../src/migration/openWIPDatabase.ts", "../../src/UndoHistory.ts", "../../src/entities/DocumentManager.ts", "../../src/files/utils.ts", "../../src/files/EntityFile.ts", "../../src/entities/EntityCache.ts", "../../src/entities/entityFieldSubscriber.ts", "../../src/entities/Entity.ts", "../../src/entities/EntityMetadata.ts", "../../src/entities/OperationBatcher.ts", "../../src/queries/QueryableStorage.ts", "../../src/entities/EntityStore.ts", "../../src/files/FileStorage.ts", "../../src/files/FileManager.ts", "../../src/migration/openQueryDatabase.ts", "../../src/queries/utils.ts", "../../src/queries/BaseQuery.ts", "../../src/queries/GetQuery.ts", "../../src/queries/FindOneQuery.ts", "../../src/queries/FindPageQuery.ts", "../../src/queries/FindInfiniteQuery.ts", "../../src/queries/FindAllQuery.ts", "../../src/queries/CollectionQueries.ts", "../../src/queries/QueryCache.ts", "../../src/sync/PresenceManager.ts", "../../src/sync/FileSync.ts", "../../src/sync/Heartbeat.ts", "../../src/sync/PushPullSync.ts", "../../../../node_modules/.pnpm/jwt-decode@3.1.2/node_modules/jwt-decode/lib/atob.js", "../../../../node_modules/.pnpm/jwt-decode@3.1.2/node_modules/jwt-decode/lib/base64_url_decode.js", "../../../../node_modules/.pnpm/jwt-decode@3.1.2/node_modules/jwt-decode/lib/index.js", "../../src/sync/ServerSyncEndpointProvider.ts", "../../src/BackoffScheduler.ts", "../../src/sync/WebSocketSync.ts", "../../src/sync/background.ts", "../../src/sync/Sync.ts", "../../src/utils/versions.ts", "../../src/client/Client.ts", "../../src/FakeWeakRef.ts", "../../src/client/constants.ts", "../../src/client/ClientDescriptor.ts", "../../src/utils/id.ts", "../../src/authorization.ts", "../../src/sync/cliSync.ts", "../../src/vanilla.ts"],
|
|
4
|
-
"sourcesContent": ["module.exports = function pad (num, size) {\n var s = '000000000' + num;\n return s.substr(s.length - size);\n};\n", "var pad = require('./pad.js');\n\nvar env = typeof window === 'object' ? window : self;\nvar globalCount = Object.keys(env).length;\nvar mimeTypesLength = navigator.mimeTypes ? navigator.mimeTypes.length : 0;\nvar clientId = pad((mimeTypesLength +\n navigator.userAgent.length).toString(36) +\n globalCount.toString(36), 4);\n\nmodule.exports = function fingerprint () {\n return clientId;\n};\n", "\nvar getRandomValue;\n\nvar crypto = typeof window !== 'undefined' &&\n (window.crypto || window.msCrypto) ||\n typeof self !== 'undefined' &&\n self.crypto;\n\nif (crypto) {\n var lim = Math.pow(2, 32) - 1;\n getRandomValue = function () {\n return Math.abs(crypto.getRandomValues(new Uint32Array(1))[0] / lim);\n };\n} else {\n getRandomValue = Math.random;\n}\n\nmodule.exports = getRandomValue;\n", "/**\n * cuid.js\n * Collision-resistant UID generator for browsers and node.\n * Sequential for fast db lookups and recency sorting.\n * Safe for element IDs and server-side lookups.\n *\n * Extracted from CLCTR\n *\n * Copyright (c) Eric Elliott 2012\n * MIT License\n */\n\nvar fingerprint = require('./lib/fingerprint.js');\nvar pad = require('./lib/pad.js');\nvar getRandomValue = require('./lib/getRandomValue.js');\n\nvar c = 0,\n blockSize = 4,\n base = 36,\n discreteValues = Math.pow(base, blockSize);\n\nfunction randomBlock () {\n return pad((getRandomValue() *\n discreteValues << 0)\n .toString(base), blockSize);\n}\n\nfunction safeCounter () {\n c = c < discreteValues ? c : 0;\n c++; // this is not subliminal\n return c - 1;\n}\n\nfunction cuid () {\n // Starting with a lowercase letter makes\n // it HTML element ID friendly.\n var letter = 'c', // hard-coded allows for sequential access\n\n // timestamp\n // warning: this exposes the exact date and time\n // that the uid was created.\n timestamp = (new Date().getTime()).toString(base),\n\n // Prevent same-machine collisions.\n counter = pad(safeCounter().toString(base), blockSize),\n\n // A few chars to generate distinct ids for different\n // clients (so different computers are far less\n // likely to generate the same id)\n print = fingerprint(),\n\n // Grab some more chars from Math.random()\n random = randomBlock() + randomBlock();\n\n return letter + timestamp + counter + print + random;\n}\n\ncuid.slug = function slug () {\n var date = new Date().getTime().toString(36),\n counter = safeCounter().toString(36).slice(-4),\n print = fingerprint().slice(0, 1) +\n fingerprint().slice(-1),\n random = randomBlock().slice(-2);\n\n return date.slice(-2) +\n counter + print + random;\n};\n\ncuid.isCuid = function isCuid (stringToCheck) {\n if (typeof stringToCheck !== 'string') return false;\n if (stringToCheck.startsWith('c')) return true;\n return false;\n};\n\ncuid.isSlug = function isSlug (stringToCheck) {\n if (typeof stringToCheck !== 'string') return false;\n var stringLength = stringToCheck.length;\n if (stringLength >= 7 && stringLength <= 10) return true;\n return false;\n};\n\ncuid.fingerprint = fingerprint;\n\nmodule.exports = cuid;\n", "!function(e){var t;\"object\"==typeof exports?module.exports=e():\"function\"==typeof define&&define.amd?define(e):(\"undefined\"!=typeof window?t=window:\"undefined\"!=typeof global?t=global:\"undefined\"!=typeof self&&(t=self),t.objectHash=e())}(function(){return function r(o,i,u){function s(n,e){if(!i[n]){if(!o[n]){var t=\"function\"==typeof require&&require;if(!e&&t)return t(n,!0);if(a)return a(n,!0);throw new Error(\"Cannot find module '\"+n+\"'\")}e=i[n]={exports:{}};o[n][0].call(e.exports,function(e){var t=o[n][1][e];return s(t||e)},e,e.exports,r,o,i,u)}return i[n].exports}for(var a=\"function\"==typeof require&&require,e=0;e<u.length;e++)s(u[e]);return s}({1:[function(w,b,m){!function(e,n,s,c,d,h,p,g,y){\"use strict\";var r=w(\"crypto\");function t(e,t){t=u(e,t);var n;return void 0===(n=\"passthrough\"!==t.algorithm?r.createHash(t.algorithm):new l).write&&(n.write=n.update,n.end=n.update),f(t,n).dispatch(e),n.update||n.end(\"\"),n.digest?n.digest(\"buffer\"===t.encoding?void 0:t.encoding):(e=n.read(),\"buffer\"!==t.encoding?e.toString(t.encoding):e)}(m=b.exports=t).sha1=function(e){return t(e)},m.keys=function(e){return t(e,{excludeValues:!0,algorithm:\"sha1\",encoding:\"hex\"})},m.MD5=function(e){return t(e,{algorithm:\"md5\",encoding:\"hex\"})},m.keysMD5=function(e){return t(e,{algorithm:\"md5\",encoding:\"hex\",excludeValues:!0})};var o=r.getHashes?r.getHashes().slice():[\"sha1\",\"md5\"],i=(o.push(\"passthrough\"),[\"buffer\",\"hex\",\"binary\",\"base64\"]);function u(e,t){var n={};if(n.algorithm=(t=t||{}).algorithm||\"sha1\",n.encoding=t.encoding||\"hex\",n.excludeValues=!!t.excludeValues,n.algorithm=n.algorithm.toLowerCase(),n.encoding=n.encoding.toLowerCase(),n.ignoreUnknown=!0===t.ignoreUnknown,n.respectType=!1!==t.respectType,n.respectFunctionNames=!1!==t.respectFunctionNames,n.respectFunctionProperties=!1!==t.respectFunctionProperties,n.unorderedArrays=!0===t.unorderedArrays,n.unorderedSets=!1!==t.unorderedSets,n.unorderedObjects=!1!==t.unorderedObjects,n.replacer=t.replacer||void 0,n.excludeKeys=t.excludeKeys||void 0,void 0===e)throw new Error(\"Object argument required.\");for(var r=0;r<o.length;++r)o[r].toLowerCase()===n.algorithm.toLowerCase()&&(n.algorithm=o[r]);if(-1===o.indexOf(n.algorithm))throw new Error('Algorithm \"'+n.algorithm+'\" not supported. supported values: '+o.join(\", \"));if(-1===i.indexOf(n.encoding)&&\"passthrough\"!==n.algorithm)throw new Error('Encoding \"'+n.encoding+'\" not supported. supported values: '+i.join(\", \"));return n}function a(e){if(\"function\"==typeof e)return null!=/^function\\s+\\w*\\s*\\(\\s*\\)\\s*{\\s+\\[native code\\]\\s+}$/i.exec(Function.prototype.toString.call(e))}function f(o,t,i){i=i||[];function u(e){return t.update?t.update(e,\"utf8\"):t.write(e,\"utf8\")}return{dispatch:function(e){return this[\"_\"+(null===(e=o.replacer?o.replacer(e):e)?\"null\":typeof e)](e)},_object:function(t){var n,e=Object.prototype.toString.call(t),r=/\\[object (.*)\\]/i.exec(e);r=(r=r?r[1]:\"unknown:[\"+e+\"]\").toLowerCase();if(0<=(e=i.indexOf(t)))return this.dispatch(\"[CIRCULAR:\"+e+\"]\");if(i.push(t),void 0!==s&&s.isBuffer&&s.isBuffer(t))return u(\"buffer:\"),u(t);if(\"object\"===r||\"function\"===r||\"asyncfunction\"===r)return e=Object.keys(t),o.unorderedObjects&&(e=e.sort()),!1===o.respectType||a(t)||e.splice(0,0,\"prototype\",\"__proto__\",\"constructor\"),o.excludeKeys&&(e=e.filter(function(e){return!o.excludeKeys(e)})),u(\"object:\"+e.length+\":\"),n=this,e.forEach(function(e){n.dispatch(e),u(\":\"),o.excludeValues||n.dispatch(t[e]),u(\",\")});if(!this[\"_\"+r]){if(o.ignoreUnknown)return u(\"[\"+r+\"]\");throw new Error('Unknown object type \"'+r+'\"')}this[\"_\"+r](t)},_array:function(e,t){t=void 0!==t?t:!1!==o.unorderedArrays;var n=this;if(u(\"array:\"+e.length+\":\"),!t||e.length<=1)return e.forEach(function(e){return n.dispatch(e)});var r=[],t=e.map(function(e){var t=new l,n=i.slice();return f(o,t,n).dispatch(e),r=r.concat(n.slice(i.length)),t.read().toString()});return i=i.concat(r),t.sort(),this._array(t,!1)},_date:function(e){return u(\"date:\"+e.toJSON())},_symbol:function(e){return u(\"symbol:\"+e.toString())},_error:function(e){return u(\"error:\"+e.toString())},_boolean:function(e){return u(\"bool:\"+e.toString())},_string:function(e){u(\"string:\"+e.length+\":\"),u(e.toString())},_function:function(e){u(\"fn:\"),a(e)?this.dispatch(\"[native]\"):this.dispatch(e.toString()),!1!==o.respectFunctionNames&&this.dispatch(\"function-name:\"+String(e.name)),o.respectFunctionProperties&&this._object(e)},_number:function(e){return u(\"number:\"+e.toString())},_xml:function(e){return u(\"xml:\"+e.toString())},_null:function(){return u(\"Null\")},_undefined:function(){return u(\"Undefined\")},_regexp:function(e){return u(\"regex:\"+e.toString())},_uint8array:function(e){return u(\"uint8array:\"),this.dispatch(Array.prototype.slice.call(e))},_uint8clampedarray:function(e){return u(\"uint8clampedarray:\"),this.dispatch(Array.prototype.slice.call(e))},_int8array:function(e){return u(\"int8array:\"),this.dispatch(Array.prototype.slice.call(e))},_uint16array:function(e){return u(\"uint16array:\"),this.dispatch(Array.prototype.slice.call(e))},_int16array:function(e){return u(\"int16array:\"),this.dispatch(Array.prototype.slice.call(e))},_uint32array:function(e){return u(\"uint32array:\"),this.dispatch(Array.prototype.slice.call(e))},_int32array:function(e){return u(\"int32array:\"),this.dispatch(Array.prototype.slice.call(e))},_float32array:function(e){return u(\"float32array:\"),this.dispatch(Array.prototype.slice.call(e))},_float64array:function(e){return u(\"float64array:\"),this.dispatch(Array.prototype.slice.call(e))},_arraybuffer:function(e){return u(\"arraybuffer:\"),this.dispatch(new Uint8Array(e))},_url:function(e){return u(\"url:\"+e.toString())},_map:function(e){u(\"map:\");e=Array.from(e);return this._array(e,!1!==o.unorderedSets)},_set:function(e){u(\"set:\");e=Array.from(e);return this._array(e,!1!==o.unorderedSets)},_file:function(e){return u(\"file:\"),this.dispatch([e.name,e.size,e.type,e.lastModfied])},_blob:function(){if(o.ignoreUnknown)return u(\"[blob]\");throw Error('Hashing Blob objects is currently not supported\\n(see https://github.com/puleos/object-hash/issues/26)\\nUse \"options.replacer\" or \"options.ignoreUnknown\"\\n')},_domwindow:function(){return u(\"domwindow\")},_bigint:function(e){return u(\"bigint:\"+e.toString())},_process:function(){return u(\"process\")},_timer:function(){return u(\"timer\")},_pipe:function(){return u(\"pipe\")},_tcp:function(){return u(\"tcp\")},_udp:function(){return u(\"udp\")},_tty:function(){return u(\"tty\")},_statwatcher:function(){return u(\"statwatcher\")},_securecontext:function(){return u(\"securecontext\")},_connection:function(){return u(\"connection\")},_zlib:function(){return u(\"zlib\")},_context:function(){return u(\"context\")},_nodescript:function(){return u(\"nodescript\")},_httpparser:function(){return u(\"httpparser\")},_dataview:function(){return u(\"dataview\")},_signal:function(){return u(\"signal\")},_fsevent:function(){return u(\"fsevent\")},_tlswrap:function(){return u(\"tlswrap\")}}}function l(){return{buf:\"\",write:function(e){this.buf+=e},end:function(e){this.buf+=e},read:function(){return this.buf}}}m.writeToStream=function(e,t,n){return void 0===n&&(n=t,t={}),f(t=u(e,t),n).dispatch(e)}}.call(this,w(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},w(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/fake_9a5aa49d.js\",\"/\")},{buffer:3,crypto:5,lYpoI2:11}],2:[function(e,t,f){!function(e,t,n,r,o,i,u,s,a){!function(e){\"use strict\";var a=\"undefined\"!=typeof Uint8Array?Uint8Array:Array,t=\"+\".charCodeAt(0),n=\"/\".charCodeAt(0),r=\"0\".charCodeAt(0),o=\"a\".charCodeAt(0),i=\"A\".charCodeAt(0),u=\"-\".charCodeAt(0),s=\"_\".charCodeAt(0);function f(e){e=e.charCodeAt(0);return e===t||e===u?62:e===n||e===s?63:e<r?-1:e<r+10?e-r+26+26:e<i+26?e-i:e<o+26?e-o+26:void 0}e.toByteArray=function(e){var t,n;if(0<e.length%4)throw new Error(\"Invalid string. Length must be a multiple of 4\");var r=e.length,r=\"=\"===e.charAt(r-2)?2:\"=\"===e.charAt(r-1)?1:0,o=new a(3*e.length/4-r),i=0<r?e.length-4:e.length,u=0;function s(e){o[u++]=e}for(t=0;t<i;t+=4,0)s((16711680&(n=f(e.charAt(t))<<18|f(e.charAt(t+1))<<12|f(e.charAt(t+2))<<6|f(e.charAt(t+3))))>>16),s((65280&n)>>8),s(255&n);return 2==r?s(255&(n=f(e.charAt(t))<<2|f(e.charAt(t+1))>>4)):1==r&&(s((n=f(e.charAt(t))<<10|f(e.charAt(t+1))<<4|f(e.charAt(t+2))>>2)>>8&255),s(255&n)),o},e.fromByteArray=function(e){var t,n,r,o,i=e.length%3,u=\"\";function s(e){return\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\".charAt(e)}for(t=0,r=e.length-i;t<r;t+=3)n=(e[t]<<16)+(e[t+1]<<8)+e[t+2],u+=s((o=n)>>18&63)+s(o>>12&63)+s(o>>6&63)+s(63&o);switch(i){case 1:u=(u+=s((n=e[e.length-1])>>2))+s(n<<4&63)+\"==\";break;case 2:u=(u=(u+=s((n=(e[e.length-2]<<8)+e[e.length-1])>>10))+s(n>>4&63))+s(n<<2&63)+\"=\"}return u}}(void 0===f?this.base64js={}:f)}.call(this,e(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},e(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js\",\"/node_modules/gulp-browserify/node_modules/base64-js/lib\")},{buffer:3,lYpoI2:11}],3:[function(O,e,H){!function(e,n,f,r,h,p,g,y,w){var a=O(\"base64-js\"),i=O(\"ieee754\");function f(e,t,n){if(!(this instanceof f))return new f(e,t,n);var r,o,i,u,s=typeof e;if(\"base64\"===t&&\"string\"==s)for(e=(u=e).trim?u.trim():u.replace(/^\\s+|\\s+$/g,\"\");e.length%4!=0;)e+=\"=\";if(\"number\"==s)r=j(e);else if(\"string\"==s)r=f.byteLength(e,t);else{if(\"object\"!=s)throw new Error(\"First argument needs to be a number, array or string.\");r=j(e.length)}if(f._useTypedArrays?o=f._augment(new Uint8Array(r)):((o=this).length=r,o._isBuffer=!0),f._useTypedArrays&&\"number\"==typeof e.byteLength)o._set(e);else if(C(u=e)||f.isBuffer(u)||u&&\"object\"==typeof u&&\"number\"==typeof u.length)for(i=0;i<r;i++)f.isBuffer(e)?o[i]=e.readUInt8(i):o[i]=e[i];else if(\"string\"==s)o.write(e,0,t);else if(\"number\"==s&&!f._useTypedArrays&&!n)for(i=0;i<r;i++)o[i]=0;return o}function b(e,t,n,r){return f._charsWritten=c(function(e){for(var t=[],n=0;n<e.length;n++)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function m(e,t,n,r){return f._charsWritten=c(function(e){for(var t,n,r=[],o=0;o<e.length;o++)n=e.charCodeAt(o),t=n>>8,n=n%256,r.push(n),r.push(t);return r}(t),e,n,r)}function v(e,t,n){var r=\"\";n=Math.min(e.length,n);for(var o=t;o<n;o++)r+=String.fromCharCode(e[o]);return r}function o(e,t,n,r){r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(null!=t,\"missing offset\"),d(t+1<e.length,\"Trying to read beyond buffer length\"));var o,r=e.length;if(!(r<=t))return n?(o=e[t],t+1<r&&(o|=e[t+1]<<8)):(o=e[t]<<8,t+1<r&&(o|=e[t+1])),o}function u(e,t,n,r){r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(null!=t,\"missing offset\"),d(t+3<e.length,\"Trying to read beyond buffer length\"));var o,r=e.length;if(!(r<=t))return n?(t+2<r&&(o=e[t+2]<<16),t+1<r&&(o|=e[t+1]<<8),o|=e[t],t+3<r&&(o+=e[t+3]<<24>>>0)):(t+1<r&&(o=e[t+1]<<16),t+2<r&&(o|=e[t+2]<<8),t+3<r&&(o|=e[t+3]),o+=e[t]<<24>>>0),o}function _(e,t,n,r){if(r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(null!=t,\"missing offset\"),d(t+1<e.length,\"Trying to read beyond buffer length\")),!(e.length<=t))return r=o(e,t,n,!0),32768&r?-1*(65535-r+1):r}function E(e,t,n,r){if(r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(null!=t,\"missing offset\"),d(t+3<e.length,\"Trying to read beyond buffer length\")),!(e.length<=t))return r=u(e,t,n,!0),2147483648&r?-1*(4294967295-r+1):r}function I(e,t,n,r){return r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(t+3<e.length,\"Trying to read beyond buffer length\")),i.read(e,t,n,23,4)}function A(e,t,n,r){return r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(t+7<e.length,\"Trying to read beyond buffer length\")),i.read(e,t,n,52,8)}function s(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+1<e.length,\"trying to write beyond buffer length\"),Y(t,65535));o=e.length;if(!(o<=n))for(var i=0,u=Math.min(o-n,2);i<u;i++)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function l(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+3<e.length,\"trying to write beyond buffer length\"),Y(t,4294967295));o=e.length;if(!(o<=n))for(var i=0,u=Math.min(o-n,4);i<u;i++)e[n+i]=t>>>8*(r?i:3-i)&255}function B(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+1<e.length,\"Trying to write beyond buffer length\"),F(t,32767,-32768)),e.length<=n||s(e,0<=t?t:65535+t+1,n,r,o)}function L(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+3<e.length,\"Trying to write beyond buffer length\"),F(t,2147483647,-2147483648)),e.length<=n||l(e,0<=t?t:4294967295+t+1,n,r,o)}function U(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+3<e.length,\"Trying to write beyond buffer length\"),D(t,34028234663852886e22,-34028234663852886e22)),e.length<=n||i.write(e,t,n,r,23,4)}function x(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+7<e.length,\"Trying to write beyond buffer length\"),D(t,17976931348623157e292,-17976931348623157e292)),e.length<=n||i.write(e,t,n,r,52,8)}H.Buffer=f,H.SlowBuffer=f,H.INSPECT_MAX_BYTES=50,f.poolSize=8192,f._useTypedArrays=function(){try{var e=new ArrayBuffer(0),t=new Uint8Array(e);return t.foo=function(){return 42},42===t.foo()&&\"function\"==typeof t.subarray}catch(e){return!1}}(),f.isEncoding=function(e){switch(String(e).toLowerCase()){case\"hex\":case\"utf8\":case\"utf-8\":case\"ascii\":case\"binary\":case\"base64\":case\"raw\":case\"ucs2\":case\"ucs-2\":case\"utf16le\":case\"utf-16le\":return!0;default:return!1}},f.isBuffer=function(e){return!(null==e||!e._isBuffer)},f.byteLength=function(e,t){var n;switch(e+=\"\",t||\"utf8\"){case\"hex\":n=e.length/2;break;case\"utf8\":case\"utf-8\":n=T(e).length;break;case\"ascii\":case\"binary\":case\"raw\":n=e.length;break;case\"base64\":n=M(e).length;break;case\"ucs2\":case\"ucs-2\":case\"utf16le\":case\"utf-16le\":n=2*e.length;break;default:throw new Error(\"Unknown encoding\")}return n},f.concat=function(e,t){if(d(C(e),\"Usage: Buffer.concat(list, [totalLength])\\nlist should be an Array.\"),0===e.length)return new f(0);if(1===e.length)return e[0];if(\"number\"!=typeof t)for(o=t=0;o<e.length;o++)t+=e[o].length;for(var n=new f(t),r=0,o=0;o<e.length;o++){var i=e[o];i.copy(n,r),r+=i.length}return n},f.prototype.write=function(e,t,n,r){isFinite(t)?isFinite(n)||(r=n,n=void 0):(a=r,r=t,t=n,n=a),t=Number(t)||0;var o,i,u,s,a=this.length-t;switch((!n||a<(n=Number(n)))&&(n=a),r=String(r||\"utf8\").toLowerCase()){case\"hex\":o=function(e,t,n,r){n=Number(n)||0;var o=e.length-n;(!r||o<(r=Number(r)))&&(r=o),d((o=t.length)%2==0,\"Invalid hex string\"),o/2<r&&(r=o/2);for(var i=0;i<r;i++){var u=parseInt(t.substr(2*i,2),16);d(!isNaN(u),\"Invalid hex string\"),e[n+i]=u}return f._charsWritten=2*i,i}(this,e,t,n);break;case\"utf8\":case\"utf-8\":i=this,u=t,s=n,o=f._charsWritten=c(T(e),i,u,s);break;case\"ascii\":case\"binary\":o=b(this,e,t,n);break;case\"base64\":i=this,u=t,s=n,o=f._charsWritten=c(M(e),i,u,s);break;case\"ucs2\":case\"ucs-2\":case\"utf16le\":case\"utf-16le\":o=m(this,e,t,n);break;default:throw new Error(\"Unknown encoding\")}return o},f.prototype.toString=function(e,t,n){var r,o,i,u,s=this;if(e=String(e||\"utf8\").toLowerCase(),t=Number(t)||0,(n=void 0!==n?Number(n):s.length)===t)return\"\";switch(e){case\"hex\":r=function(e,t,n){var r=e.length;(!t||t<0)&&(t=0);(!n||n<0||r<n)&&(n=r);for(var o=\"\",i=t;i<n;i++)o+=k(e[i]);return o}(s,t,n);break;case\"utf8\":case\"utf-8\":r=function(e,t,n){var r=\"\",o=\"\";n=Math.min(e.length,n);for(var i=t;i<n;i++)e[i]<=127?(r+=N(o)+String.fromCharCode(e[i]),o=\"\"):o+=\"%\"+e[i].toString(16);return r+N(o)}(s,t,n);break;case\"ascii\":case\"binary\":r=v(s,t,n);break;case\"base64\":o=s,u=n,r=0===(i=t)&&u===o.length?a.fromByteArray(o):a.fromByteArray(o.slice(i,u));break;case\"ucs2\":case\"ucs-2\":case\"utf16le\":case\"utf-16le\":r=function(e,t,n){for(var r=e.slice(t,n),o=\"\",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}(s,t,n);break;default:throw new Error(\"Unknown encoding\")}return r},f.prototype.toJSON=function(){return{type:\"Buffer\",data:Array.prototype.slice.call(this._arr||this,0)}},f.prototype.copy=function(e,t,n,r){if(t=t||0,(r=r||0===r?r:this.length)!==(n=n||0)&&0!==e.length&&0!==this.length){d(n<=r,\"sourceEnd < sourceStart\"),d(0<=t&&t<e.length,\"targetStart out of bounds\"),d(0<=n&&n<this.length,\"sourceStart out of bounds\"),d(0<=r&&r<=this.length,\"sourceEnd out of bounds\"),r>this.length&&(r=this.length);var o=(r=e.length-t<r-n?e.length-t+n:r)-n;if(o<100||!f._useTypedArrays)for(var i=0;i<o;i++)e[i+t]=this[i+n];else e._set(this.subarray(n,n+o),t)}},f.prototype.slice=function(e,t){var n=this.length;if(e=S(e,n,0),t=S(t,n,n),f._useTypedArrays)return f._augment(this.subarray(e,t));for(var r=t-e,o=new f(r,void 0,!0),i=0;i<r;i++)o[i]=this[i+e];return o},f.prototype.get=function(e){return console.log(\".get() is deprecated. Access using array indexes instead.\"),this.readUInt8(e)},f.prototype.set=function(e,t){return console.log(\".set() is deprecated. Access using array indexes instead.\"),this.writeUInt8(e,t)},f.prototype.readUInt8=function(e,t){if(t||(d(null!=e,\"missing offset\"),d(e<this.length,\"Trying to read beyond buffer length\")),!(e>=this.length))return this[e]},f.prototype.readUInt16LE=function(e,t){return o(this,e,!0,t)},f.prototype.readUInt16BE=function(e,t){return o(this,e,!1,t)},f.prototype.readUInt32LE=function(e,t){return u(this,e,!0,t)},f.prototype.readUInt32BE=function(e,t){return u(this,e,!1,t)},f.prototype.readInt8=function(e,t){if(t||(d(null!=e,\"missing offset\"),d(e<this.length,\"Trying to read beyond buffer length\")),!(e>=this.length))return 128&this[e]?-1*(255-this[e]+1):this[e]},f.prototype.readInt16LE=function(e,t){return _(this,e,!0,t)},f.prototype.readInt16BE=function(e,t){return _(this,e,!1,t)},f.prototype.readInt32LE=function(e,t){return E(this,e,!0,t)},f.prototype.readInt32BE=function(e,t){return E(this,e,!1,t)},f.prototype.readFloatLE=function(e,t){return I(this,e,!0,t)},f.prototype.readFloatBE=function(e,t){return I(this,e,!1,t)},f.prototype.readDoubleLE=function(e,t){return A(this,e,!0,t)},f.prototype.readDoubleBE=function(e,t){return A(this,e,!1,t)},f.prototype.writeUInt8=function(e,t,n){n||(d(null!=e,\"missing value\"),d(null!=t,\"missing offset\"),d(t<this.length,\"trying to write beyond buffer length\"),Y(e,255)),t>=this.length||(this[t]=e)},f.prototype.writeUInt16LE=function(e,t,n){s(this,e,t,!0,n)},f.prototype.writeUInt16BE=function(e,t,n){s(this,e,t,!1,n)},f.prototype.writeUInt32LE=function(e,t,n){l(this,e,t,!0,n)},f.prototype.writeUInt32BE=function(e,t,n){l(this,e,t,!1,n)},f.prototype.writeInt8=function(e,t,n){n||(d(null!=e,\"missing value\"),d(null!=t,\"missing offset\"),d(t<this.length,\"Trying to write beyond buffer length\"),F(e,127,-128)),t>=this.length||(0<=e?this.writeUInt8(e,t,n):this.writeUInt8(255+e+1,t,n))},f.prototype.writeInt16LE=function(e,t,n){B(this,e,t,!0,n)},f.prototype.writeInt16BE=function(e,t,n){B(this,e,t,!1,n)},f.prototype.writeInt32LE=function(e,t,n){L(this,e,t,!0,n)},f.prototype.writeInt32BE=function(e,t,n){L(this,e,t,!1,n)},f.prototype.writeFloatLE=function(e,t,n){U(this,e,t,!0,n)},f.prototype.writeFloatBE=function(e,t,n){U(this,e,t,!1,n)},f.prototype.writeDoubleLE=function(e,t,n){x(this,e,t,!0,n)},f.prototype.writeDoubleBE=function(e,t,n){x(this,e,t,!1,n)},f.prototype.fill=function(e,t,n){if(t=t||0,n=n||this.length,d(\"number\"==typeof(e=\"string\"==typeof(e=e||0)?e.charCodeAt(0):e)&&!isNaN(e),\"value is not a number\"),d(t<=n,\"end < start\"),n!==t&&0!==this.length){d(0<=t&&t<this.length,\"start out of bounds\"),d(0<=n&&n<=this.length,\"end out of bounds\");for(var r=t;r<n;r++)this[r]=e}},f.prototype.inspect=function(){for(var e=[],t=this.length,n=0;n<t;n++)if(e[n]=k(this[n]),n===H.INSPECT_MAX_BYTES){e[n+1]=\"...\";break}return\"<Buffer \"+e.join(\" \")+\">\"},f.prototype.toArrayBuffer=function(){if(\"undefined\"==typeof Uint8Array)throw new Error(\"Buffer.toArrayBuffer not supported in this browser\");if(f._useTypedArrays)return new f(this).buffer;for(var e=new Uint8Array(this.length),t=0,n=e.length;t<n;t+=1)e[t]=this[t];return e.buffer};var t=f.prototype;function S(e,t,n){return\"number\"!=typeof e?n:t<=(e=~~e)?t:0<=e||0<=(e+=t)?e:0}function j(e){return(e=~~Math.ceil(+e))<0?0:e}function C(e){return(Array.isArray||function(e){return\"[object Array]\"===Object.prototype.toString.call(e)})(e)}function k(e){return e<16?\"0\"+e.toString(16):e.toString(16)}function T(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<=127)t.push(e.charCodeAt(n));else for(var o=n,i=(55296<=r&&r<=57343&&n++,encodeURIComponent(e.slice(o,n+1)).substr(1).split(\"%\")),u=0;u<i.length;u++)t.push(parseInt(i[u],16))}return t}function M(e){return a.toByteArray(e)}function c(e,t,n,r){for(var o=0;o<r&&!(o+n>=t.length||o>=e.length);o++)t[o+n]=e[o];return o}function N(e){try{return decodeURIComponent(e)}catch(e){return String.fromCharCode(65533)}}function Y(e,t){d(\"number\"==typeof e,\"cannot write a non-number as a number\"),d(0<=e,\"specified a negative value for writing an unsigned value\"),d(e<=t,\"value is larger than maximum value for type\"),d(Math.floor(e)===e,\"value has a fractional component\")}function F(e,t,n){d(\"number\"==typeof e,\"cannot write a non-number as a number\"),d(e<=t,\"value larger than maximum allowed value\"),d(n<=e,\"value smaller than minimum allowed value\"),d(Math.floor(e)===e,\"value has a fractional component\")}function D(e,t,n){d(\"number\"==typeof e,\"cannot write a non-number as a number\"),d(e<=t,\"value larger than maximum allowed value\"),d(n<=e,\"value smaller than minimum allowed value\")}function d(e,t){if(!e)throw new Error(t||\"Failed assertion\")}f._augment=function(e){return e._isBuffer=!0,e._get=e.get,e._set=e.set,e.get=t.get,e.set=t.set,e.write=t.write,e.toString=t.toString,e.toLocaleString=t.toString,e.toJSON=t.toJSON,e.copy=t.copy,e.slice=t.slice,e.readUInt8=t.readUInt8,e.readUInt16LE=t.readUInt16LE,e.readUInt16BE=t.readUInt16BE,e.readUInt32LE=t.readUInt32LE,e.readUInt32BE=t.readUInt32BE,e.readInt8=t.readInt8,e.readInt16LE=t.readInt16LE,e.readInt16BE=t.readInt16BE,e.readInt32LE=t.readInt32LE,e.readInt32BE=t.readInt32BE,e.readFloatLE=t.readFloatLE,e.readFloatBE=t.readFloatBE,e.readDoubleLE=t.readDoubleLE,e.readDoubleBE=t.readDoubleBE,e.writeUInt8=t.writeUInt8,e.writeUInt16LE=t.writeUInt16LE,e.writeUInt16BE=t.writeUInt16BE,e.writeUInt32LE=t.writeUInt32LE,e.writeUInt32BE=t.writeUInt32BE,e.writeInt8=t.writeInt8,e.writeInt16LE=t.writeInt16LE,e.writeInt16BE=t.writeInt16BE,e.writeInt32LE=t.writeInt32LE,e.writeInt32BE=t.writeInt32BE,e.writeFloatLE=t.writeFloatLE,e.writeFloatBE=t.writeFloatBE,e.writeDoubleLE=t.writeDoubleLE,e.writeDoubleBE=t.writeDoubleBE,e.fill=t.fill,e.inspect=t.inspect,e.toArrayBuffer=t.toArrayBuffer,e}}.call(this,O(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},O(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/buffer/index.js\",\"/node_modules/gulp-browserify/node_modules/buffer\")},{\"base64-js\":2,buffer:3,ieee754:10,lYpoI2:11}],4:[function(c,d,e){!function(e,t,a,n,r,o,i,u,s){var a=c(\"buffer\").Buffer,f=4,l=new a(f);l.fill(0);d.exports={hash:function(e,t,n,r){for(var o=t(function(e,t){e.length%f!=0&&(n=e.length+(f-e.length%f),e=a.concat([e,l],n));for(var n,r=[],o=t?e.readInt32BE:e.readInt32LE,i=0;i<e.length;i+=f)r.push(o.call(e,i));return r}(e=a.isBuffer(e)?e:new a(e),r),8*e.length),t=r,i=new a(n),u=t?i.writeInt32BE:i.writeInt32LE,s=0;s<o.length;s++)u.call(i,o[s],4*s,!0);return i}}}.call(this,c(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},c(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/helpers.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{buffer:3,lYpoI2:11}],5:[function(v,e,_){!function(l,c,u,d,h,p,g,y,w){var u=v(\"buffer\").Buffer,e=v(\"./sha\"),t=v(\"./sha256\"),n=v(\"./rng\"),b={sha1:e,sha256:t,md5:v(\"./md5\")},s=64,a=new u(s);function r(e,n){var r=b[e=e||\"sha1\"],o=[];return r||i(\"algorithm:\",e,\"is not yet supported\"),{update:function(e){return u.isBuffer(e)||(e=new u(e)),o.push(e),e.length,this},digest:function(e){var t=u.concat(o),t=n?function(e,t,n){u.isBuffer(t)||(t=new u(t)),u.isBuffer(n)||(n=new u(n)),t.length>s?t=e(t):t.length<s&&(t=u.concat([t,a],s));for(var r=new u(s),o=new u(s),i=0;i<s;i++)r[i]=54^t[i],o[i]=92^t[i];return n=e(u.concat([r,n])),e(u.concat([o,n]))}(r,n,t):r(t);return o=null,e?t.toString(e):t}}}function i(){var e=[].slice.call(arguments).join(\" \");throw new Error([e,\"we accept pull requests\",\"http://github.com/dominictarr/crypto-browserify\"].join(\"\\n\"))}a.fill(0),_.createHash=function(e){return r(e)},_.createHmac=r,_.randomBytes=function(e,t){if(!t||!t.call)return new u(n(e));try{t.call(this,void 0,new u(n(e)))}catch(e){t(e)}};var o,f=[\"createCredentials\",\"createCipher\",\"createCipheriv\",\"createDecipher\",\"createDecipheriv\",\"createSign\",\"createVerify\",\"createDiffieHellman\",\"pbkdf2\"],m=function(e){_[e]=function(){i(\"sorry,\",e,\"is not implemented yet\")}};for(o in f)m(f[o],o)}.call(this,v(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},v(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/index.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{\"./md5\":6,\"./rng\":7,\"./sha\":8,\"./sha256\":9,buffer:3,lYpoI2:11}],6:[function(w,b,e){!function(e,r,o,i,u,a,f,l,y){var t=w(\"./helpers\");function n(e,t){e[t>>5]|=128<<t%32,e[14+(t+64>>>9<<4)]=t;for(var n=1732584193,r=-271733879,o=-1732584194,i=271733878,u=0;u<e.length;u+=16){var s=n,a=r,f=o,l=i,n=c(n,r,o,i,e[u+0],7,-680876936),i=c(i,n,r,o,e[u+1],12,-389564586),o=c(o,i,n,r,e[u+2],17,606105819),r=c(r,o,i,n,e[u+3],22,-1044525330);n=c(n,r,o,i,e[u+4],7,-176418897),i=c(i,n,r,o,e[u+5],12,1200080426),o=c(o,i,n,r,e[u+6],17,-1473231341),r=c(r,o,i,n,e[u+7],22,-45705983),n=c(n,r,o,i,e[u+8],7,1770035416),i=c(i,n,r,o,e[u+9],12,-1958414417),o=c(o,i,n,r,e[u+10],17,-42063),r=c(r,o,i,n,e[u+11],22,-1990404162),n=c(n,r,o,i,e[u+12],7,1804603682),i=c(i,n,r,o,e[u+13],12,-40341101),o=c(o,i,n,r,e[u+14],17,-1502002290),n=d(n,r=c(r,o,i,n,e[u+15],22,1236535329),o,i,e[u+1],5,-165796510),i=d(i,n,r,o,e[u+6],9,-1069501632),o=d(o,i,n,r,e[u+11],14,643717713),r=d(r,o,i,n,e[u+0],20,-373897302),n=d(n,r,o,i,e[u+5],5,-701558691),i=d(i,n,r,o,e[u+10],9,38016083),o=d(o,i,n,r,e[u+15],14,-660478335),r=d(r,o,i,n,e[u+4],20,-405537848),n=d(n,r,o,i,e[u+9],5,568446438),i=d(i,n,r,o,e[u+14],9,-1019803690),o=d(o,i,n,r,e[u+3],14,-187363961),r=d(r,o,i,n,e[u+8],20,1163531501),n=d(n,r,o,i,e[u+13],5,-1444681467),i=d(i,n,r,o,e[u+2],9,-51403784),o=d(o,i,n,r,e[u+7],14,1735328473),n=h(n,r=d(r,o,i,n,e[u+12],20,-1926607734),o,i,e[u+5],4,-378558),i=h(i,n,r,o,e[u+8],11,-2022574463),o=h(o,i,n,r,e[u+11],16,1839030562),r=h(r,o,i,n,e[u+14],23,-35309556),n=h(n,r,o,i,e[u+1],4,-1530992060),i=h(i,n,r,o,e[u+4],11,1272893353),o=h(o,i,n,r,e[u+7],16,-155497632),r=h(r,o,i,n,e[u+10],23,-1094730640),n=h(n,r,o,i,e[u+13],4,681279174),i=h(i,n,r,o,e[u+0],11,-358537222),o=h(o,i,n,r,e[u+3],16,-722521979),r=h(r,o,i,n,e[u+6],23,76029189),n=h(n,r,o,i,e[u+9],4,-640364487),i=h(i,n,r,o,e[u+12],11,-421815835),o=h(o,i,n,r,e[u+15],16,530742520),n=p(n,r=h(r,o,i,n,e[u+2],23,-995338651),o,i,e[u+0],6,-198630844),i=p(i,n,r,o,e[u+7],10,1126891415),o=p(o,i,n,r,e[u+14],15,-1416354905),r=p(r,o,i,n,e[u+5],21,-57434055),n=p(n,r,o,i,e[u+12],6,1700485571),i=p(i,n,r,o,e[u+3],10,-1894986606),o=p(o,i,n,r,e[u+10],15,-1051523),r=p(r,o,i,n,e[u+1],21,-2054922799),n=p(n,r,o,i,e[u+8],6,1873313359),i=p(i,n,r,o,e[u+15],10,-30611744),o=p(o,i,n,r,e[u+6],15,-1560198380),r=p(r,o,i,n,e[u+13],21,1309151649),n=p(n,r,o,i,e[u+4],6,-145523070),i=p(i,n,r,o,e[u+11],10,-1120210379),o=p(o,i,n,r,e[u+2],15,718787259),r=p(r,o,i,n,e[u+9],21,-343485551),n=g(n,s),r=g(r,a),o=g(o,f),i=g(i,l)}return Array(n,r,o,i)}function s(e,t,n,r,o,i){return g((t=g(g(t,e),g(r,i)))<<o|t>>>32-o,n)}function c(e,t,n,r,o,i,u){return s(t&n|~t&r,e,t,o,i,u)}function d(e,t,n,r,o,i,u){return s(t&r|n&~r,e,t,o,i,u)}function h(e,t,n,r,o,i,u){return s(t^n^r,e,t,o,i,u)}function p(e,t,n,r,o,i,u){return s(n^(t|~r),e,t,o,i,u)}function g(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}b.exports=function(e){return t.hash(e,n,16)}}.call(this,w(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},w(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/md5.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{\"./helpers\":4,buffer:3,lYpoI2:11}],7:[function(e,l,t){!function(e,t,n,r,o,i,u,s,f){var a;l.exports=a||function(e){for(var t,n=new Array(e),r=0;r<e;r++)0==(3&r)&&(t=4294967296*Math.random()),n[r]=t>>>((3&r)<<3)&255;return n}}.call(this,e(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},e(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/rng.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{buffer:3,lYpoI2:11}],8:[function(c,d,e){!function(e,t,n,r,o,s,a,f,l){var i=c(\"./helpers\");function u(l,c){l[c>>5]|=128<<24-c%32,l[15+(c+64>>9<<4)]=c;for(var e,t,n,r=Array(80),o=1732584193,i=-271733879,u=-1732584194,s=271733878,d=-1009589776,h=0;h<l.length;h+=16){for(var p=o,g=i,y=u,w=s,b=d,a=0;a<80;a++){r[a]=a<16?l[h+a]:v(r[a-3]^r[a-8]^r[a-14]^r[a-16],1);var f=m(m(v(o,5),(f=i,t=u,n=s,(e=a)<20?f&t|~f&n:!(e<40)&&e<60?f&t|f&n|t&n:f^t^n)),m(m(d,r[a]),(e=a)<20?1518500249:e<40?1859775393:e<60?-1894007588:-899497514)),d=s,s=u,u=v(i,30),i=o,o=f}o=m(o,p),i=m(i,g),u=m(u,y),s=m(s,w),d=m(d,b)}return Array(o,i,u,s,d)}function m(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function v(e,t){return e<<t|e>>>32-t}d.exports=function(e){return i.hash(e,u,20,!0)}}.call(this,c(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},c(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{\"./helpers\":4,buffer:3,lYpoI2:11}],9:[function(c,d,e){!function(e,t,n,r,u,s,a,f,l){function b(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function o(e,l){var c,d=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),t=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),n=new Array(64);e[l>>5]|=128<<24-l%32,e[15+(l+64>>9<<4)]=l;for(var r,o,h=0;h<e.length;h+=16){for(var i=t[0],u=t[1],s=t[2],p=t[3],a=t[4],g=t[5],y=t[6],w=t[7],f=0;f<64;f++)n[f]=f<16?e[f+h]:b(b(b((o=n[f-2],m(o,17)^m(o,19)^v(o,10)),n[f-7]),(o=n[f-15],m(o,7)^m(o,18)^v(o,3))),n[f-16]),c=b(b(b(b(w,m(o=a,6)^m(o,11)^m(o,25)),a&g^~a&y),d[f]),n[f]),r=b(m(r=i,2)^m(r,13)^m(r,22),i&u^i&s^u&s),w=y,y=g,g=a,a=b(p,c),p=s,s=u,u=i,i=b(c,r);t[0]=b(i,t[0]),t[1]=b(u,t[1]),t[2]=b(s,t[2]),t[3]=b(p,t[3]),t[4]=b(a,t[4]),t[5]=b(g,t[5]),t[6]=b(y,t[6]),t[7]=b(w,t[7])}return t}var i=c(\"./helpers\"),m=function(e,t){return e>>>t|e<<32-t},v=function(e,t){return e>>>t};d.exports=function(e){return i.hash(e,o,32,!0)}}.call(this,c(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},c(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha256.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{\"./helpers\":4,buffer:3,lYpoI2:11}],10:[function(e,t,f){!function(e,t,n,r,o,i,u,s,a){f.read=function(e,t,n,r,o){var i,u,l=8*o-r-1,c=(1<<l)-1,d=c>>1,s=-7,a=n?o-1:0,f=n?-1:1,o=e[t+a];for(a+=f,i=o&(1<<-s)-1,o>>=-s,s+=l;0<s;i=256*i+e[t+a],a+=f,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=r;0<s;u=256*u+e[t+a],a+=f,s-=8);if(0===i)i=1-d;else{if(i===c)return u?NaN:1/0*(o?-1:1);u+=Math.pow(2,r),i-=d}return(o?-1:1)*u*Math.pow(2,i-r)},f.write=function(e,t,l,n,r,c){var o,i,u=8*c-r-1,s=(1<<u)-1,a=s>>1,d=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:c-1,h=n?1:-1,c=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(i=isNaN(t)?1:0,o=s):(o=Math.floor(Math.log(t)/Math.LN2),t*(n=Math.pow(2,-o))<1&&(o--,n*=2),2<=(t+=1<=o+a?d/n:d*Math.pow(2,1-a))*n&&(o++,n/=2),s<=o+a?(i=0,o=s):1<=o+a?(i=(t*n-1)*Math.pow(2,r),o+=a):(i=t*Math.pow(2,a-1)*Math.pow(2,r),o=0));8<=r;e[l+f]=255&i,f+=h,i/=256,r-=8);for(o=o<<r|i,u+=r;0<u;e[l+f]=255&o,f+=h,o/=256,u-=8);e[l+f-h]|=128*c}}.call(this,e(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},e(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/ieee754/index.js\",\"/node_modules/gulp-browserify/node_modules/ieee754\")},{buffer:3,lYpoI2:11}],11:[function(e,h,t){!function(e,t,n,r,o,f,l,c,d){var i,u,s;function a(){}(e=h.exports={}).nextTick=(u=\"undefined\"!=typeof window&&window.setImmediate,s=\"undefined\"!=typeof window&&window.postMessage&&window.addEventListener,u?function(e){return window.setImmediate(e)}:s?(i=[],window.addEventListener(\"message\",function(e){var t=e.source;t!==window&&null!==t||\"process-tick\"!==e.data||(e.stopPropagation(),0<i.length&&i.shift()())},!0),function(e){i.push(e),window.postMessage(\"process-tick\",\"*\")}):function(e){setTimeout(e,0)}),e.title=\"browser\",e.browser=!0,e.env={},e.argv=[],e.on=a,e.addListener=a,e.once=a,e.off=a,e.removeListener=a,e.removeAllListeners=a,e.emit=a,e.binding=function(e){throw new Error(\"process.binding is not supported\")},e.cwd=function(){return\"/\"},e.chdir=function(e){throw new Error(\"process.chdir is not supported\")}}.call(this,e(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},e(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/process/browser.js\",\"/node_modules/gulp-browserify/node_modules/process\")},{buffer:3,lYpoI2:11}]},{},[1])(1)});", "/******************************************************************************\nCopyright (c) Microsoft Corporation.\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\n/* global Reflect, Promise, SuppressedError, Symbol */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nexport function __extends(d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\nexport var __assign = function() {\n __assign = Object.assign || function __assign(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\n }\n return t;\n }\n return __assign.apply(this, arguments);\n}\n\nexport function __rest(s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n}\n\nexport function __decorate(decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\nexport function __param(paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n}\n\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\n var _, done = false;\n for (var i = decorators.length - 1; i >= 0; i--) {\n var context = {};\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\n if (kind === \"accessor\") {\n if (result === void 0) continue;\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\n if (_ = accept(result.get)) descriptor.get = _;\n if (_ = accept(result.set)) descriptor.set = _;\n if (_ = accept(result.init)) initializers.unshift(_);\n }\n else if (_ = accept(result)) {\n if (kind === \"field\") initializers.unshift(_);\n else descriptor[key] = _;\n }\n }\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\n done = true;\n};\n\nexport function __runInitializers(thisArg, initializers, value) {\n var useValue = arguments.length > 2;\n for (var i = 0; i < initializers.length; i++) {\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\n }\n return useValue ? value : void 0;\n};\n\nexport function __propKey(x) {\n return typeof x === \"symbol\" ? x : \"\".concat(x);\n};\n\nexport function __setFunctionName(f, name, prefix) {\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\n};\n\nexport function __metadata(metadataKey, metadataValue) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\n}\n\nexport function __awaiter(thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n}\n\nexport function __generator(thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n}\n\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\n\nexport function __exportStar(m, o) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\n}\n\nexport function __values(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n}\n\nexport function __read(o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n}\n\n/** @deprecated */\nexport function __spread() {\n for (var ar = [], i = 0; i < arguments.length; i++)\n ar = ar.concat(__read(arguments[i]));\n return ar;\n}\n\n/** @deprecated */\nexport function __spreadArrays() {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n}\n\nexport function __spreadArray(to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n}\n\nexport function __await(v) {\n return this instanceof __await ? (this.v = v, this) : new __await(v);\n}\n\nexport function __asyncGenerator(thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n}\n\nexport function __asyncDelegator(o) {\n var i, p;\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\n}\n\nexport function __asyncValues(o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator], i;\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\n}\n\nexport function __makeTemplateObject(cooked, raw) {\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\n return cooked;\n};\n\nvar __setModuleDefault = Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n};\n\nexport function __importStar(mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n}\n\nexport function __importDefault(mod) {\n return (mod && mod.__esModule) ? mod : { default: mod };\n}\n\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\n}\n\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\n}\n\nexport function __classPrivateFieldIn(state, receiver) {\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\n}\n\nexport function __addDisposableResource(env, value, async) {\n if (value !== null && value !== void 0) {\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\n var dispose;\n if (async) {\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\n dispose = value[Symbol.asyncDispose];\n }\n if (dispose === void 0) {\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\n dispose = value[Symbol.dispose];\n }\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\n env.stack.push({ value: value, dispose: dispose, async: async });\n }\n else if (async) {\n env.stack.push({ async: true });\n }\n return value;\n}\n\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\n var e = new Error(message);\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\n};\n\nexport function __disposeResources(env) {\n function fail(e) {\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\n env.hasError = true;\n }\n function next() {\n while (env.stack.length) {\n var rec = env.stack.pop();\n try {\n var result = rec.dispose && rec.dispose.call(rec.value);\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\n }\n catch (e) {\n fail(e);\n }\n }\n if (env.hasError) throw env.error;\n }\n return next();\n}\n\nexport default {\n __extends,\n __assign,\n __rest,\n __decorate,\n __param,\n __metadata,\n __awaiter,\n __generator,\n __createBinding,\n __exportStar,\n __values,\n __read,\n __spread,\n __spreadArrays,\n __spreadArray,\n __await,\n __asyncGenerator,\n __asyncDelegator,\n __asyncValues,\n __makeTemplateObject,\n __importStar,\n __importDefault,\n __classPrivateFieldGet,\n __classPrivateFieldSet,\n __classPrivateFieldIn,\n __addDisposableResource,\n __disposeResources,\n};\n", "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n//# sourceMappingURL=typed-event-interfaces.js.map", null, null, null, null, null, null, null, null, "import {\n\tClientDescriptor,\n\tClientDescriptorOptions,\n} from './client/ClientDescriptor.js';\nimport { Client } from './client/Client.js';\nexport type { ClientWithCollections } from './client/Client.js';\nexport { ClientDescriptor };\nexport { Client };\n// backward compat\nexport { ClientDescriptor as StorageDescriptor };\nexport { Client as Storage };\nexport type { ClientDescriptorOptions };\nexport type { ClientDescriptorOptions as StorageInitOptions };\nexport { Entity } from './entities/Entity.js';\nexport type {\n\tObjectEntity,\n\tListEntity,\n\tEntityShape,\n\tAccessibleEntityProperty,\n\tAnyEntity,\n\tEntityDestructured,\n\tEntityInit,\n} from './entities/types.js';\nexport { ServerSync } from './sync/Sync.js';\nexport type { SyncTransportMode } from './sync/Sync.js';\nexport { EntityFile, type EntityFileSnapshot } from './files/EntityFile.js';\nexport {\n\t/** @deprecated - use schema.collection */\n\tcollection,\n\tschema,\n\tcreateDefaultMigration,\n\tmigrate,\n\tcreateMigration,\n} from '@verdant-web/common';\nexport type {\n\tStorageDocument,\n\tStorageSchema,\n\tStorageCollectionSchema,\n\tStorageAnyFieldSchema,\n\tStorageArrayFieldSchema,\n\tStorageObjectFieldSchema,\n\tStorageBooleanFieldSchema,\n\tStorageFieldSchema,\n\tStorageFileFieldSchema,\n\tStorageMapFieldSchema,\n\tStorageNumberFieldSchema,\n\tStorageStringFieldSchema,\n\tStorageFieldsSchema,\n\tIndexValueTag,\n\tMigration,\n} from '@verdant-web/common';\nexport type { UserInfo } from '@verdant-web/common';\nexport type { Query } from './queries/types.js';\nexport type { QueryStatus } from './queries/BaseQuery.js';\nexport type { CollectionQueries } from './queries/CollectionQueries.js';\nexport { MigrationPathError } from './migration/errors.js';\nexport * from './utils/id.js';\nexport { UndoHistory } from './UndoHistory.js';\nexport * from './authorization.js';\nexport * from './sync/cliSync.js';\n", "import cuid from 'cuid';\nimport { v4 } from 'uuid';\n\nexport interface TimestampProvider {\n\tnow(version: number): string;\n\tupdate(remoteTimestamp: string): void;\n\tzero(version: number): string;\n\tgetWallClockTime(timestamp: string): number;\n}\n\nconst VERSION_BLOCK_LENGTH = 4;\nconst ENCODING_NUMBER_RADIX = 36;\n\nexport function encodeVersion(version: number | string): string {\n\treturn version\n\t\t.toString(ENCODING_NUMBER_RADIX)\n\t\t.padStart(VERSION_BLOCK_LENGTH, '0');\n}\n\nexport function OLD_encodeVersion(version: number | string): string {\n\treturn version.toString().padStart(6, '0');\n}\n\nexport class NaiveTimestampProvider implements TimestampProvider {\n\tcounter = 0;\n\tnow = (version: number | string) => {\n\t\treturn (\n\t\t\tencodeVersion(version) + Date.now().toString() + '-' + this.counter++\n\t\t);\n\t};\n\tupdate = () => {\n\t\tthis.counter = 0;\n\t};\n\tzero = (version: number | string) => {\n\t\treturn encodeVersion(version) + '0' + '-' + this.counter++;\n\t};\n\tgetWallClockTime = (timestamp: string) => {\n\t\treturn parseInt(timestamp.slice(VERSION_BLOCK_LENGTH).split('-')[0], 10);\n\t};\n}\n\nexport class HybridLogicalClockTimestampProvider implements TimestampProvider {\n\tprivate latest: HLCTimestamp = {\n\t\ttime: Date.now(),\n\t\tcounter: 0,\n\t\tnode: generateNodeId(),\n\t};\n\tprivate zeroCounter = 0;\n\n\tnow = (version: string | number) => {\n\t\tthis.latest = getHlcNow(this.latest);\n\t\treturn this.get(version, this.latest);\n\t};\n\t/**\n\t * @deprecated - use now() instead and update to latest format\n\t */\n\tOLD_now = (version: string | number) => {\n\t\tthis.latest = getHlcNow(this.latest);\n\t\treturn OLD_encodeVersion(version) + OLD_serializeHlcTimestamp(this.latest);\n\t};\n\t/** Get the current timer state. Does not increment counter. */\n\ttimerState = () => {\n\t\treturn this.latest;\n\t};\n\tupdate = (remoteTimestamp: string) => {\n\t\t// strip version from remote timestamp\n\t\tconst hlcString = remoteTimestamp.slice(VERSION_BLOCK_LENGTH);\n\t\tthis.latest = updateFromRemote(\n\t\t\tthis.latest,\n\t\t\tdeserializeHlcTimestamp(hlcString),\n\t\t);\n\t};\n\tget = (version: string | number, raw: HLCTimestamp) => {\n\t\treturn encodeVersion(version) + serializeHlcTimestamp(raw);\n\t};\n\tzero = (version: string | number) => {\n\t\treturn (\n\t\t\tencodeVersion(version) +\n\t\t\tserializeHlcTimestamp({\n\t\t\t\ttime: 0,\n\t\t\t\t// to keep zero timestamps unique, we use a counter here as well\n\t\t\t\tcounter: this.zeroCounter++,\n\t\t\t\tnode: this.latest.node,\n\t\t\t})\n\t\t);\n\t};\n\tgetWallClockTime = getWallClockTime;\n}\n\nclass ClockDriftError extends Error {\n\ttype: string;\n\tconstructor(...args: any[]) {\n\t\tsuper();\n\t\tthis.type = 'ClockDriftError';\n\t\tthis.message = ['maximum clock drift exceeded'].concat(args).join(' ');\n\t}\n}\n\nclass OverflowError extends Error {\n\ttype: string;\n\tconstructor() {\n\t\tsuper();\n\t\tthis.type = 'OverflowError';\n\t\tthis.message = 'timestamp counter overflow';\n\t}\n}\n\ninterface HLCTimestamp {\n\ttime: number;\n\tcounter: number;\n\tnode: string;\n}\n\nconst COUNTER_BLOCK_LENGTH = 4;\nconst NODE_BLOCK_LENGTH = 7;\nconst MAX_CLOCK_DRIFT = 60 * 1000;\n// 9 base36 characters should last until the year 5000\n// when encoding a unix MS timestamp\nconst TIME_BLOCK_LENGTH = 9;\n\nfunction generateNodeId() {\n\treturn cuid\n\t\t.slug()\n\t\t.padStart(NODE_BLOCK_LENGTH, '0')\n\t\t.slice(0, NODE_BLOCK_LENGTH);\n}\n\nexport function serializeHlcTimestamp(ts: HLCTimestamp): string {\n\t// string representation of the time\n\tconst dateString = new Date(ts.time)\n\t\t.getTime()\n\t\t.toString(ENCODING_NUMBER_RADIX)\n\t\t.padStart(TIME_BLOCK_LENGTH, '0');\n\t// counter, 336, padded to 4 characters\n\tconst counter = ts.counter\n\t\t.toString(ENCODING_NUMBER_RADIX)\n\t\t.padStart(COUNTER_BLOCK_LENGTH, '0');\n\t// node id padded to 16 characters\n\tconst node = ts.node.padStart(NODE_BLOCK_LENGTH, '0');\n\treturn `${dateString}${counter}${node}`;\n}\n\nfunction getHlcNow(prev: HLCTimestamp): HLCTimestamp {\n\tconst wallTime = Date.now();\n\n\t// pick prev's time if it's later than our local device\n\tconst newWallTime = Math.max(prev.time, wallTime);\n\t// reset counter if wall time changed\n\tconst newCounter = prev.time === newWallTime ? prev.counter + 1 : 0;\n\n\t// check for drift\n\tif (newWallTime - wallTime > MAX_CLOCK_DRIFT) {\n\t\tthrow new ClockDriftError(newWallTime, wallTime, MAX_CLOCK_DRIFT);\n\t}\n\t// check for counter overflow (max is 4 bytes)\n\tif (newCounter > 65535) {\n\t\tthrow new OverflowError();\n\t}\n\n\treturn {\n\t\ttime: newWallTime,\n\t\tcounter: newCounter,\n\t\tnode: prev.node,\n\t};\n}\n\nfunction updateFromRemote(\n\tlocal: HLCTimestamp,\n\tremote: HLCTimestamp,\n): HLCTimestamp {\n\tconst wallTime = Date.now();\n\t// pick remote's time if it's later than our local device\n\tconst newTime = Math.max(wallTime, Math.max(local.time, remote.time));\n\n\tconst maxCounter = Math.max(local.counter, remote.counter);\n\tlet newCounter;\n\t// if all clocks are the same, increment the counter\n\tif (local.time === newTime && remote.time === newTime) {\n\t\tnewCounter = maxCounter + 1;\n\t}\n\t// if local time is the same as new time, increment our local counter\n\telse if (local.time === newTime) {\n\t\tnewCounter = local.counter + 1;\n\t}\n\t// if remote time is the same as new time, increment remote counter\n\telse if (remote.time === newTime) {\n\t\tnewCounter = remote.counter + 1;\n\t}\n\t// otherwise, reset the counter\n\telse {\n\t\tnewCounter = 0;\n\t}\n\n\t// check for drift\n\tif (newTime - wallTime > MAX_CLOCK_DRIFT) {\n\t\tthrow new ClockDriftError(newTime, wallTime, MAX_CLOCK_DRIFT);\n\t}\n\tif (newCounter > 65535) {\n\t\tthrow new OverflowError();\n\t}\n\n\treturn {\n\t\ttime: newTime,\n\t\tcounter: newCounter,\n\t\tnode: local.node,\n\t};\n}\n\nexport function deserializeHlcTimestamp(clock: string): HLCTimestamp {\n\tconst dateString = clock.slice(0, TIME_BLOCK_LENGTH);\n\tconst counter = clock.slice(\n\t\tTIME_BLOCK_LENGTH,\n\t\tTIME_BLOCK_LENGTH + COUNTER_BLOCK_LENGTH,\n\t);\n\tconst node = clock.slice(TIME_BLOCK_LENGTH + COUNTER_BLOCK_LENGTH);\n\tconst time = parseInt(dateString, ENCODING_NUMBER_RADIX);\n\tconst counterNum = parseInt(counter, ENCODING_NUMBER_RADIX);\n\n\tif (isNaN(time) || isNaN(counterNum)) {\n\t\tthrow new Error('invalid clock format');\n\t}\n\n\treturn {\n\t\ttime,\n\t\tcounter: counterNum,\n\t\tnode,\n\t};\n}\n\nfunction removeLeadingZeroes(str: string): string {\n\treturn str.replace(/^0+/, '');\n}\n\n/**\n * Below, converters for old-style timestamps are defined.\n * These are for migrating older clients to the new format.\n */\n\n/**\n * Converts a timestamp from the old format to the new format.\n */\nexport function convertOldHlcTimestamp(ts: string): string {\n\tconst versionBlock = ts.slice(0, 6);\n\t// no jokes please\n\tconst clockBlock = ts.slice(6);\n\tconst deserialized = OLD_deserializeHlcTimestamp(clockBlock);\n\n\t// version was base 10 and now is base 36\n\tconst versionNumber = parseInt(versionBlock, 10);\n\tconst encodedVersion = encodeVersion(versionNumber);\n\treturn encodedVersion + serializeHlcTimestamp(deserialized);\n}\n\nexport function OLD_serializeHlcTimestamp(ts: HLCTimestamp): string {\n\t// ISO string representation of the time\n\tconst dateString = new Date(ts.time).toISOString();\n\t// counter, base16, padded to 4 characters\n\tconst counter = ts.counter.toString(16).toUpperCase().padStart(4, '0');\n\t// node id padded to 16 characters\n\tconst node = ts.node.padStart(16, '0');\n\treturn `${dateString}-${counter}-${node}`;\n}\n\nexport function OLD_deserializeHlcTimestamp(clock: string): HLCTimestamp {\n\t// ISO string representation of the time\n\tconst dateString = clock.slice(0, 24);\n\tconst counter = clock.slice(25, 25 + 4);\n\tconst node = clock.slice(25 + 4 + 1);\n\n\tconst time = new Date(dateString).getTime();\n\tconst counterNum = parseInt(counter, 16);\n\n\tif (isNaN(time) || isNaN(counterNum)) {\n\t\tthrow new Error('invalid clock format');\n\t}\n\n\treturn {\n\t\ttime,\n\t\tcounter: counterNum,\n\t\tnode: node.slice(node.length - 7),\n\t};\n}\n\nexport function getTimestampSchemaVersion(timestamp: string): number {\n\treturn parseInt(timestamp.slice(0, VERSION_BLOCK_LENGTH), 36);\n}\n\nexport function compareTimestampSchemaVersions(a: string, b: string) {\n\treturn getTimestampSchemaVersion(a) - getTimestampSchemaVersion(b);\n}\n\nexport function getWallClockTime(timestamp: string): number {\n\treturn deserializeHlcTimestamp(timestamp.slice(VERSION_BLOCK_LENGTH)).time;\n}\n", "// Unique ID creation requires a high quality random # generator. In the browser we therefore\n// require the crypto API and do not support built-in fallback to lower quality random number\n// generators (like Math.random()).\nvar getRandomValues;\nvar rnds8 = new Uint8Array(16);\nexport default function rng() {\n // lazy load so that environments that need to polyfill have a chance to do so\n if (!getRandomValues) {\n // getRandomValues needs to be invoked in a context where \"this\" is a Crypto implementation. Also,\n // find the complete implementation of crypto (msCrypto) on IE11.\n getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);\n\n if (!getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n }\n\n return getRandomValues(rnds8);\n}", "export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;", "import REGEX from './regex.js';\n\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\n\nexport default validate;", "import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nvar byteToHex = [];\n\nfor (var i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).substr(1));\n}\n\nfunction stringify(arr) {\n var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;", "import rng from './rng.js';\nimport stringify from './stringify.js';\n\nfunction v4(options, buf, offset) {\n options = options || {};\n var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (var i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return stringify(rnds);\n}\n\nexport default v4;", "import { FileRef, isFileRef } from './files.js';\nimport { isObjectRef, ObjectRef } from './operation.js';\n\nexport function isRef(obj: any): obj is ObjectRef | FileRef {\n\treturn isObjectRef(obj) || isFileRef(obj);\n}\n\nexport function compareRefs(a: any, b: any) {\n\tif (a === b) return true;\n\tif (!isRef(a) || !isRef(b)) return false;\n\tif (a['@@type'] !== b['@@type']) return false;\n\tif (a.id !== b.id) return false;\n\treturn true;\n}\n\nexport type Ref = ObjectRef | FileRef;\n\nexport function makeObjectRef(oid: string): ObjectRef {\n\treturn { '@@type': 'ref', id: oid };\n}\n\nexport function makeFileRef(oid: string): FileRef {\n\treturn { '@@type': 'file', id: oid };\n}\n", "import { v4 } from 'uuid';\nimport { isFileRef } from './files.js';\nimport { isObjectRef, ObjectRef } from './operation.js';\nimport { isRef } from './refs.js';\nimport { isObject, assert } from './utils.js';\n\n/**\n * OIDs\n *\n * OIDs are used to identify objects in the document. They also encode\n * information about the object useful to identifying an object found\n * on its own and associating it back to its parent.\n *\n * An OID is structured as such:\n * <collection>/<root id>:<random>\n *\n * OIDs have a few characteristics:\n * - They include the collection name of the parent document\n * - They include the primary key of the parent document\n * - They may include a random sequence to identify sub-objects\n *\n * Collection name and document key are used to link any isolated\n * object back to its parent document.\n *\n * The random sequence allows the application to encode different\n * identities for objects at the same position in a document for\n * conflict resolution purposes\n */\n\nexport type ObjectIdentifier = string;\n\nconst SEGMENT_SEPARATOR = '/';\nconst RANDOM_SEPARATOR = ':';\n\n/**\n * This is the global, in-memory storage for all OIDs. It is used to\n * associate JS objects with OIDs without modifying the objects themselves.\n */\nconst oidMap = new WeakMap<any, ObjectIdentifier>();\n\nexport function getOid(obj: any) {\n\tconst oid = maybeGetOid(obj);\n\tassert(\n\t\t!!oid,\n\t\t`Object ${JSON.stringify(obj)} does not have an OID assigned to it`,\n\t);\n\treturn oid;\n}\n\nexport function maybeGetOid(obj: any): ObjectIdentifier | undefined {\n\tif (!isObject(obj)) {\n\t\treturn undefined;\n\t}\n\treturn oidMap.get(obj);\n}\n\nexport function assignOid(obj: any, oid: ObjectIdentifier) {\n\tassert(\n\t\tisObject(obj),\n\t\t`Only objects can be assigned OIDs, received ${JSON.stringify(obj)}`,\n\t);\n\tif (hasOid(obj)) {\n\t\tremoveOid(obj);\n\t}\n\toidMap.set(obj, oid);\n\treturn obj;\n}\n\nexport function hasOid(obj: any) {\n\treturn !!maybeGetOid(obj);\n}\n\nexport function removeOid(obj: any) {\n\toidMap.delete(obj);\n\treturn obj;\n}\n\n/**\n * For sub-objects, assign a random sub-OID if no OID\n * is already assigned.\n */\nexport function ensureOid(\n\tobj: any,\n\trootOid: ObjectIdentifier,\n\tcreateSubId?: () => string,\n) {\n\tif (!hasOid(obj)) {\n\t\tconst oid = createSubOid(rootOid, createSubId);\n\t\tassignOid(obj, oid);\n\t\treturn oid;\n\t} else {\n\t\treturn getOid(obj);\n\t}\n}\n\nexport function ensureCompatibleOid(\n\tobj: any,\n\trootOid: ObjectIdentifier,\n\tcreateSubId?: () => string,\n) {\n\tif (!hasOid(obj)) {\n\t\tconst oid = createSubOid(rootOid, createSubId);\n\t\tassignOid(obj, oid);\n\t\treturn oid;\n\t} else {\n\t\tconst existingOid = getOid(obj);\n\t\tif (!areOidsRelated(existingOid, rootOid)) {\n\t\t\tconst oid = createSubOid(rootOid, createSubId);\n\t\t\tassignOid(obj, oid);\n\t\t\treturn oid;\n\t\t} else {\n\t\t\treturn getOid(obj);\n\t\t}\n\t}\n}\n\nconst SANITIZE_PLACEHOLDERS = {\n\t'.': '˙',\n\t'/': '&slash;',\n\t':': ':',\n};\nfunction sanitizeFragment(id: string) {\n\t// replaces separator characters with placeholders\n\treturn id\n\t\t.replace(/[/]/g, SANITIZE_PLACEHOLDERS['/'])\n\t\t.replace(/[:]/g, SANITIZE_PLACEHOLDERS[':'])\n\t\t.replace(/[.]/g, SANITIZE_PLACEHOLDERS['.']);\n}\nfunction unsanitizeFragment(id: string) {\n\t// replaces placeholders with separator characters\n\treturn id\n\t\t.replace(/&slash;/g, '/')\n\t\t.replace(/:/g, ':')\n\t\t.replace(/˙/g, '.');\n}\n\n/**\n * Creates an OID for the document with a particular ID.\n * To create a sub-object OID, use createSubOid and pass\n * the root OID.\n */\nexport function createOid(\n\tcollection: string,\n\tdocumentId: string,\n\tsubId?: string,\n) {\n\tlet oid =\n\t\tsanitizeFragment(collection) +\n\t\tSEGMENT_SEPARATOR +\n\t\tsanitizeFragment(documentId);\n\tif (subId) {\n\t\toid += RANDOM_SEPARATOR + subId;\n\t}\n\treturn oid;\n}\n\nexport function createSubOid(\n\troot: ObjectIdentifier,\n\tcreateSubId: () => string = createOidSubId,\n) {\n\tconst { collection, id } = decomposeOid(root);\n\treturn createOid(collection, id, createSubId());\n}\n\nexport function decomposeOid(oid: ObjectIdentifier): {\n\tcollection: string;\n\tid: string;\n\tsubId?: string;\n} {\n\tlet [collection, coreId, ...others] = oid.split('/');\n\t// if 'others' exists, something's off, but maybe we can recover...\n\t// by assuming the last segment is the authz and bolting the rest onto coreId\n\tif (others.length) {\n\t\tconsole.error(\n\t\t\t`OID ${oid} has more than 3 segments. Attempting to parse it anyway.`,\n\t\t);\n\t\tcoreId += '/' + others.join('/');\n\t}\n\n\tconst [idOrLegacyPathId, random] = coreId.split(RANDOM_SEPARATOR);\n\n\tlet id;\n\t// legacy path handling. shouldn't be necessary anymore.\n\tif (idOrLegacyPathId.includes('.')) {\n\t\tid = idOrLegacyPathId.slice(0, idOrLegacyPathId.indexOf('.'));\n\t} else {\n\t\tid = idOrLegacyPathId;\n\t}\n\n\treturn {\n\t\tcollection: unsanitizeFragment(collection),\n\t\tid: unsanitizeFragment(id),\n\t\tsubId: random,\n\t};\n}\n\nexport function assertAllLevelsHaveOids(obj: any, root?: any) {\n\tassert(\n\t\tgetOid(obj),\n\t\t`Object ${JSON.stringify(obj)} must have an oid (child of ${JSON.stringify(\n\t\t\troot,\n\t\t)})`,\n\t);\n\tif (Array.isArray(obj)) {\n\t\tfor (const item of obj) {\n\t\t\tassertAllLevelsHaveOids(item, root || obj);\n\t\t}\n\t} else if (isObject(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tassertAllLevelsHaveOids(obj[key], root || obj);\n\t\t}\n\t}\n}\n\nexport function assignOidsToAllSubObjects(\n\tobj: any,\n\tcreateSubId?: () => string,\n) {\n\tconst rootOid = getOid(obj);\n\tif (Array.isArray(obj)) {\n\t\tlet item;\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\titem = obj[i];\n\t\t\tif (isObject(item) && !isRef(item)) {\n\t\t\t\tensureCompatibleOid(item, rootOid, createSubId);\n\t\t\t\tassignOidsToAllSubObjects(item, createSubId);\n\t\t\t}\n\t\t}\n\t} else if (isObject(obj) && !isRef(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tif (isObject(obj[key]) && !isRef(obj[key])) {\n\t\t\t\tensureCompatibleOid(obj[key], rootOid, createSubId);\n\t\t\t\tassignOidsToAllSubObjects(obj[key], createSubId);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function removeOidsFromAllSubObjects(obj: any) {\n\tremoveOid(obj);\n\n\tif (Array.isArray(obj)) {\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tremoveOidsFromAllSubObjects(obj[i]);\n\t\t}\n\t} else if (isObject(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tremoveOidsFromAllSubObjects(obj[key]);\n\t\t}\n\t}\n}\n\nexport function createOidSubId() {\n\treturn v4().slice(0, 8);\n}\n\nexport function createRef(oid: ObjectIdentifier): ObjectRef {\n\treturn {\n\t\t'@@type': 'ref',\n\t\tid: oid,\n\t};\n}\n\nexport function normalize(\n\tobj: any,\n\trefs: Map<ObjectIdentifier, any> = new Map(),\n): Map<ObjectIdentifier, any> {\n\tif (Array.isArray(obj)) {\n\t\tconst oid = getOid(obj);\n\t\tconst copy = assignOid([], oid);\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tconst value = obj[i];\n\t\t\tif (isObject(value)) {\n\t\t\t\tif (isObjectRef(value)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'An attempt was made to normalize an already normalized object! This is an error in verdant itself.',\n\t\t\t\t\t);\n\t\t\t\t} else if (isFileRef(value)) {\n\t\t\t\t\tcopy[i] = value;\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\tconst itemOid = getOid(value);\n\t\t\t\t\tcopy[i] = createRef(itemOid);\n\t\t\t\t\tnormalize(value, refs);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcopy[i] = value;\n\t\t\t}\n\t\t}\n\t\trefs.set(oid, copy);\n\t} else if (isObject(obj) && !isRef(obj)) {\n\t\tconst oid = getOid(obj);\n\t\tconst copy = assignOid({} as Record<string, any>, oid);\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tif (isObject(value)) {\n\t\t\t\tif (isObjectRef(value)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'An attempt was made to normalize an already normalized object! This is an error in verdant itself.',\n\t\t\t\t\t);\n\t\t\t\t} else if (isFileRef(value)) {\n\t\t\t\t\t// stop here\n\t\t\t\t\tcopy[key] = value;\n\t\t\t\t} else {\n\t\t\t\t\tconst itemOid = getOid(value);\n\t\t\t\t\tcopy[key] = createRef(itemOid);\n\t\t\t\t\tnormalize(value, refs);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcopy[key] = value;\n\t\t\t}\n\t\t}\n\t\trefs.set(oid, copy);\n\t} else if (isRef(obj)) {\n\t}\n\treturn refs;\n}\n\n/**\n * Only normalizes direct children. The created map\n * of objects will still have nested objects.\n */\nexport function normalizeFirstLevel(obj: any) {\n\tconst refs = new Map<ObjectIdentifier, any>();\n\tconst oidKeyPairs = new Map<ObjectIdentifier, string | number>();\n\tif (Array.isArray(obj)) {\n\t\tconst oid = getOid(obj);\n\t\tconst copy = assignOid([], oid);\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tconst value = obj[i];\n\t\t\tif (isObject(value)) {\n\t\t\t\tconst itemOid = getOid(value);\n\t\t\t\tcopy[i] = createRef(itemOid);\n\t\t\t\trefs.set(itemOid, value);\n\t\t\t\toidKeyPairs.set(itemOid, i);\n\t\t\t} else {\n\t\t\t\tcopy[i] = value;\n\t\t\t}\n\t\t}\n\t\trefs.set(oid, copy);\n\t} else if (isObject(obj)) {\n\t\tconst oid = getOid(obj);\n\t\tconst copy = assignOid({} as Record<string, any>, oid);\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tif (isObject(value)) {\n\t\t\t\tconst itemOid = getOid(value);\n\t\t\t\tcopy[key] = createRef(itemOid);\n\t\t\t\trefs.set(itemOid, value);\n\t\t\t\toidKeyPairs.set(itemOid, key);\n\t\t\t} else {\n\t\t\t\tcopy[key] = value;\n\t\t\t}\n\t\t}\n\t\trefs.set(oid, copy);\n\t}\n\treturn { refs, oidKeyPairs };\n}\n\nexport function getOidRoot(oid: ObjectIdentifier) {\n\treturn oid.split('.')[0].split(RANDOM_SEPARATOR)[0];\n}\n\n/**\n * Returns an inclusive range of OIDs that represent\n * all of an OID's possible sub-objects.\n */\nexport function getOidSubIdRange(oid: ObjectIdentifier) {\n\tconst root = getOidRoot(oid);\n\tconst lastSubId = createSubOid(root, () => '\\uffff');\n\treturn [`${root}${RANDOM_SEPARATOR}`, lastSubId];\n}\n\nexport function getRoots(oids: ObjectIdentifier[]) {\n\tconst set = new Set<ObjectIdentifier>();\n\tfor (const oid of oids) {\n\t\tset.add(getOidRoot(oid));\n\t}\n\treturn Array.from(set);\n}\n\nexport function areOidsRelated(oidA: ObjectIdentifier, oidB: ObjectIdentifier) {\n\treturn getOidRoot(oidA) === getOidRoot(oidB);\n}\n\nexport function isRootOid(oid: ObjectIdentifier) {\n\treturn !oid.includes(RANDOM_SEPARATOR);\n}\n\n/**\n * Recursively rewrites any OIDs in an object which are 'foreign' -\n * i.e. relate to some other object/entity - to be local to the\n * current object. This is deterministic, so it can be done\n * on multiple clients independently with predictable results.\n */\nexport function fixForeignOids(obj: any) {\n\tconst oid = maybeGetOid(obj);\n\tif (!oid) return;\n\n\tif (Array.isArray(obj)) {\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tmigrateForeignOid(oid, obj[i]);\n\t\t\tfixForeignOids(obj[i]);\n\t\t}\n\t} else if (isObject(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tmigrateForeignOid(oid, obj[key]);\n\t\t\tfixForeignOids(obj[key]);\n\t\t}\n\t}\n}\n\nfunction migrateForeignOid(parentOid: ObjectIdentifier, child: any) {\n\tconst childOid = maybeGetOid(child);\n\tif (childOid && !areOidsRelated(parentOid, childOid)) {\n\t\tconst { subId, id } = decomposeOid(childOid);\n\t\t// reuse existing subId. if child is a foreign root, use its id as subId\n\t\tassignOid(\n\t\t\tchild,\n\t\t\tcreateSubOid(parentOid, () => subId || id),\n\t\t);\n\t}\n}\n", "import { v4 } from 'uuid';\nimport { assignOid, maybeGetOid } from './oids.js';\nimport hash from 'object-hash';\n\nexport function take<T extends object, Keys extends keyof T>(\n\tobj: T,\n\tkeys: Keys[],\n): Pick<T, Keys> {\n\tconst result: any = {};\n\tfor (const key of keys) {\n\t\tresult[key] = obj[key];\n\t}\n\treturn result;\n}\n\nexport function omit<T extends object, Keys extends keyof T>(\n\tobj: T,\n\tkeys: Keys[],\n): Omit<T, Keys> {\n\tconst result: any = {};\n\tfor (const key of Object.keys(obj)) {\n\t\tif (!keys.includes(key as Keys)) {\n\t\t\tresult[key] = (obj as any)[key];\n\t\t}\n\t}\n\treturn result;\n}\n\nexport function getSortedIndex<T>(\n\tarray: T[],\n\tinsert: T,\n\tcompare: (a: T, b: T) => number,\n) {\n\tlet low = 0;\n\tlet high = array.length;\n\twhile (low < high) {\n\t\tconst mid = (low + high) >>> 1;\n\t\tconst cmp = compare(array[mid], insert);\n\t\tif (cmp < 0) {\n\t\t\tlow = mid + 1;\n\t\t} else {\n\t\t\thigh = mid;\n\t\t}\n\t}\n\treturn low;\n}\n\nfunction orderedReplacer(_: any, v: any) {\n\tif (typeof v !== 'object' || v === null || Array.isArray(v)) {\n\t\treturn v;\n\t}\n\treturn Object.fromEntries(\n\t\tObject.entries(v).sort(([ka], [kb]) => (ka < kb ? -1 : ka > kb ? 1 : 0)),\n\t);\n}\n/**\n * Consistently stringifies an object regardless\n * of key insertion order\n */\nexport function stableStringify(obj: any) {\n\treturn JSON.stringify(obj, orderedReplacer);\n}\n\n/**\n * A version of structured cloning which preserves object identity\n * references in the system.\n */\nexport function cloneDeep<T>(obj: T, copyOids = true): T {\n\tif (isObject(obj) || Array.isArray(obj)) {\n\t\tconst oid = maybeGetOid(obj);\n\t\tlet clone: any;\n\t\tif (Array.isArray(obj)) {\n\t\t\tclone = obj.map((v) => cloneDeep(v, copyOids)) as T;\n\t\t} else {\n\t\t\tclone = {};\n\t\t\tfor (const [key, value] of Object.entries(obj as any)) {\n\t\t\t\tclone[key] = cloneDeep(value, copyOids);\n\t\t\t}\n\t\t}\n\t\tif (copyOids && oid) {\n\t\t\tassignOid(clone, oid);\n\t\t}\n\t\treturn clone;\n\t}\n\treturn obj;\n}\n\n// TODO: better hash\nexport function hashObject(obj: any) {\n\t// hash the object into a unique string\n\treturn hash(obj);\n}\n\nexport function isObject(obj: any) {\n\treturn obj && typeof obj === 'object';\n}\n\nexport function roughSizeOfObject(object: any) {\n\tvar objectList = [];\n\tvar stack = [object];\n\tvar bytes = 0;\n\n\twhile (stack.length) {\n\t\tvar value = stack.pop();\n\n\t\tif (typeof value === 'boolean') {\n\t\t\tbytes += 4;\n\t\t} else if (typeof value === 'string') {\n\t\t\tbytes += value.length * 2;\n\t\t} else if (typeof value === 'number') {\n\t\t\tbytes += 8;\n\t\t} else if (typeof value === 'object' && objectList.indexOf(value) === -1) {\n\t\t\tobjectList.push(value);\n\n\t\t\tfor (var i in value) {\n\t\t\t\tstack.push(value[i]);\n\t\t\t}\n\t\t}\n\t}\n\treturn bytes;\n}\n\nexport function assert(\n\tcondition: any,\n\tmessage: string = 'assertion failed',\n): asserts condition {\n\tif (!condition) {\n\t\tthrow new Error(message);\n\t}\n}\n\nexport function generateId(length = 16) {\n\treturn v4().replace('-', '').slice(0, length);\n}\n\nexport function findLastIndex<T>(array: T[], predicate: (item: T) => boolean) {\n\tfor (let i = array.length - 1; i >= 0; i--) {\n\t\tif (predicate(array[i])) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\nexport function debounce<T extends (...args: any[]) => any>(\n\tfn: T,\n\twait: number,\n): T {\n\tlet timeout: any;\n\treturn function (this: any, ...args: any[]) {\n\t\tconst context = this;\n\t\tclearTimeout(timeout);\n\t\ttimeout = setTimeout(() => fn.apply(context, args), wait);\n\t} as any;\n}\n\nexport function throttle<T extends (...args: any[]) => any>(\n\tfn: T,\n\twait: number,\n): T {\n\tlet lastTime = 0;\n\n\t// invoke once for the last call\n\tlet trailingTimeout: any;\n\n\treturn function (this: any, ...args: any[]) {\n\t\tconst context = this;\n\t\tconst now = Date.now();\n\t\tif (now - lastTime >= wait) {\n\t\t\tlastTime = now;\n\t\t\tfn.apply(context, args);\n\t\t\tclearTimeout(trailingTimeout);\n\t\t} else {\n\t\t\tclearTimeout(trailingTimeout);\n\t\t\ttrailingTimeout = setTimeout(() => {\n\t\t\t\tlastTime = now;\n\t\t\t\tfn.apply(context, args);\n\t\t\t}, wait);\n\t\t}\n\t} as any;\n}\n", "import { isObject } from './utils.js';\n\nexport type FileRef = {\n\t'@@type': 'file';\n\tid: string;\n};\n\nexport function isFileRef(value: any): value is FileRef {\n\treturn value && value['@@type'] === 'file';\n}\nexport function createFileRef(id: string): FileRef {\n\treturn {\n\t\t'@@type': 'file',\n\t\tid,\n\t};\n}\n\nexport type FileData = {\n\tid: string;\n\t/**\n\t * For locally created files, this starts false, until it's uploaded\n\t * Remote files this is always true\n\t */\n\tremote: boolean;\n\tname: string;\n\ttype: string;\n\t/** A local File instance, if available. */\n\tfile?: Blob;\n\t/** The server URL of this file. */\n\turl?: string;\n};\n\nexport function getAllFileFields(snapshot: any): [string, FileRef][] {\n\treturn Object.entries(snapshot).filter((entry) => isFileRef(entry[1])) as [\n\t\tstring,\n\t\tFileRef,\n\t][];\n}\n\nexport function isFile(value: any) {\n\tif (typeof File !== 'undefined' && value instanceof File) {\n\t\treturn true;\n\t}\n\tif (typeof Blob !== 'undefined' && value instanceof Blob) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nexport function isFileData(value: any): value is FileData {\n\treturn (\n\t\tvalue &&\n\t\tisObject(value) &&\n\t\ttypeof value.id === 'string' &&\n\t\ttypeof value.remote === 'boolean' &&\n\t\ttypeof value.name === 'string' &&\n\t\ttypeof value.type === 'string'\n\t);\n}\n", "import {\n\tassignOid,\n\tcreateOid,\n\tdecomposeOid,\n\tgetOidRoot,\n\tObjectIdentifier,\n} from './oids.js';\nimport { isObject } from './utils.js';\n\nexport const LEGACY_OID_KEY = '__@@oid_do_not_use';\nexport const OID_KEY = '@@id';\n\nexport function maybeGetOidProperty(obj: any) {\n\tif (!isObject(obj)) {\n\t\treturn undefined;\n\t}\n\treturn obj[OID_KEY] || obj[LEGACY_OID_KEY];\n}\n\nfunction removeOidProperty(obj: any) {\n\tif (!isObject(obj)) {\n\t\treturn obj;\n\t}\n\tdelete obj[LEGACY_OID_KEY];\n\tdelete obj[OID_KEY];\n\treturn obj;\n}\n\nfunction copyOidFromPropertyToSystem(obj: any) {\n\tconst oid = maybeGetOidProperty(obj);\n\tif (oid) {\n\t\tassignOid(obj, oid);\n\t}\n}\n\n/**\n *\n * Removes the special property from all objects in the given object\n * which have an OID, transferring the OID from the property to the OID\n * system in-memory.\n */\nexport function removeOidPropertiesFromAllSubObjects(obj: any) {\n\tcopyOidFromPropertyToSystem(obj);\n\tremoveOidProperty(obj);\n\n\tif (Array.isArray(obj)) {\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tremoveOidPropertiesFromAllSubObjects(obj[i]);\n\t\t}\n\t} else if (isObject(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tremoveOidPropertiesFromAllSubObjects(obj[key]);\n\t\t}\n\t}\n}\n\nexport function isLegacyDotOid(oid: ObjectIdentifier) {\n\tconst partBeforeRandomSep = oid.split(':')[0];\n\treturn partBeforeRandomSep.includes('.');\n}\n\nexport function convertLegacyOid(oid: ObjectIdentifier) {\n\tconst { collection, id, subId } = decomposeOid(oid);\n\treturn createOid(collection, id, subId);\n}\n\n// NOTE: all legacy OIDs should now be gone.\nexport const MATCH_LEGACY_OID_JSON_STRING = /\"\\w+\\/[^\"]+?(\\.[^\"]+)+\\:[\\S]+?\"/g;\nexport function replaceLegacyOidsInJsonString(string: string) {\n\t// replace every match of a legacy OID, converting to a new OID\n\treturn string.replaceAll(MATCH_LEGACY_OID_JSON_STRING, (match) => {\n\t\tconst legacyOid = match.slice(1, match.length - 1);\n\t\treturn `\"${convertLegacyOid(legacyOid)}\"`;\n\t});\n}\nexport function replaceLegacyOidsInObject(obj: any) {\n\treturn JSON.parse(replaceLegacyOidsInJsonString(JSON.stringify(obj)));\n}\n\nexport function getLegacyDotOidSubIdRange(oid: ObjectIdentifier) {\n\tconst root = getOidRoot(oid);\n\treturn [`${root}.`, `${root}.\\uffff`];\n}\n\nexport function isOidKey(key: string) {\n\treturn key === OID_KEY || key === LEGACY_OID_KEY;\n}\n", "import { DocumentBaseline } from './baseline.js';\nimport { FileRef, isFileRef } from './files.js';\nimport {\n\tareOidsRelated,\n\tassignOid,\n\tassignOidsToAllSubObjects,\n\tcreateRef,\n\tcreateSubOid,\n\tensureOid,\n\tgetOid,\n\tgetOidRoot,\n\tmaybeGetOid,\n\tnormalize,\n\tObjectIdentifier,\n\tremoveOid,\n} from './oids.js';\nimport { isOidKey } from './oidsLegacy.js';\nimport { compareRefs, isRef } from './refs.js';\nimport { assert, cloneDeep, findLastIndex, isObject } from './utils.js';\n\n// export type ObjectIdentifier<\n// \tCollectionName extends string = string,\n// \tDocumentId extends string = string,\n// \tDocumentOid extends string = string,\n// > =\n// \t| `${CollectionName}/${DocumentId}:${DocumentOid}`\n// \t| `${CollectionName}/${DocumentId}:${DocumentOid}#${string}`;\n\nexport type ObjectRef = {\n\t'@@type': 'ref';\n\tid: ObjectIdentifier;\n};\n\nexport function isObjectRef(obj: any): obj is ObjectRef {\n\treturn obj && typeof obj === 'object' && obj['@@type'] === 'ref';\n}\n\nexport type Normalized<T> = {\n\t[key in keyof T]: T[key] extends Object ? ObjectRef : T[key];\n};\n\n// patches v2\n\nexport type PropertyName = string | number;\n/**\n * List patches can target a particular child list or\n * nested lists. The first path item is the property path\n * of the first child list, any subsequent values are nested\n * list indices.\n */\nexport type PropertyValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| undefined\n\t| ObjectRef\n\t| FileRef;\n\n// all patches refer to a specific sub-object.\ninterface BaseOperationPatch {}\n\nexport interface OperationPatchInitialize extends BaseOperationPatch {\n\top: 'initialize';\n\tvalue: any;\n}\nexport interface OperationPatchSet extends BaseOperationPatch {\n\top: 'set';\n\tname: PropertyName;\n\tvalue: PropertyValue;\n}\nexport interface OperationPatchRemove extends BaseOperationPatch {\n\top: 'remove';\n\tname: PropertyName;\n}\nexport interface OperationPatchListSet extends BaseOperationPatch {\n\top: 'list-set';\n\tindex: number;\n\tvalue: PropertyValue;\n}\nexport interface OperationPatchListPush extends BaseOperationPatch {\n\top: 'list-push';\n\tvalue: PropertyValue;\n}\nexport interface OperationPatchListInsert extends BaseOperationPatch {\n\top: 'list-insert';\n\tindex: number;\n\tvalue?: PropertyValue;\n\tvalues?: PropertyValue[];\n}\nexport interface OperationPatchListDelete extends BaseOperationPatch {\n\top: 'list-delete';\n\tindex: number;\n\tcount: number;\n}\n/**\n * Optimal for lists of object references. Moves\n * the selected item to the target index even if it\n * is not at the original index anymore.\n */\nexport interface OperationPatchListMoveByRef extends BaseOperationPatch {\n\top: 'list-move-by-ref';\n\tvalue: ObjectRef | FileRef;\n\tindex: number;\n}\n/**\n * Suitable for any list move, whether object lists\n * or primitive lists.\n */\nexport interface OperationPatchListMoveByIndex extends BaseOperationPatch {\n\top: 'list-move-by-index';\n\tfrom: number;\n\tto: number;\n}\n/**\n * Removes all instances of the value from\n * the list. Good for set behavior or removing\n * a specific item even if it changes index\n * from conflicts.\n */\nexport interface OperationPatchListRemove extends BaseOperationPatch {\n\top: 'list-remove';\n\tvalue: PropertyValue;\n\tonly?: 'first' | 'last';\n}\n\nexport interface OperationPatchListAdd extends BaseOperationPatch {\n\top: 'list-add';\n\tvalue: PropertyValue;\n}\n\nexport interface OperationPatchDelete extends BaseOperationPatch {\n\top: 'delete';\n}\n\nexport interface OperationPatchTouch extends BaseOperationPatch {\n\top: 'touch';\n}\n\nexport type OperationPatch =\n\t| OperationPatchInitialize\n\t| OperationPatchSet\n\t| OperationPatchRemove\n\t| OperationPatchListSet\n\t| OperationPatchListPush\n\t| OperationPatchListInsert\n\t| OperationPatchListDelete\n\t| OperationPatchListMoveByRef\n\t| OperationPatchListMoveByIndex\n\t| OperationPatchListRemove\n\t| OperationPatchDelete\n\t| OperationPatchListAdd\n\t| OperationPatchTouch;\n\nexport type Operation = {\n\toid: ObjectIdentifier;\n\ttimestamp: string;\n\tdata: OperationPatch;\n\tauthz?: string;\n};\n\nfunction isDiffableObject(val: any) {\n\treturn isObject(val) && !isRef(val);\n}\n\nfunction compareNonDiffable(a: any, b: any) {\n\tif (a === b) return true;\n\tif (isRef(a) && isRef(b)) return compareRefs(a, b);\n\treturn false;\n}\n\nexport function diffToPatches<T extends { [key: string]: any } | any[]>(\n\tfrom: T,\n\tto: T,\n\tgetNow: () => string,\n\tcreateSubId?: () => string,\n\tpatches: Operation[] = [],\n\toptions?: {\n\t\t/**\n\t\t * If an object is merged with another and the new one does not\n\t\t * have an OID assigned, assume it is the same identity as previous\n\t\t */\n\t\tmergeUnknownObjects?: boolean;\n\t\t/**\n\t\t * If an incoming value is not assigned on the new object, use the previous value.\n\t\t * If false, undefined properties will erase the previous value.\n\t\t */\n\t\tdefaultUndefined?: boolean;\n\t\t/**\n\t\t * Authorization to apply to all created operations\n\t\t */\n\t\tauthz?: string;\n\t},\n): Operation[] {\n\tconst authz = options?.authz;\n\tconst oid = getOid(from);\n\n\t// FIXME: allocating this function inline seems wasteful.\n\tfunction diffItems(\n\t\tkey: string | number,\n\t\tvalue: any,\n\t\toldValue: any,\n\t\tisList: boolean,\n\t) {\n\t\tif (!isDiffableObject(value)) {\n\t\t\t// for primitive fields, we can use plain sets and\n\t\t\t// do not need to recurse, of course\n\t\t\tif (!compareNonDiffable(value, oldValue)) {\n\t\t\t\tif (isList) {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\t\t\t\tindex: key as number,\n\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconst oldValueOid = maybeGetOid(oldValue);\n\t\t\tlet valueOid = maybeGetOid(value);\n\t\t\t// the user supplied an object which was already assigned an OID,\n\t\t\t// but that OID is from a separate entity: this object must\n\t\t\t// be cloned to a new identity.\n\t\t\tif (valueOid && !areOidsRelated(oid, valueOid)) {\n\t\t\t\tvalue = cloneDeep(value, false);\n\t\t\t\tvalueOid = createSubOid(oid, createSubId);\n\t\t\t\tassignOid(value, valueOid);\n\t\t\t} else if (!options?.mergeUnknownObjects) {\n\t\t\t\tvalueOid = ensureOid(value, oid, createSubId);\n\t\t\t} else {\n\t\t\t\t// if merge unknown objects is requested, we copy the previous value's oid\n\t\t\t\t// to any mirrored new value if it doesn't have one assigned already.\n\t\t\t\tif (!valueOid && oldValueOid) {\n\t\t\t\t\tassignOid(value, oldValueOid);\n\t\t\t\t\tvalueOid = oldValueOid;\n\t\t\t\t} else {\n\t\t\t\t\tvalueOid = ensureOid(value, oid, createSubId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tassert(\n\t\t\t\t!!valueOid,\n\t\t\t\t'Error: no value OID was resolved during diff. This is a bug in Verdant.',\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tareOidsRelated(oid, valueOid),\n\t\t\t\t`Error: value OID ${valueOid} is not related to parent OID ${oid}. This is a bug in Verdant.`,\n\t\t\t);\n\n\t\t\tif (oldValue === undefined || valueOid !== oldValueOid) {\n\t\t\t\t// first case: previous value exists but the OIDs are different,\n\t\t\t\t// meaning the object identity has changed\n\t\t\t\t// we add the whole new object and also update the reference on this\n\t\t\t\t// key of the parent to point to the new object\n\t\t\t\tinitialToPatches(value, valueOid, getNow, createSubId, patches);\n\t\t\t\tpatches.push(\n\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t\t\tvalue: createRef(valueOid),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tauthz,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\t// if there was an old value, we need to delete it altogether.\n\t\t\t\tif (oldValueOid !== undefined) {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid: oldValueOid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'delete',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// third case: OIDs are the same, meaning the identity is the same,\n\t\t\t\t// and we must diff the objects\n\t\t\t\tdiffToPatches(oldValue, value, getNow, createSubId, patches, options);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (Array.isArray(from) && Array.isArray(to)) {\n\t\t// diffing is more naive than native array operations.\n\t\t// we can only look at each element and decide if it should\n\t\t// be replaced or removed - no moves or pushes, etc.\n\t\tfor (let i = 0; i < to.length; i++) {\n\t\t\tconst value = to[i];\n\t\t\tconst oldValue = from[i];\n\t\t\tdiffItems(i, value, oldValue, true);\n\t\t}\n\t\t// remove any remaining items at the end of the array\n\t\tconst deletedItemsAtEnd = from.length - to.length;\n\t\tif (deletedItemsAtEnd > 0) {\n\t\t\t// if sub-items were objects, we need to delete them all\n\t\t\tfor (let i = to.length; i < from.length; i++) {\n\t\t\t\tconst value = from[i];\n\t\t\t\tconst valueOid = maybeGetOid(value);\n\t\t\t\tif (valueOid) {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid: valueOid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'delete',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// push the list-delete for the deleted items\n\t\t\tpatches.push(\n\t\t\t\taddAuthzToOp(\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'list-delete',\n\t\t\t\t\t\t\tindex: to.length,\n\t\t\t\t\t\t\tcount: deletedItemsAtEnd,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tauthz,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t} else if (Array.isArray(from) || Array.isArray(to)) {\n\t\tthrow new Error('Cannot diff an array with an object');\n\t} else if (isDiffableObject(from) && isDiffableObject(to)) {\n\t\tconst oldKeys = new Set(Object.keys(from));\n\t\tfor (const [key, value] of Object.entries(to)) {\n\t\t\tif (value === undefined && options?.defaultUndefined) continue;\n\n\t\t\toldKeys.delete(key);\n\n\t\t\tif (isOidKey(key)) continue;\n\n\t\t\tconst oldValue = from[key];\n\n\t\t\tdiffItems(key, value, oldValue, false);\n\t\t}\n\n\t\t// this set now only contains keys which were not in the new object\n\t\tif (!options?.defaultUndefined) {\n\t\t\tfor (const key of oldKeys) {\n\t\t\t\tif (isOidKey(key)) continue;\n\t\t\t\t// push the delete for the property\n\t\t\t\tpatches.push(\n\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\top: 'remove',\n\t\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tauthz,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn patches;\n}\n\nexport function shallowDiffToPatches(\n\tfrom: any,\n\tto: any,\n\tgetNow: () => string,\n\tpatches: Operation[] = [],\n\toptions?: { authz?: string },\n) {\n\tconst oid = getOid(from);\n\tconst authz = options?.authz;\n\n\tfunction diffItems(\n\t\tkey: string | number,\n\t\tvalue: any,\n\t\toldValue: any,\n\t\tisList: boolean,\n\t) {\n\t\tif (!isDiffableObject(value)) {\n\t\t\t// for primitive fields, we can use plain sets and\n\t\t\t// do not need to recurse, of course\n\t\t\tif (!compareNonDiffable(value, oldValue)) {\n\t\t\t\tif (isList) {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\t\t\t\tindex: key as number,\n\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t'Shallow diff was given a nested object. This is an error in verdant!',\n\t\t\t);\n\t\t}\n\t}\n\n\tif (Array.isArray(from) && Array.isArray(to)) {\n\t\t// diffing is more naive than native array operations.\n\t\t// we can only look at each element and decide if it should\n\t\t// be replaced or removed - no moves or pushes, etc.\n\t\tfor (let i = 0; i < to.length; i++) {\n\t\t\tconst value = to[i];\n\t\t\tconst oldValue = from[i];\n\t\t\tdiffItems(i, value, oldValue, true);\n\t\t}\n\t\t// remove any remaining items at the end of the array\n\t\tconst deletedItemsAtEnd = from.length - to.length;\n\t\tif (deletedItemsAtEnd > 0) {\n\t\t\t// push the list-delete for the deleted items\n\t\t\tpatches.push(\n\t\t\t\taddAuthzToOp(\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'list-delete',\n\t\t\t\t\t\t\tindex: to.length,\n\t\t\t\t\t\t\tcount: deletedItemsAtEnd,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tauthz,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t} else if (Array.isArray(from) || Array.isArray(to)) {\n\t\tthrow new Error('Cannot diff an array with an object');\n\t} else if (isDiffableObject(from) && isDiffableObject(to)) {\n\t\tconst oldKeys = new Set(Object.keys(from));\n\t\tfor (const [key, value] of Object.entries(to)) {\n\t\t\toldKeys.delete(key);\n\n\t\t\tif (isOidKey(key)) continue;\n\n\t\t\tconst oldValue = from[key];\n\n\t\t\tdiffItems(key, value, oldValue, false);\n\t\t}\n\n\t\t// this set now only contains keys which were not in the new object\n\t\tfor (const key of oldKeys) {\n\t\t\tif (isOidKey(key)) continue;\n\t\t\t// push the delete for the property\n\t\t\tpatches.push(\n\t\t\t\taddAuthzToOp(\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'remove',\n\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tauthz,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn patches;\n}\n\n/**\n * Takes a basic object and constructs a patch list to create it and\n * all of its nested objects.\n */\nexport function initialToPatches(\n\tinitial: any,\n\trootOid: ObjectIdentifier,\n\tgetNow: () => string,\n\tcreateSubId?: () => string,\n\tpatches: Operation[] = [],\n\toptions?: { authz?: string },\n) {\n\tassignOid(initial, rootOid);\n\tassignOidsToAllSubObjects(initial, createSubId);\n\tconst normalized = normalize(initial);\n\tfor (const key of normalized.keys()) {\n\t\tconst value = normalized.get(key);\n\t\tconst op: Operation = {\n\t\t\toid: key,\n\t\t\ttimestamp: getNow(),\n\t\t\tdata: {\n\t\t\t\top: 'initialize',\n\t\t\t\tvalue: removeOid(value),\n\t\t\t},\n\t\t};\n\t\tpatches.push(addAuthzToOp(op, options?.authz));\n\t}\n\treturn patches;\n}\n\nexport function shallowInitialToPatches(\n\tinitial: any,\n\trootOid: ObjectIdentifier,\n\tgetNow: () => string,\n\tpatches: Operation[] = [],\n\toptions?: { authz?: string },\n) {\n\tconst op: Operation = {\n\t\toid: rootOid,\n\t\ttimestamp: getNow(),\n\t\tdata: {\n\t\t\top: 'initialize',\n\t\t\tvalue: initial,\n\t\t},\n\t};\n\tpatches.push(addAuthzToOp(op, options?.authz));\n\treturn patches;\n}\n\n// saves a bit of network traffic by not attaching authz\n// key at all if not present\nfunction addAuthzToOp(op: Operation, authz?: string) {\n\tif (authz) {\n\t\top.authz = authz;\n\t}\n\treturn op;\n}\n\nexport function groupPatchesByOid(patches: Operation[]) {\n\tconst grouped: Record<ObjectIdentifier, Operation[]> = {};\n\tfor (const patch of patches) {\n\t\tif (patch.oid in grouped) {\n\t\t\tgrouped[patch.oid].push(patch);\n\t\t} else {\n\t\t\tgrouped[patch.oid] = [patch];\n\t\t}\n\t}\n\treturn grouped;\n}\n\nexport function groupPatchesByRootOid(patches: Operation[]) {\n\tconst grouped: Record<ObjectIdentifier, Operation[]> = {};\n\tfor (const patch of patches) {\n\t\tconst root = getOidRoot(patch.oid);\n\t\tif (root in grouped) {\n\t\t\tgrouped[root].push(patch);\n\t\t} else {\n\t\t\tgrouped[root] = [patch];\n\t\t}\n\t}\n\treturn grouped;\n}\n\nexport function groupBaselinesByRootOid(baselines: DocumentBaseline[]) {\n\tconst grouped: Record<ObjectIdentifier, DocumentBaseline[]> = {};\n\tfor (const patch of baselines) {\n\t\tconst root = getOidRoot(patch.oid);\n\t\tif (root in grouped) {\n\t\t\tgrouped[root].push(patch);\n\t\t} else {\n\t\t\tgrouped[root] = [patch];\n\t\t}\n\t}\n\treturn grouped;\n}\n\nexport type NormalizedObject =\n\t| {\n\t\t\t[key: PropertyName]: PropertyValue;\n\t }\n\t| Array<PropertyValue>;\n\nfunction listCheck(obj: any): obj is Array<unknown> {\n\tif (!Array.isArray(obj)) {\n\t\tconsole.error(\n\t\t\t`Cannot apply list patch; expected array, received ${JSON.stringify(\n\t\t\t\tobj,\n\t\t\t)}. This suggests your data is changing from a list to an object over time. (OID: ${maybeGetOid(\n\t\t\t\tobj,\n\t\t\t)})`,\n\t\t);\n\t\treturn false;\n\t} else {\n\t\treturn true;\n\t}\n}\n\n/**\n * The incoming object should already be normalized!\n * This function will mutate the base object.\n */\nexport function applyPatch<T extends NormalizedObject>(\n\tbase: T | undefined,\n\tpatch: OperationPatch,\n\t/**\n\t * Optionally supply a list to which any refs which\n\t * are removed during the patch will be appended.\n\t */\n\tdeletedRefs?: (FileRef | ObjectRef)[],\n): T | undefined {\n\t// deleted objects are represented by undefined\n\t// and remain deleted unless re-initialized\n\tif ((base === undefined || base === null) && patch.op !== 'initialize') {\n\t\treturn base;\n\t}\n\t// ditch typing internally.\n\tconst baseAsAny = base as any;\n\tlet index;\n\tlet spliceResult: any[];\n\n\t// a helper, pass it a value which is about\n\t// to be removed and it will append it to the list\n\t// if it was a ref\n\tfunction checkRef(field: any) {\n\t\t// don't bother if not supplied\n\t\tif (!deletedRefs) return;\n\t\tif (isRef(field)) {\n\t\t\tdeletedRefs.push(field);\n\t\t}\n\t}\n\n\tswitch (patch.op) {\n\t\tcase 'set':\n\t\t\tcheckRef(baseAsAny[patch.name]);\n\t\t\tbaseAsAny[patch.name] = patch.value;\n\t\t\tbreak;\n\t\tcase 'remove':\n\t\t\tcheckRef(baseAsAny[patch.name]);\n\t\t\tdelete baseAsAny[patch.name];\n\t\t\tbreak;\n\t\tcase 'list-set':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tcheckRef(base[patch.index]);\n\t\t\t\tbase[patch.index] = patch.value;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-push':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tbase.push(patch.value);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-delete':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tcheckRef(base[patch.index]);\n\t\t\t\tbase.splice(patch.index, patch.count);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-move-by-index':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tspliceResult = base.splice(patch.from, 1);\n\t\t\t\tbase.splice(patch.to, 0, spliceResult[0]);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-remove':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tdo {\n\t\t\t\t\tconst valueToRemove = patch.value;\n\t\t\t\t\tif (patch.only === 'last') {\n\t\t\t\t\t\tif (isObjectRef(valueToRemove)) {\n\t\t\t\t\t\t\tindex = findLastIndex(\n\t\t\t\t\t\t\t\tbase,\n\t\t\t\t\t\t\t\t(item: any) => item.id === valueToRemove.id,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = base.lastIndexOf(valueToRemove);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (isObjectRef(valueToRemove)) {\n\t\t\t\t\t\t\tindex = base.findIndex(\n\t\t\t\t\t\t\t\t(item: any) => item.id === valueToRemove.id,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = base.indexOf(valueToRemove);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (index !== -1) {\n\t\t\t\t\t\tcheckRef(base[index]);\n\t\t\t\t\t\tbase.splice(index, 1);\n\t\t\t\t\t}\n\t\t\t\t} while (!patch.only && index !== -1);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-add':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tconst alreadyHas = base.some((item: any) => {\n\t\t\t\t\tif (isObjectRef(item) && isObjectRef(patch.value)) {\n\t\t\t\t\t\treturn item.id === patch.value.id;\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn item === patch.value;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tif (!alreadyHas) {\n\t\t\t\t\tbase.push(patch.value);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-move-by-ref':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tindex = base.findIndex((v) => compareRefs(v, patch.value));\n\t\t\t\tspliceResult = base.splice(index, 1);\n\t\t\t\tbase.splice(patch.index, 0, spliceResult[0]);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-insert':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tif (!patch.value && !patch.values) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot apply list insert patch; expected value or values, received ${JSON.stringify(\n\t\t\t\t\t\t\tpatch,\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (patch.value) {\n\t\t\t\t\tbase.splice(patch.index, 0, patch.value);\n\t\t\t\t} else {\n\t\t\t\t\tbase.splice(patch.index, 0, ...patch.values!);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'delete':\n\t\t\t// collect all refs that are deleted\n\t\t\tif (Array.isArray(base)) {\n\t\t\t\tbase.forEach(checkRef);\n\t\t\t} else if (isObject(base)) {\n\t\t\t\tObject.values(base || {}).forEach(checkRef);\n\t\t\t}\n\t\t\treturn undefined;\n\t\tcase 'initialize':\n\t\t\treturn cloneDeep(patch.value);\n\t\tcase 'touch':\n\t\t\t// no-op\n\t\t\treturn base;\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported patch operation: ${(patch as any).op}`);\n\t}\n\treturn base;\n}\n\nexport function applyOperations<T extends NormalizedObject>(\n\tbase: T | undefined,\n\toperations: Operation[],\n\tdeletedRefs?: (ObjectRef | FileRef)[],\n\t/**\n\t * Provide and it will be assigned any authz info assigned\n\t * in applied operations\n\t */\n\tauthzRef?: { authz?: string },\n): T | undefined {\n\tlet cur = base as T | undefined;\n\tfor (const op of operations) {\n\t\tcur = applyPatch(cur, op.data, deletedRefs);\n\t\tif (authzRef && op.data.op === 'initialize' && op.authz) {\n\t\t\tauthzRef.authz = op.authz;\n\t\t}\n\t}\n\treturn cur;\n}\n\n/**\n * Mutates the original object in place. Returns all referenced\n * objects oids.\n */\nexport function substituteRefsWithObjects(\n\tbase: any,\n\trefs: Map<ObjectIdentifier, any>,\n\tused: ObjectIdentifier[] = [],\n): ObjectIdentifier[] {\n\tif (Array.isArray(base)) {\n\t\tfor (let i = 0; i < base.length; i++) {\n\t\t\tconst item = base[i];\n\t\t\tbase[i] = dereference(item, refs, used);\n\t\t\tif (isObject(base[i])) {\n\t\t\t\tsubstituteRefsWithObjects(base[i], refs, used);\n\t\t\t}\n\t\t}\n\t} else if (isFileRef(base)) {\n\t\t// don't do anything with file refs\n\t} else if (isObject(base)) {\n\t\t// not sure where to put this assertion but it's important to make\n\t\t// sure all nested objects include an OID\n\t\tassert(\n\t\t\tmaybeGetOid(base),\n\t\t\t`Object ${JSON.stringify(base)} must have an oid`,\n\t\t);\n\t\tfor (const key of Object.keys(base)) {\n\t\t\tbase[key] = dereference(base[key], refs, used);\n\n\t\t\t// now that objects are in place, recursively substitute\n\t\t\tif (isObject(base[key])) {\n\t\t\t\tsubstituteRefsWithObjects(base[key], refs, used);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn used;\n}\n\nfunction dereference(\n\tinput: any,\n\trefs: Map<ObjectIdentifier, any>,\n\tused: ObjectIdentifier[],\n): any {\n\tif (isObjectRef(input)) {\n\t\tused.push(input.id);\n\t\tconst resolved = refs.get(input.id);\n\t\tassert(!!resolved, `No value was found in object map for ${input.id}`);\n\t\treturn assignOid(resolved, input.id);\n\t} else {\n\t\treturn input;\n\t}\n}\n\nexport function substituteFirstLevelObjectsWithRefs<\n\tBase extends { [key: string]: any } | any[],\n>(\n\tbase: Base,\n\trefObjects: Map<ObjectIdentifier, any> = new Map(),\n): Map<ObjectIdentifier, any> {\n\tif (Array.isArray(base)) {\n\t\tfor (let i = 0; i < base.length; i++) {\n\t\t\tconst item = base[i];\n\t\t\tif (isObject(item)) {\n\t\t\t\tconst oid = getOid(item);\n\t\t\t\tbase[i] = {\n\t\t\t\t\t'@@type': 'ref',\n\t\t\t\t\tid: oid,\n\t\t\t\t};\n\t\t\t\trefObjects.set(oid, item);\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor (const [key, value] of Object.entries(base)) {\n\t\t\tif (isObject(value)) {\n\t\t\t\tbase[key] = {\n\t\t\t\t\t'@@type': 'ref',\n\t\t\t\t\tid: getOid(value),\n\t\t\t\t};\n\n\t\t\t\trefObjects.set(getOid(value), value);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn refObjects;\n}\n\nexport function operationSupersedes(op: Operation): PropertyName | boolean {\n\t// todo: add 'remove'\n\tif (op.data.op === 'set') {\n\t\treturn op.data.name;\n\t}\n\n\treturn false;\n}\n\n/**\n * Determine if an operation is superseded by a set of supersession values\n * provided by operationSupersedes. Assumes the operation OID matches\n * already.\n */\nexport function isSuperseded(\n\top: Operation,\n\tsupersession: Set<PropertyName | boolean>,\n) {\n\tif (supersession.has(true)) {\n\t\treturn true;\n\t} else if (op.data.op === 'set' || op.data.op === 'remove') {\n\t\treturn supersession.has(op.data.name);\n\t}\n\n\treturn false;\n}\n\n/**\n * Allocates a copy with only valid keys for transmitting over\n * the protocol. TODO: make this unnecessary or evaluate if it's\n * worth it to do.\n */\nexport function pickValidOperationKeys(operation: Operation): Operation {\n\treturn {\n\t\toid: operation.oid,\n\t\ttimestamp: operation.timestamp,\n\t\tdata: operation.data,\n\t\tauthz: operation.authz,\n\t};\n}\n", "export interface ReplicaInfo {\n\tid: string;\n\tackedLogicalTime: string | null;\n}\n\n/**\n * Different token types allow different replica client behaviors.\n * - Realtime: allows the client to subscribe to realtime events.\n * - Push: allows the client to push and pull data with HTTP, but not use realtime.\n * - PassivePush: allows the client to push and pull data with HTTP, but offline changes\n * will be discarded on reconnect.\n * - PassiveRealtime: allows the client to subscribe to realtime events, but offline changes\n * \t\t will be discarded on reconnect.\n * - ReadOnlyPull: the client may only pull changes using HTTP. It may not subscribe\n * to realtime events or push changes.\n * - ReadOnlyRealtime: the client may only subscribe to realtime events or pull from HTTP.\n * It may not push changes.\n *\n * Choosing the right token type can optimize client storage metrics significantly when\n * many replicas are connecting to a library.\n */\nexport enum ReplicaType {\n\tRealtime,\n\tPush,\n\tPassiveRealtime,\n\tPassivePush,\n\tReadOnlyPull,\n\tReadOnlyRealtime,\n}\n", "import cuid from 'cuid';\nimport {\n\tShapeFromFieldsWithDefaults,\n\tStorageAnyFieldSchema,\n\tStorageArrayFieldSchema,\n\tStorageBooleanFieldSchema,\n\tStorageFieldSchema,\n\tStorageFieldsSchema,\n\tStorageFileFieldSchema,\n\tStorageMapFieldSchema,\n\tStorageNumberFieldSchema,\n\tStorageObjectFieldSchema,\n\tStorageStringFieldSchema,\n} from './types.js';\n\nconst objectField = <Props extends StorageFieldsSchema>(args: {\n\tproperties: Props;\n\tnullable?: boolean;\n\tdefault?:\n\t\t| ShapeFromFieldsWithDefaults<Props>\n\t\t| (() => ShapeFromFieldsWithDefaults<Props>);\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageObjectFieldSchema<Props> => {\n\treturn {\n\t\ttype: 'object',\n\t\t...args,\n\t};\n};\n\nconst arrayField = <T extends StorageFieldSchema>(args: {\n\titems: T;\n\tnullable?: boolean;\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageArrayFieldSchema<T> => {\n\treturn {\n\t\ttype: 'array',\n\t\t...args,\n\t};\n};\n\nconst stringField = (args?: {\n\tnullable?: boolean;\n\tdefault?: string | (() => string);\n\toptions?: string[];\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageStringFieldSchema => {\n\treturn {\n\t\ttype: 'string',\n\t\t...args,\n\t};\n};\n\nconst numberField = (args?: {\n\tnullable?: boolean;\n\tdefault?: number | (() => number);\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageNumberFieldSchema => {\n\treturn {\n\t\ttype: 'number',\n\t\t...args,\n\t};\n};\n\nconst booleanField = (args?: {\n\tnullable?: boolean;\n\tdefault?: boolean | (() => boolean);\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageBooleanFieldSchema => {\n\treturn {\n\t\ttype: 'boolean',\n\t\t...args,\n\t};\n};\n\nconst anyField = <TShape>(args?: {\n\tdefault?: TShape;\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageAnyFieldSchema<TShape> => {\n\treturn {\n\t\ttype: 'any',\n\t\t...args,\n\t};\n};\n\nconst mapField = <T extends StorageFieldSchema>(args: {\n\tvalues: T;\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageMapFieldSchema<T> => {\n\treturn {\n\t\ttype: 'map',\n\t\t...args,\n\t};\n};\n\nconst fileField = (args?: {\n\tnullable?: boolean;\n\tdownloadRemote?: boolean;\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageFileFieldSchema => {\n\treturn {\n\t\ttype: 'file',\n\t\t...args,\n\t};\n};\n\n/**\n * Meant for use on primary key fields. Do not use this to refer\n * to another document as a 'foreign key'\n */\nconst idField = (): StorageStringFieldSchema => {\n\treturn {\n\t\ttype: 'string',\n\t\tdefault: cuid,\n\t};\n};\n\nexport const fields = {\n\tobject: objectField,\n\tarray: arrayField,\n\tstring: stringField,\n\tnumber: numberField,\n\tboolean: booleanField,\n\tany: anyField,\n\tmap: mapField,\n\tfile: fileField,\n\tid: idField,\n};\n", "import {\n\tCollectionCompoundIndices,\n\tStorageCollectionSchema,\n\tStorageDirectSyntheticSchema,\n\tStorageFieldsSchema,\n\tStorageSchema,\n\tStorageSyntheticIndexSchema,\n\tStorageSyntheticIndices,\n} from './types.js';\nimport { fields } from './fieldHelpers.js';\nimport cuid from 'cuid';\n\nexport function collection<\n\tFields extends StorageFieldsSchema,\n\tSynthetics extends StorageSyntheticIndices<Fields>,\n\tCompounds extends CollectionCompoundIndices<Fields, Synthetics>,\n>({\n\tsynthetics,\n\tindexes,\n\t...input\n}: StorageCollectionSchema<\n\tFields,\n\tSynthetics,\n\tCompounds\n>): StorageCollectionSchema<Fields, Synthetics, Compounds> {\n\t// back compat - copy synthetics in with indexes\n\tconst finalIndexes = { ...synthetics, ...indexes };\n\t// add all indexed fields into the synthetic indices (back compat)\n\tfor (const [key, field] of Object.entries(input.fields)) {\n\t\tif ('indexed' in field) {\n\t\t\tfinalIndexes[key] = {\n\t\t\t\tfield: key,\n\t\t\t} as StorageDirectSyntheticSchema<Fields>;\n\t\t}\n\t}\n\treturn {\n\t\t...input,\n\t\tindexes: finalIndexes as Synthetics,\n\t};\n}\n\nexport function schema<\n\t// Fields extends StorageFieldsSchema,\n\t// Indexes extends StorageSyntheticIndices<Fields>,\n\t// Compounds extends CollectionCompoundIndices<Fields, Indexes>,\n\tSchema extends StorageSchema<{\n\t\t[key: string]: StorageCollectionSchema<any, any, any>;\n\t}>,\n>(input: Schema): StorageSchema {\n\treturn input;\n}\nschema.collection = collection;\nschema.fields = fields;\nschema.generated = {\n\tid: cuid,\n};\n\nexport * from './types.js';\n\nexport * from './indexFilters.js';\nexport * from './fields.js';\nexport * from './validation.js';\nexport * from './children.js';\n", "import {\n\tCollectionCompoundIndexFilter,\n\tCollectionFilter,\n\tMatchCollectionIndexFilter,\n\tRangeCollectionIndexFilter,\n\tSortIndexFilter,\n\tStartsWithIndexFilter,\n} from './types.js';\n\nexport function isMatchIndexFilter(\n\tfilter: CollectionFilter,\n): filter is MatchCollectionIndexFilter {\n\treturn (filter as any).equals !== undefined;\n}\n\nexport function isRangeIndexFilter(\n\tfilter: CollectionFilter,\n): filter is RangeCollectionIndexFilter {\n\treturn (\n\t\t(filter as any).gte !== undefined ||\n\t\t(filter as any).lte !== undefined ||\n\t\t(filter as any).gt !== undefined ||\n\t\t(filter as any).lt !== undefined\n\t);\n}\n\nexport function isCompoundIndexFilter(\n\tfilter: CollectionFilter,\n): filter is CollectionCompoundIndexFilter {\n\treturn !!(filter as any).match;\n}\n\nexport function isStartsWithIndexFilter(\n\tfilter: CollectionFilter,\n): filter is StartsWithIndexFilter {\n\treturn (filter as any).startsWith !== undefined;\n}\n\nexport function isSortIndexFilter(\n\tfilter: CollectionFilter,\n): filter is SortIndexFilter {\n\treturn (\n\t\t!isRangeIndexFilter(filter) &&\n\t\t!isMatchIndexFilter(filter) &&\n\t\t!isCompoundIndexFilter(filter) &&\n\t\t!isStartsWithIndexFilter(filter) &&\n\t\t(filter as any).order\n\t);\n}\n", "import { LEGACY_OID_KEY, OID_KEY } from '../oidsLegacy.js';\nimport { isObject } from '../utils.js';\nimport type {\n\tStorageFieldSchema,\n\tStorageCollectionSchema,\n\tStorageFieldsSchema,\n} from './types.js';\n\nexport function isNullable(field: StorageFieldSchema) {\n\tif (field.type === 'any') return true;\n\tif (field.type === 'map') return false;\n\treturn field.nullable;\n}\n\nexport function hasDefault(field: StorageFieldSchema | undefined) {\n\tif (!field) return false;\n\tif (field.type === 'map') return true;\n\tif (field.type === 'array') return true;\n\tif (field.type === 'file') return false;\n\treturn field.default !== undefined;\n}\n\nexport function getDefault(field: StorageFieldSchema | undefined) {\n\tif (!field || !hasDefault(field)) return undefined;\n\tif (field.type === 'file') {\n\t\tif (isNullable(field)) return null;\n\t\treturn undefined;\n\t}\n\tif (field.type === 'map') return {};\n\tif (field.type === 'array') {\n\t\tif (isNullable(field)) return null;\n\t\treturn [];\n\t}\n\tif (field.type === 'object') {\n\t\tif (isNullable(field)) return null;\n\t\treturn undefined;\n\t}\n\tif (typeof field.default === 'function') {\n\t\treturn field.default();\n\t}\n\treturn field.default;\n}\n\nexport function isPrunePoint(field: StorageFieldSchema) {\n\treturn isNullable(field) || hasDefault(field);\n}\n\nexport function addFieldDefaults(\n\tcollection: StorageCollectionSchema,\n\tvalue: any,\n) {\n\tfor (const [key, field] of Object.entries(collection.fields)) {\n\t\tconst defaultValue = getFieldDefault(field);\n\t\tif (\n\t\t\t(defaultValue !== undefined && value[key] === undefined) ||\n\t\t\t// covers the case where a previously nullable field\n\t\t\t// now has a default during a new migration\n\t\t\t(!isNullable(field) && value[key] === null)\n\t\t) {\n\t\t\tvalue[key] = defaultValue;\n\t\t}\n\t\tif (value[key]) {\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(value[key], field);\n\t\t}\n\t}\n\treturn value;\n}\n\nexport function traverseCollectionFieldsAndApplyDefaults(\n\tvalue: any,\n\tfield: StorageFieldSchema,\n) {\n\tif (value === undefined || value === null) return value;\n\tif (field.type === 'object') {\n\t\tfor (const [key, subField] of Object.entries(\n\t\t\tfield.properties as StorageFieldsSchema,\n\t\t)) {\n\t\t\tif (value[key] === undefined) {\n\t\t\t\tconst defaultValue = getFieldDefault(subField);\n\t\t\t\tif (defaultValue !== undefined) {\n\t\t\t\t\tvalue[key] = defaultValue;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(value[key], subField);\n\t\t}\n\t} else if (field.type === 'array') {\n\t\tfor (const item of value) {\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(item, field.items);\n\t\t}\n\t} else if (field.type === 'map') {\n\t\tfor (const [key, item] of Object.entries(value)) {\n\t\t\t// santiy check to weed out any id field\n\t\t\tif (key === OID_KEY || key === LEGACY_OID_KEY) continue;\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(item, field.values);\n\t\t}\n\t}\n}\n\nexport function getFieldDefault(field: StorageFieldSchema) {\n\tif (\n\t\tfield.type === 'string' ||\n\t\tfield.type === 'number' ||\n\t\tfield.type === 'boolean' ||\n\t\tfield.type === 'any'\n\t) {\n\t\tif (field.default && typeof field.default === 'function') {\n\t\t\treturn field.default();\n\t\t} else if (field.default !== undefined) {\n\t\t\t// TODO: structuredClone?\n\t\t\treturn JSON.parse(JSON.stringify(field.default));\n\t\t}\n\t}\n\tif (field.type === 'array') {\n\t\treturn [];\n\t}\n\tif (field.type === 'map') {\n\t\treturn {};\n\t}\n\tif (field.type !== 'any' && field.nullable) {\n\t\treturn null;\n\t}\n\tif (field.type === 'object' && field.default) {\n\t\tconst defaultValue =\n\t\t\t// @ts-ignore\n\t\t\ttypeof field.default === 'function'\n\t\t\t\t? field.default()\n\t\t\t\t: JSON.parse(JSON.stringify(field.default));\n\t\tfor (const [key, property] of Object.entries(\n\t\t\tfield.properties as StorageFieldsSchema,\n\t\t)) {\n\t\t\tif (defaultValue[key] === undefined) {\n\t\t\t\tdefaultValue[key] = getFieldDefault(property);\n\t\t\t}\n\t\t}\n\t\treturn defaultValue;\n\t}\n\treturn undefined;\n}\n\nexport function removeExtraProperties(\n\tcollection: StorageCollectionSchema,\n\tvalue: any,\n) {\n\tfor (const [key, fieldValue] of Object.entries(value)) {\n\t\t// MUST NOT DELETE THESE!\n\t\tif (key === OID_KEY || key === LEGACY_OID_KEY) continue;\n\n\t\tif (!collection.fields[key]) {\n\t\t\tdelete value[key];\n\t\t} else {\n\t\t\ttraverseCollectionFieldsAndRemoveExtraProperties(\n\t\t\t\tfieldValue,\n\t\t\t\tcollection.fields[key],\n\t\t\t);\n\t\t}\n\t}\n\treturn value;\n}\n\nexport function traverseCollectionFieldsAndRemoveExtraProperties(\n\tvalue: any,\n\tfield: StorageFieldSchema,\n) {\n\tif (isObject(value) && field.type === 'object') {\n\t\tfor (const [key, fieldValue] of Object.entries(value)) {\n\t\t\tif (!field.properties[key]) {\n\t\t\t\tdelete value[key];\n\t\t\t} else {\n\t\t\t\ttraverseCollectionFieldsAndRemoveExtraProperties(\n\t\t\t\t\tfieldValue,\n\t\t\t\t\tfield.properties[key],\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t} else if (Array.isArray(value) && field.type === 'array') {\n\t\tfor (const item of value) {\n\t\t\ttraverseCollectionFieldsAndRemoveExtraProperties(item, field.items);\n\t\t}\n\t}\n}\n", "import { isFile, isFileData } from '../files.js';\nimport { OID_KEY } from '../oidsLegacy.js';\nimport { isObject } from '../utils.js';\nimport { getFieldDefault, hasDefault, isNullable } from './fields.js';\nimport { StorageFieldSchema, StorageFieldsSchema } from './types.js';\n\nexport function validateEntity(\n\tschema: StorageFieldsSchema,\n\tentity: any,\n): EntityValidationProblem | void {\n\tfor (const [key, value] of Object.entries(entity)) {\n\t\t// legacy -- old objects sometimes accidentally include this key\n\t\tif (key === OID_KEY) continue;\n\t\tif (!schema[key]) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-key',\n\t\t\t\tfieldPath: [key],\n\t\t\t\tmessage: `Invalid field \"${key}\"`,\n\t\t\t};\n\t\t}\n\t\tif (value) {\n\t\t\tconst err = validateEntityField({\n\t\t\t\tfield: schema[key],\n\t\t\t\tvalue,\n\t\t\t\tfieldPath: [key],\n\t\t\t});\n\t\t\tif (err) return err;\n\t\t}\n\t}\n\treturn;\n}\n\nexport type EntityValidationProblem = {\n\ttype:\n\t\t| 'null'\n\t\t| 'no-default'\n\t\t| 'invalid-type'\n\t\t| 'invalid-value'\n\t\t| 'invalid-key';\n\tfieldPath: (string | number)[];\n\tmessage: string;\n};\n\nexport function validateEntityField({\n\tfield,\n\tvalue,\n\tfieldPath = [],\n\tdepth,\n\trequireDefaults,\n}: {\n\tfield: StorageFieldSchema;\n\tvalue: any;\n\tfieldPath: (string | number)[];\n\tdepth?: number;\n\trequireDefaults?: boolean;\n}): EntityValidationProblem | undefined {\n\tif (depth !== undefined && depth <= 0) return;\n\n\tif (isNullable(field) && value === null) return;\n\tif (value === null) {\n\t\tif (requireDefaults || !hasDefault(field)) {\n\t\t\treturn {\n\t\t\t\ttype: 'no-default',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Invalid null value for field ${formatField(fieldPath)}`,\n\t\t\t};\n\t\t}\n\t}\n\n\tif (field.type === 'object') {\n\t\tif (!isObject(value)) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected object ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t\tfor (const [key, subField] of Object.entries(\n\t\t\tfield.properties as StorageFieldsSchema,\n\t\t)) {\n\t\t\t// legacy -- old objects sometimes accidentally include this key\n\t\t\tif (key === OID_KEY) continue;\n\t\t\tif (value[key]) {\n\t\t\t\tvalidateEntityField({\n\t\t\t\t\tfield: subField,\n\t\t\t\t\tvalue: value[key],\n\t\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\t// check for unexpected keys\n\t\tfor (const key of Object.keys(value)) {\n\t\t\tif (!field.properties[key]) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'invalid-key',\n\t\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\t\tmessage: `Invalid unexpected field \"${key}\" on value ${formatField(\n\t\t\t\t\t\tfieldPath,\n\t\t\t\t\t)}`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t} else if (field.type === 'array') {\n\t\tif (!Array.isArray(value)) {\n\t\t\tif (value === null && field.nullable) return;\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-value',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected array ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t\tfor (const item of value) {\n\t\t\tvalidateEntityField({\n\t\t\t\tfield: field.items,\n\t\t\t\tvalue: item,\n\t\t\t\tfieldPath: [...fieldPath, '[]'],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t});\n\t\t}\n\t} else if (field.type === 'map') {\n\t\tif (!isObject(value)) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected map for field ${formatField(\n\t\t\t\t\tfieldPath,\n\t\t\t\t)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t\tfor (const [key, item] of Object.entries(value)) {\n\t\t\tvalidateEntityField({\n\t\t\t\tfield: field.values,\n\t\t\t\tvalue: item,\n\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t});\n\t\t}\n\t} else if (field.type === 'string') {\n\t\tif (typeof value !== 'string') {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected string ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t\tif (field.options && !field.options.includes(value)) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-value',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected one of ${field.options.join(\n\t\t\t\t\t', ',\n\t\t\t\t)} for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t} else if (field.type === 'boolean') {\n\t\tif (typeof value !== 'boolean') {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected boolean ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t} else if (field.type === 'number') {\n\t\tif (typeof value !== 'number') {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected number ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t} else if (field.type === 'file') {\n\t\tif (!isFile(value) && !isFileData(value)) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected file ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t}\n}\n\nfunction formatField(fieldPath: (string | number)[]) {\n\tif (fieldPath.length === 0) return 'root';\n\treturn fieldPath.join('.');\n}\n\nexport function constrainEntity(schema: StorageFieldsSchema, entity: any): any {\n\tconst constrained: any = {};\n\tfor (const [key, value] of Object.entries(entity)) {\n\t\tif (!schema[key]) continue;\n\t\tconstrained[key] = constrainEntityField({\n\t\t\tfield: schema[key],\n\t\t\tvalue,\n\t\t\tfieldPath: [key],\n\t\t});\n\t}\n\treturn constrained;\n}\n\nexport function constrainEntityField({\n\tfield,\n\tvalue,\n\tfieldPath = [],\n\tdepth,\n}: {\n\tfield: StorageFieldSchema;\n\tvalue: any;\n\tfieldPath?: (string | number)[];\n\tdepth?: number;\n}): any {\n\tconst validationProblem = validateEntityField({\n\t\tfield,\n\t\tvalue,\n\t\tfieldPath,\n\t\tdepth,\n\t\trequireDefaults: true,\n\t});\n\n\tif (validationProblem) {\n\t\tthrow new Error(`Validation error: ${validationProblem.message}`);\n\t}\n\n\tif (field.type === 'object') {\n\t\tif (!isObject(value)) return value;\n\t\tconst constrained: any = {};\n\t\tfor (const [key, subField] of Object.entries(\n\t\t\tfield.properties as StorageFieldsSchema,\n\t\t)) {\n\t\t\tconstrained[key] = constrainEntityField({\n\t\t\t\tfield: subField,\n\t\t\t\tvalue: value[key],\n\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t});\n\t\t}\n\t\treturn constrained;\n\t} else if (field.type === 'array') {\n\t\tif (!Array.isArray(value)) return value;\n\t\treturn value.map((item) =>\n\t\t\tconstrainEntityField({\n\t\t\t\tfield: field.items,\n\t\t\t\tvalue: item,\n\t\t\t\tfieldPath: [...fieldPath, '[]'],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t}),\n\t\t);\n\t} else if (field.type === 'map') {\n\t\tif (!isObject(value)) return value;\n\t\tconst constrained: any = {};\n\t\tfor (const [key, item] of Object.entries(value)) {\n\t\t\tconstrained[key] = constrainEntityField({\n\t\t\t\tfield: field.values,\n\t\t\t\tvalue: item,\n\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t});\n\t\t}\n\t\treturn constrained;\n\t} else {\n\t\treturn value;\n\t}\n}\n", "import { StorageFieldSchema, StorageFieldsSchema } from './types.js';\n\nexport function getChildFieldSchema(\n\tschema: StorageFieldSchema | StorageFieldsSchema,\n\tkey: string | number,\n): StorageFieldSchema | null {\n\tif (schema.type === 'object') {\n\t\treturn schema.properties[key];\n\t} else if (schema.type === 'array') {\n\t\treturn schema.items;\n\t} else if (schema.type === 'map') {\n\t\treturn schema.values;\n\t} else if (schema.type === 'any') {\n\t\treturn schema;\n\t} else if (!('type' in schema)) {\n\t\treturn schema[key] ?? null;\n\t}\n\treturn null;\n}\n", "import {\n\tStorageCollectionSchema,\n\tStorageSyntheticIndexSchema,\n\tCollectionCompoundIndex,\n\tStorageDirectSyntheticSchema,\n} from './index.js';\n\n// unlikely to be used unicode character\nexport const COMPOUND_INDEX_SEPARATOR = '\\uFFFFFE';\n// 1 lower than separator\nexport const COMPOUND_INDEX_LOWER_BOUND_SEPARATOR = '\\u0000';\n// 1 higher than separator\nexport const COMPOUND_INDEX_UPPER_BOUND_SEPARATOR = '\\uFFFFFF';\n\ntype IndexableFieldValue = string | number | boolean | any[];\nexport type CompoundIndexValue = string | string[];\n\nexport function createCompoundIndexValue(\n\t...fields: IndexableFieldValue[]\n): CompoundIndexValue {\n\tconst value = expandArrayIndex(fields);\n\tif (value.length === 1) {\n\t\treturn value[0];\n\t}\n\treturn value;\n}\n\nexport function createUpperBoundIndexValue(\n\t...fields: IndexableFieldValue[]\n): string {\n\treturn (\n\t\tfields.join(COMPOUND_INDEX_SEPARATOR) +\n\t\t`${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`\n\t);\n}\n\nexport function createLowerBoundIndexValue(\n\t...fields: IndexableFieldValue[]\n): string {\n\treturn (\n\t\tfields.join(COMPOUND_INDEX_SEPARATOR) +\n\t\t`${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`\n\t);\n}\n\n/**\n * Whenever an array value is included in a compound index, we have to expand\n * the value to include all permutations of values in the array.\n * For example if we had an index id + tags on a document\n *\n * {\n * id: '1',\n * tags: ['a', 'b']\n * }\n *\n * we want to create an index:\n *\n * id_tags: ['1#a', '1#b']\n *\n * If multiple arrays are indexed we have to exponentially expand...\n *\n * id_tags_tags2: ['1#a#a', '1#a#b', '1#b#a', '1#b#b']\n *\n * To generalize this we construct a 2-level array of strings.\n * Iterating over indexed values, we expand each item into N items if\n * the current value is an array.\n *\n * Then we combine all nested arrays into compound index values.\n * This will produce an array of 1 element if none of the indexed values\n * were arrays. The caller should unwrap that.\n *\n * This function also deduplicates values.\n */\nfunction expandArrayIndex(fields: IndexableFieldValue[]): string[] {\n\tlet value: string[][] = [[]];\n\tfor (const field of fields) {\n\t\tif (Array.isArray(field)) {\n\t\t\tconst newValue: string[][] = [];\n\t\t\tfor (const previousValue of value) {\n\t\t\t\tfor (const fieldValue of field) {\n\t\t\t\t\tnewValue.push(previousValue.concat(fieldValue));\n\t\t\t\t}\n\t\t\t}\n\t\t\tvalue = newValue;\n\t\t} else {\n\t\t\tfor (const item of value) {\n\t\t\t\titem.push(`${field}`);\n\t\t\t}\n\t\t}\n\t}\n\treturn Array.from(\n\t\tnew Set(\n\t\t\tvalue.map((item) => {\n\t\t\t\treturn item.join(COMPOUND_INDEX_SEPARATOR);\n\t\t\t}),\n\t\t),\n\t);\n}\n\nexport function isDirectSynthetic(\n\tindex: any,\n): index is StorageDirectSyntheticSchema<any> {\n\treturn !!index.field;\n}\n\nexport function computeSynthetics(schema: StorageCollectionSchema, obj: any) {\n\tconst result: Record<string, any> = {};\n\tfor (const [name, property] of Object.entries(schema.indexes || {})) {\n\t\tconst index = property as StorageSyntheticIndexSchema<any>;\n\t\tif (isDirectSynthetic(index)) {\n\t\t\tresult[name] = sanitizeIndexValue(obj[index.field]);\n\t\t} else {\n\t\t\tresult[name] = sanitizeIndexValue(index.compute(obj));\n\t\t}\n\t}\n\treturn result;\n}\n\nexport function computeCompoundIndices(\n\tschema: StorageCollectionSchema<any, any, any>,\n\tdoc: any,\n): any {\n\treturn Object.entries(schema.compounds || {}).reduce<\n\t\tRecord<string, CompoundIndexValue>\n\t>(\n\t\t(acc, [indexKey, index]) => {\n\t\t\tacc[indexKey] = createCompoundIndexValue(\n\t\t\t\t...(index as CollectionCompoundIndex<any, any>).of.map(\n\t\t\t\t\t(key) => doc[key] as string | number,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<string, CompoundIndexValue>,\n\t);\n}\n\nfunction computeIndexedFields(schema: StorageCollectionSchema, doc: any) {\n\treturn Object.entries(schema.fields).reduce<Record<string, any>>(\n\t\t(acc, [key, field]) => {\n\t\t\t// TODO: remove once I'm comfortable dropping 'indexed' support\n\t\t\tif ('indexed' in field) {\n\t\t\t\tacc[key] = sanitizeIndexValue(doc[key]);\n\t\t\t}\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n}\n\nexport function getIndexValues(\n\tschema: StorageCollectionSchema<any, any, any>,\n\tdoc: any,\n) {\n\tconst basicIndexes: any = {\n\t\t[schema.primaryKey]: doc[schema.primaryKey],\n\t\t...computeIndexedFields(schema, doc),\n\t\t...computeSynthetics(schema, doc),\n\t};\n\tObject.assign(\n\t\tbasicIndexes,\n\t\tcomputeCompoundIndices(schema, { ...doc, ...basicIndexes }),\n\t);\n\tbasicIndexes['@@@snapshot'] = JSON.stringify(doc);\n\treturn basicIndexes;\n}\n\nexport function assignIndexValues(\n\tschema: StorageCollectionSchema<any, any, any>,\n\tdoc: any,\n) {\n\tObject.assign(doc, computeSynthetics(schema, doc));\n\tObject.assign(doc, computeCompoundIndices(schema, doc));\n\treturn doc;\n}\n\nexport const NULL_INDEX_VALUE = 'null';\n\nexport function sanitizeIndexValue(\n\tvalue: unknown,\n): string | number | (string | number)[] {\n\tif (value === null) {\n\t\treturn NULL_INDEX_VALUE;\n\t}\n\tif (typeof value === 'string' || typeof value === 'number') {\n\t\treturn value;\n\t}\n\tif (typeof value === 'boolean' || value === null) {\n\t\treturn `${value}`;\n\t}\n\tif (value === undefined) {\n\t\t// this shouldn't happen ,but for resiliency...\n\t\treturn 'undefined';\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map(sanitizeIndexValue) as any;\n\t}\n\tthrow new Error(`Unsupported index value: ${value}`);\n}\n", "import {\n\tstableStringify,\n\tStorageCollectionSchema,\n\tStorageSchema,\n\taddFieldDefaults,\n\tStorageDocument,\n\tCollectionFilter,\n\tStorageDocumentInit,\n\tremoveExtraProperties,\n\tassert,\n\thasOid,\n\tassignOid,\n\tgetOid,\n\thasDefault,\n\tvalidateEntity,\n\tAuthorizationKey,\n} from './index.js';\n\n/**@deprecated */\nexport interface DroppedCollectionMigrationStrategy<\n\tOld extends StorageCollectionSchema<any, any, any>,\n> {\n\t(old: Old): void | Promise<void>;\n}\n/**@deprecated */\nexport interface PreservedCollectionMigrationStrategy<\n\tOld extends StorageCollectionSchema<any, any, any>,\n\tNew extends StorageCollectionSchema<any, any, any>,\n> {\n\t(\n\t\told: StorageDocument<Old>,\n\t): StorageDocument<New> | Promise<StorageDocument<New>>;\n}\n/** @deprecated */\ntype MigrationStrategy<\n\tOld extends StorageCollectionSchema<any, any, any>,\n\tNew extends StorageCollectionSchema<any, any, any>,\n> =\n\t| DroppedCollectionMigrationStrategy<Old>\n\t| PreservedCollectionMigrationStrategy<Old, New>;\n/** @deprecated */\nexport type MigrationsKeyedOnCollection<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> =\n\t| PreservedCollectionMigrations<Old, New>\n\t| DroppedCollectionMigrations<Old, New>;\n\n/**@deprecated */\ntype NotInSchema<\n\tName extends string | number | symbol,\n\tSchema extends StorageSchema<any>,\n> = Name extends keyof Schema['collections'] ? never : Name;\n/** @deprecated */\ntype InSchema<\n\tName extends string | number | symbol,\n\tSchema extends StorageSchema<any>,\n> = Name extends keyof Schema['collections'] ? Name : never;\n/** @deprecated */\ntype DroppedCollections<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = {\n\t[Key in keyof Old['collections'] as NotInSchema<\n\t\tKey,\n\t\tNew\n\t>]: StorageCollectionSchema<any, any, any>;\n};\n/** @deprecated */\ntype PreservedCollections<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = {\n\t[Key in keyof Old['collections'] as InSchema<\n\t\tKey,\n\t\tNew\n\t>]: StorageCollectionSchema<any, any, any>;\n};\n/** @deprecated */\ntype DroppedCollectionMigrations<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = {\n\t[Key in keyof DroppedCollections<\n\t\tOld,\n\t\tNew\n\t>]: DroppedCollectionMigrationStrategy<Old['collections'][Key]>;\n};\n/** @deprecated */\ntype PreservedCollectionMigrations<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = {\n\t[Key in keyof PreservedCollections<\n\t\tOld,\n\t\tNew\n\t>]: PreservedCollectionMigrationStrategy<\n\t\tOld['collections'][Key],\n\t\tNew['collections'][Key]\n\t>;\n};\n\n/** @deprecated */\ntype StrategyFor<\n\tKey extends string,\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = Key extends keyof New['collections']\n\t? PreservedCollectionMigrationStrategy<\n\t\t\tOld['collections'][Key],\n\t\t\tNew['collections'][Key]\n\t >\n\t: DroppedCollectionMigrationStrategy<Old['collections'][Key]>;\n\n/** @deprecated */\ntype DeprecatedMigrationRunner<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = <Collection extends Extract<keyof Old['collections'], string>>(\n\tcollection: Collection,\n\tstrategy: StrategyFor<Collection, Old, New>,\n) => Promise<void>;\n\n/** @deprecated */\ntype DeprecatedMigrationQueryMaker<\n\tCollection extends StorageCollectionSchema<any, any, any>,\n> = {\n\tget(primaryKey: string): Promise<StorageDocument<Collection> | undefined>;\n\tfindOne(\n\t\tquery: CollectionFilter,\n\t): Promise<StorageDocument<Collection> | undefined>;\n\tfindAll(query?: CollectionFilter): Promise<StorageDocument<Collection>[]>;\n};\n\n/** @deprecated */\ntype DeprecatedMigrationQueries<Old extends StorageSchema<any>> = {\n\t[Key in keyof Old['collections']]: DeprecatedMigrationQueryMaker<\n\t\tOld['collections'][Key]\n\t>;\n};\n\n/** @deprecated */\ntype DeprecatedMigrationMutations<New extends StorageSchema> = {\n\t[Key in keyof New['collections']]: {\n\t\tput(\n\t\t\tdocument: StorageDocumentInit<New['collections'][Key]>,\n\t\t): Promise<StorageDocument<New['collections'][Key]>>;\n\t\tdelete(primaryKey: string): Promise<void>;\n\t};\n};\n/** @deprecated */\nexport interface DeprecatedMigrationTools<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> {\n\tmigrate: DeprecatedMigrationRunner<Old, New>;\n\tidentity: <T>(val: T) => T;\n\t/**\n\t * @deprecated - default field values are automatically\n\t * applied during migration, you don't need to use this.\n\t * Please remove it from your migrations - even old ones\n\t * (old migrations can be updated!)\n\t */\n\twithDefaults: (collectionName: string, value: any) => any;\n\tqueries: DeprecatedMigrationQueries<Old>;\n\tmutations: DeprecatedMigrationMutations<New>;\n\tinfo: {\n\t\tchangedCollections: keyof Old['collections'][];\n\t\taddedCollections: keyof New['collections'][];\n\t\tremovedCollections: keyof Old['collections'][];\n\t};\n}\n\nexport interface MigrationEngine {\n\tmigrate: (collection: string, strategy: (val: any) => any) => Promise<void>;\n\tqueries: MigrationQueries<any>;\n\tmutations: MigrationMutations<any>;\n\t/** OIDs of any new documents created during the migration */\n\tnewOids: string[];\n\t/** Promises that should be resolved before completing the migration */\n\tawaitables: Promise<any>[];\n\t/** Deletes all documents in a collection - used for removed collections */\n\tdeleteCollection: (collection: string) => Promise<void>;\n\tlog: (...messages: any[]) => void;\n}\n/** @deprecated */\ntype DeprecatedMigrationProcedure<\n\tOld extends StorageSchema,\n\tNew extends StorageSchema,\n> = (tools: DeprecatedMigrationTools<Old, New>) => Promise<void>;\n\ntype EmptySchema = {\n\tversion: 0;\n\tcollections: {};\n};\nconst emptySchema: EmptySchema = {\n\tversion: 0,\n\tcollections: {},\n};\n\n/** @deprecated - use createMigration */\nexport function migrate<Schema extends StorageSchema>(\n\tschema: Schema,\n\tprocedure: DeprecatedMigrationProcedure<EmptySchema, Schema>,\n): Migration<EmptySchema, Schema>;\n/** @deprecated = use createMigration */\nexport function migrate<Old extends StorageSchema, New extends StorageSchema>(\n\toldSchema: Old,\n\tnewSchema: New,\n\tprocedure: DeprecatedMigrationProcedure<Old, New>,\n): Migration<Old, New>;\nexport function migrate(\n\toldSchemaOrNewSchema: any,\n\tnewSchemaOrProcedure: any,\n\tprocedureIfTwoSchemas?: any,\n) {\n\tconst isProcedureSecondArgument = typeof newSchemaOrProcedure === 'function';\n\tconst oldSchema = isProcedureSecondArgument\n\t\t? emptySchema\n\t\t: oldSchemaOrNewSchema;\n\tconst newSchema = isProcedureSecondArgument\n\t\t? oldSchemaOrNewSchema\n\t\t: newSchemaOrProcedure;\n\tconst procedure = isProcedureSecondArgument\n\t\t? newSchemaOrProcedure\n\t\t: procedureIfTwoSchemas;\n\t// diff to determine changed collections\n\tconst changedCollections: string[] = Object.keys(\n\t\tnewSchema.collections,\n\t).filter(\n\t\t(key) =>\n\t\t\toldSchema.collections[key] &&\n\t\t\tstableStringify(oldSchema.collections[key]) !==\n\t\t\t\tstableStringify(newSchema.collections[key]),\n\t);\n\tconst removedCollections: string[] = Object.keys(\n\t\toldSchema.collections,\n\t).filter((key) => !newSchema.collections[key]);\n\tconst addedCollections = Object.keys(newSchema.collections).filter(\n\t\t(key) => !oldSchema.collections[key],\n\t);\n\t// collections which added one or more field defaults\n\tconst autoMigratedCollections = new Set<string>();\n\tfor (const collection of changedCollections) {\n\t\tconst oldFields = oldSchema.collections[collection].fields;\n\t\tconst newFields = newSchema.collections[collection].fields;\n\t\t// a new default was added - we can auto-migrate it\n\t\tif (\n\t\t\tObject.keys(newFields).some(\n\t\t\t\t(key) => !oldFields[key]?.default && newFields[key]?.default,\n\t\t\t)\n\t\t) {\n\t\t\tautoMigratedCollections.add(collection);\n\t\t}\n\t\t// a field was removed - we can auto-migrate it\n\t\tif (Object.keys(oldFields).some((key) => !newFields[key])) {\n\t\t\tautoMigratedCollections.add(collection);\n\t\t}\n\t}\n\n\tconst addedIndexes: Record<string, MigrationIndexDescription[]> = {};\n\tconst removedIndexes: Record<string, MigrationIndexDescription[]> = {};\n\tfor (const changed of [...changedCollections, ...addedCollections]) {\n\t\tconst oldIndexes = getIndexes(oldSchema.collections[changed]);\n\t\tconst newIndexes = getIndexes(newSchema.collections[changed]);\n\t\tconst added = newIndexes.filter(\n\t\t\t(index) => !oldIndexes.find((i) => i.name === index.name),\n\t\t);\n\t\tconst removed = oldIndexes.filter(\n\t\t\t(index) => !newIndexes.find((i) => i.name === index.name),\n\t\t);\n\t\tif (added.length > 0) {\n\t\t\taddedIndexes[changed] = added;\n\t\t\t// FIXME: don't o(n^2) this\n\t\t\tif (changedCollections.includes(changed)) {\n\t\t\t\tautoMigratedCollections.add(changed);\n\t\t\t}\n\t\t}\n\t\tif (removed.length > 0) {\n\t\t\tremovedIndexes[changed] = removed;\n\t\t\t// FIXME: don't o(n^2) this\n\t\t\tif (changedCollections.includes(changed)) {\n\t\t\t\tautoMigratedCollections.add(changed);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst withDefaults = (collectionName: string, val: any) => {\n\t\treturn addFieldDefaults(newSchema.collections[collectionName], val);\n\t};\n\tconst autoMigration = (collectionName: string) => (val: any) => {\n\t\tconst collection = newSchema.collections[collectionName];\n\t\treturn addFieldDefaults(collection, removeExtraProperties(collection, val));\n\t};\n\n\treturn {\n\t\tversion: newSchema.version,\n\t\tmigrate: async (engine: MigrationEngine) => {\n\t\t\tconst migratedCollections: string[] = [];\n\t\t\tawait procedure({\n\t\t\t\tmigrate: async (collection: any, strategy: any) => {\n\t\t\t\t\tconst auto = autoMigration(collection);\n\t\t\t\t\tconst wrapped = async (val: any) => {\n\t\t\t\t\t\tconst baseValue = await strategy(val);\n\t\t\t\t\t\t// assign OID from original value in case user's strategy\n\t\t\t\t\t\t// involves cloning\n\t\t\t\t\t\tassignOid(baseValue, getOid(val));\n\t\t\t\t\t\tconst result = auto(baseValue);\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tawait engine.migrate(collection, wrapped);\n\t\t\t\t\tmigratedCollections.push(collection);\n\t\t\t\t\t// since the user migrated this one and we wrap their\n\t\t\t\t\t// strategy with auto-migration, we can remove it from\n\t\t\t\t\t// the auto-migration list\n\t\t\t\t\tautoMigratedCollections.delete(collection);\n\t\t\t\t},\n\t\t\t\tidentity: (val: any) => val,\n\t\t\t\twithDefaults,\n\t\t\t\tinfo: {\n\t\t\t\t\tchangedCollections,\n\t\t\t\t\taddedCollections,\n\t\t\t\t\tremovedCollections,\n\t\t\t\t},\n\t\t\t\tqueries: engine.queries,\n\t\t\t\tmutations: engine.mutations,\n\t\t\t});\n\n\t\t\t// mandatory migration of fields which had defaults added or\n\t\t\t// fields removed but weren't migrated by the user\n\n\t\t\tif (newSchema.version > 1) {\n\t\t\t\tengine.log(\n\t\t\t\t\t'debug',\n\t\t\t\t\t'auto-migrating collections with new defaults',\n\t\t\t\t\tautoMigratedCollections,\n\t\t\t\t);\n\t\t\t\tfor (const name of autoMigratedCollections) {\n\t\t\t\t\tawait engine.migrate(name, autoMigration(name));\n\t\t\t\t\tmigratedCollections.push(name);\n\t\t\t\t}\n\n\t\t\t\tconst unmigrated = changedCollections.filter(\n\t\t\t\t\t(collection) => !migratedCollections.includes(collection),\n\t\t\t\t);\n\t\t\t\tif (unmigrated.length > 0) {\n\t\t\t\t\t// TODO: does this deserve a full-on error?\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`Unmigrated changed collections from version ${oldSchema.version} to version ${newSchema.version}:`,\n\t\t\t\t\t\tunmigrated,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tremovedCollections,\n\t\taddedIndexes,\n\t\tremovedIndexes,\n\t\tallCollections: Object.keys(newSchema.collections),\n\t\tchangedCollections,\n\t\taddedCollections,\n\t\toldCollections: Object.keys(oldSchema.collections),\n\t\toldSchema,\n\t\tnewSchema,\n\t};\n}\n\nexport interface MigrationIndexDescription {\n\tname: string;\n\tmultiEntry: boolean;\n\tsynthetic: boolean;\n\tcompound: boolean;\n}\n\nexport interface Migration<\n\tOld extends StorageSchema = any,\n\tNew extends StorageSchema = any,\n> {\n\tversion: number;\n\toldSchema: Old;\n\tnewSchema: New;\n\tmigrate: (engine: MigrationEngine) => Promise<void>;\n\t/** Collections which are added in the new schema and not present in the old */\n\taddedCollections: string[];\n\t/** Collections which were removed from the old schema */\n\tremovedCollections: string[];\n\t/** All collections which exist after the migration has completed - i.e. the ones in the new schema */\n\tallCollections: string[];\n\t/** Only the collections which were in the old schema */\n\toldCollections: string[];\n\t/** Collections whose fields or indexes changed between schemas */\n\tchangedCollections: string[];\n\t// new indexes mapped by collection name\n\taddedIndexes: Record<string, MigrationIndexDescription[]>;\n\t// removed indexes mapped by collection name\n\tremovedIndexes: Record<string, MigrationIndexDescription[]>;\n}\n\nexport function migrationRange(from: number, to: number) {\n\treturn [...Array(to - from).keys()].map((i) => 1 + i + from);\n}\n\nfunction getIndexes<Coll extends StorageCollectionSchema<any, any, any>>(\n\tcollection: Coll | undefined,\n): MigrationIndexDescription[] {\n\tif (!collection) return [];\n\n\treturn [\n\t\t...Object.keys(collection.indexes || {}).map((key) => ({\n\t\t\tname: key,\n\t\t\tmultiEntry: ['array', 'string[]', 'number[]', 'boolean[]'].includes(\n\t\t\t\tcollection.indexes[key].type,\n\t\t\t),\n\t\t\tsynthetic: true,\n\t\t\tcompound: false,\n\t\t})),\n\t\t...Object.keys(collection.compounds || {}).map((key) => ({\n\t\t\tname: key,\n\t\t\tmultiEntry: collection.compounds[key].of.some(\n\t\t\t\t(fieldName: string) =>\n\t\t\t\t\t(collection.fields[fieldName] || collection.indexes[fieldName])\n\t\t\t\t\t\t.type === 'array',\n\t\t\t),\n\t\t\tsynthetic: false,\n\t\t\tcompound: true,\n\t\t})),\n\t];\n}\n\n/** @deprecated - use createMigration with no procedure function */\nexport function createDefaultMigration(\n\tschema: StorageSchema,\n): Migration<{ version: 0; collections: {} }>;\n/** @deprecated - use createMigration with no procedure function */\nexport function createDefaultMigration<Old extends StorageSchema>(\n\toldSchema: Old,\n\tnewSchema: StorageSchema,\n): Migration<Old>;\nexport function createDefaultMigration(\n\tschema: StorageSchema,\n\tnewSchema?: StorageSchema<any>,\n) {\n\tlet oldSchema = newSchema\n\t\t? schema\n\t\t: {\n\t\t\t\tversion: 0,\n\t\t\t\tcollections: {},\n\t\t };\n\treturn migrate(oldSchema, newSchema || schema, async ({ migrate, info }) => {\n\t\tif ((newSchema || schema).version === 1) return;\n\n\t\tfor (const collection of info.changedCollections as any) {\n\t\t\t// @ts-ignore indefinite type resolution\n\t\t\tawait migrate(collection, (old) => old);\n\t\t}\n\t});\n}\n\n/** New, simpler type-safety migration tools */\ntype DocumentShape<Init = any, Snapshot = any> = {\n\tinit: Init;\n\tsnapshot: Snapshot;\n};\ntype SchemaDocuments = Record<string, DocumentShape>;\ntype CollectionProcedure<OldSnapshot, NewInit> = {\n\t(old: OldSnapshot): NewInit | Promise<NewInit>;\n};\ntype MigrationQueries<Old extends SchemaDocuments> = {\n\t[Key in keyof Old]: {\n\t\tget(primaryKey: string): Promise<Old[Key]['snapshot'] | undefined>;\n\t\tfindOne(query: CollectionFilter): Promise<Old[Key]['snapshot'] | undefined>;\n\t\tfindAll(query?: CollectionFilter): Promise<Old[Key]['snapshot'][]>;\n\t};\n};\ntype MigrationMutations<New extends SchemaDocuments> = {\n\t[Key in keyof New]: {\n\t\tput(\n\t\t\tdocument: New[Key]['init'],\n\t\t\toptions?: { access?: AuthorizationKey },\n\t\t): Promise<New[Key]['snapshot']>;\n\t\tdelete(primaryKey: string): Promise<void>;\n\t};\n};\ntype MigrationTools<\n\tOld extends SchemaDocuments,\n\tNew extends SchemaDocuments,\n> = {\n\t/**\n\t * Process a change in a collection's documents by taking in each existing\n\t * document and returning its new shape. This is typed so you can be\n\t * confident the proper transformations are made.\n\t */\n\tmigrate: <Collection extends keyof Old & keyof New>(\n\t\tcollection: Collection,\n\t\tstrategy: CollectionProcedure<\n\t\t\tOld[Collection]['snapshot'],\n\t\t\tNew[Collection]['init']\n\t\t>,\n\t) => Promise<void>;\n\tmutations: MigrationMutations<New>;\n\tqueries: MigrationQueries<Old>;\n\tinfo: {\n\t\tchangedCollections: (keyof Old & keyof New)[];\n\t\taddedCollections: (keyof New)[];\n\t\tremovedCollections: (keyof Old)[];\n\t};\n};\ntype MigrationProcedure<\n\tOld extends SchemaDocuments,\n\tNew extends SchemaDocuments,\n> = {\n\t(tools: MigrationTools<Old, New>): Promise<void>;\n};\ntype InitialMigrationTools<New extends SchemaDocuments> = {\n\tmutations: MigrationMutations<New>;\n};\ntype InitialMigrationProcedure<New extends SchemaDocuments> = {\n\t(tools: InitialMigrationTools<New>): Promise<void>;\n};\n\nexport function createMigration<New extends SchemaDocuments>(\n\tnewSchema: StorageSchema,\n\tprocedure?: InitialMigrationProcedure<New>,\n): any;\nexport function createMigration<\n\tOld extends SchemaDocuments,\n\tNew extends SchemaDocuments,\n>(\n\toldSchema: StorageSchema,\n\tnewSchema: StorageSchema,\n\tprocedure?: MigrationProcedure<Old, New>,\n): any;\nexport function createMigration(\n\tmaybeOldSchema: StorageSchema,\n\tmaybeNewSchemaOrProcedure?:\n\t\t| StorageSchema\n\t\t| InitialMigrationProcedure<SchemaDocuments>,\n\tmaybeProcedure?: MigrationProcedure<SchemaDocuments, SchemaDocuments>,\n): any {\n\tconst isProcedureSecondArgument =\n\t\ttypeof maybeNewSchemaOrProcedure === 'function' ||\n\t\tmaybeNewSchemaOrProcedure === undefined;\n\tconst oldSchema = isProcedureSecondArgument ? emptySchema : maybeOldSchema;\n\tconst newSchema = isProcedureSecondArgument\n\t\t? maybeOldSchema\n\t\t: maybeNewSchemaOrProcedure;\n\tconst procedure = isProcedureSecondArgument\n\t\t? maybeNewSchemaOrProcedure\n\t\t: maybeProcedure;\n\tassert(oldSchema, 'Invalid arguments to createMigration');\n\tassert(newSchema, 'Invalid arguments to createMigration');\n\tconst {\n\t\tchangedCollections,\n\t\taddedCollections,\n\t\tremovedCollections,\n\t\taddedIndexes,\n\t\tremovedIndexes,\n\t\tautoMigratedCollections,\n\t\tautoMigration,\n\t} = getMigrationInfo(oldSchema, newSchema);\n\n\treturn {\n\t\tversion: newSchema.version,\n\t\tmigrate: async (engine: MigrationEngine) => {\n\t\t\tconst migratedCollections: string[] = [];\n\t\t\tconst migrate = async (collection: any, strategy: any) => {\n\t\t\t\tconst auto = autoMigration(collection);\n\t\t\t\tconst wrapped = async (val: any) => {\n\t\t\t\t\tconst baseValue = await strategy(val);\n\t\t\t\t\t// assign OID from original value in case user's strategy\n\t\t\t\t\t// involves cloning\n\t\t\t\t\tassignOid(baseValue, getOid(val));\n\t\t\t\t\tconst result = auto(baseValue);\n\t\t\t\t\tconst validationError = validateEntity(\n\t\t\t\t\t\tnewSchema.collections[collection].fields,\n\t\t\t\t\t\tresult,\n\t\t\t\t\t);\n\t\t\t\t\tif (validationError) {\n\t\t\t\t\t\t// TODO: what? throw?\n\t\t\t\t\t}\n\t\t\t\t\treturn result;\n\t\t\t\t};\n\t\t\t\t// @ts-ignore\n\t\t\t\tawait engine.migrate(collection, wrapped);\n\t\t\t\tmigratedCollections.push(collection);\n\t\t\t\t// since the user migrated this one and we wrap their\n\t\t\t\t// strategy with auto-migration, we can remove it from\n\t\t\t\t// the auto-migration list\n\t\t\t\tautoMigratedCollections.delete(collection);\n\t\t\t};\n\t\t\tawait procedure?.({\n\t\t\t\tmigrate,\n\t\t\t\tinfo: {\n\t\t\t\t\tchangedCollections,\n\t\t\t\t\taddedCollections,\n\t\t\t\t\tremovedCollections,\n\t\t\t\t},\n\t\t\t\tqueries: engine.queries,\n\t\t\t\tmutations: engine.mutations,\n\t\t\t});\n\n\t\t\t// mandatory migration of fields which had defaults added or\n\t\t\t// fields removed but weren't migrated by the user\n\n\t\t\tif (newSchema.version > 1) {\n\t\t\t\tengine.log(\n\t\t\t\t\t'debug',\n\t\t\t\t\t'auto-migrating collections with new defaults',\n\t\t\t\t\tautoMigratedCollections,\n\t\t\t\t);\n\t\t\t\tfor (const name of autoMigratedCollections) {\n\t\t\t\t\tawait engine.migrate(name, autoMigration(name));\n\t\t\t\t\tmigratedCollections.push(name);\n\t\t\t\t}\n\n\t\t\t\t// delete all documents in deleted collections\n\t\t\t\tfor (const name of removedCollections) {\n\t\t\t\t\tawait engine.deleteCollection(name);\n\t\t\t\t}\n\n\t\t\t\tconst unmigrated = changedCollections.filter(\n\t\t\t\t\t(collection) => !migratedCollections.includes(collection),\n\t\t\t\t);\n\t\t\t\tif (unmigrated.length > 0) {\n\t\t\t\t\t// TODO: does this deserve a full-on error?\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`Unmigrated changed collections from version ${oldSchema.version} to version ${newSchema.version}:`,\n\t\t\t\t\t\tunmigrated,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tremovedCollections,\n\t\taddedIndexes,\n\t\tremovedIndexes,\n\t\tallCollections: Object.keys(newSchema.collections),\n\t\tchangedCollections,\n\t\taddedCollections,\n\t\toldCollections: Object.keys(oldSchema.collections),\n\t\toldSchema,\n\t\tnewSchema,\n\t};\n}\n\n// common tools\nfunction getMigrationInfo(oldSchema: StorageSchema, newSchema: StorageSchema) {\n\tconst changedCollections: string[] = Object.keys(\n\t\tnewSchema.collections,\n\t).filter(\n\t\t(key) =>\n\t\t\toldSchema.collections[key] &&\n\t\t\tstableStringify(oldSchema.collections[key]) !==\n\t\t\t\tstableStringify(newSchema.collections[key]),\n\t);\n\tconst removedCollections: string[] = Object.keys(\n\t\toldSchema.collections,\n\t).filter((key) => !newSchema.collections[key]);\n\tconst addedCollections = Object.keys(newSchema.collections).filter(\n\t\t(key) => !oldSchema.collections[key],\n\t);\n\t// collections which added one or more field defaults\n\tconst autoMigratedCollections = new Set<string>();\n\tfor (const collection of changedCollections) {\n\t\tconst oldFields = oldSchema.collections[collection].fields;\n\t\tconst newFields = newSchema.collections[collection].fields;\n\t\t// a new default was added - we can auto-migrate it\n\t\tif (\n\t\t\tObject.keys(newFields).some(\n\t\t\t\t(key) => !hasDefault(oldFields[key]) && hasDefault(newFields[key]),\n\t\t\t)\n\t\t) {\n\t\t\tautoMigratedCollections.add(collection);\n\t\t}\n\t\t// a field was removed - we can auto-migrate it\n\t\tif (Object.keys(oldFields).some((key) => !newFields[key])) {\n\t\t\tautoMigratedCollections.add(collection);\n\t\t}\n\t}\n\n\tconst addedIndexes: Record<string, MigrationIndexDescription[]> = {};\n\tconst removedIndexes: Record<string, MigrationIndexDescription[]> = {};\n\tfor (const changed of [...changedCollections, ...addedCollections]) {\n\t\tconst oldIndexes = getIndexes(oldSchema.collections[changed]);\n\t\tconst newIndexes = getIndexes(newSchema.collections[changed]);\n\t\tconst added = newIndexes.filter(\n\t\t\t(index) => !oldIndexes.find((i) => i.name === index.name),\n\t\t);\n\t\tconst removed = oldIndexes.filter(\n\t\t\t(index) => !newIndexes.find((i) => i.name === index.name),\n\t\t);\n\t\tif (added.length > 0) {\n\t\t\taddedIndexes[changed] = added;\n\t\t\t// FIXME: don't o(n^2) this\n\t\t\tif (changedCollections.includes(changed)) {\n\t\t\t\tautoMigratedCollections.add(changed);\n\t\t\t}\n\t\t}\n\t\tif (removed.length > 0) {\n\t\t\tremovedIndexes[changed] = removed;\n\t\t\t// FIXME: don't o(n^2) this\n\t\t\tif (changedCollections.includes(changed)) {\n\t\t\t\tautoMigratedCollections.add(changed);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst withDefaults = (collectionName: string, val: any) => {\n\t\treturn addFieldDefaults(newSchema.collections[collectionName], val);\n\t};\n\tconst autoMigration = (collectionName: string) => (val: any) => {\n\t\tconst collection = newSchema.collections[collectionName];\n\t\treturn addFieldDefaults(collection, removeExtraProperties(collection, val));\n\t};\n\n\treturn {\n\t\tchangedCollections,\n\t\taddedCollections,\n\t\tremovedCollections,\n\t\taddedIndexes,\n\t\tremovedIndexes,\n\t\tautoMigratedCollections,\n\t\twithDefaults,\n\t\tautoMigration,\n\t};\n}\n", "export interface UserInfo<Profile, Presence> {\n\t/**\n\t * This is the ID representing the user who is utilizing a\n\t * replica client to connect to the storage network.\n\t * One user may have multiple replica clients active at once,\n\t * but their presence will only reflect the most recent\n\t * replica used.\n\t */\n\tid: string;\n\t/**\n\t * This is the ID representing the replica client that is\n\t * connected to the storage network. This is used to\n\t * identify the client when sending messages to it.\n\t */\n\treplicaId: string;\n\n\t/**\n\t * This is the user's server profile. This data is associated\n\t * with the logged in user of the app and cannot be modified\n\t * by the local replica directly.\n\t */\n\tprofile: Profile;\n\n\t/**\n\t * Presence info which can update frequently as a replica\n\t * makes changes. The shape of presence is up to you.\n\t */\n\tpresence: Presence;\n\n\t/**\n\t * This is the internal presence data that Verdant uses\n\t * for some built-in presence functionality. The client\n\t * should manage it transparently to the user.\n\t */\n\tinternal: VerdantInternalPresence;\n}\n\nexport type UserInfoUpdate<Profile = any, Presence = any> = Omit<\n\tUserInfo<Profile, Presence>,\n\t'internal' | 'profile'\n> & {\n\tinternal?: VerdantInternalPresence;\n};\n\nexport interface VerdantInternalPresence {\n\tviewId?: string;\n\tlastFieldId?: string;\n\tlastFieldTimestamp?: number;\n}\n\nexport const initialInternalPresence: VerdantInternalPresence = {};\n", "/**\n * High-level patch creation for use with complex nested objects.\n */\n\nimport { FileRef } from './files.js';\nimport { createRef, createSubOid, ObjectIdentifier } from './oids.js';\nimport {\n\tdiffToPatches,\n\tinitialToPatches,\n\tObjectRef,\n\tOperation,\n\tPropertyName,\n} from './operation.js';\nimport { isRef } from './refs.js';\nimport { isObject } from './utils.js';\n\nexport class PatchCreator {\n\tconstructor(\n\t\tprivate getNow: () => string,\n\t\tprivate createSubId?: () => string,\n\t) {}\n\n\tisPrimitive = (value: any) => {\n\t\treturn !isObject(value) || isRef(value);\n\t};\n\n\tcreateDiff = (\n\t\tfrom: any,\n\t\tto: any,\n\t\toptions: { mergeUnknownObjects?: boolean; defaultUndefined?: boolean } = {},\n\t) => {\n\t\treturn diffToPatches(from, to, this.getNow, this.createSubId, [], options);\n\t};\n\n\tcreateInitialize = (obj: any, oid: ObjectIdentifier) => {\n\t\treturn initialToPatches(obj, oid, this.getNow, this.createSubId);\n\t};\n\n\tcreateSet = (\n\t\toid: ObjectIdentifier,\n\t\tkey: PropertyName,\n\t\tvalue: any,\n\t): Operation[] => {\n\t\t// incoming value must be normalized. if it's not a primitive, it and all sub-objects\n\t\t// must be created\n\t\tif (this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\tname: key,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\tconst itemOid = createSubOid(oid, this.createSubId);\n\t\t\treturn [\n\t\t\t\t// since we're setting a complex nested object, we can initialize it wholesale.\n\t\t\t\t// no diffing to do.\n\t\t\t\t...initialToPatches(value, itemOid, this.getNow),\n\t\t\t\t// then set the reference to the object\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\tvalue: createRef(itemOid),\n\t\t\t\t\t\tname: key,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateRemove = (oid: ObjectIdentifier, key: PropertyName): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'remove',\n\t\t\t\t\tname: key,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateListSet = (\n\t\toid: ObjectIdentifier,\n\t\tindex: number,\n\t\tvalue: any,\n\t): Operation[] => {\n\t\tif (this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\tconst itemOid = createSubOid(oid, this.createSubId);\n\t\t\treturn [\n\t\t\t\t...initialToPatches(value, itemOid, this.getNow),\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tvalue: createRef(itemOid),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateListPush = (oid: ObjectIdentifier, value: any): Operation[] => {\n\t\tif (this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-push',\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\tconst itemOid = createSubOid(oid, this.createSubId);\n\t\t\treturn [\n\t\t\t\t...initialToPatches(value, itemOid, this.getNow),\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-push',\n\t\t\t\t\t\tvalue: createRef(itemOid),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateListAdd = (oid: ObjectIdentifier, value: any): Operation[] => {\n\t\tif (!this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-add',\n\t\t\t\t\t\tvalue: createRef(value),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-add',\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateListInsert = (\n\t\toid: ObjectIdentifier,\n\t\tindex: number,\n\t\tvalue: any,\n\t): Operation[] => {\n\t\tif (this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\tconst itemOid = createSubOid(oid, this.createSubId);\n\t\t\treturn [\n\t\t\t\t...initialToPatches(value, itemOid, this.getNow),\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\tvalue: createRef(itemOid),\n\t\t\t\t\t\tindex,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateListRemove = (\n\t\toid: ObjectIdentifier,\n\t\tvalue: any,\n\t\tonly?: 'first' | 'last',\n\t): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'list-remove',\n\t\t\t\t\tvalue,\n\t\t\t\t\tonly,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateListDelete = (\n\t\toid: ObjectIdentifier,\n\t\tindex: number,\n\t\tcount: number = 1,\n\t): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'list-delete',\n\t\t\t\t\tindex,\n\t\t\t\t\tcount,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateListMoveByRef = (\n\t\toid: ObjectIdentifier,\n\t\tvalue: ObjectRef | FileRef,\n\t\tindex: number,\n\t): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'list-move-by-ref',\n\t\t\t\t\tvalue,\n\t\t\t\t\tindex,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateListMoveByIndex = (\n\t\toid: ObjectIdentifier,\n\t\tfromIndex: number,\n\t\ttoIndex: number,\n\t): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'list-move-by-index',\n\t\t\t\t\tfrom: fromIndex,\n\t\t\t\t\tto: toIndex,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateDelete = (oid: ObjectIdentifier): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'delete',\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateDeleteAll = (oids: ObjectIdentifier[]): Operation[] => {\n\t\treturn oids.map((oid) => ({\n\t\t\toid,\n\t\t\ttimestamp: this.getNow(),\n\t\t\tdata: {\n\t\t\t\top: 'delete',\n\t\t\t},\n\t\t}));\n\t};\n}\n", "import { generateId } from './utils.js';\n\nexport class EventSubscriber<\n\tEvents extends { [key: string]: (...args: any[]) => void },\n> {\n\tprotected subscribers: Record<\n\t\tstring,\n\t\tRecord<string, (...args: any[]) => void>\n\t> = {} as any;\n\tprotected counts: Record<string, number> = {} as any;\n\tprivate _disabled = false;\n\tprotected disposed = false;\n\n\tconstructor(private _onAllUnsubscribed?: (event: keyof Events) => void) {}\n\n\tget disabled() {\n\t\treturn this._disabled;\n\t}\n\n\tsubscriberCount = (event: Extract<keyof Events, string>) => {\n\t\treturn this.counts[event] ?? 0;\n\t};\n\n\ttotalSubscriberCount = () => {\n\t\treturn Object.values(this.counts).reduce((acc, count) => acc + count, 0);\n\t};\n\n\tsubscribe = <K extends Extract<keyof Events, string>>(\n\t\tevent: K,\n\t\tcallback: Events[K],\n\t) => {\n\t\tconst key = generateId();\n\t\tlet subscribers = this.subscribers[event];\n\t\tif (!subscribers) {\n\t\t\tsubscribers = this.subscribers[event] = {};\n\t\t}\n\t\tsubscribers[key] = callback;\n\t\tthis.counts[event] = (this.counts[event] || 0) + 1;\n\t\treturn () => {\n\t\t\t// already removed\n\t\t\tif (!this.subscribers[event]) return;\n\n\t\t\tdelete this.subscribers[event][key];\n\t\t\tthis.counts[event]--;\n\t\t\tif (this.counts[event] === 0) {\n\t\t\t\tdelete this.subscribers[event];\n\t\t\t\tdelete this.counts[event];\n\t\t\t\tif (this._onAllUnsubscribed) {\n\t\t\t\t\tthis._onAllUnsubscribed(event);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t};\n\n\temit = <K extends Extract<keyof Events, string>>(\n\t\tevent: K,\n\t\t...args: Parameters<Events[K]>\n\t) => {\n\t\tif (this._disabled) return;\n\t\tif (this.subscribers[event]) {\n\t\t\tObject.values(this.subscribers[event]).forEach((c) => c(...args));\n\t\t}\n\t};\n\n\tdispose = () => {\n\t\tthis._disabled = true;\n\t\tthis.disposed = true;\n\t\tconst events = Object.keys(this.subscribers);\n\t\tthis.subscribers = {} as any;\n\t\tthis.counts = {} as any;\n\t\tevents.forEach((event) => {\n\t\t\tif (this._onAllUnsubscribed) {\n\t\t\t\tthis._onAllUnsubscribed(event);\n\t\t\t}\n\t\t});\n\t};\n\n\tdisable = () => {\n\t\tthis._disabled = true;\n\t};\n}\n\nexport type EventsOf<T extends EventSubscriber<any>> =\n\tT extends EventSubscriber<infer E> ? keyof E : never;\n", "import { ObjectIdentifier } from './oids.js';\nimport { applyPatch, Operation } from './operation.js';\nimport { cloneDeep } from './utils.js';\n\nexport function getUndoOperations(\n\toid: ObjectIdentifier,\n\tinitial: any,\n\toperations: Operation[],\n\tgetNow: () => string,\n): Operation[] {\n\tif (initial === undefined || initial === null) {\n\t\t// if the initial state is nothing, then the undo is to delete everything.\n\t\t// there's nothing else to worry about!\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'delete',\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t}\n\t// otherwise, traverse the operations one by one,\n\t// applying them, and using the prior state to determine\n\t// what the undo operation is.\n\tlet state = cloneDeep(initial);\n\tconst undoOperations: Operation[] = [];\n\tfor (const operation of operations) {\n\t\tconst undo = getUndoOperation(oid, state, operation, getNow);\n\t\tundoOperations.unshift(...undo);\n\t\tapplyPatch(state, operation.data);\n\t}\n\treturn undoOperations;\n}\n\nfunction getUndoOperation(\n\toid: ObjectIdentifier,\n\tinitial: any,\n\toperation: Operation,\n\tgetNow: () => string,\n): Operation[] {\n\tconst data = operation.data;\n\tswitch (data.op) {\n\t\tcase 'set':\n\t\tcase 'remove':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\tname: data.name,\n\t\t\t\t\t\tvalue: initial[data.name],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-insert':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-delete',\n\t\t\t\t\t\tindex: data.index,\n\t\t\t\t\t\tcount: 1,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-delete':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\tindex: data.index,\n\t\t\t\t\t\tvalues: initial.slice(data.index, data.count),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-move-by-ref':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-move-by-ref',\n\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t\tindex: initial.indexOf(data.value),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-move-by-index':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-move-by-index',\n\t\t\t\t\t\tfrom: data.to,\n\t\t\t\t\t\tto: data.from,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'delete':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'initialize',\n\t\t\t\t\t\tvalue: initial,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-push':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-remove',\n\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t\t// best heuristic here - remove the last instance of the item.\n\t\t\t\t\t\tonly: 'last',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-remove':\n\t\t\tif (data.only === 'last') {\n\t\t\t\tconst index = initial.lastIndexOf(data.value);\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\tvalues: [data.value],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} else if (data.only === 'first') {\n\t\t\t\tconst index = initial.indexOf(data.value);\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\tvalues: [data.value],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} else {\n\t\t\t\t// find all instances of value and restore them at their\n\t\t\t\t// original index\n\t\t\t\tconst indexesOfValue = [];\n\t\t\t\tlet index = initial.indexOf(data.value);\n\t\t\t\twhile (index !== -1) {\n\t\t\t\t\tindexesOfValue.push(index);\n\t\t\t\t\tindex = initial.indexOf(data.value, index + 1);\n\t\t\t\t}\n\t\t\t\treturn indexesOfValue.map((index) => ({\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t},\n\t\t\t\t}));\n\t\t\t}\n\t\tcase 'list-add':\n\t\t\t// this one is kind of ambiguous. in theory the set may have\n\t\t\t// already included the value and so no change happened. but\n\t\t\t// basically we infer the intent is to remove what was meant\n\t\t\t// to be added by this change.\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-remove',\n\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t\tonly: 'last',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-set':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\tindex: data.index,\n\t\t\t\t\t\tvalue: initial[data.index],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'initialize':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'delete',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'touch':\n\t\t\treturn [];\n\t\tdefault:\n\t\t\tthrow new Error(`Cannot undo operation type: ${(data as any).op}`);\n\t}\n}\n", "export class Batcher<T, UserData = any> {\n\tprivate batches: Map<string, Batch<T, UserData>> = new Map();\n\n\tconstructor(\n\t\tprivate flusher: (items: T[], batchKey: string, userData: UserData) => any,\n\t) {}\n\n\tadd({\n\t\tkey,\n\t\tuserData,\n\t\titems,\n\t\tmax,\n\t\ttimeout,\n\t}: {\n\t\tkey: string;\n\t\tuserData?: UserData;\n\t\titems: T[];\n\t\tmax?: number | null;\n\t\ttimeout?: number | null;\n\t}) {\n\t\tlet batch = this.batches.get(key);\n\t\tif (!batch) {\n\t\t\tbatch = new Batch({\n\t\t\t\tmax: max || null,\n\t\t\t\tstartedAt: Date.now(),\n\t\t\t\tuserData,\n\t\t\t\ttimeout: timeout || null,\n\t\t\t\tflusher: this.flusher,\n\t\t\t\tkey,\n\t\t\t});\n\t\t\tthis.batches.set(key, batch);\n\t\t}\n\t\tbatch.update({\n\t\t\titems,\n\t\t\tmax,\n\t\t\ttimeout,\n\t\t\tuserData,\n\t\t});\n\n\t\treturn batch;\n\t}\n\n\tflush = (key: string) => {\n\t\tconst batch = this.batches.get(key);\n\t\tif (!batch) return;\n\n\t\treturn batch.flush();\n\t};\n\n\tdiscard = (key: string) => {\n\t\tconst batch = this.batches.get(key);\n\t\tif (!batch) return;\n\n\t\tbatch.discard();\n\t\tthis.batches.delete(key);\n\t};\n\n\tflushAll = () => {\n\t\treturn [...this.batches.values()].map((batch) => batch.flush());\n\t};\n\n\tgetSize = (key: string) => {\n\t\tconst batch = this.batches.get(key);\n\t\tif (!batch) return 0;\n\n\t\treturn batch.items.length;\n\t};\n}\n\nexport class Batch<T, UserData = any> {\n\titems: Array<T> = [];\n\tmax: number | null;\n\tstartedAt: number;\n\ttimeout: number | null;\n\tflushTimeout?: NodeJS.Timeout;\n\tuserData?: any;\n\tflusher: (items: T[], batchKey: string, userData: UserData) => any;\n\tkey: string;\n\n\tconstructor({\n\t\tmax,\n\t\tstartedAt,\n\t\ttimeout,\n\t\tuserData,\n\t\tflusher,\n\t\tkey,\n\t}: {\n\t\tkey: string;\n\t\tmax: number | null;\n\t\tstartedAt: number;\n\t\ttimeout: number | null;\n\t\tuserData?: UserData;\n\t\tflusher: (items: T[], batchKey: string, userData: UserData) => any;\n\t}) {\n\t\tthis.max = max;\n\t\tthis.startedAt = startedAt;\n\t\tthis.timeout = timeout;\n\t\tthis.userData = userData;\n\t\tthis.flusher = flusher;\n\t\tthis.key = key;\n\t}\n\n\tupdate = ({\n\t\titems,\n\t\tmax,\n\t\ttimeout,\n\t\tuserData,\n\t}: {\n\t\titems: Array<T>;\n\t\tmax?: number | null;\n\t\ttimeout?: number | null;\n\t\tuserData?: UserData;\n\t}) => {\n\t\tthis.items.push(...items);\n\t\tif (max !== undefined) this.max = max;\n\t\tif (timeout !== undefined) this.timeout = timeout;\n\t\tif (userData) this.userData = userData;\n\n\t\t// if the batch has items and a timeout but has not\n\t\t// scheduled yet, schedule it\n\t\tconst needsSchedule =\n\t\t\tthis.items.length !== 0 && this.timeout !== null && !this.flushTimeout;\n\n\t\t// if the batch has already reached its max, skip scheduling\n\t\t// and flush immediately\n\t\tif (this.max !== null && this.items.length >= this.max) {\n\t\t\tthis.flush();\n\t\t} else if (needsSchedule && this.timeout !== null) {\n\t\t\tthis.flushTimeout = setTimeout(this.flush, this.timeout);\n\t\t}\n\t};\n\n\tflush = () => {\n\t\tthis.flushTimeout && clearTimeout(this.flushTimeout);\n\t\tthis.flushTimeout = undefined;\n\t\tconst items = this.items;\n\t\tthis.items = [];\n\t\treturn this.flusher(items, this.key, this.userData);\n\t};\n\n\tdiscard = () => {\n\t\tthis.flushTimeout && clearTimeout(this.flushTimeout);\n\t\tthis.flushTimeout = undefined;\n\t\tthis.items = [];\n\t};\n}\n", "/**\n * Memoizes the last invocation of a function with the same memo keys.\n * As long as key identity and set doesn't change, the last computed\n * value will be returned.\n */\nexport function memoByKeys<TRet, TKeys extends any[]>(\n\tfn: (...args: unknown[]) => TRet,\n\tgetKeys: () => TKeys,\n): (...args: unknown[]) => TRet {\n\tlet cachedKeys: TKeys | undefined;\n\tlet cachedResult: TRet | undefined;\n\treturn (...args: unknown[]) => {\n\t\tconst keys = getKeys();\n\t\tif (\n\t\t\tcachedKeys &&\n\t\t\tcachedKeys.length === keys.length &&\n\t\t\tcachedKeys.every((key, i) => key === keys[i])\n\t\t) {\n\t\t\treturn cachedResult!;\n\t\t}\n\t\tcachedKeys = [...keys] as TKeys;\n\t\tcachedResult = fn(...args);\n\t\treturn cachedResult;\n\t};\n}\n", "export enum VerdantErrorCode {\n\tInvalidRequest = 4000,\n\tBodyRequired = 4001,\n\tNoToken = 4010,\n\tInvalidToken = 4011,\n\tTokenExpired = 4012,\n\tForbidden = 4030,\n\tNotFound = 4040,\n\tUnexpected = 5000,\n\tConfigurationError = 5010,\n\tNoFileStorage = 5011,\n}\n\nexport class VerdantError extends Error {\n\tstatic Code = VerdantErrorCode;\n\n\tconstructor(\n\t\tpublic code: VerdantErrorCode,\n\t\tcause?: Error | undefined,\n\t\tmessage?: string,\n\t) {\n\t\tsuper(message ?? `Verdant error: ${code}`, {\n\t\t\tcause,\n\t\t});\n\t}\n\n\tget httpStatus() {\n\t\tconst status = Math.floor(this.code / 10);\n\t\tif (status < 600) {\n\t\t\treturn status;\n\t\t}\n\t\treturn 500;\n\t}\n\n\ttoResponse = () => {\n\t\treturn JSON.stringify({\n\t\t\tcode: this.code,\n\t\t});\n\t};\n}\n\nexport function isVerdantErrorResponse(body: any): body is { code: number } {\n\treturn (\n\t\ttypeof body === 'object' && 'code' in body && typeof body.code === 'number'\n\t);\n}\n", "import { DocumentBaseline } from './baseline.js';\nimport { Operation } from './operation.js';\n\nfunction encode(str: string): AuthorizationKey {\n\tif (typeof Buffer !== 'undefined') {\n\t\tconst val = Buffer.from(str).toString('base64');\n\t\treturn val as AuthorizationKey;\n\t}\n\tconst val = btoa(str);\n\treturn val as AuthorizationKey;\n}\n\nfunction decode(str: string): string {\n\tif (typeof Buffer !== 'undefined') {\n\t\treturn Buffer.from(str, 'base64').toString();\n\t}\n\treturn atob(str);\n}\n\nexport type AuthorizationKey = string & {\n\t'@@type': 'authz';\n};\n\nexport const authz = {\n\tonlyUser: (userId: string): AuthorizationKey => encode(`u:${userId}:*`),\n\tonlyMe: (): AuthorizationKey => authz.onlyUser(ORIGINATOR_SUBJECT),\n\tdecode: (encoded: string) => {\n\t\tconst decoded = decode(encoded);\n\t\tconst parts = decoded.split(':');\n\t\tif (parts.length !== 3) {\n\t\t\tthrow new Error('Invalid authz string');\n\t\t}\n\t\treturn {\n\t\t\tscope: parts[0],\n\t\t\tsubject: parts[1],\n\t\t\taction: parts[2],\n\t\t};\n\t},\n};\n\nexport const ORIGINATOR_SUBJECT = '$$_originator_$$';\n\n/**\n * Rewrites the special \"originator\" constant subject (used by\n * local-only clients) to the given user ID.\n *\n * Used to initialize a library from a local-only replica\n */\nexport function rewriteAuthzOriginator(\n\tdata: { operations?: Operation[]; baselines?: DocumentBaseline[] },\n\tnewSubject: string,\n) {\n\tconst { operations, baselines } = data;\n\tif (operations) {\n\t\tfor (const op of operations) {\n\t\t\tif (op.authz) {\n\t\t\t\tconst decoded = authz.decode(op.authz);\n\t\t\t\tif (decoded.subject === ORIGINATOR_SUBJECT) {\n\t\t\t\t\top.authz = authz.onlyUser(newSubject);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (baselines) {\n\t\tfor (const baseline of baselines) {\n\t\t\tif (baseline.authz) {\n\t\t\t\tconst decoded = authz.decode(baseline.authz);\n\t\t\t\tif (decoded.subject === ORIGINATOR_SUBJECT) {\n\t\t\t\t\tbaseline.authz = authz.onlyUser(newSubject);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "import { roughSizeOfObject } from '@verdant-web/common';\n\nexport const globalIDB =\n\ttypeof window !== 'undefined' ? window.indexedDB : (undefined as any);\n\nexport function isAbortError(err: unknown) {\n\treturn err instanceof Error && err.name === 'AbortError';\n}\n\nexport function storeRequestPromise<T>(request: IDBRequest<T>) {\n\treturn new Promise<T>((resolve, reject) => {\n\t\trequest.onsuccess = () => {\n\t\t\tresolve(request.result);\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error && isAbortError(request.error)) {\n\t\t\t\t// TODO: is this the right thing to do?\n\t\t\t\tresolve(request.result);\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n}\n\nexport function cursorIterator<T>(\n\trequest: IDBRequest<IDBCursorWithValue | null>,\n\tcallback: (value: T | null) => boolean,\n) {\n\treturn new Promise<void>((resolve, reject) => {\n\t\trequest.onsuccess = () => {\n\t\t\tconst cursor = request.result;\n\t\t\tif (cursor) {\n\t\t\t\tif (callback(cursor.value)) {\n\t\t\t\t\tcursor.continue();\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error && isAbortError(request.error)) {\n\t\t\t\tresolve();\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n}\n\nexport function getSizeOfObjectStore(\n\tdatabase: IDBDatabase,\n\tstoreName: string,\n): Promise<{ count: number; size: number }> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst tx = database.transaction([storeName], 'readonly');\n\t\tconst store = tx.objectStore(storeName);\n\t\tconst cursorReq = store.openCursor();\n\t\tlet count = 0;\n\t\tlet size = 0;\n\t\tcursorReq.onsuccess = function (e) {\n\t\t\tconst cursor = cursorReq.result;\n\t\t\tif (cursor) {\n\t\t\t\tcount++;\n\t\t\t\tsize = size + roughSizeOfObject(cursor.value);\n\t\t\t\tcursor.continue();\n\t\t\t}\n\t\t};\n\t\tcursorReq.onerror = function (e) {\n\t\t\tif (cursorReq.error && isAbortError(cursorReq.error)) {\n\t\t\t\tresolve({\n\t\t\t\t\tcount: count,\n\t\t\t\t\tsize: size,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\treject(cursorReq.error);\n\t\t\t}\n\t\t};\n\t\ttx.oncomplete = function (e) {\n\t\t\tresolve({\n\t\t\t\tcount: count,\n\t\t\t\tsize: size,\n\t\t\t});\n\t\t};\n\t\ttx.onabort = function (e) {\n\t\t\treject(e);\n\t\t};\n\t\ttx.onerror = function (e) {\n\t\t\treject(e);\n\t\t};\n\t});\n}\n\nexport function getAllFromObjectStores(db: IDBDatabase, stores: string[]) {\n\tconst transaction = db.transaction(stores, 'readonly');\n\tconst promises = stores.map((store) => {\n\t\tconst objectStore = transaction.objectStore(store);\n\t\treturn storeRequestPromise(objectStore.getAll());\n\t});\n\treturn Promise.all(promises);\n}\n\nexport async function closeDatabase(db: IDBDatabase) {\n\tdb.close();\n\t// wait for microtask queue to clear\n\tawait new Promise<void>((resolve, reject) => {\n\t\tresolve();\n\t});\n}\n\nexport async function deleteAllDatabases(\n\tnamespace: string,\n\tindexedDB: IDBFactory = globalIDB,\n) {\n\tconst req1 = indexedDB.deleteDatabase([namespace, 'meta'].join('_'));\n\tconst req2 = indexedDB.deleteDatabase([namespace, 'collections'].join('_'));\n\tawait Promise.all([\n\t\tnew Promise((resolve, reject) => {\n\t\t\treq1.onsuccess = resolve;\n\t\t\treq1.onerror = reject;\n\t\t}),\n\t\tnew Promise((resolve, reject) => {\n\t\t\treq2.onsuccess = resolve;\n\t\t\treq2.onerror = reject;\n\t\t}),\n\t]);\n\twindow.location.reload();\n}\n\nexport function deleteDatabase(name: string, indexedDB = window.indexedDB) {\n\treturn storeRequestPromise(indexedDB.deleteDatabase(name));\n}\n\nexport async function getAllDatabaseNamesAndVersions(\n\tindexedDB: IDBFactory = window.indexedDB,\n) {\n\treturn indexedDB.databases();\n}\n\nexport function createAbortableTransaction(\n\tdb: IDBDatabase,\n\tstoreNames: string[],\n\tmode: 'readonly' | 'readwrite',\n\tabortSignal?: AbortSignal,\n\tlog?: (...args: any[]) => void,\n) {\n\tconst tx = db.transaction(storeNames, mode);\n\tif (abortSignal) {\n\t\tconst abort = () => {\n\t\t\tlog?.('debug', 'aborting transaction');\n\t\t\ttry {\n\t\t\t\ttx.abort();\n\t\t\t} catch (e) {\n\t\t\t\tlog?.('debug', 'aborting transaction failed', e);\n\t\t\t}\n\t\t};\n\t\tabortSignal.addEventListener('abort', abort);\n\t\ttx.addEventListener('error', () => {\n\t\t\tabortSignal.removeEventListener('abort', abort);\n\t\t});\n\t\ttx.addEventListener('complete', () => {\n\t\t\tabortSignal.removeEventListener('abort', abort);\n\t\t});\n\t}\n\treturn tx;\n}\n\n/**\n * Empties all data in a database without changing\n * its structure.\n */\nexport function emptyDatabase(db: IDBDatabase) {\n\tconst storeNames = Array.from(db.objectStoreNames);\n\tconst tx = db.transaction(storeNames, 'readwrite');\n\tfor (const storeName of storeNames) {\n\t\ttx.objectStore(storeName).clear();\n\t}\n\treturn new Promise<void>((resolve, reject) => {\n\t\ttx.oncomplete = () => resolve();\n\t\ttx.onerror = () => reject(tx.error);\n\t});\n}\n", "export class Disposable {\n\tprivate _disposes: (() => void)[] = [];\n\tprotected disposed = false;\n\n\tdispose = () => {\n\t\tthis.disposed = true;\n\t\tthis._disposes.forEach((dispose) => dispose());\n\t\tthis._disposes = [];\n\t};\n\n\tprotected addDispose = (dispose: () => void) => {\n\t\tthis._disposes.push(dispose);\n\t};\n}\n", "import { Context } from './context.js';\nimport {\n\tcreateAbortableTransaction,\n\tisAbortError,\n\tstoreRequestPromise,\n} from './idb.js';\nimport { Disposable } from './utils/Disposable.js';\n\nexport class IDBService extends Disposable {\n\tprotected log?: Context['log'];\n\tprivate globalAbortController = new AbortController();\n\n\tconstructor(\n\t\tprotected db: IDBDatabase,\n\t\t{ log }: { log?: Context['log'] } = {},\n\t) {\n\t\tsuper();\n\t\tthis.log = log;\n\t\tthis.addDispose(() => {\n\t\t\tthis.globalAbortController.abort();\n\t\t});\n\t}\n\n\tcreateTransaction = (\n\t\tstoreNames: string[],\n\t\topts?: {\n\t\t\tmode?: 'readonly' | 'readwrite';\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t) => {\n\t\tconst tx = createAbortableTransaction(\n\t\t\tthis.db,\n\t\t\tstoreNames,\n\t\t\topts?.mode || 'readonly',\n\t\t\topts?.abort,\n\t\t\tthis.log,\n\t\t);\n\t\tthis.globalAbortController.signal.addEventListener('abort', tx.abort);\n\t\ttx.addEventListener('complete', () => {\n\t\t\tthis.globalAbortController.signal.removeEventListener('abort', tx.abort);\n\t\t});\n\t\ttx.addEventListener('error', () => {\n\t\t\tthis.globalAbortController.signal.removeEventListener('abort', tx.abort);\n\t\t});\n\t\treturn tx;\n\t};\n\n\trun = async <T>(\n\t\tstoreName: string,\n\t\tgetRequest: (store: IDBObjectStore) => IDBRequest<T>,\n\t\topts?: {\n\t\t\tmode?: 'readonly' | 'readwrite';\n\t\t\ttransaction?: IDBTransaction;\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t): Promise<T> => {\n\t\tif (this.disposed || opts?.transaction?.error)\n\t\t\treturn Promise.resolve(undefined as any);\n\t\tconst tx = opts?.transaction || this.createTransaction([storeName], opts);\n\t\tconst store = tx.objectStore(storeName);\n\t\tconst request = getRequest(store);\n\t\treturn storeRequestPromise<T>(request);\n\t};\n\n\trunAll = async <T>(\n\t\tstoreName: string,\n\t\tgetRequests: (store: IDBObjectStore) => IDBRequest<T>[],\n\t\topts?: {\n\t\t\tmode: 'readonly' | 'readwrite';\n\t\t\ttransaction?: IDBTransaction;\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t): Promise<T[]> => {\n\t\tif (this.disposed || opts?.transaction?.error) return Promise.resolve([]);\n\t\tconst tx = opts?.transaction || this.createTransaction([storeName], opts);\n\t\tconst store = tx.objectStore(storeName);\n\t\tconst requests = getRequests(store);\n\t\treturn Promise.all(requests.map(storeRequestPromise));\n\t};\n\n\titerate = async <T>(\n\t\tstoreName: string,\n\t\tgetRequest: (store: IDBObjectStore) => IDBRequest | IDBRequest[],\n\t\titerator: (value: T, store: IDBObjectStore) => boolean | void,\n\t\topts?: {\n\t\t\tmode?: 'readonly' | 'readwrite';\n\t\t\ttransaction?: IDBTransaction;\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t): Promise<void> => {\n\t\tconst tx = opts?.transaction || this.createTransaction([storeName], opts);\n\t\tconst store = tx.objectStore(storeName);\n\t\tconst request = getRequest(store);\n\t\tif (Array.isArray(request)) {\n\t\t\treturn Promise.all(\n\t\t\t\trequest.map((req) => {\n\t\t\t\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\t\t\t\treq.onsuccess = () => {\n\t\t\t\t\t\t\tconst cursor = req.result;\n\t\t\t\t\t\t\tif (cursor) {\n\t\t\t\t\t\t\t\titerator(cursor.value, store);\n\t\t\t\t\t\t\t\tcursor.continue();\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t\treq.onerror = () => {\n\t\t\t\t\t\t\tif (req.error && isAbortError(req.error)) {\n\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treject(req.error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t\t).then(() => undefined);\n\t\t}\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\trequest.onsuccess = () => {\n\t\t\t\tconst cursor = request.result as IDBCursorWithValue | null;\n\t\t\t\tif (cursor) {\n\t\t\t\t\tconst stop = iterator(cursor.value, store);\n\t\t\t\t\tif (stop) {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcursor.continue();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = () => {\n\t\t\t\tif (request.error && isAbortError(request.error)) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else {\n\t\t\t\t\treject(request.error);\n\t\t\t\t}\n\t\t\t};\n\t\t});\n\t};\n\n\tclear = (storeName: string) => {\n\t\treturn this.run<undefined>(storeName, (store) => store.clear(), {\n\t\t\tmode: 'readwrite',\n\t\t});\n\t};\n}\n", "import { IDBService } from '../IDBService.js';\n\ntype AckInfo = {\n\ttype: 'ack';\n\t// null means no operations are acknowledged\n\t// by every peer yet.\n\tglobalAckTimestamp: string | null;\n};\n\nexport class AckInfoStore extends IDBService {\n\tgetAckInfo = async (): Promise<AckInfo> => {\n\t\tconst result = await this.run<AckInfo>('info', (store) => store.get('ack'));\n\t\tif (result) {\n\t\t\treturn result;\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tglobalAckTimestamp: null,\n\t\t\t\ttype: 'ack',\n\t\t\t};\n\t\t}\n\t};\n\n\tsetGlobalAck = async (ack: string) => {\n\t\tawait this.run(\n\t\t\t'info',\n\t\t\t(store) => store.put({ type: 'ack', globalAckTimestamp: ack }),\n\t\t\t{ mode: 'readwrite' },\n\t\t);\n\t};\n}\n", "import {\n\tDocumentBaseline,\n\tgetOidSubIdRange,\n\tgetOidRoot,\n\tObjectIdentifier,\n\tisLegacyDotOid,\n\tgetLegacyDotOidSubIdRange,\n} from '@verdant-web/common';\nimport { IDBService } from '../IDBService.js';\nimport { Context } from '../context.js';\n\nexport class BaselinesStore extends IDBService {\n\tconstructor(db: IDBDatabase, opts: { log?: Context['log'] }) {\n\t\tsuper(db, opts);\n\t}\n\n\tgetAllForDocument = async (\n\t\toid: ObjectIdentifier,\n\t\t{\n\t\t\tmode = 'readonly',\n\t\t\ttransaction,\n\t\t}: { mode?: 'readwrite' | 'readonly'; transaction?: IDBTransaction } = {},\n\t) => {\n\t\tconst baselines: DocumentBaseline[] = [];\n\t\tawait this.iterateOverAllForDocument(\n\t\t\toid,\n\t\t\t(baseline) => {\n\t\t\t\tbaselines.push(baseline);\n\t\t\t},\n\t\t\t{ mode, transaction },\n\t\t);\n\t\treturn baselines;\n\t};\n\titerateOverAllForDocument = async (\n\t\toid: ObjectIdentifier,\n\t\titerator: (baseline: DocumentBaseline, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tmode = 'readonly',\n\t\t\ttransaction,\n\t\t}: { mode?: 'readwrite' | 'readonly'; transaction?: IDBTransaction } = {},\n\t) => {\n\t\treturn this.iterate(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\tconst root = getOidRoot(oid);\n\t\t\t\tconst [start, end] = getOidSubIdRange(oid);\n\t\t\t\t// FIXME: get rid of legacy dot OIDs...\n\t\t\t\t// if (isLegacyDotOid(oid)) {\n\t\t\t\tconst [dotStart, dotEnd] = getLegacyDotOidSubIdRange(oid);\n\t\t\t\treturn [\n\t\t\t\t\tstore.openCursor(IDBKeyRange.only(root)),\n\t\t\t\t\tstore.openCursor(IDBKeyRange.bound(start, end, false, false)),\n\t\t\t\t\tstore.openCursor(IDBKeyRange.bound(dotStart, dotEnd, false, false)),\n\t\t\t\t];\n\t\t\t\t// } else {\n\t\t\t\t// \treturn [\n\t\t\t\t// \t\t// first the root itself\n\t\t\t\t// \t\tstore.openCursor(IDBKeyRange.only(root)),\n\t\t\t\t// \t\t// then the range of its possible subdocuments\n\t\t\t\t// \t\tstore.openCursor(IDBKeyRange.bound(start, end, false, false)),\n\t\t\t\t// \t];\n\t\t\t\t// }\n\t\t\t},\n\t\t\titerator,\n\t\t\t{ mode, transaction },\n\t\t);\n\t};\n\n\titerateOverAllForCollection = async (\n\t\tcollection: string,\n\t\titerator: (baseline: DocumentBaseline, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tmode = 'readonly',\n\t\t\ttransaction,\n\t\t}: { mode?: 'readwrite' | 'readonly'; transaction?: IDBTransaction } = {},\n\t) => {\n\t\treturn this.iterate(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\treturn [\n\t\t\t\t\tstore.openCursor(\n\t\t\t\t\t\tIDBKeyRange.bound(collection, collection + '\\uffff', false, false),\n\t\t\t\t\t),\n\t\t\t\t];\n\t\t\t},\n\t\t\titerator,\n\t\t\t{ mode, transaction },\n\t\t);\n\t};\n\n\tgetAllForMultipleDocuments = async (\n\t\tdocOids: string[],\n\t\t{ mode = 'readonly' }: { mode?: 'readwrite' | 'readonly' } = {},\n\t) => {\n\t\tconst result = await this.runAll<DocumentBaseline[]>(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\treturn docOids.flatMap((oid) => {\n\t\t\t\t\tconst root = getOidRoot(oid);\n\t\t\t\t\tconst [start, end] = getOidSubIdRange(oid);\n\t\t\t\t\t// FIXME: get rid of legacy dot OIDs...\n\t\t\t\t\t// if (isLegacyDotOid(oid)) {\n\t\t\t\t\tconst [dotStart, dotEnd] = getLegacyDotOidSubIdRange(oid);\n\t\t\t\t\treturn [\n\t\t\t\t\t\tstore.get(root),\n\t\t\t\t\t\tstore.getAll(IDBKeyRange.bound(start, end, false, false)),\n\t\t\t\t\t\tstore.getAll(IDBKeyRange.bound(dotStart, dotEnd, false, false)),\n\t\t\t\t\t];\n\t\t\t\t\t// } else {\n\t\t\t\t\t// \treturn [\n\t\t\t\t\t// \t\tstore.get(root),\n\t\t\t\t\t// \t\tstore.getAll(IDBKeyRange.bound(start, end, false, false)),\n\t\t\t\t\t// \t];\n\t\t\t\t\t// }\n\t\t\t\t});\n\t\t\t},\n\t\t\t{ mode },\n\t\t);\n\t\treturn result.flat();\n\t};\n\n\tgetAllSince = async (\n\t\ttimestamp: string | null,\n\t\t{ mode = 'readonly' }: { mode?: 'readwrite' | 'readonly' } = {},\n\t) => {\n\t\treturn this.run<DocumentBaseline[]>(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\tconst range = timestamp\n\t\t\t\t\t? IDBKeyRange.lowerBound(timestamp, true)\n\t\t\t\t\t: undefined;\n\t\t\t\tconst index = store.index('timestamp');\n\t\t\t\treturn index.getAll(range);\n\t\t\t},\n\t\t\t{ mode },\n\t\t);\n\t};\n\n\tget = async (\n\t\toid: ObjectIdentifier,\n\t\t{\n\t\t\ttransaction,\n\t\t\tmode = 'readonly',\n\t\t}: { transaction?: IDBTransaction; mode?: 'readwrite' | 'readonly' } = {},\n\t) => {\n\t\treturn this.run<DocumentBaseline>('baselines', (store) => store.get(oid), {\n\t\t\tmode,\n\t\t\ttransaction,\n\t\t});\n\t};\n\n\tset = async <T>(\n\t\tbaseline: DocumentBaseline<T>,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tawait this.run('baselines', (store) => store.put(baseline), {\n\t\t\tmode: 'readwrite',\n\t\t\ttransaction,\n\t\t});\n\t};\n\n\tsetAll = async <T>(\n\t\tbaselines: DocumentBaseline<T>[],\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tawait this.runAll(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\treturn baselines.map((baseline) => store.put(baseline));\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\treset = () => {\n\t\treturn this.clear('baselines');\n\t};\n\n\tdelete = async (\n\t\toid: ObjectIdentifier,\n\t\t{ transaction }: { transaction?: IDBTransaction },\n\t) => {\n\t\tawait this.run('baselines', (store) => store.delete(oid), {\n\t\t\tmode: 'readwrite',\n\t\t\ttransaction,\n\t\t});\n\t};\n}\n", "import cuid from 'cuid';\nimport { IDBService } from '../IDBService.js';\n\nexport type LocalReplicaInfo = {\n\ttype: 'localReplicaInfo';\n\tid: string;\n\tuserId: string | undefined;\n\tackedLogicalTime: string | null;\n\tlastSyncedLogicalTime: string | null;\n};\n\nexport class LocalReplicaStore extends IDBService {\n\tprivate _creating: Promise<void> | undefined;\n\tprivate cached: LocalReplicaInfo | undefined;\n\n\tget = async ({\n\t\ttransaction,\n\t}: { transaction?: IDBTransaction } = {}): Promise<LocalReplicaInfo> => {\n\t\tif (this.cached) {\n\t\t\treturn this.cached;\n\t\t}\n\n\t\tconst lookup = await this.run<LocalReplicaInfo>(\n\t\t\t'info',\n\t\t\t(store) => store.get('localReplicaInfo'),\n\t\t\t{ transaction },\n\t\t);\n\n\t\t// not cached, not in db, create it\n\t\tif (!lookup) {\n\t\t\t// prevent a race condition if get() is called again while we are\n\t\t\t// creating the replica info\n\t\t\tif (!this._creating) {\n\t\t\t\tthis._creating = (async () => {\n\t\t\t\t\t// create our own replica info now\n\t\t\t\t\tconst replicaId = cuid();\n\t\t\t\t\tconst replicaInfo: LocalReplicaInfo = {\n\t\t\t\t\t\ttype: 'localReplicaInfo',\n\t\t\t\t\t\tid: replicaId,\n\t\t\t\t\t\tuserId: undefined,\n\t\t\t\t\t\tackedLogicalTime: null,\n\t\t\t\t\t\tlastSyncedLogicalTime: null,\n\t\t\t\t\t};\n\t\t\t\t\tawait this.run('info', (store) => store.put(replicaInfo), {\n\t\t\t\t\t\tmode: 'readwrite',\n\t\t\t\t\t});\n\t\t\t\t\tthis.cached = replicaInfo;\n\t\t\t\t})();\n\t\t\t}\n\t\t\tawait this._creating;\n\n\t\t\treturn this.get({ transaction });\n\t\t}\n\n\t\tthis.cached = lookup;\n\t\treturn lookup;\n\t};\n\n\tupdate = async (\n\t\tdata: Partial<LocalReplicaInfo>,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tconst localReplicaInfo = await this.get({ transaction });\n\t\tObject.assign(localReplicaInfo, data);\n\t\tawait this.run('info', (store) => store.put(localReplicaInfo), {\n\t\t\tmode: 'readwrite',\n\t\t});\n\t\tthis.cached = localReplicaInfo;\n\t};\n\n\treset = async () => {\n\t\tconst localInfo = await this.get();\n\t\tlocalInfo.ackedLogicalTime = null;\n\t\tlocalInfo.lastSyncedLogicalTime = null;\n\t\tawait this.run('info', (store) => store.put(localInfo), {\n\t\t\tmode: 'readwrite',\n\t\t});\n\t};\n}\n", "import {\n\tAckMessage,\n\tDocumentBaseline,\n\tgetOidRoot,\n\tHeartbeatMessage,\n\tObjectIdentifier,\n\tOperation,\n\tOperationMessage,\n\tpickValidOperationKeys,\n\tPresenceUpdateMessage,\n\tSyncAckMessage,\n\tSyncMessage,\n\tVerdantInternalPresence,\n} from '@verdant-web/common';\n\nimport { Metadata } from './Metadata.js';\n\nexport class MessageCreator {\n\tconstructor(private meta: Metadata) {}\n\n\tcreateOperation = async (\n\t\tinit: Pick<OperationMessage, 'operations'> & {\n\t\t\ttimestamp?: string;\n\t\t},\n\t): Promise<OperationMessage> => {\n\t\tconst localInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'op',\n\t\t\ttimestamp: this.meta.now,\n\t\t\treplicaId: localInfo.id,\n\t\t\toperations: init.operations.map(pickValidOperationKeys),\n\t\t};\n\t};\n\n\tcreateMigrationOperation = async ({\n\t\ttargetVersion,\n\t\t...init\n\t}: Pick<OperationMessage, 'operations'> & {\n\t\ttargetVersion: number;\n\t}): Promise<OperationMessage> => {\n\t\tconst localInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'op',\n\t\t\toperations: init.operations.map((op) => ({\n\t\t\t\t...op,\n\t\t\t\ttimestamp: this.meta.time.zero(targetVersion),\n\t\t\t})),\n\t\t\ttimestamp: this.meta.time.zero(targetVersion),\n\t\t\treplicaId: localInfo.id,\n\t\t};\n\t};\n\n\t/**\n\t * @param since - override local understanding of last sync time\n\t */\n\tcreateSyncStep1 = async (since?: string | null): Promise<SyncMessage> => {\n\t\tconst localReplicaInfo = await this.meta.localReplica.get();\n\n\t\tconst provideChangesSince =\n\t\t\tsince === null ? null : localReplicaInfo.lastSyncedLogicalTime;\n\n\t\t// collect all of our operations that are newer than the server's last operation\n\t\t// if server replica isn't stored, we're syncing for the first time.\n\t\tconst operations: Operation[] = [];\n\t\tconst affectedDocs = new Set<ObjectIdentifier>();\n\n\t\t// FIXME: this branch gives bad vibes. should we always\n\t\t// send all operations from other replicas too? is there\n\t\t// ever a case where we have a \"since\" timestamp and there\n\t\t// are foreign ops that match it?\n\t\tif (provideChangesSince) {\n\t\t\tawait this.meta.operations.iterateOverAllLocalOperations(\n\t\t\t\t(patch) => {\n\t\t\t\t\toperations.push(pickValidOperationKeys(patch));\n\t\t\t\t\taffectedDocs.add(getOidRoot(patch.oid));\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tafter: provideChangesSince,\n\t\t\t\t\t// block on writes to prevent race conditions\n\t\t\t\t\tmode: 'readwrite',\n\t\t\t\t},\n\t\t\t);\n\t\t} else {\n\t\t\t// if providing the whole history, don't limit to only local\n\t\t\t// operations\n\t\t\tawait this.meta.operations.iterateOverAllOperations(\n\t\t\t\t(patch) => {\n\t\t\t\t\toperations.push(pickValidOperationKeys(patch));\n\t\t\t\t\taffectedDocs.add(getOidRoot(patch.oid));\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tmode: 'readwrite',\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\t// we only need to send baselines if we've never synced before\n\t\tlet baselines: DocumentBaseline[] = [];\n\t\tif (!provideChangesSince) {\n\t\t\tbaselines = await this.meta.baselines.getAllSince('');\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'sync',\n\t\t\tschemaVersion: this.meta.schema.currentVersion,\n\t\t\ttimestamp: this.meta.now,\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t\tresyncAll: !localReplicaInfo.lastSyncedLogicalTime,\n\t\t\toperations,\n\t\t\tbaselines,\n\t\t\tsince: provideChangesSince,\n\t\t};\n\t};\n\n\tcreatePresenceUpdate = async (data: {\n\t\tpresence?: any;\n\t\tinternal?: VerdantInternalPresence;\n\t}): Promise<PresenceUpdateMessage> => {\n\t\tconst localReplicaInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'presence-update',\n\t\t\tpresence: data.presence,\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t\tinternal: data.internal,\n\t\t};\n\t};\n\n\tcreateHeartbeat = async (): Promise<HeartbeatMessage> => {\n\t\tconst localReplicaInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'heartbeat',\n\t\t\ttimestamp: this.meta.now,\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t};\n\t};\n\n\tcreateAck = async (nonce: string): Promise<AckMessage> => {\n\t\tconst localReplicaInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'ack',\n\t\t\ttimestamp: this.meta.now,\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t\tnonce,\n\t\t};\n\t};\n}\n", "import {\n\tcreateCompoundIndexValue,\n\tcreateLowerBoundIndexValue,\n\tcreateUpperBoundIndexValue,\n\tgetOidRoot,\n\tObjectIdentifier,\n\tOperation,\n\tassert,\n} from '@verdant-web/common';\nimport { IDBService } from '../IDBService.js';\nimport { isAbortError } from '../idb.js';\n\nexport type ClientOperation = Operation & {\n\tisLocal: boolean;\n};\n\nexport type StoredClientOperation = ClientOperation & {\n\toid_timestamp: string;\n\tl_t: string;\n\td_t: string;\n};\n\nexport class OperationsStore extends IDBService {\n\tconstructor(db: IDBDatabase, opts: { log?: (...args: any[]) => void }) {\n\t\tsuper(db, opts);\n\t}\n\t/**\n\t * Iterates over every patch for the root and every sub-object\n\t * of a given document. Optionally limit by timestamp.\n\t */\n\titerateOverAllOperationsForDocument = async (\n\t\toid: ObjectIdentifier,\n\t\titerator: (patch: StoredClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tto,\n\t\t\tfrom,\n\t\t\tafter,\n\t\t\tmode = 'readonly',\n\t\t\ttransaction: providedTx,\n\t\t}: {\n\t\t\tto?: string;\n\t\t\tfrom?: string;\n\t\t\tafter?: string;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t\ttransaction?: IDBTransaction;\n\t\t} = {},\n\t): Promise<void> => {\n\t\tconst transaction =\n\t\t\tprovidedTx ||\n\t\t\tthis.createTransaction(['operations'], {\n\t\t\t\tmode,\n\t\t\t});\n\t\tconst store = transaction.objectStore('operations');\n\t\tconst index = store.index('d_t');\n\n\t\tconst startTimestamp = from || after;\n\t\tconst start = startTimestamp\n\t\t\t? createCompoundIndexValue(oid, startTimestamp)\n\t\t\t: createLowerBoundIndexValue(oid);\n\t\tconst end = to\n\t\t\t? createCompoundIndexValue(oid, to)\n\t\t\t: createUpperBoundIndexValue(oid);\n\n\t\tconst range = IDBKeyRange.bound(start, end, !!after, false);\n\n\t\tconst request = index.openCursor(range, 'next');\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tlet previousTimestamp: string | undefined;\n\t\t\trequest.onsuccess = (event) => {\n\t\t\t\tconst cursor = request.result;\n\t\t\t\tif (cursor) {\n\t\t\t\t\tconst value = cursor.value as StoredClientOperation;\n\t\t\t\t\tassert(value.oid.startsWith(oid));\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpreviousTimestamp === undefined ||\n\t\t\t\t\t\t\tpreviousTimestamp <= value.timestamp,\n\t\t\t\t\t\t`expected ${previousTimestamp} <= ${value.timestamp}`,\n\t\t\t\t\t);\n\n\t\t\t\t\titerator(value, store);\n\t\t\t\t\tpreviousTimestamp = value.timestamp;\n\t\t\t\t\tcursor.continue();\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = (event) => {\n\t\t\t\tif (isAbortError(request.error)) {\n\t\t\t\t\tresolve();\n\t\t\t\t\treturn;\n\t\t\t\t} else {\n\t\t\t\t\treject(request.error);\n\t\t\t\t}\n\t\t\t};\n\t\t});\n\t};\n\n\titerateOverAllOperationsForEntity = async (\n\t\toid: ObjectIdentifier,\n\t\titerator: (patch: StoredClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tafter,\n\t\t\tto,\n\t\t\tmode,\n\t\t\ttransaction: providedTx,\n\t\t}: {\n\t\t\tafter?: string;\n\t\t\tto?: string;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t\ttransaction?: IDBTransaction;\n\t\t},\n\t): Promise<void> => {\n\t\tconst transaction =\n\t\t\tprovidedTx || this.createTransaction(['operations'], { mode });\n\t\tconst store = transaction.objectStore('operations');\n\n\t\tconst start = after\n\t\t\t? createCompoundIndexValue(oid, after)\n\t\t\t: createLowerBoundIndexValue(oid);\n\t\tconst end = to\n\t\t\t? createCompoundIndexValue(oid, to)\n\t\t\t: createUpperBoundIndexValue(oid);\n\n\t\tconst range = IDBKeyRange.bound(start, end, !!after, false);\n\n\t\tconst request = store.openCursor(range, 'next');\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tlet previousTimestamp: string | undefined;\n\t\t\trequest.onsuccess = (event) => {\n\t\t\t\tconst cursor = request.result;\n\t\t\t\tif (cursor) {\n\t\t\t\t\tconst value = cursor.value as StoredClientOperation;\n\t\t\t\t\tassert(value.oid.startsWith(oid));\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpreviousTimestamp === undefined ||\n\t\t\t\t\t\t\tpreviousTimestamp <= value.timestamp,\n\t\t\t\t\t\t`expected ${previousTimestamp} <= ${value.timestamp}`,\n\t\t\t\t\t);\n\n\t\t\t\t\titerator(value, store);\n\t\t\t\t\tpreviousTimestamp = value.timestamp;\n\t\t\t\t\tcursor.continue();\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = (event) => {\n\t\t\t\tif (isAbortError(request.error)) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else {\n\t\t\t\t\treject(request.error);\n\t\t\t\t}\n\t\t\t};\n\t\t});\n\t};\n\n\titerateOverAllOperationsForCollection = async (\n\t\tcollection: string,\n\t\titerator: (patch: StoredClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tafter,\n\t\t\tto,\n\t\t\tmode,\n\t\t\ttransaction: providedTx,\n\t\t}: {\n\t\t\tafter?: string;\n\t\t\tto?: string;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t\ttransaction?: IDBTransaction;\n\t\t},\n\t): Promise<void> => {\n\t\tconst transaction =\n\t\t\tprovidedTx || this.createTransaction(['operations'], { mode });\n\n\t\treturn this.iterate(\n\t\t\t'operations',\n\t\t\t(store) => {\n\t\t\t\treturn store.openCursor(\n\t\t\t\t\tIDBKeyRange.bound(collection, collection + '\\uffff', false, false),\n\t\t\t\t\t'next',\n\t\t\t\t);\n\t\t\t},\n\t\t\titerator,\n\t\t\t{ mode, transaction },\n\t\t);\n\t};\n\n\titerateOverAllLocalOperations = async (\n\t\titerator: (patch: ClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tbefore,\n\t\t\tafter,\n\t\t\tmode = 'readonly',\n\t\t\ttransaction: providedTx,\n\t\t}: {\n\t\t\tbefore?: string | null;\n\t\t\tafter?: string | null;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t\ttransaction?: IDBTransaction;\n\t\t},\n\t): Promise<void> => {\n\t\tconst transaction =\n\t\t\tprovidedTx || this.createTransaction(['operations'], { mode });\n\t\tconst store = transaction.objectStore('operations');\n\t\tconst index = store.index('l_t');\n\n\t\tconst start = after\n\t\t\t? createCompoundIndexValue(true, after)\n\t\t\t: createLowerBoundIndexValue(true);\n\t\tconst end = before\n\t\t\t? createCompoundIndexValue(true, before)\n\t\t\t: createUpperBoundIndexValue(true);\n\n\t\tconst range = IDBKeyRange.bound(start, end, !!after, true);\n\n\t\tconst request = index.openCursor(range, 'next');\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tlet previousTimestamp: string | undefined;\n\t\t\trequest.onsuccess = (event) => {\n\t\t\t\tconst cursor = request.result;\n\t\t\t\tif (cursor) {\n\t\t\t\t\tconst value = cursor.value as StoredClientOperation;\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpreviousTimestamp === undefined ||\n\t\t\t\t\t\t\tpreviousTimestamp <= value.timestamp,\n\t\t\t\t\t\t`expected ${previousTimestamp} <= ${value.timestamp}`,\n\t\t\t\t\t);\n\n\t\t\t\t\titerator(value, store);\n\t\t\t\t\tpreviousTimestamp = value.timestamp;\n\t\t\t\t\tcursor.continue();\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = (event) => {\n\t\t\t\tif (isAbortError(request.error)) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else {\n\t\t\t\t\treject(request.error);\n\t\t\t\t}\n\t\t\t};\n\t\t});\n\t};\n\n\titerateOverAllOperations = async (\n\t\titerator: (patch: ClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tbefore,\n\t\t\ttransaction,\n\t\t\tmode,\n\t\t\tfrom,\n\t\t}: {\n\t\t\t/** Ending timestamp, exclusive */\n\t\t\tbefore?: string | null;\n\t\t\t/** Starting timestamp, inclusive */\n\t\t\tfrom?: string | null;\n\t\t\ttransaction?: IDBTransaction;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t},\n\t): Promise<void> => {\n\t\tawait this.iterate(\n\t\t\t'operations',\n\t\t\t(store) => {\n\t\t\t\tconst start = from ? createLowerBoundIndexValue(from) : undefined;\n\t\t\t\tconst end = before ? createUpperBoundIndexValue(before) : undefined;\n\n\t\t\t\tconst range =\n\t\t\t\t\tstart && end\n\t\t\t\t\t\t? IDBKeyRange.bound(start, end, false, true)\n\t\t\t\t\t\t: start\n\t\t\t\t\t\t? IDBKeyRange.lowerBound(start, false)\n\t\t\t\t\t\t: end\n\t\t\t\t\t\t? IDBKeyRange.upperBound(end, true)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst index = store.index('timestamp');\n\t\t\t\treturn index.openCursor(range, 'next');\n\t\t\t},\n\t\t\titerator,\n\t\t\t{ mode, transaction },\n\t\t);\n\t};\n\n\t/**\n\t * Adds a set of patches to the database.\n\t * @returns a list of affected root document OIDs.\n\t */\n\taddOperations = async (\n\t\tpatches: ClientOperation[],\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t): Promise<ObjectIdentifier[]> => {\n\t\treturn this.insert(patches.map(this.addCompoundIndexes), { transaction });\n\t};\n\n\tprivate addCompoundIndexes = (\n\t\tpatch: ClientOperation,\n\t): StoredClientOperation => {\n\t\treturn {\n\t\t\t...patch,\n\t\t\toid_timestamp: createCompoundIndexValue(\n\t\t\t\tpatch.oid,\n\t\t\t\tpatch.timestamp,\n\t\t\t) as string,\n\t\t\tl_t: createCompoundIndexValue(patch.isLocal, patch.timestamp) as string,\n\t\t\td_t: createCompoundIndexValue(\n\t\t\t\tgetOidRoot(patch.oid),\n\t\t\t\tpatch.timestamp,\n\t\t\t) as string,\n\t\t};\n\t};\n\n\tprivate insert = async (\n\t\toperations: StoredClientOperation[],\n\t\t{ transaction }: { transaction?: IDBTransaction },\n\t): Promise<ObjectIdentifier[]> => {\n\t\tconst affected = new Set<ObjectIdentifier>();\n\t\tawait this.runAll(\n\t\t\t'operations',\n\t\t\t(store) =>\n\t\t\t\toperations.map((op) => {\n\t\t\t\t\taffected.add(getOidRoot(op.oid));\n\t\t\t\t\treturn store.put(op);\n\t\t\t\t}),\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t\treturn Array.from(affected);\n\t};\n\n\treset = () => {\n\t\treturn this.clear('operations');\n\t};\n}\n", "import { StorageSchema } from '@verdant-web/common';\nimport { storeRequestPromise } from '../idb.js';\n\ntype StoredSchema = {\n\ttype: 'schema';\n\tschema: string;\n};\n\nexport class SchemaStore {\n\tprivate cached: StorageSchema<any> | null = null;\n\n\tconstructor(\n\t\tprivate readonly db: IDBDatabase,\n\t\tpublic readonly currentVersion: number,\n\t) {}\n\n\tget = async (): Promise<StorageSchema<any> | null> => {\n\t\tif (this.cached) {\n\t\t\treturn this.cached;\n\t\t}\n\n\t\tconst db = this.db;\n\t\tconst transaction = db.transaction('info', 'readonly');\n\t\tconst store = transaction.objectStore('info');\n\t\tconst request = store.get('schema');\n\t\tconst value = (await storeRequestPromise(request)) as\n\t\t\t| StoredSchema\n\t\t\t| undefined;\n\t\tif (!value) {\n\t\t\treturn null;\n\t\t}\n\t\tthis.cached = JSON.parse(value.schema);\n\t\treturn this.cached;\n\t};\n\n\tset = async (schema: StorageSchema<any>): Promise<void> => {\n\t\tconst db = this.db;\n\t\tconst transaction = db.transaction('info', 'readwrite');\n\t\tconst store = transaction.objectStore('info');\n\t\tconst request = store.put({\n\t\t\ttype: 'schema',\n\t\t\tschema: JSON.stringify(schema),\n\t\t} as StoredSchema);\n\t\tthis.cached = schema;\n\t\tawait storeRequestPromise(request);\n\t};\n}\n", "import {\n\tapplyPatch,\n\tassert,\n\tassignOid,\n\tClientMessage,\n\tDocumentBaseline,\n\tEventSubscriber,\n\tFileRef,\n\tisFileRef,\n\tgetOidRoot,\n\tHybridLogicalClockTimestampProvider,\n\tObjectIdentifier,\n\tOperation,\n\tPatchCreator,\n\tRef,\n\tStorageSchema,\n\tsubstituteRefsWithObjects,\n} from '@verdant-web/common';\nimport { AckInfoStore } from './AckInfoStore.js';\nimport { BaselinesStore } from './BaselinesStore.js';\nimport {\n\tcreateAbortableTransaction,\n\tgetAllFromObjectStores,\n\tgetSizeOfObjectStore,\n\tstoreRequestPromise,\n} from '../idb.js';\nimport { LocalReplicaInfo, LocalReplicaStore } from './LocalReplicaStore.js';\nimport { MessageCreator } from './MessageCreator.js';\nimport { ClientOperation, OperationsStore } from './OperationsStore.js';\nimport { SchemaStore } from './SchemaStore.js';\nimport { Context } from '../context.js';\n\nexport interface ExportData {\n\toperations: Operation[];\n\tbaselines: DocumentBaseline[];\n\tlocalReplica?: LocalReplicaInfo;\n\tschemaVersion: number;\n}\n\nexport class Metadata extends EventSubscriber<{\n\tmessage: (message: ClientMessage) => void;\n\trebase: (baselines: DocumentBaseline[]) => void;\n\tfilesDeleted: (files: FileRef[]) => void;\n}> {\n\treadonly operations;\n\treadonly baselines;\n\treadonly localReplica;\n\treadonly ackInfo;\n\treadonly messageCreator;\n\treadonly patchCreator;\n\treadonly schema;\n\treadonly time = new HybridLogicalClockTimestampProvider();\n\n\tprivate readonly disableRebasing: boolean = false;\n\t/**\n\t * indicates the client is shutting down and we should stop\n\t * accessing the database.\n\t */\n\tprivate _closing = false;\n\n\tprivate context: Omit<Context, 'documentDb' | 'getNow'>;\n\n\tprivate onOperation?: (operation: Operation) => void;\n\n\tconstructor({\n\t\tdisableRebasing,\n\t\tcontext,\n\t\tonOperation,\n\t}: {\n\t\tdisableRebasing?: boolean;\n\t\tcontext: Omit<Context, 'documentDb' | 'getNow'>;\n\t\tonOperation?: (operation: Operation) => void;\n\t}) {\n\t\tsuper();\n\t\tthis.context = context;\n\t\tthis.schema = new SchemaStore(context.metaDb, context.schema.version);\n\t\tthis.operations = new OperationsStore(this.db, { log: context.log });\n\t\tthis.baselines = new BaselinesStore(this.db, { log: context.log });\n\t\tthis.localReplica = new LocalReplicaStore(this.db);\n\t\tthis.ackInfo = new AckInfoStore(this.db);\n\t\tthis.messageCreator = new MessageCreator(this);\n\t\tthis.patchCreator = new PatchCreator(() => this.now);\n\t\tthis.onOperation = onOperation;\n\t\tif (disableRebasing) this.disableRebasing = disableRebasing;\n\t}\n\n\tprivate get db() {\n\t\treturn this.context.metaDb;\n\t}\n\n\tprivate get log() {\n\t\treturn this.context.log;\n\t}\n\n\tsetContext = (context: Context) => {\n\t\tthis.context = context;\n\t};\n\n\tget now() {\n\t\treturn this.time.now(this.schema.currentVersion);\n\t}\n\n\tclose = () => {\n\t\tthis._closing = true;\n\t};\n\n\t/**\n\t * Methods for accessing data\n\t */\n\n\tcreateTransaction = (\n\t\tstores: ('operations' | 'baselines')[],\n\t\topts: {\n\t\t\tabort?: AbortSignal;\n\t\t\twrite?: boolean;\n\t\t} = {},\n\t) => {\n\t\treturn createAbortableTransaction(\n\t\t\tthis.db,\n\t\t\tstores,\n\t\t\topts.write ? 'readwrite' : 'readonly',\n\t\t\topts.abort,\n\t\t\tthis.context.log,\n\t\t);\n\t};\n\n\t/**\n\t * Gets the OID and every sub-object OID for a given document.\n\t * Includes any sub-objects that are not referenced by the root object\n\t * but still happen to be in storage.\n\t */\n\tgetAllDocumentRelatedOids = async (oid: ObjectIdentifier) => {\n\t\tconst oids = new Set<ObjectIdentifier>();\n\t\tconst documentOid = getOidRoot(oid);\n\t\tassert(documentOid === oid, 'Must be root document OID');\n\t\toids.add(documentOid);\n\t\t// readwrite mode to block on other write transactions\n\t\tconst transaction = this.createTransaction(['baselines', 'operations']);\n\t\tawait Promise.all([\n\t\t\tthis.baselines.iterateOverAllForDocument(\n\t\t\t\tdocumentOid,\n\t\t\t\t(baseline) => {\n\t\t\t\t\toids.add(baseline.oid);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t\tthis.operations.iterateOverAllOperationsForDocument(\n\t\t\t\tdocumentOid,\n\t\t\t\t(patch) => {\n\t\t\t\t\toids.add(patch.oid);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t]);\n\n\t\treturn Array.from(oids);\n\t};\n\n\tgetAllCollectionRelatedOids = async (oid: ObjectIdentifier) => {\n\t\tconst oids = new Set<ObjectIdentifier>();\n\t\tconst transaction = this.db.transaction(\n\t\t\t['baselines', 'operations'],\n\t\t\t'readwrite',\n\t\t);\n\t\tawait Promise.all([\n\t\t\tthis.baselines.iterateOverAllForCollection(\n\t\t\t\toid,\n\t\t\t\t(baseline) => {\n\t\t\t\t\toids.add(baseline.oid);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t\tthis.operations.iterateOverAllOperationsForCollection(\n\t\t\t\toid,\n\t\t\t\t(patch) => {\n\t\t\t\t\toids.add(patch.oid);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t]);\n\n\t\treturn Array.from(oids);\n\t};\n\n\tgetDocumentSnapshot = async (\n\t\toid: ObjectIdentifier,\n\t\toptions: { to?: string } = {},\n\t) => {\n\t\tconst documentOid = getOidRoot(oid);\n\t\tassert(documentOid === oid, 'Must be root document OID');\n\t\tconst transaction = this.db.transaction(\n\t\t\t['baselines', 'operations'],\n\t\t\t'readwrite',\n\t\t);\n\t\tconst baselines = await this.baselines.getAllForDocument(documentOid, {\n\t\t\ttransaction,\n\t\t});\n\t\tconst objectMap = new Map<ObjectIdentifier, any>();\n\t\tfor (const baseline of baselines) {\n\t\t\tif (baseline.snapshot) {\n\t\t\t\tassignOid(baseline.snapshot, baseline.oid);\n\t\t\t}\n\t\t\tobjectMap.set(baseline.oid, baseline.snapshot);\n\t\t}\n\t\tawait this.operations.iterateOverAllOperationsForDocument(\n\t\t\tdocumentOid,\n\t\t\t(op) => {\n\t\t\t\tconst obj = objectMap.get(op.oid) || undefined;\n\t\t\t\tconst newObj = applyPatch(obj, op.data);\n\t\t\t\tif (newObj) {\n\t\t\t\t\tassignOid(newObj, op.oid);\n\t\t\t\t}\n\t\t\t\tobjectMap.set(op.oid, newObj);\n\t\t\t},\n\t\t\t{\n\t\t\t\ttransaction,\n\t\t\t\t// only apply operations up to the current time\n\t\t\t\tto: options.to || this.now,\n\t\t\t},\n\t\t);\n\t\tconst root = objectMap.get(documentOid);\n\t\tif (root) {\n\t\t\tsubstituteRefsWithObjects(root, objectMap);\n\t\t}\n\t\treturn root;\n\t};\n\n\tgetDocumentData = async (\n\t\toid: ObjectIdentifier,\n\t\topts?: {\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t) => {\n\t\tconst transaction = this.createTransaction(\n\t\t\t['baselines', 'operations'],\n\t\t\topts,\n\t\t);\n\t\tconst baselines: DocumentBaseline[] = [];\n\t\tconst operations: Record<ObjectIdentifier, Operation[]> = {};\n\t\tawait Promise.all([\n\t\t\tthis.baselines.iterateOverAllForDocument(\n\t\t\t\toid,\n\t\t\t\t(baseline) => {\n\t\t\t\t\tbaselines.push(baseline);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttransaction,\n\t\t\t\t},\n\t\t\t),\n\t\t\tthis.operations.iterateOverAllOperationsForDocument(\n\t\t\t\toid,\n\t\t\t\t(op) => {\n\t\t\t\t\toperations[op.oid] ??= [];\n\t\t\t\t\toperations[op.oid].push(op);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t]);\n\t\treturn {\n\t\t\tbaselines,\n\t\t\toperations,\n\t\t};\n\t};\n\n\tgetDocumentAuthz = async (oid: ObjectIdentifier) => {\n\t\tconst baseline = await this.baselines.get(oid);\n\t\tif (baseline) {\n\t\t\treturn baseline.authz;\n\t\t}\n\t\tlet authz;\n\t\tawait this.operations.iterateOverAllOperationsForEntity(\n\t\t\toid,\n\t\t\t(op) => {\n\t\t\t\tif (op.data.op === 'initialize') {\n\t\t\t\t\tauthz = op.authz;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t},\n\t\t\t{},\n\t\t);\n\t\treturn authz;\n\t};\n\n\t/**\n\t * Methods for writing data\n\t */\n\n\t/**\n\t * Acks that we have seen a timestamp to the server\n\t * and stores it as our local ackedLogicalTime if it's\n\t * greater than our current ackedLogicalTime.\n\t */\n\tack = async (timestamp: string) => {\n\t\tconst localReplicaInfo = await this.localReplica.get();\n\t\t// can't ack timestamps from the future.\n\t\tif (timestamp > this.now) return;\n\n\t\tthis.emit('message', {\n\t\t\ttype: 'ack',\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t\ttimestamp,\n\t\t});\n\t\tif (\n\t\t\t!this._closing &&\n\t\t\t(!localReplicaInfo.ackedLogicalTime ||\n\t\t\t\ttimestamp > localReplicaInfo.ackedLogicalTime)\n\t\t) {\n\t\t\tthis.localReplica.update({ ackedLogicalTime: timestamp });\n\t\t}\n\t};\n\n\t/**\n\t * Applies a patch to the document and stores it in the database.\n\t * @returns the oldest local history timestamp\n\t */\n\tinsertLocalOperations = async (\n\t\toperations: Operation[],\n\t\topts?: { transaction?: IDBTransaction },\n\t) => {\n\t\tif (operations.length === 0) return;\n\t\t// await this.rebaseLock;\n\t\tthis.log(\n\t\t\t'debug',\n\t\t\t`Inserting ${operations.length} local operations`,\n\t\t\toperations,\n\t\t);\n\n\t\t// add local flag, in place.\n\t\tfor (const operation of operations) {\n\t\t\t(operation as ClientOperation).isLocal = true;\n\t\t}\n\t\tawait this.operations.addOperations(operations as ClientOperation[], opts);\n\n\t\tconst message = await this.messageCreator.createOperation({ operations });\n\t\tthis.emit('message', message);\n\n\t\t// we can now enqueue and check for rebase opportunities\n\t\tthis.tryAutonomousRebase();\n\n\t\tif (this.onOperation) {\n\t\t\toperations.forEach((o) => this.onOperation!(o));\n\t\t}\n\t};\n\n\t/**\n\t * Inserts remote operations. This does not affect local history.\n\t * @returns a list of affected document OIDs\n\t */\n\tinsertRemoteOperations = async (\n\t\toperations: Operation[],\n\t\topts?: { transaction?: IDBTransaction },\n\t) => {\n\t\tif (operations.length === 0) return [];\n\t\t// await this.rebaseLock;\n\t\tthis.log(\n\t\t\t'debug',\n\t\t\t`Inserting ${operations.length} remote operations`,\n\t\t\toperations,\n\t\t);\n\n\t\tconst affectedDocumentOids = await this.operations.addOperations(\n\t\t\toperations.map((patch) => ({\n\t\t\t\t...patch,\n\t\t\t\tisLocal: false,\n\t\t\t})),\n\t\t\topts,\n\t\t);\n\n\t\tthis.ack(operations[operations.length - 1].timestamp);\n\n\t\tif (this.onOperation) {\n\t\t\toperations.forEach((o) => this.onOperation!(o));\n\t\t}\n\n\t\treturn affectedDocumentOids;\n\t};\n\n\tinsertRemoteBaselines = async (\n\t\tbaselines: DocumentBaseline[],\n\t\topts?: { transaction?: IDBTransaction },\n\t) => {\n\t\tif (baselines.length === 0) return [];\n\t\tthis.log('debug', `Inserting ${baselines.length} remote baselines`);\n\n\t\tawait this.baselines.setAll(baselines, opts);\n\n\t\t// this.ack(baselines[baselines.length - 1].timestamp);\n\n\t\tconst affectedOidSet = new Set<ObjectIdentifier>();\n\t\tbaselines.forEach((baseline) => {\n\t\t\taffectedOidSet.add(getOidRoot(baseline.oid));\n\t\t});\n\n\t\treturn Array.from(affectedOidSet);\n\t};\n\n\tinsertData = async (\n\t\tdata: {\n\t\t\tbaselines?: DocumentBaseline[];\n\t\t\toperations?: Operation[];\n\t\t\tisLocal?: boolean;\n\t\t},\n\t\topts?: { abort: AbortSignal },\n\t) => {\n\t\tconst transaction = this.createTransaction(['baselines', 'operations'], {\n\t\t\t...opts,\n\t\t\twrite: true,\n\t\t});\n\t\tif (data.baselines) {\n\t\t\tawait this.insertRemoteBaselines(data.baselines, { transaction });\n\t\t}\n\t\tif (opts?.abort?.aborted) return;\n\t\tif (data.operations) {\n\t\t\tif (data.isLocal) {\n\t\t\t\tawait this.insertLocalOperations(data.operations, { transaction });\n\t\t\t} else {\n\t\t\t\tawait this.insertRemoteOperations(data.operations, { transaction });\n\t\t\t}\n\t\t}\n\t};\n\n\tupdateLastSynced = async (timestamp: string) => {\n\t\tif (this._closing) return;\n\n\t\treturn this.localReplica.update({\n\t\t\tlastSyncedLogicalTime: timestamp,\n\t\t});\n\t};\n\n\tlastSyncedTimestamp = async () => {\n\t\tconst localReplicaInfo = await this.localReplica.get();\n\t\treturn localReplicaInfo.lastSyncedLogicalTime;\n\t};\n\n\tprivate tryAutonomousRebase = async () => {\n\t\tif (this.disableRebasing) return;\n\n\t\tconst localReplicaInfo = await this.localReplica.get();\n\t\tif (localReplicaInfo.lastSyncedLogicalTime) return; // cannot autonomously rebase if we've synced\n\t\t// but if we have never synced... we can rebase everything!\n\t\tawait this.runRebase(this.now);\n\t};\n\n\t/**\n\t * Attempt to autonomously rebase local documents without server intervention.\n\t * This can currently only happen for a client who has never synced before.\n\t * The goal is to allow local-only clients to compress their history to exactly\n\t * their undo stack.\n\t */\n\tprivate runRebase = async (globalAckTimestamp: string) => {\n\t\tif (this._closing) return;\n\n\t\t// find all operations before the global ack\n\t\tlet lastTimestamp;\n\t\tconst toRebase = new Set<ObjectIdentifier>();\n\t\tconst transaction = this.createTransaction(['baselines', 'operations'], {\n\t\t\twrite: true,\n\t\t});\n\t\tlet operationCount = 0;\n\t\tawait this.operations.iterateOverAllOperations(\n\t\t\t(patch) => {\n\t\t\t\ttoRebase.add(patch.oid);\n\t\t\t\tlastTimestamp = patch.timestamp;\n\t\t\t\toperationCount++;\n\t\t\t},\n\t\t\t{\n\t\t\t\tbefore: globalAckTimestamp,\n\t\t\t\ttransaction,\n\t\t\t},\n\t\t);\n\n\t\tif (!toRebase.size) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this._closing) {\n\t\t\treturn;\n\t\t}\n\n\t\t// rebase each affected document\n\t\tlet newBaselines = [];\n\t\tfor (const oid of toRebase) {\n\t\t\tnewBaselines.push(\n\t\t\t\tawait this.rebase(\n\t\t\t\t\toid,\n\t\t\t\t\tlastTimestamp || globalAckTimestamp,\n\t\t\t\t\ttransaction,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tthis.emit('rebase', newBaselines);\n\t};\n\n\trebase = async (\n\t\toid: ObjectIdentifier,\n\t\tupTo: string,\n\t\tprovidedTx?: IDBTransaction,\n\t) => {\n\t\t// including replica Id for testing I guess\n\t\tconst replicaId = (await this.localReplica.get()).id;\n\n\t\tthis.log('debug', '[', replicaId, ']', 'Rebasing', oid, 'up to', upTo);\n\t\tconst transaction =\n\t\t\tprovidedTx ||\n\t\t\tthis.createTransaction(['operations', 'baselines'], { write: true });\n\t\tconst baseline = await this.baselines.get(oid, { transaction });\n\t\tlet current: any = baseline?.snapshot || undefined;\n\t\tlet operationsApplied = 0;\n\t\tlet authz = baseline?.authz;\n\t\tconst deletedRefs: Ref[] = [];\n\t\tawait this.operations.iterateOverAllOperationsForEntity(\n\t\t\toid,\n\t\t\t(patch, store) => {\n\t\t\t\t// FIXME: this seems like the wrong place to do this\n\t\t\t\t// but it's here as a safety measure...\n\t\t\t\tif (!baseline || patch.timestamp > baseline.timestamp) {\n\t\t\t\t\tcurrent = applyPatch(current, patch.data, deletedRefs);\n\t\t\t\t\tif (patch.data.op === 'initialize') {\n\t\t\t\t\t\tauthz = patch.authz;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// delete all prior operations to the baseline\n\t\t\t\toperationsApplied++;\n\t\t\t\tstore.delete(patch.oid_timestamp);\n\t\t\t},\n\t\t\t{\n\t\t\t\tto: upTo,\n\t\t\t\ttransaction,\n\t\t\t},\n\t\t);\n\t\tif (current) {\n\t\t\tassignOid(current, oid);\n\t\t}\n\t\tconst newBaseline = {\n\t\t\toid,\n\t\t\tsnapshot: current,\n\t\t\ttimestamp: upTo,\n\t\t\tauthz,\n\t\t};\n\t\tif (newBaseline.snapshot) {\n\t\t\tawait this.baselines.set(newBaseline, { transaction });\n\t\t} else {\n\t\t\tawait this.baselines.delete(oid, { transaction });\n\t\t}\n\n\t\tthis.log(\n\t\t\t'debug',\n\t\t\t'successfully rebased',\n\t\t\toid,\n\t\t\t'up to',\n\t\t\tupTo,\n\t\t\t':',\n\t\t\tcurrent,\n\t\t\t'and deleted',\n\t\t\toperationsApplied,\n\t\t\t'operations',\n\t\t);\n\n\t\t// cleanup deleted refs\n\t\tif (deletedRefs.length) {\n\t\t\tconst fileRefs = deletedRefs.filter(isFileRef);\n\t\t\tif (fileRefs.length) {\n\t\t\t\tthis.emit('filesDeleted', fileRefs);\n\t\t\t}\n\t\t}\n\n\t\treturn newBaseline;\n\t};\n\n\treset = async () => {\n\t\tawait this.operations.reset();\n\t\tawait this.baselines.reset();\n\t\tawait this.localReplica.reset();\n\t};\n\n\tupdateSchema = async (schema: StorageSchema, overrideConflict?: number) => {\n\t\tconst storedSchema = await this.schema.get();\n\t\tif (storedSchema) {\n\t\t\t// version changes will be handled by migration routines in\n\t\t\t// the actual idb database loading code (see: initializeDatabases)\n\n\t\t\t// but this check determines if the schema has been changed without\n\t\t\t// a version change. if so, it will error.\n\t\t\tif (\n\t\t\t\toverrideConflict === storedSchema.version &&\n\t\t\t\tstoredSchema.version === schema.version &&\n\t\t\t\tJSON.stringify(storedSchema) !== JSON.stringify(schema)\n\t\t\t) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Schema mismatch for version ${schema.version}\n\t\t\t\t\t${JSON.stringify(storedSchema)}\n\t\t\t\t\t${JSON.stringify(schema)}`,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Schema has changed without a version change! Any changes to your schema must be accompanied by a change in schema version and a migration routine.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tawait this.schema.set(schema);\n\t};\n\n\tsetGlobalAck = async (timestamp: string) => {\n\t\tif (this._closing) return;\n\t\tawait this.ackInfo.setGlobalAck(timestamp);\n\t\tif (!this.disableRebasing) {\n\t\t\tawait this.runRebase(timestamp);\n\t\t}\n\t};\n\n\t/**\n\t * Manually triggers a storage rebase.\n\t * Rebases happen automatically as needed, so\n\t * you probably don't need this.\n\t */\n\tmanualRebase = async () => {\n\t\tif (this._closing || this.disableRebasing) return;\n\t\tconst ackInfo = await this.ackInfo.getAckInfo();\n\t\tif (ackInfo.globalAckTimestamp) {\n\t\t\tthis.runRebase(ackInfo.globalAckTimestamp);\n\t\t}\n\t};\n\n\texport = async (): Promise<ExportData> => {\n\t\tconst db = this.db;\n\t\tconst [baselines, operations] = await getAllFromObjectStores(db, [\n\t\t\t'baselines',\n\t\t\t'operations',\n\t\t]);\n\t\tconst localReplica = await this.localReplica.get();\n\t\tconst schema = await this.schema.get();\n\t\tif (!schema) {\n\t\t\tthrow new Error('Cannot export Client data before initializing');\n\t\t}\n\t\treturn {\n\t\t\toperations,\n\t\t\tbaselines,\n\t\t\tlocalReplica,\n\t\t\tschemaVersion: schema.version,\n\t\t};\n\t};\n\n\t/**\n\t * Resets local metadata and clears operation/baseline stores.\n\t * DOES NOT add operations/baselines - this should be done\n\t * through the normal higher level systems.\n\t */\n\tresetFrom = async (data: ExportData) => {\n\t\tconst db = this.db;\n\t\tconst transaction = db.transaction(\n\t\t\t['baselines', 'operations', 'info'],\n\t\t\t'readwrite',\n\t\t);\n\t\tawait storeRequestPromise(transaction.objectStore('baselines').clear());\n\t\tawait storeRequestPromise(transaction.objectStore('operations').clear());\n\t\tawait storeRequestPromise(transaction.objectStore('info').clear());\n\t\tif (data.localReplica) {\n\t\t\tawait this.localReplica.update(\n\t\t\t\t{\n\t\t\t\t\tackedLogicalTime: data.localReplica.ackedLogicalTime,\n\t\t\t\t\tlastSyncedLogicalTime: data.localReplica.lastSyncedLogicalTime,\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t);\n\t\t}\n\t};\n\n\tstats = async () => {\n\t\tconst db = this.db;\n\t\tconst operationsSize = await getSizeOfObjectStore(db, 'operations');\n\t\tconst baselinesSize = await getSizeOfObjectStore(db, 'baselines');\n\n\t\treturn {\n\t\t\toperationsSize,\n\t\t\tbaselinesSize,\n\t\t};\n\t};\n}\n\nexport function supportLegacyExport(exportData: any): ExportData {\n\tif (exportData.schema) {\n\t\texportData.schemaVersion = exportData.schema.version;\n\t\tdelete exportData.schema;\n\t}\n\treturn exportData;\n}\n", "import { replaceLegacyOidsInObject } from '@verdant-web/common';\nimport { closeDatabase, storeRequestPromise } from '../idb.js';\n\nconst migrations = [version1, version2, version3, version4, version5, version6];\n\nexport function openMetadataDatabase({\n\tindexedDB = window.indexedDB,\n\tnamespace,\n\tlog,\n\tmetadataVersion = 5,\n}: {\n\tindexedDB?: IDBFactory;\n\tnamespace: string;\n\tlog?: (...args: any[]) => void;\n\tmetadataVersion?: number;\n}): Promise<{ wasInitialized: boolean; db: IDBDatabase }> {\n\treturn new Promise<{ wasInitialized: boolean; db: IDBDatabase }>(\n\t\t(resolve, reject) => {\n\t\t\tconst request = indexedDB.open(`${namespace}_meta`, metadataVersion);\n\t\t\tlet wasInitialized = false;\n\t\t\trequest.onupgradeneeded = async (event) => {\n\t\t\t\tconst db = request.result;\n\t\t\t\tconst tx = request.transaction!;\n\n\t\t\t\tconst toRun = migrations.slice(event.oldVersion);\n\t\t\t\tfor (const migration of toRun) {\n\t\t\t\t\tawait migration(db, tx);\n\t\t\t\t}\n\n\t\t\t\tawait new Promise((resolve, reject) => {\n\t\t\t\t\ttx.addEventListener('complete', resolve);\n\t\t\t\t\ttx.addEventListener('error', reject);\n\t\t\t\t});\n\n\t\t\t\tif (!event.oldVersion) {\n\t\t\t\t\twasInitialized = true;\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = () => {\n\t\t\t\tconsole.error('Error opening database', request.error);\n\t\t\t\treject(request.error);\n\t\t\t};\n\t\t\trequest.onsuccess = () => {\n\t\t\t\tresolve({ db: request.result, wasInitialized });\n\t\t\t};\n\t\t},\n\t);\n}\n\nexport async function openWIPMetadataDatabase({\n\twipNamespace,\n\tnamespace,\n\tindexedDB,\n\tlog,\n\tmetadataVersion,\n}: {\n\tindexedDB?: IDBFactory;\n\tnamespace: string;\n\twipNamespace: string;\n\tlog?: (...args: any[]) => void;\n\tmetadataVersion?: number;\n}): Promise<{ wasInitialized: boolean; db: IDBDatabase }> {\n\tconst result = await openMetadataDatabase({\n\t\tnamespace: wipNamespace,\n\t\tindexedDB,\n\t\tlog,\n\t\tmetadataVersion,\n\t});\n\n\t// this WIP database was already set up.\n\tif (!result.wasInitialized) {\n\t\treturn result;\n\t}\n\n\tlog?.('debug', 'Beginning copy of production metadata database to WIP');\n\t// copy all data from production metadata database\n\tconst { db: prodDb } = await openMetadataDatabase({\n\t\tnamespace,\n\t\tindexedDB,\n\t\tlog,\n\t\tmetadataVersion,\n\t});\n\n\tconst tx = prodDb.transaction(\n\t\t['baselines', 'operations', 'info'],\n\t\t'readonly',\n\t);\n\tconst [baselines, operations, info] = await Promise.all([\n\t\tstoreRequestPromise(tx.objectStore('baselines').getAll()),\n\t\tstoreRequestPromise(tx.objectStore('operations').getAll()),\n\t\tstoreRequestPromise(tx.objectStore('info').getAll()),\n\t]);\n\n\tconst wipTx = result.db.transaction(\n\t\t['baselines', 'operations', 'info'],\n\t\t'readwrite',\n\t);\n\tconst wipBaselines = wipTx.objectStore('baselines');\n\tconst wipOperations = wipTx.objectStore('operations');\n\tconst wipInfo = wipTx.objectStore('info');\n\n\tfor (const baseline of baselines) {\n\t\twipBaselines.put(baseline);\n\t}\n\tfor (const operation of operations) {\n\t\twipOperations.put(operation);\n\t}\n\tfor (const infoItem of info) {\n\t\twipInfo.put(infoItem);\n\t}\n\n\tawait new Promise<void>((resolve, reject) => {\n\t\twipTx.oncomplete = () => {\n\t\t\tresolve();\n\t\t};\n\t\twipTx.onerror = (event) => {\n\t\t\treject(event);\n\t\t};\n\t\twipTx.onabort = (event) => {\n\t\t\treject(event);\n\t\t};\n\t});\n\n\tawait closeDatabase(prodDb);\n\n\tlog?.(\n\t\t'debug',\n\t\t'Finished copy of production metadata database to WIP. Copied:',\n\t\tbaselines.length,\n\t\t'baselines,',\n\t\toperations.length,\n\t\t'operations',\n\t);\n\n\treturn result;\n}\n\nasync function version1(db: IDBDatabase, tx: IDBTransaction) {\n\tconst baselinesStore = db.createObjectStore('baselines', {\n\t\tkeyPath: 'oid',\n\t});\n\tconst operationsStore = db.createObjectStore('operations', {\n\t\tkeyPath: 'oid_timestamp',\n\t});\n\tconst infoStore = db.createObjectStore('info', { keyPath: 'type' });\n\tbaselinesStore.createIndex('timestamp', 'timestamp');\n\toperationsStore.createIndex('isLocal_timestamp', 'isLocal_timestamp');\n\toperationsStore.createIndex('documentOid_timestamp', 'documentOid_timestamp');\n}\n\n/**\n * 1 -> 2 changes:\n *\n * Consolidate compound index names:\n *\n * Operations:\n * - isLocal_timestamp -> l_t\n * - documentOid_timestamp -> d_t\n */\nasync function version2(db: IDBDatabase, tx: IDBTransaction) {\n\tconst operations = tx.objectStore('operations');\n\tawait new Promise<void>((resolve, reject) => {\n\t\tconst cursorReq = operations.openCursor();\n\t\tcursorReq.onsuccess = () => {\n\t\t\t// rename the consolidated fields\n\t\t\tconst cursor = cursorReq.result;\n\t\t\tif (cursor) {\n\t\t\t\tconst { isLocal_timestamp, documentOid_timestamp, ...value } =\n\t\t\t\t\tcursor.value;\n\t\t\t\tcursor.update({\n\t\t\t\t\t...value,\n\t\t\t\t\tl_t: isLocal_timestamp,\n\t\t\t\t\td_t: documentOid_timestamp,\n\t\t\t\t});\n\t\t\t\tcursor.continue();\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t};\n\t\tcursorReq.onerror = (event) => {\n\t\t\treject(cursorReq.error);\n\t\t};\n\t});\n\t// remove the old indexes\n\toperations.deleteIndex('isLocal_timestamp');\n\toperations.deleteIndex('documentOid_timestamp');\n\t// create the new indexes\n\toperations.createIndex('l_t', 'l_t', { unique: false });\n\toperations.createIndex('o_t', 'o_t', { unique: false });\n\toperations.createIndex('d_t', 'd_t', { unique: false });\n}\n\n/**\n * 2 -> 3 changes:\n *\n * Add timestamp index to operations\n */\nasync function version3(db: IDBDatabase, tx: IDBTransaction) {\n\tconst operations = tx.objectStore('operations');\n\toperations.createIndex('timestamp', 'timestamp');\n}\n\nasync function version4(db: IDBDatabase, tx: IDBTransaction) {\n\tconst files = db.createObjectStore('files', {\n\t\tkeyPath: 'id',\n\t});\n\tfiles.createIndex('remote', 'remote');\n\tfiles.createIndex('deletedAt', 'deletedAt');\n}\n\nasync function version5(db: IDBDatabase, tx: IDBTransaction) {\n\t// rewrites all baselines and operations to replace legacy OIDs\n\t// with new ones.\n\tconst operations = tx.objectStore('operations');\n\tawait new Promise<void>((resolve, reject) => {\n\t\tconst cursorReq = operations.openCursor();\n\t\tcursorReq.onsuccess = () => {\n\t\t\tconst cursor = cursorReq.result;\n\t\t\tif (cursor) {\n\t\t\t\tconst converted = replaceLegacyOidsInObject(cursor.value);\n\t\t\t\t// conversion may change the primary key, so we need to put the\n\t\t\t\t// object back to the store\n\t\t\t\tif (converted.oid_timestamp !== cursor.primaryKey) {\n\t\t\t\t\tcursor.delete();\n\t\t\t\t\toperations.put(converted);\n\t\t\t\t} else {\n\t\t\t\t\tcursor.update(converted);\n\t\t\t\t}\n\t\t\t\tcursor.continue();\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t};\n\t\tcursorReq.onerror = (event) => {\n\t\t\treject(cursorReq.error);\n\t\t};\n\t});\n\tconst baselines = tx.objectStore('baselines');\n\tawait new Promise<void>((resolve, reject) => {\n\t\tconst cursorReq = baselines.openCursor();\n\t\tcursorReq.onsuccess = () => {\n\t\t\tconst cursor = cursorReq.result;\n\t\t\tif (cursor) {\n\t\t\t\tconst converted = replaceLegacyOidsInObject(cursor.value);\n\t\t\t\tif (converted.oid !== cursor.primaryKey) {\n\t\t\t\t\tcursor.delete();\n\t\t\t\t\tbaselines.put(converted);\n\t\t\t\t} else {\n\t\t\t\t\tcursor.update(converted);\n\t\t\t\t}\n\t\t\t\tcursor.continue();\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t};\n\t\tcursorReq.onerror = (event) => {\n\t\t\treject(cursorReq.error);\n\t\t};\n\t});\n}\n\n// version 5->6: add timestamp to file metadata\nasync function version6(db: IDBDatabase, tx: IDBTransaction) {\n\tconst files = tx.objectStore('files');\n\tfiles.createIndex('timestamp', 'timestamp');\n}\n", "import { closeDatabase, globalIDB, storeRequestPromise } from '../idb.js';\nimport { OpenDocumentDbContext } from './types.js';\n\nexport async function getDatabaseVersion(\n\tindexedDB: IDBFactory,\n\tnamespace: string,\n\tversion: number,\n\tlog?: (...args: any[]) => void,\n): Promise<number> {\n\tfunction openAndGetVersion(\n\t\tresolve: (res: [number, IDBDatabase]) => void,\n\t\treject: (err: Error) => void,\n\t) {\n\t\tlet currentVersion: number;\n\t\tlet database: IDBDatabase;\n\t\tconst request = indexedDB.open(\n\t\t\t[namespace, 'collections'].join('_'),\n\t\t\tversion,\n\t\t);\n\t\trequest.onupgradeneeded = async (event) => {\n\t\t\tcurrentVersion = event.oldVersion;\n\t\t\tconst transaction = request.transaction!;\n\t\t\tdatabase = request.result;\n\t\t\ttransaction.abort();\n\t\t};\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve([request.result.version, request.result]);\n\t\t};\n\t\trequest.onblocked = (event) => {\n\t\t\t// retry if blocked\n\t\t\tlog?.('Database blocked, waiting...');\n\t\t\t// setTimeout(() => {\n\t\t\t// \topenAndGetVersion(resolve, reject);\n\t\t\t// }, 200);\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\t// FIXME: this fails if the code is older than the local database\n\t\t\tresolve([currentVersion!, database!]);\n\t\t};\n\t}\n\tconst [currentVersion, db] = await new Promise<[number, IDBDatabase]>(\n\t\topenAndGetVersion,\n\t);\n\tawait closeDatabase(db);\n\treturn currentVersion;\n}\n\n/**\n * Upgrades the database to the given version, using the given upgrader function.\n */\nexport async function upgradeDatabase(\n\tindexedDb: IDBFactory,\n\tnamespace: string,\n\tversion: number,\n\tupgrader: (\n\t\ttransaction: IDBTransaction,\n\t\tdb: IDBDatabase,\n\t\tevent: IDBVersionChangeEvent,\n\t) => void,\n\tlog?: (...args: any[]) => void,\n): Promise<IDBDatabase> {\n\tfunction openAndUpgrade(\n\t\tresolve: (db: IDBDatabase) => void,\n\t\treject: (err: Error) => void,\n\t) {\n\t\tconst request = indexedDb.open(\n\t\t\t[namespace, 'collections'].join('_'),\n\t\t\tversion,\n\t\t);\n\t\tlet wasUpgraded = false;\n\t\trequest.onupgradeneeded = (event) => {\n\t\t\tconst transaction = request.transaction!;\n\t\t\tupgrader(transaction, request.result, event);\n\t\t\twasUpgraded = true;\n\t\t};\n\t\trequest.onsuccess = (event) => {\n\t\t\tif (wasUpgraded) {\n\t\t\t\tresolve(request.result);\n\t\t\t} else {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t'Database was not upgraded when a version change was expected',\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(request.error || new Error('Unknown error'));\n\t\t};\n\t\trequest.onblocked = (event) => {\n\t\t\tlog?.('Database upgrade blocked, waiting...');\n\t\t\t// setTimeout(() => {\n\t\t\t// \topenAndUpgrade(resolve, reject);\n\t\t\t// }, 200);\n\t\t};\n\t}\n\treturn new Promise<IDBDatabase>(openAndUpgrade);\n}\n\nexport async function acquireLock(\n\tnamespace: string,\n\tprocedure: () => Promise<void>,\n) {\n\tif (typeof navigator !== 'undefined' && navigator.locks) {\n\t\tawait navigator.locks.request(`verdant_migration_${namespace}`, procedure);\n\t} else {\n\t\t// TODO: is there a fallback?\n\t\tawait procedure();\n\t}\n}\n\nexport async function openDatabase({\n\tindexedDB = globalIDB,\n\tnamespace,\n\tversion,\n\tcontext,\n}: {\n\tindexedDB?: IDBFactory;\n\tnamespace: string;\n\tversion: number;\n\tcontext: OpenDocumentDbContext;\n}): Promise<IDBDatabase> {\n\tcontext.log('debug', 'Opening database', namespace, 'at version', version);\n\tconst db = await new Promise<IDBDatabase>((resolve, reject) => {\n\t\tconst request = indexedDB.open(\n\t\t\t[namespace, 'collections'].join('_'),\n\t\t\tversion,\n\t\t);\n\t\trequest.onupgradeneeded = async (event) => {\n\t\t\tconst transaction = request.transaction!;\n\t\t\ttransaction.abort();\n\n\t\t\tcontext.log(\n\t\t\t\t'error',\n\t\t\t\t'Database upgrade needed, but not expected',\n\t\t\t\t'Expected',\n\t\t\t\tversion,\n\t\t\t\t'Got',\n\t\t\t\trequest.result.version,\n\t\t\t);\n\t\t\treject(\n\t\t\t\trequest.error ||\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t`Migration error: database version changed unexpectedly when reading current data. Expected ${version}, got ${request.result.version}`,\n\t\t\t\t\t),\n\t\t\t);\n\t\t};\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve(request.result);\n\t\t};\n\t\trequest.onblocked = (event) => {\n\t\t\treject(new Error('Migration error: database blocked'));\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(new Error('Migration error: database error'));\n\t\t};\n\t});\n\n\tdb.addEventListener('versionchange', (event) => {\n\t\tdb.close();\n\t});\n\n\treturn db;\n}\n\nexport async function copyAll(\n\tsourceDatabase: IDBDatabase,\n\ttargetDatabase: IDBDatabase,\n) {\n\t// DOMStringList... doesn't have iterable... why\n\tconst sourceStoreNames = new Array<string>();\n\tfor (let i = 0; i < sourceDatabase.objectStoreNames.length; i++) {\n\t\tsourceStoreNames.push(sourceDatabase.objectStoreNames[i]);\n\t}\n\n\tconst copyFromTransaction = sourceDatabase.transaction(\n\t\tsourceStoreNames,\n\t\t'readonly',\n\t);\n\tconst copyFromStores = sourceStoreNames.map((name) =>\n\t\tcopyFromTransaction.objectStore(name),\n\t);\n\tconst allObjects = await Promise.all(\n\t\tcopyFromStores.map((store) => storeRequestPromise(store.getAll())),\n\t);\n\n\tconst copyToTransaction = targetDatabase.transaction(\n\t\tsourceStoreNames,\n\t\t'readwrite',\n\t);\n\tconst copyToStores = sourceStoreNames.map((name) =>\n\t\tcopyToTransaction.objectStore(name),\n\t);\n\n\tfor (let i = 0; i < copyToStores.length; i++) {\n\t\tawait Promise.all(\n\t\t\tallObjects[i].map((obj) => {\n\t\t\t\treturn storeRequestPromise(copyToStores[i].put(obj));\n\t\t\t}),\n\t\t);\n\t}\n}\n", "import {\n\tassert,\n\tCollectionCompoundIndexFilter,\n\tCollectionFilter,\n\tcreateCompoundIndexValue,\n\tcreateLowerBoundIndexValue,\n\tcreateUpperBoundIndexValue,\n\tisMatchIndexFilter,\n\tisRangeIndexFilter,\n\tisSortIndexFilter,\n\tisStartsWithIndexFilter,\n\tMatchCollectionIndexFilter,\n\tRangeCollectionIndexFilter,\n\tsanitizeIndexValue,\n\tSortIndexFilter,\n\tStartsWithIndexFilter,\n\tStorageSchema,\n} from '@verdant-web/common';\n\nconst matchIndexToIdbKeyRange = (filter: MatchCollectionIndexFilter) => {\n\treturn IDBKeyRange.only(sanitizeIndexValue(filter.equals));\n};\n\nconst sortIndexToIdbKeyRange = (filter: SortIndexFilter) => {\n\treturn undefined;\n};\n\nconst rangeIndexToIdbKeyRange = (filter: RangeCollectionIndexFilter) => {\n\tconst lower = filter.gte || filter.gt;\n\tconst upper = filter.lte || filter.lt;\n\tif (lower === upper) {\n\t\treturn IDBKeyRange.only(sanitizeIndexValue(lower));\n\t}\n\tif (!lower) {\n\t\treturn IDBKeyRange.upperBound(sanitizeIndexValue(upper), !!filter.lt);\n\t} else if (!upper) {\n\t\treturn IDBKeyRange.lowerBound(sanitizeIndexValue(lower), !!filter.gt);\n\t} else {\n\t\treturn IDBKeyRange.bound(\n\t\t\tsanitizeIndexValue(lower),\n\t\t\tsanitizeIndexValue(upper),\n\t\t\t!!filter.gt,\n\t\t\t!!filter.lt,\n\t\t);\n\t}\n};\n\nconst compoundIndexToIdbKeyRange = (\n\t// FIXME:\n\tschema: any,\n\tcollection: string,\n\tfilter: CollectionCompoundIndexFilter,\n) => {\n\t// validate the usage of the compound index:\n\t// - all match fields must be contiguous at the start of the compound order\n\tconst indexDefinition =\n\t\tschema.collections[collection].compounds[filter.where];\n\tassert(\n\t\tindexDefinition,\n\t\t`Index ${filter.where} does not exist on collection ${collection}`,\n\t);\n\tconst matchedKeys = Object.keys(filter.match).sort(\n\t\t(a, b) => indexDefinition.of.indexOf(a) - indexDefinition.of.indexOf(b),\n\t);\n\tfor (const key of matchedKeys) {\n\t\tif (indexDefinition.of.indexOf(key) !== matchedKeys.indexOf(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Compound index ${filter.where} does not have ${key} at the start of its order`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst matchedValues = matchedKeys.map(\n\t\t(key) => filter.match[key as keyof typeof filter.match] as string | number,\n\t);\n\n\t// special case: all match fields are specified - we don't need a range\n\t// query, just a single key query\n\tif (matchedKeys.length === indexDefinition.of.length) {\n\t\treturn IDBKeyRange.only(createCompoundIndexValue(...matchedValues));\n\t}\n\n\t// create our bounds for the matched values\n\tconst lower = createLowerBoundIndexValue(...matchedValues);\n\tconst upper = createUpperBoundIndexValue(...matchedValues);\n\treturn IDBKeyRange.bound(lower, upper);\n};\n\nfunction startsWithIndexToIdbKeyRange(filter: StartsWithIndexFilter) {\n\tconst lower = filter.startsWith;\n\tconst upper = filter.startsWith + '\\uffff';\n\treturn IDBKeyRange.bound(lower, upper);\n}\n\nexport function getRange(\n\tschema: StorageSchema,\n\tcollection: string,\n\tindex?: CollectionFilter,\n) {\n\tif (!index) return undefined;\n\tif (isRangeIndexFilter(index)) return rangeIndexToIdbKeyRange(index);\n\tif (isMatchIndexFilter(index)) return matchIndexToIdbKeyRange(index);\n\tif (isSortIndexFilter(index)) return sortIndexToIdbKeyRange(index);\n\tif (isStartsWithIndexFilter(index))\n\t\treturn startsWithIndexToIdbKeyRange(index);\n\treturn compoundIndexToIdbKeyRange(schema, collection, index);\n}\n", "import { CollectionFilter, createOid } from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { getRange } from './ranges.js';\nimport { isAbortError } from '../idb.js';\n\nfunction getStore(db: IDBDatabase, collection: string, write?: boolean) {\n\treturn db\n\t\t.transaction(collection, write ? 'readwrite' : 'readonly')\n\t\t.objectStore(collection);\n}\n\nexport async function findOneOid({\n\tcollection,\n\tindex,\n\tcontext,\n}: {\n\tcollection: string;\n\tindex?: CollectionFilter;\n\tcontext: Context;\n}) {\n\tconst store = getStore(context.documentDb, collection);\n\tconst source = index?.where ? store.index(index.where) : store;\n\tconst range = getRange(context.schema, collection, index);\n\tconst direction = index?.order === 'desc' ? 'prev' : 'next';\n\tconst request = source.openCursor(range, direction);\n\tconst result = await new Promise<string | null>((resolve, reject) => {\n\t\trequest.onsuccess = () => {\n\t\t\tconst cursor = request.result;\n\t\t\tif (cursor) {\n\t\t\t\tresolve(createOid(collection, cursor.primaryKey.toString()));\n\t\t\t} else {\n\t\t\t\tresolve(null);\n\t\t\t}\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error?.name === 'InvalidStateError') {\n\t\t\t\tcontext.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`findOne query failed with InvalidStateError`,\n\t\t\t\t\trequest.error,\n\t\t\t\t);\n\t\t\t\tresolve(null);\n\t\t\t} else if (isAbortError(request.error)) {\n\t\t\t\tresolve(null);\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n\treturn result;\n}\n\nexport async function findAllOids({\n\tcollection,\n\tindex,\n\tcontext,\n}: {\n\tcollection: string;\n\tindex?: CollectionFilter;\n\tcontext: Context;\n}) {\n\tconst store = getStore(context.documentDb, collection);\n\tconst source = index?.where ? store.index(index.where) : store;\n\tconst range = getRange(context.schema, collection, index);\n\tconst direction = index?.order === 'desc' ? 'prev' : 'next';\n\tconst request = source.openCursor(range, direction);\n\tconst result = await new Promise<string[]>((resolve, reject) => {\n\t\tconst results = new Set<string>();\n\t\trequest.onsuccess = () => {\n\t\t\tconst cursor = request.result;\n\t\t\tif (cursor) {\n\t\t\t\tresults.add(createOid(collection, cursor.primaryKey.toString()));\n\t\t\t\tcursor.continue();\n\t\t\t} else {\n\t\t\t\tresolve(Array.from(results));\n\t\t\t}\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error?.name === 'InvalidStateError') {\n\t\t\t\tcontext.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`findAll query failed with InvalidStateError`,\n\t\t\t\t\trequest.error,\n\t\t\t\t);\n\t\t\t\tresolve([]);\n\t\t\t} else if (isAbortError(request.error)) {\n\t\t\t\tresolve([]);\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n\treturn result;\n}\n\nexport async function findPageOfOids({\n\tcollection,\n\tindex,\n\tcontext,\n\tlimit,\n\toffset,\n}: {\n\tcollection: string;\n\tindex?: CollectionFilter;\n\tcontext: Context;\n\tlimit?: number;\n\toffset?: number;\n}) {\n\tconst store = getStore(context.documentDb, collection);\n\tconst source = index?.where ? store.index(index.where) : store;\n\tconst range = getRange(context.schema, collection, index);\n\tconst direction = index?.order === 'desc' ? 'prev' : 'next';\n\tconst request = source.openCursor(range, direction);\n\tlet hasDoneOffset = !offset;\n\tlet hasNextPage = false;\n\tlet visited = 0;\n\tconst result = await new Promise<string[]>((resolve, reject) => {\n\t\tconst results = new Set<string>();\n\t\trequest.onsuccess = () => {\n\t\t\tvisited++;\n\t\t\tconst cursor = request.result;\n\t\t\tif (cursor) {\n\t\t\t\tif (offset && !hasDoneOffset) {\n\t\t\t\t\tcursor.advance(offset);\n\t\t\t\t\thasDoneOffset = true;\n\t\t\t\t} else {\n\t\t\t\t\tif (limit && results.size < limit) {\n\t\t\t\t\t\tresults.add(createOid(collection, cursor.primaryKey.toString()));\n\t\t\t\t\t}\n\t\t\t\t\tif (limit && visited > limit) {\n\t\t\t\t\t\thasNextPage = true;\n\t\t\t\t\t\tresolve(Array.from(results));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcursor.continue();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tresolve(Array.from(results));\n\t\t\t}\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error?.name === 'InvalidStateError') {\n\t\t\t\tcontext.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`find query failed with InvalidStateError`,\n\t\t\t\t\trequest.error,\n\t\t\t\t);\n\t\t\t\tresolve([]);\n\t\t\t} else if (isAbortError(request.error)) {\n\t\t\t\tresolve([]);\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n\n\treturn {\n\t\tresult: result as string[],\n\t\thasNextPage,\n\t};\n}\n", "import {\n\tCollectionFilter,\n\tMigration,\n\tMigrationEngine,\n\tObjectIdentifier,\n\taddFieldDefaults,\n\tassert,\n\tassignOidsToAllSubObjects,\n\tcloneDeep,\n\tcreateOid,\n\tdiffToPatches,\n\tgetOid,\n\tinitialToPatches,\n\tremoveOidPropertiesFromAllSubObjects,\n\tAuthorizationKey,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { findAllOids, findOneOid } from '../queries/dbQueries.js';\nimport { OpenDocumentDbContext } from './types.js';\n\nfunction getMigrationMutations({\n\tmigration,\n\tmeta,\n\tgetMigrationNow,\n\tnewOids,\n}: {\n\tmigration: Migration<any>;\n\tnewOids: string[];\n\tgetMigrationNow: () => string;\n\tmeta: Metadata;\n}) {\n\treturn migration.allCollections.reduce((acc, collectionName) => {\n\t\tacc[collectionName] = {\n\t\t\tput: async (doc: any, options?: { access?: AuthorizationKey }) => {\n\t\t\t\t// add defaults\n\t\t\t\taddFieldDefaults(migration.newSchema.collections[collectionName], doc);\n\t\t\t\tconst primaryKey =\n\t\t\t\t\tdoc[migration.newSchema.collections[collectionName].primaryKey];\n\t\t\t\tconst oid = createOid(collectionName, primaryKey);\n\t\t\t\tnewOids.push(oid);\n\n\t\t\t\tawait meta.insertLocalOperations(\n\t\t\t\t\tinitialToPatches(doc, oid, getMigrationNow, undefined, undefined, {\n\t\t\t\t\t\tauthz: options?.access,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\treturn doc;\n\t\t\t},\n\t\t\tdelete: async (id: string) => {\n\t\t\t\tconst rootOid = createOid(collectionName, id);\n\t\t\t\tconst authz = await meta.getDocumentAuthz(rootOid);\n\t\t\t\tconst allOids = await meta.getAllDocumentRelatedOids(rootOid);\n\t\t\t\treturn meta.insertLocalOperations(\n\t\t\t\t\tallOids.map((oid) => ({\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getMigrationNow(),\n\t\t\t\t\t\tdata: { op: 'delete' },\n\t\t\t\t\t\tauthz,\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t\treturn acc;\n\t}, {} as any);\n}\n\nfunction getMigrationQueries({\n\tmigration,\n\tcontext,\n\tmeta,\n}: {\n\tmigration: Migration<any>;\n\tcontext: Context;\n\tmeta: Metadata;\n}) {\n\treturn migration.oldCollections.reduce((acc, collectionName) => {\n\t\tacc[collectionName] = {\n\t\t\tget: async (id: string) => {\n\t\t\t\tconst oid = createOid(collectionName, id);\n\t\t\t\tconst doc = await meta.getDocumentSnapshot(oid, {\n\t\t\t\t\t// only get the snapshot up to the previous version (newer operations may have synced)\n\t\t\t\t\tto: meta.time.now(migration.oldSchema.version),\n\t\t\t\t});\n\t\t\t\treturn doc;\n\t\t\t},\n\t\t\tfindOne: async (filter: CollectionFilter) => {\n\t\t\t\tconst oid = await findOneOid({\n\t\t\t\t\tcollection: collectionName,\n\t\t\t\t\tindex: filter,\n\t\t\t\t\tcontext,\n\t\t\t\t});\n\t\t\t\tif (!oid) return null;\n\t\t\t\tconst doc = await meta.getDocumentSnapshot(oid, {\n\t\t\t\t\t// only get the snapshot up to the previous version (newer operations may have synced)\n\t\t\t\t\tto: meta.time.now(migration.oldSchema.version),\n\t\t\t\t});\n\t\t\t\treturn doc;\n\t\t\t},\n\t\t\tfindAll: async (filter: CollectionFilter) => {\n\t\t\t\tconst oids = await findAllOids({\n\t\t\t\t\tcollection: collectionName,\n\t\t\t\t\tindex: filter,\n\t\t\t\t\tcontext,\n\t\t\t\t});\n\t\t\t\tconst docs = await Promise.all(\n\t\t\t\t\toids.map((oid) =>\n\t\t\t\t\t\tmeta.getDocumentSnapshot(oid, {\n\t\t\t\t\t\t\t// only get the snapshot up to the previous version (newer operations may have synced)\n\t\t\t\t\t\t\tto: meta.time.now(migration.oldSchema.version),\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn docs;\n\t\t\t},\n\t\t};\n\t\treturn acc;\n\t}, {} as any);\n}\n\nexport function getMigrationEngine({\n\tmeta,\n\tmigration,\n\tcontext,\n}: {\n\tlog?: (...args: any[]) => void;\n\tmigration: Migration;\n\tmeta: Metadata;\n\tcontext: Context;\n}): MigrationEngine {\n\tfunction getMigrationNow() {\n\t\treturn meta.time.zero(migration.version);\n\t}\n\n\tconst newOids = new Array<ObjectIdentifier>();\n\n\tconst queries = getMigrationQueries({\n\t\tmigration,\n\t\tcontext,\n\t\tmeta,\n\t});\n\tconst mutations = getMigrationMutations({\n\t\tmigration,\n\t\tgetMigrationNow,\n\t\tnewOids,\n\t\tmeta,\n\t});\n\tconst deleteCollection = async (collection: string) => {\n\t\tconst allOids = await meta.getAllCollectionRelatedOids(collection);\n\t\treturn meta.insertLocalOperations(\n\t\t\tallOids.map((oid) => ({\n\t\t\t\toid,\n\t\t\t\ttimestamp: getMigrationNow(),\n\t\t\t\tdata: { op: 'delete' },\n\t\t\t})),\n\t\t);\n\t};\n\tconst awaitables = new Array<Promise<any>>();\n\tconst engine: MigrationEngine = {\n\t\tlog: context.log,\n\t\tnewOids,\n\t\tdeleteCollection,\n\t\tmigrate: async (collection, strategy) => {\n\t\t\tconst docs = await queries[collection].findAll();\n\n\t\t\tawait Promise.all(\n\t\t\t\tdocs.filter(Boolean).map(async (doc: any) => {\n\t\t\t\t\tconst rootOid = getOid(doc);\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!!rootOid,\n\t\t\t\t\t\t`Document is missing an OID: ${JSON.stringify(doc)}`,\n\t\t\t\t\t);\n\t\t\t\t\t// FIXME: this could be optimized (making n queries for authz\n\t\t\t\t\t// when the snapshots themselves are derived from the same data...)\n\t\t\t\t\t// maybe don't use the findAll query, and instead go a level\n\t\t\t\t\t// lower to retain access to lower level data here?\n\t\t\t\t\tconst authz = await meta.getDocumentAuthz(rootOid);\n\t\t\t\t\tconst original = cloneDeep(doc);\n\t\t\t\t\t// @ts-ignore - excessive type resolution\n\t\t\t\t\tconst newValue = await strategy(doc);\n\t\t\t\t\tif (newValue) {\n\t\t\t\t\t\t// the migration has altered the shape of our document. we need\n\t\t\t\t\t\t// to create the operation from the diff and write it to meta as\n\t\t\t\t\t\t// a migration patch\n\t\t\t\t\t\tremoveOidPropertiesFromAllSubObjects(original);\n\t\t\t\t\t\tremoveOidPropertiesFromAllSubObjects(newValue);\n\t\t\t\t\t\tassignOidsToAllSubObjects(newValue);\n\t\t\t\t\t\tconst patches = diffToPatches(\n\t\t\t\t\t\t\toriginal,\n\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\tgetMigrationNow,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmergeUnknownObjects: true,\n\t\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (patches.length > 0) {\n\t\t\t\t\t\t\tawait meta.insertLocalOperations(patches);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tqueries,\n\t\tmutations,\n\t\tawaitables,\n\t};\n\treturn engine;\n}\n\nexport function getInitialMigrationEngine({\n\tmeta,\n\tmigration,\n\tcontext,\n}: {\n\tcontext: OpenDocumentDbContext;\n\tmigration: Migration;\n\tmeta: Metadata;\n}): MigrationEngine {\n\tfunction getMigrationNow() {\n\t\treturn meta.time.zero(migration.version);\n\t}\n\n\tconst newOids = new Array<ObjectIdentifier>();\n\n\tconst queries = new Proxy({} as any, {\n\t\tget() {\n\t\t\tthrow new Error(\n\t\t\t\t'Queries are not available in initial migrations; there is no database yet!',\n\t\t\t);\n\t\t},\n\t}) as any;\n\n\tconst mutations = getMigrationMutations({\n\t\tmigration,\n\t\tgetMigrationNow,\n\t\tnewOids,\n\t\tmeta,\n\t});\n\tconst engine: MigrationEngine = {\n\t\tlog: context.log,\n\t\tnewOids,\n\t\tdeleteCollection: () => {\n\t\t\tthrow new Error(\n\t\t\t\t'Calling deleteCollection() in initial migrations is not supported! Use initial migrations to seed initial data using mutations.',\n\t\t\t);\n\t\t},\n\t\tmigrate: () => {\n\t\t\tthrow new Error(\n\t\t\t\t'Calling migrate() in initial migrations is not supported! Use initial migrations to seed initial data using mutations.',\n\t\t\t);\n\t\t},\n\t\tqueries,\n\t\tmutations,\n\t\tawaitables: [],\n\t};\n\treturn engine;\n}\n", "import {\n\tMigration,\n\tMigrationEngine,\n\tcreateOid,\n\tdecomposeOid,\n\tgetIndexValues,\n\tgetOidRoot,\n} from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { ClientOperation } from '../metadata/OperationsStore.js';\nimport { acquireLock, openDatabase, upgradeDatabase } from './db.js';\nimport { getInitialMigrationEngine, getMigrationEngine } from './engine.js';\nimport { OpenDocumentDbContext } from './types.js';\nimport { closeDatabase } from '../idb.js';\n\nconst globalIDB =\n\ttypeof window !== 'undefined' ? window.indexedDB : (undefined as any);\n\nexport async function runMigrations({\n\tcontext,\n\ttoRun,\n\tmeta,\n\tindexedDB = globalIDB,\n\tnamespace = context.namespace,\n}: {\n\tcontext: OpenDocumentDbContext;\n\ttoRun: Migration<any>[];\n\tmeta: Metadata;\n\tindexedDB?: IDBFactory;\n\t/** This namespace value controls where the database being migrated is. */\n\tnamespace?: string;\n}) {\n\tawait acquireLock(namespace, async () => {\n\t\t// now the fun part\n\t\tfor (const migration of toRun) {\n\t\t\t// special case: if this is the version 1 migration, we have no pre-existing database\n\t\t\t// to use for the migration.\n\t\t\tlet engine: MigrationEngine;\n\t\t\t// migrations from 0 (i.e. initial migrations) don't attempt to open an existing db\n\t\t\tif (migration.oldSchema.version === 0) {\n\t\t\t\tengine = getInitialMigrationEngine({\n\t\t\t\t\tmeta,\n\t\t\t\t\tmigration,\n\t\t\t\t\tcontext,\n\t\t\t\t});\n\t\t\t\tawait migration.migrate(engine);\n\t\t\t} else {\n\t\t\t\t// open the database with the current (old) version for this migration. this should\n\t\t\t\t// align with the database's current version.\n\t\t\t\tconst originalDatabase = await openDatabase({\n\t\t\t\t\tindexedDB,\n\t\t\t\t\tnamespace,\n\t\t\t\t\tversion: migration.oldSchema.version,\n\t\t\t\t\tcontext,\n\t\t\t\t});\n\n\t\t\t\t// this will only write to our metadata store via operations!\n\t\t\t\tengine = getMigrationEngine({\n\t\t\t\t\tmeta,\n\t\t\t\t\tmigration,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\t...context,\n\t\t\t\t\t\tdocumentDb: originalDatabase,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\ttry {\n\t\t\t\t\tawait migration.migrate(engine);\n\t\t\t\t\t// wait on any out-of-band async operations to complete\n\t\t\t\t\tawait Promise.all(engine.awaitables);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tcontext.log(\n\t\t\t\t\t\t'critical',\n\t\t\t\t\t\t`Migration failed (${migration.oldSchema.version} -> ${migration.newSchema.version})`,\n\t\t\t\t\t\terr,\n\t\t\t\t\t);\n\t\t\t\t\tif (err instanceof Error) {\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('Unknown error during migration');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// now we have to open the database again with the next version and\n\t\t\t\t// make the appropriate schema changes during the upgrade.\n\t\t\t\tawait closeDatabase(originalDatabase);\n\t\t\t}\n\n\t\t\tcontext.log(\n\t\t\t\t'debug',\n\t\t\t\t'Upgrading database',\n\t\t\t\tnamespace,\n\t\t\t\t'to version',\n\t\t\t\tmigration.newSchema.version,\n\t\t\t);\n\t\t\tconst upgradedDatabase = await applySchemaToDatabase({\n\t\t\t\tmigration,\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace,\n\t\t\t\tcontext,\n\t\t\t});\n\n\t\t\t/**\n\t\t\t * In cases where operations from the future have been\n\t\t\t * received by this client, we may have created entire\n\t\t\t * documents in metadata which were not written to storage\n\t\t\t * because all of their operations were in the future (\n\t\t\t * i.e. in the next version). We have to find those documents\n\t\t\t * and also write their snapshots to storage, because they\n\t\t\t * won't be present in storage already to 'refresh,' so\n\t\t\t * if we don't analyze metadata for 'future' operations like\n\t\t\t * this, we won't know they exist.\n\t\t\t *\n\t\t\t * This led to behavior where the metadata would be properly\n\t\t\t * synced, but after upgrading the app and migrating, items\n\t\t\t * would be missing from findAll and findOne queries.\n\t\t\t */\n\t\t\tconst docsWithUnappliedMigrations = await getDocsWithUnappliedMigrations({\n\t\t\t\tmeta,\n\t\t\t\tcurrentVersion: migration.oldSchema.version,\n\t\t\t\tnewVersion: migration.newSchema.version,\n\t\t\t});\n\n\t\t\t// once the schema is ready, we can write back the migrated documents\n\n\t\t\tfor (const collection of migration.allCollections) {\n\t\t\t\t// first step is to read in all the keys we need to rewrite\n\t\t\t\tconst documentReadTransaction = upgradedDatabase.transaction(\n\t\t\t\t\tcollection,\n\t\t\t\t\t'readwrite',\n\t\t\t\t);\n\t\t\t\tconst readStore = documentReadTransaction.objectStore(collection);\n\t\t\t\tconst keys = await getAllKeys(readStore);\n\t\t\t\t// map the keys to OIDs\n\t\t\t\tconst oids = keys.map((key) => createOid(collection, `${key}`));\n\t\t\t\toids.push(\n\t\t\t\t\t...engine.newOids.filter((oid) => {\n\t\t\t\t\t\treturn decomposeOid(oid).collection === collection;\n\t\t\t\t\t}),\n\t\t\t\t\t...docsWithUnappliedMigrations.filter((oid) => {\n\t\t\t\t\t\treturn decomposeOid(oid).collection === collection;\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\t// add 'touch' operations to all root OIDs of all documents.\n\t\t\t\t// this marks documents which have undergone a migration\n\t\t\t\t// so that other clients know when they're working\n\t\t\t\t// with unmigrated data - by seeing that there are no\n\t\t\t\t// existing operations or baselines with a timestamp\n\t\t\t\t// that matches the current version.\n\t\t\t\t// UPDATE: no longer necessary now that pruning is a thing.\n\t\t\t\t// await Promise.all(\n\t\t\t\t// \toids.map((oid) =>\n\t\t\t\t// \t\tmeta.insertLocalOperations([\n\t\t\t\t// \t\t\t{\n\t\t\t\t// \t\t\t\toid,\n\t\t\t\t// \t\t\t\ttimestamp: meta.time.zero(migration.version),\n\t\t\t\t// \t\t\t\tdata: { op: 'touch' },\n\t\t\t\t// \t\t\t},\n\t\t\t\t// \t\t]),\n\t\t\t\t// \t),\n\t\t\t\t// );\n\n\t\t\t\tconst snapshots = await Promise.all(\n\t\t\t\t\toids.map(async (oid) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst snap = await meta.getDocumentSnapshot(oid);\n\t\t\t\t\t\t\treturn [oid, snap];\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t// this seems to happen with baselines/ops which are not fully\n\t\t\t\t\t\t\t// cleaned up after deletion?\n\t\t\t\t\t\t\tcontext.log(\n\t\t\t\t\t\t\t\t'error',\n\t\t\t\t\t\t\t\t'Could not regenerate snapshot during migration for oid',\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\t'this document will not be preserved',\n\t\t\t\t\t\t\t\te,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tconst views = snapshots\n\t\t\t\t\t.filter((s): s is [string, any] => !!s)\n\t\t\t\t\t.map(([oid, snapshot]) => {\n\t\t\t\t\t\tif (!snapshot) return [oid, undefined];\n\t\t\t\t\t\tconst view = getIndexValues(\n\t\t\t\t\t\t\tmigration.newSchema.collections[collection],\n\t\t\t\t\t\t\tsnapshot,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn [oid, view];\n\t\t\t\t\t});\n\n\t\t\t\t// now we can write the documents back\n\t\t\t\tconst documentWriteTransaction = upgradedDatabase.transaction(\n\t\t\t\t\tcollection,\n\t\t\t\t\t'readwrite',\n\t\t\t\t);\n\t\t\t\tconst writeStore = documentWriteTransaction.objectStore(collection);\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tviews.map(([oid, view]) => {\n\t\t\t\t\t\tif (view) {\n\t\t\t\t\t\t\treturn putView(writeStore, view);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst { id } = decomposeOid(oid);\n\t\t\t\t\t\t\treturn deleteView(writeStore, id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tawait closeDatabase(upgradedDatabase);\n\n\t\t\tcontext.log('debug', `Migration of ${namespace} complete.`);\n\t\t\tcontext.log(\n\t\t\t\t'info',\n\t\t\t\t`\n\t\t\t\t\u2B06\uFE0F v${migration.newSchema.version} Migration complete. Here's the rundown:\n\t\t\t\t\t- Added collections: ${migration.addedCollections.join(', ')}\n\t\t\t\t\t- Removed collections: ${migration.removedCollections.join(', ')}\n\t\t\t\t\t- Changed collections: ${migration.changedCollections.join(', ')}\n\t\t\t\t\t- New indexes: ${Object.keys(migration.addedIndexes)\n\t\t\t\t\t\t.map((col) =>\n\t\t\t\t\t\t\tmigration.addedIndexes[col].map((i) => `${col}.${i.name}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.flatMap((i) => i)\n\t\t\t\t\t\t.join(', ')}\n\t\t\t\t\t- Removed indexes: ${Object.keys(migration.removedIndexes)\n\t\t\t\t\t\t.map((col) =>\n\t\t\t\t\t\t\tmigration.removedIndexes[col].map((i) => `${col}.${i.name}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.flatMap((i) => i)\n\t\t\t\t\t\t.join(', ')}\n\t\t\t`,\n\t\t\t);\n\t\t}\n\t});\n}\n\nasync function getAllKeys(store: IDBObjectStore) {\n\treturn new Promise<IDBValidKey[]>((resolve, reject) => {\n\t\tconst request = store.getAllKeys();\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve(request.result);\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(request.error);\n\t\t};\n\t});\n}\n\nasync function deleteView(store: IDBObjectStore, id: string) {\n\tconst request = store.delete(id);\n\treturn new Promise<void>((resolve, reject) => {\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve();\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(request.error);\n\t\t};\n\t});\n}\n\nasync function putView(store: IDBObjectStore, view: any) {\n\tconst request = store.put(view);\n\treturn new Promise<void>((resolve, reject) => {\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve();\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(request.error);\n\t\t};\n\t});\n}\n\n/**\n * Gets a list of root OIDs for all documents which had operations stored already\n * that were not applied to their queryable snapshots because they were in the\n * future. These documents need to be refreshed in storage.\n */\nasync function getDocsWithUnappliedMigrations({\n\tmeta,\n\tcurrentVersion,\n\tnewVersion: _,\n}: {\n\tcurrentVersion: number;\n\tnewVersion: number;\n\tmeta: Metadata;\n}) {\n\t// scan for all operations in metadata after the current version.\n\t// this could be more efficient if also filtering below or equal newVersion but\n\t// that seems so unlikely in practice...\n\tconst unappliedOperations: ClientOperation[] = [];\n\tawait meta.operations.iterateOverAllOperations(\n\t\t(op) => unappliedOperations.push(op),\n\t\t{\n\t\t\tfrom: meta.time.zero(currentVersion + 1),\n\t\t},\n\t);\n\treturn Array.from(\n\t\tnew Set(unappliedOperations.map((op) => getOidRoot(op.oid))),\n\t);\n}\n\nexport function applySchemaToDatabase({\n\tmigration,\n\tindexedDB = globalIDB,\n\tnamespace,\n\tcontext,\n}: {\n\tmigration: Migration<any>;\n\tindexedDB?: IDBFactory;\n\tnamespace: string;\n\tcontext: OpenDocumentDbContext;\n}) {\n\treturn upgradeDatabase(\n\t\tindexedDB,\n\t\tnamespace,\n\t\tmigration.newSchema.version,\n\t\t(transaction, db) => {\n\t\t\tfor (const newCollection of migration.addedCollections) {\n\t\t\t\tdb.createObjectStore(newCollection, {\n\t\t\t\t\tkeyPath: migration.newSchema.collections[newCollection].primaryKey,\n\t\t\t\t\tautoIncrement: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tfor (const collection of migration.allCollections) {\n\t\t\t\tconst store = transaction.objectStore(collection);\n\t\t\t\t// apply new indexes\n\t\t\t\tfor (const newIndex of migration.addedIndexes[collection] || []) {\n\t\t\t\t\tstore.createIndex(newIndex.name, newIndex.name, {\n\t\t\t\t\t\tmultiEntry: newIndex.multiEntry,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\t// remove old indexes\n\t\t\t\tfor (const oldIndex of migration.removedIndexes[collection] || []) {\n\t\t\t\t\tstore.deleteIndex(oldIndex.name);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const removedCollection of migration.removedCollections) {\n\t\t\t\t// !! can't delete the store, because old operations that relate to\n\t\t\t\t// this store may still exist in history. instead, we can clear it out\n\t\t\t\t// and leave it in place\n\t\t\t\ttransaction.objectStore(removedCollection).clear();\n\t\t\t}\n\t\t},\n\t\tcontext.log,\n\t);\n}\n", "export class MigrationPathError extends Error {\n\treadonly name = 'MigrationPathError';\n\n\tconstructor(public readonly message: string) {\n\t\tsuper(message);\n\t}\n}\n", "import { Migration } from '@verdant-web/common';\nimport { MigrationPathError } from './errors.js';\n\nexport function getMigrationPath({\n\tcurrentVersion,\n\ttargetVersion,\n\tmigrations,\n}: {\n\tcurrentVersion: number;\n\ttargetVersion: number;\n\tmigrations: Migration[];\n}) {\n\tconst path = getNextPathStep({\n\t\tcurrentVersion,\n\t\ttargetVersion,\n\t\tmigrations,\n\t});\n\tif (!path) {\n\t\tthrow new MigrationPathError(\n\t\t\t`No migration path found from ${currentVersion} to ${targetVersion}! This is a bug. If you're seeing this, contact the developer and provide them with the full contents of this message.`,\n\t\t);\n\t}\n\treturn path;\n}\n\nfunction getNextPathStep({\n\tcurrentVersion,\n\ttargetVersion,\n\tmigrations,\n}: {\n\tcurrentVersion: number;\n\ttargetVersion: number;\n\tmigrations: Migration[];\n}): Migration[] | null {\n\tif (currentVersion === targetVersion) {\n\t\treturn [];\n\t}\n\n\tconst fromHere = migrations\n\t\t.filter((m) => m.oldSchema.version === currentVersion)\n\t\t.sort((a, b) => b.newSchema.version - a.newSchema.version);\n\n\t// keep trying next steps, starting from the largest step,\n\t// until we find one that leads to the target version down the line\n\twhile (fromHere.length > 0) {\n\t\tconst next = fromHere.shift()!;\n\t\t// this one goes too far (probably never relevant, but still)\n\t\tif (next.newSchema.version > targetVersion) {\n\t\t\treturn null;\n\t\t}\n\t\t// exact match - we're done, return the path\n\t\tif (next.newSchema.version === targetVersion) {\n\t\t\treturn [next];\n\t\t}\n\t\t// look ahead a down the line. do we reach the target? if so,\n\t\t// we choose this path.\n\t\tconst nextPath = getNextPathStep({\n\t\t\tcurrentVersion: next.newSchema.version,\n\t\t\ttargetVersion,\n\t\t\tmigrations,\n\t\t});\n\t\tif (nextPath) {\n\t\t\treturn [next, ...nextPath];\n\t\t}\n\n\t\t// otherwise, try the next one with a smaller increment\n\t}\n\n\t// no paths from here match at all! if another layer is calling this one,\n\t// it will fallback to its next longest step. otherwise there may\n\t// be no paths at all...\n\treturn null;\n}\n", "import { Migration } from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { copyAll, getDatabaseVersion, openDatabase } from './db.js';\nimport { runMigrations } from './migrations.js';\nimport { getMigrationPath } from './paths.js';\nimport { OpenDocumentDbContext } from './types.js';\n\nconst globalIDB =\n\ttypeof window !== 'undefined' ? window.indexedDB : (undefined as any);\n\nexport async function openWIPDatabase({\n\tversion,\n\tindexedDB = globalIDB,\n\tmigrations,\n\tmeta,\n\tcontext,\n\twipNamespace,\n}: {\n\tversion: number;\n\tmigrations: Migration<any>[];\n\tindexedDB?: IDBFactory;\n\tmeta: Metadata;\n\tcontext: OpenDocumentDbContext;\n\twipNamespace: string;\n}) {\n\tcontext.log('debug', 'Opening WIP database', wipNamespace);\n\tconst currentWIPVersion = await getDatabaseVersion(\n\t\tindexedDB,\n\t\twipNamespace,\n\t\tversion,\n\t\tcontext.log,\n\t);\n\n\tif (currentWIPVersion === version) {\n\t\tcontext.log('info', `WIP schema is up-to-date; not refreshing database`);\n\t} else {\n\t\tcontext.log('info', `WIP schema is out-of-date; refreshing database`);\n\n\t\t// first we need to copy the data from the production database to the WIP database\n\t\t// at the current (non-wip) version.\n\n\t\tconst initialToRun = getMigrationPath({\n\t\t\tcurrentVersion: currentWIPVersion,\n\t\t\ttargetVersion: version - 1,\n\t\t\tmigrations,\n\t\t});\n\n\t\tif (initialToRun.length > 0) {\n\t\t\tawait runMigrations({\n\t\t\t\tcontext,\n\t\t\t\ttoRun: initialToRun,\n\t\t\t\tmeta,\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace: wipNamespace,\n\t\t\t});\n\n\t\t\t// now, we copy the data from the main database.\n\t\t\tconst mainDatabase = await openDatabase({\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace: context.namespace,\n\t\t\t\tversion: version - 1,\n\t\t\t\tcontext,\n\t\t\t});\n\n\t\t\tconst wipDatabase = await openDatabase({\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace: wipNamespace,\n\t\t\t\tversion: version - 1,\n\t\t\t\tcontext,\n\t\t\t});\n\t\t\tawait copyAll(mainDatabase, wipDatabase);\n\t\t}\n\n\t\tconst toRun = getMigrationPath({\n\t\t\tcurrentVersion: version - 1,\n\t\t\ttargetVersion: version,\n\t\t\tmigrations,\n\t\t});\n\n\t\tif (toRun.length > 0) {\n\t\t\tawait runMigrations({\n\t\t\t\tcontext,\n\t\t\t\ttoRun,\n\t\t\t\tmeta,\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace: wipNamespace,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn openDatabase({\n\t\tindexedDB,\n\t\tnamespace: wipNamespace,\n\t\tversion,\n\t\tcontext,\n\t});\n}\n", "import { EventSubscriber } from '@verdant-web/common';\n\ntype Undoable = () => Undoable | Promise<Undoable | null> | null;\n\nexport class UndoHistory extends EventSubscriber<{ change: () => void }> {\n\tprivate _undoable: Undoable[] = [];\n\tprivate _undone: Undoable[] = [];\n\n\tget canUndo() {\n\t\treturn this._undoable.length > 0;\n\t}\n\tget canRedo() {\n\t\treturn this._undone.length > 0;\n\t}\n\n\tundo = async () => {\n\t\tconst next = this._undoable.pop();\n\t\tif (next) {\n\t\t\tconst redo = await next();\n\t\t\tif (redo) this._undone.push(redo);\n\t\t\tthis.emit('change');\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t};\n\n\tredo = async () => {\n\t\tconst next = this._undone.pop();\n\t\tif (next) {\n\t\t\tconst undo = await next();\n\t\t\tif (undo) this._undoable.push(undo);\n\t\t\tthis.emit('change');\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t};\n\n\taddUndo = (undoPoint: Undoable) => {\n\t\tthis._undoable.push(undoPoint);\n\t\tthis._undone = [];\n\t\tthis.emit('change');\n\t};\n\n\taddRedo = (redoPoint: Undoable) => {\n\t\tthis._undone.push(redoPoint);\n\t\tthis.emit('change');\n\t};\n\n\tclear = () => {\n\t\tthis._undoable = [];\n\t\tthis._undone = [];\n\t\tthis.emit('change');\n\t};\n}\n", "import {\n\taddFieldDefaults,\n\tconstrainEntity,\n\tassert,\n\tcreateOid,\n\tSchemaCollection,\n\tStorageCollectionSchema,\n\tStorageDocument,\n\tStorageSchema,\n\tisRootOid,\n\tAuthorizationKey,\n} from '@verdant-web/common';\nimport { EntityCreateOptions, EntityStore } from '../entities/EntityStore.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Sync } from '../sync/Sync.js';\nimport { Context } from '../context.js';\nimport { ObjectEntity } from '../index.js';\n\n/**\n * Exposes functionality for creating documents,\n * the only mutation which is available as an entry\n * point in the storage system.\n */\nexport class DocumentManager<Schema extends StorageSchema<any>> {\n\tconstructor(\n\t\tprivate schema: Schema,\n\t\tprivate entities: EntityStore,\n\t) {}\n\n\tprivate getOid = (collection: string, init: any) => {\n\t\tconst primaryKeyName = this.schema.collections[collection]\n\t\t\t.primaryKey as Exclude<\n\t\t\tkeyof StorageDocument<SchemaCollection<Schema, any>>,\n\t\t\tsymbol\n\t\t>;\n\t\tconst primaryKey = init[primaryKeyName];\n\t\tassert(\n\t\t\tprimaryKey,\n\t\t\t`Document must have a primary key: ${primaryKeyName.toString()} (got: ${JSON.stringify(\n\t\t\t\tinit,\n\t\t\t)})`,\n\t\t);\n\t\treturn createOid(collection, primaryKey);\n\t};\n\n\tprivate addDefaults = (collectionName: string, init: any) => {\n\t\tconst collection = this.schema.collections[\n\t\t\tcollectionName\n\t\t] as StorageCollectionSchema;\n\t\treturn addFieldDefaults(collection, init);\n\t};\n\n\tprivate validate = (collectionName: string, init: any) => {\n\t\tconst collection = this.schema.collections[\n\t\t\tcollectionName\n\t\t] as StorageCollectionSchema;\n\t\treturn constrainEntity(collection.fields, init);\n\t};\n\n\tcreate = async (\n\t\tcollection: string,\n\t\tinit: any,\n\t\toptions: {\n\t\t\tundoable?: boolean;\n\t\t\taccess?: AuthorizationKey;\n\t\t\tsilenceAccessControlWithPrimaryKeyWarning?: boolean;\n\t\t} = {},\n\t) => {\n\t\tconst widenedOptions = options as EntityCreateOptions;\n\t\tconst defaulted = this.addDefaults(collection, init);\n\t\tconst validated = this.validate(collection, defaulted);\n\t\tconst oid = this.getOid(collection, validated);\n\n\t\tif (options.access) {\n\t\t\tconst collectionSchema = this.schema.collections[collection];\n\t\t\tif (\n\t\t\t\toptions.access !== 'shared' &&\n\t\t\t\tinit[collectionSchema.primaryKey] &&\n\t\t\t\t!options.silenceAccessControlWithPrimaryKeyWarning\n\t\t\t) {\n\t\t\t\t// using a custom primary key with access control is not supported.\n\t\t\t\t// resulting docs could collide with existing docs with different permissions,\n\t\t\t\t// leading to confusing results. this logs a warning.\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Using a custom primary key with access control is not supported. This may result in corrupted documents. Read more about why: https://verdant.dev/docs/sync/access#a-warning-about-custom-primaryKey`,\n\t\t\t\t);\n\t\t\t}\n\t\t\twidenedOptions.access = options.access;\n\t\t}\n\n\t\t// documents are always objects at the root\n\t\treturn this.entities.create(validated, oid, widenedOptions) as any;\n\t};\n\n\tdelete = async (\n\t\tcollection: string,\n\t\tprimaryKey: string,\n\t\toptions: { undoable?: boolean } = {},\n\t) => {\n\t\tconst oid = createOid(collection, primaryKey);\n\t\treturn this.entities.delete(oid, options);\n\t};\n\n\tdeleteAll = async (\n\t\tids: [string, string][],\n\t\toptions: { undoable?: boolean } = {},\n\t) => {\n\t\treturn this.entities.deleteAll(\n\t\t\tids.map(([collection, primaryKey]) => createOid(collection, primaryKey)),\n\t\t\toptions,\n\t\t);\n\t};\n\n\tdeleteAllFromCollection = async (\n\t\tcollection: string,\n\t\tids: string[],\n\t\toptions: { undoable?: boolean } = {},\n\t) => {\n\t\treturn this.entities.deleteAll(\n\t\t\tids.map((primaryKey) => createOid(collection, primaryKey)),\n\t\t\toptions,\n\t\t);\n\t};\n\n\tclone = async (\n\t\tcollection: string,\n\t\tentity: ObjectEntity<any, any>,\n\t\toptions: {\n\t\t\tundoable?: boolean;\n\t\t\taccess?: AuthorizationKey;\n\t\t\tprimaryKey?: string;\n\t\t} = {},\n\t) => {\n\t\tif (!isRootOid(entity.uid)) {\n\t\t\tthrow new Error('Cannot clone non-root documents');\n\t\t}\n\t\t// take the entity snapshot\n\t\tconst snapshot = entity.getSnapshot();\n\t\t// remove the primary key\n\t\tconst collectionSchema = this.schema.collections[collection];\n\t\tdelete snapshot[collectionSchema.primaryKey];\n\t\t// if collection schema's primary key doesn't have a default value,\n\t\t// a user-supplied value is required\n\t\tif (!collectionSchema.fields[collectionSchema.primaryKey].default) {\n\t\t\tif (!options.primaryKey) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Error cloning document from collection ${collection}: collection does not have a default on primary key. You must supply a value to options.primaryKey for the clone.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tsnapshot[collectionSchema.primaryKey] = options.primaryKey;\n\t\t}\n\t\treturn this.create(collection, snapshot, options);\n\t};\n}\n", "import {\n\tcreateFileRef,\n\tFileData,\n\tisFile,\n\tisFileData,\n} from '@verdant-web/common';\nimport cuid from 'cuid';\n\nexport function createFileData(file: File): FileData {\n\treturn {\n\t\tid: cuid(),\n\t\tfile: file,\n\t\turl: undefined,\n\t\tremote: false,\n\t\tname: file.name,\n\t\ttype: file.type,\n\t};\n}\n\n/**\n * MUTATES the value.\n * Replaces File values with refs and returns the normalized value.\n * The list of files passed to the second argument will be populated with the files found in the value.\n */\nexport function processValueFiles(\n\tvalue: any,\n\tonFileIdentified: (fileData: FileData) => void,\n): any {\n\tif (typeof window !== 'undefined' && isFile(value)) {\n\t\tconst data = createFileData(value);\n\t\tonFileIdentified(data);\n\t\treturn createFileRef(data.id);\n\t}\n\n\tif (isFileData(value)) {\n\t\t// create a new ID for the file\n\t\tconst cloned = { ...value, id: cuid() };\n\t\tonFileIdentified(cloned);\n\t\treturn createFileRef(cloned.id);\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (let i = 0; i < value.length; i++) {\n\t\t\tvalue[i] = processValueFiles(value[i], onFileIdentified);\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (typeof value === 'object') {\n\t\tfor (const key in value) {\n\t\t\tvalue[key] = processValueFiles(value[key], onFileIdentified);\n\t\t}\n\t\treturn value;\n\t}\n\n\treturn value;\n}\n\nexport function fileToArrayBuffer(file: File | Blob) {\n\t// special case for testing...\n\tif ('__testReadBuffer' in file) {\n\t\treturn file.__testReadBuffer;\n\t}\n\treturn new Promise<ArrayBuffer>((resolve, reject) => {\n\t\tconst reader = new FileReader();\n\t\treader.onload = () => {\n\t\t\tresolve(reader.result as ArrayBuffer);\n\t\t};\n\t\treader.onerror = reject;\n\t\treader.readAsArrayBuffer(file);\n\t});\n}\n", "import { EventSubscriber, FileData } from '@verdant-web/common';\n\nexport type EntityFileEvents = {\n\tchange: () => void;\n};\n\nexport const UPDATE = Symbol('entity-file-update');\nexport const MARK_FAILED = Symbol('entity-file-mark-failed');\nexport const MARK_UPLOADED = Symbol('entity-file-mark-uploaded');\n\nexport type EntityFileSnapshot = {\n\tid: string;\n\turl?: string | null;\n};\n\n/**\n * Provides a consistent interface for files used in an app via\n * Entity access.\n */\nexport class EntityFile extends EventSubscriber<EntityFileEvents> {\n\t// cached object URL for a local blob file, if applicable\n\tprivate _objectUrl: string | null = null;\n\tprivate _fileData: FileData | null = null;\n\tprivate _loading = true;\n\tprivate _failed = false;\n\tprivate _downloadRemote = false;\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\t{\n\t\t\tdownloadRemote = false,\n\t\t}: {\n\t\t\tdownloadRemote?: boolean;\n\t\t} = {},\n\t) {\n\t\tsuper();\n\t\tthis._downloadRemote = downloadRemote;\n\t}\n\n\tget downloadRemote() {\n\t\treturn this._downloadRemote;\n\t}\n\tget isFile() {\n\t\treturn true;\n\t}\n\tget isUploaded() {\n\t\treturn this._fileData?.remote ?? false;\n\t}\n\n\t[UPDATE] = (fileData: FileData) => {\n\t\tthis._loading = false;\n\t\tthis._failed = false;\n\t\tthis._fileData = fileData;\n\t\tif (fileData.file) {\n\t\t\tif (this._objectUrl) {\n\t\t\t\tURL.revokeObjectURL(this._objectUrl);\n\t\t\t}\n\t\t\tthis._objectUrl = URL.createObjectURL(fileData.file);\n\t\t}\n\t\tthis.emit('change');\n\t};\n\n\t[MARK_FAILED] = () => {\n\t\tthis._failed = true;\n\t\tthis._loading = false;\n\t\tthis.emit('change');\n\t};\n\n\t[MARK_UPLOADED] = () => {\n\t\tif (!this._fileData) return;\n\t\tthis._fileData!.remote = true;\n\t\tthis.emit('change');\n\t};\n\n\tget url(): string | null {\n\t\tif (this.loading) return null;\n\t\tif (this._objectUrl) return this._objectUrl;\n\t\treturn this._fileData?.url ?? null;\n\t}\n\n\tget name(): string | null {\n\t\treturn this._fileData?.name ?? null;\n\t}\n\n\tget type(): string | null {\n\t\treturn this._fileData?.type ?? null;\n\t}\n\n\tget loading() {\n\t\treturn this._loading;\n\t}\n\n\tget failed() {\n\t\treturn this._failed;\n\t}\n\n\tdestroy = () => {\n\t\tif (this._objectUrl) {\n\t\t\tURL.revokeObjectURL(this._objectUrl);\n\t\t}\n\t\tthis.dispose();\n\t};\n\n\tgetSnapshot(): FileData {\n\t\tif (this._fileData) return this._fileData;\n\t\treturn {\n\t\t\tid: this.id,\n\t\t\turl: this._objectUrl ?? undefined,\n\t\t\tname: this.name ?? 'unknown-file',\n\t\t\tremote: false,\n\t\t\ttype: this.type ?? '',\n\t\t};\n\t}\n}\n", "import { Entity, EntityInit } from './Entity.js';\nimport { EntityFile } from '../files/EntityFile.js';\nimport { ObjectIdentifier } from '@verdant-web/common';\n\nexport class EntityCache {\n\tprivate cache = new Map<string, Entity | EntityFile>();\n\n\tconstructor({ initial }: { initial?: Entity[] } = {}) {\n\t\tif (initial) {\n\t\t\tfor (const entity of initial) {\n\t\t\t\tthis.cache.set(entity.oid, entity);\n\t\t\t}\n\t\t}\n\t}\n\n\tget = (init: EntityInit): Entity => {\n\t\tif (this.cache.has(init.oid)) {\n\t\t\treturn this.cache.get(init.oid)! as Entity;\n\t\t}\n\t\tconst entity = new Entity(init);\n\t\tthis.cache.set(init.oid, entity);\n\t\treturn entity;\n\t};\n\n\thas = (oid: ObjectIdentifier) => {\n\t\treturn this.cache.has(oid);\n\t};\n\n\tgetFile = (id: string, options: { downloadRemote: boolean }): EntityFile => {\n\t\tif (this.cache.has(id)) {\n\t\t\treturn this.cache.get(id)! as EntityFile;\n\t\t}\n\t\tconst file = new EntityFile(id, options);\n\t\tthis.cache.set(id, file);\n\t\treturn file;\n\t};\n\n\tgetCached = (oid: string) => {\n\t\treturn this.cache.get(oid);\n\t};\n}\n", "import { Entity } from './Entity.js';\nimport { EntityChangeInfo } from './types.js';\n\nexport function entityFieldSubscriber<T = any>(\n\tentity: Entity,\n\tfield: string | number | symbol,\n\tsubscriber: (\n\t\tnewValue: T,\n\t\tinfo: EntityChangeInfo & { previousValue: T },\n\t) => void,\n) {\n\tconst valueHolder = {\n\t\tpreviousValue: entity.get(field),\n\t\tisLocal: false,\n\t};\n\tfunction handler(\n\t\tthis: { previousValue: T } & EntityChangeInfo,\n\t\tinfo: EntityChangeInfo,\n\t) {\n\t\tif (entity.deleted) {\n\t\t\treturn;\n\t\t}\n\t\tconst newValue = entity.get(field);\n\t\tif (newValue !== this.previousValue) {\n\t\t\tthis.isLocal = info.isLocal;\n\t\t\tsubscriber(newValue, this);\n\t\t\tthis.previousValue = newValue;\n\t\t}\n\t}\n\treturn entity.subscribe('change', handler.bind(valueHolder));\n}\n", "import {\n\tDocumentBaseline,\n\tEntityValidationProblem,\n\tEventSubscriber,\n\tObjectIdentifier,\n\tOperation,\n\tPatchCreator,\n\tStorageFieldSchema,\n\tStorageFieldsSchema,\n\tassert,\n\tassignOid,\n\tcloneDeep,\n\tcompareRefs,\n\tcreateFileRef,\n\tcreateRef,\n\tgetChildFieldSchema,\n\tgetDefault,\n\thasDefault,\n\tisFileRef,\n\tisFile,\n\tisNullable,\n\tisObject,\n\tisObjectRef,\n\tisPrunePoint,\n\tisRef,\n\tmaybeGetOid,\n\tmemoByKeys,\n\ttraverseCollectionFieldsAndApplyDefaults,\n\tvalidateEntityField,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { FileManager } from '../files/FileManager.js';\nimport { processValueFiles } from '../files/utils.js';\nimport { EntityFile } from '../index.js';\nimport { EntityCache } from './EntityCache.js';\nimport { EntityFamilyMetadata, EntityMetadataView } from './EntityMetadata.js';\nimport {\n\tBaseEntityValue,\n\tDataFromInit,\n\tDeepPartial,\n\tEntityChange,\n\tEntityEvents,\n\tListEntity,\n\tListItemInit,\n\tListItemValue,\n\tObjectEntity,\n} from './types.js';\nimport { EntityStoreEventData, EntityStoreEvents } from './EntityStore.js';\nimport { entityFieldSubscriber } from './entityFieldSubscriber.js';\n\nexport interface EntityInit {\n\toid: ObjectIdentifier;\n\tschema: StorageFieldSchema;\n\tentityFamily?: EntityCache;\n\tmetadataFamily: EntityFamilyMetadata;\n\tparent?: Entity;\n\tctx: Context;\n\tfiles: FileManager;\n\treadonlyKeys?: string[];\n\tfieldPath?: (string | number)[];\n\tpatchCreator: PatchCreator;\n\tstoreEvents: EntityStoreEvents;\n\tdeleteSelf: () => void;\n}\n\nexport class Entity<\n\t\tInit = any,\n\t\tKeyValue extends BaseEntityValue = any,\n\t\tSnapshot extends any = DataFromInit<Init>,\n\t>\n\textends EventSubscriber<EntityEvents>\n\timplements\n\t\tObjectEntity<Init, KeyValue, Snapshot>,\n\t\tListEntity<Init, KeyValue, Snapshot>\n{\n\treadonly oid: ObjectIdentifier;\n\tprivate readonlyKeys: string[];\n\tprivate fieldPath: (string | number)[] = [];\n\t// these are shared between all entities in this family\n\tprivate entityFamily: EntityCache;\n\tprivate metadataFamily;\n\n\tprivate schema;\n\tprivate parent: Entity | undefined;\n\tprivate ctx;\n\tprivate files;\n\tprivate patchCreator;\n\tprivate storeEvents;\n\n\t// an internal representation of this Entity.\n\t// if present, this is the cached, known value. If null,\n\t// the entity is deleted. If undefined, we need to recompute\n\t// the view.\n\tprivate _viewData: EntityMetadataView | undefined = undefined;\n\tprivate validationError: EntityValidationProblem | undefined = undefined;\n\tprivate cachedDeepUpdatedAt: number | null = null;\n\t// only used for root entities to track delete/restore state.\n\tprivate wasDeletedLastChange = false;\n\tprivate cachedView: any | undefined = undefined;\n\t// provided from external creators, this is a method to delete\n\t// this entity.\n\tprivate _deleteSelf: () => void;\n\n\tconstructor({\n\t\toid,\n\t\tschema,\n\t\tentityFamily: childCache,\n\t\tparent,\n\t\tctx,\n\t\tmetadataFamily,\n\t\treadonlyKeys,\n\t\tfiles,\n\t\tpatchCreator,\n\t\tstoreEvents,\n\t\tdeleteSelf,\n\t}: EntityInit) {\n\t\tsuper();\n\n\t\tassert(!!oid, 'oid is required');\n\n\t\tthis.oid = oid;\n\t\tthis.readonlyKeys = readonlyKeys || [];\n\t\tthis.ctx = ctx;\n\t\tthis.files = files;\n\t\tthis.schema = schema;\n\t\tthis.entityFamily =\n\t\t\tchildCache ||\n\t\t\tnew EntityCache({\n\t\t\t\tinitial: [this],\n\t\t\t});\n\t\tthis.patchCreator = patchCreator;\n\t\tthis.metadataFamily = metadataFamily;\n\t\tthis.storeEvents = storeEvents;\n\t\tthis.parent = parent;\n\t\tthis._deleteSelf = deleteSelf;\n\n\t\t// TODO: should any but the root entity be listening to these?\n\t\tif (!this.parent) {\n\t\t\tstoreEvents.add.attach(this.onAdd);\n\t\t\tstoreEvents.replace.attach(this.onReplace);\n\t\t\tstoreEvents.resetAll.attach(this.onResetAll);\n\t\t}\n\t}\n\n\tprivate onAdd = (_store: any, data: EntityStoreEventData) => {\n\t\tif (data.oid === this.oid) {\n\t\t\tthis.addConfirmedData(data);\n\t\t}\n\t};\n\tprivate onReplace = (_store: any, data: EntityStoreEventData) => {\n\t\tif (data.oid === this.oid) {\n\t\t\tthis.replaceAllData(data);\n\t\t}\n\t};\n\tprivate onResetAll = () => {\n\t\tthis.resetAllData();\n\t};\n\n\tprivate get metadata() {\n\t\treturn this.metadataFamily.get(this.oid);\n\t}\n\n\t/**\n\t * The view of this Entity, not including nested\n\t * entities (that's the snapshot - see #getSnapshot())\n\t *\n\t * Nested entities are represented by refs.\n\t */\n\tprivate get viewData() {\n\t\tif (this._viewData === undefined) {\n\t\t\tthis._viewData = this.metadata.computeView();\n\t\t\tthis.validate();\n\t\t}\n\t\treturn this._viewData;\n\t}\n\n\t/** convenience getter for viewData.view */\n\tprivate get rawView() {\n\t\treturn this.viewData.view;\n\t}\n\n\t/**\n\t * An Entity's View includes the rendering of its underlying data,\n\t * connecting of children where refs were, and validation\n\t * and pruning according to schema.\n\t */\n\tprivate get view() {\n\t\tif (this.cachedView !== undefined) {\n\t\t\treturn this.cachedView;\n\t\t}\n\n\t\tif (this.viewData.deleted) {\n\t\t\treturn null;\n\t\t}\n\t\t// can't use invalid data - but this should be bubbled up to\n\t\t// a prune point\n\t\tconst rawView = this.rawView;\n\n\t\tconst viewIsWrongType =\n\t\t\t(!rawView && !isNullable(this.schema)) ||\n\t\t\t(this.schema.type === 'array' && !Array.isArray(rawView)) ||\n\t\t\t((this.schema.type === 'object' || this.schema.type === 'map') &&\n\t\t\t\t!isObject(rawView));\n\n\t\tif (viewIsWrongType) {\n\t\t\t// this will cover lists and maps, too.\n\t\t\tif (hasDefault(this.schema)) {\n\t\t\t\treturn getDefault(this.schema);\n\t\t\t}\n\t\t\t// force null - invalid - will require parent prune\n\t\t\treturn null as any;\n\t\t}\n\n\t\tthis.cachedView = this.isList ? [] : {};\n\t\tassignOid(this.cachedView, this.oid);\n\n\t\tif (Array.isArray(rawView)) {\n\t\t\tconst schema = getChildFieldSchema(this.schema, 0);\n\t\t\tif (!schema) {\n\t\t\t\t/**\n\t\t\t\t * PRUNE - this is a prune point. we can't continue\n\t\t\t\t * to render this data, so we'll just return [].\n\t\t\t\t * This skips the loop.\n\t\t\t\t */\n\t\t\t\tthis.ctx.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t'No child field schema for list entity.',\n\t\t\t\t\tthis.oid,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tfor (let i = 0; i < rawView.length; i++) {\n\t\t\t\t\tconst child = this.get(i);\n\t\t\t\t\tif (this.childIsNull(child) && !isNullable(schema)) {\n\t\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t\t'error',\n\t\t\t\t\t\t\t'Child missing in non-nullable field',\n\t\t\t\t\t\t\tthis.oid,\n\t\t\t\t\t\t\t'index:',\n\t\t\t\t\t\t\ti,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// this item will be pruned.\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.cachedView.push(child);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (isObject(rawView)) {\n\t\t\t// iterate over known properties in object-type entities;\n\t\t\t// for maps, we just iterate over the keys.\n\t\t\tconst keys =\n\t\t\t\tthis.schema.type === 'object'\n\t\t\t\t\t? Object.keys(this.schema.properties)\n\t\t\t\t\t: Object.keys(rawView);\n\t\t\tfor (const key of keys) {\n\t\t\t\tconst schema = getChildFieldSchema(this.schema, key);\n\t\t\t\tif (!schema) {\n\t\t\t\t\t/**\n\t\t\t\t\t * PRUNE - this is a prune point. we can't continue\n\t\t\t\t\t * to render this data. If this is a map, it will be\n\t\t\t\t\t * pruned empty. Otherwise, prune moves upward.\n\t\t\t\t\t *\n\t\t\t\t\t * This exits the loop.\n\t\t\t\t\t */\n\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t'error',\n\t\t\t\t\t\t'No child field schema for object entity at key',\n\t\t\t\t\t\tkey,\n\t\t\t\t\t);\n\t\t\t\t\tif (this.schema.type === 'map') {\n\t\t\t\t\t\t// it's valid to prune here if it's a map\n\t\t\t\t\t\tthis.cachedView = {};\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// otherwise prune moves upward\n\t\t\t\t\t\tthis.cachedView = null;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tconst child = this.get(key as any);\n\t\t\t\tif (this.childIsNull(child) && !isNullable(schema)) {\n\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t'error',\n\t\t\t\t\t\t'Child entity is missing for non-nullable field',\n\t\t\t\t\t\tthis.oid,\n\t\t\t\t\t\t'key:',\n\t\t\t\t\t\tkey,\n\t\t\t\t\t);\n\t\t\t\t\t/**\n\t\t\t\t\t * PRUNE - this is a prune point. we can't continue\n\t\t\t\t\t * to render this data. If this is a map, we can ignore\n\t\t\t\t\t * this value. Otherwise we must prune upward.\n\t\t\t\t\t * This exits the loop.\n\t\t\t\t\t */\n\t\t\t\t\tif (this.schema.type !== 'map') {\n\t\t\t\t\t\tthis.cachedView = null;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthis.cachedView[key] = child;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this.cachedView;\n\t}\n\n\tprivate childIsNull = (child: any) => {\n\t\tif (child instanceof Entity) {\n\t\t\tconst childView = child.view;\n\t\t\treturn childView === null || childView === undefined;\n\t\t}\n\t\treturn child === null || child === undefined;\n\t};\n\n\tget uid() {\n\t\treturn this.oid;\n\t}\n\n\tget deleted() {\n\t\treturn this.viewData.deleted || this.view === null;\n\t}\n\n\tget invalid() {\n\t\treturn !!this.validate();\n\t}\n\n\tget isList() {\n\t\t// have to turn TS off here as our two interfaces both implement\n\t\t// const values for this boolean.\n\t\treturn (\n\t\t\tthis.schema.type === 'array' || (Array.isArray(this.viewData.view) as any)\n\t\t);\n\t}\n\n\tget updatedAt() {\n\t\treturn this.viewData.updatedAt;\n\t}\n\n\tget deepUpdatedAt() {\n\t\tif (this.cachedDeepUpdatedAt) return this.cachedDeepUpdatedAt;\n\t\t// iterate over all children and take the latest timestamp\n\t\tlet latest: number | null = this.updatedAt;\n\t\tif (this.isList) {\n\t\t\tthis.forEach((child: any) => {\n\t\t\t\tif (child instanceof Entity) {\n\t\t\t\t\tconst childTimestamp = child.deepUpdatedAt;\n\t\t\t\t\tif (childTimestamp && (!latest || childTimestamp > latest)) {\n\t\t\t\t\t\tlatest = childTimestamp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tthis.values().forEach((child) => {\n\t\t\t\tif (child instanceof Entity) {\n\t\t\t\t\tconst childTimestamp = child.deepUpdatedAt;\n\t\t\t\t\tif (childTimestamp && (!latest || childTimestamp > latest)) {\n\t\t\t\t\t\tlatest = childTimestamp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tthis.cachedDeepUpdatedAt = latest;\n\t\treturn latest;\n\t}\n\n\t/**\n\t * @internal - this is relevant to Verdant's system, not users.\n\t *\n\t * Indicates whether this document is from an outdated version\n\t * of the schema - which means it cannot be used until it is upgraded.\n\t */\n\tget isOutdatedVersion(): boolean {\n\t\tif (this.parent) return this.parent.isOutdatedVersion;\n\t\treturn this.viewData.fromOlderVersion;\n\t}\n\n\t/**\n\t * Returns the storage namespace this entity came from. For example, if you\n\t * have multiple stores initialized from the same schema, you can use this\n\t * to figure out where an isolated entity was created / stored.\n\t */\n\tget namespace() {\n\t\treturn this.ctx.namespace;\n\t}\n\n\t/**\n\t * The authz string signifying the permissions this entity has.\n\t * On the client (where we are) it's only ever possible to see\n\t * an entity with either full access or access for the current\n\t * user.\n\t */\n\tget access() {\n\t\treturn this.viewData.authz;\n\t}\n\tget isAuthorized() {\n\t\treturn !!this.access;\n\t}\n\n\t/**\n\t * Introspects the schema of a child field of this entity.\n\t */\n\tgetFieldSchema = (key: any): StorageFieldSchema => {\n\t\tconst fieldSchema = getChildFieldSchema(this.schema, key);\n\t\tassert(fieldSchema, `No schema for key ${key}`);\n\t\treturn fieldSchema;\n\t};\n\n\t/**\n\t * Pruning - when entities have invalid children, we 'prune' that\n\t * data up to the nearest prunable point - a nullable field,\n\t * or a list.\n\t */\n\tprotected validate = memoByKeys(\n\t\t() => {\n\t\t\tthis.validationError =\n\t\t\t\tvalidateEntityField({\n\t\t\t\t\tfield: this.schema,\n\t\t\t\t\tvalue: this.rawView,\n\t\t\t\t\tfieldPath: this.fieldPath,\n\t\t\t\t\tdepth: 1,\n\t\t\t\t}) ?? undefined;\n\t\t\treturn this.validationError;\n\t\t},\n\t\t() => [this.viewData],\n\t);\n\n\tprivate viewWithMappedChildren = (\n\t\tmapper: (child: Entity | EntityFile) => any,\n\t) => {\n\t\tconst view = this.view;\n\t\tif (!view) {\n\t\t\treturn null;\n\t\t}\n\t\tif (Array.isArray(view)) {\n\t\t\tconst mapped = view.map((value) => {\n\t\t\t\tif (value instanceof Entity || value instanceof EntityFile) {\n\t\t\t\t\treturn mapper(value);\n\t\t\t\t} else {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t});\n\t\t\tassignOid(mapped, this.oid);\n\t\t\treturn mapped;\n\t\t} else {\n\t\t\tconst mapped = Object.entries(view).reduce((acc, [key, value]) => {\n\t\t\t\tif (value instanceof Entity || value instanceof EntityFile) {\n\t\t\t\t\tacc[key as any] = mapper(value);\n\t\t\t\t} else {\n\t\t\t\t\tacc[key as any] = value;\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t}, {} as any);\n\t\t\tassignOid(mapped, this.oid);\n\t\t\treturn mapped;\n\t\t}\n\t};\n\n\t/**\n\t * A current snapshot of this Entity's data, including nested\n\t * Entities.\n\t */\n\tgetSnapshot = (): any => {\n\t\treturn this.viewWithMappedChildren((child) => child.getSnapshot());\n\t};\n\n\t// change management methods (internal use only)\n\tprivate addPendingOperations = (operations: Operation[]) => {\n\t\tthis.ctx.log('debug', 'Entity: adding pending operations', this.oid);\n\n\t\t// apply authz to all operations\n\t\tif (this.access) {\n\t\t\tfor (const op of operations) {\n\t\t\t\top.authz = this.access;\n\t\t\t}\n\t\t}\n\n\t\tconst changes = this.metadataFamily.addPendingData(operations);\n\t\tfor (const change of changes) {\n\t\t\tthis.change(change);\n\t\t}\n\t};\n\n\tprivate addConfirmedData = (data: EntityStoreEventData) => {\n\t\tthis.ctx.log('debug', 'Entity: adding confirmed data', this.oid);\n\t\tconst changes = this.metadataFamily.addConfirmedData(data);\n\t\tfor (const change of changes) {\n\t\t\tthis.change(change);\n\t\t}\n\t};\n\n\tprivate replaceAllData = (data: EntityStoreEventData) => {\n\t\tthis.ctx.log('debug', 'Entity: replacing all data', this.oid);\n\t\tconst changes = this.metadataFamily.replaceAllData(data);\n\t\tfor (const change of changes) {\n\t\t\tthis.change(change);\n\t\t}\n\t};\n\n\tprivate resetAllData = () => {\n\t\tthis.ctx.log('debug', 'Entity: resetting all data', this.oid);\n\t\tthis.cachedDeepUpdatedAt = null;\n\t\tthis.cachedView = undefined;\n\t\tthis._viewData = undefined;\n\t\tconst changes = this.metadataFamily.replaceAllData({});\n\t\tfor (const change of changes) {\n\t\t\tthis.change(change);\n\t\t}\n\t};\n\n\tprivate invalidateCachedView = () => {\n\t\tthis._viewData = undefined;\n\t\tthis.cachedView = undefined;\n\t};\n\n\tprivate change = (ev: EntityChange) => {\n\t\tif (ev.oid === this.oid) {\n\t\t\t// reset cached view\n\t\t\tthis.invalidateCachedView();\n\t\t\tif (!this.parent) {\n\t\t\t\tthis.changeRoot(ev);\n\t\t\t} else {\n\t\t\t\tthis.changeNested(ev);\n\t\t\t}\n\t\t} else {\n\t\t\t// forward it to the correct family member. if none exists\n\t\t\t// in cache, no one will hear it anyways.\n\t\t\tconst other = this.entityFamily.getCached(ev.oid);\n\t\t\tif (other && other instanceof Entity) {\n\t\t\t\tother.change(ev);\n\t\t\t}\n\t\t}\n\t};\n\tprivate changeRoot = (ev: EntityChange) => {\n\t\t// for root entities, we need to determine if we're deleted or not\n\t\t// before firing any events\n\t\tif (this.deleted) {\n\t\t\tif (!this.wasDeletedLastChange) {\n\t\t\t\tthis.ctx.log('debug', 'Entity deleted', this.oid);\n\t\t\t\tthis.emit('delete', { isLocal: ev.isLocal });\n\t\t\t\tthis.wasDeletedLastChange = true;\n\t\t\t}\n\t\t\t// already deleted, do nothing.\n\t\t} else {\n\t\t\tif (this.wasDeletedLastChange) {\n\t\t\t\tthis.ctx.log('debug', 'Entity restored', this.oid);\n\t\t\t\tthis.emit('restore', { isLocal: ev.isLocal });\n\t\t\t\tthis.wasDeletedLastChange = false;\n\t\t\t}\n\t\t\t// emit deepchange, too\n\t\t\tthis.deepChange(this, ev);\n\t\t\t// emit the change, it's for us\n\t\t\tthis.emit('change', { isLocal: ev.isLocal });\n\t\t}\n\t};\n\tprivate changeNested = (ev: EntityChange) => {\n\t\t// chain deepChanges to parents\n\t\tthis.deepChange(this, ev);\n\t\t// emit the change, it's for us\n\t\tthis.emit('change', { isLocal: ev.isLocal });\n\t};\n\tprotected deepChange = (target: Entity, ev: EntityChange) => {\n\t\t// reset cached deep updated at timestamp; either this\n\t\t// entity or children have changed\n\t\tthis.cachedDeepUpdatedAt = null;\n\t\t// reset this flag to recompute snapshot data - children\n\t\t// or self has changed. new pruning needs to happen.\n\t\tthis.cachedView = undefined;\n\t\tthis.emit('changeDeep', target, ev);\n\t\tthis.parent?.deepChange(target, ev);\n\t};\n\n\tprivate getChild = (key: any, oid: ObjectIdentifier) => {\n\t\tconst schema = getChildFieldSchema(this.schema, key);\n\t\tif (!schema) {\n\t\t\tthrow new Error(\n\t\t\t\t`No schema for key ${String(key)} in ${JSON.stringify(this.schema)}`,\n\t\t\t);\n\t\t}\n\t\treturn this.entityFamily.get({\n\t\t\toid,\n\t\t\tschema,\n\t\t\tentityFamily: this.entityFamily,\n\t\t\tmetadataFamily: this.metadataFamily,\n\t\t\tparent: this,\n\t\t\tctx: this.ctx,\n\t\t\tfiles: this.files,\n\t\t\tfieldPath: [...this.fieldPath, key],\n\t\t\tpatchCreator: this.patchCreator,\n\t\t\tstoreEvents: this.storeEvents,\n\t\t\tdeleteSelf: this.delete.bind(this, key),\n\t\t});\n\t};\n\n\tsubscribeToField = <K extends keyof KeyValue>(\n\t\tkey: K,\n\t\tevent: 'change', // here to keep future api changes stable\n\t\tcallback: (\n\t\t\tvalue: KeyValue[K],\n\t\t\tinfo: { previousValue: KeyValue[K]; isLocal?: boolean },\n\t\t) => void,\n\t) => {\n\t\treturn entityFieldSubscriber<KeyValue[K]>(this, key, callback);\n\t};\n\n\t// generic entity methods\n\t/**\n\t * Gets a value from this Entity. If the value\n\t * is an object, it will be wrapped in another\n\t * Entity.\n\t */\n\tget = <Key extends keyof KeyValue>(key: Key): KeyValue[Key] => {\n\t\tassertNotSymbol(key);\n\n\t\tconst view = this.rawView;\n\t\tif (!view) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot access data at key ${key} on deleted entity ${this.oid}`,\n\t\t\t);\n\t\t}\n\t\tconst child = view[key as any];\n\t\tconst fieldSchema = getChildFieldSchema(this.schema, key);\n\t\tif (!fieldSchema) {\n\t\t\tthrow new Error(\n\t\t\t\t`No schema for key ${String(key)} in ${JSON.stringify(this.schema)}`,\n\t\t\t);\n\t\t}\n\t\tif (isRef(child)) {\n\t\t\tif (isFileRef(child)) {\n\t\t\t\tif (fieldSchema.type !== 'file') {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Expected file schema for key ${String(key)}, got ${\n\t\t\t\t\t\t\tfieldSchema.type\n\t\t\t\t\t\t}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst file = this.files.get(child.id, {\n\t\t\t\t\tdownloadRemote: !!fieldSchema.downloadRemote,\n\t\t\t\t});\n\n\t\t\t\t// FIXME: this seems bad and inconsistent\n\t\t\t\tfile.subscribe('change', () => {\n\t\t\t\t\tthis.deepChange(this, { isLocal: false, oid: this.oid });\n\t\t\t\t});\n\n\t\t\t\treturn file as KeyValue[Key];\n\t\t\t} else {\n\t\t\t\treturn this.getChild(key, child.id) as KeyValue[Key];\n\t\t\t}\n\t\t} else {\n\t\t\t// if this is a Map type, a missing child is\n\t\t\t// just an empty spot\n\t\t\tif (this.schema.type === 'map' && child === undefined) {\n\t\t\t\treturn undefined as KeyValue[Key];\n\t\t\t}\n\t\t\t// prune invalid primitive fields\n\t\t\tif (\n\t\t\t\tvalidateEntityField({\n\t\t\t\t\tfield: fieldSchema,\n\t\t\t\t\tvalue: child,\n\t\t\t\t\tfieldPath: [...this.fieldPath, key],\n\t\t\t\t\tdepth: 1,\n\t\t\t\t\trequireDefaults: true,\n\t\t\t\t})\n\t\t\t) {\n\t\t\t\tif (hasDefault(fieldSchema)) {\n\t\t\t\t\treturn getDefault(fieldSchema);\n\t\t\t\t}\n\t\t\t\tif (isNullable(fieldSchema)) {\n\t\t\t\t\treturn null as any;\n\t\t\t\t}\n\t\t\t\treturn undefined as any;\n\t\t\t}\n\t\t\treturn child as KeyValue[Key];\n\t\t}\n\t};\n\n\t/**\n\t * Gets a value on this entity. If the value is not\n\t * present, it will be set to the provided default\n\t * and returned synchronously. This method only sets\n\t * a new value once when a field is empty; subsequent\n\t * calls will retrieve the created value until it is\n\t * deleted.\n\t *\n\t * Note that this should only be called for nullable\n\t * fields. If the field is not nullable, the existing\n\t * value or the default value will always be returned,\n\t * and the default will not be set.\n\t */\n\tgetOrSet = <Key extends keyof Init & keyof KeyValue>(\n\t\tkey: Key,\n\t\tinit: Init[Key],\n\t): KeyValue[Key] => {\n\t\tassertNotSymbol(key);\n\t\tconst existing = this.get(key);\n\t\tif (existing) return existing;\n\t\tthis.set(key as any, init);\n\t\treturn this.get(key);\n\t};\n\n\tprivate processInputValue = (value: any, key: any) => {\n\t\tif (this.readonlyKeys.includes(key as string)) {\n\t\t\tthrow new Error(`Cannot set readonly key ${key.toString()}`);\n\t\t}\n\t\t// disassociate incoming OIDs on values and generally break object\n\t\t// references. cloning doesn't work on files so those are\n\t\t// filtered out.\n\t\t// The goal here is to be safe about a bunch of cases that could\n\t\t// result in corrupt data, like...\n\t\t// ent1.set('objField', ent2.get('objField'))\n\t\t// or\n\t\t// var shared = { foo: 'bar' };\n\t\t// ent1.set('objField', shared);\n\t\t// ent2.set('objField', shared);\n\t\t// ... each of these would result in the same object being\n\t\t// referenced in multiple entities, which could mean introduction\n\t\t// of foreign OIDs, or one object being assigned different OIDs\n\t\t// with unexpected results.\n\t\tif (!isFile(value)) {\n\t\t\tvalue = cloneDeep(value, false);\n\t\t}\n\t\tconst fieldSchema = getChildFieldSchema(this.schema, key);\n\t\tif (fieldSchema) {\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(value, fieldSchema);\n\t\t\tconst validationError = validateEntityField({\n\t\t\t\tfield: fieldSchema,\n\t\t\t\tvalue,\n\t\t\t\tfieldPath: [...this.fieldPath, key],\n\t\t\t});\n\t\t\tif (validationError) {\n\t\t\t\t// TODO: is it a good idea to throw an error here? a runtime error won't be that helpful,\n\t\t\t\t// but also we don't really want invalid data supplied.\n\t\t\t\tthrow new Error(`Validation error: ${validationError.message}`, {\n\t\t\t\t\tcause: validationError,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn processValueFiles(value, this.files.add);\n\t};\n\n\tprivate getDeleteMode = (key: any) => {\n\t\tif (this.readonlyKeys.includes(key)) {\n\t\t\treturn false;\n\t\t}\n\t\t// any is always deletable, and map values\n\t\tif (this.schema.type === 'any' || this.schema.type === 'map') {\n\t\t\treturn 'delete';\n\t\t}\n\n\t\tif (this.schema.type === 'object') {\n\t\t\tconst property = this.schema.properties[key];\n\t\t\tif (!property) {\n\t\t\t\t// huh, the property doesn't exist. it's ok to\n\t\t\t\t// remove I suppose.\n\t\t\t\treturn 'delete';\n\t\t\t}\n\t\t\tif (property.type === 'any') return 'delete';\n\t\t\t// map can't be nullable. should it be?\n\t\t\tif (property.type === 'map') return false;\n\t\t\tif (property.nullable) return 'null';\n\t\t}\n\t\t// no other types are deletable\n\t\treturn false;\n\t};\n\n\t/**\n\t * Returns the referent value of an item in the list, used for\n\t * operations which act on items. if the item is an object,\n\t * it will attempt to create an OID reference to it. If it\n\t * is a primitive, it will return the primitive.\n\t */\n\tprivate getItemRefValue = (item: any) => {\n\t\tif (item instanceof Entity) {\n\t\t\treturn createRef(item.oid);\n\t\t}\n\t\tif (item instanceof EntityFile) {\n\t\t\treturn createFileRef(item.id);\n\t\t}\n\t\tif (typeof item === 'object') {\n\t\t\tconst itemOid = maybeGetOid(item);\n\t\t\tif (!itemOid || !this.entityFamily.has(itemOid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot move object ${JSON.stringify(\n\t\t\t\t\t\titem,\n\t\t\t\t\t)} which does not exist in this list`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn createRef(itemOid);\n\t\t} else {\n\t\t\treturn item;\n\t\t}\n\t};\n\n\tset = (\n\t\tkey: any,\n\t\tvalue: any,\n\t\toptions?: {\n\t\t\t/**\n\t\t\t * Forces the creation of a change for this set even if the value is the same\n\t\t\t * as the current value for this key. This has an effect in situations where\n\t\t\t * offline changes from others are interleaved with local changes; when setting\n\t\t\t * a value to its current value (force=true), if that value were retroactively changed from\n\t\t\t * offline changes, the set would put it back to the value specified. If the\n\t\t\t * set is ignored because the value is the same (force=false), then retroactive\n\t\t\t * changes will be preserved.\n\t\t\t */\n\t\t\tforce: boolean;\n\t\t},\n\t) => {\n\t\tassertNotSymbol(key);\n\t\tif (!options?.force && this.get(key) === value) return;\n\n\t\tif (this.isList) {\n\t\t\tthis.addPendingOperations(\n\t\t\t\tthis.patchCreator.createListSet(\n\t\t\t\t\tthis.oid,\n\t\t\t\t\tkey,\n\t\t\t\t\tthis.processInputValue(value, key),\n\t\t\t\t),\n\t\t\t);\n\t\t} else {\n\t\t\tthis.addPendingOperations(\n\t\t\t\tthis.patchCreator.createSet(\n\t\t\t\t\tthis.oid,\n\t\t\t\t\tkey,\n\t\t\t\t\tthis.processInputValue(value, key),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t};\n\n\t/**\n\t * Returns a destructured version of this Entity, where child\n\t * Entities are accessible at their respective keys.\n\t */\n\tgetAll = (): KeyValue => {\n\t\treturn this.view;\n\t};\n\n\tdelete = (key: any) => {\n\t\tif (this.isList) {\n\t\t\tassertNumber(key);\n\t\t\tthis.addPendingOperations(\n\t\t\t\tthis.patchCreator.createListDelete(this.oid, key),\n\t\t\t);\n\t\t} else {\n\t\t\t// the key must be deletable - i.e. optional in the schema.\n\t\t\tconst deleteMode = this.getDeleteMode(key);\n\t\t\tif (!deleteMode) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot delete key ${key.toString()} - the property is not marked as optional in the schema.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (deleteMode === 'delete') {\n\t\t\t\tthis.addPendingOperations(\n\t\t\t\t\tthis.patchCreator.createRemove(this.oid, key),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthis.addPendingOperations(\n\t\t\t\t\tthis.patchCreator.createSet(this.oid, key, null),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n\n\t// object entity methods\n\tkeys = (): string[] => {\n\t\tif (!this.view) return [];\n\t\treturn Object.keys(this.view);\n\t};\n\n\tentries = (): [string, Exclude<KeyValue[keyof KeyValue], undefined>][] => {\n\t\tif (!this.view) return [];\n\t\treturn Object.entries(this.view);\n\t};\n\n\tvalues = (): Exclude<KeyValue[keyof KeyValue], undefined>[] => {\n\t\tif (!this.view) return [];\n\t\treturn Object.values(this.view);\n\t};\n\n\tget size() {\n\t\tif (this.isList) {\n\t\t\treturn this.length;\n\t\t}\n\t\treturn this.keys().length;\n\t}\n\n\tupdate = (\n\t\tdata: any,\n\t\t{\n\t\t\tmerge = true,\n\t\t\treplaceSubObjects = false,\n\t\t\tpreserveUndefined = false,\n\t\t}: {\n\t\t\treplaceSubObjects?: boolean;\n\t\t\tmerge?: boolean;\n\t\t\tpreserveUndefined?: boolean;\n\t\t} = {},\n\t): void => {\n\t\tif (!merge && this.schema.type !== 'any' && this.schema.type !== 'map') {\n\t\t\tthrow new Error(\n\t\t\t\t'Cannot use .update without merge if the field has a strict schema type. merge: false is only available on \"any\" or \"map\" types.',\n\t\t\t);\n\t\t}\n\t\tconst changes: any = {};\n\t\tassignOid(changes, this.oid);\n\t\tfor (const [key, field] of Object.entries(data)) {\n\t\t\tif (this.readonlyKeys.includes(key as any)) {\n\t\t\t\tthrow new Error(`Cannot set readonly key ${key.toString()}`);\n\t\t\t}\n\t\t\t// ignore undefined values unless overridden\n\t\t\tif (field === undefined && !preserveUndefined) continue;\n\n\t\t\tconst fieldSchema = getChildFieldSchema(this.schema, key);\n\t\t\tif (fieldSchema) {\n\t\t\t\ttraverseCollectionFieldsAndApplyDefaults(field, fieldSchema);\n\t\t\t}\n\t\t\tchanges[key] = this.processInputValue(field, key);\n\t\t}\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createDiff(this.getSnapshot(), changes, {\n\t\t\t\tmergeUnknownObjects: !replaceSubObjects,\n\t\t\t\tdefaultUndefined: merge,\n\t\t\t}),\n\t\t);\n\t};\n\n\t// array entity methods\n\tget length(): number {\n\t\treturn this.view.length;\n\t}\n\n\tpush = (value: ListItemInit<Init>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListPush(\n\t\t\t\tthis.oid,\n\t\t\t\tthis.processInputValue(value, this.view.length),\n\t\t\t),\n\t\t);\n\t};\n\n\tinsert = (index: number, value: ListItemInit<Init>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListInsert(\n\t\t\t\tthis.oid,\n\t\t\t\tindex,\n\t\t\t\tthis.processInputValue(value, index),\n\t\t\t),\n\t\t);\n\t};\n\n\tmove = (from: number, to: number): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListMoveByIndex(this.oid, from, to),\n\t\t);\n\t};\n\n\tmoveItem = (item: ListItemValue<KeyValue>, to: number): void => {\n\t\tconst itemRef = this.getItemRefValue(item);\n\t\tif (isRef(itemRef)) {\n\t\t\tthis.addPendingOperations(\n\t\t\t\tthis.patchCreator.createListMoveByRef(this.oid, itemRef, to),\n\t\t\t);\n\t\t} else {\n\t\t\tconst index = this.view.indexOf(item);\n\t\t\tif (index === -1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot move item ${JSON.stringify(\n\t\t\t\t\t\titem,\n\t\t\t\t\t)} which does not exist in this list`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.move(index, to);\n\t\t}\n\t};\n\n\tadd = (value: ListItemValue<KeyValue>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListAdd(\n\t\t\t\tthis.oid,\n\t\t\t\tthis.processInputValue(value, this.view.length),\n\t\t\t),\n\t\t);\n\t};\n\n\tremoveAll = (item: ListItemValue<KeyValue>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListRemove(this.oid, this.getItemRefValue(item)),\n\t\t);\n\t};\n\n\tremoveFirst = (item: ListItemValue<KeyValue>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListRemove(\n\t\t\t\tthis.oid,\n\t\t\t\tthis.getItemRefValue(item),\n\t\t\t\t'first',\n\t\t\t),\n\t\t);\n\t};\n\n\tremoveLast = (item: ListItemValue<KeyValue>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListRemove(\n\t\t\t\tthis.oid,\n\t\t\t\tthis.getItemRefValue(item),\n\t\t\t\t'last',\n\t\t\t),\n\t\t);\n\t};\n\n\t// list implements an iterator which maps items to wrapped\n\t// versions\n\t[Symbol.iterator]() {\n\t\tlet index = 0;\n\t\tlet length = this.view?.length;\n\t\treturn {\n\t\t\tnext: () => {\n\t\t\t\tif (index < length) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: this.get(index++) as ListItemValue<KeyValue>,\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t} as const;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tvalue: undefined,\n\t\t\t\t\tdone: true,\n\t\t\t\t} as const;\n\t\t\t},\n\t\t};\n\t}\n\n\tmap = <U>(\n\t\tcallback: (value: ListItemValue<KeyValue>, index: number) => U,\n\t): U[] => {\n\t\treturn this.view.map(callback);\n\t};\n\n\tfilter = (\n\t\tcallback: (value: ListItemValue<KeyValue>, index: number) => boolean,\n\t): ListItemValue<KeyValue>[] => {\n\t\treturn this.view.filter(callback);\n\t};\n\n\thas = (value: ListItemValue<KeyValue>): boolean => {\n\t\tif (!this.isList) {\n\t\t\tthrow new Error('has() is only available on list entities');\n\t\t}\n\t\tconst itemRef = this.getItemRefValue(value);\n\t\tif (isRef(itemRef)) {\n\t\t\treturn this.view.some((item: any) => {\n\t\t\t\tif (isRef(item)) {\n\t\t\t\t\treturn compareRefs(item, itemRef);\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\treturn this.view.includes(value);\n\t\t}\n\t};\n\n\tforEach = (\n\t\tcallback: (value: ListItemValue<KeyValue>, index: number) => void,\n\t): void => {\n\t\tthis.view.forEach(callback);\n\t};\n\n\treduce = <U>(\n\t\tcallback: (\n\t\t\tpreviousValue: U,\n\t\t\tcurrentValue: ListItemValue<KeyValue>,\n\t\t\tindex: number,\n\t\t) => U,\n\t\tinitialValue: U,\n\t): U => {\n\t\treturn this.view.reduce(callback, initialValue);\n\t};\n\n\tsome = (predicate: (value: ListItemValue<KeyValue>) => boolean): boolean => {\n\t\treturn this.view.some(predicate);\n\t};\n\n\tevery = (predicate: (value: ListItemValue<KeyValue>) => boolean): boolean => {\n\t\treturn this.view.every(predicate);\n\t};\n\n\tfind = (\n\t\tpredicate: (value: ListItemValue<KeyValue>) => boolean,\n\t): ListItemValue<KeyValue> | undefined => {\n\t\treturn this.view.find(predicate);\n\t};\n\n\tincludes = this.has;\n\n\t/**\n\t * Deletes this entity. WARNING: this can be tricky to\n\t * use correctly. You must not reference this entity\n\t * instance in any way after the deletion happens, or\n\t * you will get an error!\n\t *\n\t * It's a little easier to delete using client.delete\n\t * if you can manage it with your app's code. For example,\n\t * in React, use hooks.useClient() to get the client and\n\t * call delete from there.\n\t */\n\tdeleteSelf = () => {\n\t\treturn this._deleteSelf();\n\t};\n\n\t// TODO: make these escape hatches unnecessary\n\t__getViewData__ = (oid: ObjectIdentifier, type: 'confirmed' | 'pending') => {\n\t\treturn this.metadataFamily.get(oid).computeView(type === 'confirmed');\n\t};\n\t__getFamilyOids__ = () => this.metadataFamily.getAllOids();\n\n\t__discardPendingOperation__ = (operation: Operation) => {\n\t\tthis.metadataFamily.discardPendingOperation(operation);\n\t\tthis.invalidateCachedView();\n\t};\n}\n\nfunction assertNotSymbol<T>(key: T): asserts key is Exclude<T, symbol> {\n\tif (typeof key === 'symbol') throw new Error(\"Symbol keys aren't supported\");\n}\n\nfunction assertNumber(key: unknown): asserts key is number {\n\tif (typeof key !== 'number')\n\t\tthrow new Error('Only number keys are supported in list entities');\n}\n", "import {\n\tDocumentBaseline,\n\tObjectIdentifier,\n\tOperation,\n\tapplyPatch,\n\tareOidsRelated,\n\tassert,\n\tassignOid,\n\tcloneDeep,\n\tcompareTimestampSchemaVersions,\n\tgetWallClockTime,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { EntityChange } from './types.js';\n\nexport type EntityMetadataView = {\n\tview: any;\n\tfromOlderVersion: boolean;\n\tdeleted: boolean;\n\tempty: boolean;\n\tupdatedAt: number;\n\tlatestTimestamp: string | null;\n\tauthz?: string;\n};\n\nexport class EntityMetadata {\n\tprivate ctx;\n\tprivate baseline: DocumentBaseline | null = null;\n\t// these must be kept in timestamp order.\n\tprivate confirmedOperations: Operation[] = [];\n\tprivate pendingOperations: Operation[] = [];\n\treadonly oid;\n\n\tconstructor({\n\t\toid,\n\t\tctx,\n\t\tconfirmedOperations,\n\t\tpendingOperations,\n\t\tbaseline,\n\t}: {\n\t\toid: ObjectIdentifier;\n\t\tctx: Context;\n\t\tconfirmedOperations?: Operation[];\n\t\tpendingOperations?: Operation[];\n\t\tbaseline?: DocumentBaseline;\n\t}) {\n\t\tassert(oid, 'oid is required');\n\t\tthis.ctx = ctx;\n\t\tthis.oid = oid;\n\t\tif (confirmedOperations) {\n\t\t\tthis.confirmedOperations = confirmedOperations;\n\t\t}\n\t\tif (pendingOperations) {\n\t\t\tthis.pendingOperations = pendingOperations;\n\t\t}\n\t\tif (baseline) {\n\t\t\tthis.baseline = baseline;\n\t\t}\n\t}\n\n\t/**\n\t * Compute the current view of the entity.\n\t */\n\tcomputeView = (omitPending = false): EntityMetadataView => {\n\t\tconst base = cloneDeep(this.baseline?.snapshot ?? undefined);\n\t\tconst baselineTimestamp = this.baseline?.timestamp ?? null;\n\n\t\t// start with the baseline authz, if any. further init ops\n\t\t// may overwrite this.\n\t\tlet authz = this.baseline?.authz;\n\n\t\tconst confirmedResult = this.applyOperations(\n\t\t\t// apply ops to baseline\n\t\t\tbase,\n\t\t\t// deleted if there's no baseline\n\t\t\t!base,\n\t\t\t// we're applying confirmed ops first\n\t\t\tthis.confirmedOperations,\n\t\t\t// latest timestamp is the baseline timestamp, if any\n\t\t\tbaselineTimestamp,\n\t\t\t// only apply ops after the baseline timestamp\n\t\t\tbaselineTimestamp,\n\t\t);\n\t\t// now's the time to declare we saw the future if we did.\n\t\tif (confirmedResult.futureSeen) {\n\t\t\tthis.ctx.globalEvents.emit('futureSeen', confirmedResult.futureSeen);\n\t\t}\n\t\tif (confirmedResult.authz) {\n\t\t\tauthz = confirmedResult.authz;\n\t\t}\n\n\t\tconst pendingResult = omitPending\n\t\t\t? confirmedResult\n\t\t\t: this.applyOperations(\n\t\t\t\t\tconfirmedResult.view,\n\t\t\t\t\tconfirmedResult.deleted,\n\t\t\t\t\t// now we're applying pending operations\n\t\t\t\t\tthis.pendingOperations,\n\t\t\t\t\t// keep our latest timestamp up to date\n\t\t\t\t\tconfirmedResult.latestTimestamp,\n\t\t\t\t\t// we don't use after for pending ops, they're all\n\t\t\t\t\t// logically in the future\n\t\t\t\t\tnull,\n\t\t\t );\n\t\tif (pendingResult.authz) {\n\t\t\tauthz = pendingResult.authz;\n\t\t}\n\n\t\t// before letting this data out into the wild, we need\n\t\t// to associate its oid\n\t\tif (pendingResult.view) {\n\t\t\tassignOid(pendingResult.view, this.oid);\n\t\t}\n\n\t\t// note whether confirmed data has an operation/baseline from the current\n\t\t// schema or not.\n\t\tconst fromOlderVersion =\n\t\t\t!!confirmedResult.latestTimestamp &&\n\t\t\tcompareTimestampSchemaVersions(\n\t\t\t\tconfirmedResult.latestTimestamp,\n\t\t\t\tthis.ctx.getNow(),\n\t\t\t) < 0;\n\n\t\tconst empty =\n\t\t\t!this.baseline &&\n\t\t\t!this.pendingOperations.length &&\n\t\t\t!this.confirmedOperations.length;\n\t\tif (empty) {\n\t\t\tthis.ctx.log('warn', `Tried to load Entity ${this.oid} with no data`);\n\t\t}\n\n\t\tconst updatedAtTimestamp =\n\t\t\tpendingResult.latestTimestamp ??\n\t\t\tconfirmedResult.latestTimestamp ??\n\t\t\tbaselineTimestamp;\n\t\tconst updatedAt = updatedAtTimestamp\n\t\t\t? getWallClockTime(updatedAtTimestamp)\n\t\t\t: 0;\n\n\t\tif (!pendingResult.view && !pendingResult.deleted && !empty) {\n\t\t\tthis.ctx.log(\n\t\t\t\t'warn',\n\t\t\t\t`Entity ${this.oid} has no view, no deleted flag, and not empty`,\n\t\t\t);\n\t\t\tdebugger;\n\t\t}\n\n\t\treturn {\n\t\t\tview: pendingResult.view ?? undefined,\n\t\t\tdeleted: pendingResult.deleted,\n\t\t\tempty,\n\t\t\tfromOlderVersion,\n\t\t\tupdatedAt,\n\t\t\tlatestTimestamp: updatedAtTimestamp,\n\t\t\tauthz,\n\t\t};\n\t};\n\n\taddBaseline = (baseline: DocumentBaseline): void => {\n\t\t// opt out if our baseline is newer\n\t\tif (this.baseline && this.baseline.timestamp >= baseline.timestamp) {\n\t\t\treturn;\n\t\t}\n\t\tthis.baseline = baseline;\n\t\t// we can now drop any confirmed ops older than the baseline\n\t\twhile (this.confirmedOperations[0]?.timestamp < baseline.timestamp) {\n\t\t\tthis.confirmedOperations.shift();\n\t\t}\n\t};\n\n\t/**\n\t * @returns total number of new operations added\n\t */\n\taddConfirmedOperations = (operations: Operation[]): number => {\n\t\tlet totalAdded = 0;\n\t\t// the operations must be inserted in timestamp order\n\t\tfor (const op of operations) {\n\t\t\tconst index = this.confirmedOperations.findIndex(\n\t\t\t\t(o) => o.timestamp >= op.timestamp,\n\t\t\t);\n\t\t\tif (index !== -1) {\n\t\t\t\t// ensure we don't have a duplicate\n\t\t\t\tif (this.confirmedOperations[index].timestamp !== op.timestamp) {\n\t\t\t\t\t// otherwise, insert at the right place\n\t\t\t\t\tthis.confirmedOperations.splice(index, 0, op);\n\t\t\t\t\ttotalAdded++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// otherwise, append\n\t\t\t\tthis.confirmedOperations.push(op);\n\t\t\t\ttotalAdded++;\n\t\t\t}\n\t\t\t// FIXME: seems inefficient\n\t\t\t// remove this incoming op from pending if it's in there\n\t\t\tconst pendingPrior = this.pendingOperations.length;\n\t\t\tthis.discardPendingOperation(op);\n\t\t\ttotalAdded -= pendingPrior - this.pendingOperations.length;\n\t\t}\n\t\treturn totalAdded;\n\t};\n\n\taddPendingOperation = (operation: Operation) => {\n\t\t// check to see if new operation supersedes the previous one\n\t\t// we can assume pending ops are always newer\n\t\tthis.pendingOperations.push(operation);\n\t};\n\n\tdiscardPendingOperation = (operation: Operation) => {\n\t\tthis.pendingOperations = this.pendingOperations.filter(\n\t\t\t(op) => op.timestamp !== operation.timestamp,\n\t\t);\n\t};\n\n\tprivate applyOperations = (\n\t\tbase: any,\n\t\tdeleted: boolean,\n\t\toperations: Operation[],\n\t\tlatestTimestamp: string | null,\n\t\tafter: string | null,\n\t): {\n\t\tview: any;\n\t\tlatestTimestamp: string | null;\n\t\tdeleted: boolean;\n\t\tfutureSeen: string | undefined;\n\t\tauthz?: string;\n\t} => {\n\t\tlet futureSeen: string | undefined = undefined;\n\t\tlet authz: string | undefined = undefined;\n\n\t\tconst now = this.ctx.getNow();\n\t\tfor (const op of operations) {\n\t\t\t// ignore ops before our after cutoff\n\t\t\tif (after && op.timestamp <= after) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// don't apply future ops\n\t\t\tif (compareTimestampSchemaVersions(op.timestamp, now) > 0) {\n\t\t\t\tfutureSeen = op.timestamp;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// we don't actually delete the view when a delete op\n\t\t\t// comes in. the view remains useful for calculating\n\t\t\t// undo operations.\n\t\t\tif (op.data.op === 'delete') {\n\t\t\t\tdeleted = true;\n\t\t\t} else {\n\t\t\t\tbase = applyPatch(base, op.data);\n\t\t\t\tif (op.data.op === 'initialize') {\n\t\t\t\t\tdeleted = false;\n\t\t\t\t\tif (op.authz) {\n\t\t\t\t\t\tauthz = op.authz;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// track the latest timestamp\n\t\t\tif (!latestTimestamp || op.timestamp > latestTimestamp) {\n\t\t\t\tlatestTimestamp = op.timestamp;\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tview: base,\n\t\t\tlatestTimestamp: latestTimestamp ?? null,\n\t\t\tdeleted,\n\t\t\tfutureSeen,\n\t\t\tauthz,\n\t\t};\n\t};\n}\n\n/**\n * Represents the metadata for a group of entities underneath a Document.\n * Metadata is separated out this way so that these classes can be\n * garbage collected when the root Document goes out of scope.\n */\nexport class EntityFamilyMetadata {\n\tprivate ctx;\n\tprivate entities: Map<ObjectIdentifier, EntityMetadata> = new Map();\n\tprivate onPendingOperations;\n\tprivate rootOid: ObjectIdentifier;\n\n\tconstructor({\n\t\tctx,\n\t\tonPendingOperations,\n\t\trootOid,\n\t}: {\n\t\tctx: Context;\n\t\tonPendingOperations: (ops: Operation[]) => void;\n\t\trootOid: ObjectIdentifier;\n\t}) {\n\t\tthis.ctx = ctx;\n\t\tthis.rootOid = rootOid;\n\t\tthis.onPendingOperations = onPendingOperations;\n\t}\n\n\tget = (oid: ObjectIdentifier) => {\n\t\tassert(oid, 'oid is required');\n\t\tif (!this.entities.has(oid)) {\n\t\t\tthis.entities.set(oid, new EntityMetadata({ oid, ctx: this.ctx }));\n\t\t}\n\t\treturn this.entities.get(oid)!;\n\t};\n\n\tgetAllOids = () => {\n\t\treturn Array.from(this.entities.keys());\n\t};\n\n\taddConfirmedData = ({\n\t\tbaselines = [],\n\t\toperations = {},\n\t\tisLocal = false,\n\t}: {\n\t\tbaselines?: DocumentBaseline[];\n\t\toperations?: Record<ObjectIdentifier, Operation[]>;\n\t\tisLocal?: boolean;\n\t}) => {\n\t\tconst changes: Record<ObjectIdentifier, EntityChange> = {};\n\t\tfor (const baseline of baselines) {\n\t\t\tif (!areOidsRelated(this.rootOid, baseline.oid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid baseline for entity ${this.rootOid}: ` +\n\t\t\t\t\t\tJSON.stringify(baseline),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.get(baseline.oid).addBaseline(baseline);\n\t\t}\n\t\tfor (const [oid, ops] of Object.entries(operations)) {\n\t\t\tif (!areOidsRelated(this.rootOid, oid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid operations for entity ${this.rootOid}: ` +\n\t\t\t\t\t\tJSON.stringify(ops),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst added = this.get(oid).addConfirmedOperations(ops);\n\t\t\tif (added !== 0) {\n\t\t\t\tchanges[oid] ??= { oid, isLocal };\n\t\t\t}\n\t\t}\n\t\treturn Object.values(changes);\n\t};\n\n\t/**\n\t * Adds local, unconfirmed operations to the system.\n\t * The API is different here to streamline for the way\n\t * local changes are usually handled, as a list.\n\t */\n\taddPendingData = (operations: Operation[]) => {\n\t\tconst changes: Record<ObjectIdentifier, EntityChange> = {};\n\t\tfor (const op of operations) {\n\t\t\tthis.get(op.oid).addPendingOperation(op);\n\t\t\tchanges[op.oid] ??= { oid: op.oid, isLocal: true };\n\t\t}\n\t\tthis.onPendingOperations(operations);\n\t\treturn Object.values(changes);\n\t};\n\n\treplaceAllData = ({\n\t\toperations = {},\n\t\tbaselines = [],\n\t}: {\n\t\toperations?: Record<ObjectIdentifier, Operation[]>;\n\t\tbaselines?: DocumentBaseline[];\n\t}) => {\n\t\tconst oids = Array.from(this.entities.keys());\n\t\tthis.entities.clear();\n\t\tconst changes: Record<ObjectIdentifier, EntityChange> = {};\n\t\t// changes apply to all the entities we removed things from, too\n\t\tfor (const oid of oids) {\n\t\t\tchanges[oid] = { oid, isLocal: false };\n\t\t}\n\t\tfor (const baseline of baselines) {\n\t\t\tif (!areOidsRelated(this.rootOid, baseline.oid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid baseline for entity ${this.rootOid}: ` +\n\t\t\t\t\t\tJSON.stringify(baseline),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.get(baseline.oid).addBaseline(baseline);\n\t\t\tchanges[baseline.oid] ??= { oid: baseline.oid, isLocal: false };\n\t\t}\n\t\tfor (const [oid, ops] of Object.entries(operations)) {\n\t\t\tif (!areOidsRelated(this.rootOid, oid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid operations for entity ${this.rootOid}: ` +\n\t\t\t\t\t\tJSON.stringify(ops),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.get(oid).addConfirmedOperations(ops);\n\t\t\tchanges[oid] ??= { oid, isLocal: false };\n\t\t}\n\t\treturn Object.values(changes);\n\t};\n\n\tdiscardPendingOperation = (operation: Operation) => {\n\t\tconst ent = this.entities.get(operation.oid);\n\t\tent?.discardPendingOperation(operation);\n\t};\n}\n", "import {\n\tBatcher,\n\tObjectIdentifier,\n\tOperation,\n\tPropertyName,\n\tgenerateId,\n\tgetOidRoot,\n\tgetUndoOperations,\n\tgroupPatchesByOid,\n\tisSuperseded,\n\toperationSupersedes,\n} from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Context } from '../context.js';\nimport type { EntityStore } from './EntityStore.js';\nimport { Entity } from './Entity.js';\n\nconst DEFAULT_BATCH_KEY = '@@default';\n\nexport interface OperationBatch {\n\trun: (fn: () => void) => this;\n\t/** @deprecated - use commit() */\n\tflush: () => Promise<void>;\n\tcommit: () => Promise<void>;\n\tdiscard: () => void;\n}\n\nexport class OperationBatcher {\n\tprivate batcher;\n\tprivate currentBatchKey = DEFAULT_BATCH_KEY;\n\tprivate defaultBatchTimeout: number;\n\tprivate meta;\n\tprivate ctx;\n\tprivate entities;\n\n\tconstructor({\n\t\tbatchTimeout = 200,\n\t\tmeta,\n\t\tctx,\n\t\tentities,\n\t}: {\n\t\tbatchTimeout?: number;\n\t\tmeta: Metadata;\n\t\tctx: Context;\n\t\tentities: EntityStore;\n\t}) {\n\t\tthis.meta = meta;\n\t\tthis.ctx = ctx;\n\t\tthis.entities = entities;\n\t\tthis.defaultBatchTimeout = batchTimeout;\n\t\tthis.batcher = new Batcher<Operation, { undoable?: boolean }>(\n\t\t\tthis.flushOperations,\n\t\t);\n\t\tthis.batcher.add({\n\t\t\tkey: DEFAULT_BATCH_KEY,\n\t\t\titems: [],\n\t\t\tmax: 100,\n\t\t\ttimeout: batchTimeout,\n\t\t\tuserData: { undoable: true },\n\t\t});\n\t}\n\n\tget isDefaultBatch() {\n\t\treturn this.currentBatchKey === DEFAULT_BATCH_KEY;\n\t}\n\n\tprivate flushOperations = async (\n\t\toperations: Operation[],\n\t\tbatchKey: string,\n\t\tmeta: { undoable?: boolean },\n\t) => {\n\t\tthis.ctx.log(\n\t\t\t'debug',\n\t\t\t'Flushing',\n\t\t\toperations.length,\n\t\t\t'operations from batch',\n\t\t\tbatchKey,\n\t\t\t'to storage / sync',\n\t\t);\n\t\tif (!operations.length) return;\n\n\t\t// next block of logic computes superseding rules to eliminate\n\t\t// operations which are 'overshadowed' by later ones on the same\n\t\t// key.\n\n\t\tconst committed: Operation[] = [];\n\t\tconst supersessions: Record<\n\t\t\tObjectIdentifier,\n\t\t\tSet<boolean | PropertyName>\n\t\t> = {};\n\t\tfor (let i = operations.length - 1; i >= 0; i--) {\n\t\t\tconst op = operations[i];\n\n\t\t\t// check for supersession from later operation which either\n\t\t\t// covers the whole id (true) or this key\n\t\t\tconst existingSupersession = supersessions[op.oid];\n\t\t\tif (existingSupersession && isSuperseded(op, existingSupersession)) {\n\t\t\t\tthis.entities.discardPendingOperation(op);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// determine if this operation supersedes others\n\t\t\tconst supersession = operationSupersedes(op);\n\t\t\tif (supersession !== false) {\n\t\t\t\tif (!supersessions[op.oid]) {\n\t\t\t\t\tsupersessions[op.oid] = new Set<boolean | PropertyName>();\n\t\t\t\t}\n\t\t\t\tsupersessions[op.oid]!.add(supersession);\n\t\t\t}\n\n\t\t\t// add this operation to final list\n\t\t\tcommitted.unshift(op);\n\t\t}\n\n\t\t// rewrite timestamps of all operations to now - this preserves\n\t\t// the linear history of operations which are sent to the server.\n\t\t// even if multiple batches are spun up in parallel and flushed\n\t\t// after delay, the final operations in each one should reflect\n\t\t// when the batch flushed, not when the changes were made.\n\t\t// This also corresponds to user-observed behavior, since unconfirmed\n\t\t// operations are applied universally after confirmed operations locally,\n\t\t// so even operations which were made before a remote operation but\n\t\t// have not been confirmed yet will appear to come after the remote one\n\t\t// despite the provisional timestamp being earlier\n\t\t// NOTE: this MUST be mutating the original operation object! this timestamp\n\t\t// also serves as a unique ID for deduplication later.\n\n\t\t// NOTE: need to rewind back in order to set timestamps correctly.\n\t\t// cannot be done in reversed loop above or timestamps would be\n\t\t// in reverse order.\n\t\tfor (const op of committed) {\n\t\t\top.timestamp = this.meta.now;\n\t\t}\n\t\tawait this.commitOperations(committed, meta);\n\t};\n\n\t/**\n\t * Immediately flushes operations to storage / sync.\n\t * Providing source to second arg skips hydrating related\n\t * Entity from storage, which is useful when that Entity\n\t * isn't in storage (i.e. still creating) or just to speed\n\t * up the commit.\n\t */\n\tcommitOperations = async (\n\t\toperations: Operation[],\n\t\tmeta: { undoable?: boolean; source?: Entity },\n\t) => {\n\t\tif (!operations.length) return;\n\t\t// now is the time to decide on what the undo operations will\n\t\t// look like, based on the confirmed view of the related entities.\n\t\tif (meta.undoable) {\n\t\t\tconst undo = await this.createUndo({\n\t\t\t\tops: operations,\n\t\t\t\tsource: meta.source,\n\t\t\t});\n\t\t\tif (undo) this.ctx.undoHistory.addUndo(undo);\n\t\t}\n\t\t// ship it out to EntityStore to compute final snapshots\n\t\t// write to storage and refresh entities and queries\n\t\tawait this.entities.addData({\n\t\t\toperations,\n\t\t\tbaselines: [],\n\t\t\tisLocal: true,\n\t\t});\n\t};\n\n\t/**\n\t * Adds operations to the active batch.\n\t */\n\taddOperations = (operations: Operation[]) => {\n\t\tif (!operations.length) return;\n\t\tthis.batcher.add({\n\t\t\tkey: this.currentBatchKey,\n\t\t\titems: operations,\n\t\t});\n\t\tthis.ctx.log(\n\t\t\t`debug`,\n\t\t\t'added',\n\t\t\toperations.length,\n\t\t\t'ops to batch',\n\t\t\tthis.currentBatchKey,\n\t\t\t', size = ',\n\t\t\tthis.batcher.getSize(this.currentBatchKey),\n\t\t);\n\t};\n\n\tbatch = ({\n\t\tundoable = true,\n\t\tbatchName = generateId(),\n\t\tmax = null,\n\t\ttimeout = this.defaultBatchTimeout,\n\t}: {\n\t\t/** Allows turning off undo for this batch, making it 'permanent' */\n\t\tundoable?: boolean;\n\t\t/**\n\t\t * Provide a stable name to any invocation of .batch() and the changes made\n\t\t * within run() will all be added to the same batch. If a batch hits the max\n\t\t * limit or timeout and is flushed, the name will be reused for a new batch\n\t\t * automatically. Provide a stable name to make changes from anywhere in your\n\t\t * app to be grouped together in the same batch with the same limit behavior.\n\t\t *\n\t\t * Limit configuration provided to each invocation of .batch() with the same\n\t\t * name will overwrite any other invocation's limit configuration. It's\n\t\t * recommended to provide limits in one place and only provide a name\n\t\t * in others.\n\t\t */\n\t\tbatchName?: string;\n\t\t/**\n\t\t * The maximum number of operations the batch will hold before flushing\n\t\t * automatically. If null, the batch will not flush automatically based\n\t\t * on operation count.\n\t\t */\n\t\tmax?: number | null;\n\t\t/**\n\t\t * The number of milliseconds to wait before flushing the batch automatically.\n\t\t * If null, the batch will not flush automatically based on time. It is not\n\t\t * recommended to set this to null, as an unflushed batch will never be written\n\t\t * to storage or sync. If you do require undefined timing in a batch, make sure\n\t\t * to always call .commit() on the batch yourself.\n\t\t */\n\t\ttimeout?: number | null;\n\t} = {}): OperationBatch => {\n\t\tconst internalBatch = this.batcher.add({\n\t\t\tkey: batchName,\n\t\t\tmax,\n\t\t\ttimeout,\n\t\t\titems: [],\n\t\t\tuserData: { undoable },\n\t\t});\n\t\tconst externalApi = {\n\t\t\trun: (fn: () => void) => {\n\t\t\t\t// while the provided function runs, operations are forwarded\n\t\t\t\t// to the new batch instead of default. this relies on the function\n\t\t\t\t// being synchronous.\n\t\t\t\tthis.currentBatchKey = batchName;\n\t\t\t\tfn();\n\t\t\t\tthis.currentBatchKey = DEFAULT_BATCH_KEY;\n\t\t\t\treturn externalApi;\n\t\t\t},\n\t\t\tcommit: async () => {\n\t\t\t\t// before running a batch, the default operations must be flushed\n\t\t\t\t// this better preserves undo history behavior...\n\t\t\t\t// if we left the default batch open while flushing a named batch,\n\t\t\t\t// then the default batch would be flushed after the named batch,\n\t\t\t\t// and the default batch could contain operations both prior and\n\t\t\t\t// after the named batch. this would result in a confusing undo\n\t\t\t\t// history where the first undo might reverse changes before and\n\t\t\t\t// after a set of other changes.\n\t\t\t\tawait this.batcher.flush(DEFAULT_BATCH_KEY);\n\t\t\t\treturn internalBatch.flush();\n\t\t\t},\n\t\t\tflush: () => externalApi.commit(),\n\t\t\tdiscard: () => {\n\t\t\t\tthis.batcher.discard(batchName);\n\t\t\t},\n\t\t};\n\t\treturn externalApi;\n\t};\n\n\tflushAll = () => Promise.all(this.batcher.flushAll());\n\n\tprivate createUndo = async (data: { ops: Operation[]; source?: Entity }) => {\n\t\t// this can't be done on-demand because we rely on the current\n\t\t// state of the entities to calculate the inverse operations.\n\t\tconst inverseOps = await this.getInverseOperations(data);\n\n\t\tif (!inverseOps.length) return null;\n\n\t\treturn async () => {\n\t\t\tconst redo = await this.createUndo({\n\t\t\t\tops: inverseOps,\n\t\t\t\tsource: data.source,\n\t\t\t});\n\t\t\t// set time to now for all undo operations, they're happening now.\n\t\t\tfor (const op of inverseOps) {\n\t\t\t\top.timestamp = this.meta.now;\n\t\t\t}\n\t\t\tawait this.commitOperations(\n\t\t\t\tinverseOps,\n\t\t\t\t// undos should not generate their own undo operations\n\t\t\t\t// since they already calculate redo as the inverse.\n\t\t\t\t{ undoable: false },\n\t\t\t);\n\t\t\treturn redo;\n\t\t};\n\t};\n\tprivate getInverseOperations = async ({\n\t\tops,\n\t\tsource,\n\t}: {\n\t\tops: Operation[];\n\t\tsource?: Entity;\n\t}) => {\n\t\tconst grouped = groupPatchesByOid(ops);\n\t\tconst inverseOps: Operation[] = [];\n\t\tconst getNow = () => this.meta.now;\n\t\tawait Promise.all(\n\t\t\tObject.entries(grouped).map(async ([oid, patches]): Promise<void> => {\n\t\t\t\tconst entity = source ?? (await this.entities.hydrate(getOidRoot(oid)));\n\t\t\t\t// TODO: this is getting the rebased baseline? how? are ops being submitted early?\n\t\t\t\tconst viewData = entity?.__getViewData__(oid, 'confirmed');\n\t\t\t\tif (!viewData) {\n\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t'warn',\n\t\t\t\t\t\t'could not find entity',\n\t\t\t\t\t\toid,\n\t\t\t\t\t\t'for undo operation',\n\t\t\t\t\t\tops,\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst inverse = getUndoOperations(oid, viewData.view, patches, getNow);\n\t\t\t\tinverseOps.unshift(...inverse);\n\t\t\t}),\n\t\t);\n\t\treturn inverseOps;\n\t};\n}\n", "import {\n\tObjectIdentifier,\n\tdecomposeOid,\n\tgetIndexValues,\n} from '@verdant-web/common';\nimport { IDBService } from '../IDBService.js';\nimport { Context } from '../context.js';\nimport { storeRequestPromise } from '../idb.js';\n\nexport class QueryableStorage extends IDBService {\n\tprivate ctx;\n\n\tconstructor({ ctx }: { ctx: Context }) {\n\t\tsuper(ctx.documentDb, { log: ctx.log });\n\t\tthis.ctx = ctx;\n\t\tthis.addDispose(\n\t\t\tthis.ctx.internalEvents.subscribe('documentDbChanged', (db) => {\n\t\t\t\tthis.db = db;\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * DELETES EVERYTHING IN THE QUERYABLE DATABASE\n\t */\n\treset = async () => {\n\t\tconst allCollections = Object.keys(this.ctx.schema.collections);\n\t\tconst tx = this.createTransaction(allCollections, { mode: 'readwrite' });\n\t\tawait Promise.all(\n\t\t\tallCollections.map((collection) => {\n\t\t\t\tconst store = tx.objectStore(collection);\n\t\t\t\treturn storeRequestPromise(store.clear());\n\t\t\t}),\n\t\t);\n\t\t// notify queries to re-run now.\n\t\tthis.ctx.entityEvents.emit('collectionsChanged', allCollections);\n\t\tthis.ctx.log('info', '\uD83D\uDCA8 Reset queryable storage');\n\t};\n\n\tsaveEntities = async (\n\t\tentities: { oid: ObjectIdentifier; getSnapshot: () => any }[],\n\t\topts?: { abort?: AbortSignal },\n\t) => {\n\t\tif (entities.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet collections = Array.from(\n\t\t\tnew Set(entities.map((e) => decomposeOid(e.oid).collection)),\n\t\t);\n\t\t// we could theoretically receive entities from old schema versions which no\n\t\t// longer have collections. We should ignore these. If we don't, the transaction\n\t\t// will fail, because the object store doesn't exist.\n\t\tconst toRemove = collections.filter((c) => !this.ctx.schema.collections[c]);\n\t\tif (toRemove.length > 0) {\n\t\t\tthis.ctx.log(\n\t\t\t\t'warn',\n\t\t\t\t`Ignoring entities from collections that no longer exist: ${toRemove.join(\n\t\t\t\t\t', ',\n\t\t\t\t)}`,\n\t\t\t);\n\t\t\tconst withRemoved = new Set(collections);\n\t\t\ttoRemove.forEach((c) => withRemoved.delete(c));\n\t\t\tcollections = Array.from(withRemoved);\n\t\t}\n\t\tconst options = {\n\t\t\ttransaction: this.createTransaction(collections, {\n\t\t\t\tmode: 'readwrite',\n\t\t\t\tabort: opts?.abort,\n\t\t\t}),\n\t\t};\n\t\tawait Promise.all(\n\t\t\tentities.map(async (e) => {\n\t\t\t\tconst snapshot = e.getSnapshot();\n\t\t\t\ttry {\n\t\t\t\t\tawait this.saveDocument(e.oid, snapshot, options);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t'error',\n\t\t\t\t\t\t`Error saving document ${e.oid} (${JSON.stringify(snapshot)})`,\n\t\t\t\t\t\terr,\n\t\t\t\t\t);\n\t\t\t\t\tif (err instanceof Error) {\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('Unknown error saving document');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\toptions.transaction.commit();\n\t\tthis.ctx.entityEvents.emit('collectionsChanged', collections);\n\t\tfor (const entity of entities) {\n\t\t\tthis.ctx.entityEvents.emit('documentChanged', entity.oid);\n\t\t}\n\t};\n\n\tprivate saveDocument = async (\n\t\toid: ObjectIdentifier,\n\t\tdoc: any,\n\t\t{ transaction }: { transaction?: IDBTransaction },\n\t) => {\n\t\tthis.ctx.log('debug', `Saving document indexes for querying ${oid}`, doc);\n\t\tconst { collection, id } = decomposeOid(oid);\n\t\tif (!doc) {\n\t\t\tawait this.run(collection, (store) => store.delete(id), {\n\t\t\t\tmode: 'readwrite',\n\t\t\t\ttransaction,\n\t\t\t});\n\t\t\tthis.ctx.log('debug', `Deleted document indexes for querying ${oid}`);\n\t\t} else {\n\t\t\tconst schema = this.ctx.schema.collections[collection];\n\t\t\t// no need to validate before storing; the entity's snapshot is already validated.\n\t\t\tconst indexes = getIndexValues(schema, doc);\n\t\t\tawait this.run(collection, (store) => store.put(indexes), {\n\t\t\t\tmode: 'readwrite',\n\t\t\t\ttransaction,\n\t\t\t});\n\t\t\tthis.ctx.log('debug', `Saved document indexes for querying ${oid}`, doc);\n\t\t}\n\t};\n}\n", "import {\n\tDocumentBaseline,\n\tObjectIdentifier,\n\tOperation,\n\tStorageFieldsSchema,\n\tStorageObjectFieldSchema,\n\tassert,\n\tassignOid,\n\tdecomposeOid,\n\tgetOidRoot,\n\tgroupBaselinesByRootOid,\n\tgroupPatchesByOid,\n\tgroupPatchesByRootOid,\n\tisRootOid,\n\tremoveOidsFromAllSubObjects,\n\tAuthorizationKey,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Entity } from './Entity.js';\nimport { Disposable } from '../utils/Disposable.js';\nimport { EntityFamilyMetadata } from './EntityMetadata.js';\nimport { FileManager } from '../files/FileManager.js';\nimport { OperationBatcher } from './OperationBatcher.js';\nimport { QueryableStorage } from '../queries/QueryableStorage.js';\nimport { WeakEvent } from 'weak-event';\nimport { processValueFiles } from '../files/utils.js';\n\nenum AbortReason {\n\tReset,\n}\n\nexport type EntityStoreEventData = {\n\toid: ObjectIdentifier;\n\toperations?: Record<string, Operation[]>;\n\tbaselines?: DocumentBaseline[];\n\tisLocal: boolean;\n};\n\nexport type EntityStoreEvents = {\n\tadd: WeakEvent<EntityStore, EntityStoreEventData>;\n\treplace: WeakEvent<EntityStore, EntityStoreEventData>;\n\tresetAll: WeakEvent<EntityStore, void>;\n};\n\nexport interface IncomingData {\n\toperations?: Operation[];\n\tbaselines?: DocumentBaseline[];\n\treset?: boolean;\n\tisLocal?: boolean;\n}\n\nexport interface EntityCreateOptions {\n\tundoable?: boolean;\n\taccess?: AuthorizationKey;\n}\n\nexport class EntityStore extends Disposable {\n\tprivate ctx;\n\tprivate meta;\n\tprivate files;\n\tprivate batcher;\n\tprivate queryableStorage;\n\tprivate events: EntityStoreEvents = {\n\t\tadd: new WeakEvent(),\n\t\treplace: new WeakEvent(),\n\t\tresetAll: new WeakEvent(),\n\t};\n\tprivate cache = new Map<ObjectIdentifier, WeakRef<Entity>>();\n\tprivate pendingEntityPromises = new Map<\n\t\tObjectIdentifier,\n\t\tPromise<Entity | null>\n\t>();\n\t// halts the current data queue processing\n\tprivate abortDataQueueController = new AbortController();\n\tprivate ongoingResetPromise: Promise<void> | null = null;\n\tprivate entityFinalizationRegistry = new FinalizationRegistry(\n\t\t(oid: ObjectIdentifier) => {\n\t\t\tthis.ctx.log('debug', 'Entity GC', oid);\n\t\t},\n\t);\n\n\tconstructor({\n\t\tctx,\n\t\tmeta,\n\t\tfiles,\n\t}: {\n\t\tctx: Context;\n\t\tmeta: Metadata;\n\t\tfiles: FileManager;\n\t}) {\n\t\tsuper();\n\n\t\tthis.ctx = ctx;\n\t\tthis.meta = meta;\n\t\tthis.files = files;\n\t\tthis.queryableStorage = new QueryableStorage({ ctx });\n\t\tthis.batcher = new OperationBatcher({\n\t\t\tctx,\n\t\t\tmeta,\n\t\t\tentities: this,\n\t\t});\n\t}\n\n\t// expose batch APIs\n\tget batch() {\n\t\treturn this.batcher.batch;\n\t}\n\tget flushAllBatches() {\n\t\treturn this.batcher.flushAll;\n\t}\n\n\t// internal-ish API to load remote / stored data\n\taddData = async (data: IncomingData) => {\n\t\tif (this.disposed) {\n\t\t\tthis.ctx.log('warn', 'EntityStore is disposed, not adding incoming data');\n\t\t\treturn;\n\t\t}\n\t\t// for resets - abort any other changes, reset everything,\n\t\t// then proceed\n\t\tif (data.reset) {\n\t\t\tthis.ctx.log(\n\t\t\t\t'info',\n\t\t\t\t'Resetting local store to replicate remote synced data - dropping any current transactions',\n\t\t\t);\n\t\t\t// cancel any other ongoing data - it will all\n\t\t\t// be replaced by the reset\n\t\t\tthis.abortDataQueueController.abort(AbortReason.Reset);\n\t\t\tthis.abortDataQueueController = new AbortController();\n\t\t\tthis.ongoingResetPromise = this.resetData().finally(() => {\n\t\t\t\tthis.ongoingResetPromise = null;\n\t\t\t\tthis.ctx.globalEvents.emit('resetToServer');\n\t\t\t});\n\t\t}\n\n\t\t// await either the reset we just started, or any that was\n\t\t// in progress when this data came in.\n\t\tif (this.ongoingResetPromise) {\n\t\t\tthis.ctx.log('debug', 'Waiting for ongoing reset to complete');\n\t\t\tawait this.ongoingResetPromise;\n\t\t\tthis.ctx.log('debug', 'Ongoing reset complete');\n\t\t}\n\n\t\tawait this.processData(data);\n\t};\n\n\tempty = async () => {\n\t\tawait this.queryableStorage.reset();\n\t\tthis.events.resetAll.invoke(this);\n\t\tthis.cache.clear();\n\t};\n\n\tprivate resetData = async () => {\n\t\tif (this.disposed) {\n\t\t\tthis.ctx.log('warn', 'EntityStore is disposed, not resetting local data');\n\t\t\treturn;\n\t\t}\n\t\tawait this.meta.reset();\n\t\tawait this.queryableStorage.reset();\n\t\tthis.events.resetAll.invoke(this);\n\t};\n\n\tprivate processData = async (data: IncomingData) => {\n\t\tif (this.disposed) {\n\t\t\tthis.ctx.log(\n\t\t\t\t'warn',\n\t\t\t\t'EntityStore is disposed, not processing incoming data',\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst baselines = data?.baselines ?? [];\n\t\tconst operations = data?.operations ?? [];\n\n\t\tthis.ctx.log('debug', 'Processing incoming data', {\n\t\t\toperations: operations.length,\n\t\t\tbaselines: baselines.length,\n\t\t\treset: !!data.reset,\n\t\t});\n\n\t\tconst allDocumentOids: ObjectIdentifier[] = Array.from(\n\t\t\tnew Set(\n\t\t\t\tbaselines\n\t\t\t\t\t.map((b) => getOidRoot(b.oid))\n\t\t\t\t\t.concat(operations.map((o) => getOidRoot(o.oid))),\n\t\t\t),\n\t\t);\n\t\tconst baselinesGroupedByOid = groupBaselinesByRootOid(baselines);\n\t\tconst operationsGroupedByOid = groupPatchesByRootOid(operations);\n\n\t\tthis.ctx.log('debug', 'Applying data to live entities');\n\t\t// synchronously add/replace data in any open entities via eventing\n\t\tfor (const oid of allDocumentOids) {\n\t\t\tconst baselines = baselinesGroupedByOid[oid];\n\t\t\tconst operations = operationsGroupedByOid[oid] ?? [];\n\t\t\tconst groupedOperations = groupPatchesByOid(operations);\n\t\t\t// what happens if an entity is being hydrated\n\t\t\t// while this is happening? - we wait for the hydration promise\n\t\t\t// to complete, then invoke the event\n\t\t\tconst event = data.reset ? this.events.replace : this.events.add;\n\t\t\tconst hydrationPromise = this.pendingEntityPromises.get(oid);\n\t\t\tif (hydrationPromise) {\n\t\t\t\thydrationPromise.then(() => {\n\t\t\t\t\tevent.invoke(this, {\n\t\t\t\t\t\toid,\n\t\t\t\t\t\tbaselines,\n\t\t\t\t\t\toperations: groupedOperations,\n\t\t\t\t\t\tisLocal: false,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tevent.invoke(this, {\n\t\t\t\t\toid,\n\t\t\t\t\tbaselines,\n\t\t\t\t\toperations: groupedOperations,\n\t\t\t\t\tisLocal: false,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst abortOptions = {\n\t\t\tabort: this.abortDataQueueController.signal,\n\t\t};\n\n\t\t// then, asynchronously add to the database\n\t\t// this also emits messages to sync\n\t\t// TODO: could messages be sent to sync before storage,\n\t\t// so that realtime is lower latency? What would happen\n\t\t// if the storage failed?\n\t\tawait this.meta.insertData(data, abortOptions);\n\n\t\t// recompute all affected documents for querying\n\t\tconst entities = await Promise.all(\n\t\t\tallDocumentOids.map(async (oid) => {\n\t\t\t\tconst entity = await this.hydrate(oid, abortOptions);\n\t\t\t\t// if the entity is not found, we return a stub that\n\t\t\t\t// indicates it's deleted and should be cleared\n\t\t\t\treturn (\n\t\t\t\t\tentity ?? {\n\t\t\t\t\t\toid,\n\t\t\t\t\t\tgetSnapshot(): any {\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\ttry {\n\t\t\tawait this.queryableStorage.saveEntities(entities, abortOptions);\n\t\t} catch (err) {\n\t\t\tif (this.disposed) {\n\t\t\t\tthis.ctx.log(\n\t\t\t\t\t'warn',\n\t\t\t\t\t'Error saving entities to queryable storage - EntityStore is disposed',\n\t\t\t\t\terr,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthis.ctx.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t'Error saving entities to queryable storage',\n\t\t\t\t\terr,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n\n\t// internal-ish API for creating Entities from OIDs\n\t// when query results come in\n\thydrate = async (\n\t\toid: string,\n\t\topts?: { abort: AbortSignal },\n\t): Promise<Entity | null> => {\n\t\tif (!isRootOid(oid)) {\n\t\t\tthrow new Error('Cannot hydrate non-root entity');\n\t\t}\n\n\t\tif (this.cache.has(oid)) {\n\t\t\tthis.ctx.log('debug', 'Hydrating entity from cache', oid);\n\t\t\tconst cached = this.cache.get(oid);\n\t\t\tif (cached) {\n\t\t\t\tconst entity = cached.deref();\n\t\t\t\tif (entity) {\n\t\t\t\t\tif (entity.deleted) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\treturn entity;\n\t\t\t\t} else {\n\t\t\t\t\tthis.ctx.log('debug', \"Removing GC'd entity from cache\", oid);\n\t\t\t\t\tthis.cache.delete(oid);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// we don't want to hydrate two entities in parallel, so\n\t\t// we use a promise to ensure that only one is ever\n\t\t// constructed at a time\n\t\tconst pendingPromise = this.pendingEntityPromises.get(oid);\n\t\tif (!pendingPromise) {\n\t\t\tthis.ctx.log('debug', 'Hydrating entity from storage', oid);\n\t\t\tconst entity = this.constructEntity(oid);\n\t\t\tif (!entity) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst pendingPromise = this.loadEntity(entity, opts);\n\t\t\tpendingPromise.finally(() => {\n\t\t\t\tthis.pendingEntityPromises.delete(oid);\n\t\t\t});\n\t\t\tthis.pendingEntityPromises.set(oid, pendingPromise);\n\t\t\treturn pendingPromise;\n\t\t} else {\n\t\t\tthis.ctx.log('debug', 'Waiting for entity hydration', oid);\n\t\t\treturn pendingPromise;\n\t\t}\n\t};\n\n\tdestroy = async () => {\n\t\tthis.dispose();\n\t\tawait this.batcher.flushAll();\n\t};\n\n\t// public APIs for manipulating entities\n\n\t/**\n\t * Creates a new Entity with the given initial data.\n\t */\n\tcreate = async (\n\t\tinitial: any,\n\t\toid: ObjectIdentifier,\n\t\t{ undoable = true, access }: EntityCreateOptions = {},\n\t) => {\n\t\tthis.ctx.log('debug', 'Creating new entity', oid);\n\t\tconst { collection } = decomposeOid(oid);\n\t\t// remove any OID associations from the initial data\n\t\tremoveOidsFromAllSubObjects(initial);\n\t\t// grab files and replace them with refs\n\t\tconst processed = processValueFiles(initial, this.files.add);\n\n\t\tassignOid(processed, oid);\n\n\t\t// creating a new Entity with no data, then preloading the operations\n\t\tconst entity = this.constructEntity(oid);\n\t\tif (!entity) {\n\t\t\tthrow new Error(\n\t\t\t\t`Could not put new document: no schema exists for collection ${collection}`,\n\t\t\t);\n\t\t}\n\n\t\tconst operations = this.meta.patchCreator.createInitialize(processed, oid);\n\t\tif (access) {\n\t\t\toperations.forEach((op) => {\n\t\t\t\top.authz = access;\n\t\t\t});\n\t\t}\n\t\tawait this.batcher.commitOperations(operations, {\n\t\t\tundoable: !!undoable,\n\t\t\tsource: entity,\n\t\t});\n\n\t\t// TODONE: what happens if you create an entity with an OID that already\n\t\t// exists?\n\t\t// A: it will overwrite the existing entity\n\n\t\t// we still need to synchronously add the initial operations to the Entity\n\t\t// even though they are flowing through the system\n\t\t// FIXME: this could be better aligned to avoid grouping here\n\t\tconst operationsGroupedByOid = groupPatchesByOid(operations);\n\t\tthis.events.add.invoke(this, {\n\t\t\toperations: operationsGroupedByOid,\n\t\t\tisLocal: true,\n\t\t\toid,\n\t\t});\n\t\tthis.cache.set(oid, this.ctx.weakRef(entity));\n\n\t\treturn entity;\n\t};\n\n\tdeleteAll = async (\n\t\toids: ObjectIdentifier[],\n\t\toptions?: { undoable?: boolean },\n\t) => {\n\t\tthis.ctx.log('info', 'Deleting documents', oids);\n\t\tassert(\n\t\t\toids.every((oid) => oid === getOidRoot(oid)),\n\t\t\t'Only root documents may be deleted via client methods',\n\t\t);\n\n\t\tconst entities = await Promise.all(oids.map((oid) => this.hydrate(oid)));\n\n\t\t// remove the entities from cache\n\t\toids.forEach((oid) => {\n\t\t\tthis.cache.delete(oid);\n\t\t\tthis.ctx.log('debug', 'Deleted document from cache', oid);\n\t\t});\n\n\t\tconst operations: Operation[] = [];\n\t\tfor (const entity of entities) {\n\t\t\tif (entity) {\n\t\t\t\tconst oids = entity.__getFamilyOids__();\n\t\t\t\tconst deletes = this.meta.patchCreator.createDeleteAll(oids);\n\t\t\t\tfor (const op of deletes) {\n\t\t\t\t\top.authz = entity.access;\n\t\t\t\t}\n\t\t\t\toperations.push(...deletes);\n\t\t\t}\n\t\t}\n\n\t\tawait this.batcher.commitOperations(operations, {\n\t\t\tundoable: options?.undoable === undefined ? true : options.undoable,\n\t\t});\n\t};\n\n\tdelete = async (oid: ObjectIdentifier, options?: { undoable?: boolean }) => {\n\t\treturn this.deleteAll([oid], options);\n\t};\n\n\tprivate getCollectionSchema = (\n\t\tcollectionName: string,\n\t): {\n\t\tschema: StorageObjectFieldSchema<any> | null;\n\t\treadonlyKeys: string[];\n\t} => {\n\t\tconst schema = this.ctx.schema.collections[collectionName];\n\t\tif (!schema) {\n\t\t\tthis.ctx.log('warn', `Missing schema for collection: ${collectionName}`);\n\t\t\treturn {\n\t\t\t\tschema: null,\n\t\t\t\treadonlyKeys: [],\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t// convert to object schema for compatibility\n\t\t\tschema: {\n\t\t\t\ttype: 'object',\n\t\t\t\tnullable: false,\n\t\t\t\tproperties: schema.fields as any,\n\t\t\t},\n\t\t\treadonlyKeys: [schema.primaryKey],\n\t\t};\n\t};\n\n\t/**\n\t * Constructs an entity from an OID, but does not load it.\n\t */\n\tprivate constructEntity = (oid: string): Entity | null => {\n\t\tconst { collection } = decomposeOid(oid);\n\t\tconst { schema, readonlyKeys } = this.getCollectionSchema(collection);\n\n\t\tif (!schema) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tthrow new Error('Cannot hydrate entity after store has been disposed');\n\t\t}\n\n\t\tconst metadataFamily = new EntityFamilyMetadata({\n\t\t\tctx: this.ctx,\n\t\t\tonPendingOperations: this.onPendingOperations,\n\t\t\trootOid: oid,\n\t\t});\n\n\t\t// this is created synchronously so it's immediately available\n\t\t// to begin capturing incoming data.\n\t\treturn new Entity({\n\t\t\tctx: this.ctx,\n\t\t\toid,\n\t\t\tschema,\n\t\t\treadonlyKeys,\n\t\t\tfiles: this.files,\n\t\t\tmetadataFamily: metadataFamily,\n\t\t\tpatchCreator: this.meta.patchCreator,\n\t\t\tstoreEvents: this.events,\n\t\t\tdeleteSelf: this.delete.bind(this, oid),\n\t\t});\n\t};\n\n\tprivate onPendingOperations = (operations: Operation[]) => {\n\t\tthis.batcher.addOperations(operations);\n\t};\n\n\tdiscardPendingOperation = (operation: Operation) => {\n\t\tconst root = getOidRoot(operation.oid);\n\t\tthis.cache.get(root)?.deref()?.__discardPendingOperation__(operation);\n\t};\n\n\t/**\n\t * Loads initial Entity data from storage\n\t */\n\tprivate loadEntity = async (\n\t\tentity: Entity,\n\t\topts?: { abort: AbortSignal },\n\t): Promise<Entity | null> => {\n\t\tawait this.loadEntityData(entity, opts);\n\n\t\t// only set the cache after loading.\n\t\t// TODO: is this cache/promise stuff redundant?\n\t\tthis.cache.set(entity.oid, this.ctx.weakRef(entity));\n\t\tthis.entityFinalizationRegistry.register(entity, entity.oid);\n\n\t\treturn entity;\n\t};\n\n\tprivate loadEntityData = async (\n\t\tentity: Entity,\n\t\topts?: { abort: AbortSignal },\n\t) => {\n\t\tconst { operations, baselines } = await this.meta.getDocumentData(\n\t\t\tentity.oid,\n\t\t\topts,\n\t\t);\n\n\t\tif (!baselines.length && !Object.keys(operations).length) {\n\t\t\tthis.ctx.log('debug', 'No data found for entity', entity.oid);\n\t\t\treturn null;\n\t\t}\n\n\t\tthis.ctx.log('debug', 'Loaded entity from storage', entity.oid);\n\n\t\tthis.events.replace.invoke(this, {\n\t\t\toid: entity.oid,\n\t\t\tbaselines,\n\t\t\toperations,\n\t\t\tisLocal: false,\n\t\t});\n\n\t\treturn entity;\n\t};\n\n\t/**\n\t * Drops all entities from the cache. Any entities\n\t * referenced will go 'dead'...\n\t */\n\tclearCache = () => {\n\t\tthis.cache.clear();\n\t};\n}\n", "import { FileData } from '@verdant-web/common';\nimport { IDBService } from '../IDBService.js';\nimport { fileToArrayBuffer } from './utils.js';\nimport { getAllFromObjectStores, getSizeOfObjectStore } from '../idb.js';\n\n/**\n * When stored in IDB, replace the file blob with an array buffer\n * since it's more compatible, and replace remote boolean with\n * a string since IDB doesn't support boolean indexes.\n */\nexport interface StoredFileData extends Omit<FileData, 'remote' | 'file'> {\n\tremote: 'true' | 'false';\n\tbuffer?: ArrayBuffer;\n\tdeletedAt: number | null;\n\ttimestamp?: string;\n}\n\nexport interface ReturnedFileData extends FileData {\n\tdeletedAt: number | null;\n}\n\nexport class FileStorage extends IDBService {\n\taddFile = async (\n\t\tfile: FileData,\n\t\t{\n\t\t\ttransaction,\n\t\t\tdownloadRemote = false,\n\t\t}: { transaction?: IDBTransaction; downloadRemote?: boolean } = {},\n\t) => {\n\t\tlet buffer = file.file ? await fileToArrayBuffer(file.file) : undefined;\n\t\tif (!buffer && downloadRemote && file.url) {\n\t\t\ttry {\n\t\t\t\tbuffer = await fetch(file.url, {\n\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\tcredentials: 'include',\n\t\t\t\t}).then((r) => r.arrayBuffer());\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"Failed to download file to cache it locally. The file will still be available using its URL. Check the file server's CORS configuration.\",\n\t\t\t\t\terr,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn this.run(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.put({\n\t\t\t\t\tid: file.id,\n\t\t\t\t\t// IDB doesn't support boolean indexes\n\t\t\t\t\tremote: file.remote ? 'true' : 'false',\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\tname: file.name,\n\t\t\t\t\ttype: file.type,\n\t\t\t\t\turl: file.url,\n\t\t\t\t\tbuffer,\n\t\t\t\t} as StoredFileData);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\tprivate hydrateFileData = (raw: StoredFileData): ReturnedFileData => {\n\t\t(raw as any).remote = raw.remote === 'true';\n\t\tconst buffer = raw.buffer;\n\t\tdelete raw.buffer;\n\t\t(raw as unknown as FileData).file = buffer\n\t\t\t? arrayBufferToBlob(buffer, raw.type)\n\t\t\t: undefined;\n\t\treturn raw as unknown as ReturnedFileData;\n\t};\n\n\tmarkUploaded = async (\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tconst current = await this.getFileRaw(id, { transaction });\n\n\t\tif (!current) {\n\t\t\tthrow new Error('File is not in local database');\n\t\t}\n\n\t\treturn this.run(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.put({\n\t\t\t\t\t...current,\n\t\t\t\t\tremote: 'true',\n\t\t\t\t} as StoredFileData);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\tprivate getFileRaw = async (\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t): Promise<StoredFileData | undefined> => {\n\t\tconst raw = await this.run<StoredFileData>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.get(id);\n\t\t\t},\n\t\t\t{ mode: 'readonly', transaction },\n\t\t);\n\t\tif (!raw) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn raw;\n\t};\n\n\tgetFile = async (\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t): Promise<ReturnedFileData | undefined> => {\n\t\tconst raw = await this.getFileRaw(id, { transaction });\n\t\tif (!raw) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.hydrateFileData(raw);\n\t};\n\n\tdeleteFile(\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) {\n\t\treturn this.run<undefined>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.delete(id);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t}\n\n\tmarkPendingDelete = async (\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tconst current = await this.getFileRaw(id, { transaction });\n\n\t\tif (!current) {\n\t\t\tthrow new Error('File is not in local database');\n\t\t}\n\n\t\treturn this.run(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.put({\n\t\t\t\t\t...current,\n\t\t\t\t\tdeletedAt: Date.now(),\n\t\t\t\t} as StoredFileData);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\tlistUnsynced = async () => {\n\t\tconst raw = await this.run<StoredFileData[]>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.index('remote').getAll('false');\n\t\t\t},\n\t\t\t{ mode: 'readonly' },\n\t\t);\n\t\treturn raw.map(this.hydrateFileData);\n\t};\n\n\tresetSyncedStatusSince = async (since: string | null) => {\n\t\tconst tx = this.createTransaction(['files'], { mode: 'readwrite' });\n\t\tconst raw = await this.run<StoredFileData[]>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.index('remote').getAll('true');\n\t\t\t},\n\t\t\t{ transaction: tx },\n\t\t);\n\n\t\tconst filtered = raw.filter(\n\t\t\t(file) => !file.timestamp || !since || file.timestamp > since,\n\t\t);\n\n\t\tawait Promise.all(\n\t\t\tfiltered.map((file) => {\n\t\t\t\treturn this.run(\n\t\t\t\t\t'files',\n\t\t\t\t\t(store) => {\n\t\t\t\t\t\treturn store.put({\n\t\t\t\t\t\t\t...file,\n\t\t\t\t\t\t\tremote: 'false',\n\t\t\t\t\t\t} as StoredFileData);\n\t\t\t\t\t},\n\t\t\t\t\t{ transaction: tx },\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t};\n\n\titerateOverPendingDelete = (\n\t\titerator: (file: ReturnedFileData, store: IDBObjectStore) => void,\n\t\ttransaction?: IDBTransaction,\n\t) => {\n\t\treturn this.iterate<StoredFileData>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store\n\t\t\t\t\t.index('deletedAt')\n\t\t\t\t\t.openCursor(IDBKeyRange.lowerBound(0, true));\n\t\t\t},\n\t\t\t(value, store) => {\n\t\t\t\titerator(this.hydrateFileData(value), store);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\tgetAll = async () => {\n\t\tconst [files] = await getAllFromObjectStores(this.db, ['files']);\n\t\treturn files.map(this.hydrateFileData);\n\t};\n\n\tstats = async () => {\n\t\treturn {\n\t\t\tsize: await getSizeOfObjectStore(this.db, 'files'),\n\t\t};\n\t};\n}\n\nexport function arrayBufferToBlob(buffer: ArrayBuffer, type: string) {\n\treturn new Blob([buffer], { type });\n}\n", "import { FileData, FileRef } from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Sync } from '../sync/Sync.js';\nimport {\n\tEntityFile,\n\tMARK_FAILED,\n\tMARK_UPLOADED,\n\tUPDATE,\n} from './EntityFile.js';\nimport {\n\tFileStorage,\n\tReturnedFileData,\n\tStoredFileData,\n} from './FileStorage.js';\n\n/**\n * Default: if file was deleted > 3 days ago\n */\nfunction defaultCanCleanup(fileData: ReturnedFileData) {\n\treturn (\n\t\tfileData.deletedAt !== null &&\n\t\tfileData.deletedAt < Date.now() - 1000 * 60 * 24 * 3\n\t);\n}\n\nexport interface FileManagerConfig {\n\t/**\n\t * Override the heuristic for deciding when a deleted file can be cleaned up.\n\t * By default this waits 3 days since deletion, then deletes the file data.\n\t * If the file has been synchronized to a server, it could still be restored\n\t * if the server has not yet deleted it.\n\t */\n\tcanCleanupDeletedFile?: (file: ReturnedFileData) => boolean;\n}\n\nexport class FileManager {\n\tprivate storage;\n\tprivate sync;\n\tprivate context;\n\n\tprivate files = new Map<string, EntityFile>();\n\tprivate config: Required<FileManagerConfig>;\n\tprivate meta: Metadata;\n\n\tprivate maxUploadRetries = 3;\n\tprivate maxDownloadRetries = 3;\n\n\tconstructor({\n\t\tdb,\n\t\tsync,\n\t\tcontext,\n\t\tmeta,\n\t\tconfig = {},\n\t}: {\n\t\tdb: IDBDatabase;\n\t\tsync: Sync;\n\t\tcontext: Context;\n\t\tconfig?: FileManagerConfig;\n\t\tmeta: Metadata;\n\t}) {\n\t\tthis.storage = new FileStorage(db);\n\t\tthis.sync = sync;\n\t\tthis.context = context;\n\t\tthis.meta = meta;\n\t\tthis.config = {\n\t\t\tcanCleanupDeletedFile: defaultCanCleanup,\n\t\t\t...config,\n\t\t};\n\n\t\tthis.sync.subscribe('onlineChange', this.onOnlineChange);\n\t\tthis.meta.subscribe('filesDeleted', this.handleFileRefsDeleted);\n\t\tthis.sync.subscribe('serverReset', this.storage.resetSyncedStatusSince);\n\t\t// check on startup to see if files can be cleaned up\n\t\tthis.tryCleanupDeletedFiles();\n\t}\n\n\tadd = async (file: FileData) => {\n\t\t// this method accepts a FileData which refers to a remote\n\t\t// file, as well as local files. in the case of a remote file,\n\t\t// we actually re-download and upload the file again. this powers\n\t\t// the cloning of documents with files; we clone their filedata\n\t\t// and re-upload to a new file ID. otherwise, when the cloned\n\t\t// filedata was marked deleted, the original file would be deleted\n\t\t// and the clone would refer to a missing file.\n\t\tif (file.url && !file.file) {\n\t\t\tconst blob = await this.downloadRemoteFile(file.url);\n\t\t\t// convert blob to file with name and type\n\t\t\tfile.file = new File([blob], file.name, { type: file.type });\n\t\t}\n\n\t\tfile.remote = false;\n\t\t// immediately cache the file\n\t\tif (!this.files.has(file.id)) {\n\t\t\tconst entityFile = new EntityFile(file.id);\n\t\t\tentityFile[UPDATE](file);\n\t\t\tthis.files.set(file.id, entityFile);\n\t\t} else {\n\t\t\tthis.files.get(file.id);\n\t\t}\n\t\t// write to local storage and send to sync immediately\n\t\tawait this.storage.addFile(file);\n\t\t// send to sync\n\t\tif (file.file && this.sync.status === 'active') {\n\t\t\tawait this.uploadFile(file);\n\t\t}\n\t};\n\n\tprivate uploadFile = async (file: FileData, retries = 0) => {\n\t\tconst result = await this.sync.uploadFile(file);\n\t\tif (result.success) {\n\t\t\tawait this.storage.markUploaded(file.id);\n\t\t\tconst cached = this.files.get(file.id);\n\t\t\tif (cached) {\n\t\t\t\tcached[MARK_UPLOADED]();\n\t\t\t}\n\t\t\tthis.context.log('info', 'File uploaded', file.id);\n\t\t} else {\n\t\t\tif (result.retry && retries < this.maxUploadRetries) {\n\t\t\t\tthis.context.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`Error uploading file ${file.id}, retrying...`,\n\t\t\t\t\tresult.error,\n\t\t\t\t);\n\t\t\t\t// schedule a retry\n\t\t\t\tsetTimeout(this.uploadFile, 1000, file, retries + 1);\n\t\t\t} else {\n\t\t\t\tthis.context.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`Failed to upload file ${file.id}. Not retrying until next sync.`,\n\t\t\t\t\tresult.error,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate downloadRemoteFile = async (\n\t\turl: string,\n\t\tretries = 0,\n\t): Promise<Blob> => {\n\t\tconst resp = await fetch(url, {\n\t\t\tmethod: 'GET',\n\t\t\tcredentials: 'include',\n\t\t});\n\t\tif (!resp.ok) {\n\t\t\tif (retries < this.maxDownloadRetries) {\n\t\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis.downloadRemoteFile(url, retries + 1).then(resolve, reject);\n\t\t\t\t\t}, 1000);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Failed to download file: ${resp.status}`);\n\t\t\t}\n\t\t}\n\t\tconst blob = await resp.blob();\n\t\treturn blob;\n\t};\n\n\t/**\n\t * Immediately returns an EntityFile to use, then either loads\n\t * the file from cache, local database, or the server.\n\t */\n\tget = (id: string, options?: { downloadRemote?: boolean }) => {\n\t\tif (this.files.has(id)) {\n\t\t\treturn this.files.get(id)!;\n\t\t}\n\t\tconst file = new EntityFile(id, options);\n\t\tthis.files.set(id, file);\n\t\tthis.load(file);\n\t\treturn file;\n\t};\n\n\tprivate load = async (file: EntityFile, retries = 0) => {\n\t\tif (retries > this.maxDownloadRetries) {\n\t\t\tthis.context.log('error', 'Failed to load file after 5 retries');\n\t\t\tfile[MARK_FAILED]();\n\t\t\treturn;\n\t\t}\n\n\t\tconst fileData = await this.storage.getFile(file.id);\n\t\tif (fileData) {\n\t\t\tfile[UPDATE](fileData);\n\t\t} else {\n\t\t\t// maybe we don't have it yet, it might be on the server still.\n\t\t\ttry {\n\t\t\t\tconst result = await this.sync.getFile(file.id);\n\t\t\t\tif (result.success) {\n\t\t\t\t\tfile[UPDATE](result.data);\n\t\t\t\t\tawait this.storage.addFile(result.data, {\n\t\t\t\t\t\tdownloadRemote: file.downloadRemote,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tthis.context.log('error', 'Failed to load file', result);\n\t\t\t\t\tfile[MARK_FAILED]();\n\t\t\t\t\tif (result.retry) {\n\t\t\t\t\t\t// schedule a retry\n\t\t\t\t\t\tsetTimeout(this.load, 1000, file, retries + 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tthis.context.log('error', 'Failed to load file', err);\n\t\t\t\tfile[MARK_FAILED]();\n\t\t\t\t// schedule a retry\n\t\t\t\tsetTimeout(this.load, 1000, file, retries + 1);\n\t\t\t}\n\t\t}\n\t};\n\n\tlistUnsynced = async () => {\n\t\treturn this.storage.listUnsynced();\n\t};\n\n\texportAll = async (downloadRemote = false) => {\n\t\tconst storedFiles = await this.storage.getAll();\n\t\tif (downloadRemote) {\n\t\t\tfor (const storedFile of storedFiles) {\n\t\t\t\t// if it doesn't have a buffer, we need to read\n\t\t\t\t// one from the server\n\t\t\t\tif (!storedFile.file && storedFile.url) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst blob = await fetch(storedFile.url, {\n\t\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t\t\tcredentials: 'include',\n\t\t\t\t\t\t}).then((r) => r.blob());\n\t\t\t\t\t\tstoredFile.file = blob;\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tthis.context.log(\n\t\t\t\t\t\t\t'error',\n\t\t\t\t\t\t\t\"Failed to download file to cache it locally. The file will still be available using its URL. Check the file server's CORS configuration.\",\n\t\t\t\t\t\t\terr,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn storedFiles;\n\t};\n\n\timportAll = async (files: ReturnedFileData[]) => {\n\t\tawait Promise.all(files.map((file) => this.add(file)));\n\t};\n\n\tprivate onOnlineChange = async (online: boolean) => {\n\t\t// if online, try to upload any unsynced files\n\t\tif (online) {\n\t\t\tconst unsynced = await this.listUnsynced();\n\t\t\tawait Promise.all(unsynced.map(this.uploadFile));\n\t\t}\n\t};\n\n\ttryCleanupDeletedFiles = async () => {\n\t\tlet count = 0;\n\t\tlet skipCount = 0;\n\t\tawait this.storage.iterateOverPendingDelete((fileData, store) => {\n\t\t\tif (this.config.canCleanupDeletedFile(fileData)) {\n\t\t\t\tcount++;\n\t\t\t\tstore.delete(fileData.id);\n\t\t\t} else {\n\t\t\t\tskipCount++;\n\t\t\t}\n\t\t});\n\n\t\tthis.context.log(\n\t\t\t'info',\n\t\t\t`Cleaned up ${count} files, skipped ${skipCount} files`,\n\t\t);\n\t};\n\n\tprivate handleFileRefsDeleted = async (fileRefs: FileRef[]) => {\n\t\tconst tx = this.storage.createTransaction(['files'], { mode: 'readwrite' });\n\t\tawait Promise.all(\n\t\t\tfileRefs.map(async (fileRef) => {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.storage.markPendingDelete(fileRef.id, { transaction: tx });\n\t\t\t\t} catch (err) {\n\t\t\t\t\tthis.context.log('error', 'Failed to mark file for deletion', err);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tthis.context.log(\n\t\t\t'info',\n\t\t\t`Marked ${fileRefs.length} files as pending delete`,\n\t\t);\n\t};\n\n\tclose = () => {\n\t\tthis.storage.dispose();\n\t};\n\n\tstats = () => {\n\t\treturn this.storage.stats();\n\t};\n}\n", "import { Migration } from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { getDatabaseVersion, openDatabase } from './db.js';\nimport { runMigrations } from './migrations.js';\nimport { getMigrationPath } from './paths.js';\nimport { OpenDocumentDbContext } from './types.js';\n\nconst globalIDB =\n\ttypeof window !== 'undefined' ? window.indexedDB : (undefined as any);\n\nexport async function openQueryDatabase({\n\tversion,\n\tindexedDB = globalIDB,\n\tmigrations,\n\tmeta,\n\tcontext,\n}: {\n\tversion: number;\n\tmigrations: Migration<any>[];\n\tindexedDB?: IDBFactory;\n\tmeta: Metadata;\n\tcontext: OpenDocumentDbContext;\n}) {\n\tif (context.schema.wip) {\n\t\tthrow new Error('Cannot open a production client with a WIP schema!');\n\t}\n\n\tconst currentVersion = await getDatabaseVersion(\n\t\tindexedDB,\n\t\tcontext.namespace,\n\t\tversion,\n\t\tcontext.log,\n\t);\n\n\tcontext.log(\n\t\t'debug',\n\t\t'Current database version:',\n\t\tcurrentVersion,\n\t\t'target version:',\n\t\tversion,\n\t);\n\n\tconst toRun = getMigrationPath({\n\t\tcurrentVersion,\n\t\ttargetVersion: version,\n\t\tmigrations,\n\t});\n\n\tif (toRun.length > 0) {\n\t\tcontext.log(\n\t\t\t'debug',\n\t\t\t'Migrations to run:',\n\t\t\ttoRun.map((m) => m.version),\n\t\t);\n\t\tawait runMigrations({ context, toRun, meta, indexedDB });\n\t}\n\treturn openDatabase({\n\t\tindexedDB,\n\t\tnamespace: context.namespace,\n\t\tversion,\n\t\tcontext,\n\t});\n}\n", "import { CollectionIndexFilter, hashObject } from '@verdant-web/common';\nimport { Entity } from '../entities/Entity.js';\n\nfunction existsFilter<T>(x: T | null): x is T {\n\treturn x !== null;\n}\n\nexport function filterResultSet(results: any): any {\n\tif (Array.isArray(results)) {\n\t\treturn results.map(filterResultSet).filter(existsFilter);\n\t} else if (results instanceof Entity) {\n\t\treturn results.deleted ? null : results;\n\t} else {\n\t\treturn results;\n\t}\n}\n\nexport function areIndexesEqual(\n\ta?: CollectionIndexFilter,\n\tb?: CollectionIndexFilter,\n) {\n\treturn (!a && !b) || (a && b && hashObject(a) === hashObject(b));\n}\n", "import { EventSubscriber } from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { Entity } from '../entities/Entity.js';\nimport { Disposable } from '../utils/Disposable.js';\nimport { filterResultSet } from './utils.js';\n\nexport type BaseQueryEvents = {\n\tchange: (value: any) => void;\n\tstatusChange: (status: QueryStatus) => void;\n};\n\nexport type BaseQueryOptions<T> = {\n\tcontext: Context;\n\tinitial: T;\n\tcollection: string;\n\tkey: string;\n\tshouldUpdate?: (updatedCollections: string[]) => boolean;\n};\n\nexport type QueryStatus = 'initial' | 'initializing' | 'revalidating' | 'ready';\n\nexport const ON_ALL_UNSUBSCRIBED = Symbol('ON_ALL_UNSUBSCRIBED');\nexport const UPDATE = Symbol('UPDATE');\n\n// export interface BaseQuery<T> {\n// \tsubscribe(event: 'change', callback: (value: T) => void): () => void;\n// \tsubscribe(event: 'statusChange', callback: (status: QueryStatus) => void): () => void;\n// \tsubscribe(callback: (value: T) => void): () => void;\n// }\n\nexport abstract class BaseQuery<T> extends Disposable {\n\tprivate _rawValue;\n\tprivate _value;\n\n\tprivate _events;\n\tprivate _internalUnsubscribes: (() => void)[] = [];\n\tprivate _allUnsubscribedHandler?: (query: BaseQuery<T>) => void;\n\tprivate _status: QueryStatus = 'initial';\n\tprivate _executionPromise: Promise<T> | null = null;\n\n\tprotected context;\n\n\treadonly collection;\n\treadonly key;\n\treadonly isListQuery;\n\n\tconstructor({\n\t\tinitial,\n\t\tcontext,\n\t\tcollection,\n\t\tkey,\n\t\tshouldUpdate,\n\t}: BaseQueryOptions<T>) {\n\t\tsuper();\n\t\tthis._rawValue = initial;\n\t\tthis._value = initial;\n\t\tthis.isListQuery = Array.isArray(initial);\n\t\tthis._events = new EventSubscriber<BaseQueryEvents>(\n\t\t\t(event: keyof BaseQueryEvents) => {\n\t\t\t\tif (event === 'change') this._allUnsubscribedHandler?.(this);\n\t\t\t},\n\t\t);\n\t\tthis.context = context;\n\t\tthis.key = key;\n\t\tthis.collection = collection;\n\t\tconst shouldUpdateFn =\n\t\t\tshouldUpdate ||\n\t\t\t((collections: string[]) => collections.includes(collection));\n\t\tthis.addDispose(\n\t\t\tthis.context.entityEvents.subscribe(\n\t\t\t\t'collectionsChanged',\n\t\t\t\t(collections) => {\n\t\t\t\t\tif (shouldUpdateFn(collections)) {\n\t\t\t\t\t\tthis.context.log('info', 'Updating query', this.key);\n\t\t\t\t\t\t// immediately refilter the result set - deleted\n\t\t\t\t\t\t// entities will already be nulled out\n\t\t\t\t\t\t// this.refreshValue();\n\t\t\t\t\t\tthis.execute();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t\t// TODO: subscribe to document changes and update if necessary.\n\t}\n\n\tget current() {\n\t\treturn this._value;\n\t}\n\n\tget resolved() {\n\t\tif (this.status === 'ready') return Promise.resolve(this._value);\n\t\treturn this._executionPromise ?? this.execute();\n\t}\n\n\tget subscribed() {\n\t\treturn this._events.totalSubscriberCount() > 0;\n\t}\n\n\tget status() {\n\t\treturn this._status;\n\t}\n\n\tprivate set status(v: QueryStatus) {\n\t\tif (this._status === v) return;\n\t\tthis._status = v;\n\t\tthis._events.emit('statusChange', this._status);\n\t}\n\n\tget hasDeleted() {\n\t\tif (this.isListQuery) {\n\t\t\treturn (this._rawValue as any[]).length !== (this._value as any[]).length;\n\t\t}\n\t\treturn !!this._rawValue && !this._value;\n\t}\n\n\t/**\n\t * Subscribe to changes in the query value.\n\t *\n\t * @deprecated use the two parameter form instead\n\t */\n\tsubscribe(callback: (value: T) => void): () => void;\n\t/**\n\t * Subscribe to changes in the query value.\n\t */\n\tsubscribe(event: 'change', callback: (value: T) => void): () => void;\n\t/**\n\t * Subscribe to changes in the query state.\n\t */\n\tsubscribe(\n\t\tevent: 'statusChange',\n\t\tcallback: (status: QueryStatus) => void,\n\t): () => void;\n\tsubscribe(eventOrCallback: any, callback?: any) {\n\t\t// change subscription has special behavior...\n\t\tif (callback === undefined && typeof eventOrCallback === 'function') {\n\t\t\t// accessing for side effects... eh\n\t\t\tthis.resolved;\n\t\t\treturn this._events.subscribe('change', eventOrCallback);\n\t\t} else if (eventOrCallback === 'change' && callback !== undefined) {\n\t\t\t// accessing for side effects... eh\n\t\t\tthis.resolved;\n\t\t\treturn this._events.subscribe('change', callback);\n\t\t} else if (\n\t\t\teventOrCallback === 'statusChange' &&\n\t\t\ttypeof callback === 'function'\n\t\t) {\n\t\t\treturn this._events.subscribe(eventOrCallback, callback);\n\t\t} else {\n\t\t\tthrow new Error('Invalid invocation of Query.subscribe');\n\t\t}\n\t}\n\n\tprotected setValue = (value: T) => {\n\t\tthis._rawValue = value;\n\t\tthis.subscribeToDeleteAndRestore(this._rawValue);\n\t\tconst filtered = filterResultSet(value);\n\n\t\t// prevent excess change notifications by diffing\n\t\t// value by identity for single-value queries,\n\t\t// and by item identity for multi-value\n\t\tlet changed = true;\n\t\t// always fire change when going from initial to ready\n\t\tif (this.status === 'initializing' || this.status === 'initial') {\n\t\t\tchanged = true;\n\t\t} else {\n\t\t\t// compare values by identity, after filtering.\n\t\t\tif (this.isListQuery) {\n\t\t\t\tif (\n\t\t\t\t\t(this._value as any[]).length === (filtered as any[]).length &&\n\t\t\t\t\t(this._value as any[]).every((v, i) => v === (filtered as any[])[i])\n\t\t\t\t) {\n\t\t\t\t\tchanged = false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (this._value === filtered) {\n\t\t\t\t\tchanged = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis._value = filtered;\n\n\t\tif (changed) {\n\t\t\tthis.context.log('debug', 'Query value changed', this.key);\n\t\t\tthis._events.emit('change', this._value);\n\t\t}\n\t\tthis.status = 'ready';\n\t};\n\n\t// re-applies filtering if results have changed\n\tprotected refreshValue = () => {\n\t\tthis.setValue(this._rawValue);\n\t};\n\n\tprivate subscribeToDeleteAndRestore = (value: T) => {\n\t\twhile (this._internalUnsubscribes.length) {\n\t\t\tthis._internalUnsubscribes.pop()?.();\n\t\t}\n\n\t\tif (Array.isArray(value)) {\n\t\t\tvalue.forEach((entity: any) => {\n\t\t\t\tif (entity instanceof Entity) {\n\t\t\t\t\tthis._internalUnsubscribes.push(\n\t\t\t\t\t\tentity.subscribe('delete', this.refreshValue),\n\t\t\t\t\t);\n\t\t\t\t\tthis._internalUnsubscribes.push(\n\t\t\t\t\t\tentity.subscribe('restore', this.refreshValue),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (value instanceof Entity) {\n\t\t\tthis._internalUnsubscribes.push(\n\t\t\t\tvalue.subscribe('delete', this.refreshValue),\n\t\t\t);\n\t\t\tthis._internalUnsubscribes.push(\n\t\t\t\tvalue.subscribe('restore', () => {\n\t\t\t\t\tthis.refreshValue();\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t};\n\n\texecute = () => {\n\t\tthis.context.log('debug', 'Executing query', this.key);\n\n\t\tif (this.status === 'initial') {\n\t\t\tthis.status = 'initializing';\n\t\t} else if (this.status === 'ready') {\n\t\t\tthis.status = 'revalidating';\n\t\t}\n\t\t// no status change needed if already in a 'running' status.\n\n\t\tthis._executionPromise = this.run()\n\t\t\t.then(() => this._value)\n\t\t\t.catch((err) => {\n\t\t\t\tif (err instanceof Error) {\n\t\t\t\t\tif (\n\t\t\t\t\t\terr.name === 'InvalidStateError' ||\n\t\t\t\t\t\terr.name === 'InvalidAccessError'\n\t\t\t\t\t) {\n\t\t\t\t\t\t// possibly accessing db while it's closed. not much we can do.\n\t\t\t\t\t\treturn this._value;\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error('Unknown error executing query');\n\t\t\t\t}\n\t\t\t});\n\t\treturn this._executionPromise;\n\t};\n\tprotected abstract run(): Promise<void>;\n\n\t[ON_ALL_UNSUBSCRIBED] = (handler: (query: BaseQuery<T>) => void) => {\n\t\tthis._allUnsubscribedHandler = handler;\n\t};\n}\n", "import { createOid } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions } from './BaseQuery.js';\n\nexport class GetQuery<T> extends BaseQuery<T | null> {\n\tprivate hydrate;\n\tprivate oid;\n\n\tconstructor({\n\t\tid,\n\t\thydrate,\n\t\t...rest\n\t}: {\n\t\tid: string;\n\t\thydrate: (oid: string) => Promise<T>;\n\t} & Omit<BaseQueryOptions<T | null>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: null,\n\t\t\t...rest,\n\t\t});\n\t\tthis.oid = createOid(rest.collection, id);\n\t\tthis.hydrate = hydrate;\n\t}\n\n\tprotected run = async () => {\n\t\tconst value = await this.hydrate(this.oid);\n\t\tthis.setValue(value);\n\t};\n}\n", "import { CollectionFilter } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';\nimport { findOneOid } from './dbQueries.js';\nimport { areIndexesEqual } from './utils.js';\n\nexport class FindOneQuery<T> extends BaseQuery<T | null> {\n\tprivate index;\n\tprivate hydrate;\n\n\tconstructor({\n\t\tindex,\n\t\thydrate,\n\t\t...rest\n\t}: {\n\t\tindex?: CollectionFilter;\n\t\thydrate: (oid: string) => Promise<T>;\n\t} & Omit<BaseQueryOptions<T | null>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: null,\n\t\t\t...rest,\n\t\t});\n\t\tthis.index = index;\n\t\tthis.hydrate = hydrate;\n\t}\n\n\tprotected run = async () => {\n\t\tconst oid = await findOneOid({\n\t\t\tcollection: this.collection,\n\t\t\tindex: this.index,\n\t\t\tcontext: this.context,\n\t\t});\n\t\tthis.setValue(oid ? await this.hydrate(oid) : null);\n\t};\n\n\t[UPDATE] = (index: CollectionFilter | undefined) => {\n\t\tif (areIndexesEqual(this.index, index)) return;\n\t\tthis.index = index;\n\t\tthis.execute();\n\t};\n}\n", "import { CollectionFilter } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';\nimport { findPageOfOids } from './dbQueries.js';\nimport { areIndexesEqual } from './utils.js';\n\nexport class FindPageQuery<T> extends BaseQuery<T[]> {\n\tprivate index;\n\tprivate hydrate;\n\tprivate _pageSize: number;\n\tprivate _page: number;\n\tprivate _hasNextPage: boolean = false;\n\n\tget pageSize() {\n\t\treturn this._pageSize;\n\t}\n\n\tget page() {\n\t\treturn this._page;\n\t}\n\n\tget hasNextPage() {\n\t\treturn this._hasNextPage;\n\t}\n\n\tget hasPreviousPage() {\n\t\treturn this._page > 0;\n\t}\n\n\tconstructor({\n\t\tindex,\n\t\thydrate,\n\t\tpageSize,\n\t\tpage,\n\t\t...rest\n\t}: {\n\t\tindex?: CollectionFilter;\n\t\thydrate: (oid: string) => Promise<T>;\n\t\tpageSize: number;\n\t\tpage: number;\n\t} & Omit<BaseQueryOptions<T[]>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: [],\n\t\t\t...rest,\n\t\t});\n\t\tthis.index = index;\n\t\tthis.hydrate = hydrate;\n\t\tthis._pageSize = pageSize;\n\t\tthis._page = page;\n\t}\n\n\tprotected run = async () => {\n\t\tconst { result, hasNextPage } = await findPageOfOids({\n\t\t\tcollection: this.collection,\n\t\t\tindex: this.index,\n\t\t\tcontext: this.context,\n\t\t\tlimit: this._pageSize,\n\t\t\toffset: this._page * this._pageSize,\n\t\t});\n\t\tthis._hasNextPage = hasNextPage;\n\t\tthis.setValue(await Promise.all(result.map(this.hydrate)));\n\t};\n\n\tnextPage = async () => {\n\t\tif (!this.hasNextPage) return;\n\n\t\tthis._page++;\n\t\tawait this.run();\n\t};\n\n\tpreviousPage = async () => {\n\t\tif (this._page === 0) return;\n\n\t\tthis._page--;\n\t\tawait this.run();\n\t};\n\n\tsetPage = async (page: number) => {\n\t\tthis._page = page;\n\t\tawait this.run();\n\t};\n\n\t[UPDATE] = (index: CollectionFilter | undefined) => {\n\t\tif (areIndexesEqual(this.index, index)) return;\n\t\tthis.index = index;\n\t\tthis.execute();\n\t};\n}\n", "import { CollectionFilter } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';\nimport { findPageOfOids } from './dbQueries.js';\nimport { areIndexesEqual } from './utils.js';\n\nexport class FindInfiniteQuery<T> extends BaseQuery<T[]> {\n\tprivate index;\n\tprivate hydrate;\n\tprivate _upToPage = 1;\n\tprivate _pageSize: number;\n\tprivate _hasNextPage: boolean = false;\n\n\tget pageSize() {\n\t\treturn this._pageSize;\n\t}\n\n\tget hasMore() {\n\t\treturn this._hasNextPage;\n\t}\n\n\tconstructor({\n\t\thydrate,\n\t\tpageSize,\n\t\tindex,\n\t\t...rest\n\t}: {\n\t\thydrate: (oid: string) => Promise<T>;\n\t\tpageSize: number;\n\t\tindex?: CollectionFilter;\n\t} & Omit<BaseQueryOptions<T[]>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: [],\n\t\t\t...rest,\n\t\t});\n\t\tthis.index = index;\n\t\tthis.hydrate = hydrate;\n\t\tthis._pageSize = pageSize;\n\t}\n\n\tprotected run = async () => {\n\t\tconst { result, hasNextPage } = await findPageOfOids({\n\t\t\tcollection: this.collection,\n\t\t\tcontext: this.context,\n\t\t\tlimit: this._pageSize * this._upToPage,\n\t\t\toffset: 0,\n\t\t\tindex: this.index,\n\t\t});\n\t\tthis._hasNextPage = hasNextPage;\n\t\tthis.setValue(await Promise.all(result.map(this.hydrate)));\n\t};\n\n\tpublic loadMore = async () => {\n\t\tconst { result, hasNextPage } = await findPageOfOids({\n\t\t\tcollection: this.collection,\n\t\t\tcontext: this.context,\n\t\t\tlimit: this._pageSize,\n\t\t\toffset: this._pageSize * this._upToPage,\n\t\t\tindex: this.index,\n\t\t});\n\t\tthis._hasNextPage = hasNextPage;\n\t\tthis._upToPage++;\n\t\tthis.setValue([\n\t\t\t...this.current,\n\t\t\t...(await Promise.all(result.map(this.hydrate))),\n\t\t]);\n\t};\n\n\t[UPDATE] = (index: CollectionFilter | undefined) => {\n\t\tif (areIndexesEqual(this.index, index)) return;\n\t\tthis.index = index;\n\t\tthis.execute();\n\t};\n}\n", "import { CollectionFilter } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';\nimport { findAllOids } from './dbQueries.js';\nimport { areIndexesEqual } from './utils.js';\n\nexport class FindAllQuery<T> extends BaseQuery<T[]> {\n\tprivate index;\n\tprivate hydrate;\n\n\tconstructor({\n\t\tindex,\n\t\thydrate,\n\t\t...rest\n\t}: {\n\t\tindex?: CollectionFilter;\n\t\thydrate: (oid: string) => Promise<T>;\n\t} & Omit<BaseQueryOptions<T[]>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: [],\n\t\t\t...rest,\n\t\t});\n\t\tthis.index = index;\n\t\tthis.hydrate = hydrate;\n\t}\n\n\tprotected run = async () => {\n\t\tconst oids = await findAllOids({\n\t\t\tcollection: this.collection,\n\t\t\tindex: this.index,\n\t\t\tcontext: this.context,\n\t\t});\n\t\tthis.context.log(\n\t\t\t'debug',\n\t\t\t`FindAllQuery: ${oids.length} oids found: ${oids}`,\n\t\t);\n\t\tthis.setValue(await Promise.all(oids.map(this.hydrate)));\n\t};\n\n\t[UPDATE] = (index: CollectionFilter | undefined) => {\n\t\tif (areIndexesEqual(this.index, index)) return;\n\t\tthis.index = index;\n\t\tthis.execute();\n\t};\n}\n", "import {\n\tAuthorizationKey,\n\tCollectionFilter,\n\thashObject,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { EntityStore } from '../entities/EntityStore.js';\nimport { GetQuery } from './GetQuery.js';\nimport { QueryCache } from './QueryCache.js';\nimport { FindOneQuery } from './FindOneQuery.js';\nimport { FindPageQuery } from './FindPageQuery.js';\nimport { FindInfiniteQuery } from './FindInfiniteQuery.js';\nimport { FindAllQuery } from './FindAllQuery.js';\nimport { DocumentManager } from '../entities/DocumentManager.js';\nimport { Entity, ObjectEntity } from '../index.js';\nimport { UPDATE } from './BaseQuery.js';\n\nexport class CollectionQueries<\n\tT extends ObjectEntity<any, any>,\n\tInit,\n\tFilter extends CollectionFilter,\n> {\n\tprivate cache;\n\tprivate collection;\n\tprivate hydrate: (oid: string) => Promise<T>;\n\tprivate context;\n\tprivate documentManager;\n\n\tput: (\n\t\tinit: Init,\n\t\toptions?: { undoable?: boolean; access?: AuthorizationKey },\n\t) => Promise<T>;\n\tdelete: (id: string, options?: { undoable?: boolean }) => Promise<void>;\n\tdeleteAll: (ids: string[], options?: { undoable?: boolean }) => Promise<void>;\n\tclone: (\n\t\tentity: ObjectEntity<any, any>,\n\t\toptions?: {\n\t\t\tundoable?: boolean;\n\t\t\taccess?: AuthorizationKey;\n\t\t\tprimaryKey?: string;\n\t\t},\n\t) => Promise<T>;\n\n\tconstructor({\n\t\tcollection,\n\t\tcache,\n\t\tentities,\n\t\tcontext,\n\t\tdocumentManager,\n\t}: {\n\t\tcollection: string;\n\t\tcache: QueryCache;\n\t\tentities: EntityStore;\n\t\tcontext: Context;\n\t\tdocumentManager: DocumentManager<any>;\n\t}) {\n\t\tthis.cache = cache;\n\t\tthis.collection = collection;\n\t\tthis.hydrate = entities.hydrate as any;\n\t\tthis.context = context;\n\t\tthis.documentManager = documentManager;\n\n\t\tthis.put = this.documentManager.create.bind(\n\t\t\tthis.documentManager,\n\t\t\tthis.collection,\n\t\t);\n\t\tthis.delete = this.documentManager.delete.bind(\n\t\t\tthis.documentManager,\n\t\t\tthis.collection,\n\t\t);\n\t\tthis.deleteAll = this.documentManager.deleteAllFromCollection.bind(\n\t\t\tthis.documentManager,\n\t\t\tthis.collection,\n\t\t);\n\t\tthis.clone = this.documentManager.clone.bind(\n\t\t\tthis.documentManager,\n\t\t\tthis.collection,\n\t\t);\n\t}\n\n\tprivate serializeIndex = (index?: CollectionFilter) => {\n\t\tif (!index) return '';\n\t\treturn hashObject(index);\n\t};\n\n\tget = (id: string) => {\n\t\tconst key = `get:${this.collection}:${id}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew GetQuery<T>({\n\t\t\t\t\tid,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t}),\n\t\t);\n\t};\n\n\tfindOne = ({\n\t\tindex,\n\t\tkey: providedKey,\n\t}: { index?: Filter; key?: string } = {}) => {\n\t\tconst key =\n\t\t\tprovidedKey || `findOne:${this.collection}:${this.serializeIndex(index)}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew FindOneQuery<T>({\n\t\t\t\t\tindex,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t}),\n\t\t\t(existing) => {\n\t\t\t\texisting[UPDATE](index);\n\t\t\t},\n\t\t);\n\t};\n\n\tfindAll = ({\n\t\tindex,\n\t\tkey: providedKey,\n\t}: { index?: Filter; key?: string } = {}) => {\n\t\tconst key =\n\t\t\tprovidedKey || `findAll:${this.collection}:${this.serializeIndex(index)}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew FindAllQuery<T>({\n\t\t\t\t\tindex,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t}),\n\t\t\t(existing) => {\n\t\t\t\texisting[UPDATE](index);\n\t\t\t},\n\t\t);\n\t};\n\n\tfindPage = ({\n\t\tindex,\n\t\tpageSize,\n\t\tpage,\n\t\tkey: providedKey,\n\t}: {\n\t\tindex?: Filter;\n\t\tpageSize: number;\n\t\tpage: number;\n\t\tkey?: string;\n\t}) => {\n\t\tconst key =\n\t\t\tprovidedKey ||\n\t\t\t`findPage:${this.collection}:${this.serializeIndex(index)}:${pageSize}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew FindPageQuery<T>({\n\t\t\t\t\tindex,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t\tpageSize,\n\t\t\t\t\tpage,\n\t\t\t\t}),\n\t\t\t(existing) => {\n\t\t\t\texisting[UPDATE](index);\n\t\t\t},\n\t\t);\n\t};\n\n\tfindAllInfinite = ({\n\t\tindex,\n\t\tpageSize,\n\t\tkey: providedKey,\n\t}: {\n\t\tindex?: Filter;\n\t\tpageSize: number;\n\t\tkey?: string;\n\t}) => {\n\t\tconst key =\n\t\t\tprovidedKey ||\n\t\t\t`findAllInfinite:${this.collection}:${this.serializeIndex(\n\t\t\t\tindex,\n\t\t\t)}:${pageSize}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew FindInfiniteQuery<T>({\n\t\t\t\t\tindex,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t\tpageSize,\n\t\t\t\t}),\n\t\t\t(existing) => {\n\t\t\t\texisting[UPDATE](index);\n\t\t\t},\n\t\t);\n\t};\n}\n", "import { Context } from '../context.js';\nimport { Disposable } from '../utils/Disposable.js';\nimport { BaseQuery, ON_ALL_UNSUBSCRIBED } from './BaseQuery.js';\n\nexport class QueryCache extends Disposable {\n\tprivate _cache: Map<string, BaseQuery<any>> = new Map();\n\tprivate _evictionTime;\n\tprivate context;\n\n\tconstructor({\n\t\tevictionTime = 5 * 1000,\n\t\tcontext,\n\t}: {\n\t\tevictionTime?: number;\n\t\tcontext: Context;\n\t}) {\n\t\tsuper();\n\n\t\tthis._evictionTime = evictionTime;\n\t\tthis.context = context;\n\t}\n\n\tget<T extends BaseQuery<any>>(key: string): T | null {\n\t\treturn (this._cache.get(key) as T) || null;\n\t}\n\n\tset<V extends BaseQuery<any>>(value: V) {\n\t\tthis._cache.set(value.key, value);\n\t\tvalue[ON_ALL_UNSUBSCRIBED](this.onQueryUnsubscribed);\n\t\treturn value;\n\t}\n\n\tgetOrSet<V extends BaseQuery<any>>(\n\t\tkey: string,\n\t\tcreate: () => V,\n\t\tupdate?: (query: V) => void,\n\t) {\n\t\tconst existing = this.get<V>(key);\n\t\tif (existing) {\n\t\t\tupdate?.(existing);\n\t\t\treturn existing;\n\t\t}\n\t\treturn this.set(create());\n\t}\n\n\tprivate onQueryUnsubscribed = (query: BaseQuery<any>) => {\n\t\tsetTimeout(() => {\n\t\t\tif (query.subscribed) return;\n\t\t\t// double check before evicting... possible the cache\n\t\t\t// got a different version of this query.\n\t\t\tif (this._cache.get(query.key) === query) {\n\t\t\t\tthis._cache.delete(query.key);\n\t\t\t}\n\t\t}, this._evictionTime);\n\t};\n\n\tdropAll = () => {\n\t\tthis._cache.forEach((query) => query.dispose());\n\t\tthis._cache.clear();\n\t};\n\n\tforceRefreshAll = () => {\n\t\tthis._cache.forEach((q) => q.execute());\n\t};\n}\n", "import {\n\tServerMessage,\n\tEventSubscriber,\n\tBatcher,\n\tBatch,\n\tVerdantInternalPresence,\n\tinitialInternalPresence,\n} from '@verdant-web/common';\nimport type { UserInfo } from '../index.js';\nimport {\n\tLocalReplicaInfo,\n\tLocalReplicaStore,\n} from '../metadata/LocalReplicaStore.js';\n\nexport const HANDLE_MESSAGE = Symbol('handleMessage');\n\nexport class PresenceManager<\n\tProfile = any,\n\tPresence = any,\n> extends EventSubscriber<{\n\t/**\n\t * Fired when a particular peer's presence changes\n\t */\n\tpeerChanged: (userId: string, presence: UserInfo<Profile, Presence>) => void;\n\t/**\n\t * Fired immediately when a change to local presence is made. This change may not\n\t * yet have been sent to the server (see: \"update\" event)\n\t */\n\tselfChanged: (presence: UserInfo<Profile, Presence>) => void;\n\t/** Fired when any number of peer presences have changed */\n\tpeersChanged: (peers: Record<string, UserInfo<Profile, Presence>>) => void;\n\t/** Fired when a peer presence goes offline */\n\tpeerLeft: (userId: string, lastPresence: UserInfo<Profile, Presence>) => void;\n\t/** Fired after local presence changes are flushed to the server. */\n\tupdate: (data: {\n\t\tpresence?: Presence;\n\t\tinternal?: VerdantInternalPresence;\n\t}) => void;\n\tload: () => void;\n\t/** Fired on any change to a peer or the local user */\n\tchange: () => void;\n}> {\n\tprivate _peers = {} as Record<string, UserInfo<Profile, Presence>>;\n\tprivate _self = { profile: {} } as UserInfo<Profile, Presence>;\n\t// keep track of own replica IDs - applications may care if we're \"alone\" but with multiple devices.\n\tprivate _selfReplicaIds = new Set<string>();\n\tprivate _peerIds = new Array<string>();\n\tprivate _updateBatcher;\n\tprivate _updateBatch: Batch<{\n\t\tpresence?: Partial<Presence>;\n\t\tinternal?: Partial<VerdantInternalPresence>;\n\t}>;\n\n\tget self() {\n\t\treturn this._self;\n\t}\n\n\tget peers() {\n\t\treturn this._peers;\n\t}\n\n\tget peerIds() {\n\t\treturn this._peerIds;\n\t}\n\n\tget everyone() {\n\t\tconst everyone = { ...this._peers };\n\t\teveryone[this.self.id] = this.self;\n\t\treturn everyone;\n\t}\n\n\tget selfReplicaIds() {\n\t\treturn this._selfReplicaIds;\n\t}\n\n\tconstructor({\n\t\tinitialPresence,\n\t\tupdateBatchTimeout = 200,\n\t\tdefaultProfile,\n\t\treplicaStore,\n\t}: {\n\t\tinitialPresence: Presence;\n\t\tdefaultProfile: Profile;\n\t\tupdateBatchTimeout?: number;\n\t\treplicaStore: LocalReplicaStore;\n\t}) {\n\t\tsuper();\n\t\tthis.self.presence = initialPresence;\n\t\tthis.self.profile = defaultProfile;\n\t\tthis.self.internal = initialInternalPresence;\n\t\tthis.self.id = '';\n\t\tthis.self.replicaId = '';\n\n\t\t// set the local replica ID as soon as it's loaded\n\t\treplicaStore.get().then((info) => {\n\t\t\tthis.self.replicaId = info.id;\n\t\t});\n\n\t\tthis._updateBatcher = new Batcher(this.flushPresenceUpdates);\n\t\tthis._updateBatch = this._updateBatcher.add({\n\t\t\tmax: 25,\n\t\t\ttimeout: updateBatchTimeout,\n\t\t\titems: [],\n\t\t\tkey: 'default',\n\t\t});\n\t}\n\n\t/**\n\t * Decides if an update is for the local user or not. Even if it's a different replica\n\t * than the local one.\n\t *\n\t * If the replicaId matches, we use that first - we may not know the local replica's User ID yet,\n\t * e.g. on the first presence update.\n\t *\n\t * Otherwise, match the user ID to our local copy.\n\t */\n\tprivate isSelf = (\n\t\tlocalReplicaInfo: LocalReplicaInfo,\n\t\tuserInfo: UserInfo<Profile, Presence>,\n\t) => {\n\t\treturn (\n\t\t\tlocalReplicaInfo.id === userInfo.replicaId ||\n\t\t\tthis._selfReplicaIds.has(userInfo.replicaId) ||\n\t\t\tthis._self.id === userInfo.id\n\t\t);\n\t};\n\n\t[HANDLE_MESSAGE] = async (\n\t\tlocalReplicaInfo: LocalReplicaInfo,\n\t\tmessage: ServerMessage,\n\t) => {\n\t\tlet peersChanged = false;\n\t\tlet selfChanged = false;\n\t\tconst peerIdsSet = new Set<string>(this.peerIds);\n\n\t\tif (message.type === 'presence-changed') {\n\t\t\tif (this.isSelf(localReplicaInfo, message.userInfo)) {\n\t\t\t\tthis._self = message.userInfo;\n\t\t\t\tthis._selfReplicaIds.add(message.userInfo.replicaId);\n\t\t\t\tselfChanged = true;\n\t\t\t\tthis.emit('selfChanged', message.userInfo);\n\t\t\t} else {\n\t\t\t\tpeerIdsSet.add(message.userInfo.id);\n\t\t\t\tthis._peers[message.userInfo.id] = message.userInfo;\n\t\t\t\tpeersChanged = true;\n\t\t\t\tthis.emit('peerChanged', message.userInfo.id, message.userInfo);\n\t\t\t}\n\t\t} else if (message.type === 'sync-resp') {\n\t\t\t// reset to provided presence data, which includes all peers.\n\t\t\tthis._peers = {};\n\t\t\tpeerIdsSet.clear();\n\n\t\t\tfor (const [id, userInfo] of Object.entries(message.peerPresence)) {\n\t\t\t\tif (this.isSelf(localReplicaInfo, userInfo)) {\n\t\t\t\t\tthis._self = userInfo;\n\t\t\t\t\tthis._selfReplicaIds.add(userInfo.replicaId);\n\t\t\t\t\tselfChanged = true;\n\t\t\t\t\tthis.emit('selfChanged', userInfo);\n\t\t\t\t} else {\n\t\t\t\t\tpeersChanged = true;\n\t\t\t\t\tpeerIdsSet.add(id);\n\t\t\t\t\tthis._peers[id] = userInfo;\n\t\t\t\t\tthis.emit('peerChanged', id, userInfo);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (message.type === 'presence-offline') {\n\t\t\tpeerIdsSet.delete(message.userId);\n\t\t\tthis._selfReplicaIds.delete(message.replicaId);\n\t\t\tconst lastPresence = this._peers[message.userId];\n\t\t\tdelete this._peers[message.userId];\n\t\t\tpeersChanged = true;\n\t\t\tthis.emit('peerLeft', message.userId, lastPresence);\n\t\t}\n\t\tif (peersChanged) {\n\t\t\t// important that this stays sorted to keep stable order, don't want\n\t\t\t// peers swapping around.\n\t\t\tthis._peerIds = Array.from(peerIdsSet).sort();\n\t\t\tthis.emit('peersChanged', this._peers);\n\t\t}\n\t\tif (peersChanged || selfChanged) {\n\t\t\tthis.emit('change');\n\t\t}\n\t};\n\n\tupdate = async (presence: Partial<Presence>) => {\n\t\tthis._updateBatch.update({\n\t\t\titems: [{ presence }],\n\t\t});\n\t\t// proactively update the local presence\n\t\tthis.self.presence = { ...this.self.presence, ...presence };\n\t\tthis.emit('selfChanged', this.self);\n\t\tthis.emit('change');\n\t};\n\n\tflushPresenceUpdates = (\n\t\tpresenceUpdates: {\n\t\t\tpresence?: Partial<Presence>;\n\t\t\tinternal?: Partial<VerdantInternalPresence>;\n\t\t}[],\n\t) => {\n\t\tconst data = {\n\t\t\tpresence: this.self.presence,\n\t\t\tinternal: this.self.internal,\n\t\t};\n\t\tfor (const update of presenceUpdates) {\n\t\t\tif (update.presence) {\n\t\t\t\tObject.assign(data.presence as any, update.presence);\n\t\t\t}\n\t\t\tif (update.internal) {\n\t\t\t\tObject.assign(data.internal, update.internal);\n\t\t\t}\n\t\t}\n\t\tthis.emit('update', data);\n\t};\n\n\tsetViewId = (viewId: string | undefined) => {\n\t\tthis._updateBatch.update({\n\t\t\titems: [{ internal: { viewId } }],\n\t\t});\n\t\tthis.self.internal.viewId = viewId;\n\t\tthis.emit('selfChanged', this.self);\n\t\tthis.emit('change');\n\t};\n\n\tsetFieldId = (fieldId: string | undefined, timestamp = Date.now()) => {\n\t\tthis._updateBatch.update({\n\t\t\titems: [\n\t\t\t\t{ internal: { lastFieldId: fieldId, lastFieldTimestamp: timestamp } },\n\t\t\t],\n\t\t});\n\t\tthis.self.internal.lastFieldId = fieldId;\n\t\tthis.emit('selfChanged', this.self);\n\t\tthis.emit('change');\n\t};\n\n\t/**\n\t * Get all peers that are in the same view as the local user.\n\t */\n\tgetViewPeers = () => {\n\t\treturn (\n\t\t\tthis._peerIds\n\t\t\t\t.map((id) => this._peers[id])\n\t\t\t\t// undefined view matches all peers. otherwise,\n\t\t\t\t// filter to only those in the same view.\n\t\t\t\t.filter(\n\t\t\t\t\t(peer) =>\n\t\t\t\t\t\tthis.self.internal.viewId === undefined ||\n\t\t\t\t\t\tpeer.internal.viewId === this.self.internal.viewId,\n\t\t\t\t)\n\t\t);\n\t};\n\n\t/**\n\t * Get all peers that have interacted with the specified\n\t * field most recently.\n\t */\n\tgetFieldPeers = (fieldId: string, expirationPeriod = 60 * 1000) => {\n\t\treturn this._peerIds\n\t\t\t.map((id) => this._peers[id])\n\t\t\t.filter(\n\t\t\t\t(peer) =>\n\t\t\t\t\tpeer.internal.lastFieldId === fieldId &&\n\t\t\t\t\tDate.now() - peer.internal.lastFieldTimestamp! < expirationPeriod,\n\t\t\t);\n\t};\n}\n", "import { FileData } from '@verdant-web/common';\nimport { ServerSyncEndpointProvider } from './ServerSyncEndpointProvider.js';\n\nexport interface FileUploadResult {\n\tsuccess: boolean;\n\tretry: boolean;\n\terror?: string;\n}\n\nexport type FilePullResult =\n\t| {\n\t\t\tsuccess: true;\n\t\t\tdata: FileData;\n\t }\n\t| {\n\t\t\tsuccess: false;\n\t\t\tretry: boolean;\n\t\t\terror?: any;\n\t };\n\nexport class FileSync {\n\tprivate endpointProvider: ServerSyncEndpointProvider;\n\tprivate log: (...args: any[]) => any;\n\n\tconstructor({\n\t\tendpointProvider,\n\t\tlog,\n\t}: {\n\t\tendpointProvider: ServerSyncEndpointProvider;\n\t\tlog: (...args: any[]) => any;\n\t}) {\n\t\tthis.endpointProvider = endpointProvider;\n\t\tthis.log = log;\n\t}\n\n\tuploadFile = async (data: FileData): Promise<FileUploadResult> => {\n\t\tconst file = data.file;\n\n\t\tif (!file) {\n\t\t\tthrow new Error('Cannot upload a non-local file');\n\t\t}\n\n\t\t// multipart upload\n\t\tconst { files: fileEndpoint, token } =\n\t\t\tawait this.endpointProvider.getEndpoints();\n\n\t\tconst formData = new FormData();\n\t\tformData.append('file', file);\n\n\t\ttry {\n\t\t\tconst response = await fetch(fileEndpoint + `/${data.id}`, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: formData,\n\t\t\t\tcredentials: 'include',\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (response.ok) {\n\t\t\t\tthis.log('info', 'File upload successful');\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: true,\n\t\t\t\t\tretry: false,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tconst responseText = await response.text();\n\t\t\t\tthis.log('error', 'File upload failed', response.status, responseText);\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\tretry: response.status >= 500,\n\t\t\t\t\terror: `Failed to upload file: ${response.status} ${responseText}`,\n\t\t\t\t};\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tthis.log('error', 'File upload failed', e);\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\tretry: true,\n\t\t\t\terror: (e as Error).message,\n\t\t\t};\n\t\t}\n\t};\n\n\tgetFile = async (id: string): Promise<FilePullResult> => {\n\t\tconst { files: fileEndpoint, token } =\n\t\t\tawait this.endpointProvider.getEndpoints();\n\n\t\ttry {\n\t\t\tconst response = await fetch(fileEndpoint + `/${id}`, {\n\t\t\t\tmethod: 'GET',\n\t\t\t\tcredentials: 'include',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (response.ok) {\n\t\t\t\tconst data = await response.json();\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: true,\n\t\t\t\t\tdata,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tthis.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t'File information fetch failed',\n\t\t\t\t\tresponse.status,\n\t\t\t\t\tawait response.text(),\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\tretry: response.status >= 500 || response.status === 404,\n\t\t\t\t};\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tthis.log('error', 'File information fetch failed', e);\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: e,\n\t\t\t\tretry: true,\n\t\t\t};\n\t\t}\n\t};\n}\n", "import { EventSubscriber } from '@verdant-web/common';\n\nexport class Heartbeat extends EventSubscriber<{\n\tmissed: () => void;\n\tbeat: () => void;\n}> {\n\tprivate _interval: number;\n\tprivate deadlineLength: number;\n\tprivate nextBeat: NodeJS.Timeout | null = null;\n\tprivate deadline: NodeJS.Timeout | null = null;\n\n\tget interval() {\n\t\treturn this._interval;\n\t}\n\n\tconstructor({\n\t\tinterval = 15 * 1000,\n\t\tdeadlineLength = 3 * 1000,\n\t\trestartOnTabFocus = true,\n\t}: {\n\t\tinterval?: number;\n\t\tdeadlineLength?: number;\n\t\trestartOnTabFocus?: boolean;\n\t} = {}) {\n\t\tsuper();\n\t\tthis._interval = interval;\n\t\tthis.deadlineLength = deadlineLength;\n\t\tif (typeof window !== 'undefined' && restartOnTabFocus) {\n\t\t\twindow.addEventListener('pageshow', () => this.start(true));\n\t\t\tdocument.addEventListener('visibilitychange', () => {\n\t\t\t\tif (document.visibilityState === 'visible') {\n\t\t\t\t\tthis.start(true);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tkeepAlive = () => {\n\t\tif (this.deadline) {\n\t\t\tclearTimeout(this.deadline);\n\t\t\tthis.deadline = null;\n\t\t\tthis.start();\n\t\t}\n\t};\n\n\tstart = (immediate = false) => {\n\t\tthis.stop();\n\t\tif (immediate) {\n\t\t\tthis.beat();\n\t\t} else {\n\t\t\tthis.nextBeat = setTimeout(this.beat, this._interval);\n\t\t}\n\t};\n\n\tstop = () => {\n\t\tif (this.nextBeat) {\n\t\t\tclearTimeout(this.nextBeat);\n\t\t}\n\t\tif (this.deadline) {\n\t\t\tclearTimeout(this.deadline);\n\t\t}\n\t};\n\n\tprivate beat = async () => {\n\t\tthis.emit('beat');\n\t\tthis.deadline = setTimeout(this.onDeadline, this.deadlineLength);\n\t};\n\n\tprivate onDeadline = () => {\n\t\tthis.deadline = null;\n\t\tthis.emit('missed');\n\t};\n\n\t/**\n\t * Only takes affect after the next beat\n\t */\n\tsetInterval = (interval: number) => {\n\t\tthis._interval = interval;\n\t};\n}\n", "import {\n\tClientMessage,\n\tEventSubscriber,\n\tPresenceUpdateMessage,\n\tServerMessage,\n\tVerdantErrorCode,\n\tdebounce,\n\tisVerdantErrorResponse,\n\tthrottle,\n} from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { PresenceManager } from './PresenceManager.js';\nimport { Heartbeat } from './Heartbeat.js';\nimport { ServerSyncEndpointProvider } from './ServerSyncEndpointProvider.js';\nimport { SyncTransport, SyncTransportEvents } from './Sync.js';\n\nexport class PushPullSync\n\textends EventSubscriber<SyncTransportEvents>\n\timplements SyncTransport\n{\n\treadonly meta: Metadata;\n\treadonly presence: PresenceManager;\n\tprivate endpointProvider;\n\tprivate heartbeat;\n\tprivate fetch;\n\n\treadonly mode = 'pull';\n\tprivate log;\n\n\tprivate _isConnected = false;\n\tprivate _status: 'active' | 'paused' = 'paused';\n\tprivate _hasSynced = false;\n\n\tconstructor({\n\t\tendpointProvider,\n\t\tmeta,\n\t\tpresence,\n\t\tinterval = 15 * 1000,\n\t\tlog = () => {},\n\t\tfetch = window.fetch.bind(window),\n\t}: {\n\t\tendpointProvider: ServerSyncEndpointProvider;\n\t\tmeta: Metadata;\n\t\tpresence: PresenceManager;\n\t\tinterval?: number;\n\t\tlog?: (...args: any[]) => any;\n\t\tfetch?: typeof window.fetch;\n\t}) {\n\t\tsuper();\n\t\tthis.log = log;\n\t\tthis.meta = meta;\n\t\tthis.presence = presence;\n\t\tthis.endpointProvider = endpointProvider;\n\t\tthis.fetch = fetch;\n\n\t\tthis.heartbeat = new Heartbeat({\n\t\t\tinterval,\n\t\t});\n\t\tthis.heartbeat.subscribe('beat', this.onHeartbeat);\n\t\tthis.heartbeat.subscribe('missed', this.onHeartbeatMissed);\n\t}\n\n\tsetInterval = (interval: number) => {\n\t\tthis.heartbeat.setInterval(interval);\n\t};\n\n\tget interval() {\n\t\treturn this.heartbeat.interval;\n\t}\n\n\tget hasSynced() {\n\t\treturn this._hasSynced;\n\t}\n\n\tprivate sendRequest = async (messages: ClientMessage[]) => {\n\t\tthis.log('Sending sync request', messages);\n\t\ttry {\n\t\t\tconst { http: host, token } = await this.endpointProvider.getEndpoints();\n\t\t\tconst response = await this.fetch(host, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tmessages,\n\t\t\t\t}),\n\t\t\t\tcredentials: 'include',\n\t\t\t});\n\t\t\tif (response.ok) {\n\t\t\t\tthis.heartbeat.keepAlive();\n\t\t\t\tconst json = (await response.json()) as {\n\t\t\t\t\tmessages: ServerMessage[];\n\t\t\t\t};\n\t\t\t\t// for (const message of json.messages) {\n\t\t\t\t// \tthis.handleServerMessage(message);\n\t\t\t\t// }\n\t\t\t\tconst handlePromise = Promise.all(\n\t\t\t\t\tjson.messages.map(this.handleServerMessage),\n\t\t\t\t);\n\t\t\t\tif (!this._isConnected) {\n\t\t\t\t\tthis._isConnected = true;\n\t\t\t\t\tthis.emit('onlineChange', true);\n\t\t\t\t}\n\t\t\t\tawait handlePromise;\n\t\t\t} else {\n\t\t\t\tthis.log('Sync request failed', response.status, await response.text());\n\n\t\t\t\tif (this._isConnected) {\n\t\t\t\t\tthis._isConnected = false;\n\t\t\t\t\tthis.emit('onlineChange', false);\n\t\t\t\t}\n\n\t\t\t\tconst json = await response.json();\n\t\t\t\tif (isVerdantErrorResponse(json)) {\n\t\t\t\t\t// token expired... retry again later after clearing it\n\t\t\t\t\tif (json.code === VerdantErrorCode.TokenExpired) {\n\t\t\t\t\t\tthis.endpointProvider.clearCache();\n\t\t\t\t\t\tthis.heartbeat.keepAlive();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// only keep trying if the error was not 4xx\n\t\t\t\tif (response.status >= 500) {\n\t\t\t\t\tthis.heartbeat.keepAlive();\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (this._isConnected) {\n\t\t\t\tthis._isConnected = false;\n\t\t\t\tthis.emit('onlineChange', false);\n\t\t\t}\n\t\t\tthis.log(error);\n\n\t\t\tthis.heartbeat.keepAlive();\n\t\t}\n\t};\n\n\tprivate handleServerMessage = async (message: ServerMessage) => {\n\t\tif (message.type === 'sync-resp') {\n\t\t\t// we need to ack the nonce to confirm that we received the sync-resp\n\t\t\t// but we can go ahead and preemptively allow ops to be sent\n\t\t\tthis._hasSynced = true;\n\t\t\tif (message.ackThisNonce) {\n\t\t\t\tthis.log('Sending sync ack', message.ackThisNonce);\n\t\t\t\tawait this.sendRequest([\n\t\t\t\t\tawait this.meta.messageCreator.createAck(message.ackThisNonce),\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t\tthis.emit('message', message);\n\t};\n\n\t// reduce rate of presence messages sent; each one would trigger an HTTP\n\t// request, which is not ideal if presence is updating rapidly.\n\tthrottledPresenceUpdate = throttle((message: PresenceUpdateMessage) => {\n\t\tthis.sendRequest([message]);\n\t}, 3000);\n\n\tsend = (message: ClientMessage) => {\n\t\t// only certain messages are sent for pull-based sync.\n\t\tswitch (message.type) {\n\t\t\tcase 'presence-update':\n\t\t\t\treturn this.throttledPresenceUpdate(message);\n\t\t\tcase 'sync':\n\t\t\tcase 'heartbeat':\n\t\t\t\treturn this.sendRequest([message]);\n\t\t\tcase 'op':\n\t\t\t\tif (this._hasSynced) {\n\t\t\t\t\treturn this.sendRequest([message]);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tstart = async () => {\n\t\tif (this.status === 'active') {\n\t\t\treturn;\n\t\t}\n\t\tawait this.endpointProvider.getEndpoints();\n\t\tthis.heartbeat.start(true);\n\t\tthis._status = 'active';\n\t};\n\tstop(): void {\n\t\tthis.heartbeat.stop();\n\t\tthis._status = 'paused';\n\t}\n\n\tdestroy = () => {\n\t\tthis.dispose();\n\t\tthis.stop();\n\t};\n\treconnect(): void {\n\t\tthis.heartbeat.start(true);\n\t}\n\n\tignoreIncoming(): void {\n\t\tthis.stop();\n\t}\n\n\t// on a heartbeat, do a sync\n\tprivate onHeartbeat = async () => {\n\t\t// for HTTP sync we send presence first, so that the sync-resp message\n\t\t// will include the client's own presence info and fill in missing profile\n\t\t// data on the first request. otherwise it would have to wait for the second.\n\t\tthis.sendRequest([\n\t\t\tawait this.meta.messageCreator.createPresenceUpdate(this.presence.self),\n\t\t\tawait this.meta.messageCreator.createSyncStep1(),\n\t\t]);\n\t};\n\n\t// if the server fails to respond in a certain amount of time, we assume\n\t// the connection is lost and go offline.\n\tprivate onHeartbeatMissed = async () => {\n\t\tthis.emit('onlineChange', false);\n\t\tthis.log('Missed heartbeat');\n\t\tthis._isConnected = false;\n\t};\n\n\tsyncOnce = async () => {\n\t\tawait this.sendRequest([await this.meta.messageCreator.createSyncStep1()]);\n\t};\n\n\tget isConnected(): boolean {\n\t\treturn this._isConnected;\n\t}\n\tget status() {\n\t\treturn this._status;\n\t}\n}\n", "/**\n * The code was extracted from:\n * https://github.com/davidchambers/Base64.js\n */\n\nvar chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";\n\nfunction InvalidCharacterError(message) {\n this.message = message;\n}\n\nInvalidCharacterError.prototype = new Error();\nInvalidCharacterError.prototype.name = \"InvalidCharacterError\";\n\nfunction polyfill(input) {\n var str = String(input).replace(/=+$/, \"\");\n if (str.length % 4 == 1) {\n throw new InvalidCharacterError(\n \"'atob' failed: The string to be decoded is not correctly encoded.\"\n );\n }\n for (\n // initialize result and counters\n var bc = 0, bs, buffer, idx = 0, output = \"\";\n // get next character\n (buffer = str.charAt(idx++));\n // character found in table? initialize bit storage and add its ascii value;\n ~buffer &&\n ((bs = bc % 4 ? bs * 64 + buffer : buffer),\n // and if not first of each 4 characters,\n // convert the first 8 bits to one ascii character\n bc++ % 4) ?\n (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) :\n 0\n ) {\n // try to find character in table (0-63, not found => -1)\n buffer = chars.indexOf(buffer);\n }\n return output;\n}\n\nexport default (typeof window !== \"undefined\" &&\n window.atob &&\n window.atob.bind(window)) ||\npolyfill;", "import atob from \"./atob\";\n\nfunction b64DecodeUnicode(str) {\n return decodeURIComponent(\n atob(str).replace(/(.)/g, function(m, p) {\n var code = p.charCodeAt(0).toString(16).toUpperCase();\n if (code.length < 2) {\n code = \"0\" + code;\n }\n return \"%\" + code;\n })\n );\n}\n\nexport default function(str) {\n var output = str.replace(/-/g, \"+\").replace(/_/g, \"/\");\n switch (output.length % 4) {\n case 0:\n break;\n case 2:\n output += \"==\";\n break;\n case 3:\n output += \"=\";\n break;\n default:\n throw \"Illegal base64url string!\";\n }\n\n try {\n return b64DecodeUnicode(output);\n } catch (err) {\n return atob(output);\n }\n}", "\"use strict\";\n\nimport base64_url_decode from \"./base64_url_decode\";\n\nexport function InvalidTokenError(message) {\n this.message = message;\n}\n\nInvalidTokenError.prototype = new Error();\nInvalidTokenError.prototype.name = \"InvalidTokenError\";\n\nexport default function(token, options) {\n if (typeof token !== \"string\") {\n throw new InvalidTokenError(\"Invalid token specified\");\n }\n\n options = options || {};\n var pos = options.header === true ? 0 : 1;\n try {\n return JSON.parse(base64_url_decode(token.split(\".\")[pos]));\n } catch (e) {\n throw new InvalidTokenError(\"Invalid token specified: \" + e.message);\n }\n}", "import { assert, ReplicaType } from '@verdant-web/common';\nimport { default as jwtDecode } from 'jwt-decode';\n\nexport interface ServerSyncEndpointProviderConfig {\n\t/**\n\t * The location of the endpoint used to retrieve an\n\t * authorization token for the client.\n\t */\n\tauthEndpoint?: string;\n\t/**\n\t * A custom function to retrieve authorization\n\t * data. Use whatever fetching mechanism you want.\n\t */\n\tfetchAuth?: () => Promise<{\n\t\taccessToken: string;\n\t}>;\n\t/**\n\t * A spec-compliant fetch implementation. If not provided,\n\t * the global fetch will be used. authEndpoint will\n\t * be used to fetch the token.\n\t */\n\tfetch?: typeof fetch;\n}\n\nexport interface SyncTokenInfo {\n\turl: string;\n\tfileUrl: string;\n\ttype: ReplicaType;\n\tuserId: string;\n\tlibraryId: string;\n\trole?: string;\n}\n\nexport class ServerSyncEndpointProvider {\n\tprivate cached = null as {\n\t\thttp: string;\n\t\twebsocket: string;\n\t\tfiles: string;\n\t\ttoken: string;\n\t} | null;\n\ttokenInfo: SyncTokenInfo | null = null;\n\n\tget type() {\n\t\treturn this.tokenInfo?.type ?? ReplicaType.Realtime;\n\t}\n\n\tconstructor(private config: ServerSyncEndpointProviderConfig) {\n\t\tif (!config.authEndpoint && !config.fetchAuth) {\n\t\t\tthrow new Error(\n\t\t\t\t'Either authEndpoint or fetchAuth must be provided to ServerSyncEndpointProvider',\n\t\t\t);\n\t\t}\n\t}\n\n\tgetEndpoints = async () => {\n\t\tif (this.cached) {\n\t\t\treturn this.cached;\n\t\t}\n\n\t\tlet result: { accessToken: string };\n\t\tif (this.config.fetchAuth) {\n\t\t\tresult = await this.config.fetchAuth();\n\t\t} else {\n\t\t\tconst fetchImpl = this.config.fetch || fetch.bind(window);\n\t\t\tresult = await fetchImpl(this.config.authEndpoint!, {\n\t\t\t\tcredentials: 'include',\n\t\t\t}).then((res) => {\n\t\t\t\tif (!res.ok) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Auth endpoint returned non-200 response: ${res.status}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\treturn res.json();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tassert(result.accessToken, 'No access token provided from auth endpoint');\n\t\tconst decoded = (jwtDecode as any)(result.accessToken);\n\t\tassert(decoded.url, 'No sync endpoint provided from auth endpoint');\n\t\tassert(\n\t\t\tdecoded.type !== undefined,\n\t\t\t'No replica type provided from auth endpoint',\n\t\t);\n\t\tthis.tokenInfo = {\n\t\t\tuserId: decoded.sub,\n\t\t\tlibraryId: decoded.lib,\n\t\t\turl: decoded.url,\n\t\t\tfileUrl: decoded.file,\n\t\t\trole: decoded.role,\n\t\t\ttype: parseInt(decoded.type + '') as ReplicaType,\n\t\t};\n\t\tconst url = new URL(decoded.url);\n\t\turl.protocol = url.protocol.replace('ws', 'http');\n\t\tconst httpEndpoint = url.toString();\n\t\turl.protocol = url.protocol.replace('http', 'ws');\n\t\tconst websocketEndpoint = url.toString();\n\t\tlet fileEndpoint: string = decoded.file;\n\t\tif (!fileEndpoint) {\n\t\t\t// default to http endpoint + '/files';\n\t\t\tconst fileUrl = new URL(httpEndpoint);\n\t\t\tfileUrl.pathname = fileUrl.pathname + '/files';\n\t\t\tfileEndpoint = fileUrl.toString();\n\t\t}\n\t\tthis.cached = {\n\t\t\thttp: httpEndpoint,\n\t\t\twebsocket: websocketEndpoint,\n\t\t\tfiles: fileEndpoint,\n\t\t\ttoken: result.accessToken,\n\t\t};\n\t\treturn this.cached;\n\t};\n\n\tclearCache = () => {\n\t\tthis.cached = null;\n\t};\n}\n", "import { EventSubscriber } from '@verdant-web/common';\n\nexport class BackoffScheduler extends EventSubscriber<{\n\ttrigger: () => void;\n}> {\n\tprivate readonly backoff: Backoff;\n\tprivate timer: NodeJS.Timeout | null = null;\n\tprivate isScheduled = false;\n\n\tconstructor(backoff: Backoff) {\n\t\tsuper();\n\t\tthis.backoff = backoff;\n\t}\n\n\tnext = () => {\n\t\tif (!this.isScheduled) {\n\t\t\tthis.isScheduled = true;\n\t\t\tthis.timer = setTimeout(() => {\n\t\t\t\tthis.emit('trigger');\n\t\t\t\tthis.isScheduled = false;\n\t\t\t\tthis.backoff.next();\n\t\t\t}, this.backoff.current);\n\t\t}\n\t};\n\n\treset = () => {\n\t\tthis.backoff.reset();\n\t\tif (this.timer) {\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = null;\n\t\t}\n\t};\n}\n\nexport class Backoff {\n\tcurrent = 0;\n\tprivate readonly max: number;\n\tprivate readonly factor: number;\n\n\tconstructor(max: number, factor: number) {\n\t\tthis.max = max;\n\t\tthis.factor = factor;\n\t}\n\n\tnext = () => {\n\t\tthis.current = Math.min(this.max, this.current * this.factor);\n\t};\n\n\treset = () => {\n\t\tthis.current = 0;\n\t};\n}\n", "import {\n\tClientMessage,\n\tEventSubscriber,\n\tServerMessage,\n} from '@verdant-web/common';\nimport { Backoff, BackoffScheduler } from '../BackoffScheduler.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Heartbeat } from './Heartbeat.js';\nimport { PresenceManager } from './PresenceManager.js';\nimport { ServerSyncEndpointProvider } from './ServerSyncEndpointProvider.js';\nimport { SyncTransport, SyncTransportEvents } from './Sync.js';\n\nexport class WebSocketSync\n\textends EventSubscriber<SyncTransportEvents>\n\timplements SyncTransport\n{\n\tprivate meta: Metadata;\n\treadonly presence: PresenceManager;\n\tprivate socket: WebSocket | null = null;\n\t// messages awaiting websocket connection to send\n\tprivate connectQueue: ClientMessage[] = [];\n\t// messages awaiting sync response to send\n\tprivate syncQueue: ClientMessage[] = [];\n\t// messages waiting for sync to finish\n\tprivate incomingQueue: ServerMessage[] = [];\n\tprivate endpointProvider;\n\tprivate _status: 'active' | 'paused' = 'paused';\n\tprivate synced = false;\n\tprivate hasStartedSync = false;\n\tprivate _ignoreIncoming = false;\n\n\treadonly mode = 'realtime';\n\tprivate log = (...args: any[]) => {};\n\n\tprivate heartbeat = new Heartbeat();\n\n\tprivate reconnectScheduler = new BackoffScheduler(\n\t\tnew Backoff(60 * 1000, 1.5),\n\t);\n\n\tconstructor({\n\t\tendpointProvider,\n\t\tmeta,\n\t\tpresence,\n\t\tlog,\n\t}: {\n\t\tendpointProvider: ServerSyncEndpointProvider;\n\t\tmeta: Metadata;\n\t\tpresence: PresenceManager;\n\t\tlog?: (...args: any[]) => any;\n\t}) {\n\t\tsuper();\n\t\tthis.log = log || this.log;\n\t\tthis.endpointProvider = endpointProvider;\n\t\tthis.meta = meta;\n\t\tthis.presence = presence;\n\n\t\tthis.reconnectScheduler.subscribe('trigger', this.initializeSocket);\n\t\tthis.heartbeat.subscribe('beat', this.sendHeartbeat);\n\t}\n\n\tget hasSynced() {\n\t\treturn this.synced;\n\t}\n\n\tprivate onOpen = () => {\n\t\tif (!this.socket) {\n\t\t\tthrow new Error('Invalid sync state: online but socket is null');\n\t\t}\n\t\tthis.synced = false;\n\t\tif (this.connectQueue.length) {\n\t\t\tfor (const msg of this.connectQueue) {\n\t\t\t\tthis.log('Sending queued message', JSON.stringify(msg, null, 2));\n\t\t\t\tthis.socket.send(JSON.stringify(msg));\n\t\t\t}\n\t\t\tthis.connectQueue = [];\n\t\t}\n\t\tthis.log('Sync connected');\n\t\tthis.onOnlineChange(true);\n\t\tthis.reconnectScheduler.reset();\n\t};\n\n\tprivate onOnlineChange = async (online: boolean) => {\n\t\tthis.log('Socket online change', online);\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\t\tif (!online) {\n\t\t\tthis.hasStartedSync = false;\n\t\t\tthis.synced = false;\n\t\t\tthis.heartbeat.stop();\n\t\t} else {\n\t\t\tthis.log('Starting sync');\n\t\t\tthis.hasStartedSync = true;\n\t\t\tthis.synced = false;\n\t\t\tthis.send(\n\t\t\t\tawait this.meta.messageCreator.createPresenceUpdate(this.presence.self),\n\t\t\t);\n\t\t\tthis.send(await this.meta.messageCreator.createSyncStep1());\n\t\t\tthis.heartbeat.start();\n\t\t}\n\t\tthis.emit('onlineChange', online);\n\t};\n\n\tprivate onMessage = async (event: MessageEvent) => {\n\t\tif (this._ignoreIncoming) {\n\t\t\tthis.log(\n\t\t\t\t'Ignoring incoming message (ignore incoming flag set)',\n\t\t\t\tevent.data,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst message = JSON.parse(event.data) as ServerMessage;\n\t\tswitch (message.type) {\n\t\t\tcase 'sync-resp':\n\t\t\t\tif (message.ackThisNonce) {\n\t\t\t\t\t// we need to send the ack to confirm we got the response\n\t\t\t\t\tthis.send(\n\t\t\t\t\t\tawait this.meta.messageCreator.createAck(message.ackThisNonce),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.hasStartedSync = true;\n\t\t\t\tthis.synced = true;\n\t\t\t\tif (this.syncQueue.length) {\n\t\t\t\t\tif (message.overwriteLocalData) {\n\t\t\t\t\t\tthis.log(\n\t\t\t\t\t\t\t'warn',\n\t\t\t\t\t\t\t'Overwriting local data - dropping outgoing message queue',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.syncQueue = [];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfor (const msg of this.syncQueue) {\n\t\t\t\t\t\t\tthis.send(msg);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.syncQueue = [];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.emit('message', message);\n\t\t\t\tif (this.incomingQueue.length) {\n\t\t\t\t\tfor (const msg of this.incomingQueue) {\n\t\t\t\t\t\tthis.emit('message', msg);\n\t\t\t\t\t}\n\t\t\t\t\tthis.incomingQueue = [];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'need-since':\n\t\t\tcase 'presence-changed':\n\t\t\tcase 'presence-offline':\n\t\t\t\tthis.emit('message', message);\n\t\t\t\tbreak;\n\t\t\tcase 'op-re':\n\t\t\t\tif (!this.synced) {\n\t\t\t\t\tthis.log(\n\t\t\t\t\t\t`Enqueueing op-re message because sync hasn't finished yet`,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t);\n\t\t\t\t\tthis.incomingQueue.push(message);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tthis.emit('message', message);\n\t\t\t\tbreak;\n\t\t\tcase 'heartbeat-response':\n\t\t\t\tthis.heartbeat.keepAlive();\n\t\t\t\tthis.emit('message', message);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tif (this.synced) {\n\t\t\t\t\tthis.emit('message', message);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tprivate onError = (event: Event) => {\n\t\tthis.log(event);\n\t\tthis.reconnectScheduler.next();\n\n\t\tthis.log(`Attempting reconnect to websocket sync`);\n\t};\n\n\tprivate onClose = (event: CloseEvent) => {\n\t\tthis.log('Sync disconnected');\n\t\tthis.onOnlineChange(false);\n\t\tthis.onError(event);\n\t};\n\n\tprivate initializeSocket = async () => {\n\t\tconst endpoint = await this.endpointProvider.getEndpoints();\n\t\t// abusing protocols to pass the auth token\n\t\tthis.socket = new WebSocket(endpoint.websocket, ['Bearer', endpoint.token]);\n\t\tthis.socket.addEventListener('message', this.onMessage);\n\t\tthis.socket.addEventListener('open', this.onOpen);\n\t\tthis.socket.addEventListener('error', this.onError);\n\t\tthis.socket.addEventListener('close', this.onClose);\n\t\treturn this.socket;\n\t};\n\n\tprivate sendHeartbeat = async () => {\n\t\tthis.send(await this.meta.messageCreator.createHeartbeat());\n\t};\n\n\treconnect = () => {\n\t\tthis.stop();\n\t\tthis.start();\n\t};\n\n\tprivate canSkipSyncWait = (message: ClientMessage) => {\n\t\treturn (\n\t\t\tmessage.type === 'sync' ||\n\t\t\tmessage.type === 'presence-update' ||\n\t\t\tmessage.type === 'sync-ack' ||\n\t\t\tmessage.type === 'heartbeat'\n\t\t);\n\t};\n\n\tsend = (message: ClientMessage) => {\n\t\tif (this.status !== 'active') return;\n\n\t\t// wait until a sync has started before doing anything other than sync.\n\t\t// new \"op\" messages can arrive before sync has started, so we need to wait\n\t\tif (!this.hasStartedSync && !this.canSkipSyncWait(message)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.canSkipSyncWait(message)) {\n\t\t\tif (this.socket?.readyState === WebSocket.OPEN) {\n\t\t\t\tthis.log('Sending message', JSON.stringify(message, null, 2));\n\t\t\t\tthis.socket!.send(JSON.stringify(message));\n\t\t\t} else {\n\t\t\t\tthis.log(\n\t\t\t\t\t'Enqueueing message until socket is open',\n\t\t\t\t\tJSON.stringify(message, null, 2),\n\t\t\t\t);\n\t\t\t\tthis.connectQueue.push(message);\n\t\t\t}\n\t\t} else if (this.synced) {\n\t\t\tif (this.socket?.readyState === WebSocket.OPEN) {\n\t\t\t\tthis.log('Sending message', JSON.stringify(message, null, 2));\n\t\t\t\tthis.socket.send(JSON.stringify(message));\n\t\t\t}\n\t\t} else if (this.hasStartedSync) {\n\t\t\tthis.log(\n\t\t\t\t'Enqueueing message until synced',\n\t\t\t\tJSON.stringify(message, null, 2),\n\t\t\t);\n\t\t\tthis.syncQueue.push(message);\n\t\t}\n\t};\n\n\tdestroy = () => {\n\t\tthis.dispose();\n\t\tthis.stop();\n\t};\n\n\tstart = async () => {\n\t\tif (this.socket) {\n\t\t\treturn;\n\t\t}\n\t\tawait this.initializeSocket();\n\t\tthis._status = 'active';\n\t};\n\n\tstop = () => {\n\t\tthis.socket?.removeEventListener('message', this.onMessage);\n\t\tthis.socket?.removeEventListener('close', this.onClose);\n\t\tthis.socket?.close();\n\t\tthis.socket = null;\n\t\tthis._status = 'paused';\n\t};\n\n\tignoreIncoming(): void {\n\t\tthis.incomingQueue = [];\n\t\tthis._ignoreIncoming = true;\n\t}\n\n\tget isConnected() {\n\t\treturn this.socket?.readyState === WebSocket.OPEN;\n\t}\n\n\tget status() {\n\t\treturn this._status;\n\t}\n}\n", "export async function attemptToRegisterBackgroundSync() {\n\ttry {\n\t\tconst status = await navigator.permissions.query({\n\t\t\tname: 'periodic-background-sync' as any,\n\t\t});\n\t\tif (status.state === 'granted') {\n\t\t\t// Periodic background sync can be used.\n\t\t\tconst registration = await navigator.serviceWorker.ready;\n\t\t\tif ('periodicSync' in registration) {\n\t\t\t\ttry {\n\t\t\t\t\tawait (registration.periodicSync as any).register('verdant-sync', {\n\t\t\t\t\t\t// An interval of one day.\n\t\t\t\t\t\tminInterval: 24 * 60 * 60 * 1000,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Periodic background sync cannot be used.\n\t\t\t\t\tconsole.warn('Failed to register background sync:', error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Periodic background sync cannot be used.\n\t\t\tconsole.debug('Background sync permission is not granted:', status);\n\t\t}\n\t} catch (error) {\n\t\tconsole.error('Failed to initiate background sync:', error);\n\t}\n}\n", "import {\n\tClientMessage,\n\tDocumentBaseline,\n\tEventSubscriber,\n\tFileData,\n\tOperation,\n\tReplicaType,\n\trewriteAuthzOriginator,\n\tServerMessage,\n\tVerdantError,\n\tVerdantInternalPresence,\n} from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { HANDLE_MESSAGE, PresenceManager } from './PresenceManager.js';\nimport { FilePullResult, FileSync, FileUploadResult } from './FileSync.js';\nimport { PushPullSync } from './PushPullSync.js';\nimport {\n\tServerSyncEndpointProvider,\n\tServerSyncEndpointProviderConfig,\n} from './ServerSyncEndpointProvider.js';\nimport { WebSocketSync } from './WebSocketSync.js';\nimport { Context } from '../context.js';\nimport { attemptToRegisterBackgroundSync } from './background.js';\n\ntype SyncEvents = {\n\tonlineChange: (isOnline: boolean) => void;\n\tsyncingChange: (syncing: boolean) => void;\n\t/** When the server has lost data and re-requests data from the past */\n\tserverReset: (since: string | null) => void;\n};\n\nexport type SyncTransportEvents = SyncEvents & {\n\tmessage: (message: ServerMessage) => void;\n};\n\nexport interface SyncTransport extends EventSubscriber<SyncTransportEvents> {\n\treadonly presence: PresenceManager;\n\n\treadonly mode: SyncTransportMode;\n\treadonly hasSynced: boolean;\n\n\tsend(message: ClientMessage): void;\n\n\tstart(): Promise<void>;\n\tignoreIncoming(): void;\n\tstop(): void;\n\n\tdestroy(): void;\n\n\treconnect(): void;\n\n\treadonly isConnected: boolean;\n\treadonly status: 'active' | 'paused';\n}\n\nexport interface Sync<Presence = any, Profile = any>\n\textends EventSubscriber<SyncEvents> {\n\tsetMode(mode: SyncTransportMode): void;\n\tsetPullInterval(interval: number): void;\n\treadonly pullInterval: number;\n\tuploadFile(data: FileData): Promise<FileUploadResult>;\n\tgetFile(fileId: string): Promise<FilePullResult>;\n\treadonly presence: PresenceManager<Profile, Presence>;\n\tsend(message: ClientMessage): void;\n\tstart(): Promise<void>;\n\tstop(): void;\n\tignoreIncoming(): void;\n\tdestroy(): void;\n\treconnect(): void;\n\tsyncOnce(): Promise<void>;\n\treadonly isConnected: boolean;\n\treadonly status: 'active' | 'paused';\n\treadonly mode: SyncTransportMode;\n}\n\nexport class NoSync<Presence = any, Profile = any>\n\textends EventSubscriber<SyncEvents>\n\timplements Sync<Presence, Profile>\n{\n\treadonly mode = 'pull';\n\n\tpublic send(): void {}\n\n\tpublic async start(): Promise<void> {}\n\n\tpublic stop(): void {}\n\n\tpublic ignoreIncoming(): void {}\n\n\tpublic destroy = () => {};\n\n\tpublic reconnect(): void {}\n\n\tpublic setMode(): void {}\n\tpublic setPullInterval(): void {}\n\n\tpublic readonly isConnected = false;\n\tpublic readonly status = 'paused';\n\tpublic readonly pullInterval = 0;\n\n\tpublic readonly presence;\n\n\tconstructor({ meta }: { meta: Metadata }) {\n\t\tsuper();\n\t\tthis.presence = new PresenceManager({\n\t\t\tinitialPresence: null as any,\n\t\t\tdefaultProfile: null as any,\n\t\t\treplicaStore: meta.localReplica,\n\t\t});\n\t}\n\n\tuploadFile = async () => {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tretry: false,\n\t\t};\n\t};\n\n\tgetFile = async (): Promise<FilePullResult> => {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tretry: false,\n\t\t};\n\t};\n\n\tsyncOnce: () => Promise<void> = async () => {};\n}\n\nexport type SyncTransportMode = 'realtime' | 'pull';\n\nexport interface ServerSyncOptions<Profile = any, Presence = any>\n\textends ServerSyncEndpointProviderConfig {\n\t/**\n\t * When a client first connects, it will use this presence value.\n\t */\n\tinitialPresence: Presence;\n\t/**\n\t * Before connecting to the server, the local client will have\n\t * this value for their profile data. You can either cache and store\n\t * profile data from a previous connection or provide defaults like\n\t * empty strings.\n\t */\n\tdefaultProfile: Profile;\n\n\t/**\n\t * Provide `false` to disable transport selection. Transport selection\n\t * automatically switches between HTTP and WebSocket based sync depending\n\t * on the number of peers connected. If a user is alone, they will use\n\t * HTTP push/pull to sync changes. If another user joins, both users will\n\t * be upgraded to websockets.\n\t *\n\t * Provide `peers-only` to only automatically use websockets if other\n\t * users connect, but not if another device for the current user connects.\n\t * By default, automatic transport selection will upgrade to websockets if\n\t * another device from the current user connects, but if realtime sync is\n\t * not necessary for such cases, you can save bandwidth by disabling this.\n\t *\n\t * Turning off this feature allows you more control over the transport\n\t * which can be useful for low-power devices or to save server traffic.\n\t * To modify transport modes manually, utilize `client.sync.setMode`.\n\t * The built-in behavior is essentially switching modes based on\n\t * the number of peers detected by client.sync.presence.\n\t */\n\tautomaticTransportSelection?: boolean | 'peers-only';\n\tinitialTransport?: SyncTransportMode;\n\tautoStart?: boolean;\n\t/**\n\t * Optionally specify an interval, in milliseconds, to poll the server\n\t * when in pull mode.\n\t */\n\tpullInterval?: number;\n\t/**\n\t * Presence updates are batched to reduce number of requests / messages\n\t * sent to the server. You can specify the batching time slice, in milliseconds,\n\t */\n\tpresenceUpdateBatchTimeout?: number;\n\t/**\n\t * Experimental: sync messages over a broadcast channel between tabs.\n\t * Fixes tabs not reactively updating to changes when other tabs are open,\n\t * but is not yet thoroughly vetted.\n\t */\n\tuseBroadcastChannel?: boolean;\n\t/**\n\t * Listen for outgoing messages from the client to the server.\n\t * Not sure why you want to do this, but be careful.\n\t */\n\tonOutgoingMessage?: (message: ClientMessage) => void;\n\n\tEXPERIMENTAL_backgroundSync?: boolean;\n}\n\nexport class ServerSync<Presence = any, Profile = any>\n\textends EventSubscriber<SyncEvents>\n\timplements Sync<Presence, Profile>\n{\n\tprivate webSocketSync: WebSocketSync;\n\tprivate pushPullSync: PushPullSync;\n\tprivate fileSync: FileSync;\n\tprivate activeSync: SyncTransport;\n\tprivate endpointProvider;\n\tprivate onData: (data: {\n\t\toperations: Operation[];\n\t\tbaselines?: DocumentBaseline[];\n\t\treset?: boolean;\n\t}) => Promise<void>;\n\tprivate broadcastChannel: BroadcastChannel | null = null;\n\tprivate _activelySyncing = false;\n\n\tprivate meta: Metadata;\n\n\treadonly presence: PresenceManager<Profile, Presence>;\n\n\tprivate onOutgoingMessage?: (message: ClientMessage) => void;\n\n\tprivate log;\n\n\tconstructor(\n\t\t{\n\t\t\tauthEndpoint,\n\t\t\tfetchAuth,\n\t\t\tfetch,\n\t\t\tinitialPresence,\n\t\t\tautomaticTransportSelection = true,\n\t\t\tautoStart,\n\t\t\tinitialTransport,\n\t\t\tpullInterval,\n\t\t\tpresenceUpdateBatchTimeout,\n\t\t\tdefaultProfile,\n\t\t\tuseBroadcastChannel,\n\t\t\tonOutgoingMessage,\n\t\t\tEXPERIMENTAL_backgroundSync,\n\t\t}: ServerSyncOptions<Profile, Presence>,\n\t\t{\n\t\t\tmeta,\n\t\t\tctx,\n\t\t\tonData,\n\t\t}: {\n\t\t\tmeta: Metadata;\n\t\t\tctx: Context;\n\t\t\tonData: (data: {\n\t\t\t\toperations: Operation[];\n\t\t\t\tbaselines?: DocumentBaseline[];\n\t\t\t\treset?: boolean;\n\t\t\t}) => Promise<void>;\n\t\t},\n\t) {\n\t\tsuper();\n\t\tthis.meta = meta;\n\t\tthis.onData = onData;\n\t\tthis.log = ctx.log;\n\t\tthis.onOutgoingMessage = onOutgoingMessage;\n\t\tthis.presence = new PresenceManager({\n\t\t\tinitialPresence,\n\t\t\tdefaultProfile,\n\t\t\tupdateBatchTimeout: presenceUpdateBatchTimeout,\n\t\t\treplicaStore: meta.localReplica,\n\t\t});\n\t\tthis.endpointProvider = new ServerSyncEndpointProvider({\n\t\t\tauthEndpoint,\n\t\t\tfetchAuth,\n\t\t\tfetch,\n\t\t});\n\n\t\tthis.webSocketSync = new WebSocketSync({\n\t\t\tendpointProvider: this.endpointProvider,\n\t\t\tmeta,\n\t\t\tpresence: this.presence,\n\t\t\tlog: ctx.log,\n\t\t});\n\t\tthis.pushPullSync = new PushPullSync({\n\t\t\tendpointProvider: this.endpointProvider,\n\t\t\tmeta,\n\t\t\tpresence: this.presence,\n\t\t\tlog: ctx.log,\n\t\t\tinterval: pullInterval,\n\t\t\tfetch,\n\t\t});\n\t\tthis.fileSync = new FileSync({\n\t\t\tendpointProvider: this.endpointProvider,\n\t\t\tlog: ctx.log,\n\t\t});\n\t\tif (useBroadcastChannel && 'BroadcastChannel' in window) {\n\t\t\tthis.broadcastChannel = new BroadcastChannel(`verdant-${ctx.namespace}`);\n\t\t\tthis.broadcastChannel.addEventListener(\n\t\t\t\t'message',\n\t\t\t\tthis.handleBroadcastChannelMessage,\n\t\t\t);\n\t\t}\n\t\tif (initialTransport === 'realtime') {\n\t\t\tthis.activeSync = this.webSocketSync;\n\t\t} else {\n\t\t\tthis.activeSync = this.pushPullSync;\n\t\t}\n\n\t\tthis.presence.subscribe('update', this.handlePresenceUpdate);\n\n\t\tthis.meta.subscribe('message', this.send);\n\n\t\tthis.webSocketSync.subscribe('message', this.handleMessage);\n\t\tthis.webSocketSync.subscribe('onlineChange', this.handleOnlineChange);\n\n\t\tthis.pushPullSync.subscribe('message', this.handleMessage);\n\t\tthis.pushPullSync.subscribe('onlineChange', this.handleOnlineChange);\n\n\t\tif (automaticTransportSelection && this.canDoRealtime) {\n\t\t\t// automatically shift between transport modes depending\n\t\t\t// on whether any peers are present (matching view if\n\t\t\t// applicable)\n\t\t\tconst decideIfUpgrade = () => {\n\t\t\t\tif (switchoverTimeout) {\n\t\t\t\t\tclearTimeout(switchoverTimeout);\n\t\t\t\t}\n\t\t\t\tconst hasPeers = this.presence.getViewPeers().length > 0;\n\t\t\t\tconst shouldUpgrade =\n\t\t\t\t\thasPeers ||\n\t\t\t\t\t(automaticTransportSelection !== 'peers-only' &&\n\t\t\t\t\t\tthis.presence.selfReplicaIds.size > 1);\n\t\t\t\tif (shouldUpgrade && this.mode === 'pull') {\n\t\t\t\t\tthis.setMode('realtime');\n\t\t\t\t} else if (!shouldUpgrade && this.mode === 'realtime') {\n\t\t\t\t\t// wait 1 second then switch to pull mode if still empty\n\t\t\t\t\tswitchoverTimeout = setTimeout(() => {\n\t\t\t\t\t\tif (this.presence.getViewPeers().length === 0) {\n\t\t\t\t\t\t\tthis.setMode('pull');\n\t\t\t\t\t\t}\n\t\t\t\t\t}, 1000);\n\t\t\t\t}\n\t\t\t};\n\t\t\tlet switchoverTimeout: NodeJS.Timeout;\n\t\t\tthis.presence.subscribe('peersChanged', decideIfUpgrade);\n\t\t\tif (automaticTransportSelection !== 'peers-only') {\n\t\t\t\tthis.presence.subscribe('selfChanged', decideIfUpgrade);\n\t\t\t}\n\t\t}\n\n\t\tif (autoStart) {\n\t\t\tthis.start();\n\t\t}\n\n\t\tif (EXPERIMENTAL_backgroundSync) {\n\t\t\tattemptToRegisterBackgroundSync();\n\t\t}\n\t}\n\n\tget canDoRealtime() {\n\t\treturn (\n\t\t\tthis.endpointProvider.type === ReplicaType.Realtime ||\n\t\t\tthis.endpointProvider.type === ReplicaType.PassiveRealtime ||\n\t\t\tthis.endpointProvider.type === ReplicaType.ReadOnlyRealtime\n\t\t);\n\t}\n\n\tget syncing() {\n\t\treturn this._activelySyncing;\n\t}\n\n\tprivate handleBroadcastChannelMessage = (event: MessageEvent) => {\n\t\tif (event.data.type === 'sync') {\n\t\t\tthis.handleMessage(event.data.message, { source: 'broadcastChannel' });\n\t\t}\n\t};\n\n\tprivate onTokenExpired = () => {\n\t\tthis.endpointProvider.clearCache();\n\t};\n\n\tprivate handleMessage = async (\n\t\tmessage: ServerMessage,\n\t\t{ source }: { source: 'network' | 'broadcastChannel' } = {\n\t\t\tsource: 'network',\n\t\t},\n\t) => {\n\t\t// TODO: move this into metadata\n\t\tif (message.type === 'op-re' || message.type === 'sync-resp') {\n\t\t\tfor (const op of message.operations) {\n\t\t\t\tthis.meta.time.update(op.timestamp);\n\t\t\t}\n\t\t}\n\n\t\tthis.log('debug', 'sync message', JSON.stringify(message, null, 2));\n\t\tswitch (message.type) {\n\t\t\tcase 'op-re':\n\t\t\t\tawait this.onData({\n\t\t\t\t\toperations: message.operations,\n\t\t\t\t\tbaselines: message.baselines,\n\t\t\t\t});\n\t\t\t\tif (message.globalAckTimestamp) {\n\t\t\t\t\tawait this.meta.setGlobalAck(message.globalAckTimestamp);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'global-ack':\n\t\t\t\tawait this.meta.setGlobalAck(message.timestamp);\n\t\t\t\tbreak;\n\t\t\tcase 'sync-resp':\n\t\t\t\tthis._activelySyncing = true;\n\t\t\t\tthis.emit('syncingChange', true);\n\t\t\t\tawait this.onData({\n\t\t\t\t\toperations: message.operations,\n\t\t\t\t\tbaselines: message.baselines,\n\t\t\t\t\treset: message.overwriteLocalData,\n\t\t\t\t});\n\n\t\t\t\tif (message.globalAckTimestamp) {\n\t\t\t\t\tawait this.meta.setGlobalAck(message.globalAckTimestamp);\n\t\t\t\t}\n\n\t\t\t\tawait this.meta.updateLastSynced(message.ackedTimestamp);\n\t\t\t\tthis._activelySyncing = false;\n\t\t\t\tthis.emit('syncingChange', false);\n\t\t\t\tbreak;\n\t\t\tcase 'need-since':\n\t\t\t\tthis.emit('serverReset', message.since);\n\t\t\t\tthis.activeSync.send(\n\t\t\t\t\tawait this.meta.messageCreator.createSyncStep1(message.since),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'server-ack':\n\t\t\t\tawait this.meta.updateLastSynced(message.timestamp);\n\t\t}\n\n\t\t// avoid rebroadcasting messages\n\t\tif (source === 'network') {\n\t\t\tthis.broadcastChannel?.postMessage({\n\t\t\t\ttype: 'sync',\n\t\t\t\tmessage,\n\t\t\t});\n\t\t}\n\n\t\t// update presence if necessary\n\t\tthis.presence[HANDLE_MESSAGE](await this.meta.localReplica.get(), message);\n\t};\n\tprivate handleOnlineChange = (online: boolean) => {\n\t\tthis.emit('onlineChange', online);\n\t};\n\tprivate handlePresenceUpdate = async (data: {\n\t\tpresence?: Presence;\n\t\tinternal?: VerdantInternalPresence;\n\t}) => {\n\t\tthis.send(await this.meta.messageCreator.createPresenceUpdate(data));\n\t};\n\n\tsetMode = (transport: SyncTransportMode) => {\n\t\tif (transport === 'realtime' && !this.canDoRealtime) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot switch to realtime mode, because the current auth token does not allow it`,\n\t\t\t);\n\t\t}\n\n\t\tlet newSync: SyncTransport;\n\t\tif (transport === 'realtime') {\n\t\t\tnewSync = this.webSocketSync;\n\t\t} else {\n\t\t\tnewSync = this.pushPullSync;\n\t\t}\n\n\t\tif (newSync === this.activeSync) return;\n\t\tthis.log('debug', 'switching to', transport, 'mode');\n\n\t\t// transfer state to new sync\n\t\tif (this.activeSync.status === 'active') {\n\t\t\tnewSync.start();\n\t\t}\n\t\tthis.activeSync.stop();\n\t\tthis.activeSync = newSync;\n\t};\n\n\tsetPullInterval = (interval: number) => {\n\t\tthis.pushPullSync.setInterval(interval);\n\t};\n\n\tget pullInterval() {\n\t\treturn this.pushPullSync.interval;\n\t}\n\n\tsend = async (message: ClientMessage) => {\n\t\tif (this.activeSync.status === 'active') {\n\t\t\t// before sync, replace 'originator' authz subjects\n\t\t\t// with token userId. This is the easiest place to\n\t\t\t// do this and allows the rest of the system to be\n\t\t\t// ambivalent about user identity when assigning\n\t\t\t// authorization for the current user.\n\t\t\tconst userId = this.endpointProvider.tokenInfo?.userId;\n\t\t\tif (!userId) {\n\t\t\t\tthrow new VerdantError(\n\t\t\t\t\tVerdantError.Code.Unexpected,\n\t\t\t\t\tundefined,\n\t\t\t\t\t'Active sync has invalid token info',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (message.type === 'sync' || message.type === 'op') {\n\t\t\t\trewriteAuthzOriginator(message, userId);\n\t\t\t}\n\t\t\tawait this.activeSync.send(message);\n\t\t\tthis.onOutgoingMessage?.(message);\n\t\t}\n\t};\n\n\tuploadFile = async (info: FileData) => {\n\t\tthis.log('info', 'Uploading file', {\n\t\t\tname: info.name,\n\t\t\ttype: info.type,\n\t\t\tid: info.id,\n\t\t\tsize: info.file?.size,\n\t\t});\n\t\tif (this.activeSync.status === 'active') {\n\t\t\treturn this.fileSync.uploadFile(info);\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\tretry: false,\n\t\t\t\terror: 'Sync is not active',\n\t\t\t};\n\t\t}\n\t};\n\n\tgetFile = async (id: string) => {\n\t\t// TODO: should this error? or just try anyway?\n\t\tif (this.activeSync.status === 'active') {\n\t\t\treturn this.fileSync.getFile(id);\n\t\t} else {\n\t\t\tthrow new Error('Offline, cannot retrieve remote file details');\n\t\t}\n\t};\n\n\tpublic start = () => {\n\t\treturn this.activeSync.start();\n\t};\n\n\tpublic stop = () => {\n\t\treturn this.activeSync.stop();\n\t};\n\n\tpublic ignoreIncoming(): void {\n\t\tthis.activeSync.ignoreIncoming();\n\t}\n\n\tpublic destroy = () => {\n\t\tthis.dispose();\n\t\tthis.webSocketSync.destroy();\n\t\tthis.pushPullSync.destroy();\n\t};\n\n\tpublic reconnect = () => {\n\t\treturn this.activeSync.reconnect();\n\t};\n\n\t/**\n\t * Runs one isolated sync cycle over HTTP. This is useful for\n\t * syncing via a periodic background job in a service worker,\n\t * which keeps a client up to date while the app isn't open.\n\t */\n\tpublic syncOnce = () => {\n\t\treturn this.pushPullSync.syncOnce();\n\t};\n\n\tpublic get isConnected(): boolean {\n\t\treturn this.activeSync.isConnected;\n\t}\n\n\tpublic get status() {\n\t\treturn this.activeSync.status;\n\t}\n\n\tpublic get mode() {\n\t\treturn this.activeSync.mode;\n\t}\n}\n", "import {\n\tDocumentBaseline,\n\tgetTimestampSchemaVersion,\n\tOperation,\n} from '@verdant-web/common';\n\nexport function getLatestVersion(data: {\n\toperations: Operation[];\n\tbaselines?: DocumentBaseline[];\n}) {\n\tconst timestamps = data.operations\n\t\t.map((op) => op.timestamp)\n\t\t.concat(data.baselines?.map((b) => b.timestamp) ?? []);\n\tconst latestVersion = timestamps.reduce((v, ts) => {\n\t\tconst tsVersion = getTimestampSchemaVersion(ts);\n\t\tif (tsVersion > v) {\n\t\t\treturn tsVersion;\n\t\t}\n\t\treturn v;\n\t}, 0);\n\n\treturn latestVersion;\n}\n", "import {\n\tdebounce,\n\tDocumentBaseline,\n\tEventSubscriber,\n\tgetTimestampSchemaVersion,\n\tMigration,\n\tOperation,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { DocumentManager } from '../entities/DocumentManager.js';\nimport { EntityStore } from '../entities/EntityStore.js';\nimport { FileManager, FileManagerConfig } from '../files/FileManager.js';\nimport { ReturnedFileData } from '../files/FileStorage.js';\nimport {\n\tcloseDatabase,\n\tdeleteAllDatabases,\n\tgetSizeOfObjectStore,\n} from '../idb.js';\nimport {\n\tExportData,\n\tMetadata,\n\tsupportLegacyExport,\n} from '../metadata/Metadata.js';\nimport { openQueryDatabase } from '../migration/openQueryDatabase.js';\nimport { CollectionQueries } from '../queries/CollectionQueries.js';\nimport { QueryCache } from '../queries/QueryCache.js';\nimport { NoSync, ServerSync, ServerSyncOptions, Sync } from '../sync/Sync.js';\nimport { getLatestVersion } from '../utils/versions.js';\n\ninterface ClientConfig<Presence = any> {\n\tsyncConfig?: ServerSyncOptions<Presence>;\n\tmigrations: Migration[];\n\tfiles?: FileManagerConfig;\n}\n\n// not actually used below, but helpful for internal code which\n// might rely on this stuff...\nexport type ClientWithCollections = Client & {\n\t[key: string]: CollectionQueries<any, any, any>;\n};\n\nexport class Client<Presence = any, Profile = any> extends EventSubscriber<{\n\t/**\n\t * Called when a change from a future version of the application has\n\t * been witnessed. These changes are not applied but it indicates\n\t * the app has been updated and a peer is using a newer version.\n\t * You should listen to this event and prompt the user to reload\n\t * their client, or reload it for them.\n\t *\n\t * This event may be called multiple times.\n\t */\n\tfutureSeen: () => void;\n\t/**\n\t * The server requested this replica reset its state\n\t * completely. This can happen when the replica has\n\t * been offline for too long and reconnects.\n\t */\n\tresetToServer: () => void;\n\t/**\n\t * These are errors that, as a developer, you should subscribe to\n\t * and prompt users to contact you for resolution. Usually these errors\n\t * indicate the client is in an unrecoverable state.\n\t */\n\tdeveloperError: (err: Error) => void;\n}> {\n\treadonly meta: Metadata;\n\tprivate _entities: EntityStore;\n\tprivate _queryCache: QueryCache;\n\tprivate _documentManager: DocumentManager<any>;\n\tprivate _fileManager: FileManager;\n\tprivate _closed = false;\n\n\treadonly collectionNames: string[];\n\n\tprivate _sync!: Sync<Presence, Profile>;\n\n\tget sync() {\n\t\treturn this._sync;\n\t}\n\n\tget entities() {\n\t\treturn this._entities;\n\t}\n\n\tget documentManager() {\n\t\treturn this._documentManager;\n\t}\n\n\tconstructor(\n\t\tprivate config: ClientConfig,\n\t\tprivate context: Context,\n\t\tcomponents: { meta: Metadata },\n\t) {\n\t\tsuper();\n\t\tthis.meta = components.meta;\n\t\tthis.collectionNames = Object.keys(context.schema.collections);\n\t\tthis._sync =\n\t\t\tthis.config.syncConfig && !context.schema.wip\n\t\t\t\t? new ServerSync<Presence, Profile>(this.config.syncConfig, {\n\t\t\t\t\t\tmeta: this.meta,\n\t\t\t\t\t\tonData: this.addData,\n\t\t\t\t\t\tctx: this.context,\n\t\t\t\t })\n\t\t\t\t: new NoSync<Presence, Profile>({ meta: this.meta });\n\t\tif (context.schema.wip && this.config.syncConfig) {\n\t\t\tcontext.log(\n\t\t\t\t'warn',\n\t\t\t\t'\u26A0\uFE0F\u26A0\uFE0F Sync is disabled for WIP schemas. Commit your schema changes to start syncing again. \u26A0\uFE0F\u26A0\uFE0F',\n\t\t\t);\n\t\t}\n\n\t\tthis._fileManager = new FileManager({\n\t\t\tdb: this.metaDb,\n\t\t\tsync: this.sync,\n\t\t\tcontext: this.context,\n\t\t\tconfig: this.config.files,\n\t\t\tmeta: this.meta,\n\t\t});\n\t\tthis._queryCache = new QueryCache({\n\t\t\tcontext,\n\t\t});\n\t\tthis._entities = new EntityStore({\n\t\t\tctx: this.context,\n\t\t\tmeta: this.meta,\n\t\t\tfiles: this._fileManager,\n\t\t});\n\t\tthis._documentManager = new DocumentManager(this.schema, this._entities);\n\n\t\tconst notifyFutureSeen = debounce(() => {\n\t\t\tthis.emit('futureSeen');\n\t\t}, 300);\n\t\tthis.context.globalEvents.subscribe('futureSeen', notifyFutureSeen);\n\t\tthis.context.globalEvents.subscribe('resetToServer', () => {\n\t\t\tthis.emit('resetToServer');\n\t\t});\n\n\t\tthis.watchForVersionChange();\n\n\t\tthis.metaDb.addEventListener('versionchange', () => {\n\t\t\tthis.context.log?.(\n\t\t\t\t'warn',\n\t\t\t\t`Another tab has requested a version change for ${this.namespace}`,\n\t\t\t);\n\t\t\tthis.metaDb.close();\n\t\t\tif (typeof window !== 'undefined') {\n\t\t\t\twindow.location.reload();\n\t\t\t}\n\t\t});\n\n\t\t// self-assign collection shortcuts. these are not typed\n\t\t// here but are typed in the generated code...\n\t\tfor (const [name, _collection] of Object.entries(\n\t\t\tcontext.schema.collections,\n\t\t)) {\n\t\t\tconst collectionName = name;\n\t\t\t(this as any)[collectionName] = new CollectionQueries({\n\t\t\t\tcollection: collectionName,\n\t\t\t\tcache: this._queryCache,\n\t\t\t\tcontext: this.context,\n\t\t\t\tentities: this.entities,\n\t\t\t\tdocumentManager: this.documentManager,\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate watchForVersionChange = () => {\n\t\tthis.documentDb.addEventListener('versionchange', () => {\n\t\t\tthis.context.log?.(\n\t\t\t\t'warn',\n\t\t\t\t`Another tab has requested a version change for ${this.namespace}`,\n\t\t\t);\n\t\t\tthis.documentDb.close();\n\t\t\tif (typeof window !== 'undefined') {\n\t\t\t\twindow.location.reload();\n\t\t\t}\n\t\t});\n\t};\n\n\tprivate importingPromise = Promise.resolve();\n\tprivate addData = async (data: {\n\t\toperations: Operation[];\n\t\tbaselines?: DocumentBaseline[];\n\t\treset?: boolean;\n\t}) => {\n\t\t// always wait for an ongoing import to complete before handling data.\n\t\tawait this.importingPromise;\n\n\t\ttry {\n\t\t\tconst schemaVersion = data.reset\n\t\t\t\t? getLatestVersion(data)\n\t\t\t\t: this.schema.version;\n\n\t\t\tif (schemaVersion < this.schema.version) {\n\t\t\t\t/**\n\t\t\t\t * Edge case: the server has an older version of the library\n\t\t\t\t * than the client schema, but it wants the client to reset.\n\t\t\t\t *\n\t\t\t\t * This happens when a truant or new client loads up newest client\n\t\t\t\t * code with a new schema version, but the last sync to the\n\t\t\t\t * server was from an old version. It's particularly a problem\n\t\t\t\t * if the new schema drops collections, since the IDB table for\n\t\t\t\t * that collection will no longer exist, so loading in old data\n\t\t\t\t * will result in an error.\n\t\t\t\t *\n\t\t\t\t * To handle this, we treat the reset data as if it were an import\n\t\t\t\t * of exported data. The import procedure handles older\n\t\t\t\t * schema versions by resetting the database to the imported\n\t\t\t\t * version, then migrating up to the current version.\n\t\t\t\t */\n\t\t\t\tthis.context.log(\n\t\t\t\t\t'warn',\n\t\t\t\t\t'Incoming reset sync data is from an old schema version',\n\t\t\t\t\tschemaVersion,\n\t\t\t\t\t`(current ${this.schema.version})`,\n\t\t\t\t);\n\t\t\t\t// run through the import flow to properly handle old versions\n\t\t\t\treturn await this.import({\n\t\t\t\t\tdata: {\n\t\t\t\t\t\toperations: data.operations,\n\t\t\t\t\t\tbaselines: data.baselines ?? [],\n\t\t\t\t\t\t// keep existing\n\t\t\t\t\t\tlocalReplica: undefined,\n\t\t\t\t\t\tschemaVersion,\n\t\t\t\t\t},\n\t\t\t\t\tfileData: [],\n\t\t\t\t\tfiles: [],\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\treturn await this._entities.addData(data);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthis.context.log('critical', 'Sync failed', err);\n\t\t\tthis.emit(\n\t\t\t\t'developerError',\n\t\t\t\tnew Error('Sync failed, see logs or cause', {\n\t\t\t\t\tcause: err,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tthrow err;\n\t\t}\n\t};\n\n\tget documentDb() {\n\t\treturn this.context.documentDb;\n\t}\n\n\tget metaDb() {\n\t\treturn this.context.metaDb;\n\t}\n\n\tget schema() {\n\t\treturn this.context.schema;\n\t}\n\n\tget namespace() {\n\t\treturn this.context.namespace;\n\t}\n\n\tget undoHistory() {\n\t\treturn this.context.undoHistory;\n\t}\n\n\t/**\n\t * Batch multiple operations together to be executed in a single transaction.\n\t * The changes made will not be included in the same undo history step as\n\t * any other changes made outside of the batch. You can also disable undo\n\t * for your batch to omit changes from undo history.\n\t *\n\t * Provide a batch name to apply multiple changes to the same batch\n\t * across different invocations. Batches will automatically flush after\n\t * a short delay or if they reach a maximum size.\n\t */\n\tget batch() {\n\t\treturn this.entities.batch;\n\t}\n\n\tstats = async (): Promise<ClientStats> => {\n\t\tconst collectionNames = Object.keys(this.schema.collections);\n\t\tlet collections = {} as Record<string, { count: number; size: number }>;\n\t\tif (this.disposed) {\n\t\t\treturn {} as any;\n\t\t}\n\t\tfor (const collectionName of collectionNames) {\n\t\t\ttry {\n\t\t\t\tcollections[collectionName] = await getSizeOfObjectStore(\n\t\t\t\t\tthis.documentDb,\n\t\t\t\t\tcollectionName,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\tthis.context.log?.('error', err);\n\t\t\t}\n\t\t}\n\t\tif (this.disposed) {\n\t\t\treturn { collections } as any;\n\t\t}\n\t\tconst meta = await this.meta.stats();\n\t\tconst storage =\n\t\t\ttypeof navigator !== 'undefined' &&\n\t\t\ttypeof navigator.storage !== 'undefined' &&\n\t\t\t'estimate' in navigator.storage\n\t\t\t\t? await navigator.storage.estimate()\n\t\t\t\t: undefined;\n\n\t\tconst files = await this._fileManager.stats();\n\n\t\t// determine data:metadata ratio for total size of all collections vs metadata\n\t\tconst totalCollectionsSize = Object.values(collections).reduce(\n\t\t\t(acc, { size }) => acc + size,\n\t\t\t0,\n\t\t);\n\t\tconst totalMetaSize = meta.baselinesSize.size + meta.operationsSize.size;\n\t\tconst metaToDataRatio = totalMetaSize / totalCollectionsSize;\n\n\t\treturn {\n\t\t\tcollections,\n\t\t\tmeta,\n\t\t\tstorage,\n\t\t\ttotalMetaSize,\n\t\t\ttotalCollectionsSize,\n\t\t\tmetaToDataRatio,\n\t\t\tfiles,\n\t\t\tquotaUsage:\n\t\t\t\tstorage?.usage && storage?.quota\n\t\t\t\t\t? storage.usage / storage.quota\n\t\t\t\t\t: undefined,\n\t\t};\n\t};\n\n\tclose = async () => {\n\t\tthis._closed = true;\n\t\tthis.sync.ignoreIncoming();\n\t\tawait this._entities.flushAllBatches();\n\t\tthis._fileManager.close();\n\t\tthis.sync.stop();\n\t\tthis.sync.destroy();\n\t\t// this step does have the potential to flush\n\t\t// changes to storage, so don't close metadata db yet\n\t\tawait this._entities.destroy();\n\n\t\tthis.meta.close();\n\n\t\t// the idea here is to flush the microtask queue -\n\t\t// we may have queued tasks related to queries that\n\t\t// we want to settle before closing the databases\n\t\t// to avoid invalid state errors\n\t\tawait new Promise<void>(async (resolve) => {\n\t\t\tawait closeDatabase(this.documentDb);\n\t\t\tawait closeDatabase(this.metaDb);\n\t\t\tresolve();\n\t\t});\n\n\t\tthis.context.log?.('info', 'Client closed');\n\t};\n\n\t__dangerous__resetLocal = async () => {\n\t\tthis.sync.stop();\n\t\tawait deleteAllDatabases(this.namespace, indexedDB);\n\t};\n\n\texport = async (\n\t\t{ downloadRemoteFiles }: { downloadRemoteFiles?: boolean } = {\n\t\t\tdownloadRemoteFiles: true,\n\t\t},\n\t) => {\n\t\tthis.context.log('info', 'Exporting data...');\n\t\tconst metaExport = await this.meta.export();\n\t\tconst filesExport = await this._fileManager.exportAll(downloadRemoteFiles);\n\t\t// split files into data and files\n\t\tconst fileData: Array<Omit<ReturnedFileData, 'file'>> = [];\n\t\tconst files: Array<File> = [];\n\n\t\tfor (const fileExport of filesExport) {\n\t\t\tconst file = fileExport.file;\n\t\t\tdelete fileExport.file;\n\t\t\tfileData.push(fileExport);\n\t\t\tif (file) {\n\t\t\t\t// rename with ID\n\t\t\t\tconst asFile = new File(\n\t\t\t\t\t[file],\n\t\t\t\t\tthis.getFileExportName(fileExport.name, fileExport.id),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: fileExport.type,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tfiles.push(asFile);\n\t\t\t} else {\n\t\t\t\tthis.context.log(\n\t\t\t\t\t'warn',\n\t\t\t\t\t`File ${fileExport.id} was could not be loaded locally or from the server. It will be missing in the export.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tdata: metaExport,\n\t\t\tfileData,\n\t\t\tfiles,\n\t\t};\n\t};\n\n\tprivate getFileExportName = (originalFileName: string, id: string) => {\n\t\treturn `${id}___${originalFileName}`;\n\t};\n\n\tprivate parseFileExportname = (name: string) => {\n\t\tconst [id, originalFileName] = name.split('___');\n\t\treturn { id, originalFileName };\n\t};\n\n\timport = async ({\n\t\tdata: rawData,\n\t\tfileData,\n\t\tfiles,\n\t}: {\n\t\tdata: ExportData;\n\t\tfileData: Array<Omit<ReturnedFileData, 'file'>>;\n\t\tfiles: File[];\n\t}) => {\n\t\t/**\n\t\t * Importing is a pretty involved procedure because of the possibility of\n\t\t * importing an export from an older version of the schema. We can't add\n\t\t * data from older schemas because the indexes may have changed or whole\n\t\t * collections may have been since deleted, leaving no corresponding IDB\n\t\t * tables.\n\t\t *\n\t\t * Since IDB doesn't allow us to go backwards, and we are resetting all\n\t\t * data anyways, the import procedure blows away the current queryable DB\n\t\t * and restarts from the imported schema version. It then migrates up\n\t\t * to the latest (current) version. These migrations are added to the imported\n\t\t * data to produce the final state.\n\t\t */\n\n\t\t// register importing promise to halt other data handling\n\t\tlet resolve = () => {};\n\t\tthis.importingPromise = new Promise<void>((res) => {\n\t\t\tresolve = res;\n\t\t});\n\n\t\tconst data = supportLegacyExport(rawData);\n\t\tthis.context.log('info', 'Importing data...');\n\t\t// close the document DB\n\t\tawait closeDatabase(this.context.documentDb);\n\n\t\tawait this.meta.resetFrom(data);\n\t\t// re-attach files to their file data and import\n\t\tconst fileToIdMap = new Map(\n\t\t\tfiles.map((file) => {\n\t\t\t\tconst { id } = this.parseFileExportname(file.name);\n\t\t\t\treturn [id, file];\n\t\t\t}),\n\t\t);\n\t\tconst importedFiles: ReturnedFileData[] = fileData.map((fileData) => {\n\t\t\tconst file = fileToIdMap.get(fileData.id);\n\n\t\t\treturn {\n\t\t\t\t...fileData,\n\t\t\t\tfile,\n\t\t\t};\n\t\t});\n\t\tawait this._fileManager.importAll(importedFiles);\n\t\t// now delete the document DB, open it to the specified version\n\t\t// and run migrations to get it to the latest version\n\t\tconst version = data.schemaVersion;\n\t\tconst deleteReq = indexedDB.deleteDatabase(\n\t\t\t[this.namespace, 'collections'].join('_'),\n\t\t);\n\t\tawait new Promise((resolve, reject) => {\n\t\t\tdeleteReq.onsuccess = resolve;\n\t\t\tdeleteReq.onerror = reject;\n\t\t});\n\t\t// reset our context to the imported schema for now\n\t\tconst currentSchema = this.context.schema;\n\t\tif (currentSchema.version !== version) {\n\t\t\tconst oldSchema = this.context.oldSchemas?.find(\n\t\t\t\t(s) => s.version === version,\n\t\t\t);\n\t\t\tif (!oldSchema) {\n\t\t\t\tthis.emit(\n\t\t\t\t\t'developerError',\n\t\t\t\t\tnew Error(`Could not find schema for version ${version}`),\n\t\t\t\t);\n\t\t\t\tthrow new Error(`Could not find schema for version ${version}`);\n\t\t\t}\n\n\t\t\tthis.context.schema = oldSchema;\n\t\t}\n\t\t// now open the document DB empty at the specified version\n\t\t// and initialize it from the meta DB\n\t\tthis.context.documentDb = await openQueryDatabase({\n\t\t\tmeta: this.meta,\n\t\t\tmigrations: this.config.migrations,\n\t\t\tcontext: this.context,\n\t\t\tversion,\n\t\t});\n\t\tthis.context.internalEvents.emit('documentDbChanged', this.documentDb);\n\t\t// re-initialize data\n\t\tthis.context.log('info', 'Re-initializing data from imported data...');\n\t\tawait this._entities.addData({\n\t\t\toperations: data.operations,\n\t\t\tbaselines: data.baselines,\n\t\t\treset: true,\n\t\t});\n\t\t// close the database and reopen to latest version, applying\n\t\t// migrations\n\t\tawait closeDatabase(this.context.documentDb);\n\t\tthis.context.log('info', 'Migrating up to latest schema...');\n\t\t// put the schema back\n\t\tthis.context.schema = currentSchema;\n\t\tthis.context.documentDb = await openQueryDatabase({\n\t\t\tmeta: this.meta,\n\t\t\tmigrations: this.config.migrations,\n\t\t\tcontext: this.context,\n\t\t\tversion: currentSchema.version,\n\t\t});\n\t\tthis.context.internalEvents.emit('documentDbChanged', this.documentDb);\n\t\t// re-establish watcher on database\n\t\tthis.watchForVersionChange();\n\n\t\t// finally... clear out memory cache of entities and\n\t\t// re-run all active queries.\n\t\tthis.entities.clearCache();\n\t\tthis._queryCache.forceRefreshAll();\n\n\t\tresolve();\n\t};\n\n\t/**\n\t * Export all data, then re-import it. This might resolve\n\t * some issues with the local database, but it should\n\t * only be done as a second-to-last resort. The last resort\n\t * would be __dangerous__resetLocal on ClientDescriptor, which\n\t * clears all local data.\n\t *\n\t * Unlike __dangerous__resetLocal, this method allows local-only\n\t * clients to recover data, whereas __dangerous__resetLocal only\n\t * lets networked clients recover from the server.\n\t */\n\t__dangerous__hardReset = async () => {\n\t\tconst exportData = await this.export();\n\t\tawait this.import(exportData);\n\t};\n\n\t/**\n\t * Immediately runs the file deletion process. This is useful\n\t * for testing, mostly. Or if your client is long-lived, since\n\t * normally this cleanup only runs on startup.\n\t *\n\t * Note this still follows the file deletion heuristic configured\n\t * on the client. So if you clean up files 3 days after delete,\n\t * invoking this manually will not skip that 3 day waiting period.\n\t */\n\t__cleanupFilesImmediately = () => {\n\t\treturn this._fileManager.tryCleanupDeletedFiles();\n\t};\n\n\t/**\n\t * Manually triggers storage rebasing. Follows normal\n\t * rebasing rules. Rebases already happen automatically\n\t * during normal operation, so you probably don't need this.\n\t */\n\t__manualRebase = () => this.meta.manualRebase();\n}\n\nexport interface ClientStats {\n\tcollections: Record<string, { count: number; size: number }>;\n\tmeta: {\n\t\tbaselinesSize: { count: number; size: number };\n\t\toperationsSize: { count: number; size: number };\n\t};\n\tfiles: {\n\t\tsize: { count: number; size: number };\n\t};\n\tstorage: StorageEstimate | undefined;\n\ttotalMetaSize: number;\n\ttotalCollectionsSize: number;\n\tmetaToDataRatio: number;\n\tquotaUsage: number | undefined;\n}\n", "/**\n * This exists since I'm a little anxious about using WeakRef in production\n * and want to be able to roll it back quickly to debug issues. Basically by adding\n * import { WeakRef } from 'FakeWeakRef' to the top of the file, we can switch back\n * to using a simple object reference.\n */\n\nexport class FakeWeakRef<T extends symbol | object> {\n\tconstructor(value: T) {\n\t\tthis.value = value;\n\t}\n\n\tvalue: T;\n\n\tderef(): T | undefined {\n\t\treturn this.value;\n\t}\n}\n", "export const METADATA_VERSION_KEY = Symbol('metadataVersion');\n", "import {\n\tEventSubscriber,\n\tMigration,\n\tOperation,\n\tStorageSchema,\n\thashObject,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { FileManagerConfig } from '../files/FileManager.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport {\n\topenMetadataDatabase,\n\topenWIPMetadataDatabase,\n} from '../metadata/openMetadataDatabase.js';\nimport { openWIPDatabase } from '../migration/openWIPDatabase.js';\nimport { ServerSyncOptions } from '../sync/Sync.js';\nimport { UndoHistory } from '../UndoHistory.js';\nimport { Client } from './Client.js';\nimport {\n\tdeleteAllDatabases,\n\tdeleteDatabase,\n\tgetAllDatabaseNamesAndVersions,\n} from '../idb.js';\nimport { FakeWeakRef } from '../FakeWeakRef.js';\nimport { METADATA_VERSION_KEY } from './constants.js';\nimport { openQueryDatabase } from '../migration/openQueryDatabase.js';\n\nexport interface ClientDescriptorOptions<Presence = any, Profile = any> {\n\t/** The schema used to create this client */\n\tschema: StorageSchema<any>;\n\toldSchemas?: StorageSchema<any>[];\n\t/** Migrations, in order, to upgrade to each successive version of the schema */\n\tmigrations: Migration<any>[];\n\t/** Provide a sync config to turn on synchronization with a server */\n\tsync?: ServerSyncOptions<Profile, Presence>;\n\t/** Optionally override the IndexedDB implementation */\n\tindexedDb?: IDBFactory;\n\t/**\n\t * Namespaces are used to separate data from different clients in IndexedDB.\n\t */\n\tnamespace: string;\n\t/**\n\t * Provide your own UndoHistory to have a unified undo system across multiple\n\t * clients if you so desire.\n\t */\n\tundoHistory?: UndoHistory;\n\t/**\n\t * Provide a log function to log internal debug messages\n\t */\n\tlog?: (\n\t\tlevel: 'debug' | 'info' | 'warn' | 'error' | 'critical',\n\t\t...args: any[]\n\t) => void;\n\tdisableRebasing?: boolean;\n\t/**\n\t * Provide a specific schema number to override the schema version\n\t * in the database. This is useful for testing migrations or recovering\n\t * from a mistakenly deployed incorrect schema. A specific version is required\n\t * so that you don't leave this on accidentally for all new schemas.\n\t */\n\toverrideSchemaConflict?: number;\n\t/**\n\t * Configuration for file management\n\t */\n\tfiles?: FileManagerConfig;\n\n\t/**\n\t * Listen for operations as they are applied to the database.\n\t * Wouldn't recommend using this unless you know what you're doing.\n\t * It's a very hot code path...\n\t */\n\tonOperation?: (operation: Operation) => void;\n\t/**\n\t * Enables experimental WeakRef usage to cull documents\n\t * from cache that aren't being used. This is a performance\n\t * optimization which has been tested under all Verdant's test\n\t * suites but I still want to keep testing it in the real world\n\t * before turning it on.\n\t */\n\tEXPERIMENTAL_weakRefs?: boolean;\n\n\t// not for public use\n\t[METADATA_VERSION_KEY]?: number;\n}\n\n/**\n * Since storage initialization is async, this class wraps the core\n * Storage creation promise and exposes some metadata which can\n * be useful immediately.\n */\nexport class ClientDescriptor<\n\tPresence = any,\n\tProfile = any,\n\tClientImpl extends Client = Client<Presence, Profile>,\n> {\n\tprivate readonly _readyPromise: Promise<ClientImpl>;\n\t// assertions because these are defined by plucking them from\n\t// Promise initializer\n\tprivate resolveReady!: (storage: ClientImpl) => void;\n\tprivate rejectReady!: (err: Error) => void;\n\tprivate _resolvedValue: ClientImpl | undefined;\n\tprivate _initializing = false;\n\tprivate _namespace: string;\n\n\tget namespace() {\n\t\treturn this._namespace;\n\t}\n\n\tconstructor(\n\t\tprivate readonly init: ClientDescriptorOptions<Presence, Profile>,\n\t) {\n\t\tthis._readyPromise = new Promise((resolve, reject) => {\n\t\t\tthis.resolveReady = resolve;\n\t\t\tthis.rejectReady = reject;\n\t\t});\n\t\tthis._namespace = init.namespace;\n\t}\n\n\tprivate initialize = async (init: ClientDescriptorOptions) => {\n\t\t// if server-side and no alternative IndexedDB implementation was provided,\n\t\t// we can't initialize the storage\n\t\tif (typeof window === 'undefined' && !init.indexedDb) {\n\t\t\tthrow new Error(\n\t\t\t\t'A verdant client was initialized in an environment without IndexedDB. If you are using verdant in a server-rendered framework, you must enforce that all clients are initialized on the client-side, or you must provide some mock interface of IDBFactory to the ClientDescriptor options.',\n\t\t\t);\n\t\t}\n\n\t\tif (this._initializing || this._resolvedValue) {\n\t\t\treturn this._readyPromise;\n\t\t}\n\t\tthis._initializing = true;\n\t\ttry {\n\t\t\tlet storage: ClientImpl;\n\t\t\tif (init.schema.wip) {\n\t\t\t\tstorage = await this.initializeWIPDatabases(init);\n\t\t\t} else {\n\t\t\t\tstorage = await this.initializeDatabases(init);\n\t\t\t\tthis.cleanupWIPDatabases(init);\n\t\t\t}\n\n\t\t\tthis.resolveReady(storage);\n\t\t\tthis._resolvedValue = storage;\n\t\t\treturn storage;\n\t\t} catch (err) {\n\t\t\tif (err instanceof Error) {\n\t\t\t\tthis.rejectReady(err as Error);\n\t\t\t\tthrow err;\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unknown error initializing storage');\n\t\t\t}\n\t\t} finally {\n\t\t\tthis._initializing = false;\n\t\t}\n\t};\n\n\tprivate initializeDatabases = async (init: ClientDescriptorOptions) => {\n\t\tconst metadataVersion = init[METADATA_VERSION_KEY];\n\t\tconst { db: metaDb } = await openMetadataDatabase({\n\t\t\tindexedDB: init.indexedDb,\n\t\t\tlog: init.log,\n\t\t\tnamespace: init.namespace,\n\t\t\tmetadataVersion,\n\t\t});\n\n\t\tconst context: Omit<Context, 'documentDb' | 'getNow'> = {\n\t\t\tnamespace: this._namespace,\n\t\t\tmetaDb,\n\t\t\tschema: init.schema,\n\t\t\tlog: init.log || (() => {}),\n\t\t\tundoHistory: init.undoHistory || new UndoHistory(),\n\t\t\tentityEvents: new EventSubscriber(),\n\t\t\tglobalEvents: new EventSubscriber(),\n\t\t\tinternalEvents: new EventSubscriber(),\n\t\t\tweakRef: (value) => {\n\t\t\t\tif (init.EXPERIMENTAL_weakRefs) {\n\t\t\t\t\treturn new WeakRef(value);\n\t\t\t\t} else {\n\t\t\t\t\treturn new FakeWeakRef(value) as unknown as WeakRef<typeof value>;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmigrations: init.migrations,\n\t\t\toldSchemas: init.oldSchemas,\n\t\t};\n\t\tconst meta = new Metadata({\n\t\t\tcontext,\n\t\t\tdisableRebasing: init.disableRebasing,\n\t\t\tonOperation: init.onOperation,\n\t\t});\n\n\t\t// verify schema integrity\n\t\tawait meta.updateSchema(init.schema, init.overrideSchemaConflict);\n\n\t\tconst contextWithNow: Omit<Context, 'documentDb'> = Object.assign(context, {\n\t\t\tgetNow: () => meta.now,\n\t\t});\n\n\t\tconst documentDb = await openQueryDatabase({\n\t\t\tcontext: contextWithNow,\n\t\t\tversion: init.schema.version,\n\t\t\tmeta,\n\t\t\tmigrations: init.migrations,\n\t\t\tindexedDB: init.indexedDb,\n\t\t});\n\n\t\tconst fullContext: Context = Object.assign(contextWithNow, { documentDb });\n\n\t\tconst storage = new Client(\n\t\t\t{\n\t\t\t\tsyncConfig: init.sync,\n\t\t\t\tmigrations: init.migrations,\n\t\t\t\tfiles: init.files,\n\t\t\t},\n\t\t\tfullContext,\n\t\t\t{\n\t\t\t\tmeta,\n\t\t\t},\n\t\t) as ClientImpl;\n\n\t\treturn storage;\n\t};\n\n\tprivate initializeWIPDatabases = async (init: ClientDescriptorOptions) => {\n\t\tconst schemaHash = hashObject(init.schema);\n\t\tconsole.info(`WIP schema in use. Opening database with hash ${schemaHash}`);\n\n\t\tconst wipNamespace = `@@wip_${init.namespace}_${schemaHash}`;\n\t\tconst { db: metaDb } = await openWIPMetadataDatabase({\n\t\t\tindexedDB: init.indexedDb,\n\t\t\tlog: init.log,\n\t\t\tnamespace: init.namespace,\n\t\t\twipNamespace: wipNamespace,\n\t\t});\n\n\t\tconst context: Omit<Context, 'documentDb' | 'getNow'> = {\n\t\t\tnamespace: this._namespace,\n\t\t\tmetaDb,\n\t\t\tschema: init.schema,\n\t\t\tlog: init.log || (() => {}),\n\t\t\tundoHistory: init.undoHistory || new UndoHistory(),\n\t\t\tentityEvents: new EventSubscriber(),\n\t\t\tglobalEvents: new EventSubscriber(),\n\t\t\tinternalEvents: new EventSubscriber(),\n\t\t\tweakRef: (value) => {\n\t\t\t\tif (init.EXPERIMENTAL_weakRefs) {\n\t\t\t\t\treturn new WeakRef(value);\n\t\t\t\t} else {\n\t\t\t\t\treturn new FakeWeakRef(value) as unknown as WeakRef<typeof value>;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmigrations: init.migrations,\n\t\t\toldSchemas: init.oldSchemas,\n\t\t};\n\t\tconst meta = new Metadata({\n\t\t\tcontext,\n\t\t\tdisableRebasing: init.disableRebasing,\n\t\t});\n\n\t\tconst contextWithNow: Omit<Context, 'documentDb'> = Object.assign(context, {\n\t\t\tgetNow: () => meta.now,\n\t\t});\n\n\t\t// verify schema integrity\n\t\tawait meta.updateSchema(init.schema, init.overrideSchemaConflict);\n\n\t\tconst documentDb = await openWIPDatabase({\n\t\t\tcontext: contextWithNow,\n\t\t\tversion: init.schema.version,\n\t\t\tmeta,\n\t\t\tmigrations: init.migrations,\n\t\t\tindexedDB: init.indexedDb,\n\t\t\twipNamespace,\n\t\t});\n\n\t\tconst fullContext: Context = Object.assign(contextWithNow, { documentDb });\n\n\t\tconst storage = new Client(\n\t\t\t{\n\t\t\t\tsyncConfig: init.sync,\n\t\t\t\tmigrations: init.migrations,\n\t\t\t\tfiles: init.files,\n\t\t\t},\n\t\t\tfullContext,\n\t\t\t{\n\t\t\t\tmeta,\n\t\t\t},\n\t\t) as ClientImpl;\n\n\t\treturn storage;\n\t};\n\n\tprivate cleanupWIPDatabases = async (init: ClientDescriptorOptions) => {\n\t\tconst databaseInfo = await getAllDatabaseNamesAndVersions(init.indexedDb);\n\t\tconst wipDatabases = databaseInfo\n\t\t\t.filter((db) => db.name?.startsWith('@@wip_'))\n\t\t\t.map((db) => db.name!);\n\t\t// don't clear a current WIP database.\n\t\tconst wipDatabasesToDelete = wipDatabases.filter(\n\t\t\t(db) =>\n\t\t\t\t!db.startsWith(`@@wip_${init.namespace}_${hashObject(init.schema)}`),\n\t\t);\n\t\tfor (const db of wipDatabasesToDelete) {\n\t\t\tawait deleteDatabase(db, init.indexedDb);\n\t\t}\n\t};\n\n\tget current() {\n\t\t// exposing an immediate value if already resolved lets us\n\t\t// skip the promise microtask when accessing this externally if\n\t\t// the initialization has been completed.\n\t\treturn this._resolvedValue;\n\t}\n\n\tget readyPromise() {\n\t\treturn this._readyPromise;\n\t}\n\n\tget schema() {\n\t\treturn this.init.schema;\n\t}\n\n\topen = () => this.initialize(this.init);\n\n\tclose = async () => {\n\t\tif (this._resolvedValue) {\n\t\t\tthis._resolvedValue.close();\n\t\t}\n\t\tif (this._initializing) {\n\t\t\t(await this._readyPromise).close();\n\t\t}\n\t};\n\n\t__dangerous__resetLocal = async () => {\n\t\tawait deleteAllDatabases(this.namespace);\n\t};\n}\n", "import cuid from 'cuid';\n\nexport function id(short?: boolean) {\n\tif (short) return cuid.slug();\n\treturn cuid();\n}\n", "import { authz } from '@verdant-web/common';\n\nexport const authorization = {\n\tprivate: authz.onlyMe(),\n\tpublic: undefined,\n};\n", "export function cliSync<Presence extends any = any>(\n\tlibraryId: string,\n\t{\n\t\tport = 3242,\n\t\tinitialPresence = {} as any,\n\t}: { port?: number; initialPresence?: Presence } = {},\n) {\n\tlet userId = localStorage.getItem('verdant-userId');\n\tif (!userId) {\n\t\tuserId = `user-${Math.random().toString(36).slice(2)}`;\n\t\tlocalStorage.setItem('verdant-userId', userId);\n\t}\n\treturn {\n\t\tdefaultProfile: { id: userId },\n\t\tinitialPresence,\n\t\tauthEndpoint: `http://localhost:${port}/auth/${libraryId}?userId=${userId}`,\n\t};\n}\n", "import * as everything from './index.js';\n\n(window as any).Verdant = everything;\n"],
|
|
5
|
-
"mappings": "8qBAAA,IAAAA,GAAAC,GAAA,CAAAC,GAAAC,KAAA,CAAAA,GAAO,QAAU,SAAcC,EAAKC,EAAM,CACxC,IAAIC,EAAI,YAAcF,EACtB,OAAOE,EAAE,OAAOA,EAAE,OAASD,CAAI,CACjC,ICHA,IAAAE,GAAAC,GAAA,CAAAC,GAAAC,KAAA,KAAIC,GAAM,KAENC,GAAM,OAAO,QAAW,SAAW,OAAS,KAC5CC,GAAc,OAAO,KAAKD,EAAG,EAAE,OAC/BE,GAAkB,UAAU,UAAY,UAAU,UAAU,OAAS,EACrEC,GAAWJ,IAAKG,GAClB,UAAU,UAAU,QAAQ,SAAS,EAAE,EACvCD,GAAY,SAAS,EAAE,EAAG,CAAC,EAE7BH,GAAO,QAAU,UAAwB,CACvC,OAAOK,EACT,ICXA,IAAAC,GAAAC,GAAA,CAAAC,GAAAC,KAAA,CACA,IAAIC,GAEAC,GAAS,OAAO,OAAW,MAC5B,OAAO,QAAU,OAAO,WACzB,OAAO,KAAS,KAChB,KAAK,OAEHA,IACIC,GAAM,KAAK,IAAI,EAAG,EAAE,EAAI,EAC5BF,GAAiB,UAAY,CACzB,OAAO,KAAK,IAAIC,GAAO,gBAAgB,IAAI,YAAY,CAAC,CAAC,EAAE,CAAC,EAAIC,EAAG,CACvE,GAEAF,GAAiB,KAAK,OALlB,IAAAE,GAQRH,GAAO,QAAUC,KCjBjB,IAAAG,GAAAC,G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pD,aAAa,QAAQ,iBAAkBA,CAAM,GAEvC,CACN,eAAgB,CAAE,GAAIA,CAAO,EAC7B,gBAAAD,EACA,aAAc,oBAAoBD,CAAI,SAASD,CAAS,WAAWG,CAAM,EAC1E,CACD,CCfC,OAAe,QAAUC",
|
|
4
|
+
"sourcesContent": ["module.exports = function pad (num, size) {\n var s = '000000000' + num;\n return s.substr(s.length - size);\n};\n", "var pad = require('./pad.js');\n\nvar env = typeof window === 'object' ? window : self;\nvar globalCount = Object.keys(env).length;\nvar mimeTypesLength = navigator.mimeTypes ? navigator.mimeTypes.length : 0;\nvar clientId = pad((mimeTypesLength +\n navigator.userAgent.length).toString(36) +\n globalCount.toString(36), 4);\n\nmodule.exports = function fingerprint () {\n return clientId;\n};\n", "\nvar getRandomValue;\n\nvar crypto = typeof window !== 'undefined' &&\n (window.crypto || window.msCrypto) ||\n typeof self !== 'undefined' &&\n self.crypto;\n\nif (crypto) {\n var lim = Math.pow(2, 32) - 1;\n getRandomValue = function () {\n return Math.abs(crypto.getRandomValues(new Uint32Array(1))[0] / lim);\n };\n} else {\n getRandomValue = Math.random;\n}\n\nmodule.exports = getRandomValue;\n", "/**\n * cuid.js\n * Collision-resistant UID generator for browsers and node.\n * Sequential for fast db lookups and recency sorting.\n * Safe for element IDs and server-side lookups.\n *\n * Extracted from CLCTR\n *\n * Copyright (c) Eric Elliott 2012\n * MIT License\n */\n\nvar fingerprint = require('./lib/fingerprint.js');\nvar pad = require('./lib/pad.js');\nvar getRandomValue = require('./lib/getRandomValue.js');\n\nvar c = 0,\n blockSize = 4,\n base = 36,\n discreteValues = Math.pow(base, blockSize);\n\nfunction randomBlock () {\n return pad((getRandomValue() *\n discreteValues << 0)\n .toString(base), blockSize);\n}\n\nfunction safeCounter () {\n c = c < discreteValues ? c : 0;\n c++; // this is not subliminal\n return c - 1;\n}\n\nfunction cuid () {\n // Starting with a lowercase letter makes\n // it HTML element ID friendly.\n var letter = 'c', // hard-coded allows for sequential access\n\n // timestamp\n // warning: this exposes the exact date and time\n // that the uid was created.\n timestamp = (new Date().getTime()).toString(base),\n\n // Prevent same-machine collisions.\n counter = pad(safeCounter().toString(base), blockSize),\n\n // A few chars to generate distinct ids for different\n // clients (so different computers are far less\n // likely to generate the same id)\n print = fingerprint(),\n\n // Grab some more chars from Math.random()\n random = randomBlock() + randomBlock();\n\n return letter + timestamp + counter + print + random;\n}\n\ncuid.slug = function slug () {\n var date = new Date().getTime().toString(36),\n counter = safeCounter().toString(36).slice(-4),\n print = fingerprint().slice(0, 1) +\n fingerprint().slice(-1),\n random = randomBlock().slice(-2);\n\n return date.slice(-2) +\n counter + print + random;\n};\n\ncuid.isCuid = function isCuid (stringToCheck) {\n if (typeof stringToCheck !== 'string') return false;\n if (stringToCheck.startsWith('c')) return true;\n return false;\n};\n\ncuid.isSlug = function isSlug (stringToCheck) {\n if (typeof stringToCheck !== 'string') return false;\n var stringLength = stringToCheck.length;\n if (stringLength >= 7 && stringLength <= 10) return true;\n return false;\n};\n\ncuid.fingerprint = fingerprint;\n\nmodule.exports = cuid;\n", "!function(e){var t;\"object\"==typeof exports?module.exports=e():\"function\"==typeof define&&define.amd?define(e):(\"undefined\"!=typeof window?t=window:\"undefined\"!=typeof global?t=global:\"undefined\"!=typeof self&&(t=self),t.objectHash=e())}(function(){return function r(o,i,u){function s(n,e){if(!i[n]){if(!o[n]){var t=\"function\"==typeof require&&require;if(!e&&t)return t(n,!0);if(a)return a(n,!0);throw new Error(\"Cannot find module '\"+n+\"'\")}e=i[n]={exports:{}};o[n][0].call(e.exports,function(e){var t=o[n][1][e];return s(t||e)},e,e.exports,r,o,i,u)}return i[n].exports}for(var a=\"function\"==typeof require&&require,e=0;e<u.length;e++)s(u[e]);return s}({1:[function(w,b,m){!function(e,n,s,c,d,h,p,g,y){\"use strict\";var r=w(\"crypto\");function t(e,t){t=u(e,t);var n;return void 0===(n=\"passthrough\"!==t.algorithm?r.createHash(t.algorithm):new l).write&&(n.write=n.update,n.end=n.update),f(t,n).dispatch(e),n.update||n.end(\"\"),n.digest?n.digest(\"buffer\"===t.encoding?void 0:t.encoding):(e=n.read(),\"buffer\"!==t.encoding?e.toString(t.encoding):e)}(m=b.exports=t).sha1=function(e){return t(e)},m.keys=function(e){return t(e,{excludeValues:!0,algorithm:\"sha1\",encoding:\"hex\"})},m.MD5=function(e){return t(e,{algorithm:\"md5\",encoding:\"hex\"})},m.keysMD5=function(e){return t(e,{algorithm:\"md5\",encoding:\"hex\",excludeValues:!0})};var o=r.getHashes?r.getHashes().slice():[\"sha1\",\"md5\"],i=(o.push(\"passthrough\"),[\"buffer\",\"hex\",\"binary\",\"base64\"]);function u(e,t){var n={};if(n.algorithm=(t=t||{}).algorithm||\"sha1\",n.encoding=t.encoding||\"hex\",n.excludeValues=!!t.excludeValues,n.algorithm=n.algorithm.toLowerCase(),n.encoding=n.encoding.toLowerCase(),n.ignoreUnknown=!0===t.ignoreUnknown,n.respectType=!1!==t.respectType,n.respectFunctionNames=!1!==t.respectFunctionNames,n.respectFunctionProperties=!1!==t.respectFunctionProperties,n.unorderedArrays=!0===t.unorderedArrays,n.unorderedSets=!1!==t.unorderedSets,n.unorderedObjects=!1!==t.unorderedObjects,n.replacer=t.replacer||void 0,n.excludeKeys=t.excludeKeys||void 0,void 0===e)throw new Error(\"Object argument required.\");for(var r=0;r<o.length;++r)o[r].toLowerCase()===n.algorithm.toLowerCase()&&(n.algorithm=o[r]);if(-1===o.indexOf(n.algorithm))throw new Error('Algorithm \"'+n.algorithm+'\" not supported. supported values: '+o.join(\", \"));if(-1===i.indexOf(n.encoding)&&\"passthrough\"!==n.algorithm)throw new Error('Encoding \"'+n.encoding+'\" not supported. supported values: '+i.join(\", \"));return n}function a(e){if(\"function\"==typeof e)return null!=/^function\\s+\\w*\\s*\\(\\s*\\)\\s*{\\s+\\[native code\\]\\s+}$/i.exec(Function.prototype.toString.call(e))}function f(o,t,i){i=i||[];function u(e){return t.update?t.update(e,\"utf8\"):t.write(e,\"utf8\")}return{dispatch:function(e){return this[\"_\"+(null===(e=o.replacer?o.replacer(e):e)?\"null\":typeof e)](e)},_object:function(t){var n,e=Object.prototype.toString.call(t),r=/\\[object (.*)\\]/i.exec(e);r=(r=r?r[1]:\"unknown:[\"+e+\"]\").toLowerCase();if(0<=(e=i.indexOf(t)))return this.dispatch(\"[CIRCULAR:\"+e+\"]\");if(i.push(t),void 0!==s&&s.isBuffer&&s.isBuffer(t))return u(\"buffer:\"),u(t);if(\"object\"===r||\"function\"===r||\"asyncfunction\"===r)return e=Object.keys(t),o.unorderedObjects&&(e=e.sort()),!1===o.respectType||a(t)||e.splice(0,0,\"prototype\",\"__proto__\",\"constructor\"),o.excludeKeys&&(e=e.filter(function(e){return!o.excludeKeys(e)})),u(\"object:\"+e.length+\":\"),n=this,e.forEach(function(e){n.dispatch(e),u(\":\"),o.excludeValues||n.dispatch(t[e]),u(\",\")});if(!this[\"_\"+r]){if(o.ignoreUnknown)return u(\"[\"+r+\"]\");throw new Error('Unknown object type \"'+r+'\"')}this[\"_\"+r](t)},_array:function(e,t){t=void 0!==t?t:!1!==o.unorderedArrays;var n=this;if(u(\"array:\"+e.length+\":\"),!t||e.length<=1)return e.forEach(function(e){return n.dispatch(e)});var r=[],t=e.map(function(e){var t=new l,n=i.slice();return f(o,t,n).dispatch(e),r=r.concat(n.slice(i.length)),t.read().toString()});return i=i.concat(r),t.sort(),this._array(t,!1)},_date:function(e){return u(\"date:\"+e.toJSON())},_symbol:function(e){return u(\"symbol:\"+e.toString())},_error:function(e){return u(\"error:\"+e.toString())},_boolean:function(e){return u(\"bool:\"+e.toString())},_string:function(e){u(\"string:\"+e.length+\":\"),u(e.toString())},_function:function(e){u(\"fn:\"),a(e)?this.dispatch(\"[native]\"):this.dispatch(e.toString()),!1!==o.respectFunctionNames&&this.dispatch(\"function-name:\"+String(e.name)),o.respectFunctionProperties&&this._object(e)},_number:function(e){return u(\"number:\"+e.toString())},_xml:function(e){return u(\"xml:\"+e.toString())},_null:function(){return u(\"Null\")},_undefined:function(){return u(\"Undefined\")},_regexp:function(e){return u(\"regex:\"+e.toString())},_uint8array:function(e){return u(\"uint8array:\"),this.dispatch(Array.prototype.slice.call(e))},_uint8clampedarray:function(e){return u(\"uint8clampedarray:\"),this.dispatch(Array.prototype.slice.call(e))},_int8array:function(e){return u(\"int8array:\"),this.dispatch(Array.prototype.slice.call(e))},_uint16array:function(e){return u(\"uint16array:\"),this.dispatch(Array.prototype.slice.call(e))},_int16array:function(e){return u(\"int16array:\"),this.dispatch(Array.prototype.slice.call(e))},_uint32array:function(e){return u(\"uint32array:\"),this.dispatch(Array.prototype.slice.call(e))},_int32array:function(e){return u(\"int32array:\"),this.dispatch(Array.prototype.slice.call(e))},_float32array:function(e){return u(\"float32array:\"),this.dispatch(Array.prototype.slice.call(e))},_float64array:function(e){return u(\"float64array:\"),this.dispatch(Array.prototype.slice.call(e))},_arraybuffer:function(e){return u(\"arraybuffer:\"),this.dispatch(new Uint8Array(e))},_url:function(e){return u(\"url:\"+e.toString())},_map:function(e){u(\"map:\");e=Array.from(e);return this._array(e,!1!==o.unorderedSets)},_set:function(e){u(\"set:\");e=Array.from(e);return this._array(e,!1!==o.unorderedSets)},_file:function(e){return u(\"file:\"),this.dispatch([e.name,e.size,e.type,e.lastModfied])},_blob:function(){if(o.ignoreUnknown)return u(\"[blob]\");throw Error('Hashing Blob objects is currently not supported\\n(see https://github.com/puleos/object-hash/issues/26)\\nUse \"options.replacer\" or \"options.ignoreUnknown\"\\n')},_domwindow:function(){return u(\"domwindow\")},_bigint:function(e){return u(\"bigint:\"+e.toString())},_process:function(){return u(\"process\")},_timer:function(){return u(\"timer\")},_pipe:function(){return u(\"pipe\")},_tcp:function(){return u(\"tcp\")},_udp:function(){return u(\"udp\")},_tty:function(){return u(\"tty\")},_statwatcher:function(){return u(\"statwatcher\")},_securecontext:function(){return u(\"securecontext\")},_connection:function(){return u(\"connection\")},_zlib:function(){return u(\"zlib\")},_context:function(){return u(\"context\")},_nodescript:function(){return u(\"nodescript\")},_httpparser:function(){return u(\"httpparser\")},_dataview:function(){return u(\"dataview\")},_signal:function(){return u(\"signal\")},_fsevent:function(){return u(\"fsevent\")},_tlswrap:function(){return u(\"tlswrap\")}}}function l(){return{buf:\"\",write:function(e){this.buf+=e},end:function(e){this.buf+=e},read:function(){return this.buf}}}m.writeToStream=function(e,t,n){return void 0===n&&(n=t,t={}),f(t=u(e,t),n).dispatch(e)}}.call(this,w(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},w(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/fake_9a5aa49d.js\",\"/\")},{buffer:3,crypto:5,lYpoI2:11}],2:[function(e,t,f){!function(e,t,n,r,o,i,u,s,a){!function(e){\"use strict\";var a=\"undefined\"!=typeof Uint8Array?Uint8Array:Array,t=\"+\".charCodeAt(0),n=\"/\".charCodeAt(0),r=\"0\".charCodeAt(0),o=\"a\".charCodeAt(0),i=\"A\".charCodeAt(0),u=\"-\".charCodeAt(0),s=\"_\".charCodeAt(0);function f(e){e=e.charCodeAt(0);return e===t||e===u?62:e===n||e===s?63:e<r?-1:e<r+10?e-r+26+26:e<i+26?e-i:e<o+26?e-o+26:void 0}e.toByteArray=function(e){var t,n;if(0<e.length%4)throw new Error(\"Invalid string. Length must be a multiple of 4\");var r=e.length,r=\"=\"===e.charAt(r-2)?2:\"=\"===e.charAt(r-1)?1:0,o=new a(3*e.length/4-r),i=0<r?e.length-4:e.length,u=0;function s(e){o[u++]=e}for(t=0;t<i;t+=4,0)s((16711680&(n=f(e.charAt(t))<<18|f(e.charAt(t+1))<<12|f(e.charAt(t+2))<<6|f(e.charAt(t+3))))>>16),s((65280&n)>>8),s(255&n);return 2==r?s(255&(n=f(e.charAt(t))<<2|f(e.charAt(t+1))>>4)):1==r&&(s((n=f(e.charAt(t))<<10|f(e.charAt(t+1))<<4|f(e.charAt(t+2))>>2)>>8&255),s(255&n)),o},e.fromByteArray=function(e){var t,n,r,o,i=e.length%3,u=\"\";function s(e){return\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\".charAt(e)}for(t=0,r=e.length-i;t<r;t+=3)n=(e[t]<<16)+(e[t+1]<<8)+e[t+2],u+=s((o=n)>>18&63)+s(o>>12&63)+s(o>>6&63)+s(63&o);switch(i){case 1:u=(u+=s((n=e[e.length-1])>>2))+s(n<<4&63)+\"==\";break;case 2:u=(u=(u+=s((n=(e[e.length-2]<<8)+e[e.length-1])>>10))+s(n>>4&63))+s(n<<2&63)+\"=\"}return u}}(void 0===f?this.base64js={}:f)}.call(this,e(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},e(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js\",\"/node_modules/gulp-browserify/node_modules/base64-js/lib\")},{buffer:3,lYpoI2:11}],3:[function(O,e,H){!function(e,n,f,r,h,p,g,y,w){var a=O(\"base64-js\"),i=O(\"ieee754\");function f(e,t,n){if(!(this instanceof f))return new f(e,t,n);var r,o,i,u,s=typeof e;if(\"base64\"===t&&\"string\"==s)for(e=(u=e).trim?u.trim():u.replace(/^\\s+|\\s+$/g,\"\");e.length%4!=0;)e+=\"=\";if(\"number\"==s)r=j(e);else if(\"string\"==s)r=f.byteLength(e,t);else{if(\"object\"!=s)throw new Error(\"First argument needs to be a number, array or string.\");r=j(e.length)}if(f._useTypedArrays?o=f._augment(new Uint8Array(r)):((o=this).length=r,o._isBuffer=!0),f._useTypedArrays&&\"number\"==typeof e.byteLength)o._set(e);else if(C(u=e)||f.isBuffer(u)||u&&\"object\"==typeof u&&\"number\"==typeof u.length)for(i=0;i<r;i++)f.isBuffer(e)?o[i]=e.readUInt8(i):o[i]=e[i];else if(\"string\"==s)o.write(e,0,t);else if(\"number\"==s&&!f._useTypedArrays&&!n)for(i=0;i<r;i++)o[i]=0;return o}function b(e,t,n,r){return f._charsWritten=c(function(e){for(var t=[],n=0;n<e.length;n++)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function m(e,t,n,r){return f._charsWritten=c(function(e){for(var t,n,r=[],o=0;o<e.length;o++)n=e.charCodeAt(o),t=n>>8,n=n%256,r.push(n),r.push(t);return r}(t),e,n,r)}function v(e,t,n){var r=\"\";n=Math.min(e.length,n);for(var o=t;o<n;o++)r+=String.fromCharCode(e[o]);return r}function o(e,t,n,r){r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(null!=t,\"missing offset\"),d(t+1<e.length,\"Trying to read beyond buffer length\"));var o,r=e.length;if(!(r<=t))return n?(o=e[t],t+1<r&&(o|=e[t+1]<<8)):(o=e[t]<<8,t+1<r&&(o|=e[t+1])),o}function u(e,t,n,r){r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(null!=t,\"missing offset\"),d(t+3<e.length,\"Trying to read beyond buffer length\"));var o,r=e.length;if(!(r<=t))return n?(t+2<r&&(o=e[t+2]<<16),t+1<r&&(o|=e[t+1]<<8),o|=e[t],t+3<r&&(o+=e[t+3]<<24>>>0)):(t+1<r&&(o=e[t+1]<<16),t+2<r&&(o|=e[t+2]<<8),t+3<r&&(o|=e[t+3]),o+=e[t]<<24>>>0),o}function _(e,t,n,r){if(r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(null!=t,\"missing offset\"),d(t+1<e.length,\"Trying to read beyond buffer length\")),!(e.length<=t))return r=o(e,t,n,!0),32768&r?-1*(65535-r+1):r}function E(e,t,n,r){if(r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(null!=t,\"missing offset\"),d(t+3<e.length,\"Trying to read beyond buffer length\")),!(e.length<=t))return r=u(e,t,n,!0),2147483648&r?-1*(4294967295-r+1):r}function I(e,t,n,r){return r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(t+3<e.length,\"Trying to read beyond buffer length\")),i.read(e,t,n,23,4)}function A(e,t,n,r){return r||(d(\"boolean\"==typeof n,\"missing or invalid endian\"),d(t+7<e.length,\"Trying to read beyond buffer length\")),i.read(e,t,n,52,8)}function s(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+1<e.length,\"trying to write beyond buffer length\"),Y(t,65535));o=e.length;if(!(o<=n))for(var i=0,u=Math.min(o-n,2);i<u;i++)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function l(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+3<e.length,\"trying to write beyond buffer length\"),Y(t,4294967295));o=e.length;if(!(o<=n))for(var i=0,u=Math.min(o-n,4);i<u;i++)e[n+i]=t>>>8*(r?i:3-i)&255}function B(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+1<e.length,\"Trying to write beyond buffer length\"),F(t,32767,-32768)),e.length<=n||s(e,0<=t?t:65535+t+1,n,r,o)}function L(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+3<e.length,\"Trying to write beyond buffer length\"),F(t,2147483647,-2147483648)),e.length<=n||l(e,0<=t?t:4294967295+t+1,n,r,o)}function U(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+3<e.length,\"Trying to write beyond buffer length\"),D(t,34028234663852886e22,-34028234663852886e22)),e.length<=n||i.write(e,t,n,r,23,4)}function x(e,t,n,r,o){o||(d(null!=t,\"missing value\"),d(\"boolean\"==typeof r,\"missing or invalid endian\"),d(null!=n,\"missing offset\"),d(n+7<e.length,\"Trying to write beyond buffer length\"),D(t,17976931348623157e292,-17976931348623157e292)),e.length<=n||i.write(e,t,n,r,52,8)}H.Buffer=f,H.SlowBuffer=f,H.INSPECT_MAX_BYTES=50,f.poolSize=8192,f._useTypedArrays=function(){try{var e=new ArrayBuffer(0),t=new Uint8Array(e);return t.foo=function(){return 42},42===t.foo()&&\"function\"==typeof t.subarray}catch(e){return!1}}(),f.isEncoding=function(e){switch(String(e).toLowerCase()){case\"hex\":case\"utf8\":case\"utf-8\":case\"ascii\":case\"binary\":case\"base64\":case\"raw\":case\"ucs2\":case\"ucs-2\":case\"utf16le\":case\"utf-16le\":return!0;default:return!1}},f.isBuffer=function(e){return!(null==e||!e._isBuffer)},f.byteLength=function(e,t){var n;switch(e+=\"\",t||\"utf8\"){case\"hex\":n=e.length/2;break;case\"utf8\":case\"utf-8\":n=T(e).length;break;case\"ascii\":case\"binary\":case\"raw\":n=e.length;break;case\"base64\":n=M(e).length;break;case\"ucs2\":case\"ucs-2\":case\"utf16le\":case\"utf-16le\":n=2*e.length;break;default:throw new Error(\"Unknown encoding\")}return n},f.concat=function(e,t){if(d(C(e),\"Usage: Buffer.concat(list, [totalLength])\\nlist should be an Array.\"),0===e.length)return new f(0);if(1===e.length)return e[0];if(\"number\"!=typeof t)for(o=t=0;o<e.length;o++)t+=e[o].length;for(var n=new f(t),r=0,o=0;o<e.length;o++){var i=e[o];i.copy(n,r),r+=i.length}return n},f.prototype.write=function(e,t,n,r){isFinite(t)?isFinite(n)||(r=n,n=void 0):(a=r,r=t,t=n,n=a),t=Number(t)||0;var o,i,u,s,a=this.length-t;switch((!n||a<(n=Number(n)))&&(n=a),r=String(r||\"utf8\").toLowerCase()){case\"hex\":o=function(e,t,n,r){n=Number(n)||0;var o=e.length-n;(!r||o<(r=Number(r)))&&(r=o),d((o=t.length)%2==0,\"Invalid hex string\"),o/2<r&&(r=o/2);for(var i=0;i<r;i++){var u=parseInt(t.substr(2*i,2),16);d(!isNaN(u),\"Invalid hex string\"),e[n+i]=u}return f._charsWritten=2*i,i}(this,e,t,n);break;case\"utf8\":case\"utf-8\":i=this,u=t,s=n,o=f._charsWritten=c(T(e),i,u,s);break;case\"ascii\":case\"binary\":o=b(this,e,t,n);break;case\"base64\":i=this,u=t,s=n,o=f._charsWritten=c(M(e),i,u,s);break;case\"ucs2\":case\"ucs-2\":case\"utf16le\":case\"utf-16le\":o=m(this,e,t,n);break;default:throw new Error(\"Unknown encoding\")}return o},f.prototype.toString=function(e,t,n){var r,o,i,u,s=this;if(e=String(e||\"utf8\").toLowerCase(),t=Number(t)||0,(n=void 0!==n?Number(n):s.length)===t)return\"\";switch(e){case\"hex\":r=function(e,t,n){var r=e.length;(!t||t<0)&&(t=0);(!n||n<0||r<n)&&(n=r);for(var o=\"\",i=t;i<n;i++)o+=k(e[i]);return o}(s,t,n);break;case\"utf8\":case\"utf-8\":r=function(e,t,n){var r=\"\",o=\"\";n=Math.min(e.length,n);for(var i=t;i<n;i++)e[i]<=127?(r+=N(o)+String.fromCharCode(e[i]),o=\"\"):o+=\"%\"+e[i].toString(16);return r+N(o)}(s,t,n);break;case\"ascii\":case\"binary\":r=v(s,t,n);break;case\"base64\":o=s,u=n,r=0===(i=t)&&u===o.length?a.fromByteArray(o):a.fromByteArray(o.slice(i,u));break;case\"ucs2\":case\"ucs-2\":case\"utf16le\":case\"utf-16le\":r=function(e,t,n){for(var r=e.slice(t,n),o=\"\",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}(s,t,n);break;default:throw new Error(\"Unknown encoding\")}return r},f.prototype.toJSON=function(){return{type:\"Buffer\",data:Array.prototype.slice.call(this._arr||this,0)}},f.prototype.copy=function(e,t,n,r){if(t=t||0,(r=r||0===r?r:this.length)!==(n=n||0)&&0!==e.length&&0!==this.length){d(n<=r,\"sourceEnd < sourceStart\"),d(0<=t&&t<e.length,\"targetStart out of bounds\"),d(0<=n&&n<this.length,\"sourceStart out of bounds\"),d(0<=r&&r<=this.length,\"sourceEnd out of bounds\"),r>this.length&&(r=this.length);var o=(r=e.length-t<r-n?e.length-t+n:r)-n;if(o<100||!f._useTypedArrays)for(var i=0;i<o;i++)e[i+t]=this[i+n];else e._set(this.subarray(n,n+o),t)}},f.prototype.slice=function(e,t){var n=this.length;if(e=S(e,n,0),t=S(t,n,n),f._useTypedArrays)return f._augment(this.subarray(e,t));for(var r=t-e,o=new f(r,void 0,!0),i=0;i<r;i++)o[i]=this[i+e];return o},f.prototype.get=function(e){return console.log(\".get() is deprecated. Access using array indexes instead.\"),this.readUInt8(e)},f.prototype.set=function(e,t){return console.log(\".set() is deprecated. Access using array indexes instead.\"),this.writeUInt8(e,t)},f.prototype.readUInt8=function(e,t){if(t||(d(null!=e,\"missing offset\"),d(e<this.length,\"Trying to read beyond buffer length\")),!(e>=this.length))return this[e]},f.prototype.readUInt16LE=function(e,t){return o(this,e,!0,t)},f.prototype.readUInt16BE=function(e,t){return o(this,e,!1,t)},f.prototype.readUInt32LE=function(e,t){return u(this,e,!0,t)},f.prototype.readUInt32BE=function(e,t){return u(this,e,!1,t)},f.prototype.readInt8=function(e,t){if(t||(d(null!=e,\"missing offset\"),d(e<this.length,\"Trying to read beyond buffer length\")),!(e>=this.length))return 128&this[e]?-1*(255-this[e]+1):this[e]},f.prototype.readInt16LE=function(e,t){return _(this,e,!0,t)},f.prototype.readInt16BE=function(e,t){return _(this,e,!1,t)},f.prototype.readInt32LE=function(e,t){return E(this,e,!0,t)},f.prototype.readInt32BE=function(e,t){return E(this,e,!1,t)},f.prototype.readFloatLE=function(e,t){return I(this,e,!0,t)},f.prototype.readFloatBE=function(e,t){return I(this,e,!1,t)},f.prototype.readDoubleLE=function(e,t){return A(this,e,!0,t)},f.prototype.readDoubleBE=function(e,t){return A(this,e,!1,t)},f.prototype.writeUInt8=function(e,t,n){n||(d(null!=e,\"missing value\"),d(null!=t,\"missing offset\"),d(t<this.length,\"trying to write beyond buffer length\"),Y(e,255)),t>=this.length||(this[t]=e)},f.prototype.writeUInt16LE=function(e,t,n){s(this,e,t,!0,n)},f.prototype.writeUInt16BE=function(e,t,n){s(this,e,t,!1,n)},f.prototype.writeUInt32LE=function(e,t,n){l(this,e,t,!0,n)},f.prototype.writeUInt32BE=function(e,t,n){l(this,e,t,!1,n)},f.prototype.writeInt8=function(e,t,n){n||(d(null!=e,\"missing value\"),d(null!=t,\"missing offset\"),d(t<this.length,\"Trying to write beyond buffer length\"),F(e,127,-128)),t>=this.length||(0<=e?this.writeUInt8(e,t,n):this.writeUInt8(255+e+1,t,n))},f.prototype.writeInt16LE=function(e,t,n){B(this,e,t,!0,n)},f.prototype.writeInt16BE=function(e,t,n){B(this,e,t,!1,n)},f.prototype.writeInt32LE=function(e,t,n){L(this,e,t,!0,n)},f.prototype.writeInt32BE=function(e,t,n){L(this,e,t,!1,n)},f.prototype.writeFloatLE=function(e,t,n){U(this,e,t,!0,n)},f.prototype.writeFloatBE=function(e,t,n){U(this,e,t,!1,n)},f.prototype.writeDoubleLE=function(e,t,n){x(this,e,t,!0,n)},f.prototype.writeDoubleBE=function(e,t,n){x(this,e,t,!1,n)},f.prototype.fill=function(e,t,n){if(t=t||0,n=n||this.length,d(\"number\"==typeof(e=\"string\"==typeof(e=e||0)?e.charCodeAt(0):e)&&!isNaN(e),\"value is not a number\"),d(t<=n,\"end < start\"),n!==t&&0!==this.length){d(0<=t&&t<this.length,\"start out of bounds\"),d(0<=n&&n<=this.length,\"end out of bounds\");for(var r=t;r<n;r++)this[r]=e}},f.prototype.inspect=function(){for(var e=[],t=this.length,n=0;n<t;n++)if(e[n]=k(this[n]),n===H.INSPECT_MAX_BYTES){e[n+1]=\"...\";break}return\"<Buffer \"+e.join(\" \")+\">\"},f.prototype.toArrayBuffer=function(){if(\"undefined\"==typeof Uint8Array)throw new Error(\"Buffer.toArrayBuffer not supported in this browser\");if(f._useTypedArrays)return new f(this).buffer;for(var e=new Uint8Array(this.length),t=0,n=e.length;t<n;t+=1)e[t]=this[t];return e.buffer};var t=f.prototype;function S(e,t,n){return\"number\"!=typeof e?n:t<=(e=~~e)?t:0<=e||0<=(e+=t)?e:0}function j(e){return(e=~~Math.ceil(+e))<0?0:e}function C(e){return(Array.isArray||function(e){return\"[object Array]\"===Object.prototype.toString.call(e)})(e)}function k(e){return e<16?\"0\"+e.toString(16):e.toString(16)}function T(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<=127)t.push(e.charCodeAt(n));else for(var o=n,i=(55296<=r&&r<=57343&&n++,encodeURIComponent(e.slice(o,n+1)).substr(1).split(\"%\")),u=0;u<i.length;u++)t.push(parseInt(i[u],16))}return t}function M(e){return a.toByteArray(e)}function c(e,t,n,r){for(var o=0;o<r&&!(o+n>=t.length||o>=e.length);o++)t[o+n]=e[o];return o}function N(e){try{return decodeURIComponent(e)}catch(e){return String.fromCharCode(65533)}}function Y(e,t){d(\"number\"==typeof e,\"cannot write a non-number as a number\"),d(0<=e,\"specified a negative value for writing an unsigned value\"),d(e<=t,\"value is larger than maximum value for type\"),d(Math.floor(e)===e,\"value has a fractional component\")}function F(e,t,n){d(\"number\"==typeof e,\"cannot write a non-number as a number\"),d(e<=t,\"value larger than maximum allowed value\"),d(n<=e,\"value smaller than minimum allowed value\"),d(Math.floor(e)===e,\"value has a fractional component\")}function D(e,t,n){d(\"number\"==typeof e,\"cannot write a non-number as a number\"),d(e<=t,\"value larger than maximum allowed value\"),d(n<=e,\"value smaller than minimum allowed value\")}function d(e,t){if(!e)throw new Error(t||\"Failed assertion\")}f._augment=function(e){return e._isBuffer=!0,e._get=e.get,e._set=e.set,e.get=t.get,e.set=t.set,e.write=t.write,e.toString=t.toString,e.toLocaleString=t.toString,e.toJSON=t.toJSON,e.copy=t.copy,e.slice=t.slice,e.readUInt8=t.readUInt8,e.readUInt16LE=t.readUInt16LE,e.readUInt16BE=t.readUInt16BE,e.readUInt32LE=t.readUInt32LE,e.readUInt32BE=t.readUInt32BE,e.readInt8=t.readInt8,e.readInt16LE=t.readInt16LE,e.readInt16BE=t.readInt16BE,e.readInt32LE=t.readInt32LE,e.readInt32BE=t.readInt32BE,e.readFloatLE=t.readFloatLE,e.readFloatBE=t.readFloatBE,e.readDoubleLE=t.readDoubleLE,e.readDoubleBE=t.readDoubleBE,e.writeUInt8=t.writeUInt8,e.writeUInt16LE=t.writeUInt16LE,e.writeUInt16BE=t.writeUInt16BE,e.writeUInt32LE=t.writeUInt32LE,e.writeUInt32BE=t.writeUInt32BE,e.writeInt8=t.writeInt8,e.writeInt16LE=t.writeInt16LE,e.writeInt16BE=t.writeInt16BE,e.writeInt32LE=t.writeInt32LE,e.writeInt32BE=t.writeInt32BE,e.writeFloatLE=t.writeFloatLE,e.writeFloatBE=t.writeFloatBE,e.writeDoubleLE=t.writeDoubleLE,e.writeDoubleBE=t.writeDoubleBE,e.fill=t.fill,e.inspect=t.inspect,e.toArrayBuffer=t.toArrayBuffer,e}}.call(this,O(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},O(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/buffer/index.js\",\"/node_modules/gulp-browserify/node_modules/buffer\")},{\"base64-js\":2,buffer:3,ieee754:10,lYpoI2:11}],4:[function(c,d,e){!function(e,t,a,n,r,o,i,u,s){var a=c(\"buffer\").Buffer,f=4,l=new a(f);l.fill(0);d.exports={hash:function(e,t,n,r){for(var o=t(function(e,t){e.length%f!=0&&(n=e.length+(f-e.length%f),e=a.concat([e,l],n));for(var n,r=[],o=t?e.readInt32BE:e.readInt32LE,i=0;i<e.length;i+=f)r.push(o.call(e,i));return r}(e=a.isBuffer(e)?e:new a(e),r),8*e.length),t=r,i=new a(n),u=t?i.writeInt32BE:i.writeInt32LE,s=0;s<o.length;s++)u.call(i,o[s],4*s,!0);return i}}}.call(this,c(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},c(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/helpers.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{buffer:3,lYpoI2:11}],5:[function(v,e,_){!function(l,c,u,d,h,p,g,y,w){var u=v(\"buffer\").Buffer,e=v(\"./sha\"),t=v(\"./sha256\"),n=v(\"./rng\"),b={sha1:e,sha256:t,md5:v(\"./md5\")},s=64,a=new u(s);function r(e,n){var r=b[e=e||\"sha1\"],o=[];return r||i(\"algorithm:\",e,\"is not yet supported\"),{update:function(e){return u.isBuffer(e)||(e=new u(e)),o.push(e),e.length,this},digest:function(e){var t=u.concat(o),t=n?function(e,t,n){u.isBuffer(t)||(t=new u(t)),u.isBuffer(n)||(n=new u(n)),t.length>s?t=e(t):t.length<s&&(t=u.concat([t,a],s));for(var r=new u(s),o=new u(s),i=0;i<s;i++)r[i]=54^t[i],o[i]=92^t[i];return n=e(u.concat([r,n])),e(u.concat([o,n]))}(r,n,t):r(t);return o=null,e?t.toString(e):t}}}function i(){var e=[].slice.call(arguments).join(\" \");throw new Error([e,\"we accept pull requests\",\"http://github.com/dominictarr/crypto-browserify\"].join(\"\\n\"))}a.fill(0),_.createHash=function(e){return r(e)},_.createHmac=r,_.randomBytes=function(e,t){if(!t||!t.call)return new u(n(e));try{t.call(this,void 0,new u(n(e)))}catch(e){t(e)}};var o,f=[\"createCredentials\",\"createCipher\",\"createCipheriv\",\"createDecipher\",\"createDecipheriv\",\"createSign\",\"createVerify\",\"createDiffieHellman\",\"pbkdf2\"],m=function(e){_[e]=function(){i(\"sorry,\",e,\"is not implemented yet\")}};for(o in f)m(f[o],o)}.call(this,v(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},v(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/index.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{\"./md5\":6,\"./rng\":7,\"./sha\":8,\"./sha256\":9,buffer:3,lYpoI2:11}],6:[function(w,b,e){!function(e,r,o,i,u,a,f,l,y){var t=w(\"./helpers\");function n(e,t){e[t>>5]|=128<<t%32,e[14+(t+64>>>9<<4)]=t;for(var n=1732584193,r=-271733879,o=-1732584194,i=271733878,u=0;u<e.length;u+=16){var s=n,a=r,f=o,l=i,n=c(n,r,o,i,e[u+0],7,-680876936),i=c(i,n,r,o,e[u+1],12,-389564586),o=c(o,i,n,r,e[u+2],17,606105819),r=c(r,o,i,n,e[u+3],22,-1044525330);n=c(n,r,o,i,e[u+4],7,-176418897),i=c(i,n,r,o,e[u+5],12,1200080426),o=c(o,i,n,r,e[u+6],17,-1473231341),r=c(r,o,i,n,e[u+7],22,-45705983),n=c(n,r,o,i,e[u+8],7,1770035416),i=c(i,n,r,o,e[u+9],12,-1958414417),o=c(o,i,n,r,e[u+10],17,-42063),r=c(r,o,i,n,e[u+11],22,-1990404162),n=c(n,r,o,i,e[u+12],7,1804603682),i=c(i,n,r,o,e[u+13],12,-40341101),o=c(o,i,n,r,e[u+14],17,-1502002290),n=d(n,r=c(r,o,i,n,e[u+15],22,1236535329),o,i,e[u+1],5,-165796510),i=d(i,n,r,o,e[u+6],9,-1069501632),o=d(o,i,n,r,e[u+11],14,643717713),r=d(r,o,i,n,e[u+0],20,-373897302),n=d(n,r,o,i,e[u+5],5,-701558691),i=d(i,n,r,o,e[u+10],9,38016083),o=d(o,i,n,r,e[u+15],14,-660478335),r=d(r,o,i,n,e[u+4],20,-405537848),n=d(n,r,o,i,e[u+9],5,568446438),i=d(i,n,r,o,e[u+14],9,-1019803690),o=d(o,i,n,r,e[u+3],14,-187363961),r=d(r,o,i,n,e[u+8],20,1163531501),n=d(n,r,o,i,e[u+13],5,-1444681467),i=d(i,n,r,o,e[u+2],9,-51403784),o=d(o,i,n,r,e[u+7],14,1735328473),n=h(n,r=d(r,o,i,n,e[u+12],20,-1926607734),o,i,e[u+5],4,-378558),i=h(i,n,r,o,e[u+8],11,-2022574463),o=h(o,i,n,r,e[u+11],16,1839030562),r=h(r,o,i,n,e[u+14],23,-35309556),n=h(n,r,o,i,e[u+1],4,-1530992060),i=h(i,n,r,o,e[u+4],11,1272893353),o=h(o,i,n,r,e[u+7],16,-155497632),r=h(r,o,i,n,e[u+10],23,-1094730640),n=h(n,r,o,i,e[u+13],4,681279174),i=h(i,n,r,o,e[u+0],11,-358537222),o=h(o,i,n,r,e[u+3],16,-722521979),r=h(r,o,i,n,e[u+6],23,76029189),n=h(n,r,o,i,e[u+9],4,-640364487),i=h(i,n,r,o,e[u+12],11,-421815835),o=h(o,i,n,r,e[u+15],16,530742520),n=p(n,r=h(r,o,i,n,e[u+2],23,-995338651),o,i,e[u+0],6,-198630844),i=p(i,n,r,o,e[u+7],10,1126891415),o=p(o,i,n,r,e[u+14],15,-1416354905),r=p(r,o,i,n,e[u+5],21,-57434055),n=p(n,r,o,i,e[u+12],6,1700485571),i=p(i,n,r,o,e[u+3],10,-1894986606),o=p(o,i,n,r,e[u+10],15,-1051523),r=p(r,o,i,n,e[u+1],21,-2054922799),n=p(n,r,o,i,e[u+8],6,1873313359),i=p(i,n,r,o,e[u+15],10,-30611744),o=p(o,i,n,r,e[u+6],15,-1560198380),r=p(r,o,i,n,e[u+13],21,1309151649),n=p(n,r,o,i,e[u+4],6,-145523070),i=p(i,n,r,o,e[u+11],10,-1120210379),o=p(o,i,n,r,e[u+2],15,718787259),r=p(r,o,i,n,e[u+9],21,-343485551),n=g(n,s),r=g(r,a),o=g(o,f),i=g(i,l)}return Array(n,r,o,i)}function s(e,t,n,r,o,i){return g((t=g(g(t,e),g(r,i)))<<o|t>>>32-o,n)}function c(e,t,n,r,o,i,u){return s(t&n|~t&r,e,t,o,i,u)}function d(e,t,n,r,o,i,u){return s(t&r|n&~r,e,t,o,i,u)}function h(e,t,n,r,o,i,u){return s(t^n^r,e,t,o,i,u)}function p(e,t,n,r,o,i,u){return s(n^(t|~r),e,t,o,i,u)}function g(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}b.exports=function(e){return t.hash(e,n,16)}}.call(this,w(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},w(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/md5.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{\"./helpers\":4,buffer:3,lYpoI2:11}],7:[function(e,l,t){!function(e,t,n,r,o,i,u,s,f){var a;l.exports=a||function(e){for(var t,n=new Array(e),r=0;r<e;r++)0==(3&r)&&(t=4294967296*Math.random()),n[r]=t>>>((3&r)<<3)&255;return n}}.call(this,e(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},e(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/rng.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{buffer:3,lYpoI2:11}],8:[function(c,d,e){!function(e,t,n,r,o,s,a,f,l){var i=c(\"./helpers\");function u(l,c){l[c>>5]|=128<<24-c%32,l[15+(c+64>>9<<4)]=c;for(var e,t,n,r=Array(80),o=1732584193,i=-271733879,u=-1732584194,s=271733878,d=-1009589776,h=0;h<l.length;h+=16){for(var p=o,g=i,y=u,w=s,b=d,a=0;a<80;a++){r[a]=a<16?l[h+a]:v(r[a-3]^r[a-8]^r[a-14]^r[a-16],1);var f=m(m(v(o,5),(f=i,t=u,n=s,(e=a)<20?f&t|~f&n:!(e<40)&&e<60?f&t|f&n|t&n:f^t^n)),m(m(d,r[a]),(e=a)<20?1518500249:e<40?1859775393:e<60?-1894007588:-899497514)),d=s,s=u,u=v(i,30),i=o,o=f}o=m(o,p),i=m(i,g),u=m(u,y),s=m(s,w),d=m(d,b)}return Array(o,i,u,s,d)}function m(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function v(e,t){return e<<t|e>>>32-t}d.exports=function(e){return i.hash(e,u,20,!0)}}.call(this,c(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},c(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{\"./helpers\":4,buffer:3,lYpoI2:11}],9:[function(c,d,e){!function(e,t,n,r,u,s,a,f,l){function b(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function o(e,l){var c,d=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),t=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),n=new Array(64);e[l>>5]|=128<<24-l%32,e[15+(l+64>>9<<4)]=l;for(var r,o,h=0;h<e.length;h+=16){for(var i=t[0],u=t[1],s=t[2],p=t[3],a=t[4],g=t[5],y=t[6],w=t[7],f=0;f<64;f++)n[f]=f<16?e[f+h]:b(b(b((o=n[f-2],m(o,17)^m(o,19)^v(o,10)),n[f-7]),(o=n[f-15],m(o,7)^m(o,18)^v(o,3))),n[f-16]),c=b(b(b(b(w,m(o=a,6)^m(o,11)^m(o,25)),a&g^~a&y),d[f]),n[f]),r=b(m(r=i,2)^m(r,13)^m(r,22),i&u^i&s^u&s),w=y,y=g,g=a,a=b(p,c),p=s,s=u,u=i,i=b(c,r);t[0]=b(i,t[0]),t[1]=b(u,t[1]),t[2]=b(s,t[2]),t[3]=b(p,t[3]),t[4]=b(a,t[4]),t[5]=b(g,t[5]),t[6]=b(y,t[6]),t[7]=b(w,t[7])}return t}var i=c(\"./helpers\"),m=function(e,t){return e>>>t|e<<32-t},v=function(e,t){return e>>>t};d.exports=function(e){return i.hash(e,o,32,!0)}}.call(this,c(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},c(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha256.js\",\"/node_modules/gulp-browserify/node_modules/crypto-browserify\")},{\"./helpers\":4,buffer:3,lYpoI2:11}],10:[function(e,t,f){!function(e,t,n,r,o,i,u,s,a){f.read=function(e,t,n,r,o){var i,u,l=8*o-r-1,c=(1<<l)-1,d=c>>1,s=-7,a=n?o-1:0,f=n?-1:1,o=e[t+a];for(a+=f,i=o&(1<<-s)-1,o>>=-s,s+=l;0<s;i=256*i+e[t+a],a+=f,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=r;0<s;u=256*u+e[t+a],a+=f,s-=8);if(0===i)i=1-d;else{if(i===c)return u?NaN:1/0*(o?-1:1);u+=Math.pow(2,r),i-=d}return(o?-1:1)*u*Math.pow(2,i-r)},f.write=function(e,t,l,n,r,c){var o,i,u=8*c-r-1,s=(1<<u)-1,a=s>>1,d=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:c-1,h=n?1:-1,c=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(i=isNaN(t)?1:0,o=s):(o=Math.floor(Math.log(t)/Math.LN2),t*(n=Math.pow(2,-o))<1&&(o--,n*=2),2<=(t+=1<=o+a?d/n:d*Math.pow(2,1-a))*n&&(o++,n/=2),s<=o+a?(i=0,o=s):1<=o+a?(i=(t*n-1)*Math.pow(2,r),o+=a):(i=t*Math.pow(2,a-1)*Math.pow(2,r),o=0));8<=r;e[l+f]=255&i,f+=h,i/=256,r-=8);for(o=o<<r|i,u+=r;0<u;e[l+f]=255&o,f+=h,o/=256,u-=8);e[l+f-h]|=128*c}}.call(this,e(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},e(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/ieee754/index.js\",\"/node_modules/gulp-browserify/node_modules/ieee754\")},{buffer:3,lYpoI2:11}],11:[function(e,h,t){!function(e,t,n,r,o,f,l,c,d){var i,u,s;function a(){}(e=h.exports={}).nextTick=(u=\"undefined\"!=typeof window&&window.setImmediate,s=\"undefined\"!=typeof window&&window.postMessage&&window.addEventListener,u?function(e){return window.setImmediate(e)}:s?(i=[],window.addEventListener(\"message\",function(e){var t=e.source;t!==window&&null!==t||\"process-tick\"!==e.data||(e.stopPropagation(),0<i.length&&i.shift()())},!0),function(e){i.push(e),window.postMessage(\"process-tick\",\"*\")}):function(e){setTimeout(e,0)}),e.title=\"browser\",e.browser=!0,e.env={},e.argv=[],e.on=a,e.addListener=a,e.once=a,e.off=a,e.removeListener=a,e.removeAllListeners=a,e.emit=a,e.binding=function(e){throw new Error(\"process.binding is not supported\")},e.cwd=function(){return\"/\"},e.chdir=function(e){throw new Error(\"process.chdir is not supported\")}}.call(this,e(\"lYpoI2\"),\"undefined\"!=typeof self?self:\"undefined\"!=typeof window?window:{},e(\"buffer\").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],\"/node_modules/gulp-browserify/node_modules/process/browser.js\",\"/node_modules/gulp-browserify/node_modules/process\")},{buffer:3,lYpoI2:11}]},{},[1])(1)});", "/******************************************************************************\nCopyright (c) Microsoft Corporation.\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\n/* global Reflect, Promise, SuppressedError, Symbol */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nexport function __extends(d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\nexport var __assign = function() {\n __assign = Object.assign || function __assign(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\n }\n return t;\n }\n return __assign.apply(this, arguments);\n}\n\nexport function __rest(s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n}\n\nexport function __decorate(decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\nexport function __param(paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n}\n\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\n var _, done = false;\n for (var i = decorators.length - 1; i >= 0; i--) {\n var context = {};\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\n if (kind === \"accessor\") {\n if (result === void 0) continue;\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\n if (_ = accept(result.get)) descriptor.get = _;\n if (_ = accept(result.set)) descriptor.set = _;\n if (_ = accept(result.init)) initializers.unshift(_);\n }\n else if (_ = accept(result)) {\n if (kind === \"field\") initializers.unshift(_);\n else descriptor[key] = _;\n }\n }\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\n done = true;\n};\n\nexport function __runInitializers(thisArg, initializers, value) {\n var useValue = arguments.length > 2;\n for (var i = 0; i < initializers.length; i++) {\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\n }\n return useValue ? value : void 0;\n};\n\nexport function __propKey(x) {\n return typeof x === \"symbol\" ? x : \"\".concat(x);\n};\n\nexport function __setFunctionName(f, name, prefix) {\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\n};\n\nexport function __metadata(metadataKey, metadataValue) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\n}\n\nexport function __awaiter(thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n}\n\nexport function __generator(thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n}\n\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\n\nexport function __exportStar(m, o) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\n}\n\nexport function __values(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n}\n\nexport function __read(o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n}\n\n/** @deprecated */\nexport function __spread() {\n for (var ar = [], i = 0; i < arguments.length; i++)\n ar = ar.concat(__read(arguments[i]));\n return ar;\n}\n\n/** @deprecated */\nexport function __spreadArrays() {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n}\n\nexport function __spreadArray(to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n}\n\nexport function __await(v) {\n return this instanceof __await ? (this.v = v, this) : new __await(v);\n}\n\nexport function __asyncGenerator(thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n}\n\nexport function __asyncDelegator(o) {\n var i, p;\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\n}\n\nexport function __asyncValues(o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator], i;\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\n}\n\nexport function __makeTemplateObject(cooked, raw) {\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\n return cooked;\n};\n\nvar __setModuleDefault = Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n};\n\nexport function __importStar(mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n}\n\nexport function __importDefault(mod) {\n return (mod && mod.__esModule) ? mod : { default: mod };\n}\n\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\n}\n\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\n}\n\nexport function __classPrivateFieldIn(state, receiver) {\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\n}\n\nexport function __addDisposableResource(env, value, async) {\n if (value !== null && value !== void 0) {\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\n var dispose;\n if (async) {\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\n dispose = value[Symbol.asyncDispose];\n }\n if (dispose === void 0) {\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\n dispose = value[Symbol.dispose];\n }\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\n env.stack.push({ value: value, dispose: dispose, async: async });\n }\n else if (async) {\n env.stack.push({ async: true });\n }\n return value;\n}\n\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\n var e = new Error(message);\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\n};\n\nexport function __disposeResources(env) {\n function fail(e) {\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\n env.hasError = true;\n }\n function next() {\n while (env.stack.length) {\n var rec = env.stack.pop();\n try {\n var result = rec.dispose && rec.dispose.call(rec.value);\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\n }\n catch (e) {\n fail(e);\n }\n }\n if (env.hasError) throw env.error;\n }\n return next();\n}\n\nexport default {\n __extends,\n __assign,\n __rest,\n __decorate,\n __param,\n __metadata,\n __awaiter,\n __generator,\n __createBinding,\n __exportStar,\n __values,\n __read,\n __spread,\n __spreadArrays,\n __spreadArray,\n __await,\n __asyncGenerator,\n __asyncDelegator,\n __asyncValues,\n __makeTemplateObject,\n __importStar,\n __importDefault,\n __classPrivateFieldGet,\n __classPrivateFieldSet,\n __classPrivateFieldIn,\n __addDisposableResource,\n __disposeResources,\n};\n", "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n//# sourceMappingURL=typed-event-interfaces.js.map", null, null, null, null, null, null, null, null, "import {\n\tClientDescriptor,\n\tClientDescriptorOptions,\n} from './client/ClientDescriptor.js';\nimport { Client } from './client/Client.js';\nexport type { ClientWithCollections } from './client/Client.js';\nexport { ClientDescriptor };\nexport { Client };\n// backward compat\nexport { ClientDescriptor as StorageDescriptor };\nexport { Client as Storage };\nexport type { ClientDescriptorOptions };\nexport type { ClientDescriptorOptions as StorageInitOptions };\nexport { Entity } from './entities/Entity.js';\nexport type {\n\tObjectEntity,\n\tListEntity,\n\tEntityShape,\n\tAccessibleEntityProperty,\n\tAnyEntity,\n\tEntityDestructured,\n\tEntityInit,\n} from './entities/types.js';\nexport { ServerSync } from './sync/Sync.js';\nexport type { SyncTransportMode } from './sync/Sync.js';\nexport { EntityFile, type EntityFileSnapshot } from './files/EntityFile.js';\nexport {\n\t/** @deprecated - use schema.collection */\n\tcollection,\n\tschema,\n\tcreateDefaultMigration,\n\tmigrate,\n\tcreateMigration,\n} from '@verdant-web/common';\nexport type {\n\tStorageDocument,\n\tStorageSchema,\n\tStorageCollectionSchema,\n\tStorageAnyFieldSchema,\n\tStorageArrayFieldSchema,\n\tStorageObjectFieldSchema,\n\tStorageBooleanFieldSchema,\n\tStorageFieldSchema,\n\tStorageFileFieldSchema,\n\tStorageMapFieldSchema,\n\tStorageNumberFieldSchema,\n\tStorageStringFieldSchema,\n\tStorageFieldsSchema,\n\tIndexValueTag,\n\tMigration,\n} from '@verdant-web/common';\nexport type { UserInfo } from '@verdant-web/common';\nexport type { Query } from './queries/types.js';\nexport type { QueryStatus } from './queries/BaseQuery.js';\nexport type { CollectionQueries } from './queries/CollectionQueries.js';\nexport { MigrationPathError } from './migration/errors.js';\nexport * from './utils/id.js';\nexport { UndoHistory } from './UndoHistory.js';\nexport * from './authorization.js';\nexport * from './sync/cliSync.js';\n", "import cuid from 'cuid';\nimport { v4 } from 'uuid';\n\nexport interface TimestampProvider {\n\tnow(version: number): string;\n\tupdate(remoteTimestamp: string): void;\n\tzero(version: number): string;\n\tgetWallClockTime(timestamp: string): number;\n}\n\nconst VERSION_BLOCK_LENGTH = 4;\nconst ENCODING_NUMBER_RADIX = 36;\n\nexport function encodeVersion(version: number | string): string {\n\treturn version\n\t\t.toString(ENCODING_NUMBER_RADIX)\n\t\t.padStart(VERSION_BLOCK_LENGTH, '0');\n}\n\nexport function OLD_encodeVersion(version: number | string): string {\n\treturn version.toString().padStart(6, '0');\n}\n\nexport class NaiveTimestampProvider implements TimestampProvider {\n\tcounter = 0;\n\tnow = (version: number | string) => {\n\t\treturn (\n\t\t\tencodeVersion(version) + Date.now().toString() + '-' + this.counter++\n\t\t);\n\t};\n\tupdate = () => {\n\t\tthis.counter = 0;\n\t};\n\tzero = (version: number | string) => {\n\t\treturn encodeVersion(version) + '0' + '-' + this.counter++;\n\t};\n\tgetWallClockTime = (timestamp: string) => {\n\t\treturn parseInt(timestamp.slice(VERSION_BLOCK_LENGTH).split('-')[0], 10);\n\t};\n}\n\nexport class HybridLogicalClockTimestampProvider implements TimestampProvider {\n\tprivate latest: HLCTimestamp = {\n\t\ttime: Date.now(),\n\t\tcounter: 0,\n\t\tnode: generateNodeId(),\n\t};\n\tprivate zeroCounter = 0;\n\n\tnow = (version: string | number) => {\n\t\tthis.latest = getHlcNow(this.latest);\n\t\treturn this.get(version, this.latest);\n\t};\n\t/**\n\t * @deprecated - use now() instead and update to latest format\n\t */\n\tOLD_now = (version: string | number) => {\n\t\tthis.latest = getHlcNow(this.latest);\n\t\treturn OLD_encodeVersion(version) + OLD_serializeHlcTimestamp(this.latest);\n\t};\n\t/** Get the current timer state. Does not increment counter. */\n\ttimerState = () => {\n\t\treturn this.latest;\n\t};\n\tupdate = (remoteTimestamp: string) => {\n\t\t// strip version from remote timestamp\n\t\tconst hlcString = remoteTimestamp.slice(VERSION_BLOCK_LENGTH);\n\t\tthis.latest = updateFromRemote(\n\t\t\tthis.latest,\n\t\t\tdeserializeHlcTimestamp(hlcString),\n\t\t);\n\t};\n\tget = (version: string | number, raw: HLCTimestamp) => {\n\t\treturn encodeVersion(version) + serializeHlcTimestamp(raw);\n\t};\n\tzero = (version: string | number) => {\n\t\treturn (\n\t\t\tencodeVersion(version) +\n\t\t\tserializeHlcTimestamp({\n\t\t\t\ttime: 0,\n\t\t\t\t// to keep zero timestamps unique, we use a counter here as well\n\t\t\t\tcounter: this.zeroCounter++,\n\t\t\t\tnode: this.latest.node,\n\t\t\t})\n\t\t);\n\t};\n\tgetWallClockTime = getWallClockTime;\n}\n\nclass ClockDriftError extends Error {\n\ttype: string;\n\tconstructor(...args: any[]) {\n\t\tsuper();\n\t\tthis.type = 'ClockDriftError';\n\t\tthis.message = ['maximum clock drift exceeded'].concat(args).join(' ');\n\t}\n}\n\nclass OverflowError extends Error {\n\ttype: string;\n\tconstructor() {\n\t\tsuper();\n\t\tthis.type = 'OverflowError';\n\t\tthis.message = 'timestamp counter overflow';\n\t}\n}\n\ninterface HLCTimestamp {\n\ttime: number;\n\tcounter: number;\n\tnode: string;\n}\n\nconst COUNTER_BLOCK_LENGTH = 4;\nconst NODE_BLOCK_LENGTH = 7;\nconst MAX_CLOCK_DRIFT = 60 * 1000;\n// 9 base36 characters should last until the year 5000\n// when encoding a unix MS timestamp\nconst TIME_BLOCK_LENGTH = 9;\n\nfunction generateNodeId() {\n\treturn cuid\n\t\t.slug()\n\t\t.padStart(NODE_BLOCK_LENGTH, '0')\n\t\t.slice(0, NODE_BLOCK_LENGTH);\n}\n\nexport function serializeHlcTimestamp(ts: HLCTimestamp): string {\n\t// string representation of the time\n\tconst dateString = new Date(ts.time)\n\t\t.getTime()\n\t\t.toString(ENCODING_NUMBER_RADIX)\n\t\t.padStart(TIME_BLOCK_LENGTH, '0');\n\t// counter, 336, padded to 4 characters\n\tconst counter = ts.counter\n\t\t.toString(ENCODING_NUMBER_RADIX)\n\t\t.padStart(COUNTER_BLOCK_LENGTH, '0');\n\t// node id padded to 16 characters\n\tconst node = ts.node.padStart(NODE_BLOCK_LENGTH, '0');\n\treturn `${dateString}${counter}${node}`;\n}\n\nfunction getHlcNow(prev: HLCTimestamp): HLCTimestamp {\n\tconst wallTime = Date.now();\n\n\t// pick prev's time if it's later than our local device\n\tconst newWallTime = Math.max(prev.time, wallTime);\n\t// reset counter if wall time changed\n\tconst newCounter = prev.time === newWallTime ? prev.counter + 1 : 0;\n\n\t// check for drift\n\tif (newWallTime - wallTime > MAX_CLOCK_DRIFT) {\n\t\tthrow new ClockDriftError(newWallTime, wallTime, MAX_CLOCK_DRIFT);\n\t}\n\t// check for counter overflow (max is 4 bytes)\n\tif (newCounter > 65535) {\n\t\tthrow new OverflowError();\n\t}\n\n\treturn {\n\t\ttime: newWallTime,\n\t\tcounter: newCounter,\n\t\tnode: prev.node,\n\t};\n}\n\nfunction updateFromRemote(\n\tlocal: HLCTimestamp,\n\tremote: HLCTimestamp,\n): HLCTimestamp {\n\tconst wallTime = Date.now();\n\t// pick remote's time if it's later than our local device\n\tconst newTime = Math.max(wallTime, Math.max(local.time, remote.time));\n\n\tconst maxCounter = Math.max(local.counter, remote.counter);\n\tlet newCounter;\n\t// if all clocks are the same, increment the counter\n\tif (local.time === newTime && remote.time === newTime) {\n\t\tnewCounter = maxCounter + 1;\n\t}\n\t// if local time is the same as new time, increment our local counter\n\telse if (local.time === newTime) {\n\t\tnewCounter = local.counter + 1;\n\t}\n\t// if remote time is the same as new time, increment remote counter\n\telse if (remote.time === newTime) {\n\t\tnewCounter = remote.counter + 1;\n\t}\n\t// otherwise, reset the counter\n\telse {\n\t\tnewCounter = 0;\n\t}\n\n\t// check for drift\n\tif (newTime - wallTime > MAX_CLOCK_DRIFT) {\n\t\tthrow new ClockDriftError(newTime, wallTime, MAX_CLOCK_DRIFT);\n\t}\n\tif (newCounter > 65535) {\n\t\tthrow new OverflowError();\n\t}\n\n\treturn {\n\t\ttime: newTime,\n\t\tcounter: newCounter,\n\t\tnode: local.node,\n\t};\n}\n\nexport function deserializeHlcTimestamp(clock: string): HLCTimestamp {\n\tconst dateString = clock.slice(0, TIME_BLOCK_LENGTH);\n\tconst counter = clock.slice(\n\t\tTIME_BLOCK_LENGTH,\n\t\tTIME_BLOCK_LENGTH + COUNTER_BLOCK_LENGTH,\n\t);\n\tconst node = clock.slice(TIME_BLOCK_LENGTH + COUNTER_BLOCK_LENGTH);\n\tconst time = parseInt(dateString, ENCODING_NUMBER_RADIX);\n\tconst counterNum = parseInt(counter, ENCODING_NUMBER_RADIX);\n\n\tif (isNaN(time) || isNaN(counterNum)) {\n\t\tthrow new Error('invalid clock format');\n\t}\n\n\treturn {\n\t\ttime,\n\t\tcounter: counterNum,\n\t\tnode,\n\t};\n}\n\nfunction removeLeadingZeroes(str: string): string {\n\treturn str.replace(/^0+/, '');\n}\n\n/**\n * Below, converters for old-style timestamps are defined.\n * These are for migrating older clients to the new format.\n */\n\n/**\n * Converts a timestamp from the old format to the new format.\n */\nexport function convertOldHlcTimestamp(ts: string): string {\n\tconst versionBlock = ts.slice(0, 6);\n\t// no jokes please\n\tconst clockBlock = ts.slice(6);\n\tconst deserialized = OLD_deserializeHlcTimestamp(clockBlock);\n\n\t// version was base 10 and now is base 36\n\tconst versionNumber = parseInt(versionBlock, 10);\n\tconst encodedVersion = encodeVersion(versionNumber);\n\treturn encodedVersion + serializeHlcTimestamp(deserialized);\n}\n\nexport function OLD_serializeHlcTimestamp(ts: HLCTimestamp): string {\n\t// ISO string representation of the time\n\tconst dateString = new Date(ts.time).toISOString();\n\t// counter, base16, padded to 4 characters\n\tconst counter = ts.counter.toString(16).toUpperCase().padStart(4, '0');\n\t// node id padded to 16 characters\n\tconst node = ts.node.padStart(16, '0');\n\treturn `${dateString}-${counter}-${node}`;\n}\n\nexport function OLD_deserializeHlcTimestamp(clock: string): HLCTimestamp {\n\t// ISO string representation of the time\n\tconst dateString = clock.slice(0, 24);\n\tconst counter = clock.slice(25, 25 + 4);\n\tconst node = clock.slice(25 + 4 + 1);\n\n\tconst time = new Date(dateString).getTime();\n\tconst counterNum = parseInt(counter, 16);\n\n\tif (isNaN(time) || isNaN(counterNum)) {\n\t\tthrow new Error('invalid clock format');\n\t}\n\n\treturn {\n\t\ttime,\n\t\tcounter: counterNum,\n\t\tnode: node.slice(node.length - 7),\n\t};\n}\n\nexport function getTimestampSchemaVersion(timestamp: string): number {\n\treturn parseInt(timestamp.slice(0, VERSION_BLOCK_LENGTH), 36);\n}\n\nexport function compareTimestampSchemaVersions(a: string, b: string) {\n\treturn getTimestampSchemaVersion(a) - getTimestampSchemaVersion(b);\n}\n\nexport function getWallClockTime(timestamp: string): number {\n\treturn deserializeHlcTimestamp(timestamp.slice(VERSION_BLOCK_LENGTH)).time;\n}\n", "// Unique ID creation requires a high quality random # generator. In the browser we therefore\n// require the crypto API and do not support built-in fallback to lower quality random number\n// generators (like Math.random()).\nvar getRandomValues;\nvar rnds8 = new Uint8Array(16);\nexport default function rng() {\n // lazy load so that environments that need to polyfill have a chance to do so\n if (!getRandomValues) {\n // getRandomValues needs to be invoked in a context where \"this\" is a Crypto implementation. Also,\n // find the complete implementation of crypto (msCrypto) on IE11.\n getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);\n\n if (!getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n }\n\n return getRandomValues(rnds8);\n}", "export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;", "import REGEX from './regex.js';\n\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\n\nexport default validate;", "import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nvar byteToHex = [];\n\nfor (var i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).substr(1));\n}\n\nfunction stringify(arr) {\n var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;", "import rng from './rng.js';\nimport stringify from './stringify.js';\n\nfunction v4(options, buf, offset) {\n options = options || {};\n var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (var i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return stringify(rnds);\n}\n\nexport default v4;", "import { FileRef, isFileRef } from './files.js';\nimport { isObjectRef, ObjectRef } from './operation.js';\n\nexport function isRef(obj: any): obj is ObjectRef | FileRef {\n\treturn isObjectRef(obj) || isFileRef(obj);\n}\n\nexport function compareRefs(a: any, b: any) {\n\tif (a === b) return true;\n\tif (!isRef(a) || !isRef(b)) return false;\n\tif (a['@@type'] !== b['@@type']) return false;\n\tif (a.id !== b.id) return false;\n\treturn true;\n}\n\nexport type Ref = ObjectRef | FileRef;\n\nexport function makeObjectRef(oid: string): ObjectRef {\n\treturn { '@@type': 'ref', id: oid };\n}\n\nexport function makeFileRef(oid: string): FileRef {\n\treturn { '@@type': 'file', id: oid };\n}\n", "import { v4 } from 'uuid';\nimport { isFileRef } from './files.js';\nimport { isObjectRef, ObjectRef } from './operation.js';\nimport { isRef } from './refs.js';\nimport { isObject, assert } from './utils.js';\n\n/**\n * OIDs\n *\n * OIDs are used to identify objects in the document. They also encode\n * information about the object useful to identifying an object found\n * on its own and associating it back to its parent.\n *\n * An OID is structured as such:\n * <collection>/<root id>:<random>\n *\n * OIDs have a few characteristics:\n * - They include the collection name of the parent document\n * - They include the primary key of the parent document\n * - They may include a random sequence to identify sub-objects\n *\n * Collection name and document key are used to link any isolated\n * object back to its parent document.\n *\n * The random sequence allows the application to encode different\n * identities for objects at the same position in a document for\n * conflict resolution purposes\n */\n\nexport type ObjectIdentifier = string;\n\nconst SEGMENT_SEPARATOR = '/';\nconst RANDOM_SEPARATOR = ':';\n\n/**\n * This is the global, in-memory storage for all OIDs. It is used to\n * associate JS objects with OIDs without modifying the objects themselves.\n */\nconst oidMap = new WeakMap<any, ObjectIdentifier>();\n\nexport function getOid(obj: any) {\n\tconst oid = maybeGetOid(obj);\n\tassert(\n\t\t!!oid,\n\t\t`Object ${JSON.stringify(obj)} does not have an OID assigned to it`,\n\t);\n\treturn oid;\n}\n\nexport function maybeGetOid(obj: any): ObjectIdentifier | undefined {\n\tif (!isObject(obj)) {\n\t\treturn undefined;\n\t}\n\treturn oidMap.get(obj);\n}\n\nexport function assignOid(obj: any, oid: ObjectIdentifier) {\n\tassert(\n\t\tisObject(obj),\n\t\t`Only objects can be assigned OIDs, received ${JSON.stringify(obj)}`,\n\t);\n\tif (hasOid(obj)) {\n\t\tremoveOid(obj);\n\t}\n\toidMap.set(obj, oid);\n\treturn obj;\n}\n\nexport function hasOid(obj: any) {\n\treturn !!maybeGetOid(obj);\n}\n\nexport function removeOid(obj: any) {\n\toidMap.delete(obj);\n\treturn obj;\n}\n\n/**\n * For sub-objects, assign a random sub-OID if no OID\n * is already assigned.\n */\nexport function ensureOid(\n\tobj: any,\n\trootOid: ObjectIdentifier,\n\tcreateSubId?: () => string,\n) {\n\tif (!hasOid(obj)) {\n\t\tconst oid = createSubOid(rootOid, createSubId);\n\t\tassignOid(obj, oid);\n\t\treturn oid;\n\t} else {\n\t\treturn getOid(obj);\n\t}\n}\n\nexport function ensureCompatibleOid(\n\tobj: any,\n\trootOid: ObjectIdentifier,\n\tcreateSubId?: () => string,\n) {\n\tif (!hasOid(obj)) {\n\t\tconst oid = createSubOid(rootOid, createSubId);\n\t\tassignOid(obj, oid);\n\t\treturn oid;\n\t} else {\n\t\tconst existingOid = getOid(obj);\n\t\tif (!areOidsRelated(existingOid, rootOid)) {\n\t\t\tconst oid = createSubOid(rootOid, createSubId);\n\t\t\tassignOid(obj, oid);\n\t\t\treturn oid;\n\t\t} else {\n\t\t\treturn getOid(obj);\n\t\t}\n\t}\n}\n\nconst SANITIZE_PLACEHOLDERS = {\n\t'.': '˙',\n\t'/': '&slash;',\n\t':': ':',\n};\nfunction sanitizeFragment(id: string) {\n\t// replaces separator characters with placeholders\n\treturn id\n\t\t.replace(/[/]/g, SANITIZE_PLACEHOLDERS['/'])\n\t\t.replace(/[:]/g, SANITIZE_PLACEHOLDERS[':'])\n\t\t.replace(/[.]/g, SANITIZE_PLACEHOLDERS['.']);\n}\nfunction unsanitizeFragment(id: string) {\n\t// replaces placeholders with separator characters\n\treturn id\n\t\t.replace(/&slash;/g, '/')\n\t\t.replace(/:/g, ':')\n\t\t.replace(/˙/g, '.');\n}\n\n/**\n * Creates an OID for the document with a particular ID.\n * To create a sub-object OID, use createSubOid and pass\n * the root OID.\n */\nexport function createOid(\n\tcollection: string,\n\tdocumentId: string,\n\tsubId?: string,\n) {\n\tlet oid =\n\t\tsanitizeFragment(collection) +\n\t\tSEGMENT_SEPARATOR +\n\t\tsanitizeFragment(documentId);\n\tif (subId) {\n\t\toid += RANDOM_SEPARATOR + subId;\n\t}\n\treturn oid;\n}\n\nexport function createSubOid(\n\troot: ObjectIdentifier,\n\tcreateSubId: () => string = createOidSubId,\n) {\n\tconst { collection, id } = decomposeOid(root);\n\treturn createOid(collection, id, createSubId());\n}\n\nexport function decomposeOid(oid: ObjectIdentifier): {\n\tcollection: string;\n\tid: string;\n\tsubId?: string;\n} {\n\tlet [collection, coreId, ...others] = oid.split('/');\n\t// if 'others' exists, something's off, but maybe we can recover...\n\t// by assuming the last segment is the authz and bolting the rest onto coreId\n\tif (others.length) {\n\t\tconsole.error(\n\t\t\t`OID ${oid} has more than 3 segments. Attempting to parse it anyway.`,\n\t\t);\n\t\tcoreId += '/' + others.join('/');\n\t}\n\n\tconst [idOrLegacyPathId, random] = coreId.split(RANDOM_SEPARATOR);\n\n\tlet id;\n\t// legacy path handling. shouldn't be necessary anymore.\n\tif (idOrLegacyPathId.includes('.')) {\n\t\tid = idOrLegacyPathId.slice(0, idOrLegacyPathId.indexOf('.'));\n\t} else {\n\t\tid = idOrLegacyPathId;\n\t}\n\n\treturn {\n\t\tcollection: unsanitizeFragment(collection),\n\t\tid: unsanitizeFragment(id),\n\t\tsubId: random,\n\t};\n}\n\nexport function assertAllLevelsHaveOids(obj: any, root?: any) {\n\tassert(\n\t\tgetOid(obj),\n\t\t`Object ${JSON.stringify(obj)} must have an oid (child of ${JSON.stringify(\n\t\t\troot,\n\t\t)})`,\n\t);\n\tif (Array.isArray(obj)) {\n\t\tfor (const item of obj) {\n\t\t\tassertAllLevelsHaveOids(item, root || obj);\n\t\t}\n\t} else if (isObject(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tassertAllLevelsHaveOids(obj[key], root || obj);\n\t\t}\n\t}\n}\n\nexport function assignOidsToAllSubObjects(\n\tobj: any,\n\tcreateSubId?: () => string,\n) {\n\tconst rootOid = getOid(obj);\n\tif (Array.isArray(obj)) {\n\t\tlet item;\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\titem = obj[i];\n\t\t\tif (isObject(item) && !isRef(item)) {\n\t\t\t\tensureCompatibleOid(item, rootOid, createSubId);\n\t\t\t\tassignOidsToAllSubObjects(item, createSubId);\n\t\t\t}\n\t\t}\n\t} else if (isObject(obj) && !isRef(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tif (isObject(obj[key]) && !isRef(obj[key])) {\n\t\t\t\tensureCompatibleOid(obj[key], rootOid, createSubId);\n\t\t\t\tassignOidsToAllSubObjects(obj[key], createSubId);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function removeOidsFromAllSubObjects(obj: any) {\n\tremoveOid(obj);\n\n\tif (Array.isArray(obj)) {\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tremoveOidsFromAllSubObjects(obj[i]);\n\t\t}\n\t} else if (isObject(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tremoveOidsFromAllSubObjects(obj[key]);\n\t\t}\n\t}\n}\n\nexport function createOidSubId() {\n\treturn v4().slice(0, 8);\n}\n\nexport function createRef(oid: ObjectIdentifier): ObjectRef {\n\treturn {\n\t\t'@@type': 'ref',\n\t\tid: oid,\n\t};\n}\n\nexport function normalize(\n\tobj: any,\n\trefs: Map<ObjectIdentifier, any> = new Map(),\n): Map<ObjectIdentifier, any> {\n\tif (Array.isArray(obj)) {\n\t\tconst oid = getOid(obj);\n\t\tconst copy = assignOid([], oid);\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tconst value = obj[i];\n\t\t\tif (isObject(value)) {\n\t\t\t\tif (isObjectRef(value)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'An attempt was made to normalize an already normalized object! This is an error in verdant itself.',\n\t\t\t\t\t);\n\t\t\t\t} else if (isFileRef(value)) {\n\t\t\t\t\tcopy[i] = value;\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\tconst itemOid = getOid(value);\n\t\t\t\t\tcopy[i] = createRef(itemOid);\n\t\t\t\t\tnormalize(value, refs);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcopy[i] = value;\n\t\t\t}\n\t\t}\n\t\trefs.set(oid, copy);\n\t} else if (isObject(obj) && !isRef(obj)) {\n\t\tconst oid = getOid(obj);\n\t\tconst copy = assignOid({} as Record<string, any>, oid);\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tif (isObject(value)) {\n\t\t\t\tif (isObjectRef(value)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'An attempt was made to normalize an already normalized object! This is an error in verdant itself.',\n\t\t\t\t\t);\n\t\t\t\t} else if (isFileRef(value)) {\n\t\t\t\t\t// stop here\n\t\t\t\t\tcopy[key] = value;\n\t\t\t\t} else {\n\t\t\t\t\tconst itemOid = getOid(value);\n\t\t\t\t\tcopy[key] = createRef(itemOid);\n\t\t\t\t\tnormalize(value, refs);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcopy[key] = value;\n\t\t\t}\n\t\t}\n\t\trefs.set(oid, copy);\n\t} else if (isRef(obj)) {\n\t}\n\treturn refs;\n}\n\n/**\n * Only normalizes direct children. The created map\n * of objects will still have nested objects.\n */\nexport function normalizeFirstLevel(obj: any) {\n\tconst refs = new Map<ObjectIdentifier, any>();\n\tconst oidKeyPairs = new Map<ObjectIdentifier, string | number>();\n\tif (Array.isArray(obj)) {\n\t\tconst oid = getOid(obj);\n\t\tconst copy = assignOid([], oid);\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tconst value = obj[i];\n\t\t\tif (isObject(value)) {\n\t\t\t\tconst itemOid = getOid(value);\n\t\t\t\tcopy[i] = createRef(itemOid);\n\t\t\t\trefs.set(itemOid, value);\n\t\t\t\toidKeyPairs.set(itemOid, i);\n\t\t\t} else {\n\t\t\t\tcopy[i] = value;\n\t\t\t}\n\t\t}\n\t\trefs.set(oid, copy);\n\t} else if (isObject(obj)) {\n\t\tconst oid = getOid(obj);\n\t\tconst copy = assignOid({} as Record<string, any>, oid);\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tif (isObject(value)) {\n\t\t\t\tconst itemOid = getOid(value);\n\t\t\t\tcopy[key] = createRef(itemOid);\n\t\t\t\trefs.set(itemOid, value);\n\t\t\t\toidKeyPairs.set(itemOid, key);\n\t\t\t} else {\n\t\t\t\tcopy[key] = value;\n\t\t\t}\n\t\t}\n\t\trefs.set(oid, copy);\n\t}\n\treturn { refs, oidKeyPairs };\n}\n\nexport function getOidRoot(oid: ObjectIdentifier) {\n\treturn oid.split('.')[0].split(RANDOM_SEPARATOR)[0];\n}\n\n/**\n * Returns an inclusive range of OIDs that represent\n * all of an OID's possible sub-objects.\n */\nexport function getOidSubIdRange(oid: ObjectIdentifier) {\n\tconst root = getOidRoot(oid);\n\tconst lastSubId = createSubOid(root, () => '\\uffff');\n\treturn [`${root}${RANDOM_SEPARATOR}`, lastSubId];\n}\n\nexport function getRoots(oids: ObjectIdentifier[]) {\n\tconst set = new Set<ObjectIdentifier>();\n\tfor (const oid of oids) {\n\t\tset.add(getOidRoot(oid));\n\t}\n\treturn Array.from(set);\n}\n\nexport function areOidsRelated(oidA: ObjectIdentifier, oidB: ObjectIdentifier) {\n\treturn getOidRoot(oidA) === getOidRoot(oidB);\n}\n\nexport function isRootOid(oid: ObjectIdentifier) {\n\treturn !oid.includes(RANDOM_SEPARATOR);\n}\n\n/**\n * Recursively rewrites any OIDs in an object which are 'foreign' -\n * i.e. relate to some other object/entity - to be local to the\n * current object. This is deterministic, so it can be done\n * on multiple clients independently with predictable results.\n */\nexport function fixForeignOids(obj: any) {\n\tconst oid = maybeGetOid(obj);\n\tif (!oid) return;\n\n\tif (Array.isArray(obj)) {\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tmigrateForeignOid(oid, obj[i]);\n\t\t\tfixForeignOids(obj[i]);\n\t\t}\n\t} else if (isObject(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tmigrateForeignOid(oid, obj[key]);\n\t\t\tfixForeignOids(obj[key]);\n\t\t}\n\t}\n}\n\nfunction migrateForeignOid(parentOid: ObjectIdentifier, child: any) {\n\tconst childOid = maybeGetOid(child);\n\tif (childOid && !areOidsRelated(parentOid, childOid)) {\n\t\tconst { subId, id } = decomposeOid(childOid);\n\t\t// reuse existing subId. if child is a foreign root, use its id as subId\n\t\tassignOid(\n\t\t\tchild,\n\t\t\tcreateSubOid(parentOid, () => subId || id),\n\t\t);\n\t}\n}\n", "import { v4 } from 'uuid';\nimport { assignOid, maybeGetOid } from './oids.js';\nimport hash from 'object-hash';\n\nexport function take<T extends object, Keys extends keyof T>(\n\tobj: T,\n\tkeys: Keys[],\n): Pick<T, Keys> {\n\tconst result: any = {};\n\tfor (const key of keys) {\n\t\tresult[key] = obj[key];\n\t}\n\treturn result;\n}\n\nexport function omit<T extends object, Keys extends keyof T>(\n\tobj: T,\n\tkeys: Keys[],\n): Omit<T, Keys> {\n\tconst result: any = {};\n\tfor (const key of Object.keys(obj)) {\n\t\tif (!keys.includes(key as Keys)) {\n\t\t\tresult[key] = (obj as any)[key];\n\t\t}\n\t}\n\treturn result;\n}\n\nexport function getSortedIndex<T>(\n\tarray: T[],\n\tinsert: T,\n\tcompare: (a: T, b: T) => number,\n) {\n\tlet low = 0;\n\tlet high = array.length;\n\twhile (low < high) {\n\t\tconst mid = (low + high) >>> 1;\n\t\tconst cmp = compare(array[mid], insert);\n\t\tif (cmp < 0) {\n\t\t\tlow = mid + 1;\n\t\t} else {\n\t\t\thigh = mid;\n\t\t}\n\t}\n\treturn low;\n}\n\nfunction orderedReplacer(_: any, v: any) {\n\tif (typeof v !== 'object' || v === null || Array.isArray(v)) {\n\t\treturn v;\n\t}\n\treturn Object.fromEntries(\n\t\tObject.entries(v).sort(([ka], [kb]) => (ka < kb ? -1 : ka > kb ? 1 : 0)),\n\t);\n}\n/**\n * Consistently stringifies an object regardless\n * of key insertion order\n */\nexport function stableStringify(obj: any) {\n\treturn JSON.stringify(obj, orderedReplacer);\n}\n\n/**\n * A version of structured cloning which preserves object identity\n * references in the system.\n */\nexport function cloneDeep<T>(obj: T, copyOids = true): T {\n\t// shortcut... if OIDs aren't important, we can use the built-in\n\t// structured cloning algorithm which should be faster.\n\tif (!copyOids && typeof structuredClone === 'function') {\n\t\treturn structuredClone(obj);\n\t}\n\n\tif (isObject(obj) || Array.isArray(obj)) {\n\t\tconst oid = maybeGetOid(obj);\n\t\tlet clone: any;\n\t\tif (Array.isArray(obj)) {\n\t\t\tclone = obj.map((v) => cloneDeep(v, copyOids)) as T;\n\t\t} else {\n\t\t\tclone = {};\n\t\t\tfor (const [key, value] of Object.entries(obj as any)) {\n\t\t\t\tclone[key] = cloneDeep(value, copyOids);\n\t\t\t}\n\t\t}\n\t\tif (copyOids && oid) {\n\t\t\tassignOid(clone, oid);\n\t\t}\n\t\treturn clone;\n\t}\n\treturn obj;\n}\n\n// TODO: better hash\nexport function hashObject(obj: any) {\n\t// hash the object into a unique string\n\treturn hash(obj);\n}\n\nexport function isObject(obj: any) {\n\treturn obj && typeof obj === 'object';\n}\n\nexport function roughSizeOfObject(object: any) {\n\tvar objectList = [];\n\tvar stack = [object];\n\tvar bytes = 0;\n\n\twhile (stack.length) {\n\t\tvar value = stack.pop();\n\n\t\tif (typeof value === 'boolean') {\n\t\t\tbytes += 4;\n\t\t} else if (typeof value === 'string') {\n\t\t\tbytes += value.length * 2;\n\t\t} else if (typeof value === 'number') {\n\t\t\tbytes += 8;\n\t\t} else if (typeof value === 'object' && objectList.indexOf(value) === -1) {\n\t\t\tobjectList.push(value);\n\n\t\t\tfor (var i in value) {\n\t\t\t\tstack.push(value[i]);\n\t\t\t}\n\t\t}\n\t}\n\treturn bytes;\n}\n\nexport function assert(\n\tcondition: any,\n\tmessage: string = 'assertion failed',\n): asserts condition {\n\tif (!condition) {\n\t\tthrow new Error(message);\n\t}\n}\n\nexport function generateId(length = 16) {\n\treturn v4().replace('-', '').slice(0, length);\n}\n\nexport function findLastIndex<T>(array: T[], predicate: (item: T) => boolean) {\n\tfor (let i = array.length - 1; i >= 0; i--) {\n\t\tif (predicate(array[i])) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\nexport function debounce<T extends (...args: any[]) => any>(\n\tfn: T,\n\twait: number,\n): T {\n\tlet timeout: any;\n\treturn function (this: any, ...args: any[]) {\n\t\tconst context = this;\n\t\tclearTimeout(timeout);\n\t\ttimeout = setTimeout(() => fn.apply(context, args), wait);\n\t} as any;\n}\n\nexport function throttle<T extends (...args: any[]) => any>(\n\tfn: T,\n\twait: number,\n): T {\n\tlet lastTime = 0;\n\n\t// invoke once for the last call\n\tlet trailingTimeout: any;\n\n\treturn function (this: any, ...args: any[]) {\n\t\tconst context = this;\n\t\tconst now = Date.now();\n\t\tif (now - lastTime >= wait) {\n\t\t\tlastTime = now;\n\t\t\tfn.apply(context, args);\n\t\t\tclearTimeout(trailingTimeout);\n\t\t} else {\n\t\t\tclearTimeout(trailingTimeout);\n\t\t\ttrailingTimeout = setTimeout(() => {\n\t\t\t\tlastTime = now;\n\t\t\t\tfn.apply(context, args);\n\t\t\t}, wait);\n\t\t}\n\t} as any;\n}\n", "import { isObject } from './utils.js';\n\nexport type FileRef = {\n\t'@@type': 'file';\n\tid: string;\n};\n\nexport function isFileRef(value: any): value is FileRef {\n\treturn value && value['@@type'] === 'file';\n}\nexport function createFileRef(id: string): FileRef {\n\treturn {\n\t\t'@@type': 'file',\n\t\tid,\n\t};\n}\n\nexport type FileData = {\n\tid: string;\n\t/**\n\t * For locally created files, this starts false, until it's uploaded\n\t * Remote files this is always true\n\t */\n\tremote: boolean;\n\tname: string;\n\ttype: string;\n\t/** A local File instance, if available. */\n\tfile?: Blob;\n\t/** The server URL of this file. */\n\turl?: string;\n};\n\nexport function getAllFileFields(snapshot: any): [string, FileRef][] {\n\treturn Object.entries(snapshot).filter((entry) => isFileRef(entry[1])) as [\n\t\tstring,\n\t\tFileRef,\n\t][];\n}\n\nexport function isFile(value: any) {\n\tif (typeof File !== 'undefined' && value instanceof File) {\n\t\treturn true;\n\t}\n\tif (typeof Blob !== 'undefined' && value instanceof Blob) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nexport function isFileData(value: any): value is FileData {\n\treturn (\n\t\tvalue &&\n\t\tisObject(value) &&\n\t\ttypeof value.id === 'string' &&\n\t\ttypeof value.remote === 'boolean' &&\n\t\ttypeof value.name === 'string' &&\n\t\ttypeof value.type === 'string'\n\t);\n}\n", "import {\n\tassignOid,\n\tcreateOid,\n\tdecomposeOid,\n\tgetOidRoot,\n\tObjectIdentifier,\n} from './oids.js';\nimport { isObject } from './utils.js';\n\nexport const LEGACY_OID_KEY = '__@@oid_do_not_use';\nexport const OID_KEY = '@@id';\n\nexport function maybeGetOidProperty(obj: any) {\n\tif (!isObject(obj)) {\n\t\treturn undefined;\n\t}\n\treturn obj[OID_KEY] || obj[LEGACY_OID_KEY];\n}\n\nfunction removeOidProperty(obj: any) {\n\tif (!isObject(obj)) {\n\t\treturn obj;\n\t}\n\tdelete obj[LEGACY_OID_KEY];\n\tdelete obj[OID_KEY];\n\treturn obj;\n}\n\nfunction copyOidFromPropertyToSystem(obj: any) {\n\tconst oid = maybeGetOidProperty(obj);\n\tif (oid) {\n\t\tassignOid(obj, oid);\n\t}\n}\n\n/**\n *\n * Removes the special property from all objects in the given object\n * which have an OID, transferring the OID from the property to the OID\n * system in-memory.\n */\nexport function removeOidPropertiesFromAllSubObjects(obj: any) {\n\tcopyOidFromPropertyToSystem(obj);\n\tremoveOidProperty(obj);\n\n\tif (Array.isArray(obj)) {\n\t\tfor (let i = 0; i < obj.length; i++) {\n\t\t\tremoveOidPropertiesFromAllSubObjects(obj[i]);\n\t\t}\n\t} else if (isObject(obj)) {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tremoveOidPropertiesFromAllSubObjects(obj[key]);\n\t\t}\n\t}\n}\n\nexport function isLegacyDotOid(oid: ObjectIdentifier) {\n\tconst partBeforeRandomSep = oid.split(':')[0];\n\treturn partBeforeRandomSep.includes('.');\n}\n\nexport function convertLegacyOid(oid: ObjectIdentifier) {\n\tconst { collection, id, subId } = decomposeOid(oid);\n\treturn createOid(collection, id, subId);\n}\n\n// NOTE: all legacy OIDs should now be gone.\nexport const MATCH_LEGACY_OID_JSON_STRING = /\"\\w+\\/[^\"]+?(\\.[^\"]+)+\\:[\\S]+?\"/g;\nexport function replaceLegacyOidsInJsonString(string: string) {\n\t// replace every match of a legacy OID, converting to a new OID\n\treturn string.replaceAll(MATCH_LEGACY_OID_JSON_STRING, (match) => {\n\t\tconst legacyOid = match.slice(1, match.length - 1);\n\t\treturn `\"${convertLegacyOid(legacyOid)}\"`;\n\t});\n}\nexport function replaceLegacyOidsInObject(obj: any) {\n\treturn JSON.parse(replaceLegacyOidsInJsonString(JSON.stringify(obj)));\n}\n\nexport function getLegacyDotOidSubIdRange(oid: ObjectIdentifier) {\n\tconst root = getOidRoot(oid);\n\treturn [`${root}.`, `${root}.\\uffff`];\n}\n\nexport function isOidKey(key: string) {\n\treturn key === OID_KEY || key === LEGACY_OID_KEY;\n}\n", "import { DocumentBaseline } from './baseline.js';\nimport { FileRef, isFileRef } from './files.js';\nimport {\n\tareOidsRelated,\n\tassignOid,\n\tassignOidsToAllSubObjects,\n\tcreateRef,\n\tcreateSubOid,\n\tensureOid,\n\tgetOid,\n\tgetOidRoot,\n\tmaybeGetOid,\n\tnormalize,\n\tObjectIdentifier,\n\tremoveOid,\n} from './oids.js';\nimport { isOidKey } from './oidsLegacy.js';\nimport { compareRefs, isRef } from './refs.js';\nimport { assert, cloneDeep, findLastIndex, isObject } from './utils.js';\n\n// export type ObjectIdentifier<\n// \tCollectionName extends string = string,\n// \tDocumentId extends string = string,\n// \tDocumentOid extends string = string,\n// > =\n// \t| `${CollectionName}/${DocumentId}:${DocumentOid}`\n// \t| `${CollectionName}/${DocumentId}:${DocumentOid}#${string}`;\n\nexport type ObjectRef = {\n\t'@@type': 'ref';\n\tid: ObjectIdentifier;\n};\n\nexport function isObjectRef(obj: any): obj is ObjectRef {\n\treturn obj && typeof obj === 'object' && obj['@@type'] === 'ref';\n}\n\nexport type Normalized<T> = {\n\t[key in keyof T]: T[key] extends Object ? ObjectRef : T[key];\n};\n\n// patches v2\n\nexport type PropertyName = string | number;\n/**\n * List patches can target a particular child list or\n * nested lists. The first path item is the property path\n * of the first child list, any subsequent values are nested\n * list indices.\n */\nexport type PropertyValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| undefined\n\t| ObjectRef\n\t| FileRef;\n\n// all patches refer to a specific sub-object.\ninterface BaseOperationPatch {}\n\nexport interface OperationPatchInitialize extends BaseOperationPatch {\n\top: 'initialize';\n\tvalue: any;\n}\nexport interface OperationPatchSet extends BaseOperationPatch {\n\top: 'set';\n\tname: PropertyName;\n\tvalue: PropertyValue;\n}\nexport interface OperationPatchRemove extends BaseOperationPatch {\n\top: 'remove';\n\tname: PropertyName;\n}\nexport interface OperationPatchListSet extends BaseOperationPatch {\n\top: 'list-set';\n\tindex: number;\n\tvalue: PropertyValue;\n}\nexport interface OperationPatchListPush extends BaseOperationPatch {\n\top: 'list-push';\n\tvalue: PropertyValue;\n}\nexport interface OperationPatchListInsert extends BaseOperationPatch {\n\top: 'list-insert';\n\tindex: number;\n\tvalue?: PropertyValue;\n\tvalues?: PropertyValue[];\n}\nexport interface OperationPatchListDelete extends BaseOperationPatch {\n\top: 'list-delete';\n\tindex: number;\n\tcount: number;\n}\n/**\n * Optimal for lists of object references. Moves\n * the selected item to the target index even if it\n * is not at the original index anymore.\n */\nexport interface OperationPatchListMoveByRef extends BaseOperationPatch {\n\top: 'list-move-by-ref';\n\tvalue: ObjectRef | FileRef;\n\tindex: number;\n}\n/**\n * Suitable for any list move, whether object lists\n * or primitive lists.\n */\nexport interface OperationPatchListMoveByIndex extends BaseOperationPatch {\n\top: 'list-move-by-index';\n\tfrom: number;\n\tto: number;\n}\n/**\n * Removes all instances of the value from\n * the list. Good for set behavior or removing\n * a specific item even if it changes index\n * from conflicts.\n */\nexport interface OperationPatchListRemove extends BaseOperationPatch {\n\top: 'list-remove';\n\tvalue: PropertyValue;\n\tonly?: 'first' | 'last';\n}\n\nexport interface OperationPatchListAdd extends BaseOperationPatch {\n\top: 'list-add';\n\tvalue: PropertyValue;\n}\n\nexport interface OperationPatchDelete extends BaseOperationPatch {\n\top: 'delete';\n}\n\nexport interface OperationPatchTouch extends BaseOperationPatch {\n\top: 'touch';\n}\n\nexport type OperationPatch =\n\t| OperationPatchInitialize\n\t| OperationPatchSet\n\t| OperationPatchRemove\n\t| OperationPatchListSet\n\t| OperationPatchListPush\n\t| OperationPatchListInsert\n\t| OperationPatchListDelete\n\t| OperationPatchListMoveByRef\n\t| OperationPatchListMoveByIndex\n\t| OperationPatchListRemove\n\t| OperationPatchDelete\n\t| OperationPatchListAdd\n\t| OperationPatchTouch;\n\nexport type Operation = {\n\toid: ObjectIdentifier;\n\ttimestamp: string;\n\tdata: OperationPatch;\n\tauthz?: string;\n};\n\nfunction isDiffableObject(val: any) {\n\treturn isObject(val) && !isRef(val);\n}\n\nfunction compareNonDiffable(a: any, b: any) {\n\tif (a === b) return true;\n\tif (isRef(a) && isRef(b)) return compareRefs(a, b);\n\treturn false;\n}\n\nexport function diffToPatches<T extends { [key: string]: any } | any[]>(\n\tfrom: T,\n\tto: T,\n\tgetNow: () => string,\n\tcreateSubId?: () => string,\n\tpatches: Operation[] = [],\n\toptions?: {\n\t\t/**\n\t\t * If an object is merged with another and the new one does not\n\t\t * have an OID assigned, assume it is the same identity as previous\n\t\t */\n\t\tmergeUnknownObjects?: boolean;\n\t\t/**\n\t\t * If an incoming value is not assigned on the new object, use the previous value.\n\t\t * If false, undefined properties will erase the previous value.\n\t\t */\n\t\tdefaultUndefined?: boolean;\n\t\t/**\n\t\t * Authorization to apply to all created operations\n\t\t */\n\t\tauthz?: string;\n\t},\n): Operation[] {\n\tconst authz = options?.authz;\n\tconst oid = getOid(from);\n\n\t// FIXME: allocating this function inline seems wasteful.\n\tfunction diffItems(\n\t\tkey: string | number,\n\t\tvalue: any,\n\t\toldValue: any,\n\t\tisList: boolean,\n\t) {\n\t\tif (!isDiffableObject(value)) {\n\t\t\t// for primitive fields, we can use plain sets and\n\t\t\t// do not need to recurse, of course\n\t\t\tif (!compareNonDiffable(value, oldValue)) {\n\t\t\t\tif (isList) {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\t\t\t\tindex: key as number,\n\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconst oldValueOid = maybeGetOid(oldValue);\n\t\t\tlet valueOid = maybeGetOid(value);\n\t\t\t// the user supplied an object which was already assigned an OID,\n\t\t\t// but that OID is from a separate entity: this object must\n\t\t\t// be cloned to a new identity.\n\t\t\tif (valueOid && !areOidsRelated(oid, valueOid)) {\n\t\t\t\tvalue = cloneDeep(value, false);\n\t\t\t\tvalueOid = createSubOid(oid, createSubId);\n\t\t\t\tassignOid(value, valueOid);\n\t\t\t} else if (!options?.mergeUnknownObjects) {\n\t\t\t\tvalueOid = ensureOid(value, oid, createSubId);\n\t\t\t} else {\n\t\t\t\t// if merge unknown objects is requested, we copy the previous value's oid\n\t\t\t\t// to any mirrored new value if it doesn't have one assigned already.\n\t\t\t\tif (!valueOid && oldValueOid) {\n\t\t\t\t\tassignOid(value, oldValueOid);\n\t\t\t\t\tvalueOid = oldValueOid;\n\t\t\t\t} else {\n\t\t\t\t\tvalueOid = ensureOid(value, oid, createSubId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tassert(\n\t\t\t\t!!valueOid,\n\t\t\t\t'Error: no value OID was resolved during diff. This is a bug in Verdant.',\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tareOidsRelated(oid, valueOid),\n\t\t\t\t`Error: value OID ${valueOid} is not related to parent OID ${oid}. This is a bug in Verdant.`,\n\t\t\t);\n\n\t\t\tif (oldValue === undefined || valueOid !== oldValueOid) {\n\t\t\t\t// first case: previous value exists but the OIDs are different,\n\t\t\t\t// meaning the object identity has changed\n\t\t\t\t// we add the whole new object and also update the reference on this\n\t\t\t\t// key of the parent to point to the new object\n\t\t\t\tinitialToPatches(value, valueOid, getNow, createSubId, patches);\n\t\t\t\tpatches.push(\n\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t\t\tvalue: createRef(valueOid),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tauthz,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\t// if there was an old value, we need to delete it altogether.\n\t\t\t\tif (oldValueOid !== undefined) {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid: oldValueOid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'delete',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// third case: OIDs are the same, meaning the identity is the same,\n\t\t\t\t// and we must diff the objects\n\t\t\t\tdiffToPatches(oldValue, value, getNow, createSubId, patches, options);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (Array.isArray(from) && Array.isArray(to)) {\n\t\t// diffing is more naive than native array operations.\n\t\t// we can only look at each element and decide if it should\n\t\t// be replaced or removed - no moves or pushes, etc.\n\t\tfor (let i = 0; i < to.length; i++) {\n\t\t\tconst value = to[i];\n\t\t\tconst oldValue = from[i];\n\t\t\tdiffItems(i, value, oldValue, true);\n\t\t}\n\t\t// remove any remaining items at the end of the array\n\t\tconst deletedItemsAtEnd = from.length - to.length;\n\t\tif (deletedItemsAtEnd > 0) {\n\t\t\t// if sub-items were objects, we need to delete them all\n\t\t\tfor (let i = to.length; i < from.length; i++) {\n\t\t\t\tconst value = from[i];\n\t\t\t\tconst valueOid = maybeGetOid(value);\n\t\t\t\tif (valueOid) {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid: valueOid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'delete',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// push the list-delete for the deleted items\n\t\t\tpatches.push(\n\t\t\t\taddAuthzToOp(\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'list-delete',\n\t\t\t\t\t\t\tindex: to.length,\n\t\t\t\t\t\t\tcount: deletedItemsAtEnd,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tauthz,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t} else if (Array.isArray(from) || Array.isArray(to)) {\n\t\tthrow new Error('Cannot diff an array with an object');\n\t} else if (isDiffableObject(from) && isDiffableObject(to)) {\n\t\tconst oldKeys = new Set(Object.keys(from));\n\t\tfor (const [key, value] of Object.entries(to)) {\n\t\t\tif (value === undefined && options?.defaultUndefined) continue;\n\n\t\t\toldKeys.delete(key);\n\n\t\t\tif (isOidKey(key)) continue;\n\n\t\t\tconst oldValue = from[key];\n\n\t\t\tdiffItems(key, value, oldValue, false);\n\t\t}\n\n\t\t// this set now only contains keys which were not in the new object\n\t\tif (!options?.defaultUndefined) {\n\t\t\tfor (const key of oldKeys) {\n\t\t\t\tif (isOidKey(key)) continue;\n\t\t\t\t// push the delete for the property\n\t\t\t\tpatches.push(\n\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\top: 'remove',\n\t\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tauthz,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn patches;\n}\n\nexport function shallowDiffToPatches(\n\tfrom: any,\n\tto: any,\n\tgetNow: () => string,\n\tpatches: Operation[] = [],\n\toptions?: { authz?: string },\n) {\n\tconst oid = getOid(from);\n\tconst authz = options?.authz;\n\n\tfunction diffItems(\n\t\tkey: string | number,\n\t\tvalue: any,\n\t\toldValue: any,\n\t\tisList: boolean,\n\t) {\n\t\tif (!isDiffableObject(value)) {\n\t\t\t// for primitive fields, we can use plain sets and\n\t\t\t// do not need to recurse, of course\n\t\t\tif (!compareNonDiffable(value, oldValue)) {\n\t\t\t\tif (isList) {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\t\t\t\tindex: key as number,\n\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tpatches.push(\n\t\t\t\t\t\taddAuthzToOp(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t'Shallow diff was given a nested object. This is an error in verdant!',\n\t\t\t);\n\t\t}\n\t}\n\n\tif (Array.isArray(from) && Array.isArray(to)) {\n\t\t// diffing is more naive than native array operations.\n\t\t// we can only look at each element and decide if it should\n\t\t// be replaced or removed - no moves or pushes, etc.\n\t\tfor (let i = 0; i < to.length; i++) {\n\t\t\tconst value = to[i];\n\t\t\tconst oldValue = from[i];\n\t\t\tdiffItems(i, value, oldValue, true);\n\t\t}\n\t\t// remove any remaining items at the end of the array\n\t\tconst deletedItemsAtEnd = from.length - to.length;\n\t\tif (deletedItemsAtEnd > 0) {\n\t\t\t// push the list-delete for the deleted items\n\t\t\tpatches.push(\n\t\t\t\taddAuthzToOp(\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'list-delete',\n\t\t\t\t\t\t\tindex: to.length,\n\t\t\t\t\t\t\tcount: deletedItemsAtEnd,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tauthz,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t} else if (Array.isArray(from) || Array.isArray(to)) {\n\t\tthrow new Error('Cannot diff an array with an object');\n\t} else if (isDiffableObject(from) && isDiffableObject(to)) {\n\t\tconst oldKeys = new Set(Object.keys(from));\n\t\tfor (const [key, value] of Object.entries(to)) {\n\t\t\toldKeys.delete(key);\n\n\t\t\tif (isOidKey(key)) continue;\n\n\t\t\tconst oldValue = from[key];\n\n\t\t\tdiffItems(key, value, oldValue, false);\n\t\t}\n\n\t\t// this set now only contains keys which were not in the new object\n\t\tfor (const key of oldKeys) {\n\t\t\tif (isOidKey(key)) continue;\n\t\t\t// push the delete for the property\n\t\t\tpatches.push(\n\t\t\t\taddAuthzToOp(\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'remove',\n\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tauthz,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn patches;\n}\n\n/**\n * Takes a basic object and constructs a patch list to create it and\n * all of its nested objects.\n */\nexport function initialToPatches(\n\tinitial: any,\n\trootOid: ObjectIdentifier,\n\tgetNow: () => string,\n\tcreateSubId?: () => string,\n\tpatches: Operation[] = [],\n\toptions?: { authz?: string },\n) {\n\tassignOid(initial, rootOid);\n\tassignOidsToAllSubObjects(initial, createSubId);\n\tconst normalized = normalize(initial);\n\tfor (const key of normalized.keys()) {\n\t\tconst value = normalized.get(key);\n\t\tconst op: Operation = {\n\t\t\toid: key,\n\t\t\ttimestamp: getNow(),\n\t\t\tdata: {\n\t\t\t\top: 'initialize',\n\t\t\t\tvalue: removeOid(value),\n\t\t\t},\n\t\t};\n\t\tpatches.push(addAuthzToOp(op, options?.authz));\n\t}\n\treturn patches;\n}\n\nexport function shallowInitialToPatches(\n\tinitial: any,\n\trootOid: ObjectIdentifier,\n\tgetNow: () => string,\n\tpatches: Operation[] = [],\n\toptions?: { authz?: string },\n) {\n\tconst op: Operation = {\n\t\toid: rootOid,\n\t\ttimestamp: getNow(),\n\t\tdata: {\n\t\t\top: 'initialize',\n\t\t\tvalue: initial,\n\t\t},\n\t};\n\tpatches.push(addAuthzToOp(op, options?.authz));\n\treturn patches;\n}\n\n// saves a bit of network traffic by not attaching authz\n// key at all if not present\nfunction addAuthzToOp(op: Operation, authz?: string) {\n\tif (authz) {\n\t\top.authz = authz;\n\t}\n\treturn op;\n}\n\nexport function groupPatchesByOid(patches: Operation[]) {\n\tconst grouped: Record<ObjectIdentifier, Operation[]> = {};\n\tfor (const patch of patches) {\n\t\tif (patch.oid in grouped) {\n\t\t\tgrouped[patch.oid].push(patch);\n\t\t} else {\n\t\t\tgrouped[patch.oid] = [patch];\n\t\t}\n\t}\n\treturn grouped;\n}\n\nexport function groupPatchesByRootOid(patches: Operation[]) {\n\tconst grouped: Record<ObjectIdentifier, Operation[]> = {};\n\tfor (const patch of patches) {\n\t\tconst root = getOidRoot(patch.oid);\n\t\tif (root in grouped) {\n\t\t\tgrouped[root].push(patch);\n\t\t} else {\n\t\t\tgrouped[root] = [patch];\n\t\t}\n\t}\n\treturn grouped;\n}\n\nexport function groupBaselinesByRootOid(baselines: DocumentBaseline[]) {\n\tconst grouped: Record<ObjectIdentifier, DocumentBaseline[]> = {};\n\tfor (const patch of baselines) {\n\t\tconst root = getOidRoot(patch.oid);\n\t\tif (root in grouped) {\n\t\t\tgrouped[root].push(patch);\n\t\t} else {\n\t\t\tgrouped[root] = [patch];\n\t\t}\n\t}\n\treturn grouped;\n}\n\nexport type NormalizedObject =\n\t| {\n\t\t\t[key: PropertyName]: PropertyValue;\n\t }\n\t| Array<PropertyValue>;\n\nfunction listCheck(obj: any): obj is Array<unknown> {\n\tif (!Array.isArray(obj)) {\n\t\tconsole.error(\n\t\t\t`Cannot apply list patch; expected array, received ${JSON.stringify(\n\t\t\t\tobj,\n\t\t\t)}. This suggests your data is changing from a list to an object over time. (OID: ${maybeGetOid(\n\t\t\t\tobj,\n\t\t\t)})`,\n\t\t);\n\t\treturn false;\n\t} else {\n\t\treturn true;\n\t}\n}\n\n/**\n * The incoming object should already be normalized!\n * This function will mutate the base object.\n */\nexport function applyPatch<T extends NormalizedObject>(\n\tbase: T | undefined,\n\tpatch: OperationPatch,\n\t/**\n\t * Optionally supply a list to which any refs which\n\t * are removed during the patch will be appended.\n\t */\n\tdeletedRefs?: (FileRef | ObjectRef)[],\n): T | undefined {\n\t// deleted objects are represented by undefined\n\t// and remain deleted unless re-initialized\n\tif ((base === undefined || base === null) && patch.op !== 'initialize') {\n\t\treturn base;\n\t}\n\t// ditch typing internally.\n\tconst baseAsAny = base as any;\n\tlet index;\n\tlet spliceResult: any[];\n\n\t// a helper, pass it a value which is about\n\t// to be removed and it will append it to the list\n\t// if it was a ref\n\tfunction checkRef(field: any) {\n\t\t// don't bother if not supplied\n\t\tif (!deletedRefs) return;\n\t\tif (isRef(field)) {\n\t\t\tdeletedRefs.push(field);\n\t\t}\n\t}\n\n\tswitch (patch.op) {\n\t\tcase 'set':\n\t\t\tcheckRef(baseAsAny[patch.name]);\n\t\t\tbaseAsAny[patch.name] = patch.value;\n\t\t\tbreak;\n\t\tcase 'remove':\n\t\t\tcheckRef(baseAsAny[patch.name]);\n\t\t\tdelete baseAsAny[patch.name];\n\t\t\tbreak;\n\t\tcase 'list-set':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tcheckRef(base[patch.index]);\n\t\t\t\tbase[patch.index] = patch.value;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-push':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tbase.push(patch.value);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-delete':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tcheckRef(base[patch.index]);\n\t\t\t\tbase.splice(patch.index, patch.count);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-move-by-index':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tspliceResult = base.splice(patch.from, 1);\n\t\t\t\tbase.splice(patch.to, 0, spliceResult[0]);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-remove':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tdo {\n\t\t\t\t\tconst valueToRemove = patch.value;\n\t\t\t\t\tif (patch.only === 'last') {\n\t\t\t\t\t\tif (isObjectRef(valueToRemove)) {\n\t\t\t\t\t\t\tindex = findLastIndex(\n\t\t\t\t\t\t\t\tbase,\n\t\t\t\t\t\t\t\t(item: any) => item.id === valueToRemove.id,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = base.lastIndexOf(valueToRemove);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (isObjectRef(valueToRemove)) {\n\t\t\t\t\t\t\tindex = base.findIndex(\n\t\t\t\t\t\t\t\t(item: any) => item.id === valueToRemove.id,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = base.indexOf(valueToRemove);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (index !== -1) {\n\t\t\t\t\t\tcheckRef(base[index]);\n\t\t\t\t\t\tbase.splice(index, 1);\n\t\t\t\t\t}\n\t\t\t\t} while (!patch.only && index !== -1);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-add':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tconst alreadyHas = base.some((item: any) => {\n\t\t\t\t\tif (isObjectRef(item) && isObjectRef(patch.value)) {\n\t\t\t\t\t\treturn item.id === patch.value.id;\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn item === patch.value;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tif (!alreadyHas) {\n\t\t\t\t\tbase.push(patch.value);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-move-by-ref':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tindex = base.findIndex((v) => compareRefs(v, patch.value));\n\t\t\t\tspliceResult = base.splice(index, 1);\n\t\t\t\tbase.splice(patch.index, 0, spliceResult[0]);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'list-insert':\n\t\t\tif (listCheck(base)) {\n\t\t\t\tif (!patch.value && !patch.values) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot apply list insert patch; expected value or values, received ${JSON.stringify(\n\t\t\t\t\t\t\tpatch,\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (patch.value) {\n\t\t\t\t\tbase.splice(patch.index, 0, patch.value);\n\t\t\t\t} else {\n\t\t\t\t\tbase.splice(patch.index, 0, ...patch.values!);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'delete':\n\t\t\t// collect all refs that are deleted\n\t\t\tif (Array.isArray(base)) {\n\t\t\t\tbase.forEach(checkRef);\n\t\t\t} else if (isObject(base)) {\n\t\t\t\tObject.values(base || {}).forEach(checkRef);\n\t\t\t}\n\t\t\treturn undefined;\n\t\tcase 'initialize':\n\t\t\treturn cloneDeep(patch.value);\n\t\tcase 'touch':\n\t\t\t// no-op\n\t\t\treturn base;\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported patch operation: ${(patch as any).op}`);\n\t}\n\treturn base;\n}\n\nexport function applyOperations<T extends NormalizedObject>(\n\tbase: T | undefined,\n\toperations: Operation[],\n\tdeletedRefs?: (ObjectRef | FileRef)[],\n\t/**\n\t * Provide and it will be assigned any authz info assigned\n\t * in applied operations\n\t */\n\tauthzRef?: { authz?: string },\n): T | undefined {\n\tlet cur = base as T | undefined;\n\tfor (const op of operations) {\n\t\tcur = applyPatch(cur, op.data, deletedRefs);\n\t\tif (authzRef && op.data.op === 'initialize' && op.authz) {\n\t\t\tauthzRef.authz = op.authz;\n\t\t}\n\t}\n\treturn cur;\n}\n\n/**\n * Mutates the original object in place. Returns all referenced\n * objects oids.\n */\nexport function substituteRefsWithObjects(\n\tbase: any,\n\trefs: Map<ObjectIdentifier, any>,\n\tused: ObjectIdentifier[] = [],\n): ObjectIdentifier[] {\n\tif (Array.isArray(base)) {\n\t\tfor (let i = 0; i < base.length; i++) {\n\t\t\tconst item = base[i];\n\t\t\tbase[i] = dereference(item, refs, used);\n\t\t\tif (isObject(base[i])) {\n\t\t\t\tsubstituteRefsWithObjects(base[i], refs, used);\n\t\t\t}\n\t\t}\n\t} else if (isFileRef(base)) {\n\t\t// don't do anything with file refs\n\t} else if (isObject(base)) {\n\t\t// not sure where to put this assertion but it's important to make\n\t\t// sure all nested objects include an OID\n\t\tassert(\n\t\t\tmaybeGetOid(base),\n\t\t\t`Object ${JSON.stringify(base)} must have an oid`,\n\t\t);\n\t\tfor (const key of Object.keys(base)) {\n\t\t\tbase[key] = dereference(base[key], refs, used);\n\n\t\t\t// now that objects are in place, recursively substitute\n\t\t\tif (isObject(base[key])) {\n\t\t\t\tsubstituteRefsWithObjects(base[key], refs, used);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn used;\n}\n\nfunction dereference(\n\tinput: any,\n\trefs: Map<ObjectIdentifier, any>,\n\tused: ObjectIdentifier[],\n): any {\n\tif (isObjectRef(input)) {\n\t\tused.push(input.id);\n\t\tconst resolved = refs.get(input.id);\n\t\tassert(!!resolved, `No value was found in object map for ${input.id}`);\n\t\treturn assignOid(resolved, input.id);\n\t} else {\n\t\treturn input;\n\t}\n}\n\nexport function substituteFirstLevelObjectsWithRefs<\n\tBase extends { [key: string]: any } | any[],\n>(\n\tbase: Base,\n\trefObjects: Map<ObjectIdentifier, any> = new Map(),\n): Map<ObjectIdentifier, any> {\n\tif (Array.isArray(base)) {\n\t\tfor (let i = 0; i < base.length; i++) {\n\t\t\tconst item = base[i];\n\t\t\tif (isObject(item)) {\n\t\t\t\tconst oid = getOid(item);\n\t\t\t\tbase[i] = {\n\t\t\t\t\t'@@type': 'ref',\n\t\t\t\t\tid: oid,\n\t\t\t\t};\n\t\t\t\trefObjects.set(oid, item);\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor (const [key, value] of Object.entries(base)) {\n\t\t\tif (isObject(value)) {\n\t\t\t\tbase[key] = {\n\t\t\t\t\t'@@type': 'ref',\n\t\t\t\t\tid: getOid(value),\n\t\t\t\t};\n\n\t\t\t\trefObjects.set(getOid(value), value);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn refObjects;\n}\n\nexport function operationSupersedes(op: Operation): PropertyName | boolean {\n\t// todo: add 'remove'\n\tif (op.data.op === 'set') {\n\t\treturn op.data.name;\n\t}\n\n\treturn false;\n}\n\n/**\n * Determine if an operation is superseded by a set of supersession values\n * provided by operationSupersedes. Assumes the operation OID matches\n * already.\n */\nexport function isSuperseded(\n\top: Operation,\n\tsupersession: Set<PropertyName | boolean>,\n) {\n\tif (supersession.has(true)) {\n\t\treturn true;\n\t} else if (op.data.op === 'set' || op.data.op === 'remove') {\n\t\treturn supersession.has(op.data.name);\n\t}\n\n\treturn false;\n}\n\n/**\n * Allocates a copy with only valid keys for transmitting over\n * the protocol. TODO: make this unnecessary or evaluate if it's\n * worth it to do.\n */\nexport function pickValidOperationKeys(operation: Operation): Operation {\n\treturn {\n\t\toid: operation.oid,\n\t\ttimestamp: operation.timestamp,\n\t\tdata: operation.data,\n\t\tauthz: operation.authz,\n\t};\n}\n", "export interface ReplicaInfo {\n\tid: string;\n\tackedLogicalTime: string | null;\n}\n\n/**\n * Different token types allow different replica client behaviors.\n * - Realtime: allows the client to subscribe to realtime events.\n * - Push: allows the client to push and pull data with HTTP, but not use realtime.\n * - PassivePush: allows the client to push and pull data with HTTP, but offline changes\n * will be discarded on reconnect.\n * - PassiveRealtime: allows the client to subscribe to realtime events, but offline changes\n * \t\t will be discarded on reconnect.\n * - ReadOnlyPull: the client may only pull changes using HTTP. It may not subscribe\n * to realtime events or push changes.\n * - ReadOnlyRealtime: the client may only subscribe to realtime events or pull from HTTP.\n * It may not push changes.\n *\n * Choosing the right token type can optimize client storage metrics significantly when\n * many replicas are connecting to a library.\n */\nexport enum ReplicaType {\n\tRealtime,\n\tPush,\n\tPassiveRealtime,\n\tPassivePush,\n\tReadOnlyPull,\n\tReadOnlyRealtime,\n}\n", "import cuid from 'cuid';\nimport {\n\tShapeFromFieldsWithDefaults,\n\tStorageAnyFieldSchema,\n\tStorageArrayFieldSchema,\n\tStorageBooleanFieldSchema,\n\tStorageFieldSchema,\n\tStorageFieldsSchema,\n\tStorageFileFieldSchema,\n\tStorageMapFieldSchema,\n\tStorageNumberFieldSchema,\n\tStorageObjectFieldSchema,\n\tStorageStringFieldSchema,\n} from './types.js';\n\nconst objectField = <Props extends StorageFieldsSchema>(args: {\n\tproperties: Props;\n\tnullable?: boolean;\n\tdefault?:\n\t\t| ShapeFromFieldsWithDefaults<Props>\n\t\t| (() => ShapeFromFieldsWithDefaults<Props>);\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageObjectFieldSchema<Props> => {\n\treturn {\n\t\ttype: 'object',\n\t\t...args,\n\t};\n};\n\nconst arrayField = <T extends StorageFieldSchema>(args: {\n\titems: T;\n\tnullable?: boolean;\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageArrayFieldSchema<T> => {\n\treturn {\n\t\ttype: 'array',\n\t\t...args,\n\t};\n};\n\nconst stringField = (args?: {\n\tnullable?: boolean;\n\tdefault?: string | (() => string);\n\toptions?: string[];\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageStringFieldSchema => {\n\treturn {\n\t\ttype: 'string',\n\t\t...args,\n\t};\n};\n\nconst numberField = (args?: {\n\tnullable?: boolean;\n\tdefault?: number | (() => number);\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageNumberFieldSchema => {\n\treturn {\n\t\ttype: 'number',\n\t\t...args,\n\t};\n};\n\nconst booleanField = (args?: {\n\tnullable?: boolean;\n\tdefault?: boolean | (() => boolean);\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageBooleanFieldSchema => {\n\treturn {\n\t\ttype: 'boolean',\n\t\t...args,\n\t};\n};\n\nconst anyField = <TShape>(args?: {\n\tdefault?: TShape;\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageAnyFieldSchema<TShape> => {\n\treturn {\n\t\ttype: 'any',\n\t\t...args,\n\t};\n};\n\nconst mapField = <T extends StorageFieldSchema>(args: {\n\tvalues: T;\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageMapFieldSchema<T> => {\n\treturn {\n\t\ttype: 'map',\n\t\t...args,\n\t};\n};\n\nconst fileField = (args?: {\n\tnullable?: boolean;\n\tdownloadRemote?: boolean;\n\t/** Add some docs to your field which will annotate the generated typing */\n\tdocumentation?: string;\n}): StorageFileFieldSchema => {\n\treturn {\n\t\ttype: 'file',\n\t\t...args,\n\t};\n};\n\n/**\n * Meant for use on primary key fields. Do not use this to refer\n * to another document as a 'foreign key'\n */\nconst idField = (): StorageStringFieldSchema => {\n\treturn {\n\t\ttype: 'string',\n\t\tdefault: cuid,\n\t};\n};\n\nexport const fields = {\n\tobject: objectField,\n\tarray: arrayField,\n\tstring: stringField,\n\tnumber: numberField,\n\tboolean: booleanField,\n\tany: anyField,\n\tmap: mapField,\n\tfile: fileField,\n\tid: idField,\n};\n", "import {\n\tCollectionCompoundIndices,\n\tStorageCollectionSchema,\n\tStorageDirectSyntheticSchema,\n\tStorageFieldsSchema,\n\tStorageSchema,\n\tStorageSyntheticIndexSchema,\n\tStorageSyntheticIndices,\n} from './types.js';\nimport { fields } from './fieldHelpers.js';\nimport cuid from 'cuid';\n\nexport function collection<\n\tFields extends StorageFieldsSchema,\n\tSynthetics extends StorageSyntheticIndices<Fields>,\n\tCompounds extends CollectionCompoundIndices<Fields, Synthetics>,\n>({\n\tsynthetics,\n\tindexes,\n\t...input\n}: StorageCollectionSchema<\n\tFields,\n\tSynthetics,\n\tCompounds\n>): StorageCollectionSchema<Fields, Synthetics, Compounds> {\n\t// back compat - copy synthetics in with indexes\n\tconst finalIndexes = { ...synthetics, ...indexes };\n\t// add all indexed fields into the synthetic indices (back compat)\n\tfor (const [key, field] of Object.entries(input.fields)) {\n\t\tif ('indexed' in field) {\n\t\t\tfinalIndexes[key] = {\n\t\t\t\tfield: key,\n\t\t\t} as StorageDirectSyntheticSchema<Fields>;\n\t\t}\n\t}\n\treturn {\n\t\t...input,\n\t\tindexes: finalIndexes as Synthetics,\n\t};\n}\n\nexport function schema<\n\t// Fields extends StorageFieldsSchema,\n\t// Indexes extends StorageSyntheticIndices<Fields>,\n\t// Compounds extends CollectionCompoundIndices<Fields, Indexes>,\n\tSchema extends StorageSchema<{\n\t\t[key: string]: StorageCollectionSchema<any, any, any>;\n\t}>,\n>(input: Schema): StorageSchema {\n\treturn input;\n}\nschema.collection = collection;\nschema.fields = fields;\nschema.generated = {\n\tid: cuid,\n};\n\nexport * from './types.js';\n\nexport * from './indexFilters.js';\nexport * from './fields.js';\nexport * from './validation.js';\nexport * from './children.js';\n", "import {\n\tCollectionCompoundIndexFilter,\n\tCollectionFilter,\n\tMatchCollectionIndexFilter,\n\tRangeCollectionIndexFilter,\n\tSortIndexFilter,\n\tStartsWithIndexFilter,\n} from './types.js';\n\nexport function isMatchIndexFilter(\n\tfilter: CollectionFilter,\n): filter is MatchCollectionIndexFilter {\n\treturn (filter as any).equals !== undefined;\n}\n\nexport function isRangeIndexFilter(\n\tfilter: CollectionFilter,\n): filter is RangeCollectionIndexFilter {\n\treturn (\n\t\t(filter as any).gte !== undefined ||\n\t\t(filter as any).lte !== undefined ||\n\t\t(filter as any).gt !== undefined ||\n\t\t(filter as any).lt !== undefined\n\t);\n}\n\nexport function isCompoundIndexFilter(\n\tfilter: CollectionFilter,\n): filter is CollectionCompoundIndexFilter {\n\treturn !!(filter as any).match;\n}\n\nexport function isStartsWithIndexFilter(\n\tfilter: CollectionFilter,\n): filter is StartsWithIndexFilter {\n\treturn (filter as any).startsWith !== undefined;\n}\n\nexport function isSortIndexFilter(\n\tfilter: CollectionFilter,\n): filter is SortIndexFilter {\n\treturn (\n\t\t!isRangeIndexFilter(filter) &&\n\t\t!isMatchIndexFilter(filter) &&\n\t\t!isCompoundIndexFilter(filter) &&\n\t\t!isStartsWithIndexFilter(filter) &&\n\t\t(filter as any).order\n\t);\n}\n", "import { LEGACY_OID_KEY, OID_KEY } from '../oidsLegacy.js';\nimport { isObject } from '../utils.js';\nimport type {\n\tStorageFieldSchema,\n\tStorageCollectionSchema,\n\tStorageFieldsSchema,\n} from './types.js';\n\nexport function isNullable(field: StorageFieldSchema) {\n\tif (field.type === 'any') return true;\n\tif (field.type === 'map') return false;\n\treturn field.nullable;\n}\n\nexport function hasDefault(field: StorageFieldSchema | undefined) {\n\tif (!field) return false;\n\tif (field.type === 'map') return true;\n\tif (field.type === 'array') return true;\n\tif (field.type === 'file') return false;\n\treturn field.default !== undefined;\n}\n\nexport function getDefault(field: StorageFieldSchema | undefined) {\n\tif (!field || !hasDefault(field)) return undefined;\n\tif (field.type === 'file') {\n\t\tif (isNullable(field)) return null;\n\t\treturn undefined;\n\t}\n\tif (field.type === 'map') return {};\n\tif (field.type === 'array') {\n\t\tif (isNullable(field)) return null;\n\t\treturn [];\n\t}\n\tif (field.type === 'object') {\n\t\tif (isNullable(field)) return null;\n\t\treturn undefined;\n\t}\n\tif (typeof field.default === 'function') {\n\t\treturn field.default();\n\t}\n\treturn field.default;\n}\n\nexport function isPrunePoint(field: StorageFieldSchema) {\n\treturn isNullable(field) || hasDefault(field);\n}\n\nexport function addFieldDefaults(\n\tcollection: StorageCollectionSchema,\n\tvalue: any,\n) {\n\tfor (const [key, field] of Object.entries(collection.fields)) {\n\t\tconst defaultValue = getFieldDefault(field);\n\t\tif (\n\t\t\t(defaultValue !== undefined && value[key] === undefined) ||\n\t\t\t// covers the case where a previously nullable field\n\t\t\t// now has a default during a new migration\n\t\t\t(!isNullable(field) && value[key] === null)\n\t\t) {\n\t\t\tvalue[key] = defaultValue;\n\t\t}\n\t\tif (value[key]) {\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(value[key], field);\n\t\t}\n\t}\n\treturn value;\n}\n\nexport function traverseCollectionFieldsAndApplyDefaults(\n\tvalue: any,\n\tfield: StorageFieldSchema,\n) {\n\tif (value === undefined || value === null) return value;\n\tif (field.type === 'object') {\n\t\tfor (const [key, subField] of Object.entries(\n\t\t\tfield.properties as StorageFieldsSchema,\n\t\t)) {\n\t\t\tif (value[key] === undefined) {\n\t\t\t\tconst defaultValue = getFieldDefault(subField);\n\t\t\t\tif (defaultValue !== undefined) {\n\t\t\t\t\tvalue[key] = defaultValue;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(value[key], subField);\n\t\t}\n\t} else if (field.type === 'array') {\n\t\tfor (const item of value) {\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(item, field.items);\n\t\t}\n\t} else if (field.type === 'map') {\n\t\tfor (const [key, item] of Object.entries(value)) {\n\t\t\t// santiy check to weed out any id field\n\t\t\tif (key === OID_KEY || key === LEGACY_OID_KEY) continue;\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(item, field.values);\n\t\t}\n\t}\n}\n\nexport function getFieldDefault(field: StorageFieldSchema) {\n\tif (\n\t\tfield.type === 'string' ||\n\t\tfield.type === 'number' ||\n\t\tfield.type === 'boolean' ||\n\t\tfield.type === 'any'\n\t) {\n\t\tif (field.default && typeof field.default === 'function') {\n\t\t\treturn field.default();\n\t\t} else if (field.default !== undefined) {\n\t\t\t// TODO: structuredClone?\n\t\t\treturn JSON.parse(JSON.stringify(field.default));\n\t\t}\n\t}\n\tif (field.type === 'array') {\n\t\treturn [];\n\t}\n\tif (field.type === 'map') {\n\t\treturn {};\n\t}\n\tif (field.type !== 'any' && field.nullable) {\n\t\treturn null;\n\t}\n\tif (field.type === 'object' && field.default) {\n\t\tconst defaultValue =\n\t\t\t// @ts-ignore\n\t\t\ttypeof field.default === 'function'\n\t\t\t\t? field.default()\n\t\t\t\t: JSON.parse(JSON.stringify(field.default));\n\t\tfor (const [key, property] of Object.entries(\n\t\t\tfield.properties as StorageFieldsSchema,\n\t\t)) {\n\t\t\tif (defaultValue[key] === undefined) {\n\t\t\t\tdefaultValue[key] = getFieldDefault(property);\n\t\t\t}\n\t\t}\n\t\treturn defaultValue;\n\t}\n\treturn undefined;\n}\n\nexport function removeExtraProperties(\n\tcollection: StorageCollectionSchema,\n\tvalue: any,\n) {\n\tfor (const [key, fieldValue] of Object.entries(value)) {\n\t\t// MUST NOT DELETE THESE!\n\t\tif (key === OID_KEY || key === LEGACY_OID_KEY) continue;\n\n\t\tif (!collection.fields[key]) {\n\t\t\tdelete value[key];\n\t\t} else {\n\t\t\ttraverseCollectionFieldsAndRemoveExtraProperties(\n\t\t\t\tfieldValue,\n\t\t\t\tcollection.fields[key],\n\t\t\t);\n\t\t}\n\t}\n\treturn value;\n}\n\nexport function traverseCollectionFieldsAndRemoveExtraProperties(\n\tvalue: any,\n\tfield: StorageFieldSchema,\n) {\n\tif (isObject(value) && field.type === 'object') {\n\t\tfor (const [key, fieldValue] of Object.entries(value)) {\n\t\t\tif (!field.properties[key]) {\n\t\t\t\tdelete value[key];\n\t\t\t} else {\n\t\t\t\ttraverseCollectionFieldsAndRemoveExtraProperties(\n\t\t\t\t\tfieldValue,\n\t\t\t\t\tfield.properties[key],\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t} else if (Array.isArray(value) && field.type === 'array') {\n\t\tfor (const item of value) {\n\t\t\ttraverseCollectionFieldsAndRemoveExtraProperties(item, field.items);\n\t\t}\n\t}\n}\n", "import { isFile, isFileData } from '../files.js';\nimport { OID_KEY } from '../oidsLegacy.js';\nimport { isObject } from '../utils.js';\nimport { getFieldDefault, hasDefault, isNullable } from './fields.js';\nimport { StorageFieldSchema, StorageFieldsSchema } from './types.js';\n\nexport function validateEntity(\n\tschema: StorageFieldsSchema,\n\tentity: any,\n): EntityValidationProblem | void {\n\tfor (const [key, value] of Object.entries(entity)) {\n\t\t// legacy -- old objects sometimes accidentally include this key\n\t\tif (key === OID_KEY) continue;\n\t\tif (!schema[key]) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-key',\n\t\t\t\tfieldPath: [key],\n\t\t\t\tmessage: `Invalid field \"${key}\"`,\n\t\t\t};\n\t\t}\n\t\tif (value) {\n\t\t\tconst err = validateEntityField({\n\t\t\t\tfield: schema[key],\n\t\t\t\tvalue,\n\t\t\t\tfieldPath: [key],\n\t\t\t});\n\t\t\tif (err) return err;\n\t\t}\n\t}\n\treturn;\n}\n\nexport type EntityValidationProblem = {\n\ttype:\n\t\t| 'null'\n\t\t| 'no-default'\n\t\t| 'invalid-type'\n\t\t| 'invalid-value'\n\t\t| 'invalid-key';\n\tfieldPath: (string | number)[];\n\tmessage: string;\n};\n\nexport function validateEntityField({\n\tfield,\n\tvalue,\n\tfieldPath = [],\n\tdepth,\n\trequireDefaults,\n}: {\n\tfield: StorageFieldSchema;\n\tvalue: any;\n\tfieldPath: (string | number)[];\n\tdepth?: number;\n\trequireDefaults?: boolean;\n}): EntityValidationProblem | undefined {\n\tif (depth !== undefined && depth <= 0) return;\n\n\tif (isNullable(field) && value === null) return;\n\tif (value === null) {\n\t\tif (requireDefaults || !hasDefault(field)) {\n\t\t\treturn {\n\t\t\t\ttype: 'no-default',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Invalid null value for field ${formatField(fieldPath)}`,\n\t\t\t};\n\t\t}\n\t}\n\n\tif (field.type === 'object') {\n\t\tif (!isObject(value)) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected object ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t\tfor (const [key, subField] of Object.entries(\n\t\t\tfield.properties as StorageFieldsSchema,\n\t\t)) {\n\t\t\t// legacy -- old objects sometimes accidentally include this key\n\t\t\tif (key === OID_KEY) continue;\n\t\t\tif (value[key]) {\n\t\t\t\tvalidateEntityField({\n\t\t\t\t\tfield: subField,\n\t\t\t\t\tvalue: value[key],\n\t\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\t// check for unexpected keys\n\t\tfor (const key of Object.keys(value)) {\n\t\t\tif (!field.properties[key]) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'invalid-key',\n\t\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\t\tmessage: `Invalid unexpected field \"${key}\" on value ${formatField(\n\t\t\t\t\t\tfieldPath,\n\t\t\t\t\t)}`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t} else if (field.type === 'array') {\n\t\tif (!Array.isArray(value)) {\n\t\t\tif (value === null && field.nullable) return;\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-value',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected array ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t\tfor (const item of value) {\n\t\t\tvalidateEntityField({\n\t\t\t\tfield: field.items,\n\t\t\t\tvalue: item,\n\t\t\t\tfieldPath: [...fieldPath, '[]'],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t});\n\t\t}\n\t} else if (field.type === 'map') {\n\t\tif (!isObject(value)) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected map for field ${formatField(\n\t\t\t\t\tfieldPath,\n\t\t\t\t)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t\tfor (const [key, item] of Object.entries(value)) {\n\t\t\tvalidateEntityField({\n\t\t\t\tfield: field.values,\n\t\t\t\tvalue: item,\n\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t});\n\t\t}\n\t} else if (field.type === 'string') {\n\t\tif (typeof value !== 'string') {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected string ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t\tif (field.options && !field.options.includes(value)) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-value',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected one of ${field.options.join(\n\t\t\t\t\t', ',\n\t\t\t\t)} for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t} else if (field.type === 'boolean') {\n\t\tif (typeof value !== 'boolean') {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected boolean ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t} else if (field.type === 'number') {\n\t\tif (typeof value !== 'number') {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected number ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t} else if (field.type === 'file') {\n\t\tif (!isFile(value) && !isFileData(value)) {\n\t\t\treturn {\n\t\t\t\ttype: 'invalid-type',\n\t\t\t\tfieldPath,\n\t\t\t\tmessage: `Expected file ${\n\t\t\t\t\tfield.nullable ? 'or null ' : ''\n\t\t\t\t}for field ${formatField(fieldPath)}, got ${value}`,\n\t\t\t};\n\t\t}\n\t}\n}\n\nfunction formatField(fieldPath: (string | number)[]) {\n\tif (fieldPath.length === 0) return 'root';\n\treturn fieldPath.join('.');\n}\n\nexport function constrainEntity(schema: StorageFieldsSchema, entity: any): any {\n\tconst constrained: any = {};\n\tfor (const [key, value] of Object.entries(entity)) {\n\t\tif (!schema[key]) continue;\n\t\tconstrained[key] = constrainEntityField({\n\t\t\tfield: schema[key],\n\t\t\tvalue,\n\t\t\tfieldPath: [key],\n\t\t});\n\t}\n\treturn constrained;\n}\n\nexport function constrainEntityField({\n\tfield,\n\tvalue,\n\tfieldPath = [],\n\tdepth,\n}: {\n\tfield: StorageFieldSchema;\n\tvalue: any;\n\tfieldPath?: (string | number)[];\n\tdepth?: number;\n}): any {\n\tconst validationProblem = validateEntityField({\n\t\tfield,\n\t\tvalue,\n\t\tfieldPath,\n\t\tdepth,\n\t\trequireDefaults: true,\n\t});\n\n\tif (validationProblem) {\n\t\tthrow new Error(`Validation error: ${validationProblem.message}`);\n\t}\n\n\tif (field.type === 'object') {\n\t\tif (!isObject(value)) return value;\n\t\tconst constrained: any = {};\n\t\tfor (const [key, subField] of Object.entries(\n\t\t\tfield.properties as StorageFieldsSchema,\n\t\t)) {\n\t\t\tconstrained[key] = constrainEntityField({\n\t\t\t\tfield: subField,\n\t\t\t\tvalue: value[key],\n\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t});\n\t\t}\n\t\treturn constrained;\n\t} else if (field.type === 'array') {\n\t\tif (!Array.isArray(value)) return value;\n\t\treturn value.map((item) =>\n\t\t\tconstrainEntityField({\n\t\t\t\tfield: field.items,\n\t\t\t\tvalue: item,\n\t\t\t\tfieldPath: [...fieldPath, '[]'],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t}),\n\t\t);\n\t} else if (field.type === 'map') {\n\t\tif (!isObject(value)) return value;\n\t\tconst constrained: any = {};\n\t\tfor (const [key, item] of Object.entries(value)) {\n\t\t\tconstrained[key] = constrainEntityField({\n\t\t\t\tfield: field.values,\n\t\t\t\tvalue: item,\n\t\t\t\tfieldPath: [...fieldPath, key],\n\t\t\t\tdepth: depth !== undefined ? depth - 1 : undefined,\n\t\t\t});\n\t\t}\n\t\treturn constrained;\n\t} else {\n\t\treturn value;\n\t}\n}\n", "import { StorageFieldSchema, StorageFieldsSchema } from './types.js';\n\nexport function getChildFieldSchema(\n\tschema: StorageFieldSchema | StorageFieldsSchema,\n\tkey: string | number,\n): StorageFieldSchema | null {\n\tif (schema.type === 'object') {\n\t\treturn schema.properties[key];\n\t} else if (schema.type === 'array') {\n\t\treturn schema.items;\n\t} else if (schema.type === 'map') {\n\t\treturn schema.values;\n\t} else if (schema.type === 'any') {\n\t\treturn schema;\n\t} else if (!('type' in schema)) {\n\t\treturn schema[key] ?? null;\n\t}\n\treturn null;\n}\n", "import {\n\tStorageCollectionSchema,\n\tStorageSyntheticIndexSchema,\n\tCollectionCompoundIndex,\n\tStorageDirectSyntheticSchema,\n} from './index.js';\n\n// unlikely to be used unicode character\nexport const COMPOUND_INDEX_SEPARATOR = '\\uFFFFFE';\n// 1 lower than separator\nexport const COMPOUND_INDEX_LOWER_BOUND_SEPARATOR = '\\u0000';\n// 1 higher than separator\nexport const COMPOUND_INDEX_UPPER_BOUND_SEPARATOR = '\\uFFFFFF';\n\ntype IndexableFieldValue = string | number | boolean | any[];\nexport type CompoundIndexValue = string | string[];\n\nexport function createCompoundIndexValue(\n\t...fields: IndexableFieldValue[]\n): CompoundIndexValue {\n\tconst value = expandArrayIndex(fields);\n\tif (value.length === 1) {\n\t\treturn value[0];\n\t}\n\treturn value;\n}\n\nexport function createUpperBoundIndexValue(\n\t...fields: IndexableFieldValue[]\n): string {\n\treturn (\n\t\tfields.join(COMPOUND_INDEX_SEPARATOR) +\n\t\t`${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`\n\t);\n}\n\nexport function createLowerBoundIndexValue(\n\t...fields: IndexableFieldValue[]\n): string {\n\treturn (\n\t\tfields.join(COMPOUND_INDEX_SEPARATOR) +\n\t\t`${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`\n\t);\n}\n\n/**\n * Whenever an array value is included in a compound index, we have to expand\n * the value to include all permutations of values in the array.\n * For example if we had an index id + tags on a document\n *\n * {\n * id: '1',\n * tags: ['a', 'b']\n * }\n *\n * we want to create an index:\n *\n * id_tags: ['1#a', '1#b']\n *\n * If multiple arrays are indexed we have to exponentially expand...\n *\n * id_tags_tags2: ['1#a#a', '1#a#b', '1#b#a', '1#b#b']\n *\n * To generalize this we construct a 2-level array of strings.\n * Iterating over indexed values, we expand each item into N items if\n * the current value is an array.\n *\n * Then we combine all nested arrays into compound index values.\n * This will produce an array of 1 element if none of the indexed values\n * were arrays. The caller should unwrap that.\n *\n * This function also deduplicates values.\n */\nfunction expandArrayIndex(fields: IndexableFieldValue[]): string[] {\n\tlet value: string[][] = [[]];\n\tfor (const field of fields) {\n\t\tif (Array.isArray(field)) {\n\t\t\tconst newValue: string[][] = [];\n\t\t\tfor (const previousValue of value) {\n\t\t\t\tfor (const fieldValue of field) {\n\t\t\t\t\tnewValue.push(previousValue.concat(fieldValue));\n\t\t\t\t}\n\t\t\t}\n\t\t\tvalue = newValue;\n\t\t} else {\n\t\t\tfor (const item of value) {\n\t\t\t\titem.push(`${field}`);\n\t\t\t}\n\t\t}\n\t}\n\treturn Array.from(\n\t\tnew Set(\n\t\t\tvalue.map((item) => {\n\t\t\t\treturn item.join(COMPOUND_INDEX_SEPARATOR);\n\t\t\t}),\n\t\t),\n\t);\n}\n\nexport function isDirectSynthetic(\n\tindex: any,\n): index is StorageDirectSyntheticSchema<any> {\n\treturn !!index.field;\n}\n\nexport function computeSynthetics(schema: StorageCollectionSchema, obj: any) {\n\tconst result: Record<string, any> = {};\n\tfor (const [name, property] of Object.entries(schema.indexes || {})) {\n\t\tconst index = property as StorageSyntheticIndexSchema<any>;\n\t\tif (isDirectSynthetic(index)) {\n\t\t\tresult[name] = sanitizeIndexValue(obj[index.field]);\n\t\t} else {\n\t\t\tresult[name] = sanitizeIndexValue(index.compute(obj));\n\t\t}\n\t}\n\treturn result;\n}\n\nexport function computeCompoundIndices(\n\tschema: StorageCollectionSchema<any, any, any>,\n\tdoc: any,\n): any {\n\treturn Object.entries(schema.compounds || {}).reduce<\n\t\tRecord<string, CompoundIndexValue>\n\t>(\n\t\t(acc, [indexKey, index]) => {\n\t\t\tacc[indexKey] = createCompoundIndexValue(\n\t\t\t\t...(index as CollectionCompoundIndex<any, any>).of.map(\n\t\t\t\t\t(key) => doc[key] as string | number,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<string, CompoundIndexValue>,\n\t);\n}\n\nfunction computeIndexedFields(schema: StorageCollectionSchema, doc: any) {\n\treturn Object.entries(schema.fields).reduce<Record<string, any>>(\n\t\t(acc, [key, field]) => {\n\t\t\t// TODO: remove once I'm comfortable dropping 'indexed' support\n\t\t\tif ('indexed' in field) {\n\t\t\t\tacc[key] = sanitizeIndexValue(doc[key]);\n\t\t\t}\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n}\n\nexport function getIndexValues(\n\tschema: StorageCollectionSchema<any, any, any>,\n\tdoc: any,\n) {\n\tconst basicIndexes: any = {\n\t\t[schema.primaryKey]: doc[schema.primaryKey],\n\t\t...computeIndexedFields(schema, doc),\n\t\t...computeSynthetics(schema, doc),\n\t};\n\tObject.assign(\n\t\tbasicIndexes,\n\t\tcomputeCompoundIndices(schema, { ...doc, ...basicIndexes }),\n\t);\n\tbasicIndexes['@@@snapshot'] = JSON.stringify(doc);\n\treturn basicIndexes;\n}\n\nexport function assignIndexValues(\n\tschema: StorageCollectionSchema<any, any, any>,\n\tdoc: any,\n) {\n\tObject.assign(doc, computeSynthetics(schema, doc));\n\tObject.assign(doc, computeCompoundIndices(schema, doc));\n\treturn doc;\n}\n\nexport const NULL_INDEX_VALUE = 'null';\n\nexport function sanitizeIndexValue(\n\tvalue: unknown,\n): string | number | (string | number)[] {\n\tif (value === null) {\n\t\treturn NULL_INDEX_VALUE;\n\t}\n\tif (typeof value === 'string' || typeof value === 'number') {\n\t\treturn value;\n\t}\n\tif (typeof value === 'boolean' || value === null) {\n\t\treturn `${value}`;\n\t}\n\tif (value === undefined) {\n\t\t// this shouldn't happen ,but for resiliency...\n\t\treturn 'undefined';\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map(sanitizeIndexValue) as any;\n\t}\n\tthrow new Error(`Unsupported index value: ${value}`);\n}\n", "import {\n\tstableStringify,\n\tStorageCollectionSchema,\n\tStorageSchema,\n\taddFieldDefaults,\n\tStorageDocument,\n\tCollectionFilter,\n\tStorageDocumentInit,\n\tremoveExtraProperties,\n\tassert,\n\thasOid,\n\tassignOid,\n\tgetOid,\n\thasDefault,\n\tvalidateEntity,\n\tAuthorizationKey,\n} from './index.js';\n\n/**@deprecated */\nexport interface DroppedCollectionMigrationStrategy<\n\tOld extends StorageCollectionSchema<any, any, any>,\n> {\n\t(old: Old): void | Promise<void>;\n}\n/**@deprecated */\nexport interface PreservedCollectionMigrationStrategy<\n\tOld extends StorageCollectionSchema<any, any, any>,\n\tNew extends StorageCollectionSchema<any, any, any>,\n> {\n\t(\n\t\told: StorageDocument<Old>,\n\t): StorageDocument<New> | Promise<StorageDocument<New>>;\n}\n/** @deprecated */\ntype MigrationStrategy<\n\tOld extends StorageCollectionSchema<any, any, any>,\n\tNew extends StorageCollectionSchema<any, any, any>,\n> =\n\t| DroppedCollectionMigrationStrategy<Old>\n\t| PreservedCollectionMigrationStrategy<Old, New>;\n/** @deprecated */\nexport type MigrationsKeyedOnCollection<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> =\n\t| PreservedCollectionMigrations<Old, New>\n\t| DroppedCollectionMigrations<Old, New>;\n\n/**@deprecated */\ntype NotInSchema<\n\tName extends string | number | symbol,\n\tSchema extends StorageSchema<any>,\n> = Name extends keyof Schema['collections'] ? never : Name;\n/** @deprecated */\ntype InSchema<\n\tName extends string | number | symbol,\n\tSchema extends StorageSchema<any>,\n> = Name extends keyof Schema['collections'] ? Name : never;\n/** @deprecated */\ntype DroppedCollections<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = {\n\t[Key in keyof Old['collections'] as NotInSchema<\n\t\tKey,\n\t\tNew\n\t>]: StorageCollectionSchema<any, any, any>;\n};\n/** @deprecated */\ntype PreservedCollections<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = {\n\t[Key in keyof Old['collections'] as InSchema<\n\t\tKey,\n\t\tNew\n\t>]: StorageCollectionSchema<any, any, any>;\n};\n/** @deprecated */\ntype DroppedCollectionMigrations<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = {\n\t[Key in keyof DroppedCollections<\n\t\tOld,\n\t\tNew\n\t>]: DroppedCollectionMigrationStrategy<Old['collections'][Key]>;\n};\n/** @deprecated */\ntype PreservedCollectionMigrations<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = {\n\t[Key in keyof PreservedCollections<\n\t\tOld,\n\t\tNew\n\t>]: PreservedCollectionMigrationStrategy<\n\t\tOld['collections'][Key],\n\t\tNew['collections'][Key]\n\t>;\n};\n\n/** @deprecated */\ntype StrategyFor<\n\tKey extends string,\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = Key extends keyof New['collections']\n\t? PreservedCollectionMigrationStrategy<\n\t\t\tOld['collections'][Key],\n\t\t\tNew['collections'][Key]\n\t >\n\t: DroppedCollectionMigrationStrategy<Old['collections'][Key]>;\n\n/** @deprecated */\ntype DeprecatedMigrationRunner<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> = <Collection extends Extract<keyof Old['collections'], string>>(\n\tcollection: Collection,\n\tstrategy: StrategyFor<Collection, Old, New>,\n) => Promise<void>;\n\n/** @deprecated */\ntype DeprecatedMigrationQueryMaker<\n\tCollection extends StorageCollectionSchema<any, any, any>,\n> = {\n\tget(primaryKey: string): Promise<StorageDocument<Collection> | undefined>;\n\tfindOne(\n\t\tquery: CollectionFilter,\n\t): Promise<StorageDocument<Collection> | undefined>;\n\tfindAll(query?: CollectionFilter): Promise<StorageDocument<Collection>[]>;\n};\n\n/** @deprecated */\ntype DeprecatedMigrationQueries<Old extends StorageSchema<any>> = {\n\t[Key in keyof Old['collections']]: DeprecatedMigrationQueryMaker<\n\t\tOld['collections'][Key]\n\t>;\n};\n\n/** @deprecated */\ntype DeprecatedMigrationMutations<New extends StorageSchema> = {\n\t[Key in keyof New['collections']]: {\n\t\tput(\n\t\t\tdocument: StorageDocumentInit<New['collections'][Key]>,\n\t\t): Promise<StorageDocument<New['collections'][Key]>>;\n\t\tdelete(primaryKey: string): Promise<void>;\n\t};\n};\n/** @deprecated */\nexport interface DeprecatedMigrationTools<\n\tOld extends StorageSchema<any>,\n\tNew extends StorageSchema<any>,\n> {\n\tmigrate: DeprecatedMigrationRunner<Old, New>;\n\tidentity: <T>(val: T) => T;\n\t/**\n\t * @deprecated - default field values are automatically\n\t * applied during migration, you don't need to use this.\n\t * Please remove it from your migrations - even old ones\n\t * (old migrations can be updated!)\n\t */\n\twithDefaults: (collectionName: string, value: any) => any;\n\tqueries: DeprecatedMigrationQueries<Old>;\n\tmutations: DeprecatedMigrationMutations<New>;\n\tinfo: {\n\t\tchangedCollections: keyof Old['collections'][];\n\t\taddedCollections: keyof New['collections'][];\n\t\tremovedCollections: keyof Old['collections'][];\n\t};\n}\n\nexport interface MigrationEngine {\n\tmigrate: (collection: string, strategy: (val: any) => any) => Promise<void>;\n\tqueries: MigrationQueries<any>;\n\tmutations: MigrationMutations<any>;\n\t/** OIDs of any new documents created during the migration */\n\tnewOids: string[];\n\t/** Promises that should be resolved before completing the migration */\n\tawaitables: Promise<any>[];\n\t/** Deletes all documents in a collection - used for removed collections */\n\tdeleteCollection: (collection: string) => Promise<void>;\n\tlog: (...messages: any[]) => void;\n}\n/** @deprecated */\ntype DeprecatedMigrationProcedure<\n\tOld extends StorageSchema,\n\tNew extends StorageSchema,\n> = (tools: DeprecatedMigrationTools<Old, New>) => Promise<void>;\n\ntype EmptySchema = {\n\tversion: 0;\n\tcollections: {};\n};\nconst emptySchema: EmptySchema = {\n\tversion: 0,\n\tcollections: {},\n};\n\n/** @deprecated - use createMigration */\nexport function migrate<Schema extends StorageSchema>(\n\tschema: Schema,\n\tprocedure: DeprecatedMigrationProcedure<EmptySchema, Schema>,\n): Migration<EmptySchema, Schema>;\n/** @deprecated = use createMigration */\nexport function migrate<Old extends StorageSchema, New extends StorageSchema>(\n\toldSchema: Old,\n\tnewSchema: New,\n\tprocedure: DeprecatedMigrationProcedure<Old, New>,\n): Migration<Old, New>;\nexport function migrate(\n\toldSchemaOrNewSchema: any,\n\tnewSchemaOrProcedure: any,\n\tprocedureIfTwoSchemas?: any,\n) {\n\tconst isProcedureSecondArgument = typeof newSchemaOrProcedure === 'function';\n\tconst oldSchema = isProcedureSecondArgument\n\t\t? emptySchema\n\t\t: oldSchemaOrNewSchema;\n\tconst newSchema = isProcedureSecondArgument\n\t\t? oldSchemaOrNewSchema\n\t\t: newSchemaOrProcedure;\n\tconst procedure = isProcedureSecondArgument\n\t\t? newSchemaOrProcedure\n\t\t: procedureIfTwoSchemas;\n\t// diff to determine changed collections\n\tconst changedCollections: string[] = Object.keys(\n\t\tnewSchema.collections,\n\t).filter(\n\t\t(key) =>\n\t\t\toldSchema.collections[key] &&\n\t\t\tstableStringify(oldSchema.collections[key]) !==\n\t\t\t\tstableStringify(newSchema.collections[key]),\n\t);\n\tconst removedCollections: string[] = Object.keys(\n\t\toldSchema.collections,\n\t).filter((key) => !newSchema.collections[key]);\n\tconst addedCollections = Object.keys(newSchema.collections).filter(\n\t\t(key) => !oldSchema.collections[key],\n\t);\n\t// collections which added one or more field defaults\n\tconst autoMigratedCollections = new Set<string>();\n\tfor (const collection of changedCollections) {\n\t\tconst oldFields = oldSchema.collections[collection].fields;\n\t\tconst newFields = newSchema.collections[collection].fields;\n\t\t// a new default was added - we can auto-migrate it\n\t\tif (\n\t\t\tObject.keys(newFields).some(\n\t\t\t\t(key) => !oldFields[key]?.default && newFields[key]?.default,\n\t\t\t)\n\t\t) {\n\t\t\tautoMigratedCollections.add(collection);\n\t\t}\n\t\t// a field was removed - we can auto-migrate it\n\t\tif (Object.keys(oldFields).some((key) => !newFields[key])) {\n\t\t\tautoMigratedCollections.add(collection);\n\t\t}\n\t}\n\n\tconst addedIndexes: Record<string, MigrationIndexDescription[]> = {};\n\tconst removedIndexes: Record<string, MigrationIndexDescription[]> = {};\n\tfor (const changed of [...changedCollections, ...addedCollections]) {\n\t\tconst oldIndexes = getIndexes(oldSchema.collections[changed]);\n\t\tconst newIndexes = getIndexes(newSchema.collections[changed]);\n\t\tconst added = newIndexes.filter(\n\t\t\t(index) => !oldIndexes.find((i) => i.name === index.name),\n\t\t);\n\t\tconst removed = oldIndexes.filter(\n\t\t\t(index) => !newIndexes.find((i) => i.name === index.name),\n\t\t);\n\t\tif (added.length > 0) {\n\t\t\taddedIndexes[changed] = added;\n\t\t\t// FIXME: don't o(n^2) this\n\t\t\tif (changedCollections.includes(changed)) {\n\t\t\t\tautoMigratedCollections.add(changed);\n\t\t\t}\n\t\t}\n\t\tif (removed.length > 0) {\n\t\t\tremovedIndexes[changed] = removed;\n\t\t\t// FIXME: don't o(n^2) this\n\t\t\tif (changedCollections.includes(changed)) {\n\t\t\t\tautoMigratedCollections.add(changed);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst withDefaults = (collectionName: string, val: any) => {\n\t\treturn addFieldDefaults(newSchema.collections[collectionName], val);\n\t};\n\tconst autoMigration = (collectionName: string) => (val: any) => {\n\t\tconst collection = newSchema.collections[collectionName];\n\t\treturn addFieldDefaults(collection, removeExtraProperties(collection, val));\n\t};\n\n\treturn {\n\t\tversion: newSchema.version,\n\t\tmigrate: async (engine: MigrationEngine) => {\n\t\t\tconst migratedCollections: string[] = [];\n\t\t\tawait procedure({\n\t\t\t\tmigrate: async (collection: any, strategy: any) => {\n\t\t\t\t\tconst auto = autoMigration(collection);\n\t\t\t\t\tconst wrapped = async (val: any) => {\n\t\t\t\t\t\tconst baseValue = await strategy(val);\n\t\t\t\t\t\t// assign OID from original value in case user's strategy\n\t\t\t\t\t\t// involves cloning\n\t\t\t\t\t\tassignOid(baseValue, getOid(val));\n\t\t\t\t\t\tconst result = auto(baseValue);\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tawait engine.migrate(collection, wrapped);\n\t\t\t\t\tmigratedCollections.push(collection);\n\t\t\t\t\t// since the user migrated this one and we wrap their\n\t\t\t\t\t// strategy with auto-migration, we can remove it from\n\t\t\t\t\t// the auto-migration list\n\t\t\t\t\tautoMigratedCollections.delete(collection);\n\t\t\t\t},\n\t\t\t\tidentity: (val: any) => val,\n\t\t\t\twithDefaults,\n\t\t\t\tinfo: {\n\t\t\t\t\tchangedCollections,\n\t\t\t\t\taddedCollections,\n\t\t\t\t\tremovedCollections,\n\t\t\t\t},\n\t\t\t\tqueries: engine.queries,\n\t\t\t\tmutations: engine.mutations,\n\t\t\t});\n\n\t\t\t// mandatory migration of fields which had defaults added or\n\t\t\t// fields removed but weren't migrated by the user\n\n\t\t\tif (newSchema.version > 1) {\n\t\t\t\tengine.log(\n\t\t\t\t\t'debug',\n\t\t\t\t\t'auto-migrating collections with new defaults',\n\t\t\t\t\tautoMigratedCollections,\n\t\t\t\t);\n\t\t\t\tfor (const name of autoMigratedCollections) {\n\t\t\t\t\tawait engine.migrate(name, autoMigration(name));\n\t\t\t\t\tmigratedCollections.push(name);\n\t\t\t\t}\n\n\t\t\t\tconst unmigrated = changedCollections.filter(\n\t\t\t\t\t(collection) => !migratedCollections.includes(collection),\n\t\t\t\t);\n\t\t\t\tif (unmigrated.length > 0) {\n\t\t\t\t\t// TODO: does this deserve a full-on error?\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`Unmigrated changed collections from version ${oldSchema.version} to version ${newSchema.version}:`,\n\t\t\t\t\t\tunmigrated,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tremovedCollections,\n\t\taddedIndexes,\n\t\tremovedIndexes,\n\t\tallCollections: Object.keys(newSchema.collections),\n\t\tchangedCollections,\n\t\taddedCollections,\n\t\toldCollections: Object.keys(oldSchema.collections),\n\t\toldSchema,\n\t\tnewSchema,\n\t};\n}\n\nexport interface MigrationIndexDescription {\n\tname: string;\n\tmultiEntry: boolean;\n\tsynthetic: boolean;\n\tcompound: boolean;\n}\n\nexport interface Migration<\n\tOld extends StorageSchema = any,\n\tNew extends StorageSchema = any,\n> {\n\tversion: number;\n\toldSchema: Old;\n\tnewSchema: New;\n\tmigrate: (engine: MigrationEngine) => Promise<void>;\n\t/** Collections which are added in the new schema and not present in the old */\n\taddedCollections: string[];\n\t/** Collections which were removed from the old schema */\n\tremovedCollections: string[];\n\t/** All collections which exist after the migration has completed - i.e. the ones in the new schema */\n\tallCollections: string[];\n\t/** Only the collections which were in the old schema */\n\toldCollections: string[];\n\t/** Collections whose fields or indexes changed between schemas */\n\tchangedCollections: string[];\n\t// new indexes mapped by collection name\n\taddedIndexes: Record<string, MigrationIndexDescription[]>;\n\t// removed indexes mapped by collection name\n\tremovedIndexes: Record<string, MigrationIndexDescription[]>;\n}\n\nexport function migrationRange(from: number, to: number) {\n\treturn [...Array(to - from).keys()].map((i) => 1 + i + from);\n}\n\nfunction getIndexes<Coll extends StorageCollectionSchema<any, any, any>>(\n\tcollection: Coll | undefined,\n): MigrationIndexDescription[] {\n\tif (!collection) return [];\n\n\treturn [\n\t\t...Object.keys(collection.indexes || {}).map((key) => ({\n\t\t\tname: key,\n\t\t\tmultiEntry: ['array', 'string[]', 'number[]', 'boolean[]'].includes(\n\t\t\t\tcollection.indexes[key].type,\n\t\t\t),\n\t\t\tsynthetic: true,\n\t\t\tcompound: false,\n\t\t})),\n\t\t...Object.keys(collection.compounds || {}).map((key) => ({\n\t\t\tname: key,\n\t\t\tmultiEntry: collection.compounds[key].of.some(\n\t\t\t\t(fieldName: string) =>\n\t\t\t\t\t(collection.fields[fieldName] || collection.indexes[fieldName])\n\t\t\t\t\t\t.type === 'array',\n\t\t\t),\n\t\t\tsynthetic: false,\n\t\t\tcompound: true,\n\t\t})),\n\t];\n}\n\n/** @deprecated - use createMigration with no procedure function */\nexport function createDefaultMigration(\n\tschema: StorageSchema,\n): Migration<{ version: 0; collections: {} }>;\n/** @deprecated - use createMigration with no procedure function */\nexport function createDefaultMigration<Old extends StorageSchema>(\n\toldSchema: Old,\n\tnewSchema: StorageSchema,\n): Migration<Old>;\nexport function createDefaultMigration(\n\tschema: StorageSchema,\n\tnewSchema?: StorageSchema<any>,\n) {\n\tlet oldSchema = newSchema\n\t\t? schema\n\t\t: {\n\t\t\t\tversion: 0,\n\t\t\t\tcollections: {},\n\t\t };\n\treturn migrate(oldSchema, newSchema || schema, async ({ migrate, info }) => {\n\t\tif ((newSchema || schema).version === 1) return;\n\n\t\tfor (const collection of info.changedCollections as any) {\n\t\t\t// @ts-ignore indefinite type resolution\n\t\t\tawait migrate(collection, (old) => old);\n\t\t}\n\t});\n}\n\n/** New, simpler type-safety migration tools */\ntype DocumentShape<Init = any, Snapshot = any> = {\n\tinit: Init;\n\tsnapshot: Snapshot;\n};\ntype SchemaDocuments = Record<string, DocumentShape>;\ntype CollectionProcedure<OldSnapshot, NewInit> = {\n\t(old: OldSnapshot): NewInit | Promise<NewInit>;\n};\ntype MigrationQueries<Old extends SchemaDocuments> = {\n\t[Key in keyof Old]: {\n\t\tget(primaryKey: string): Promise<Old[Key]['snapshot'] | undefined>;\n\t\tfindOne(query: CollectionFilter): Promise<Old[Key]['snapshot'] | undefined>;\n\t\tfindAll(query?: CollectionFilter): Promise<Old[Key]['snapshot'][]>;\n\t};\n};\ntype MigrationMutations<New extends SchemaDocuments> = {\n\t[Key in keyof New]: {\n\t\tput(\n\t\t\tdocument: New[Key]['init'],\n\t\t\toptions?: { access?: AuthorizationKey },\n\t\t): Promise<New[Key]['snapshot']>;\n\t\tdelete(primaryKey: string): Promise<void>;\n\t};\n};\ntype MigrationTools<\n\tOld extends SchemaDocuments,\n\tNew extends SchemaDocuments,\n> = {\n\t/**\n\t * Process a change in a collection's documents by taking in each existing\n\t * document and returning its new shape. This is typed so you can be\n\t * confident the proper transformations are made.\n\t */\n\tmigrate: <Collection extends keyof Old & keyof New>(\n\t\tcollection: Collection,\n\t\tstrategy: CollectionProcedure<\n\t\t\tOld[Collection]['snapshot'],\n\t\t\tNew[Collection]['init']\n\t\t>,\n\t) => Promise<void>;\n\tmutations: MigrationMutations<New>;\n\tqueries: MigrationQueries<Old>;\n\tinfo: {\n\t\tchangedCollections: (keyof Old & keyof New)[];\n\t\taddedCollections: (keyof New)[];\n\t\tremovedCollections: (keyof Old)[];\n\t};\n};\ntype MigrationProcedure<\n\tOld extends SchemaDocuments,\n\tNew extends SchemaDocuments,\n> = {\n\t(tools: MigrationTools<Old, New>): Promise<void>;\n};\ntype InitialMigrationTools<New extends SchemaDocuments> = {\n\tmutations: MigrationMutations<New>;\n};\ntype InitialMigrationProcedure<New extends SchemaDocuments> = {\n\t(tools: InitialMigrationTools<New>): Promise<void>;\n};\n\nexport function createMigration<New extends SchemaDocuments>(\n\tnewSchema: StorageSchema,\n\tprocedure?: InitialMigrationProcedure<New>,\n): any;\nexport function createMigration<\n\tOld extends SchemaDocuments,\n\tNew extends SchemaDocuments,\n>(\n\toldSchema: StorageSchema,\n\tnewSchema: StorageSchema,\n\tprocedure?: MigrationProcedure<Old, New>,\n): any;\nexport function createMigration(\n\tmaybeOldSchema: StorageSchema,\n\tmaybeNewSchemaOrProcedure?:\n\t\t| StorageSchema\n\t\t| InitialMigrationProcedure<SchemaDocuments>,\n\tmaybeProcedure?: MigrationProcedure<SchemaDocuments, SchemaDocuments>,\n): any {\n\tconst isProcedureSecondArgument =\n\t\ttypeof maybeNewSchemaOrProcedure === 'function' ||\n\t\tmaybeNewSchemaOrProcedure === undefined;\n\tconst oldSchema = isProcedureSecondArgument ? emptySchema : maybeOldSchema;\n\tconst newSchema = isProcedureSecondArgument\n\t\t? maybeOldSchema\n\t\t: maybeNewSchemaOrProcedure;\n\tconst procedure = isProcedureSecondArgument\n\t\t? maybeNewSchemaOrProcedure\n\t\t: maybeProcedure;\n\tassert(oldSchema, 'Invalid arguments to createMigration');\n\tassert(newSchema, 'Invalid arguments to createMigration');\n\tconst {\n\t\tchangedCollections,\n\t\taddedCollections,\n\t\tremovedCollections,\n\t\taddedIndexes,\n\t\tremovedIndexes,\n\t\tautoMigratedCollections,\n\t\tautoMigration,\n\t} = getMigrationInfo(oldSchema, newSchema);\n\n\treturn {\n\t\tversion: newSchema.version,\n\t\tmigrate: async (engine: MigrationEngine) => {\n\t\t\tconst migratedCollections: string[] = [];\n\t\t\tconst migrate = async (collection: any, strategy: any) => {\n\t\t\t\tconst auto = autoMigration(collection);\n\t\t\t\tconst wrapped = async (val: any) => {\n\t\t\t\t\tconst baseValue = await strategy(val);\n\t\t\t\t\t// assign OID from original value in case user's strategy\n\t\t\t\t\t// involves cloning\n\t\t\t\t\tassignOid(baseValue, getOid(val));\n\t\t\t\t\tconst result = auto(baseValue);\n\t\t\t\t\tconst validationError = validateEntity(\n\t\t\t\t\t\tnewSchema.collections[collection].fields,\n\t\t\t\t\t\tresult,\n\t\t\t\t\t);\n\t\t\t\t\tif (validationError) {\n\t\t\t\t\t\t// TODO: what? throw?\n\t\t\t\t\t}\n\t\t\t\t\treturn result;\n\t\t\t\t};\n\t\t\t\t// @ts-ignore\n\t\t\t\tawait engine.migrate(collection, wrapped);\n\t\t\t\tmigratedCollections.push(collection);\n\t\t\t\t// since the user migrated this one and we wrap their\n\t\t\t\t// strategy with auto-migration, we can remove it from\n\t\t\t\t// the auto-migration list\n\t\t\t\tautoMigratedCollections.delete(collection);\n\t\t\t};\n\t\t\tawait procedure?.({\n\t\t\t\tmigrate,\n\t\t\t\tinfo: {\n\t\t\t\t\tchangedCollections,\n\t\t\t\t\taddedCollections,\n\t\t\t\t\tremovedCollections,\n\t\t\t\t},\n\t\t\t\tqueries: engine.queries,\n\t\t\t\tmutations: engine.mutations,\n\t\t\t});\n\n\t\t\t// mandatory migration of fields which had defaults added or\n\t\t\t// fields removed but weren't migrated by the user\n\n\t\t\tif (newSchema.version > 1) {\n\t\t\t\tengine.log(\n\t\t\t\t\t'debug',\n\t\t\t\t\t'auto-migrating collections with new defaults',\n\t\t\t\t\tautoMigratedCollections,\n\t\t\t\t);\n\t\t\t\tfor (const name of autoMigratedCollections) {\n\t\t\t\t\tawait engine.migrate(name, autoMigration(name));\n\t\t\t\t\tmigratedCollections.push(name);\n\t\t\t\t}\n\n\t\t\t\t// delete all documents in deleted collections\n\t\t\t\tfor (const name of removedCollections) {\n\t\t\t\t\tawait engine.deleteCollection(name);\n\t\t\t\t}\n\n\t\t\t\tconst unmigrated = changedCollections.filter(\n\t\t\t\t\t(collection) => !migratedCollections.includes(collection),\n\t\t\t\t);\n\t\t\t\tif (unmigrated.length > 0) {\n\t\t\t\t\t// TODO: does this deserve a full-on error?\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`Unmigrated changed collections from version ${oldSchema.version} to version ${newSchema.version}:`,\n\t\t\t\t\t\tunmigrated,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tremovedCollections,\n\t\taddedIndexes,\n\t\tremovedIndexes,\n\t\tallCollections: Object.keys(newSchema.collections),\n\t\tchangedCollections,\n\t\taddedCollections,\n\t\toldCollections: Object.keys(oldSchema.collections),\n\t\toldSchema,\n\t\tnewSchema,\n\t};\n}\n\n// common tools\nfunction getMigrationInfo(oldSchema: StorageSchema, newSchema: StorageSchema) {\n\tconst changedCollections: string[] = Object.keys(\n\t\tnewSchema.collections,\n\t).filter(\n\t\t(key) =>\n\t\t\toldSchema.collections[key] &&\n\t\t\tstableStringify(oldSchema.collections[key]) !==\n\t\t\t\tstableStringify(newSchema.collections[key]),\n\t);\n\tconst removedCollections: string[] = Object.keys(\n\t\toldSchema.collections,\n\t).filter((key) => !newSchema.collections[key]);\n\tconst addedCollections = Object.keys(newSchema.collections).filter(\n\t\t(key) => !oldSchema.collections[key],\n\t);\n\t// collections which added one or more field defaults\n\tconst autoMigratedCollections = new Set<string>();\n\tfor (const collection of changedCollections) {\n\t\tconst oldFields = oldSchema.collections[collection].fields;\n\t\tconst newFields = newSchema.collections[collection].fields;\n\t\t// a new default was added - we can auto-migrate it\n\t\tif (\n\t\t\tObject.keys(newFields).some(\n\t\t\t\t(key) => !hasDefault(oldFields[key]) && hasDefault(newFields[key]),\n\t\t\t)\n\t\t) {\n\t\t\tautoMigratedCollections.add(collection);\n\t\t}\n\t\t// a field was removed - we can auto-migrate it\n\t\tif (Object.keys(oldFields).some((key) => !newFields[key])) {\n\t\t\tautoMigratedCollections.add(collection);\n\t\t}\n\t}\n\n\tconst addedIndexes: Record<string, MigrationIndexDescription[]> = {};\n\tconst removedIndexes: Record<string, MigrationIndexDescription[]> = {};\n\tfor (const changed of [...changedCollections, ...addedCollections]) {\n\t\tconst oldIndexes = getIndexes(oldSchema.collections[changed]);\n\t\tconst newIndexes = getIndexes(newSchema.collections[changed]);\n\t\tconst added = newIndexes.filter(\n\t\t\t(index) => !oldIndexes.find((i) => i.name === index.name),\n\t\t);\n\t\tconst removed = oldIndexes.filter(\n\t\t\t(index) => !newIndexes.find((i) => i.name === index.name),\n\t\t);\n\t\tif (added.length > 0) {\n\t\t\taddedIndexes[changed] = added;\n\t\t\t// FIXME: don't o(n^2) this\n\t\t\tif (changedCollections.includes(changed)) {\n\t\t\t\tautoMigratedCollections.add(changed);\n\t\t\t}\n\t\t}\n\t\tif (removed.length > 0) {\n\t\t\tremovedIndexes[changed] = removed;\n\t\t\t// FIXME: don't o(n^2) this\n\t\t\tif (changedCollections.includes(changed)) {\n\t\t\t\tautoMigratedCollections.add(changed);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst withDefaults = (collectionName: string, val: any) => {\n\t\treturn addFieldDefaults(newSchema.collections[collectionName], val);\n\t};\n\tconst autoMigration = (collectionName: string) => (val: any) => {\n\t\tconst collection = newSchema.collections[collectionName];\n\t\treturn addFieldDefaults(collection, removeExtraProperties(collection, val));\n\t};\n\n\treturn {\n\t\tchangedCollections,\n\t\taddedCollections,\n\t\tremovedCollections,\n\t\taddedIndexes,\n\t\tremovedIndexes,\n\t\tautoMigratedCollections,\n\t\twithDefaults,\n\t\tautoMigration,\n\t};\n}\n", "export interface UserInfo<Profile, Presence> {\n\t/**\n\t * This is the ID representing the user who is utilizing a\n\t * replica client to connect to the storage network.\n\t * One user may have multiple replica clients active at once,\n\t * but their presence will only reflect the most recent\n\t * replica used.\n\t */\n\tid: string;\n\t/**\n\t * This is the ID representing the replica client that is\n\t * connected to the storage network. This is used to\n\t * identify the client when sending messages to it.\n\t */\n\treplicaId: string;\n\n\t/**\n\t * This is the user's server profile. This data is associated\n\t * with the logged in user of the app and cannot be modified\n\t * by the local replica directly.\n\t */\n\tprofile: Profile;\n\n\t/**\n\t * Presence info which can update frequently as a replica\n\t * makes changes. The shape of presence is up to you.\n\t */\n\tpresence: Presence;\n\n\t/**\n\t * This is the internal presence data that Verdant uses\n\t * for some built-in presence functionality. The client\n\t * should manage it transparently to the user.\n\t */\n\tinternal: VerdantInternalPresence;\n}\n\nexport type UserInfoUpdate<Profile = any, Presence = any> = Omit<\n\tUserInfo<Profile, Presence>,\n\t'internal' | 'profile'\n> & {\n\tinternal?: VerdantInternalPresence;\n};\n\nexport interface VerdantInternalPresence {\n\tviewId?: string;\n\tlastFieldId?: string;\n\tlastFieldTimestamp?: number;\n}\n\nexport const initialInternalPresence: VerdantInternalPresence = {};\n", "/**\n * High-level patch creation for use with complex nested objects.\n */\n\nimport { FileRef } from './files.js';\nimport { createRef, createSubOid, ObjectIdentifier } from './oids.js';\nimport {\n\tdiffToPatches,\n\tinitialToPatches,\n\tObjectRef,\n\tOperation,\n\tPropertyName,\n} from './operation.js';\nimport { isRef } from './refs.js';\nimport { isObject } from './utils.js';\n\nexport class PatchCreator {\n\tconstructor(\n\t\tprivate getNow: () => string,\n\t\tprivate createSubId?: () => string,\n\t) {}\n\n\tisPrimitive = (value: any) => {\n\t\treturn !isObject(value) || isRef(value);\n\t};\n\n\tcreateDiff = (\n\t\tfrom: any,\n\t\tto: any,\n\t\toptions: { mergeUnknownObjects?: boolean; defaultUndefined?: boolean } = {},\n\t) => {\n\t\treturn diffToPatches(from, to, this.getNow, this.createSubId, [], options);\n\t};\n\n\tcreateInitialize = (obj: any, oid: ObjectIdentifier) => {\n\t\treturn initialToPatches(obj, oid, this.getNow, this.createSubId);\n\t};\n\n\tcreateSet = (\n\t\toid: ObjectIdentifier,\n\t\tkey: PropertyName,\n\t\tvalue: any,\n\t): Operation[] => {\n\t\t// incoming value must be normalized. if it's not a primitive, it and all sub-objects\n\t\t// must be created\n\t\tif (this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\tname: key,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\tconst itemOid = createSubOid(oid, this.createSubId);\n\t\t\treturn [\n\t\t\t\t// since we're setting a complex nested object, we can initialize it wholesale.\n\t\t\t\t// no diffing to do.\n\t\t\t\t...initialToPatches(value, itemOid, this.getNow),\n\t\t\t\t// then set the reference to the object\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\tvalue: createRef(itemOid),\n\t\t\t\t\t\tname: key,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateRemove = (oid: ObjectIdentifier, key: PropertyName): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'remove',\n\t\t\t\t\tname: key,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateListSet = (\n\t\toid: ObjectIdentifier,\n\t\tindex: number,\n\t\tvalue: any,\n\t): Operation[] => {\n\t\tif (this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\tconst itemOid = createSubOid(oid, this.createSubId);\n\t\t\treturn [\n\t\t\t\t...initialToPatches(value, itemOid, this.getNow),\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tvalue: createRef(itemOid),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateListPush = (oid: ObjectIdentifier, value: any): Operation[] => {\n\t\tif (this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-push',\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\tconst itemOid = createSubOid(oid, this.createSubId);\n\t\t\treturn [\n\t\t\t\t...initialToPatches(value, itemOid, this.getNow),\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-push',\n\t\t\t\t\t\tvalue: createRef(itemOid),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateListAdd = (oid: ObjectIdentifier, value: any): Operation[] => {\n\t\tif (!this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-add',\n\t\t\t\t\t\tvalue: createRef(value),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-add',\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateListInsert = (\n\t\toid: ObjectIdentifier,\n\t\tindex: number,\n\t\tvalue: any,\n\t): Operation[] => {\n\t\tif (this.isPrimitive(value)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else {\n\t\t\tconst itemOid = createSubOid(oid, this.createSubId);\n\t\t\treturn [\n\t\t\t\t...initialToPatches(value, itemOid, this.getNow),\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\tvalue: createRef(itemOid),\n\t\t\t\t\t\tindex,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t};\n\n\tcreateListRemove = (\n\t\toid: ObjectIdentifier,\n\t\tvalue: any,\n\t\tonly?: 'first' | 'last',\n\t): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'list-remove',\n\t\t\t\t\tvalue,\n\t\t\t\t\tonly,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateListDelete = (\n\t\toid: ObjectIdentifier,\n\t\tindex: number,\n\t\tcount: number = 1,\n\t): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'list-delete',\n\t\t\t\t\tindex,\n\t\t\t\t\tcount,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateListMoveByRef = (\n\t\toid: ObjectIdentifier,\n\t\tvalue: ObjectRef | FileRef,\n\t\tindex: number,\n\t): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'list-move-by-ref',\n\t\t\t\t\tvalue,\n\t\t\t\t\tindex,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateListMoveByIndex = (\n\t\toid: ObjectIdentifier,\n\t\tfromIndex: number,\n\t\ttoIndex: number,\n\t): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'list-move-by-index',\n\t\t\t\t\tfrom: fromIndex,\n\t\t\t\t\tto: toIndex,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateDelete = (oid: ObjectIdentifier): Operation[] => {\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: this.getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'delete',\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t};\n\n\tcreateDeleteAll = (oids: ObjectIdentifier[]): Operation[] => {\n\t\treturn oids.map((oid) => ({\n\t\t\toid,\n\t\t\ttimestamp: this.getNow(),\n\t\t\tdata: {\n\t\t\t\top: 'delete',\n\t\t\t},\n\t\t}));\n\t};\n}\n", "import { generateId } from './utils.js';\n\nexport class EventSubscriber<\n\tEvents extends { [key: string]: (...args: any[]) => void },\n> {\n\tprotected subscribers: Record<\n\t\tstring,\n\t\tRecord<string, (...args: any[]) => void>\n\t> = {} as any;\n\tprotected counts: Record<string, number> = {} as any;\n\tprivate _disabled = false;\n\tprotected disposed = false;\n\n\tconstructor(private _onAllUnsubscribed?: (event: keyof Events) => void) {}\n\n\tget disabled() {\n\t\treturn this._disabled;\n\t}\n\n\tsubscriberCount = (event: Extract<keyof Events, string>) => {\n\t\treturn this.counts[event] ?? 0;\n\t};\n\n\ttotalSubscriberCount = () => {\n\t\treturn Object.values(this.counts).reduce((acc, count) => acc + count, 0);\n\t};\n\n\tsubscribe = <K extends Extract<keyof Events, string>>(\n\t\tevent: K,\n\t\tcallback: Events[K],\n\t) => {\n\t\tconst key = generateId();\n\t\tlet subscribers = this.subscribers[event];\n\t\tif (!subscribers) {\n\t\t\tsubscribers = this.subscribers[event] = {};\n\t\t}\n\t\tsubscribers[key] = callback;\n\t\tthis.counts[event] = (this.counts[event] || 0) + 1;\n\t\treturn () => {\n\t\t\t// already removed\n\t\t\tif (!this.subscribers[event]) return;\n\n\t\t\tdelete this.subscribers[event][key];\n\t\t\tthis.counts[event]--;\n\t\t\tif (this.counts[event] === 0) {\n\t\t\t\tdelete this.subscribers[event];\n\t\t\t\tdelete this.counts[event];\n\t\t\t\tif (this._onAllUnsubscribed) {\n\t\t\t\t\tthis._onAllUnsubscribed(event);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t};\n\n\temit = <K extends Extract<keyof Events, string>>(\n\t\tevent: K,\n\t\t...args: Parameters<Events[K]>\n\t) => {\n\t\tif (this._disabled) return;\n\t\tif (this.subscribers[event]) {\n\t\t\tObject.values(this.subscribers[event]).forEach((c) => c(...args));\n\t\t}\n\t};\n\n\tdispose = () => {\n\t\tthis._disabled = true;\n\t\tthis.disposed = true;\n\t\tconst events = Object.keys(this.subscribers);\n\t\tthis.subscribers = {} as any;\n\t\tthis.counts = {} as any;\n\t\tevents.forEach((event) => {\n\t\t\tif (this._onAllUnsubscribed) {\n\t\t\t\tthis._onAllUnsubscribed(event);\n\t\t\t}\n\t\t});\n\t};\n\n\tdisable = () => {\n\t\tthis._disabled = true;\n\t};\n}\n\nexport type EventsOf<T extends EventSubscriber<any>> =\n\tT extends EventSubscriber<infer E> ? keyof E : never;\n", "import { ObjectIdentifier } from './oids.js';\nimport { applyPatch, Operation } from './operation.js';\nimport { cloneDeep } from './utils.js';\n\nexport function getUndoOperations(\n\toid: ObjectIdentifier,\n\tinitial: any,\n\toperations: Operation[],\n\tgetNow: () => string,\n): Operation[] {\n\tif (initial === undefined || initial === null) {\n\t\t// if the initial state is nothing, then the undo is to delete everything.\n\t\t// there's nothing else to worry about!\n\t\treturn [\n\t\t\t{\n\t\t\t\toid,\n\t\t\t\ttimestamp: getNow(),\n\t\t\t\tdata: {\n\t\t\t\t\top: 'delete',\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t}\n\t// otherwise, traverse the operations one by one,\n\t// applying them, and using the prior state to determine\n\t// what the undo operation is.\n\tlet state = cloneDeep(initial);\n\tconst undoOperations: Operation[] = [];\n\tfor (const operation of operations) {\n\t\tconst undo = getUndoOperation(oid, state, operation, getNow);\n\t\tundoOperations.unshift(...undo);\n\t\tapplyPatch(state, operation.data);\n\t}\n\treturn undoOperations;\n}\n\nfunction getUndoOperation(\n\toid: ObjectIdentifier,\n\tinitial: any,\n\toperation: Operation,\n\tgetNow: () => string,\n): Operation[] {\n\tconst data = operation.data;\n\tswitch (data.op) {\n\t\tcase 'set':\n\t\tcase 'remove':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'set',\n\t\t\t\t\t\tname: data.name,\n\t\t\t\t\t\tvalue: initial[data.name],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-insert':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-delete',\n\t\t\t\t\t\tindex: data.index,\n\t\t\t\t\t\tcount: 1,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-delete':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\tindex: data.index,\n\t\t\t\t\t\tvalues: initial.slice(data.index, data.count),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-move-by-ref':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-move-by-ref',\n\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t\tindex: initial.indexOf(data.value),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-move-by-index':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-move-by-index',\n\t\t\t\t\t\tfrom: data.to,\n\t\t\t\t\t\tto: data.from,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'delete':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'initialize',\n\t\t\t\t\t\tvalue: initial,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-push':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-remove',\n\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t\t// best heuristic here - remove the last instance of the item.\n\t\t\t\t\t\tonly: 'last',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-remove':\n\t\t\tif (data.only === 'last') {\n\t\t\t\tconst index = initial.lastIndexOf(data.value);\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\tvalues: [data.value],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} else if (data.only === 'first') {\n\t\t\t\tconst index = initial.indexOf(data.value);\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\tvalues: [data.value],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} else {\n\t\t\t\t// find all instances of value and restore them at their\n\t\t\t\t// original index\n\t\t\t\tconst indexesOfValue = [];\n\t\t\t\tlet index = initial.indexOf(data.value);\n\t\t\t\twhile (index !== -1) {\n\t\t\t\t\tindexesOfValue.push(index);\n\t\t\t\t\tindex = initial.indexOf(data.value, index + 1);\n\t\t\t\t}\n\t\t\t\treturn indexesOfValue.map((index) => ({\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-insert',\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t},\n\t\t\t\t}));\n\t\t\t}\n\t\tcase 'list-add':\n\t\t\t// this one is kind of ambiguous. in theory the set may have\n\t\t\t// already included the value and so no change happened. but\n\t\t\t// basically we infer the intent is to remove what was meant\n\t\t\t// to be added by this change.\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-remove',\n\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t\tonly: 'last',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'list-set':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'list-set',\n\t\t\t\t\t\tindex: data.index,\n\t\t\t\t\t\tvalue: initial[data.index],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'initialize':\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\toid,\n\t\t\t\t\ttimestamp: getNow(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\top: 'delete',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\tcase 'touch':\n\t\t\treturn [];\n\t\tdefault:\n\t\t\tthrow new Error(`Cannot undo operation type: ${(data as any).op}`);\n\t}\n}\n", "export class Batcher<T, UserData = any> {\n\tprivate batches: Map<string, Batch<T, UserData>> = new Map();\n\n\tconstructor(\n\t\tprivate flusher: (items: T[], batchKey: string, userData: UserData) => any,\n\t) {}\n\n\tadd({\n\t\tkey,\n\t\tuserData,\n\t\titems,\n\t\tmax,\n\t\ttimeout,\n\t}: {\n\t\tkey: string;\n\t\tuserData?: UserData;\n\t\titems: T[];\n\t\tmax?: number | null;\n\t\ttimeout?: number | null;\n\t}) {\n\t\tlet batch = this.batches.get(key);\n\t\tif (!batch) {\n\t\t\tbatch = new Batch({\n\t\t\t\tmax: max || null,\n\t\t\t\tstartedAt: Date.now(),\n\t\t\t\tuserData,\n\t\t\t\ttimeout: timeout || null,\n\t\t\t\tflusher: this.flusher,\n\t\t\t\tkey,\n\t\t\t});\n\t\t\tthis.batches.set(key, batch);\n\t\t}\n\t\tbatch.update({\n\t\t\titems,\n\t\t\tmax,\n\t\t\ttimeout,\n\t\t\tuserData,\n\t\t});\n\n\t\treturn batch;\n\t}\n\n\tflush = (key: string) => {\n\t\tconst batch = this.batches.get(key);\n\t\tif (!batch) return;\n\n\t\treturn batch.flush();\n\t};\n\n\tdiscard = (key: string) => {\n\t\tconst batch = this.batches.get(key);\n\t\tif (!batch) return;\n\n\t\tbatch.discard();\n\t\tthis.batches.delete(key);\n\t};\n\n\tflushAll = () => {\n\t\treturn [...this.batches.values()].map((batch) => batch.flush());\n\t};\n\n\tgetSize = (key: string) => {\n\t\tconst batch = this.batches.get(key);\n\t\tif (!batch) return 0;\n\n\t\treturn batch.items.length;\n\t};\n}\n\nexport class Batch<T, UserData = any> {\n\titems: Array<T> = [];\n\tmax: number | null;\n\tstartedAt: number;\n\ttimeout: number | null;\n\tflushTimeout?: NodeJS.Timeout;\n\tuserData?: any;\n\tflusher: (items: T[], batchKey: string, userData: UserData) => any;\n\tkey: string;\n\n\tconstructor({\n\t\tmax,\n\t\tstartedAt,\n\t\ttimeout,\n\t\tuserData,\n\t\tflusher,\n\t\tkey,\n\t}: {\n\t\tkey: string;\n\t\tmax: number | null;\n\t\tstartedAt: number;\n\t\ttimeout: number | null;\n\t\tuserData?: UserData;\n\t\tflusher: (items: T[], batchKey: string, userData: UserData) => any;\n\t}) {\n\t\tthis.max = max;\n\t\tthis.startedAt = startedAt;\n\t\tthis.timeout = timeout;\n\t\tthis.userData = userData;\n\t\tthis.flusher = flusher;\n\t\tthis.key = key;\n\t}\n\n\tupdate = ({\n\t\titems,\n\t\tmax,\n\t\ttimeout,\n\t\tuserData,\n\t}: {\n\t\titems: Array<T>;\n\t\tmax?: number | null;\n\t\ttimeout?: number | null;\n\t\tuserData?: UserData;\n\t}) => {\n\t\tthis.items.push(...items);\n\t\tif (max !== undefined) this.max = max;\n\t\tif (timeout !== undefined) this.timeout = timeout;\n\t\tif (userData) this.userData = userData;\n\n\t\t// if the batch has items and a timeout but has not\n\t\t// scheduled yet, schedule it\n\t\tconst needsSchedule =\n\t\t\tthis.items.length !== 0 && this.timeout !== null && !this.flushTimeout;\n\n\t\t// if the batch has already reached its max, skip scheduling\n\t\t// and flush immediately\n\t\tif (this.max !== null && this.items.length >= this.max) {\n\t\t\tthis.flush();\n\t\t} else if (needsSchedule && this.timeout !== null) {\n\t\t\tthis.flushTimeout = setTimeout(this.flush, this.timeout);\n\t\t}\n\t};\n\n\tflush = () => {\n\t\tthis.flushTimeout && clearTimeout(this.flushTimeout);\n\t\tthis.flushTimeout = undefined;\n\t\tconst items = this.items;\n\t\tthis.items = [];\n\t\treturn this.flusher(items, this.key, this.userData);\n\t};\n\n\tdiscard = () => {\n\t\tthis.flushTimeout && clearTimeout(this.flushTimeout);\n\t\tthis.flushTimeout = undefined;\n\t\tthis.items = [];\n\t};\n}\n", "/**\n * Memoizes the last invocation of a function with the same memo keys.\n * As long as key identity and set doesn't change, the last computed\n * value will be returned.\n */\nexport function memoByKeys<TRet, TKeys extends any[]>(\n\tfn: (...args: unknown[]) => TRet,\n\tgetKeys: () => TKeys,\n): (...args: unknown[]) => TRet {\n\tlet cachedKeys: TKeys | undefined;\n\tlet cachedResult: TRet | undefined;\n\treturn (...args: unknown[]) => {\n\t\tconst keys = getKeys();\n\t\tif (\n\t\t\tcachedKeys &&\n\t\t\tcachedKeys.length === keys.length &&\n\t\t\tcachedKeys.every((key, i) => key === keys[i])\n\t\t) {\n\t\t\treturn cachedResult!;\n\t\t}\n\t\tcachedKeys = [...keys] as TKeys;\n\t\tcachedResult = fn(...args);\n\t\treturn cachedResult;\n\t};\n}\n", "export enum VerdantErrorCode {\n\tInvalidRequest = 4000,\n\tBodyRequired = 4001,\n\tNoToken = 4010,\n\tInvalidToken = 4011,\n\tTokenExpired = 4012,\n\tForbidden = 4030,\n\tNotFound = 4040,\n\tUnexpected = 5000,\n\tConfigurationError = 5010,\n\tNoFileStorage = 5011,\n}\n\nexport class VerdantError extends Error {\n\tstatic Code = VerdantErrorCode;\n\n\tconstructor(\n\t\tpublic code: VerdantErrorCode,\n\t\tcause?: Error | undefined,\n\t\tmessage?: string,\n\t) {\n\t\tsuper(message ?? `Verdant error: ${code}`, {\n\t\t\tcause,\n\t\t});\n\t}\n\n\tget httpStatus() {\n\t\tconst status = Math.floor(this.code / 10);\n\t\tif (status < 600) {\n\t\t\treturn status;\n\t\t}\n\t\treturn 500;\n\t}\n\n\ttoResponse = () => {\n\t\treturn JSON.stringify({\n\t\t\tcode: this.code,\n\t\t});\n\t};\n}\n\nexport function isVerdantErrorResponse(body: any): body is { code: number } {\n\treturn (\n\t\ttypeof body === 'object' && 'code' in body && typeof body.code === 'number'\n\t);\n}\n", "import { DocumentBaseline } from './baseline.js';\nimport { Operation } from './operation.js';\n\nfunction encode(str: string): AuthorizationKey {\n\tif (typeof Buffer !== 'undefined') {\n\t\tconst val = Buffer.from(str).toString('base64');\n\t\treturn val as AuthorizationKey;\n\t}\n\tconst val = btoa(str);\n\treturn val as AuthorizationKey;\n}\n\nfunction decode(str: string): string {\n\tif (typeof Buffer !== 'undefined') {\n\t\treturn Buffer.from(str, 'base64').toString();\n\t}\n\treturn atob(str);\n}\n\nexport type AuthorizationKey = string & {\n\t'@@type': 'authz';\n};\n\nexport const authz = {\n\tonlyUser: (userId: string): AuthorizationKey => encode(`u:${userId}:*`),\n\tonlyMe: (): AuthorizationKey => authz.onlyUser(ORIGINATOR_SUBJECT),\n\tdecode: (encoded: string) => {\n\t\tconst decoded = decode(encoded);\n\t\tconst parts = decoded.split(':');\n\t\tif (parts.length !== 3) {\n\t\t\tthrow new Error('Invalid authz string');\n\t\t}\n\t\treturn {\n\t\t\tscope: parts[0],\n\t\t\tsubject: parts[1],\n\t\t\taction: parts[2],\n\t\t};\n\t},\n};\n\nexport const ORIGINATOR_SUBJECT = '$$_originator_$$';\n\n/**\n * Rewrites the special \"originator\" constant subject (used by\n * local-only clients) to the given user ID.\n *\n * Used to initialize a library from a local-only replica\n */\nexport function rewriteAuthzOriginator(\n\tdata: { operations?: Operation[]; baselines?: DocumentBaseline[] },\n\tnewSubject: string,\n) {\n\tconst { operations, baselines } = data;\n\tif (operations) {\n\t\tfor (const op of operations) {\n\t\t\tif (op.authz) {\n\t\t\t\tconst decoded = authz.decode(op.authz);\n\t\t\t\tif (decoded.subject === ORIGINATOR_SUBJECT) {\n\t\t\t\t\top.authz = authz.onlyUser(newSubject);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (baselines) {\n\t\tfor (const baseline of baselines) {\n\t\t\tif (baseline.authz) {\n\t\t\t\tconst decoded = authz.decode(baseline.authz);\n\t\t\t\tif (decoded.subject === ORIGINATOR_SUBJECT) {\n\t\t\t\t\tbaseline.authz = authz.onlyUser(newSubject);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "import { roughSizeOfObject } from '@verdant-web/common';\n\nexport const globalIDB =\n\ttypeof window !== 'undefined' ? window.indexedDB : (undefined as any);\n\nexport function isAbortError(err: unknown) {\n\treturn err instanceof Error && err.name === 'AbortError';\n}\n\nexport function storeRequestPromise<T>(request: IDBRequest<T>) {\n\treturn new Promise<T>((resolve, reject) => {\n\t\trequest.onsuccess = () => {\n\t\t\tresolve(request.result);\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error && isAbortError(request.error)) {\n\t\t\t\t// TODO: is this the right thing to do?\n\t\t\t\tresolve(request.result);\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n}\n\nexport function cursorIterator<T>(\n\trequest: IDBRequest<IDBCursorWithValue | null>,\n\tcallback: (value: T | null) => boolean,\n) {\n\treturn new Promise<void>((resolve, reject) => {\n\t\trequest.onsuccess = () => {\n\t\t\tconst cursor = request.result;\n\t\t\tif (cursor) {\n\t\t\t\tif (callback(cursor.value)) {\n\t\t\t\t\tcursor.continue();\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error && isAbortError(request.error)) {\n\t\t\t\tresolve();\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n}\n\nexport function getSizeOfObjectStore(\n\tdatabase: IDBDatabase,\n\tstoreName: string,\n): Promise<{ count: number; size: number }> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst tx = database.transaction([storeName], 'readonly');\n\t\tconst store = tx.objectStore(storeName);\n\t\tconst cursorReq = store.openCursor();\n\t\tlet count = 0;\n\t\tlet size = 0;\n\t\tcursorReq.onsuccess = function (e) {\n\t\t\tconst cursor = cursorReq.result;\n\t\t\tif (cursor) {\n\t\t\t\tcount++;\n\t\t\t\tsize = size + roughSizeOfObject(cursor.value);\n\t\t\t\tcursor.continue();\n\t\t\t}\n\t\t};\n\t\tcursorReq.onerror = function (e) {\n\t\t\tif (cursorReq.error && isAbortError(cursorReq.error)) {\n\t\t\t\tresolve({\n\t\t\t\t\tcount: count,\n\t\t\t\t\tsize: size,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\treject(cursorReq.error);\n\t\t\t}\n\t\t};\n\t\ttx.oncomplete = function (e) {\n\t\t\tresolve({\n\t\t\t\tcount: count,\n\t\t\t\tsize: size,\n\t\t\t});\n\t\t};\n\t\ttx.onabort = function (e) {\n\t\t\treject(e);\n\t\t};\n\t\ttx.onerror = function (e) {\n\t\t\treject(e);\n\t\t};\n\t});\n}\n\nexport function getAllFromObjectStores(db: IDBDatabase, stores: string[]) {\n\tconst transaction = db.transaction(stores, 'readonly');\n\tconst promises = stores.map((store) => {\n\t\tconst objectStore = transaction.objectStore(store);\n\t\treturn storeRequestPromise(objectStore.getAll());\n\t});\n\treturn Promise.all(promises);\n}\n\nexport async function closeDatabase(db: IDBDatabase) {\n\tdb.close();\n\t// wait for microtask queue to clear\n\tawait new Promise<void>((resolve, reject) => {\n\t\tresolve();\n\t});\n}\n\nexport async function deleteAllDatabases(\n\tnamespace: string,\n\tindexedDB: IDBFactory = globalIDB,\n) {\n\tconst req1 = indexedDB.deleteDatabase([namespace, 'meta'].join('_'));\n\tconst req2 = indexedDB.deleteDatabase([namespace, 'collections'].join('_'));\n\tawait Promise.all([\n\t\tnew Promise((resolve, reject) => {\n\t\t\treq1.onsuccess = resolve;\n\t\t\treq1.onerror = reject;\n\t\t}),\n\t\tnew Promise((resolve, reject) => {\n\t\t\treq2.onsuccess = resolve;\n\t\t\treq2.onerror = reject;\n\t\t}),\n\t]);\n\twindow.location.reload();\n}\n\nexport function deleteDatabase(name: string, indexedDB = window.indexedDB) {\n\treturn storeRequestPromise(indexedDB.deleteDatabase(name));\n}\n\nexport async function getAllDatabaseNamesAndVersions(\n\tindexedDB: IDBFactory = window.indexedDB,\n) {\n\treturn indexedDB.databases();\n}\n\nexport function createAbortableTransaction(\n\tdb: IDBDatabase,\n\tstoreNames: string[],\n\tmode: 'readonly' | 'readwrite',\n\tabortSignal?: AbortSignal,\n\tlog?: (...args: any[]) => void,\n) {\n\tconst tx = db.transaction(storeNames, mode);\n\tif (abortSignal) {\n\t\tconst abort = () => {\n\t\t\tlog?.('debug', 'aborting transaction');\n\t\t\ttry {\n\t\t\t\ttx.abort();\n\t\t\t} catch (e) {\n\t\t\t\tlog?.('debug', 'aborting transaction failed', e);\n\t\t\t}\n\t\t};\n\t\tabortSignal.addEventListener('abort', abort);\n\t\ttx.addEventListener('error', () => {\n\t\t\tabortSignal.removeEventListener('abort', abort);\n\t\t});\n\t\ttx.addEventListener('complete', () => {\n\t\t\tabortSignal.removeEventListener('abort', abort);\n\t\t});\n\t}\n\treturn tx;\n}\n\n/**\n * Empties all data in a database without changing\n * its structure.\n */\nexport function emptyDatabase(db: IDBDatabase) {\n\tconst storeNames = Array.from(db.objectStoreNames);\n\tconst tx = db.transaction(storeNames, 'readwrite');\n\tfor (const storeName of storeNames) {\n\t\ttx.objectStore(storeName).clear();\n\t}\n\treturn new Promise<void>((resolve, reject) => {\n\t\ttx.oncomplete = () => resolve();\n\t\ttx.onerror = () => reject(tx.error);\n\t});\n}\n", "export class Disposable {\n\tprivate _disposes: (() => void)[] = [];\n\tprotected disposed = false;\n\n\tdispose = () => {\n\t\tthis.disposed = true;\n\t\tthis._disposes.forEach((dispose) => dispose());\n\t\tthis._disposes = [];\n\t};\n\n\tprotected addDispose = (dispose: () => void) => {\n\t\tthis._disposes.push(dispose);\n\t};\n}\n", "import { Context } from './context.js';\nimport {\n\tcreateAbortableTransaction,\n\tisAbortError,\n\tstoreRequestPromise,\n} from './idb.js';\nimport { Disposable } from './utils/Disposable.js';\n\nexport class IDBService extends Disposable {\n\tprotected log?: Context['log'];\n\tprivate globalAbortController = new AbortController();\n\n\tconstructor(\n\t\tprotected db: IDBDatabase,\n\t\t{ log }: { log?: Context['log'] } = {},\n\t) {\n\t\tsuper();\n\t\tthis.log = log;\n\t\tthis.addDispose(() => {\n\t\t\tthis.globalAbortController.abort();\n\t\t});\n\t}\n\n\tcreateTransaction = (\n\t\tstoreNames: string[],\n\t\topts?: {\n\t\t\tmode?: 'readonly' | 'readwrite';\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t) => {\n\t\tconst tx = createAbortableTransaction(\n\t\t\tthis.db,\n\t\t\tstoreNames,\n\t\t\topts?.mode || 'readonly',\n\t\t\topts?.abort,\n\t\t\tthis.log,\n\t\t);\n\t\tthis.globalAbortController.signal.addEventListener('abort', tx.abort);\n\t\ttx.addEventListener('complete', () => {\n\t\t\tthis.globalAbortController.signal.removeEventListener('abort', tx.abort);\n\t\t});\n\t\ttx.addEventListener('error', () => {\n\t\t\tthis.globalAbortController.signal.removeEventListener('abort', tx.abort);\n\t\t});\n\t\treturn tx;\n\t};\n\n\trun = async <T>(\n\t\tstoreName: string,\n\t\tgetRequest: (store: IDBObjectStore) => IDBRequest<T>,\n\t\topts?: {\n\t\t\tmode?: 'readonly' | 'readwrite';\n\t\t\ttransaction?: IDBTransaction;\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t): Promise<T> => {\n\t\tif (this.disposed || opts?.transaction?.error)\n\t\t\treturn Promise.resolve(undefined as any);\n\t\tconst tx = opts?.transaction || this.createTransaction([storeName], opts);\n\t\tconst store = tx.objectStore(storeName);\n\t\tconst request = getRequest(store);\n\t\treturn storeRequestPromise<T>(request);\n\t};\n\n\trunAll = async <T>(\n\t\tstoreName: string,\n\t\tgetRequests: (store: IDBObjectStore) => IDBRequest<T>[],\n\t\topts?: {\n\t\t\tmode: 'readonly' | 'readwrite';\n\t\t\ttransaction?: IDBTransaction;\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t): Promise<T[]> => {\n\t\tif (this.disposed || opts?.transaction?.error) return Promise.resolve([]);\n\t\tconst tx = opts?.transaction || this.createTransaction([storeName], opts);\n\t\tconst store = tx.objectStore(storeName);\n\t\tconst requests = getRequests(store);\n\t\treturn Promise.all(requests.map(storeRequestPromise));\n\t};\n\n\titerate = async <T>(\n\t\tstoreName: string,\n\t\tgetRequest: (store: IDBObjectStore) => IDBRequest | IDBRequest[],\n\t\titerator: (value: T, store: IDBObjectStore) => boolean | void,\n\t\topts?: {\n\t\t\tmode?: 'readonly' | 'readwrite';\n\t\t\ttransaction?: IDBTransaction;\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t): Promise<void> => {\n\t\tconst tx = opts?.transaction || this.createTransaction([storeName], opts);\n\t\tconst store = tx.objectStore(storeName);\n\t\tconst request = getRequest(store);\n\t\tif (Array.isArray(request)) {\n\t\t\treturn Promise.all(\n\t\t\t\trequest.map((req) => {\n\t\t\t\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\t\t\t\treq.onsuccess = () => {\n\t\t\t\t\t\t\tconst cursor = req.result;\n\t\t\t\t\t\t\tif (cursor) {\n\t\t\t\t\t\t\t\titerator(cursor.value, store);\n\t\t\t\t\t\t\t\tcursor.continue();\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t\treq.onerror = () => {\n\t\t\t\t\t\t\tif (req.error && isAbortError(req.error)) {\n\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treject(req.error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t\t).then(() => undefined);\n\t\t}\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\trequest.onsuccess = () => {\n\t\t\t\tconst cursor = request.result as IDBCursorWithValue | null;\n\t\t\t\tif (cursor) {\n\t\t\t\t\tconst stop = iterator(cursor.value, store);\n\t\t\t\t\tif (stop) {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcursor.continue();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = () => {\n\t\t\t\tif (request.error && isAbortError(request.error)) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else {\n\t\t\t\t\treject(request.error);\n\t\t\t\t}\n\t\t\t};\n\t\t});\n\t};\n\n\tclear = (storeName: string) => {\n\t\treturn this.run<undefined>(storeName, (store) => store.clear(), {\n\t\t\tmode: 'readwrite',\n\t\t});\n\t};\n}\n", "import { IDBService } from '../IDBService.js';\n\ntype AckInfo = {\n\ttype: 'ack';\n\t// null means no operations are acknowledged\n\t// by every peer yet.\n\tglobalAckTimestamp: string | null;\n};\n\nexport class AckInfoStore extends IDBService {\n\tgetAckInfo = async (): Promise<AckInfo> => {\n\t\tconst result = await this.run<AckInfo>('info', (store) => store.get('ack'));\n\t\tif (result) {\n\t\t\treturn result;\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tglobalAckTimestamp: null,\n\t\t\t\ttype: 'ack',\n\t\t\t};\n\t\t}\n\t};\n\n\tsetGlobalAck = async (ack: string) => {\n\t\tawait this.run(\n\t\t\t'info',\n\t\t\t(store) => store.put({ type: 'ack', globalAckTimestamp: ack }),\n\t\t\t{ mode: 'readwrite' },\n\t\t);\n\t};\n}\n", "import {\n\tDocumentBaseline,\n\tgetOidSubIdRange,\n\tgetOidRoot,\n\tObjectIdentifier,\n\tisLegacyDotOid,\n\tgetLegacyDotOidSubIdRange,\n} from '@verdant-web/common';\nimport { IDBService } from '../IDBService.js';\nimport { Context } from '../context.js';\n\nexport class BaselinesStore extends IDBService {\n\tconstructor(db: IDBDatabase, opts: { log?: Context['log'] }) {\n\t\tsuper(db, opts);\n\t}\n\n\tgetAllForDocument = async (\n\t\toid: ObjectIdentifier,\n\t\t{\n\t\t\tmode = 'readonly',\n\t\t\ttransaction,\n\t\t}: { mode?: 'readwrite' | 'readonly'; transaction?: IDBTransaction } = {},\n\t) => {\n\t\tconst baselines: DocumentBaseline[] = [];\n\t\tawait this.iterateOverAllForDocument(\n\t\t\toid,\n\t\t\t(baseline) => {\n\t\t\t\tbaselines.push(baseline);\n\t\t\t},\n\t\t\t{ mode, transaction },\n\t\t);\n\t\treturn baselines;\n\t};\n\titerateOverAllForDocument = async (\n\t\toid: ObjectIdentifier,\n\t\titerator: (baseline: DocumentBaseline, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tmode = 'readonly',\n\t\t\ttransaction,\n\t\t}: { mode?: 'readwrite' | 'readonly'; transaction?: IDBTransaction } = {},\n\t) => {\n\t\treturn this.iterate(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\tconst root = getOidRoot(oid);\n\t\t\t\tconst [start, end] = getOidSubIdRange(oid);\n\t\t\t\t// FIXME: get rid of legacy dot OIDs...\n\t\t\t\t// if (isLegacyDotOid(oid)) {\n\t\t\t\tconst [dotStart, dotEnd] = getLegacyDotOidSubIdRange(oid);\n\t\t\t\treturn [\n\t\t\t\t\tstore.openCursor(IDBKeyRange.only(root)),\n\t\t\t\t\tstore.openCursor(IDBKeyRange.bound(start, end, false, false)),\n\t\t\t\t\tstore.openCursor(IDBKeyRange.bound(dotStart, dotEnd, false, false)),\n\t\t\t\t];\n\t\t\t\t// } else {\n\t\t\t\t// \treturn [\n\t\t\t\t// \t\t// first the root itself\n\t\t\t\t// \t\tstore.openCursor(IDBKeyRange.only(root)),\n\t\t\t\t// \t\t// then the range of its possible subdocuments\n\t\t\t\t// \t\tstore.openCursor(IDBKeyRange.bound(start, end, false, false)),\n\t\t\t\t// \t];\n\t\t\t\t// }\n\t\t\t},\n\t\t\titerator,\n\t\t\t{ mode, transaction },\n\t\t);\n\t};\n\n\titerateOverAllForCollection = async (\n\t\tcollection: string,\n\t\titerator: (baseline: DocumentBaseline, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tmode = 'readonly',\n\t\t\ttransaction,\n\t\t}: { mode?: 'readwrite' | 'readonly'; transaction?: IDBTransaction } = {},\n\t) => {\n\t\treturn this.iterate(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\treturn [\n\t\t\t\t\tstore.openCursor(\n\t\t\t\t\t\tIDBKeyRange.bound(collection, collection + '\\uffff', false, false),\n\t\t\t\t\t),\n\t\t\t\t];\n\t\t\t},\n\t\t\titerator,\n\t\t\t{ mode, transaction },\n\t\t);\n\t};\n\n\tgetAllForMultipleDocuments = async (\n\t\tdocOids: string[],\n\t\t{ mode = 'readonly' }: { mode?: 'readwrite' | 'readonly' } = {},\n\t) => {\n\t\tconst result = await this.runAll<DocumentBaseline[]>(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\treturn docOids.flatMap((oid) => {\n\t\t\t\t\tconst root = getOidRoot(oid);\n\t\t\t\t\tconst [start, end] = getOidSubIdRange(oid);\n\t\t\t\t\t// FIXME: get rid of legacy dot OIDs...\n\t\t\t\t\t// if (isLegacyDotOid(oid)) {\n\t\t\t\t\tconst [dotStart, dotEnd] = getLegacyDotOidSubIdRange(oid);\n\t\t\t\t\treturn [\n\t\t\t\t\t\tstore.get(root),\n\t\t\t\t\t\tstore.getAll(IDBKeyRange.bound(start, end, false, false)),\n\t\t\t\t\t\tstore.getAll(IDBKeyRange.bound(dotStart, dotEnd, false, false)),\n\t\t\t\t\t];\n\t\t\t\t\t// } else {\n\t\t\t\t\t// \treturn [\n\t\t\t\t\t// \t\tstore.get(root),\n\t\t\t\t\t// \t\tstore.getAll(IDBKeyRange.bound(start, end, false, false)),\n\t\t\t\t\t// \t];\n\t\t\t\t\t// }\n\t\t\t\t});\n\t\t\t},\n\t\t\t{ mode },\n\t\t);\n\t\treturn result.flat();\n\t};\n\n\tgetAllSince = async (\n\t\ttimestamp: string | null,\n\t\t{ mode = 'readonly' }: { mode?: 'readwrite' | 'readonly' } = {},\n\t) => {\n\t\treturn this.run<DocumentBaseline[]>(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\tconst range = timestamp\n\t\t\t\t\t? IDBKeyRange.lowerBound(timestamp, true)\n\t\t\t\t\t: undefined;\n\t\t\t\tconst index = store.index('timestamp');\n\t\t\t\treturn index.getAll(range);\n\t\t\t},\n\t\t\t{ mode },\n\t\t);\n\t};\n\n\tget = async (\n\t\toid: ObjectIdentifier,\n\t\t{\n\t\t\ttransaction,\n\t\t\tmode = 'readonly',\n\t\t}: { transaction?: IDBTransaction; mode?: 'readwrite' | 'readonly' } = {},\n\t) => {\n\t\treturn this.run<DocumentBaseline>('baselines', (store) => store.get(oid), {\n\t\t\tmode,\n\t\t\ttransaction,\n\t\t});\n\t};\n\n\tset = async <T>(\n\t\tbaseline: DocumentBaseline<T>,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tawait this.run('baselines', (store) => store.put(baseline), {\n\t\t\tmode: 'readwrite',\n\t\t\ttransaction,\n\t\t});\n\t};\n\n\tsetAll = async <T>(\n\t\tbaselines: DocumentBaseline<T>[],\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tawait this.runAll(\n\t\t\t'baselines',\n\t\t\t(store) => {\n\t\t\t\treturn baselines.map((baseline) => store.put(baseline));\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\treset = () => {\n\t\treturn this.clear('baselines');\n\t};\n\n\tdelete = async (\n\t\toid: ObjectIdentifier,\n\t\t{ transaction }: { transaction?: IDBTransaction },\n\t) => {\n\t\tawait this.run('baselines', (store) => store.delete(oid), {\n\t\t\tmode: 'readwrite',\n\t\t\ttransaction,\n\t\t});\n\t};\n}\n", "import cuid from 'cuid';\nimport { IDBService } from '../IDBService.js';\n\nexport type LocalReplicaInfo = {\n\ttype: 'localReplicaInfo';\n\tid: string;\n\tuserId: string | undefined;\n\tackedLogicalTime: string | null;\n\tlastSyncedLogicalTime: string | null;\n};\n\nexport class LocalReplicaStore extends IDBService {\n\tprivate _creating: Promise<void> | undefined;\n\tprivate cached: LocalReplicaInfo | undefined;\n\n\tget = async ({\n\t\ttransaction,\n\t}: { transaction?: IDBTransaction } = {}): Promise<LocalReplicaInfo> => {\n\t\tif (this.cached) {\n\t\t\treturn this.cached;\n\t\t}\n\n\t\tconst lookup = await this.run<LocalReplicaInfo>(\n\t\t\t'info',\n\t\t\t(store) => store.get('localReplicaInfo'),\n\t\t\t{ transaction },\n\t\t);\n\n\t\t// not cached, not in db, create it\n\t\tif (!lookup) {\n\t\t\t// prevent a race condition if get() is called again while we are\n\t\t\t// creating the replica info\n\t\t\tif (!this._creating) {\n\t\t\t\tthis._creating = (async () => {\n\t\t\t\t\t// create our own replica info now\n\t\t\t\t\tconst replicaId = cuid();\n\t\t\t\t\tconst replicaInfo: LocalReplicaInfo = {\n\t\t\t\t\t\ttype: 'localReplicaInfo',\n\t\t\t\t\t\tid: replicaId,\n\t\t\t\t\t\tuserId: undefined,\n\t\t\t\t\t\tackedLogicalTime: null,\n\t\t\t\t\t\tlastSyncedLogicalTime: null,\n\t\t\t\t\t};\n\t\t\t\t\tawait this.run('info', (store) => store.put(replicaInfo), {\n\t\t\t\t\t\tmode: 'readwrite',\n\t\t\t\t\t});\n\t\t\t\t\tthis.cached = replicaInfo;\n\t\t\t\t})();\n\t\t\t}\n\t\t\tawait this._creating;\n\n\t\t\treturn this.get({ transaction });\n\t\t}\n\n\t\tthis.cached = lookup;\n\t\treturn lookup;\n\t};\n\n\tupdate = async (\n\t\tdata: Partial<LocalReplicaInfo>,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tconst localReplicaInfo = await this.get({ transaction });\n\t\tObject.assign(localReplicaInfo, data);\n\t\tawait this.run('info', (store) => store.put(localReplicaInfo), {\n\t\t\tmode: 'readwrite',\n\t\t});\n\t\tthis.cached = localReplicaInfo;\n\t};\n\n\treset = async () => {\n\t\tconst localInfo = await this.get();\n\t\tlocalInfo.ackedLogicalTime = null;\n\t\tlocalInfo.lastSyncedLogicalTime = null;\n\t\tawait this.run('info', (store) => store.put(localInfo), {\n\t\t\tmode: 'readwrite',\n\t\t});\n\t};\n}\n", "import {\n\tAckMessage,\n\tDocumentBaseline,\n\tgetOidRoot,\n\tHeartbeatMessage,\n\tObjectIdentifier,\n\tOperation,\n\tOperationMessage,\n\tpickValidOperationKeys,\n\tPresenceUpdateMessage,\n\tSyncAckMessage,\n\tSyncMessage,\n\tVerdantInternalPresence,\n} from '@verdant-web/common';\n\nimport { Metadata } from './Metadata.js';\n\nexport class MessageCreator {\n\tconstructor(private meta: Metadata) {}\n\n\tcreateOperation = async (\n\t\tinit: Pick<OperationMessage, 'operations'> & {\n\t\t\ttimestamp?: string;\n\t\t},\n\t): Promise<OperationMessage> => {\n\t\tconst localInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'op',\n\t\t\ttimestamp: this.meta.now,\n\t\t\treplicaId: localInfo.id,\n\t\t\toperations: init.operations.map(pickValidOperationKeys),\n\t\t};\n\t};\n\n\tcreateMigrationOperation = async ({\n\t\ttargetVersion,\n\t\t...init\n\t}: Pick<OperationMessage, 'operations'> & {\n\t\ttargetVersion: number;\n\t}): Promise<OperationMessage> => {\n\t\tconst localInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'op',\n\t\t\toperations: init.operations.map((op) => ({\n\t\t\t\t...op,\n\t\t\t\ttimestamp: this.meta.time.zero(targetVersion),\n\t\t\t})),\n\t\t\ttimestamp: this.meta.time.zero(targetVersion),\n\t\t\treplicaId: localInfo.id,\n\t\t};\n\t};\n\n\t/**\n\t * @param since - override local understanding of last sync time\n\t */\n\tcreateSyncStep1 = async (since?: string | null): Promise<SyncMessage> => {\n\t\tconst localReplicaInfo = await this.meta.localReplica.get();\n\n\t\tconst provideChangesSince =\n\t\t\tsince === null ? null : localReplicaInfo.lastSyncedLogicalTime;\n\n\t\t// collect all of our operations that are newer than the server's last operation\n\t\t// if server replica isn't stored, we're syncing for the first time.\n\t\tconst operations: Operation[] = [];\n\t\tconst affectedDocs = new Set<ObjectIdentifier>();\n\n\t\t// FIXME: this branch gives bad vibes. should we always\n\t\t// send all operations from other replicas too? is there\n\t\t// ever a case where we have a \"since\" timestamp and there\n\t\t// are foreign ops that match it?\n\t\tif (provideChangesSince) {\n\t\t\tawait this.meta.operations.iterateOverAllLocalOperations(\n\t\t\t\t(patch) => {\n\t\t\t\t\toperations.push(pickValidOperationKeys(patch));\n\t\t\t\t\taffectedDocs.add(getOidRoot(patch.oid));\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tafter: provideChangesSince,\n\t\t\t\t\t// block on writes to prevent race conditions\n\t\t\t\t\tmode: 'readwrite',\n\t\t\t\t},\n\t\t\t);\n\t\t} else {\n\t\t\t// if providing the whole history, don't limit to only local\n\t\t\t// operations\n\t\t\tawait this.meta.operations.iterateOverAllOperations(\n\t\t\t\t(patch) => {\n\t\t\t\t\toperations.push(pickValidOperationKeys(patch));\n\t\t\t\t\taffectedDocs.add(getOidRoot(patch.oid));\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tmode: 'readwrite',\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\t// we only need to send baselines if we've never synced before\n\t\tlet baselines: DocumentBaseline[] = [];\n\t\tif (!provideChangesSince) {\n\t\t\tbaselines = await this.meta.baselines.getAllSince('');\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'sync',\n\t\t\tschemaVersion: this.meta.schema.currentVersion,\n\t\t\ttimestamp: this.meta.now,\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t\tresyncAll: !localReplicaInfo.lastSyncedLogicalTime,\n\t\t\toperations,\n\t\t\tbaselines,\n\t\t\tsince: provideChangesSince,\n\t\t};\n\t};\n\n\tcreatePresenceUpdate = async (data: {\n\t\tpresence?: any;\n\t\tinternal?: VerdantInternalPresence;\n\t}): Promise<PresenceUpdateMessage> => {\n\t\tconst localReplicaInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'presence-update',\n\t\t\tpresence: data.presence,\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t\tinternal: data.internal,\n\t\t};\n\t};\n\n\tcreateHeartbeat = async (): Promise<HeartbeatMessage> => {\n\t\tconst localReplicaInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'heartbeat',\n\t\t\ttimestamp: this.meta.now,\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t};\n\t};\n\n\tcreateAck = async (nonce: string): Promise<AckMessage> => {\n\t\tconst localReplicaInfo = await this.meta.localReplica.get();\n\t\treturn {\n\t\t\ttype: 'ack',\n\t\t\ttimestamp: this.meta.now,\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t\tnonce,\n\t\t};\n\t};\n}\n", "import {\n\tcreateCompoundIndexValue,\n\tcreateLowerBoundIndexValue,\n\tcreateUpperBoundIndexValue,\n\tgetOidRoot,\n\tObjectIdentifier,\n\tOperation,\n\tassert,\n} from '@verdant-web/common';\nimport { IDBService } from '../IDBService.js';\nimport { isAbortError } from '../idb.js';\n\nexport type ClientOperation = Operation & {\n\tisLocal: boolean;\n};\n\nexport type StoredClientOperation = ClientOperation & {\n\toid_timestamp: string;\n\tl_t: string;\n\td_t: string;\n};\n\nexport class OperationsStore extends IDBService {\n\tconstructor(db: IDBDatabase, opts: { log?: (...args: any[]) => void }) {\n\t\tsuper(db, opts);\n\t}\n\t/**\n\t * Iterates over every patch for the root and every sub-object\n\t * of a given document. Optionally limit by timestamp.\n\t */\n\titerateOverAllOperationsForDocument = async (\n\t\toid: ObjectIdentifier,\n\t\titerator: (patch: StoredClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tto,\n\t\t\tfrom,\n\t\t\tafter,\n\t\t\tmode = 'readonly',\n\t\t\ttransaction: providedTx,\n\t\t}: {\n\t\t\tto?: string;\n\t\t\tfrom?: string;\n\t\t\tafter?: string;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t\ttransaction?: IDBTransaction;\n\t\t} = {},\n\t): Promise<void> => {\n\t\tconst transaction =\n\t\t\tprovidedTx ||\n\t\t\tthis.createTransaction(['operations'], {\n\t\t\t\tmode,\n\t\t\t});\n\t\tconst store = transaction.objectStore('operations');\n\t\tconst index = store.index('d_t');\n\n\t\tconst startTimestamp = from || after;\n\t\tconst start = startTimestamp\n\t\t\t? createCompoundIndexValue(oid, startTimestamp)\n\t\t\t: createLowerBoundIndexValue(oid);\n\t\tconst end = to\n\t\t\t? createCompoundIndexValue(oid, to)\n\t\t\t: createUpperBoundIndexValue(oid);\n\n\t\tconst range = IDBKeyRange.bound(start, end, !!after, false);\n\n\t\tconst request = index.openCursor(range, 'next');\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tlet previousTimestamp: string | undefined;\n\t\t\trequest.onsuccess = (event) => {\n\t\t\t\tconst cursor = request.result;\n\t\t\t\tif (cursor) {\n\t\t\t\t\tconst value = cursor.value as StoredClientOperation;\n\t\t\t\t\tassert(value.oid.startsWith(oid));\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpreviousTimestamp === undefined ||\n\t\t\t\t\t\t\tpreviousTimestamp <= value.timestamp,\n\t\t\t\t\t\t`expected ${previousTimestamp} <= ${value.timestamp}`,\n\t\t\t\t\t);\n\n\t\t\t\t\titerator(value, store);\n\t\t\t\t\tpreviousTimestamp = value.timestamp;\n\t\t\t\t\tcursor.continue();\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = (event) => {\n\t\t\t\tif (isAbortError(request.error)) {\n\t\t\t\t\tresolve();\n\t\t\t\t\treturn;\n\t\t\t\t} else {\n\t\t\t\t\treject(request.error);\n\t\t\t\t}\n\t\t\t};\n\t\t});\n\t};\n\n\titerateOverAllOperationsForEntity = async (\n\t\toid: ObjectIdentifier,\n\t\titerator: (patch: StoredClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tafter,\n\t\t\tto,\n\t\t\tmode,\n\t\t\ttransaction: providedTx,\n\t\t}: {\n\t\t\tafter?: string;\n\t\t\tto?: string;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t\ttransaction?: IDBTransaction;\n\t\t},\n\t): Promise<void> => {\n\t\tconst transaction =\n\t\t\tprovidedTx || this.createTransaction(['operations'], { mode });\n\t\tconst store = transaction.objectStore('operations');\n\n\t\tconst start = after\n\t\t\t? createCompoundIndexValue(oid, after)\n\t\t\t: createLowerBoundIndexValue(oid);\n\t\tconst end = to\n\t\t\t? createCompoundIndexValue(oid, to)\n\t\t\t: createUpperBoundIndexValue(oid);\n\n\t\tconst range = IDBKeyRange.bound(start, end, !!after, false);\n\n\t\tconst request = store.openCursor(range, 'next');\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tlet previousTimestamp: string | undefined;\n\t\t\trequest.onsuccess = (event) => {\n\t\t\t\tconst cursor = request.result;\n\t\t\t\tif (cursor) {\n\t\t\t\t\tconst value = cursor.value as StoredClientOperation;\n\t\t\t\t\tassert(value.oid.startsWith(oid));\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpreviousTimestamp === undefined ||\n\t\t\t\t\t\t\tpreviousTimestamp <= value.timestamp,\n\t\t\t\t\t\t`expected ${previousTimestamp} <= ${value.timestamp}`,\n\t\t\t\t\t);\n\n\t\t\t\t\titerator(value, store);\n\t\t\t\t\tpreviousTimestamp = value.timestamp;\n\t\t\t\t\tcursor.continue();\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = (event) => {\n\t\t\t\tif (isAbortError(request.error)) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else {\n\t\t\t\t\treject(request.error);\n\t\t\t\t}\n\t\t\t};\n\t\t});\n\t};\n\n\titerateOverAllOperationsForCollection = async (\n\t\tcollection: string,\n\t\titerator: (patch: StoredClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tafter,\n\t\t\tto,\n\t\t\tmode,\n\t\t\ttransaction: providedTx,\n\t\t}: {\n\t\t\tafter?: string;\n\t\t\tto?: string;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t\ttransaction?: IDBTransaction;\n\t\t},\n\t): Promise<void> => {\n\t\tconst transaction =\n\t\t\tprovidedTx || this.createTransaction(['operations'], { mode });\n\n\t\treturn this.iterate(\n\t\t\t'operations',\n\t\t\t(store) => {\n\t\t\t\treturn store.openCursor(\n\t\t\t\t\tIDBKeyRange.bound(collection, collection + '\\uffff', false, false),\n\t\t\t\t\t'next',\n\t\t\t\t);\n\t\t\t},\n\t\t\titerator,\n\t\t\t{ mode, transaction },\n\t\t);\n\t};\n\n\titerateOverAllLocalOperations = async (\n\t\titerator: (patch: ClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tbefore,\n\t\t\tafter,\n\t\t\tmode = 'readonly',\n\t\t\ttransaction: providedTx,\n\t\t}: {\n\t\t\tbefore?: string | null;\n\t\t\tafter?: string | null;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t\ttransaction?: IDBTransaction;\n\t\t},\n\t): Promise<void> => {\n\t\tconst transaction =\n\t\t\tprovidedTx || this.createTransaction(['operations'], { mode });\n\t\tconst store = transaction.objectStore('operations');\n\t\tconst index = store.index('l_t');\n\n\t\tconst start = after\n\t\t\t? createCompoundIndexValue(true, after)\n\t\t\t: createLowerBoundIndexValue(true);\n\t\tconst end = before\n\t\t\t? createCompoundIndexValue(true, before)\n\t\t\t: createUpperBoundIndexValue(true);\n\n\t\tconst range = IDBKeyRange.bound(start, end, !!after, true);\n\n\t\tconst request = index.openCursor(range, 'next');\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tlet previousTimestamp: string | undefined;\n\t\t\trequest.onsuccess = (event) => {\n\t\t\t\tconst cursor = request.result;\n\t\t\t\tif (cursor) {\n\t\t\t\t\tconst value = cursor.value as StoredClientOperation;\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpreviousTimestamp === undefined ||\n\t\t\t\t\t\t\tpreviousTimestamp <= value.timestamp,\n\t\t\t\t\t\t`expected ${previousTimestamp} <= ${value.timestamp}`,\n\t\t\t\t\t);\n\n\t\t\t\t\titerator(value, store);\n\t\t\t\t\tpreviousTimestamp = value.timestamp;\n\t\t\t\t\tcursor.continue();\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = (event) => {\n\t\t\t\tif (isAbortError(request.error)) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else {\n\t\t\t\t\treject(request.error);\n\t\t\t\t}\n\t\t\t};\n\t\t});\n\t};\n\n\titerateOverAllOperations = async (\n\t\titerator: (patch: ClientOperation, store: IDBObjectStore) => void,\n\t\t{\n\t\t\tbefore,\n\t\t\ttransaction,\n\t\t\tmode,\n\t\t\tfrom,\n\t\t}: {\n\t\t\t/** Ending timestamp, exclusive */\n\t\t\tbefore?: string | null;\n\t\t\t/** Starting timestamp, inclusive */\n\t\t\tfrom?: string | null;\n\t\t\ttransaction?: IDBTransaction;\n\t\t\tmode?: 'readwrite' | 'readonly';\n\t\t},\n\t): Promise<void> => {\n\t\tawait this.iterate(\n\t\t\t'operations',\n\t\t\t(store) => {\n\t\t\t\tconst start = from ? createLowerBoundIndexValue(from) : undefined;\n\t\t\t\tconst end = before ? createUpperBoundIndexValue(before) : undefined;\n\n\t\t\t\tconst range =\n\t\t\t\t\tstart && end\n\t\t\t\t\t\t? IDBKeyRange.bound(start, end, false, true)\n\t\t\t\t\t\t: start\n\t\t\t\t\t\t? IDBKeyRange.lowerBound(start, false)\n\t\t\t\t\t\t: end\n\t\t\t\t\t\t? IDBKeyRange.upperBound(end, true)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst index = store.index('timestamp');\n\t\t\t\treturn index.openCursor(range, 'next');\n\t\t\t},\n\t\t\titerator,\n\t\t\t{ mode, transaction },\n\t\t);\n\t};\n\n\t/**\n\t * Adds a set of patches to the database.\n\t * @returns a list of affected root document OIDs.\n\t */\n\taddOperations = async (\n\t\tpatches: ClientOperation[],\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t): Promise<ObjectIdentifier[]> => {\n\t\treturn this.insert(patches.map(this.addCompoundIndexes), { transaction });\n\t};\n\n\tprivate addCompoundIndexes = (\n\t\tpatch: ClientOperation,\n\t): StoredClientOperation => {\n\t\treturn {\n\t\t\t...patch,\n\t\t\toid_timestamp: createCompoundIndexValue(\n\t\t\t\tpatch.oid,\n\t\t\t\tpatch.timestamp,\n\t\t\t) as string,\n\t\t\tl_t: createCompoundIndexValue(patch.isLocal, patch.timestamp) as string,\n\t\t\td_t: createCompoundIndexValue(\n\t\t\t\tgetOidRoot(patch.oid),\n\t\t\t\tpatch.timestamp,\n\t\t\t) as string,\n\t\t};\n\t};\n\n\tprivate insert = async (\n\t\toperations: StoredClientOperation[],\n\t\t{ transaction }: { transaction?: IDBTransaction },\n\t): Promise<ObjectIdentifier[]> => {\n\t\tconst affected = new Set<ObjectIdentifier>();\n\t\tawait this.runAll(\n\t\t\t'operations',\n\t\t\t(store) =>\n\t\t\t\toperations.map((op) => {\n\t\t\t\t\taffected.add(getOidRoot(op.oid));\n\t\t\t\t\treturn store.put(op);\n\t\t\t\t}),\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t\treturn Array.from(affected);\n\t};\n\n\treset = () => {\n\t\treturn this.clear('operations');\n\t};\n}\n", "import { StorageSchema } from '@verdant-web/common';\nimport { storeRequestPromise } from '../idb.js';\n\ntype StoredSchema = {\n\ttype: 'schema';\n\tschema: string;\n};\n\nexport class SchemaStore {\n\tprivate cached: StorageSchema<any> | null = null;\n\n\tconstructor(\n\t\tprivate readonly db: IDBDatabase,\n\t\tpublic readonly currentVersion: number,\n\t) {}\n\n\tget = async (): Promise<StorageSchema<any> | null> => {\n\t\tif (this.cached) {\n\t\t\treturn this.cached;\n\t\t}\n\n\t\tconst db = this.db;\n\t\tconst transaction = db.transaction('info', 'readonly');\n\t\tconst store = transaction.objectStore('info');\n\t\tconst request = store.get('schema');\n\t\tconst value = (await storeRequestPromise(request)) as\n\t\t\t| StoredSchema\n\t\t\t| undefined;\n\t\tif (!value) {\n\t\t\treturn null;\n\t\t}\n\t\tthis.cached = JSON.parse(value.schema);\n\t\treturn this.cached;\n\t};\n\n\tset = async (schema: StorageSchema<any>): Promise<void> => {\n\t\tconst db = this.db;\n\t\tconst transaction = db.transaction('info', 'readwrite');\n\t\tconst store = transaction.objectStore('info');\n\t\tconst request = store.put({\n\t\t\ttype: 'schema',\n\t\t\tschema: JSON.stringify(schema),\n\t\t} as StoredSchema);\n\t\tthis.cached = schema;\n\t\tawait storeRequestPromise(request);\n\t};\n}\n", "import {\n\tapplyPatch,\n\tassert,\n\tassignOid,\n\tClientMessage,\n\tDocumentBaseline,\n\tEventSubscriber,\n\tFileRef,\n\tisFileRef,\n\tgetOidRoot,\n\tHybridLogicalClockTimestampProvider,\n\tObjectIdentifier,\n\tOperation,\n\tPatchCreator,\n\tRef,\n\tStorageSchema,\n\tsubstituteRefsWithObjects,\n} from '@verdant-web/common';\nimport { AckInfoStore } from './AckInfoStore.js';\nimport { BaselinesStore } from './BaselinesStore.js';\nimport {\n\tcreateAbortableTransaction,\n\tgetAllFromObjectStores,\n\tgetSizeOfObjectStore,\n\tstoreRequestPromise,\n} from '../idb.js';\nimport { LocalReplicaInfo, LocalReplicaStore } from './LocalReplicaStore.js';\nimport { MessageCreator } from './MessageCreator.js';\nimport { ClientOperation, OperationsStore } from './OperationsStore.js';\nimport { SchemaStore } from './SchemaStore.js';\nimport { Context } from '../context.js';\n\nexport interface ExportData {\n\toperations: Operation[];\n\tbaselines: DocumentBaseline[];\n\tlocalReplica?: LocalReplicaInfo;\n\tschemaVersion: number;\n}\n\nexport class Metadata extends EventSubscriber<{\n\tmessage: (message: ClientMessage) => void;\n\trebase: (baselines: DocumentBaseline[]) => void;\n\tfilesDeleted: (files: FileRef[]) => void;\n}> {\n\treadonly operations;\n\treadonly baselines;\n\treadonly localReplica;\n\treadonly ackInfo;\n\treadonly messageCreator;\n\treadonly patchCreator;\n\treadonly schema;\n\treadonly time = new HybridLogicalClockTimestampProvider();\n\n\tprivate readonly disableRebasing: boolean = false;\n\t/**\n\t * indicates the client is shutting down and we should stop\n\t * accessing the database.\n\t */\n\tprivate _closing = false;\n\n\tprivate context: Omit<Context, 'documentDb' | 'getNow'>;\n\n\tprivate onOperation?: (operation: Operation) => void;\n\n\tconstructor({\n\t\tdisableRebasing,\n\t\tcontext,\n\t\tonOperation,\n\t}: {\n\t\tdisableRebasing?: boolean;\n\t\tcontext: Omit<Context, 'documentDb' | 'getNow'>;\n\t\tonOperation?: (operation: Operation) => void;\n\t}) {\n\t\tsuper();\n\t\tthis.context = context;\n\t\tthis.schema = new SchemaStore(context.metaDb, context.schema.version);\n\t\tthis.operations = new OperationsStore(this.db, { log: context.log });\n\t\tthis.baselines = new BaselinesStore(this.db, { log: context.log });\n\t\tthis.localReplica = new LocalReplicaStore(this.db);\n\t\tthis.ackInfo = new AckInfoStore(this.db);\n\t\tthis.messageCreator = new MessageCreator(this);\n\t\tthis.patchCreator = new PatchCreator(() => this.now);\n\t\tthis.onOperation = onOperation;\n\t\tif (disableRebasing) this.disableRebasing = disableRebasing;\n\t}\n\n\tprivate get db() {\n\t\treturn this.context.metaDb;\n\t}\n\n\tprivate get log() {\n\t\treturn this.context.log;\n\t}\n\n\tsetContext = (context: Context) => {\n\t\tthis.context = context;\n\t};\n\n\tget now() {\n\t\treturn this.time.now(this.schema.currentVersion);\n\t}\n\n\tclose = () => {\n\t\tthis._closing = true;\n\t};\n\n\t/**\n\t * Methods for accessing data\n\t */\n\n\tcreateTransaction = (\n\t\tstores: ('operations' | 'baselines')[],\n\t\topts: {\n\t\t\tabort?: AbortSignal;\n\t\t\twrite?: boolean;\n\t\t} = {},\n\t) => {\n\t\treturn createAbortableTransaction(\n\t\t\tthis.db,\n\t\t\tstores,\n\t\t\topts.write ? 'readwrite' : 'readonly',\n\t\t\topts.abort,\n\t\t\tthis.context.log,\n\t\t);\n\t};\n\n\t/**\n\t * Gets the OID and every sub-object OID for a given document.\n\t * Includes any sub-objects that are not referenced by the root object\n\t * but still happen to be in storage.\n\t */\n\tgetAllDocumentRelatedOids = async (oid: ObjectIdentifier) => {\n\t\tconst oids = new Set<ObjectIdentifier>();\n\t\tconst documentOid = getOidRoot(oid);\n\t\tassert(documentOid === oid, 'Must be root document OID');\n\t\toids.add(documentOid);\n\t\t// readwrite mode to block on other write transactions\n\t\tconst transaction = this.createTransaction(['baselines', 'operations']);\n\t\tawait Promise.all([\n\t\t\tthis.baselines.iterateOverAllForDocument(\n\t\t\t\tdocumentOid,\n\t\t\t\t(baseline) => {\n\t\t\t\t\toids.add(baseline.oid);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t\tthis.operations.iterateOverAllOperationsForDocument(\n\t\t\t\tdocumentOid,\n\t\t\t\t(patch) => {\n\t\t\t\t\toids.add(patch.oid);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t]);\n\n\t\treturn Array.from(oids);\n\t};\n\n\tgetAllCollectionRelatedOids = async (oid: ObjectIdentifier) => {\n\t\tconst oids = new Set<ObjectIdentifier>();\n\t\tconst transaction = this.db.transaction(\n\t\t\t['baselines', 'operations'],\n\t\t\t'readwrite',\n\t\t);\n\t\tawait Promise.all([\n\t\t\tthis.baselines.iterateOverAllForCollection(\n\t\t\t\toid,\n\t\t\t\t(baseline) => {\n\t\t\t\t\toids.add(baseline.oid);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t\tthis.operations.iterateOverAllOperationsForCollection(\n\t\t\t\toid,\n\t\t\t\t(patch) => {\n\t\t\t\t\toids.add(patch.oid);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t]);\n\n\t\treturn Array.from(oids);\n\t};\n\n\tgetDocumentSnapshot = async (\n\t\toid: ObjectIdentifier,\n\t\toptions: { to?: string } = {},\n\t) => {\n\t\tconst documentOid = getOidRoot(oid);\n\t\tassert(documentOid === oid, 'Must be root document OID');\n\t\tconst transaction = this.db.transaction(\n\t\t\t['baselines', 'operations'],\n\t\t\t'readwrite',\n\t\t);\n\t\tconst baselines = await this.baselines.getAllForDocument(documentOid, {\n\t\t\ttransaction,\n\t\t});\n\t\tconst objectMap = new Map<ObjectIdentifier, any>();\n\t\tfor (const baseline of baselines) {\n\t\t\tif (baseline.snapshot) {\n\t\t\t\tassignOid(baseline.snapshot, baseline.oid);\n\t\t\t}\n\t\t\tobjectMap.set(baseline.oid, baseline.snapshot);\n\t\t}\n\t\tawait this.operations.iterateOverAllOperationsForDocument(\n\t\t\tdocumentOid,\n\t\t\t(op) => {\n\t\t\t\tconst obj = objectMap.get(op.oid) || undefined;\n\t\t\t\tconst newObj = applyPatch(obj, op.data);\n\t\t\t\tif (newObj) {\n\t\t\t\t\tassignOid(newObj, op.oid);\n\t\t\t\t}\n\t\t\t\tobjectMap.set(op.oid, newObj);\n\t\t\t},\n\t\t\t{\n\t\t\t\ttransaction,\n\t\t\t\t// only apply operations up to the current time\n\t\t\t\tto: options.to || this.now,\n\t\t\t},\n\t\t);\n\t\tconst root = objectMap.get(documentOid);\n\t\tif (root) {\n\t\t\tsubstituteRefsWithObjects(root, objectMap);\n\t\t}\n\t\treturn root;\n\t};\n\n\tgetDocumentData = async (\n\t\toid: ObjectIdentifier,\n\t\topts?: {\n\t\t\tabort?: AbortSignal;\n\t\t},\n\t) => {\n\t\tconst transaction = this.createTransaction(\n\t\t\t['baselines', 'operations'],\n\t\t\topts,\n\t\t);\n\t\tconst baselines: DocumentBaseline[] = [];\n\t\tconst operations: Record<ObjectIdentifier, Operation[]> = {};\n\t\tawait Promise.all([\n\t\t\tthis.baselines.iterateOverAllForDocument(\n\t\t\t\toid,\n\t\t\t\t(baseline) => {\n\t\t\t\t\tbaselines.push(baseline);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttransaction,\n\t\t\t\t},\n\t\t\t),\n\t\t\tthis.operations.iterateOverAllOperationsForDocument(\n\t\t\t\toid,\n\t\t\t\t(op) => {\n\t\t\t\t\toperations[op.oid] ??= [];\n\t\t\t\t\toperations[op.oid].push(op);\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t),\n\t\t]);\n\t\treturn {\n\t\t\tbaselines,\n\t\t\toperations,\n\t\t};\n\t};\n\n\tgetDocumentAuthz = async (oid: ObjectIdentifier) => {\n\t\tconst baseline = await this.baselines.get(oid);\n\t\tif (baseline) {\n\t\t\treturn baseline.authz;\n\t\t}\n\t\tlet authz;\n\t\tawait this.operations.iterateOverAllOperationsForEntity(\n\t\t\toid,\n\t\t\t(op) => {\n\t\t\t\tif (op.data.op === 'initialize') {\n\t\t\t\t\tauthz = op.authz;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t},\n\t\t\t{},\n\t\t);\n\t\treturn authz;\n\t};\n\n\t/**\n\t * Methods for writing data\n\t */\n\n\t/**\n\t * Acks that we have seen a timestamp to the server\n\t * and stores it as our local ackedLogicalTime if it's\n\t * greater than our current ackedLogicalTime.\n\t */\n\tack = async (timestamp: string) => {\n\t\tconst localReplicaInfo = await this.localReplica.get();\n\t\t// can't ack timestamps from the future.\n\t\tif (timestamp > this.now) return;\n\n\t\tthis.emit('message', {\n\t\t\ttype: 'ack',\n\t\t\treplicaId: localReplicaInfo.id,\n\t\t\ttimestamp,\n\t\t});\n\t\tif (\n\t\t\t!this._closing &&\n\t\t\t(!localReplicaInfo.ackedLogicalTime ||\n\t\t\t\ttimestamp > localReplicaInfo.ackedLogicalTime)\n\t\t) {\n\t\t\tthis.localReplica.update({ ackedLogicalTime: timestamp });\n\t\t}\n\t};\n\n\t/**\n\t * Applies a patch to the document and stores it in the database.\n\t * @returns the oldest local history timestamp\n\t */\n\tinsertLocalOperations = async (\n\t\toperations: Operation[],\n\t\topts?: { transaction?: IDBTransaction },\n\t) => {\n\t\tif (operations.length === 0) return;\n\t\t// await this.rebaseLock;\n\t\tthis.log(\n\t\t\t'debug',\n\t\t\t`Inserting ${operations.length} local operations`,\n\t\t\toperations,\n\t\t);\n\n\t\t// add local flag, in place.\n\t\tfor (const operation of operations) {\n\t\t\t(operation as ClientOperation).isLocal = true;\n\t\t}\n\t\tawait this.operations.addOperations(operations as ClientOperation[], opts);\n\n\t\tconst message = await this.messageCreator.createOperation({ operations });\n\t\tthis.emit('message', message);\n\n\t\t// we can now enqueue and check for rebase opportunities\n\t\tthis.tryAutonomousRebase();\n\n\t\tif (this.onOperation) {\n\t\t\toperations.forEach((o) => this.onOperation!(o));\n\t\t}\n\t};\n\n\t/**\n\t * Inserts remote operations. This does not affect local history.\n\t * @returns a list of affected document OIDs\n\t */\n\tinsertRemoteOperations = async (\n\t\toperations: Operation[],\n\t\topts?: { transaction?: IDBTransaction },\n\t) => {\n\t\tif (operations.length === 0) return [];\n\t\t// await this.rebaseLock;\n\t\tthis.log(\n\t\t\t'debug',\n\t\t\t`Inserting ${operations.length} remote operations`,\n\t\t\toperations,\n\t\t);\n\n\t\tconst affectedDocumentOids = await this.operations.addOperations(\n\t\t\toperations.map((patch) => ({\n\t\t\t\t...patch,\n\t\t\t\tisLocal: false,\n\t\t\t})),\n\t\t\topts,\n\t\t);\n\n\t\tthis.ack(operations[operations.length - 1].timestamp);\n\n\t\tif (this.onOperation) {\n\t\t\toperations.forEach((o) => this.onOperation!(o));\n\t\t}\n\n\t\treturn affectedDocumentOids;\n\t};\n\n\tinsertRemoteBaselines = async (\n\t\tbaselines: DocumentBaseline[],\n\t\topts?: { transaction?: IDBTransaction },\n\t) => {\n\t\tif (baselines.length === 0) return [];\n\t\tthis.log('debug', `Inserting ${baselines.length} remote baselines`);\n\n\t\tawait this.baselines.setAll(baselines, opts);\n\n\t\t// this.ack(baselines[baselines.length - 1].timestamp);\n\n\t\tconst affectedOidSet = new Set<ObjectIdentifier>();\n\t\tbaselines.forEach((baseline) => {\n\t\t\taffectedOidSet.add(getOidRoot(baseline.oid));\n\t\t});\n\n\t\treturn Array.from(affectedOidSet);\n\t};\n\n\tinsertData = async (\n\t\tdata: {\n\t\t\tbaselines?: DocumentBaseline[];\n\t\t\toperations?: Operation[];\n\t\t\tisLocal?: boolean;\n\t\t},\n\t\topts?: { abort: AbortSignal },\n\t) => {\n\t\tconst transaction = this.createTransaction(['baselines', 'operations'], {\n\t\t\t...opts,\n\t\t\twrite: true,\n\t\t});\n\t\tif (data.baselines) {\n\t\t\tawait this.insertRemoteBaselines(data.baselines, { transaction });\n\t\t}\n\t\tif (opts?.abort?.aborted) return;\n\t\tif (data.operations) {\n\t\t\tif (data.isLocal) {\n\t\t\t\tawait this.insertLocalOperations(data.operations, { transaction });\n\t\t\t} else {\n\t\t\t\tawait this.insertRemoteOperations(data.operations, { transaction });\n\t\t\t}\n\t\t}\n\t};\n\n\tupdateLastSynced = async (timestamp: string) => {\n\t\tif (this._closing) return;\n\n\t\treturn this.localReplica.update({\n\t\t\tlastSyncedLogicalTime: timestamp,\n\t\t});\n\t};\n\n\tlastSyncedTimestamp = async () => {\n\t\tconst localReplicaInfo = await this.localReplica.get();\n\t\treturn localReplicaInfo.lastSyncedLogicalTime;\n\t};\n\n\tprivate tryAutonomousRebase = async () => {\n\t\tif (this.disableRebasing) return;\n\n\t\tconst localReplicaInfo = await this.localReplica.get();\n\t\tif (localReplicaInfo.lastSyncedLogicalTime) return; // cannot autonomously rebase if we've synced\n\t\t// but if we have never synced... we can rebase everything!\n\t\tawait this.runRebase(this.now);\n\t};\n\n\t/**\n\t * Attempt to autonomously rebase local documents without server intervention.\n\t * This can currently only happen for a client who has never synced before.\n\t * The goal is to allow local-only clients to compress their history to exactly\n\t * their undo stack.\n\t */\n\tprivate runRebase = async (globalAckTimestamp: string) => {\n\t\tif (this._closing) return;\n\n\t\t// find all operations before the global ack\n\t\tlet lastTimestamp;\n\t\tconst toRebase = new Set<ObjectIdentifier>();\n\t\tconst transaction = this.createTransaction(['baselines', 'operations'], {\n\t\t\twrite: true,\n\t\t});\n\t\tlet operationCount = 0;\n\t\tawait this.operations.iterateOverAllOperations(\n\t\t\t(patch) => {\n\t\t\t\ttoRebase.add(patch.oid);\n\t\t\t\tlastTimestamp = patch.timestamp;\n\t\t\t\toperationCount++;\n\t\t\t},\n\t\t\t{\n\t\t\t\tbefore: globalAckTimestamp,\n\t\t\t\ttransaction,\n\t\t\t},\n\t\t);\n\n\t\tif (!toRebase.size) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this._closing) {\n\t\t\treturn;\n\t\t}\n\n\t\t// rebase each affected document\n\t\tlet newBaselines = [];\n\t\tfor (const oid of toRebase) {\n\t\t\tnewBaselines.push(\n\t\t\t\tawait this.rebase(\n\t\t\t\t\toid,\n\t\t\t\t\tlastTimestamp || globalAckTimestamp,\n\t\t\t\t\ttransaction,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tthis.emit('rebase', newBaselines);\n\t};\n\n\trebase = async (\n\t\toid: ObjectIdentifier,\n\t\tupTo: string,\n\t\tprovidedTx?: IDBTransaction,\n\t) => {\n\t\t// including replica Id for testing I guess\n\t\tconst replicaId = (await this.localReplica.get()).id;\n\n\t\tthis.log('debug', '[', replicaId, ']', 'Rebasing', oid, 'up to', upTo);\n\t\tconst transaction =\n\t\t\tprovidedTx ||\n\t\t\tthis.createTransaction(['operations', 'baselines'], { write: true });\n\t\tconst baseline = await this.baselines.get(oid, { transaction });\n\t\tlet current: any = baseline?.snapshot || undefined;\n\t\tlet operationsApplied = 0;\n\t\tlet authz = baseline?.authz;\n\t\tconst deletedRefs: Ref[] = [];\n\t\tawait this.operations.iterateOverAllOperationsForEntity(\n\t\t\toid,\n\t\t\t(patch, store) => {\n\t\t\t\t// FIXME: this seems like the wrong place to do this\n\t\t\t\t// but it's here as a safety measure...\n\t\t\t\tif (!baseline || patch.timestamp > baseline.timestamp) {\n\t\t\t\t\tcurrent = applyPatch(current, patch.data, deletedRefs);\n\t\t\t\t\tif (patch.data.op === 'initialize') {\n\t\t\t\t\t\tauthz = patch.authz;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// delete all prior operations to the baseline\n\t\t\t\toperationsApplied++;\n\t\t\t\tstore.delete(patch.oid_timestamp);\n\t\t\t},\n\t\t\t{\n\t\t\t\tto: upTo,\n\t\t\t\ttransaction,\n\t\t\t},\n\t\t);\n\t\tif (current) {\n\t\t\tassignOid(current, oid);\n\t\t}\n\t\tconst newBaseline = {\n\t\t\toid,\n\t\t\tsnapshot: current,\n\t\t\ttimestamp: upTo,\n\t\t\tauthz,\n\t\t};\n\t\tif (newBaseline.snapshot) {\n\t\t\tawait this.baselines.set(newBaseline, { transaction });\n\t\t} else {\n\t\t\tawait this.baselines.delete(oid, { transaction });\n\t\t}\n\n\t\tthis.log(\n\t\t\t'debug',\n\t\t\t'successfully rebased',\n\t\t\toid,\n\t\t\t'up to',\n\t\t\tupTo,\n\t\t\t':',\n\t\t\tcurrent,\n\t\t\t'and deleted',\n\t\t\toperationsApplied,\n\t\t\t'operations',\n\t\t);\n\n\t\t// cleanup deleted refs\n\t\tif (deletedRefs.length) {\n\t\t\tconst fileRefs = deletedRefs.filter(isFileRef);\n\t\t\tif (fileRefs.length) {\n\t\t\t\tthis.emit('filesDeleted', fileRefs);\n\t\t\t}\n\t\t}\n\n\t\treturn newBaseline;\n\t};\n\n\treset = async () => {\n\t\tawait this.operations.reset();\n\t\tawait this.baselines.reset();\n\t\tawait this.localReplica.reset();\n\t};\n\n\tupdateSchema = async (schema: StorageSchema, overrideConflict?: number) => {\n\t\tconst storedSchema = await this.schema.get();\n\t\tif (storedSchema) {\n\t\t\t// version changes will be handled by migration routines in\n\t\t\t// the actual idb database loading code (see: initializeDatabases)\n\n\t\t\t// but this check determines if the schema has been changed without\n\t\t\t// a version change. if so, it will error.\n\t\t\tif (\n\t\t\t\toverrideConflict === storedSchema.version &&\n\t\t\t\tstoredSchema.version === schema.version &&\n\t\t\t\tJSON.stringify(storedSchema) !== JSON.stringify(schema)\n\t\t\t) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Schema mismatch for version ${schema.version}\n\t\t\t\t\t${JSON.stringify(storedSchema)}\n\t\t\t\t\t${JSON.stringify(schema)}`,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Schema has changed without a version change! Any changes to your schema must be accompanied by a change in schema version and a migration routine.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tawait this.schema.set(schema);\n\t};\n\n\tsetGlobalAck = async (timestamp: string) => {\n\t\tif (this._closing) return;\n\t\tawait this.ackInfo.setGlobalAck(timestamp);\n\t\tif (!this.disableRebasing) {\n\t\t\tawait this.runRebase(timestamp);\n\t\t}\n\t};\n\n\t/**\n\t * Manually triggers a storage rebase.\n\t * Rebases happen automatically as needed, so\n\t * you probably don't need this.\n\t */\n\tmanualRebase = async () => {\n\t\tif (this._closing || this.disableRebasing) return;\n\t\tconst ackInfo = await this.ackInfo.getAckInfo();\n\t\tif (ackInfo.globalAckTimestamp) {\n\t\t\tthis.runRebase(ackInfo.globalAckTimestamp);\n\t\t}\n\t};\n\n\texport = async (): Promise<ExportData> => {\n\t\tconst db = this.db;\n\t\tconst [baselines, operations] = await getAllFromObjectStores(db, [\n\t\t\t'baselines',\n\t\t\t'operations',\n\t\t]);\n\t\tconst localReplica = await this.localReplica.get();\n\t\tconst schema = await this.schema.get();\n\t\tif (!schema) {\n\t\t\tthrow new Error('Cannot export Client data before initializing');\n\t\t}\n\t\treturn {\n\t\t\toperations,\n\t\t\tbaselines,\n\t\t\tlocalReplica,\n\t\t\tschemaVersion: schema.version,\n\t\t};\n\t};\n\n\t/**\n\t * Resets local metadata and clears operation/baseline stores.\n\t * DOES NOT add operations/baselines - this should be done\n\t * through the normal higher level systems.\n\t */\n\tresetFrom = async (data: ExportData) => {\n\t\tconst db = this.db;\n\t\tconst transaction = db.transaction(\n\t\t\t['baselines', 'operations', 'info'],\n\t\t\t'readwrite',\n\t\t);\n\t\tawait storeRequestPromise(transaction.objectStore('baselines').clear());\n\t\tawait storeRequestPromise(transaction.objectStore('operations').clear());\n\t\tawait storeRequestPromise(transaction.objectStore('info').clear());\n\t\tif (data.localReplica) {\n\t\t\tawait this.localReplica.update(\n\t\t\t\t{\n\t\t\t\t\tackedLogicalTime: data.localReplica.ackedLogicalTime,\n\t\t\t\t\tlastSyncedLogicalTime: data.localReplica.lastSyncedLogicalTime,\n\t\t\t\t},\n\t\t\t\t{ transaction },\n\t\t\t);\n\t\t}\n\t};\n\n\tstats = async () => {\n\t\tconst db = this.db;\n\t\tconst operationsSize = await getSizeOfObjectStore(db, 'operations');\n\t\tconst baselinesSize = await getSizeOfObjectStore(db, 'baselines');\n\n\t\treturn {\n\t\t\toperationsSize,\n\t\t\tbaselinesSize,\n\t\t};\n\t};\n}\n\nexport function supportLegacyExport(exportData: any): ExportData {\n\tif (exportData.schema) {\n\t\texportData.schemaVersion = exportData.schema.version;\n\t\tdelete exportData.schema;\n\t}\n\treturn exportData;\n}\n", "import { replaceLegacyOidsInObject } from '@verdant-web/common';\nimport { closeDatabase, storeRequestPromise } from '../idb.js';\n\nconst migrations = [version1, version2, version3, version4, version5, version6];\n\nexport function openMetadataDatabase({\n\tindexedDB = window.indexedDB,\n\tnamespace,\n\tlog,\n\tmetadataVersion = 5,\n}: {\n\tindexedDB?: IDBFactory;\n\tnamespace: string;\n\tlog?: (...args: any[]) => void;\n\tmetadataVersion?: number;\n}): Promise<{ wasInitialized: boolean; db: IDBDatabase }> {\n\treturn new Promise<{ wasInitialized: boolean; db: IDBDatabase }>(\n\t\t(resolve, reject) => {\n\t\t\tconst request = indexedDB.open(`${namespace}_meta`, metadataVersion);\n\t\t\tlet wasInitialized = false;\n\t\t\trequest.onupgradeneeded = async (event) => {\n\t\t\t\tconst db = request.result;\n\t\t\t\tconst tx = request.transaction!;\n\n\t\t\t\tconst toRun = migrations.slice(event.oldVersion);\n\t\t\t\tfor (const migration of toRun) {\n\t\t\t\t\tawait migration(db, tx);\n\t\t\t\t}\n\n\t\t\t\tawait new Promise((resolve, reject) => {\n\t\t\t\t\ttx.addEventListener('complete', resolve);\n\t\t\t\t\ttx.addEventListener('error', reject);\n\t\t\t\t});\n\n\t\t\t\tif (!event.oldVersion) {\n\t\t\t\t\twasInitialized = true;\n\t\t\t\t}\n\t\t\t};\n\t\t\trequest.onerror = () => {\n\t\t\t\tconsole.error('Error opening database', request.error);\n\t\t\t\treject(request.error);\n\t\t\t};\n\t\t\trequest.onsuccess = () => {\n\t\t\t\tresolve({ db: request.result, wasInitialized });\n\t\t\t};\n\t\t},\n\t);\n}\n\nexport async function openWIPMetadataDatabase({\n\twipNamespace,\n\tnamespace,\n\tindexedDB,\n\tlog,\n\tmetadataVersion,\n}: {\n\tindexedDB?: IDBFactory;\n\tnamespace: string;\n\twipNamespace: string;\n\tlog?: (...args: any[]) => void;\n\tmetadataVersion?: number;\n}): Promise<{ wasInitialized: boolean; db: IDBDatabase }> {\n\tconst result = await openMetadataDatabase({\n\t\tnamespace: wipNamespace,\n\t\tindexedDB,\n\t\tlog,\n\t\tmetadataVersion,\n\t});\n\n\t// this WIP database was already set up.\n\tif (!result.wasInitialized) {\n\t\treturn result;\n\t}\n\n\tlog?.('debug', 'Beginning copy of production metadata database to WIP');\n\t// copy all data from production metadata database\n\tconst { db: prodDb } = await openMetadataDatabase({\n\t\tnamespace,\n\t\tindexedDB,\n\t\tlog,\n\t\tmetadataVersion,\n\t});\n\n\tconst tx = prodDb.transaction(\n\t\t['baselines', 'operations', 'info'],\n\t\t'readonly',\n\t);\n\tconst [baselines, operations, info] = await Promise.all([\n\t\tstoreRequestPromise(tx.objectStore('baselines').getAll()),\n\t\tstoreRequestPromise(tx.objectStore('operations').getAll()),\n\t\tstoreRequestPromise(tx.objectStore('info').getAll()),\n\t]);\n\n\tconst wipTx = result.db.transaction(\n\t\t['baselines', 'operations', 'info'],\n\t\t'readwrite',\n\t);\n\tconst wipBaselines = wipTx.objectStore('baselines');\n\tconst wipOperations = wipTx.objectStore('operations');\n\tconst wipInfo = wipTx.objectStore('info');\n\n\tfor (const baseline of baselines) {\n\t\twipBaselines.put(baseline);\n\t}\n\tfor (const operation of operations) {\n\t\twipOperations.put(operation);\n\t}\n\tfor (const infoItem of info) {\n\t\twipInfo.put(infoItem);\n\t}\n\n\tawait new Promise<void>((resolve, reject) => {\n\t\twipTx.oncomplete = () => {\n\t\t\tresolve();\n\t\t};\n\t\twipTx.onerror = (event) => {\n\t\t\treject(event);\n\t\t};\n\t\twipTx.onabort = (event) => {\n\t\t\treject(event);\n\t\t};\n\t});\n\n\tawait closeDatabase(prodDb);\n\n\tlog?.(\n\t\t'debug',\n\t\t'Finished copy of production metadata database to WIP. Copied:',\n\t\tbaselines.length,\n\t\t'baselines,',\n\t\toperations.length,\n\t\t'operations',\n\t);\n\n\treturn result;\n}\n\nasync function version1(db: IDBDatabase, tx: IDBTransaction) {\n\tconst baselinesStore = db.createObjectStore('baselines', {\n\t\tkeyPath: 'oid',\n\t});\n\tconst operationsStore = db.createObjectStore('operations', {\n\t\tkeyPath: 'oid_timestamp',\n\t});\n\tconst infoStore = db.createObjectStore('info', { keyPath: 'type' });\n\tbaselinesStore.createIndex('timestamp', 'timestamp');\n\toperationsStore.createIndex('isLocal_timestamp', 'isLocal_timestamp');\n\toperationsStore.createIndex('documentOid_timestamp', 'documentOid_timestamp');\n}\n\n/**\n * 1 -> 2 changes:\n *\n * Consolidate compound index names:\n *\n * Operations:\n * - isLocal_timestamp -> l_t\n * - documentOid_timestamp -> d_t\n */\nasync function version2(db: IDBDatabase, tx: IDBTransaction) {\n\tconst operations = tx.objectStore('operations');\n\tawait new Promise<void>((resolve, reject) => {\n\t\tconst cursorReq = operations.openCursor();\n\t\tcursorReq.onsuccess = () => {\n\t\t\t// rename the consolidated fields\n\t\t\tconst cursor = cursorReq.result;\n\t\t\tif (cursor) {\n\t\t\t\tconst { isLocal_timestamp, documentOid_timestamp, ...value } =\n\t\t\t\t\tcursor.value;\n\t\t\t\tcursor.update({\n\t\t\t\t\t...value,\n\t\t\t\t\tl_t: isLocal_timestamp,\n\t\t\t\t\td_t: documentOid_timestamp,\n\t\t\t\t});\n\t\t\t\tcursor.continue();\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t};\n\t\tcursorReq.onerror = (event) => {\n\t\t\treject(cursorReq.error);\n\t\t};\n\t});\n\t// remove the old indexes\n\toperations.deleteIndex('isLocal_timestamp');\n\toperations.deleteIndex('documentOid_timestamp');\n\t// create the new indexes\n\toperations.createIndex('l_t', 'l_t', { unique: false });\n\toperations.createIndex('o_t', 'o_t', { unique: false });\n\toperations.createIndex('d_t', 'd_t', { unique: false });\n}\n\n/**\n * 2 -> 3 changes:\n *\n * Add timestamp index to operations\n */\nasync function version3(db: IDBDatabase, tx: IDBTransaction) {\n\tconst operations = tx.objectStore('operations');\n\toperations.createIndex('timestamp', 'timestamp');\n}\n\nasync function version4(db: IDBDatabase, tx: IDBTransaction) {\n\tconst files = db.createObjectStore('files', {\n\t\tkeyPath: 'id',\n\t});\n\tfiles.createIndex('remote', 'remote');\n\tfiles.createIndex('deletedAt', 'deletedAt');\n}\n\nasync function version5(db: IDBDatabase, tx: IDBTransaction) {\n\t// rewrites all baselines and operations to replace legacy OIDs\n\t// with new ones.\n\tconst operations = tx.objectStore('operations');\n\tawait new Promise<void>((resolve, reject) => {\n\t\tconst cursorReq = operations.openCursor();\n\t\tcursorReq.onsuccess = () => {\n\t\t\tconst cursor = cursorReq.result;\n\t\t\tif (cursor) {\n\t\t\t\tconst converted = replaceLegacyOidsInObject(cursor.value);\n\t\t\t\t// conversion may change the primary key, so we need to put the\n\t\t\t\t// object back to the store\n\t\t\t\tif (converted.oid_timestamp !== cursor.primaryKey) {\n\t\t\t\t\tcursor.delete();\n\t\t\t\t\toperations.put(converted);\n\t\t\t\t} else {\n\t\t\t\t\tcursor.update(converted);\n\t\t\t\t}\n\t\t\t\tcursor.continue();\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t};\n\t\tcursorReq.onerror = (event) => {\n\t\t\treject(cursorReq.error);\n\t\t};\n\t});\n\tconst baselines = tx.objectStore('baselines');\n\tawait new Promise<void>((resolve, reject) => {\n\t\tconst cursorReq = baselines.openCursor();\n\t\tcursorReq.onsuccess = () => {\n\t\t\tconst cursor = cursorReq.result;\n\t\t\tif (cursor) {\n\t\t\t\tconst converted = replaceLegacyOidsInObject(cursor.value);\n\t\t\t\tif (converted.oid !== cursor.primaryKey) {\n\t\t\t\t\tcursor.delete();\n\t\t\t\t\tbaselines.put(converted);\n\t\t\t\t} else {\n\t\t\t\t\tcursor.update(converted);\n\t\t\t\t}\n\t\t\t\tcursor.continue();\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t};\n\t\tcursorReq.onerror = (event) => {\n\t\t\treject(cursorReq.error);\n\t\t};\n\t});\n}\n\n// version 5->6: add timestamp to file metadata\nasync function version6(db: IDBDatabase, tx: IDBTransaction) {\n\tconst files = tx.objectStore('files');\n\tfiles.createIndex('timestamp', 'timestamp');\n}\n", "import { closeDatabase, globalIDB, storeRequestPromise } from '../idb.js';\nimport { OpenDocumentDbContext } from './types.js';\n\nexport async function getDatabaseVersion(\n\tindexedDB: IDBFactory,\n\tnamespace: string,\n\tversion: number,\n\tlog?: (...args: any[]) => void,\n): Promise<number> {\n\tfunction openAndGetVersion(\n\t\tresolve: (res: [number, IDBDatabase]) => void,\n\t\treject: (err: Error) => void,\n\t) {\n\t\tlet currentVersion: number;\n\t\tlet database: IDBDatabase;\n\t\tconst request = indexedDB.open(\n\t\t\t[namespace, 'collections'].join('_'),\n\t\t\tversion,\n\t\t);\n\t\trequest.onupgradeneeded = async (event) => {\n\t\t\tcurrentVersion = event.oldVersion;\n\t\t\tconst transaction = request.transaction!;\n\t\t\tdatabase = request.result;\n\t\t\ttransaction.abort();\n\t\t};\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve([request.result.version, request.result]);\n\t\t};\n\t\trequest.onblocked = (event) => {\n\t\t\t// retry if blocked\n\t\t\tlog?.('Database blocked, waiting...');\n\t\t\t// setTimeout(() => {\n\t\t\t// \topenAndGetVersion(resolve, reject);\n\t\t\t// }, 200);\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\t// FIXME: this fails if the code is older than the local database\n\t\t\tresolve([currentVersion!, database!]);\n\t\t};\n\t}\n\tconst [currentVersion, db] = await new Promise<[number, IDBDatabase]>(\n\t\topenAndGetVersion,\n\t);\n\tawait closeDatabase(db);\n\treturn currentVersion;\n}\n\n/**\n * Upgrades the database to the given version, using the given upgrader function.\n */\nexport async function upgradeDatabase(\n\tindexedDb: IDBFactory,\n\tnamespace: string,\n\tversion: number,\n\tupgrader: (\n\t\ttransaction: IDBTransaction,\n\t\tdb: IDBDatabase,\n\t\tevent: IDBVersionChangeEvent,\n\t) => void,\n\tlog?: (...args: any[]) => void,\n): Promise<IDBDatabase> {\n\tfunction openAndUpgrade(\n\t\tresolve: (db: IDBDatabase) => void,\n\t\treject: (err: Error) => void,\n\t) {\n\t\tconst request = indexedDb.open(\n\t\t\t[namespace, 'collections'].join('_'),\n\t\t\tversion,\n\t\t);\n\t\tlet wasUpgraded = false;\n\t\trequest.onupgradeneeded = (event) => {\n\t\t\tconst transaction = request.transaction!;\n\t\t\tupgrader(transaction, request.result, event);\n\t\t\twasUpgraded = true;\n\t\t};\n\t\trequest.onsuccess = (event) => {\n\t\t\tif (wasUpgraded) {\n\t\t\t\tresolve(request.result);\n\t\t\t} else {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t'Database was not upgraded when a version change was expected',\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(request.error || new Error('Unknown error'));\n\t\t};\n\t\trequest.onblocked = (event) => {\n\t\t\tlog?.('Database upgrade blocked, waiting...');\n\t\t\t// setTimeout(() => {\n\t\t\t// \topenAndUpgrade(resolve, reject);\n\t\t\t// }, 200);\n\t\t};\n\t}\n\treturn new Promise<IDBDatabase>(openAndUpgrade);\n}\n\nexport async function acquireLock(\n\tnamespace: string,\n\tprocedure: () => Promise<void>,\n) {\n\tif (typeof navigator !== 'undefined' && navigator.locks) {\n\t\tawait navigator.locks.request(`verdant_migration_${namespace}`, procedure);\n\t} else {\n\t\t// TODO: is there a fallback?\n\t\tawait procedure();\n\t}\n}\n\nexport async function openDatabase({\n\tindexedDB = globalIDB,\n\tnamespace,\n\tversion,\n\tcontext,\n}: {\n\tindexedDB?: IDBFactory;\n\tnamespace: string;\n\tversion: number;\n\tcontext: OpenDocumentDbContext;\n}): Promise<IDBDatabase> {\n\tcontext.log('debug', 'Opening database', namespace, 'at version', version);\n\tconst db = await new Promise<IDBDatabase>((resolve, reject) => {\n\t\tconst request = indexedDB.open(\n\t\t\t[namespace, 'collections'].join('_'),\n\t\t\tversion,\n\t\t);\n\t\trequest.onupgradeneeded = async (event) => {\n\t\t\tconst transaction = request.transaction!;\n\t\t\ttransaction.abort();\n\n\t\t\tcontext.log(\n\t\t\t\t'error',\n\t\t\t\t'Database upgrade needed, but not expected',\n\t\t\t\t'Expected',\n\t\t\t\tversion,\n\t\t\t\t'Got',\n\t\t\t\trequest.result.version,\n\t\t\t);\n\t\t\treject(\n\t\t\t\trequest.error ||\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t`Migration error: database version changed unexpectedly when reading current data. Expected ${version}, got ${request.result.version}`,\n\t\t\t\t\t),\n\t\t\t);\n\t\t};\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve(request.result);\n\t\t};\n\t\trequest.onblocked = (event) => {\n\t\t\treject(new Error('Migration error: database blocked'));\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(new Error('Migration error: database error'));\n\t\t};\n\t});\n\n\tdb.addEventListener('versionchange', (event) => {\n\t\tdb.close();\n\t});\n\n\treturn db;\n}\n\nexport async function copyAll(\n\tsourceDatabase: IDBDatabase,\n\ttargetDatabase: IDBDatabase,\n) {\n\t// DOMStringList... doesn't have iterable... why\n\tconst sourceStoreNames = new Array<string>();\n\tfor (let i = 0; i < sourceDatabase.objectStoreNames.length; i++) {\n\t\tsourceStoreNames.push(sourceDatabase.objectStoreNames[i]);\n\t}\n\n\tconst copyFromTransaction = sourceDatabase.transaction(\n\t\tsourceStoreNames,\n\t\t'readonly',\n\t);\n\tconst copyFromStores = sourceStoreNames.map((name) =>\n\t\tcopyFromTransaction.objectStore(name),\n\t);\n\tconst allObjects = await Promise.all(\n\t\tcopyFromStores.map((store) => storeRequestPromise(store.getAll())),\n\t);\n\n\tconst copyToTransaction = targetDatabase.transaction(\n\t\tsourceStoreNames,\n\t\t'readwrite',\n\t);\n\tconst copyToStores = sourceStoreNames.map((name) =>\n\t\tcopyToTransaction.objectStore(name),\n\t);\n\n\tfor (let i = 0; i < copyToStores.length; i++) {\n\t\tawait Promise.all(\n\t\t\tallObjects[i].map((obj) => {\n\t\t\t\treturn storeRequestPromise(copyToStores[i].put(obj));\n\t\t\t}),\n\t\t);\n\t}\n}\n", "import {\n\tassert,\n\tCollectionCompoundIndexFilter,\n\tCollectionFilter,\n\tcreateCompoundIndexValue,\n\tcreateLowerBoundIndexValue,\n\tcreateUpperBoundIndexValue,\n\tisMatchIndexFilter,\n\tisRangeIndexFilter,\n\tisSortIndexFilter,\n\tisStartsWithIndexFilter,\n\tMatchCollectionIndexFilter,\n\tRangeCollectionIndexFilter,\n\tsanitizeIndexValue,\n\tSortIndexFilter,\n\tStartsWithIndexFilter,\n\tStorageSchema,\n} from '@verdant-web/common';\n\nconst matchIndexToIdbKeyRange = (filter: MatchCollectionIndexFilter) => {\n\treturn IDBKeyRange.only(sanitizeIndexValue(filter.equals));\n};\n\nconst sortIndexToIdbKeyRange = (filter: SortIndexFilter) => {\n\treturn undefined;\n};\n\nconst rangeIndexToIdbKeyRange = (filter: RangeCollectionIndexFilter) => {\n\tconst lower = filter.gte || filter.gt;\n\tconst upper = filter.lte || filter.lt;\n\tif (lower === upper) {\n\t\treturn IDBKeyRange.only(sanitizeIndexValue(lower));\n\t}\n\tif (!lower) {\n\t\treturn IDBKeyRange.upperBound(sanitizeIndexValue(upper), !!filter.lt);\n\t} else if (!upper) {\n\t\treturn IDBKeyRange.lowerBound(sanitizeIndexValue(lower), !!filter.gt);\n\t} else {\n\t\treturn IDBKeyRange.bound(\n\t\t\tsanitizeIndexValue(lower),\n\t\t\tsanitizeIndexValue(upper),\n\t\t\t!!filter.gt,\n\t\t\t!!filter.lt,\n\t\t);\n\t}\n};\n\nconst compoundIndexToIdbKeyRange = (\n\t// FIXME:\n\tschema: any,\n\tcollection: string,\n\tfilter: CollectionCompoundIndexFilter,\n) => {\n\t// validate the usage of the compound index:\n\t// - all match fields must be contiguous at the start of the compound order\n\tconst indexDefinition =\n\t\tschema.collections[collection].compounds[filter.where];\n\tassert(\n\t\tindexDefinition,\n\t\t`Index ${filter.where} does not exist on collection ${collection}`,\n\t);\n\tconst matchedKeys = Object.keys(filter.match).sort(\n\t\t(a, b) => indexDefinition.of.indexOf(a) - indexDefinition.of.indexOf(b),\n\t);\n\tfor (const key of matchedKeys) {\n\t\tif (indexDefinition.of.indexOf(key) !== matchedKeys.indexOf(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Compound index ${filter.where} does not have ${key} at the start of its order`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst matchedValues = matchedKeys.map(\n\t\t(key) => filter.match[key as keyof typeof filter.match] as string | number,\n\t);\n\n\t// special case: all match fields are specified - we don't need a range\n\t// query, just a single key query\n\tif (matchedKeys.length === indexDefinition.of.length) {\n\t\treturn IDBKeyRange.only(createCompoundIndexValue(...matchedValues));\n\t}\n\n\t// create our bounds for the matched values\n\tconst lower = createLowerBoundIndexValue(...matchedValues);\n\tconst upper = createUpperBoundIndexValue(...matchedValues);\n\treturn IDBKeyRange.bound(lower, upper);\n};\n\nfunction startsWithIndexToIdbKeyRange(filter: StartsWithIndexFilter) {\n\tconst lower = filter.startsWith;\n\tconst upper = filter.startsWith + '\\uffff';\n\treturn IDBKeyRange.bound(lower, upper);\n}\n\nexport function getRange(\n\tschema: StorageSchema,\n\tcollection: string,\n\tindex?: CollectionFilter,\n) {\n\tif (!index) return undefined;\n\tif (isRangeIndexFilter(index)) return rangeIndexToIdbKeyRange(index);\n\tif (isMatchIndexFilter(index)) return matchIndexToIdbKeyRange(index);\n\tif (isSortIndexFilter(index)) return sortIndexToIdbKeyRange(index);\n\tif (isStartsWithIndexFilter(index))\n\t\treturn startsWithIndexToIdbKeyRange(index);\n\treturn compoundIndexToIdbKeyRange(schema, collection, index);\n}\n", "import { CollectionFilter, createOid } from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { getRange } from './ranges.js';\nimport { isAbortError } from '../idb.js';\n\nfunction getStore(db: IDBDatabase, collection: string, write?: boolean) {\n\treturn db\n\t\t.transaction(collection, write ? 'readwrite' : 'readonly')\n\t\t.objectStore(collection);\n}\n\nexport async function findOneOid({\n\tcollection,\n\tindex,\n\tcontext,\n}: {\n\tcollection: string;\n\tindex?: CollectionFilter;\n\tcontext: Context;\n}) {\n\tconst store = getStore(context.documentDb, collection);\n\tconst source = index?.where ? store.index(index.where) : store;\n\tconst range = getRange(context.schema, collection, index);\n\tconst direction = index?.order === 'desc' ? 'prev' : 'next';\n\tconst request = source.openCursor(range, direction);\n\tconst result = await new Promise<string | null>((resolve, reject) => {\n\t\trequest.onsuccess = () => {\n\t\t\tconst cursor = request.result;\n\t\t\tif (cursor) {\n\t\t\t\tresolve(createOid(collection, cursor.primaryKey.toString()));\n\t\t\t} else {\n\t\t\t\tresolve(null);\n\t\t\t}\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error?.name === 'InvalidStateError') {\n\t\t\t\tcontext.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`findOne query failed with InvalidStateError`,\n\t\t\t\t\trequest.error,\n\t\t\t\t);\n\t\t\t\tresolve(null);\n\t\t\t} else if (isAbortError(request.error)) {\n\t\t\t\tresolve(null);\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n\treturn result;\n}\n\nexport async function findAllOids({\n\tcollection,\n\tindex,\n\tcontext,\n}: {\n\tcollection: string;\n\tindex?: CollectionFilter;\n\tcontext: Context;\n}) {\n\tconst store = getStore(context.documentDb, collection);\n\tconst source = index?.where ? store.index(index.where) : store;\n\tconst range = getRange(context.schema, collection, index);\n\tconst direction = index?.order === 'desc' ? 'prev' : 'next';\n\tconst request = source.openCursor(range, direction);\n\tconst result = await new Promise<string[]>((resolve, reject) => {\n\t\tconst results = new Set<string>();\n\t\trequest.onsuccess = () => {\n\t\t\tconst cursor = request.result;\n\t\t\tif (cursor) {\n\t\t\t\tresults.add(createOid(collection, cursor.primaryKey.toString()));\n\t\t\t\tcursor.continue();\n\t\t\t} else {\n\t\t\t\tresolve(Array.from(results));\n\t\t\t}\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error?.name === 'InvalidStateError') {\n\t\t\t\tcontext.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`findAll query failed with InvalidStateError`,\n\t\t\t\t\trequest.error,\n\t\t\t\t);\n\t\t\t\tresolve([]);\n\t\t\t} else if (isAbortError(request.error)) {\n\t\t\t\tresolve([]);\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n\treturn result;\n}\n\nexport async function findPageOfOids({\n\tcollection,\n\tindex,\n\tcontext,\n\tlimit,\n\toffset,\n}: {\n\tcollection: string;\n\tindex?: CollectionFilter;\n\tcontext: Context;\n\tlimit?: number;\n\toffset?: number;\n}) {\n\tconst store = getStore(context.documentDb, collection);\n\tconst source = index?.where ? store.index(index.where) : store;\n\tconst range = getRange(context.schema, collection, index);\n\tconst direction = index?.order === 'desc' ? 'prev' : 'next';\n\tconst request = source.openCursor(range, direction);\n\tlet hasDoneOffset = !offset;\n\tlet hasNextPage = false;\n\tlet visited = 0;\n\tconst result = await new Promise<string[]>((resolve, reject) => {\n\t\tconst results = new Set<string>();\n\t\trequest.onsuccess = () => {\n\t\t\tvisited++;\n\t\t\tconst cursor = request.result;\n\t\t\tif (cursor) {\n\t\t\t\tif (offset && !hasDoneOffset) {\n\t\t\t\t\tcursor.advance(offset);\n\t\t\t\t\thasDoneOffset = true;\n\t\t\t\t} else {\n\t\t\t\t\tif (limit && results.size < limit) {\n\t\t\t\t\t\tresults.add(createOid(collection, cursor.primaryKey.toString()));\n\t\t\t\t\t}\n\t\t\t\t\tif (limit && visited > limit) {\n\t\t\t\t\t\thasNextPage = true;\n\t\t\t\t\t\tresolve(Array.from(results));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcursor.continue();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tresolve(Array.from(results));\n\t\t\t}\n\t\t};\n\t\trequest.onerror = () => {\n\t\t\tif (request.error?.name === 'InvalidStateError') {\n\t\t\t\tcontext.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`find query failed with InvalidStateError`,\n\t\t\t\t\trequest.error,\n\t\t\t\t);\n\t\t\t\tresolve([]);\n\t\t\t} else if (isAbortError(request.error)) {\n\t\t\t\tresolve([]);\n\t\t\t} else {\n\t\t\t\treject(request.error);\n\t\t\t}\n\t\t};\n\t});\n\n\treturn {\n\t\tresult: result as string[],\n\t\thasNextPage,\n\t};\n}\n", "import {\n\tCollectionFilter,\n\tMigration,\n\tMigrationEngine,\n\tObjectIdentifier,\n\taddFieldDefaults,\n\tassert,\n\tassignOidsToAllSubObjects,\n\tcloneDeep,\n\tcreateOid,\n\tdiffToPatches,\n\tgetOid,\n\tinitialToPatches,\n\tremoveOidPropertiesFromAllSubObjects,\n\tAuthorizationKey,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { findAllOids, findOneOid } from '../queries/dbQueries.js';\nimport { OpenDocumentDbContext } from './types.js';\n\nfunction getMigrationMutations({\n\tmigration,\n\tmeta,\n\tgetMigrationNow,\n\tnewOids,\n}: {\n\tmigration: Migration<any>;\n\tnewOids: string[];\n\tgetMigrationNow: () => string;\n\tmeta: Metadata;\n}) {\n\treturn migration.allCollections.reduce((acc, collectionName) => {\n\t\tacc[collectionName] = {\n\t\t\tput: async (doc: any, options?: { access?: AuthorizationKey }) => {\n\t\t\t\t// add defaults\n\t\t\t\taddFieldDefaults(migration.newSchema.collections[collectionName], doc);\n\t\t\t\tconst primaryKey =\n\t\t\t\t\tdoc[migration.newSchema.collections[collectionName].primaryKey];\n\t\t\t\tconst oid = createOid(collectionName, primaryKey);\n\t\t\t\tnewOids.push(oid);\n\n\t\t\t\tawait meta.insertLocalOperations(\n\t\t\t\t\tinitialToPatches(doc, oid, getMigrationNow, undefined, undefined, {\n\t\t\t\t\t\tauthz: options?.access,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\treturn doc;\n\t\t\t},\n\t\t\tdelete: async (id: string) => {\n\t\t\t\tconst rootOid = createOid(collectionName, id);\n\t\t\t\tconst authz = await meta.getDocumentAuthz(rootOid);\n\t\t\t\tconst allOids = await meta.getAllDocumentRelatedOids(rootOid);\n\t\t\t\treturn meta.insertLocalOperations(\n\t\t\t\t\tallOids.map((oid) => ({\n\t\t\t\t\t\toid,\n\t\t\t\t\t\ttimestamp: getMigrationNow(),\n\t\t\t\t\t\tdata: { op: 'delete' },\n\t\t\t\t\t\tauthz,\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t\treturn acc;\n\t}, {} as any);\n}\n\nfunction getMigrationQueries({\n\tmigration,\n\tcontext,\n\tmeta,\n}: {\n\tmigration: Migration<any>;\n\tcontext: Context;\n\tmeta: Metadata;\n}) {\n\treturn migration.oldCollections.reduce((acc, collectionName) => {\n\t\tacc[collectionName] = {\n\t\t\tget: async (id: string) => {\n\t\t\t\tconst oid = createOid(collectionName, id);\n\t\t\t\tconst doc = await meta.getDocumentSnapshot(oid, {\n\t\t\t\t\t// only get the snapshot up to the previous version (newer operations may have synced)\n\t\t\t\t\tto: meta.time.now(migration.oldSchema.version),\n\t\t\t\t});\n\t\t\t\treturn doc;\n\t\t\t},\n\t\t\tfindOne: async (filter: CollectionFilter) => {\n\t\t\t\tconst oid = await findOneOid({\n\t\t\t\t\tcollection: collectionName,\n\t\t\t\t\tindex: filter,\n\t\t\t\t\tcontext,\n\t\t\t\t});\n\t\t\t\tif (!oid) return null;\n\t\t\t\tconst doc = await meta.getDocumentSnapshot(oid, {\n\t\t\t\t\t// only get the snapshot up to the previous version (newer operations may have synced)\n\t\t\t\t\tto: meta.time.now(migration.oldSchema.version),\n\t\t\t\t});\n\t\t\t\treturn doc;\n\t\t\t},\n\t\t\tfindAll: async (filter: CollectionFilter) => {\n\t\t\t\tconst oids = await findAllOids({\n\t\t\t\t\tcollection: collectionName,\n\t\t\t\t\tindex: filter,\n\t\t\t\t\tcontext,\n\t\t\t\t});\n\t\t\t\tconst docs = await Promise.all(\n\t\t\t\t\toids.map((oid) =>\n\t\t\t\t\t\tmeta.getDocumentSnapshot(oid, {\n\t\t\t\t\t\t\t// only get the snapshot up to the previous version (newer operations may have synced)\n\t\t\t\t\t\t\tto: meta.time.now(migration.oldSchema.version),\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn docs;\n\t\t\t},\n\t\t};\n\t\treturn acc;\n\t}, {} as any);\n}\n\nexport function getMigrationEngine({\n\tmeta,\n\tmigration,\n\tcontext,\n}: {\n\tlog?: (...args: any[]) => void;\n\tmigration: Migration;\n\tmeta: Metadata;\n\tcontext: Context;\n}): MigrationEngine {\n\tfunction getMigrationNow() {\n\t\treturn meta.time.zero(migration.version);\n\t}\n\n\tconst newOids = new Array<ObjectIdentifier>();\n\n\tconst queries = getMigrationQueries({\n\t\tmigration,\n\t\tcontext,\n\t\tmeta,\n\t});\n\tconst mutations = getMigrationMutations({\n\t\tmigration,\n\t\tgetMigrationNow,\n\t\tnewOids,\n\t\tmeta,\n\t});\n\tconst deleteCollection = async (collection: string) => {\n\t\tconst allOids = await meta.getAllCollectionRelatedOids(collection);\n\t\treturn meta.insertLocalOperations(\n\t\t\tallOids.map((oid) => ({\n\t\t\t\toid,\n\t\t\t\ttimestamp: getMigrationNow(),\n\t\t\t\tdata: { op: 'delete' },\n\t\t\t})),\n\t\t);\n\t};\n\tconst awaitables = new Array<Promise<any>>();\n\tconst engine: MigrationEngine = {\n\t\tlog: context.log,\n\t\tnewOids,\n\t\tdeleteCollection,\n\t\tmigrate: async (collection, strategy) => {\n\t\t\tconst docs = await queries[collection].findAll();\n\n\t\t\tawait Promise.all(\n\t\t\t\tdocs.filter(Boolean).map(async (doc: any) => {\n\t\t\t\t\tconst rootOid = getOid(doc);\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!!rootOid,\n\t\t\t\t\t\t`Document is missing an OID: ${JSON.stringify(doc)}`,\n\t\t\t\t\t);\n\t\t\t\t\t// FIXME: this could be optimized (making n queries for authz\n\t\t\t\t\t// when the snapshots themselves are derived from the same data...)\n\t\t\t\t\t// maybe don't use the findAll query, and instead go a level\n\t\t\t\t\t// lower to retain access to lower level data here?\n\t\t\t\t\tconst authz = await meta.getDocumentAuthz(rootOid);\n\t\t\t\t\tconst original = cloneDeep(doc);\n\t\t\t\t\t// @ts-ignore - excessive type resolution\n\t\t\t\t\tconst newValue = await strategy(doc);\n\t\t\t\t\tif (newValue) {\n\t\t\t\t\t\t// the migration has altered the shape of our document. we need\n\t\t\t\t\t\t// to create the operation from the diff and write it to meta as\n\t\t\t\t\t\t// a migration patch\n\t\t\t\t\t\tremoveOidPropertiesFromAllSubObjects(original);\n\t\t\t\t\t\tremoveOidPropertiesFromAllSubObjects(newValue);\n\t\t\t\t\t\tassignOidsToAllSubObjects(newValue);\n\t\t\t\t\t\tconst patches = diffToPatches(\n\t\t\t\t\t\t\toriginal,\n\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\tgetMigrationNow,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmergeUnknownObjects: true,\n\t\t\t\t\t\t\t\tauthz,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (patches.length > 0) {\n\t\t\t\t\t\t\tawait meta.insertLocalOperations(patches);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tqueries,\n\t\tmutations,\n\t\tawaitables,\n\t};\n\treturn engine;\n}\n\nexport function getInitialMigrationEngine({\n\tmeta,\n\tmigration,\n\tcontext,\n}: {\n\tcontext: OpenDocumentDbContext;\n\tmigration: Migration;\n\tmeta: Metadata;\n}): MigrationEngine {\n\tfunction getMigrationNow() {\n\t\treturn meta.time.zero(migration.version);\n\t}\n\n\tconst newOids = new Array<ObjectIdentifier>();\n\n\tconst queries = new Proxy({} as any, {\n\t\tget() {\n\t\t\tthrow new Error(\n\t\t\t\t'Queries are not available in initial migrations; there is no database yet!',\n\t\t\t);\n\t\t},\n\t}) as any;\n\n\tconst mutations = getMigrationMutations({\n\t\tmigration,\n\t\tgetMigrationNow,\n\t\tnewOids,\n\t\tmeta,\n\t});\n\tconst engine: MigrationEngine = {\n\t\tlog: context.log,\n\t\tnewOids,\n\t\tdeleteCollection: () => {\n\t\t\tthrow new Error(\n\t\t\t\t'Calling deleteCollection() in initial migrations is not supported! Use initial migrations to seed initial data using mutations.',\n\t\t\t);\n\t\t},\n\t\tmigrate: () => {\n\t\t\tthrow new Error(\n\t\t\t\t'Calling migrate() in initial migrations is not supported! Use initial migrations to seed initial data using mutations.',\n\t\t\t);\n\t\t},\n\t\tqueries,\n\t\tmutations,\n\t\tawaitables: [],\n\t};\n\treturn engine;\n}\n", "import {\n\tMigration,\n\tMigrationEngine,\n\tcreateOid,\n\tdecomposeOid,\n\tgetIndexValues,\n\tgetOidRoot,\n} from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { ClientOperation } from '../metadata/OperationsStore.js';\nimport { acquireLock, openDatabase, upgradeDatabase } from './db.js';\nimport { getInitialMigrationEngine, getMigrationEngine } from './engine.js';\nimport { OpenDocumentDbContext } from './types.js';\nimport { closeDatabase } from '../idb.js';\n\nconst globalIDB =\n\ttypeof window !== 'undefined' ? window.indexedDB : (undefined as any);\n\nexport async function runMigrations({\n\tcontext,\n\ttoRun,\n\tmeta,\n\tindexedDB = globalIDB,\n\tnamespace = context.namespace,\n}: {\n\tcontext: OpenDocumentDbContext;\n\ttoRun: Migration<any>[];\n\tmeta: Metadata;\n\tindexedDB?: IDBFactory;\n\t/** This namespace value controls where the database being migrated is. */\n\tnamespace?: string;\n}) {\n\tawait acquireLock(namespace, async () => {\n\t\t// now the fun part\n\t\tfor (const migration of toRun) {\n\t\t\t// special case: if this is the version 1 migration, we have no pre-existing database\n\t\t\t// to use for the migration.\n\t\t\tlet engine: MigrationEngine;\n\t\t\t// migrations from 0 (i.e. initial migrations) don't attempt to open an existing db\n\t\t\tif (migration.oldSchema.version === 0) {\n\t\t\t\tengine = getInitialMigrationEngine({\n\t\t\t\t\tmeta,\n\t\t\t\t\tmigration,\n\t\t\t\t\tcontext,\n\t\t\t\t});\n\t\t\t\tawait migration.migrate(engine);\n\t\t\t} else {\n\t\t\t\t// open the database with the current (old) version for this migration. this should\n\t\t\t\t// align with the database's current version.\n\t\t\t\tconst originalDatabase = await openDatabase({\n\t\t\t\t\tindexedDB,\n\t\t\t\t\tnamespace,\n\t\t\t\t\tversion: migration.oldSchema.version,\n\t\t\t\t\tcontext,\n\t\t\t\t});\n\n\t\t\t\t// this will only write to our metadata store via operations!\n\t\t\t\tengine = getMigrationEngine({\n\t\t\t\t\tmeta,\n\t\t\t\t\tmigration,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\t...context,\n\t\t\t\t\t\tdocumentDb: originalDatabase,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\ttry {\n\t\t\t\t\tawait migration.migrate(engine);\n\t\t\t\t\t// wait on any out-of-band async operations to complete\n\t\t\t\t\tawait Promise.all(engine.awaitables);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tcontext.log(\n\t\t\t\t\t\t'critical',\n\t\t\t\t\t\t`Migration failed (${migration.oldSchema.version} -> ${migration.newSchema.version})`,\n\t\t\t\t\t\terr,\n\t\t\t\t\t);\n\t\t\t\t\tif (err instanceof Error) {\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('Unknown error during migration');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// now we have to open the database again with the next version and\n\t\t\t\t// make the appropriate schema changes during the upgrade.\n\t\t\t\tawait closeDatabase(originalDatabase);\n\t\t\t}\n\n\t\t\tcontext.log(\n\t\t\t\t'debug',\n\t\t\t\t'Upgrading database',\n\t\t\t\tnamespace,\n\t\t\t\t'to version',\n\t\t\t\tmigration.newSchema.version,\n\t\t\t);\n\t\t\tconst upgradedDatabase = await applySchemaToDatabase({\n\t\t\t\tmigration,\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace,\n\t\t\t\tcontext,\n\t\t\t});\n\n\t\t\t/**\n\t\t\t * In cases where operations from the future have been\n\t\t\t * received by this client, we may have created entire\n\t\t\t * documents in metadata which were not written to storage\n\t\t\t * because all of their operations were in the future (\n\t\t\t * i.e. in the next version). We have to find those documents\n\t\t\t * and also write their snapshots to storage, because they\n\t\t\t * won't be present in storage already to 'refresh,' so\n\t\t\t * if we don't analyze metadata for 'future' operations like\n\t\t\t * this, we won't know they exist.\n\t\t\t *\n\t\t\t * This led to behavior where the metadata would be properly\n\t\t\t * synced, but after upgrading the app and migrating, items\n\t\t\t * would be missing from findAll and findOne queries.\n\t\t\t */\n\t\t\tconst docsWithUnappliedMigrations = await getDocsWithUnappliedMigrations({\n\t\t\t\tmeta,\n\t\t\t\tcurrentVersion: migration.oldSchema.version,\n\t\t\t\tnewVersion: migration.newSchema.version,\n\t\t\t});\n\n\t\t\t// once the schema is ready, we can write back the migrated documents\n\n\t\t\tfor (const collection of migration.allCollections) {\n\t\t\t\t// first step is to read in all the keys we need to rewrite\n\t\t\t\tconst documentReadTransaction = upgradedDatabase.transaction(\n\t\t\t\t\tcollection,\n\t\t\t\t\t'readwrite',\n\t\t\t\t);\n\t\t\t\tconst readStore = documentReadTransaction.objectStore(collection);\n\t\t\t\tconst keys = await getAllKeys(readStore);\n\t\t\t\t// map the keys to OIDs\n\t\t\t\tconst oids = keys.map((key) => createOid(collection, `${key}`));\n\t\t\t\toids.push(\n\t\t\t\t\t...engine.newOids.filter((oid) => {\n\t\t\t\t\t\treturn decomposeOid(oid).collection === collection;\n\t\t\t\t\t}),\n\t\t\t\t\t...docsWithUnappliedMigrations.filter((oid) => {\n\t\t\t\t\t\treturn decomposeOid(oid).collection === collection;\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\t// add 'touch' operations to all root OIDs of all documents.\n\t\t\t\t// this marks documents which have undergone a migration\n\t\t\t\t// so that other clients know when they're working\n\t\t\t\t// with unmigrated data - by seeing that there are no\n\t\t\t\t// existing operations or baselines with a timestamp\n\t\t\t\t// that matches the current version.\n\t\t\t\t// UPDATE: no longer necessary now that pruning is a thing.\n\t\t\t\t// await Promise.all(\n\t\t\t\t// \toids.map((oid) =>\n\t\t\t\t// \t\tmeta.insertLocalOperations([\n\t\t\t\t// \t\t\t{\n\t\t\t\t// \t\t\t\toid,\n\t\t\t\t// \t\t\t\ttimestamp: meta.time.zero(migration.version),\n\t\t\t\t// \t\t\t\tdata: { op: 'touch' },\n\t\t\t\t// \t\t\t},\n\t\t\t\t// \t\t]),\n\t\t\t\t// \t),\n\t\t\t\t// );\n\n\t\t\t\tconst snapshots = await Promise.all(\n\t\t\t\t\toids.map(async (oid) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst snap = await meta.getDocumentSnapshot(oid);\n\t\t\t\t\t\t\treturn [oid, snap];\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t// this seems to happen with baselines/ops which are not fully\n\t\t\t\t\t\t\t// cleaned up after deletion?\n\t\t\t\t\t\t\tcontext.log(\n\t\t\t\t\t\t\t\t'error',\n\t\t\t\t\t\t\t\t'Could not regenerate snapshot during migration for oid',\n\t\t\t\t\t\t\t\toid,\n\t\t\t\t\t\t\t\t'this document will not be preserved',\n\t\t\t\t\t\t\t\te,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tconst views = snapshots\n\t\t\t\t\t.filter((s): s is [string, any] => !!s)\n\t\t\t\t\t.map(([oid, snapshot]) => {\n\t\t\t\t\t\tif (!snapshot) return [oid, undefined];\n\t\t\t\t\t\tconst view = getIndexValues(\n\t\t\t\t\t\t\tmigration.newSchema.collections[collection],\n\t\t\t\t\t\t\tsnapshot,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn [oid, view];\n\t\t\t\t\t});\n\n\t\t\t\t// now we can write the documents back\n\t\t\t\tconst documentWriteTransaction = upgradedDatabase.transaction(\n\t\t\t\t\tcollection,\n\t\t\t\t\t'readwrite',\n\t\t\t\t);\n\t\t\t\tconst writeStore = documentWriteTransaction.objectStore(collection);\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tviews.map(([oid, view]) => {\n\t\t\t\t\t\tif (view) {\n\t\t\t\t\t\t\treturn putView(writeStore, view);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst { id } = decomposeOid(oid);\n\t\t\t\t\t\t\treturn deleteView(writeStore, id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tawait closeDatabase(upgradedDatabase);\n\n\t\t\tcontext.log('debug', `Migration of ${namespace} complete.`);\n\t\t\tcontext.log(\n\t\t\t\t'info',\n\t\t\t\t`\n\t\t\t\t\u2B06\uFE0F v${migration.newSchema.version} Migration complete. Here's the rundown:\n\t\t\t\t\t- Added collections: ${migration.addedCollections.join(', ')}\n\t\t\t\t\t- Removed collections: ${migration.removedCollections.join(', ')}\n\t\t\t\t\t- Changed collections: ${migration.changedCollections.join(', ')}\n\t\t\t\t\t- New indexes: ${Object.keys(migration.addedIndexes)\n\t\t\t\t\t\t.map((col) =>\n\t\t\t\t\t\t\tmigration.addedIndexes[col].map((i) => `${col}.${i.name}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.flatMap((i) => i)\n\t\t\t\t\t\t.join(', ')}\n\t\t\t\t\t- Removed indexes: ${Object.keys(migration.removedIndexes)\n\t\t\t\t\t\t.map((col) =>\n\t\t\t\t\t\t\tmigration.removedIndexes[col].map((i) => `${col}.${i.name}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.flatMap((i) => i)\n\t\t\t\t\t\t.join(', ')}\n\t\t\t`,\n\t\t\t);\n\t\t}\n\t});\n}\n\nasync function getAllKeys(store: IDBObjectStore) {\n\treturn new Promise<IDBValidKey[]>((resolve, reject) => {\n\t\tconst request = store.getAllKeys();\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve(request.result);\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(request.error);\n\t\t};\n\t});\n}\n\nasync function deleteView(store: IDBObjectStore, id: string) {\n\tconst request = store.delete(id);\n\treturn new Promise<void>((resolve, reject) => {\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve();\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(request.error);\n\t\t};\n\t});\n}\n\nasync function putView(store: IDBObjectStore, view: any) {\n\tconst request = store.put(view);\n\treturn new Promise<void>((resolve, reject) => {\n\t\trequest.onsuccess = (event) => {\n\t\t\tresolve();\n\t\t};\n\t\trequest.onerror = (event) => {\n\t\t\treject(request.error);\n\t\t};\n\t});\n}\n\n/**\n * Gets a list of root OIDs for all documents which had operations stored already\n * that were not applied to their queryable snapshots because they were in the\n * future. These documents need to be refreshed in storage.\n */\nasync function getDocsWithUnappliedMigrations({\n\tmeta,\n\tcurrentVersion,\n\tnewVersion: _,\n}: {\n\tcurrentVersion: number;\n\tnewVersion: number;\n\tmeta: Metadata;\n}) {\n\t// scan for all operations in metadata after the current version.\n\t// this could be more efficient if also filtering below or equal newVersion but\n\t// that seems so unlikely in practice...\n\tconst unappliedOperations: ClientOperation[] = [];\n\tawait meta.operations.iterateOverAllOperations(\n\t\t(op) => unappliedOperations.push(op),\n\t\t{\n\t\t\tfrom: meta.time.zero(currentVersion + 1),\n\t\t},\n\t);\n\treturn Array.from(\n\t\tnew Set(unappliedOperations.map((op) => getOidRoot(op.oid))),\n\t);\n}\n\nexport function applySchemaToDatabase({\n\tmigration,\n\tindexedDB = globalIDB,\n\tnamespace,\n\tcontext,\n}: {\n\tmigration: Migration<any>;\n\tindexedDB?: IDBFactory;\n\tnamespace: string;\n\tcontext: OpenDocumentDbContext;\n}) {\n\treturn upgradeDatabase(\n\t\tindexedDB,\n\t\tnamespace,\n\t\tmigration.newSchema.version,\n\t\t(transaction, db) => {\n\t\t\tfor (const newCollection of migration.addedCollections) {\n\t\t\t\tdb.createObjectStore(newCollection, {\n\t\t\t\t\tkeyPath: migration.newSchema.collections[newCollection].primaryKey,\n\t\t\t\t\tautoIncrement: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tfor (const collection of migration.allCollections) {\n\t\t\t\tconst store = transaction.objectStore(collection);\n\t\t\t\t// apply new indexes\n\t\t\t\tfor (const newIndex of migration.addedIndexes[collection] || []) {\n\t\t\t\t\tstore.createIndex(newIndex.name, newIndex.name, {\n\t\t\t\t\t\tmultiEntry: newIndex.multiEntry,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\t// remove old indexes\n\t\t\t\tfor (const oldIndex of migration.removedIndexes[collection] || []) {\n\t\t\t\t\tstore.deleteIndex(oldIndex.name);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const removedCollection of migration.removedCollections) {\n\t\t\t\t// !! can't delete the store, because old operations that relate to\n\t\t\t\t// this store may still exist in history. instead, we can clear it out\n\t\t\t\t// and leave it in place\n\t\t\t\ttransaction.objectStore(removedCollection).clear();\n\t\t\t}\n\t\t},\n\t\tcontext.log,\n\t);\n}\n", "export class MigrationPathError extends Error {\n\treadonly name = 'MigrationPathError';\n\n\tconstructor(public readonly message: string) {\n\t\tsuper(message);\n\t}\n}\n", "import { Migration } from '@verdant-web/common';\nimport { MigrationPathError } from './errors.js';\n\nexport function getMigrationPath({\n\tcurrentVersion,\n\ttargetVersion,\n\tmigrations,\n}: {\n\tcurrentVersion: number;\n\ttargetVersion: number;\n\tmigrations: Migration[];\n}) {\n\tconst path = getNextPathStep({\n\t\tcurrentVersion,\n\t\ttargetVersion,\n\t\tmigrations,\n\t});\n\tif (!path) {\n\t\tthrow new MigrationPathError(\n\t\t\t`No migration path found from ${currentVersion} to ${targetVersion}! This is a bug. If you're seeing this, contact the developer and provide them with the full contents of this message.`,\n\t\t);\n\t}\n\treturn path;\n}\n\nfunction getNextPathStep({\n\tcurrentVersion,\n\ttargetVersion,\n\tmigrations,\n}: {\n\tcurrentVersion: number;\n\ttargetVersion: number;\n\tmigrations: Migration[];\n}): Migration[] | null {\n\tif (currentVersion === targetVersion) {\n\t\treturn [];\n\t}\n\n\tconst fromHere = migrations\n\t\t.filter((m) => m.oldSchema.version === currentVersion)\n\t\t.sort((a, b) => b.newSchema.version - a.newSchema.version);\n\n\t// keep trying next steps, starting from the largest step,\n\t// until we find one that leads to the target version down the line\n\twhile (fromHere.length > 0) {\n\t\tconst next = fromHere.shift()!;\n\t\t// this one goes too far (probably never relevant, but still)\n\t\tif (next.newSchema.version > targetVersion) {\n\t\t\treturn null;\n\t\t}\n\t\t// exact match - we're done, return the path\n\t\tif (next.newSchema.version === targetVersion) {\n\t\t\treturn [next];\n\t\t}\n\t\t// look ahead a down the line. do we reach the target? if so,\n\t\t// we choose this path.\n\t\tconst nextPath = getNextPathStep({\n\t\t\tcurrentVersion: next.newSchema.version,\n\t\t\ttargetVersion,\n\t\t\tmigrations,\n\t\t});\n\t\tif (nextPath) {\n\t\t\treturn [next, ...nextPath];\n\t\t}\n\n\t\t// otherwise, try the next one with a smaller increment\n\t}\n\n\t// no paths from here match at all! if another layer is calling this one,\n\t// it will fallback to its next longest step. otherwise there may\n\t// be no paths at all...\n\treturn null;\n}\n", "import { Migration } from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { copyAll, getDatabaseVersion, openDatabase } from './db.js';\nimport { runMigrations } from './migrations.js';\nimport { getMigrationPath } from './paths.js';\nimport { OpenDocumentDbContext } from './types.js';\n\nconst globalIDB =\n\ttypeof window !== 'undefined' ? window.indexedDB : (undefined as any);\n\nexport async function openWIPDatabase({\n\tversion,\n\tindexedDB = globalIDB,\n\tmigrations,\n\tmeta,\n\tcontext,\n\twipNamespace,\n}: {\n\tversion: number;\n\tmigrations: Migration<any>[];\n\tindexedDB?: IDBFactory;\n\tmeta: Metadata;\n\tcontext: OpenDocumentDbContext;\n\twipNamespace: string;\n}) {\n\tcontext.log('debug', 'Opening WIP database', wipNamespace);\n\tconst currentWIPVersion = await getDatabaseVersion(\n\t\tindexedDB,\n\t\twipNamespace,\n\t\tversion,\n\t\tcontext.log,\n\t);\n\n\tif (currentWIPVersion === version) {\n\t\tcontext.log('info', `WIP schema is up-to-date; not refreshing database`);\n\t} else {\n\t\tcontext.log('info', `WIP schema is out-of-date; refreshing database`);\n\n\t\t// first we need to copy the data from the production database to the WIP database\n\t\t// at the current (non-wip) version.\n\n\t\tconst initialToRun = getMigrationPath({\n\t\t\tcurrentVersion: currentWIPVersion,\n\t\t\ttargetVersion: version - 1,\n\t\t\tmigrations,\n\t\t});\n\n\t\tif (initialToRun.length > 0) {\n\t\t\tawait runMigrations({\n\t\t\t\tcontext,\n\t\t\t\ttoRun: initialToRun,\n\t\t\t\tmeta,\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace: wipNamespace,\n\t\t\t});\n\n\t\t\t// now, we copy the data from the main database.\n\t\t\tconst mainDatabase = await openDatabase({\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace: context.namespace,\n\t\t\t\tversion: version - 1,\n\t\t\t\tcontext,\n\t\t\t});\n\n\t\t\tconst wipDatabase = await openDatabase({\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace: wipNamespace,\n\t\t\t\tversion: version - 1,\n\t\t\t\tcontext,\n\t\t\t});\n\t\t\tawait copyAll(mainDatabase, wipDatabase);\n\t\t}\n\n\t\tconst toRun = getMigrationPath({\n\t\t\tcurrentVersion: version - 1,\n\t\t\ttargetVersion: version,\n\t\t\tmigrations,\n\t\t});\n\n\t\tif (toRun.length > 0) {\n\t\t\tawait runMigrations({\n\t\t\t\tcontext,\n\t\t\t\ttoRun,\n\t\t\t\tmeta,\n\t\t\t\tindexedDB,\n\t\t\t\tnamespace: wipNamespace,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn openDatabase({\n\t\tindexedDB,\n\t\tnamespace: wipNamespace,\n\t\tversion,\n\t\tcontext,\n\t});\n}\n", "import { EventSubscriber } from '@verdant-web/common';\n\ntype Undoable = () => Undoable | Promise<Undoable | null> | null;\n\nexport class UndoHistory extends EventSubscriber<{ change: () => void }> {\n\tprivate _undoable: Undoable[] = [];\n\tprivate _undone: Undoable[] = [];\n\n\tget canUndo() {\n\t\treturn this._undoable.length > 0;\n\t}\n\tget canRedo() {\n\t\treturn this._undone.length > 0;\n\t}\n\n\tundo = async () => {\n\t\tconst next = this._undoable.pop();\n\t\tif (next) {\n\t\t\tconst redo = await next();\n\t\t\tif (redo) this._undone.push(redo);\n\t\t\tthis.emit('change');\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t};\n\n\tredo = async () => {\n\t\tconst next = this._undone.pop();\n\t\tif (next) {\n\t\t\tconst undo = await next();\n\t\t\tif (undo) this._undoable.push(undo);\n\t\t\tthis.emit('change');\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t};\n\n\taddUndo = (undoPoint: Undoable) => {\n\t\tthis._undoable.push(undoPoint);\n\t\tthis._undone = [];\n\t\tthis.emit('change');\n\t};\n\n\taddRedo = (redoPoint: Undoable) => {\n\t\tthis._undone.push(redoPoint);\n\t\tthis.emit('change');\n\t};\n\n\tclear = () => {\n\t\tthis._undoable = [];\n\t\tthis._undone = [];\n\t\tthis.emit('change');\n\t};\n}\n", "import {\n\taddFieldDefaults,\n\tconstrainEntity,\n\tassert,\n\tcreateOid,\n\tSchemaCollection,\n\tStorageCollectionSchema,\n\tStorageDocument,\n\tStorageSchema,\n\tisRootOid,\n\tAuthorizationKey,\n} from '@verdant-web/common';\nimport { EntityCreateOptions, EntityStore } from '../entities/EntityStore.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Sync } from '../sync/Sync.js';\nimport { Context } from '../context.js';\nimport { ObjectEntity } from '../index.js';\n\n/**\n * Exposes functionality for creating documents,\n * the only mutation which is available as an entry\n * point in the storage system.\n */\nexport class DocumentManager<Schema extends StorageSchema<any>> {\n\tconstructor(\n\t\tprivate schema: Schema,\n\t\tprivate entities: EntityStore,\n\t) {}\n\n\tprivate getOid = (collection: string, init: any) => {\n\t\tconst primaryKeyName = this.schema.collections[collection]\n\t\t\t.primaryKey as Exclude<\n\t\t\tkeyof StorageDocument<SchemaCollection<Schema, any>>,\n\t\t\tsymbol\n\t\t>;\n\t\tconst primaryKey = init[primaryKeyName];\n\t\tassert(\n\t\t\tprimaryKey,\n\t\t\t`Document must have a primary key: ${primaryKeyName.toString()} (got: ${JSON.stringify(\n\t\t\t\tinit,\n\t\t\t)})`,\n\t\t);\n\t\treturn createOid(collection, primaryKey);\n\t};\n\n\tprivate addDefaults = (collectionName: string, init: any) => {\n\t\tconst collection = this.schema.collections[\n\t\t\tcollectionName\n\t\t] as StorageCollectionSchema;\n\t\treturn addFieldDefaults(collection, init);\n\t};\n\n\tprivate validate = (collectionName: string, init: any) => {\n\t\tconst collection = this.schema.collections[\n\t\t\tcollectionName\n\t\t] as StorageCollectionSchema;\n\t\treturn constrainEntity(collection.fields, init);\n\t};\n\n\tcreate = async (\n\t\tcollection: string,\n\t\tinit: any,\n\t\toptions: {\n\t\t\tundoable?: boolean;\n\t\t\taccess?: AuthorizationKey;\n\t\t\tsilenceAccessControlWithPrimaryKeyWarning?: boolean;\n\t\t} = {},\n\t) => {\n\t\tconst widenedOptions = options as EntityCreateOptions;\n\t\tconst defaulted = this.addDefaults(collection, init);\n\t\tconst validated = this.validate(collection, defaulted);\n\t\tconst oid = this.getOid(collection, validated);\n\n\t\tif (options.access) {\n\t\t\tconst collectionSchema = this.schema.collections[collection];\n\t\t\tif (\n\t\t\t\toptions.access !== 'shared' &&\n\t\t\t\tinit[collectionSchema.primaryKey] &&\n\t\t\t\t!options.silenceAccessControlWithPrimaryKeyWarning\n\t\t\t) {\n\t\t\t\t// using a custom primary key with access control is not supported.\n\t\t\t\t// resulting docs could collide with existing docs with different permissions,\n\t\t\t\t// leading to confusing results. this logs a warning.\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Using a custom primary key with access control is not supported. This may result in corrupted documents. Read more about why: https://verdant.dev/docs/sync/access#a-warning-about-custom-primaryKey`,\n\t\t\t\t);\n\t\t\t}\n\t\t\twidenedOptions.access = options.access;\n\t\t}\n\n\t\t// documents are always objects at the root\n\t\treturn this.entities.create(validated, oid, widenedOptions) as any;\n\t};\n\n\tdelete = async (\n\t\tcollection: string,\n\t\tprimaryKey: string,\n\t\toptions: { undoable?: boolean } = {},\n\t) => {\n\t\tconst oid = createOid(collection, primaryKey);\n\t\treturn this.entities.delete(oid, options);\n\t};\n\n\tdeleteAll = async (\n\t\tids: [string, string][],\n\t\toptions: { undoable?: boolean } = {},\n\t) => {\n\t\treturn this.entities.deleteAll(\n\t\t\tids.map(([collection, primaryKey]) => createOid(collection, primaryKey)),\n\t\t\toptions,\n\t\t);\n\t};\n\n\tdeleteAllFromCollection = async (\n\t\tcollection: string,\n\t\tids: string[],\n\t\toptions: { undoable?: boolean } = {},\n\t) => {\n\t\treturn this.entities.deleteAll(\n\t\t\tids.map((primaryKey) => createOid(collection, primaryKey)),\n\t\t\toptions,\n\t\t);\n\t};\n\n\tclone = async (\n\t\tcollection: string,\n\t\tentity: ObjectEntity<any, any>,\n\t\toptions: {\n\t\t\tundoable?: boolean;\n\t\t\taccess?: AuthorizationKey;\n\t\t\tprimaryKey?: string;\n\t\t} = {},\n\t) => {\n\t\tif (!isRootOid(entity.uid)) {\n\t\t\tthrow new Error('Cannot clone non-root documents');\n\t\t}\n\t\t// take the entity snapshot\n\t\tconst snapshot = entity.getSnapshot();\n\t\t// remove the primary key\n\t\tconst collectionSchema = this.schema.collections[collection];\n\t\tdelete snapshot[collectionSchema.primaryKey];\n\t\t// if collection schema's primary key doesn't have a default value,\n\t\t// a user-supplied value is required\n\t\tif (!collectionSchema.fields[collectionSchema.primaryKey].default) {\n\t\t\tif (!options.primaryKey) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Error cloning document from collection ${collection}: collection does not have a default on primary key. You must supply a value to options.primaryKey for the clone.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tsnapshot[collectionSchema.primaryKey] = options.primaryKey;\n\t\t}\n\t\treturn this.create(collection, snapshot, options);\n\t};\n}\n", "import {\n\tcreateFileRef,\n\tFileData,\n\tisFile,\n\tisFileData,\n} from '@verdant-web/common';\nimport cuid from 'cuid';\n\nexport function createFileData(file: File): FileData {\n\treturn {\n\t\tid: cuid(),\n\t\tfile: file,\n\t\turl: undefined,\n\t\tremote: false,\n\t\tname: file.name,\n\t\ttype: file.type,\n\t};\n}\n\n/**\n * MUTATES the value.\n * Replaces File values with refs and returns the normalized value.\n * The list of files passed to the second argument will be populated with the files found in the value.\n */\nexport function processValueFiles(\n\tvalue: any,\n\tonFileIdentified: (fileData: FileData) => void,\n): any {\n\tif (typeof window !== 'undefined' && isFile(value)) {\n\t\tconst data = createFileData(value);\n\t\tonFileIdentified(data);\n\t\treturn createFileRef(data.id);\n\t}\n\n\tif (isFileData(value)) {\n\t\t// create a new ID for the file\n\t\tconst cloned = { ...value, id: cuid() };\n\t\tonFileIdentified(cloned);\n\t\treturn createFileRef(cloned.id);\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (let i = 0; i < value.length; i++) {\n\t\t\tvalue[i] = processValueFiles(value[i], onFileIdentified);\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (typeof value === 'object') {\n\t\tfor (const key in value) {\n\t\t\tvalue[key] = processValueFiles(value[key], onFileIdentified);\n\t\t}\n\t\treturn value;\n\t}\n\n\treturn value;\n}\n\nexport function fileToArrayBuffer(file: File | Blob) {\n\t// special case for testing...\n\tif ('__testReadBuffer' in file) {\n\t\treturn file.__testReadBuffer;\n\t}\n\treturn new Promise<ArrayBuffer>((resolve, reject) => {\n\t\tconst reader = new FileReader();\n\t\treader.onload = () => {\n\t\t\tresolve(reader.result as ArrayBuffer);\n\t\t};\n\t\treader.onerror = reject;\n\t\treader.readAsArrayBuffer(file);\n\t});\n}\n", "import { EventSubscriber, FileData } from '@verdant-web/common';\n\nexport type EntityFileEvents = {\n\tchange: () => void;\n};\n\nexport const UPDATE = Symbol('entity-file-update');\nexport const MARK_FAILED = Symbol('entity-file-mark-failed');\nexport const MARK_UPLOADED = Symbol('entity-file-mark-uploaded');\n\nexport type EntityFileSnapshot = {\n\tid: string;\n\turl?: string | null;\n};\n\n/**\n * Provides a consistent interface for files used in an app via\n * Entity access.\n */\nexport class EntityFile extends EventSubscriber<EntityFileEvents> {\n\t// cached object URL for a local blob file, if applicable\n\tprivate _objectUrl: string | null = null;\n\tprivate _fileData: FileData | null = null;\n\tprivate _loading = true;\n\tprivate _failed = false;\n\tprivate _downloadRemote = false;\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\t{\n\t\t\tdownloadRemote = false,\n\t\t}: {\n\t\t\tdownloadRemote?: boolean;\n\t\t} = {},\n\t) {\n\t\tsuper();\n\t\tthis._downloadRemote = downloadRemote;\n\t}\n\n\tget downloadRemote() {\n\t\treturn this._downloadRemote;\n\t}\n\tget isFile() {\n\t\treturn true;\n\t}\n\tget isUploaded() {\n\t\treturn this._fileData?.remote ?? false;\n\t}\n\n\t[UPDATE] = (fileData: FileData) => {\n\t\tthis._loading = false;\n\t\tthis._failed = false;\n\t\tthis._fileData = fileData;\n\t\tif (fileData.file) {\n\t\t\tif (this._objectUrl) {\n\t\t\t\tURL.revokeObjectURL(this._objectUrl);\n\t\t\t}\n\t\t\tthis._objectUrl = URL.createObjectURL(fileData.file);\n\t\t}\n\t\tthis.emit('change');\n\t};\n\n\t[MARK_FAILED] = () => {\n\t\tthis._failed = true;\n\t\tthis._loading = false;\n\t\tthis.emit('change');\n\t};\n\n\t[MARK_UPLOADED] = () => {\n\t\tif (!this._fileData) return;\n\t\tthis._fileData!.remote = true;\n\t\tthis.emit('change');\n\t};\n\n\tget url(): string | null {\n\t\tif (this.loading) return null;\n\t\tif (this._objectUrl) return this._objectUrl;\n\t\treturn this._fileData?.url ?? null;\n\t}\n\n\tget name(): string | null {\n\t\treturn this._fileData?.name ?? null;\n\t}\n\n\tget type(): string | null {\n\t\treturn this._fileData?.type ?? null;\n\t}\n\n\tget loading() {\n\t\treturn this._loading;\n\t}\n\n\tget failed() {\n\t\treturn this._failed;\n\t}\n\n\tdestroy = () => {\n\t\tif (this._objectUrl) {\n\t\t\tURL.revokeObjectURL(this._objectUrl);\n\t\t}\n\t\tthis.dispose();\n\t};\n\n\tgetSnapshot(): FileData {\n\t\tif (this._fileData) return this._fileData;\n\t\treturn {\n\t\t\tid: this.id,\n\t\t\turl: this._objectUrl ?? undefined,\n\t\t\tname: this.name ?? 'unknown-file',\n\t\t\tremote: false,\n\t\t\ttype: this.type ?? '',\n\t\t};\n\t}\n}\n", "import { Entity, EntityInit } from './Entity.js';\nimport { EntityFile } from '../files/EntityFile.js';\nimport { ObjectIdentifier } from '@verdant-web/common';\n\nexport class EntityCache {\n\tprivate cache = new Map<string, Entity | EntityFile>();\n\n\tconstructor({ initial }: { initial?: Entity[] } = {}) {\n\t\tif (initial) {\n\t\t\tfor (const entity of initial) {\n\t\t\t\tthis.cache.set(entity.oid, entity);\n\t\t\t}\n\t\t}\n\t}\n\n\tget = (init: EntityInit): Entity => {\n\t\tif (this.cache.has(init.oid)) {\n\t\t\treturn this.cache.get(init.oid)! as Entity;\n\t\t}\n\t\tconst entity = new Entity(init);\n\t\tthis.cache.set(init.oid, entity);\n\t\treturn entity;\n\t};\n\n\thas = (oid: ObjectIdentifier) => {\n\t\treturn this.cache.has(oid);\n\t};\n\n\tgetFile = (id: string, options: { downloadRemote: boolean }): EntityFile => {\n\t\tif (this.cache.has(id)) {\n\t\t\treturn this.cache.get(id)! as EntityFile;\n\t\t}\n\t\tconst file = new EntityFile(id, options);\n\t\tthis.cache.set(id, file);\n\t\treturn file;\n\t};\n\n\tgetCached = (oid: string) => {\n\t\treturn this.cache.get(oid);\n\t};\n}\n", "import { Entity } from './Entity.js';\nimport { EntityChangeInfo } from './types.js';\n\nexport function entityFieldSubscriber<T = any>(\n\tentity: Entity,\n\tfield: string | number | symbol,\n\tsubscriber: (\n\t\tnewValue: T,\n\t\tinfo: EntityChangeInfo & { previousValue: T },\n\t) => void,\n) {\n\tconst valueHolder = {\n\t\tpreviousValue: entity.get(field),\n\t\tisLocal: false,\n\t};\n\tfunction handler(\n\t\tthis: { previousValue: T } & EntityChangeInfo,\n\t\tinfo: EntityChangeInfo,\n\t) {\n\t\tif (entity.deleted) {\n\t\t\treturn;\n\t\t}\n\t\tconst newValue = entity.get(field);\n\t\tif (newValue !== this.previousValue) {\n\t\t\tthis.isLocal = info.isLocal;\n\t\t\tsubscriber(newValue, this);\n\t\t\tthis.previousValue = newValue;\n\t\t}\n\t}\n\treturn entity.subscribe('change', handler.bind(valueHolder));\n}\n", "import {\n\tDocumentBaseline,\n\tEntityValidationProblem,\n\tEventSubscriber,\n\tObjectIdentifier,\n\tOperation,\n\tPatchCreator,\n\tStorageFieldSchema,\n\tStorageFieldsSchema,\n\tassert,\n\tassignOid,\n\tcloneDeep,\n\tcompareRefs,\n\tcreateFileRef,\n\tcreateRef,\n\tgetChildFieldSchema,\n\tgetDefault,\n\thasDefault,\n\tisFileRef,\n\tisFile,\n\tisNullable,\n\tisObject,\n\tisObjectRef,\n\tisPrunePoint,\n\tisRef,\n\tmaybeGetOid,\n\tmemoByKeys,\n\ttraverseCollectionFieldsAndApplyDefaults,\n\tvalidateEntityField,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { FileManager } from '../files/FileManager.js';\nimport { processValueFiles } from '../files/utils.js';\nimport { EntityFile } from '../index.js';\nimport { EntityCache } from './EntityCache.js';\nimport { EntityFamilyMetadata, EntityMetadataView } from './EntityMetadata.js';\nimport {\n\tBaseEntityValue,\n\tDataFromInit,\n\tDeepPartial,\n\tEntityChange,\n\tEntityEvents,\n\tListEntity,\n\tListItemInit,\n\tListItemValue,\n\tObjectEntity,\n} from './types.js';\nimport { EntityStoreEventData, EntityStoreEvents } from './EntityStore.js';\nimport { entityFieldSubscriber } from './entityFieldSubscriber.js';\n\nexport interface EntityInit {\n\toid: ObjectIdentifier;\n\tschema: StorageFieldSchema;\n\tentityFamily?: EntityCache;\n\tmetadataFamily: EntityFamilyMetadata;\n\tparent?: Entity;\n\tctx: Context;\n\tfiles: FileManager;\n\treadonlyKeys?: string[];\n\tfieldPath?: (string | number)[];\n\tpatchCreator: PatchCreator;\n\tstoreEvents: EntityStoreEvents;\n\tdeleteSelf: () => void;\n}\n\nexport class Entity<\n\t\tInit = any,\n\t\tKeyValue extends BaseEntityValue = any,\n\t\tSnapshot extends any = DataFromInit<Init>,\n\t>\n\textends EventSubscriber<EntityEvents>\n\timplements\n\t\tObjectEntity<Init, KeyValue, Snapshot>,\n\t\tListEntity<Init, KeyValue, Snapshot>\n{\n\treadonly oid: ObjectIdentifier;\n\tprivate readonlyKeys: string[];\n\tprivate fieldPath: (string | number)[] = [];\n\t// these are shared between all entities in this family\n\tprivate entityFamily: EntityCache;\n\tprivate metadataFamily;\n\n\tprivate schema;\n\tprivate parent: Entity | undefined;\n\tprivate ctx;\n\tprivate files;\n\tprivate patchCreator;\n\tprivate storeEvents;\n\n\t// an internal representation of this Entity.\n\t// if present, this is the cached, known value. If null,\n\t// the entity is deleted. If undefined, we need to recompute\n\t// the view.\n\tprivate _viewData: EntityMetadataView | undefined = undefined;\n\tprivate validationError: EntityValidationProblem | undefined = undefined;\n\tprivate cachedDeepUpdatedAt: number | null = null;\n\t// only used for root entities to track delete/restore state.\n\tprivate wasDeletedLastChange = false;\n\tprivate cachedView: any | undefined = undefined;\n\t// provided from external creators, this is a method to delete\n\t// this entity.\n\tprivate _deleteSelf: () => void;\n\n\tconstructor({\n\t\toid,\n\t\tschema,\n\t\tentityFamily: childCache,\n\t\tparent,\n\t\tctx,\n\t\tmetadataFamily,\n\t\treadonlyKeys,\n\t\tfiles,\n\t\tpatchCreator,\n\t\tstoreEvents,\n\t\tdeleteSelf,\n\t}: EntityInit) {\n\t\tsuper();\n\n\t\tassert(!!oid, 'oid is required');\n\n\t\tthis.oid = oid;\n\t\tthis.readonlyKeys = readonlyKeys || [];\n\t\tthis.ctx = ctx;\n\t\tthis.files = files;\n\t\tthis.schema = schema;\n\t\tthis.entityFamily =\n\t\t\tchildCache ||\n\t\t\tnew EntityCache({\n\t\t\t\tinitial: [this],\n\t\t\t});\n\t\tthis.patchCreator = patchCreator;\n\t\tthis.metadataFamily = metadataFamily;\n\t\tthis.storeEvents = storeEvents;\n\t\tthis.parent = parent;\n\t\tthis._deleteSelf = deleteSelf;\n\n\t\t// TODO: should any but the root entity be listening to these?\n\t\tif (!this.parent) {\n\t\t\tstoreEvents.add.attach(this.onAdd);\n\t\t\tstoreEvents.replace.attach(this.onReplace);\n\t\t\tstoreEvents.resetAll.attach(this.onResetAll);\n\t\t}\n\t}\n\n\tprivate onAdd = (_store: any, data: EntityStoreEventData) => {\n\t\tif (data.oid === this.oid) {\n\t\t\tthis.addConfirmedData(data);\n\t\t}\n\t};\n\tprivate onReplace = (_store: any, data: EntityStoreEventData) => {\n\t\tif (data.oid === this.oid) {\n\t\t\tthis.replaceAllData(data);\n\t\t}\n\t};\n\tprivate onResetAll = () => {\n\t\tthis.resetAllData();\n\t};\n\n\tprivate get metadata() {\n\t\treturn this.metadataFamily.get(this.oid);\n\t}\n\n\t/**\n\t * The view of this Entity, not including nested\n\t * entities (that's the snapshot - see #getSnapshot())\n\t *\n\t * Nested entities are represented by refs.\n\t */\n\tprivate get viewData() {\n\t\tif (this._viewData === undefined) {\n\t\t\tthis._viewData = this.metadata.computeView();\n\t\t\tthis.validate();\n\t\t}\n\t\treturn this._viewData;\n\t}\n\n\t/** convenience getter for viewData.view */\n\tprivate get rawView() {\n\t\treturn this.viewData.view;\n\t}\n\n\t/**\n\t * An Entity's View includes the rendering of its underlying data,\n\t * connecting of children where refs were, and validation\n\t * and pruning according to schema.\n\t */\n\tprivate get view() {\n\t\tif (this.cachedView !== undefined) {\n\t\t\treturn this.cachedView;\n\t\t}\n\n\t\tif (this.viewData.deleted) {\n\t\t\treturn null;\n\t\t}\n\t\t// can't use invalid data - but this should be bubbled up to\n\t\t// a prune point\n\t\tconst rawView = this.rawView;\n\n\t\tconst viewIsWrongType =\n\t\t\t(!rawView && !isNullable(this.schema)) ||\n\t\t\t(this.schema.type === 'array' && !Array.isArray(rawView)) ||\n\t\t\t((this.schema.type === 'object' || this.schema.type === 'map') &&\n\t\t\t\t!isObject(rawView));\n\n\t\tif (viewIsWrongType) {\n\t\t\t// this will cover lists and maps, too.\n\t\t\tif (hasDefault(this.schema)) {\n\t\t\t\treturn getDefault(this.schema);\n\t\t\t}\n\t\t\t// force null - invalid - will require parent prune\n\t\t\treturn null as any;\n\t\t}\n\n\t\tthis.cachedView = this.isList ? [] : {};\n\t\tassignOid(this.cachedView, this.oid);\n\n\t\tif (Array.isArray(rawView)) {\n\t\t\tconst schema = getChildFieldSchema(this.schema, 0);\n\t\t\tif (!schema) {\n\t\t\t\t/**\n\t\t\t\t * PRUNE - this is a prune point. we can't continue\n\t\t\t\t * to render this data, so we'll just return [].\n\t\t\t\t * This skips the loop.\n\t\t\t\t */\n\t\t\t\tthis.ctx.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t'No child field schema for list entity.',\n\t\t\t\t\tthis.oid,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tfor (let i = 0; i < rawView.length; i++) {\n\t\t\t\t\tconst child = this.get(i);\n\t\t\t\t\tif (this.childIsNull(child) && !isNullable(schema)) {\n\t\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t\t'error',\n\t\t\t\t\t\t\t'Child missing in non-nullable field',\n\t\t\t\t\t\t\tthis.oid,\n\t\t\t\t\t\t\t'index:',\n\t\t\t\t\t\t\ti,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// this item will be pruned.\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.cachedView.push(child);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (isObject(rawView)) {\n\t\t\t// iterate over known properties in object-type entities;\n\t\t\t// for maps, we just iterate over the keys.\n\t\t\tconst keys =\n\t\t\t\tthis.schema.type === 'object'\n\t\t\t\t\t? Object.keys(this.schema.properties)\n\t\t\t\t\t: Object.keys(rawView);\n\t\t\tfor (const key of keys) {\n\t\t\t\tconst schema = getChildFieldSchema(this.schema, key);\n\t\t\t\tif (!schema) {\n\t\t\t\t\t/**\n\t\t\t\t\t * PRUNE - this is a prune point. we can't continue\n\t\t\t\t\t * to render this data. If this is a map, it will be\n\t\t\t\t\t * pruned empty. Otherwise, prune moves upward.\n\t\t\t\t\t *\n\t\t\t\t\t * This exits the loop.\n\t\t\t\t\t */\n\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t'error',\n\t\t\t\t\t\t'No child field schema for object entity at key',\n\t\t\t\t\t\tkey,\n\t\t\t\t\t);\n\t\t\t\t\tif (this.schema.type === 'map') {\n\t\t\t\t\t\t// it's valid to prune here if it's a map\n\t\t\t\t\t\tthis.cachedView = {};\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// otherwise prune moves upward\n\t\t\t\t\t\tthis.cachedView = null;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tconst child = this.get(key as any);\n\t\t\t\tif (this.childIsNull(child) && !isNullable(schema)) {\n\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t'error',\n\t\t\t\t\t\t'Child entity is missing for non-nullable field',\n\t\t\t\t\t\tthis.oid,\n\t\t\t\t\t\t'key:',\n\t\t\t\t\t\tkey,\n\t\t\t\t\t);\n\t\t\t\t\t/**\n\t\t\t\t\t * PRUNE - this is a prune point. we can't continue\n\t\t\t\t\t * to render this data. If this is a map, we can ignore\n\t\t\t\t\t * this value. Otherwise we must prune upward.\n\t\t\t\t\t * This exits the loop.\n\t\t\t\t\t */\n\t\t\t\t\tif (this.schema.type !== 'map') {\n\t\t\t\t\t\tthis.cachedView = null;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthis.cachedView[key] = child;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this.cachedView;\n\t}\n\n\tprivate childIsNull = (child: any) => {\n\t\tif (child instanceof Entity) {\n\t\t\tconst childView = child.view;\n\t\t\treturn childView === null || childView === undefined;\n\t\t}\n\t\treturn child === null || child === undefined;\n\t};\n\n\tget uid() {\n\t\treturn this.oid;\n\t}\n\n\tget deleted() {\n\t\treturn this.viewData.deleted || this.view === null;\n\t}\n\n\tget invalid() {\n\t\treturn !!this.validate();\n\t}\n\n\tget isList() {\n\t\t// have to turn TS off here as our two interfaces both implement\n\t\t// const values for this boolean.\n\t\treturn (\n\t\t\tthis.schema.type === 'array' || (Array.isArray(this.viewData.view) as any)\n\t\t);\n\t}\n\n\tget updatedAt() {\n\t\treturn this.viewData.updatedAt;\n\t}\n\n\tget deepUpdatedAt() {\n\t\tif (this.cachedDeepUpdatedAt) return this.cachedDeepUpdatedAt;\n\t\t// iterate over all children and take the latest timestamp\n\t\tlet latest: number | null = this.updatedAt;\n\t\tif (this.isList) {\n\t\t\tthis.forEach((child: any) => {\n\t\t\t\tif (child instanceof Entity) {\n\t\t\t\t\tconst childTimestamp = child.deepUpdatedAt;\n\t\t\t\t\tif (childTimestamp && (!latest || childTimestamp > latest)) {\n\t\t\t\t\t\tlatest = childTimestamp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tthis.values().forEach((child) => {\n\t\t\t\tif (child instanceof Entity) {\n\t\t\t\t\tconst childTimestamp = child.deepUpdatedAt;\n\t\t\t\t\tif (childTimestamp && (!latest || childTimestamp > latest)) {\n\t\t\t\t\t\tlatest = childTimestamp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tthis.cachedDeepUpdatedAt = latest;\n\t\treturn latest;\n\t}\n\n\t/**\n\t * @internal - this is relevant to Verdant's system, not users.\n\t *\n\t * Indicates whether this document is from an outdated version\n\t * of the schema - which means it cannot be used until it is upgraded.\n\t */\n\tget isOutdatedVersion(): boolean {\n\t\tif (this.parent) return this.parent.isOutdatedVersion;\n\t\treturn this.viewData.fromOlderVersion;\n\t}\n\n\t/**\n\t * Returns the storage namespace this entity came from. For example, if you\n\t * have multiple stores initialized from the same schema, you can use this\n\t * to figure out where an isolated entity was created / stored.\n\t */\n\tget namespace() {\n\t\treturn this.ctx.namespace;\n\t}\n\n\t/**\n\t * The authz string signifying the permissions this entity has.\n\t * On the client (where we are) it's only ever possible to see\n\t * an entity with either full access or access for the current\n\t * user.\n\t */\n\tget access() {\n\t\treturn this.viewData.authz;\n\t}\n\tget isAuthorized() {\n\t\treturn !!this.access;\n\t}\n\n\t/**\n\t * Introspects the schema of a child field of this entity.\n\t */\n\tgetFieldSchema = (key: any): StorageFieldSchema => {\n\t\tconst fieldSchema = getChildFieldSchema(this.schema, key);\n\t\tassert(fieldSchema, `No schema for key ${key}`);\n\t\treturn fieldSchema;\n\t};\n\n\t/**\n\t * Pruning - when entities have invalid children, we 'prune' that\n\t * data up to the nearest prunable point - a nullable field,\n\t * or a list.\n\t */\n\tprotected validate = memoByKeys(\n\t\t() => {\n\t\t\tthis.validationError =\n\t\t\t\tvalidateEntityField({\n\t\t\t\t\tfield: this.schema,\n\t\t\t\t\tvalue: this.rawView,\n\t\t\t\t\tfieldPath: this.fieldPath,\n\t\t\t\t\tdepth: 1,\n\t\t\t\t}) ?? undefined;\n\t\t\treturn this.validationError;\n\t\t},\n\t\t() => [this.viewData],\n\t);\n\n\tprivate viewWithMappedChildren = (\n\t\tmapper: (child: Entity | EntityFile) => any,\n\t) => {\n\t\tconst view = this.view;\n\t\tif (!view) {\n\t\t\treturn null;\n\t\t}\n\t\tif (Array.isArray(view)) {\n\t\t\tconst mapped = view.map((value) => {\n\t\t\t\tif (value instanceof Entity || value instanceof EntityFile) {\n\t\t\t\t\treturn mapper(value);\n\t\t\t\t} else {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t});\n\t\t\tassignOid(mapped, this.oid);\n\t\t\treturn mapped;\n\t\t} else {\n\t\t\tconst mapped = Object.entries(view).reduce((acc, [key, value]) => {\n\t\t\t\tif (value instanceof Entity || value instanceof EntityFile) {\n\t\t\t\t\tacc[key as any] = mapper(value);\n\t\t\t\t} else {\n\t\t\t\t\tacc[key as any] = value;\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t}, {} as any);\n\t\t\tassignOid(mapped, this.oid);\n\t\t\treturn mapped;\n\t\t}\n\t};\n\n\t/**\n\t * A current snapshot of this Entity's data, including nested\n\t * Entities.\n\t */\n\tgetSnapshot = (): any => {\n\t\treturn this.viewWithMappedChildren((child) => child.getSnapshot());\n\t};\n\n\t// change management methods (internal use only)\n\tprivate addPendingOperations = (operations: Operation[]) => {\n\t\tthis.ctx.log('debug', 'Entity: adding pending operations', this.oid);\n\n\t\t// apply authz to all operations\n\t\tif (this.access) {\n\t\t\tfor (const op of operations) {\n\t\t\t\top.authz = this.access;\n\t\t\t}\n\t\t}\n\n\t\tconst changes = this.metadataFamily.addPendingData(operations);\n\t\tfor (const change of changes) {\n\t\t\tthis.change(change);\n\t\t}\n\t};\n\n\tprivate addConfirmedData = (data: EntityStoreEventData) => {\n\t\tthis.ctx.log('debug', 'Entity: adding confirmed data', this.oid);\n\t\tconst changes = this.metadataFamily.addConfirmedData(data);\n\t\tfor (const change of changes) {\n\t\t\tthis.change(change);\n\t\t}\n\t};\n\n\tprivate replaceAllData = (data: EntityStoreEventData) => {\n\t\tthis.ctx.log('debug', 'Entity: replacing all data', this.oid);\n\t\tconst changes = this.metadataFamily.replaceAllData(data);\n\t\tfor (const change of changes) {\n\t\t\tthis.change(change);\n\t\t}\n\t};\n\n\tprivate resetAllData = () => {\n\t\tthis.ctx.log('debug', 'Entity: resetting all data', this.oid);\n\t\tthis.cachedDeepUpdatedAt = null;\n\t\tthis.cachedView = undefined;\n\t\tthis._viewData = undefined;\n\t\tconst changes = this.metadataFamily.replaceAllData({});\n\t\tfor (const change of changes) {\n\t\t\tthis.change(change);\n\t\t}\n\t};\n\n\tprivate invalidateCachedView = () => {\n\t\tthis._viewData = undefined;\n\t\tthis.cachedView = undefined;\n\t};\n\n\tprivate change = (ev: EntityChange) => {\n\t\tif (ev.oid === this.oid) {\n\t\t\t// reset cached view\n\t\t\tthis.invalidateCachedView();\n\t\t\tif (!this.parent) {\n\t\t\t\tthis.changeRoot(ev);\n\t\t\t} else {\n\t\t\t\tthis.changeNested(ev);\n\t\t\t}\n\t\t} else {\n\t\t\t// forward it to the correct family member. if none exists\n\t\t\t// in cache, no one will hear it anyways.\n\t\t\tconst other = this.entityFamily.getCached(ev.oid);\n\t\t\tif (other && other instanceof Entity) {\n\t\t\t\tother.change(ev);\n\t\t\t}\n\t\t}\n\t};\n\tprivate changeRoot = (ev: EntityChange) => {\n\t\t// for root entities, we need to determine if we're deleted or not\n\t\t// before firing any events\n\t\tif (this.deleted) {\n\t\t\tif (!this.wasDeletedLastChange) {\n\t\t\t\tthis.ctx.log('debug', 'Entity deleted', this.oid);\n\t\t\t\tthis.emit('delete', { isLocal: ev.isLocal });\n\t\t\t\tthis.wasDeletedLastChange = true;\n\t\t\t}\n\t\t\t// already deleted, do nothing.\n\t\t} else {\n\t\t\tif (this.wasDeletedLastChange) {\n\t\t\t\tthis.ctx.log('debug', 'Entity restored', this.oid);\n\t\t\t\tthis.emit('restore', { isLocal: ev.isLocal });\n\t\t\t\tthis.wasDeletedLastChange = false;\n\t\t\t}\n\t\t\t// emit deepchange, too\n\t\t\tthis.deepChange(this, ev);\n\t\t\t// emit the change, it's for us\n\t\t\tthis.emit('change', { isLocal: ev.isLocal });\n\t\t}\n\t};\n\tprivate changeNested = (ev: EntityChange) => {\n\t\t// chain deepChanges to parents\n\t\tthis.deepChange(this, ev);\n\t\t// emit the change, it's for us\n\t\tthis.emit('change', { isLocal: ev.isLocal });\n\t};\n\tprotected deepChange = (target: Entity, ev: EntityChange) => {\n\t\t// reset cached deep updated at timestamp; either this\n\t\t// entity or children have changed\n\t\tthis.cachedDeepUpdatedAt = null;\n\t\t// reset this flag to recompute snapshot data - children\n\t\t// or self has changed. new pruning needs to happen.\n\t\tthis.cachedView = undefined;\n\t\tthis.emit('changeDeep', target, ev);\n\t\tthis.parent?.deepChange(target, ev);\n\t};\n\n\tprivate getChild = (key: any, oid: ObjectIdentifier) => {\n\t\tconst schema = getChildFieldSchema(this.schema, key);\n\t\tif (!schema) {\n\t\t\tthrow new Error(\n\t\t\t\t`No schema for key ${String(key)} in ${JSON.stringify(this.schema)}`,\n\t\t\t);\n\t\t}\n\t\treturn this.entityFamily.get({\n\t\t\toid,\n\t\t\tschema,\n\t\t\tentityFamily: this.entityFamily,\n\t\t\tmetadataFamily: this.metadataFamily,\n\t\t\tparent: this,\n\t\t\tctx: this.ctx,\n\t\t\tfiles: this.files,\n\t\t\tfieldPath: [...this.fieldPath, key],\n\t\t\tpatchCreator: this.patchCreator,\n\t\t\tstoreEvents: this.storeEvents,\n\t\t\tdeleteSelf: this.delete.bind(this, key),\n\t\t});\n\t};\n\n\tsubscribeToField = <K extends keyof KeyValue>(\n\t\tkey: K,\n\t\tevent: 'change', // here to keep future api changes stable\n\t\tcallback: (\n\t\t\tvalue: KeyValue[K],\n\t\t\tinfo: { previousValue: KeyValue[K]; isLocal?: boolean },\n\t\t) => void,\n\t) => {\n\t\treturn entityFieldSubscriber<KeyValue[K]>(this, key, callback);\n\t};\n\n\t// generic entity methods\n\t/**\n\t * Gets a value from this Entity. If the value\n\t * is an object, it will be wrapped in another\n\t * Entity.\n\t */\n\tget = <Key extends keyof KeyValue>(key: Key): KeyValue[Key] => {\n\t\tassertNotSymbol(key);\n\n\t\tconst view = this.rawView;\n\t\tif (!view) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot access data at key ${key} on deleted entity ${this.oid}`,\n\t\t\t);\n\t\t}\n\t\tconst child = view[key as any];\n\t\tconst fieldSchema = getChildFieldSchema(this.schema, key);\n\t\tif (!fieldSchema) {\n\t\t\tthrow new Error(\n\t\t\t\t`No schema for key ${String(key)} in ${JSON.stringify(this.schema)}`,\n\t\t\t);\n\t\t}\n\t\tif (isRef(child)) {\n\t\t\tif (isFileRef(child)) {\n\t\t\t\tif (fieldSchema.type !== 'file') {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Expected file schema for key ${String(key)}, got ${\n\t\t\t\t\t\t\tfieldSchema.type\n\t\t\t\t\t\t}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst file = this.files.get(child.id, {\n\t\t\t\t\tdownloadRemote: !!fieldSchema.downloadRemote,\n\t\t\t\t});\n\n\t\t\t\t// FIXME: this seems bad and inconsistent\n\t\t\t\tfile.subscribe('change', () => {\n\t\t\t\t\tthis.deepChange(this, { isLocal: false, oid: this.oid });\n\t\t\t\t});\n\n\t\t\t\treturn file as KeyValue[Key];\n\t\t\t} else {\n\t\t\t\treturn this.getChild(key, child.id) as KeyValue[Key];\n\t\t\t}\n\t\t} else {\n\t\t\t// if this is a Map type, a missing child is\n\t\t\t// just an empty spot\n\t\t\tif (this.schema.type === 'map' && child === undefined) {\n\t\t\t\treturn undefined as KeyValue[Key];\n\t\t\t}\n\t\t\t// prune invalid primitive fields\n\t\t\tif (\n\t\t\t\tvalidateEntityField({\n\t\t\t\t\tfield: fieldSchema,\n\t\t\t\t\tvalue: child,\n\t\t\t\t\tfieldPath: [...this.fieldPath, key],\n\t\t\t\t\tdepth: 1,\n\t\t\t\t\trequireDefaults: true,\n\t\t\t\t})\n\t\t\t) {\n\t\t\t\tif (hasDefault(fieldSchema)) {\n\t\t\t\t\treturn getDefault(fieldSchema);\n\t\t\t\t}\n\t\t\t\tif (isNullable(fieldSchema)) {\n\t\t\t\t\treturn null as any;\n\t\t\t\t}\n\t\t\t\treturn undefined as any;\n\t\t\t}\n\t\t\treturn child as KeyValue[Key];\n\t\t}\n\t};\n\n\t/**\n\t * Gets a value on this entity. If the value is not\n\t * present, it will be set to the provided default\n\t * and returned synchronously. This method only sets\n\t * a new value once when a field is empty; subsequent\n\t * calls will retrieve the created value until it is\n\t * deleted.\n\t *\n\t * Note that this should only be called for nullable\n\t * fields. If the field is not nullable, the existing\n\t * value or the default value will always be returned,\n\t * and the default will not be set.\n\t */\n\tgetOrSet = <Key extends keyof Init & keyof KeyValue>(\n\t\tkey: Key,\n\t\tinit: Init[Key],\n\t): KeyValue[Key] => {\n\t\tassertNotSymbol(key);\n\t\tconst existing = this.get(key);\n\t\tif (existing) return existing;\n\t\tthis.set(key as any, init);\n\t\treturn this.get(key);\n\t};\n\n\tprivate processInputValue = (value: any, key: any) => {\n\t\tif (this.readonlyKeys.includes(key as string)) {\n\t\t\tthrow new Error(`Cannot set readonly key ${key.toString()}`);\n\t\t}\n\t\t// disassociate incoming OIDs on values and generally break object\n\t\t// references. cloning doesn't work on files so those are\n\t\t// filtered out.\n\t\t// The goal here is to be safe about a bunch of cases that could\n\t\t// result in corrupt data, like...\n\t\t// ent1.set('objField', ent2.get('objField'))\n\t\t// or\n\t\t// var shared = { foo: 'bar' };\n\t\t// ent1.set('objField', shared);\n\t\t// ent2.set('objField', shared);\n\t\t// ... each of these would result in the same object being\n\t\t// referenced in multiple entities, which could mean introduction\n\t\t// of foreign OIDs, or one object being assigned different OIDs\n\t\t// with unexpected results.\n\t\tif (!isFile(value)) {\n\t\t\tvalue = cloneDeep(value, false);\n\t\t}\n\t\tconst fieldSchema = getChildFieldSchema(this.schema, key);\n\t\tif (fieldSchema) {\n\t\t\ttraverseCollectionFieldsAndApplyDefaults(value, fieldSchema);\n\t\t\tconst validationError = validateEntityField({\n\t\t\t\tfield: fieldSchema,\n\t\t\t\tvalue,\n\t\t\t\tfieldPath: [...this.fieldPath, key],\n\t\t\t});\n\t\t\tif (validationError) {\n\t\t\t\t// TODO: is it a good idea to throw an error here? a runtime error won't be that helpful,\n\t\t\t\t// but also we don't really want invalid data supplied.\n\t\t\t\tthrow new Error(`Validation error: ${validationError.message}`, {\n\t\t\t\t\tcause: validationError,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn processValueFiles(value, this.files.add);\n\t};\n\n\tprivate getDeleteMode = (key: any) => {\n\t\tif (this.readonlyKeys.includes(key)) {\n\t\t\treturn false;\n\t\t}\n\t\t// any is always deletable, and map values\n\t\tif (this.schema.type === 'any' || this.schema.type === 'map') {\n\t\t\treturn 'delete';\n\t\t}\n\n\t\tif (this.schema.type === 'object') {\n\t\t\tconst property = this.schema.properties[key];\n\t\t\tif (!property) {\n\t\t\t\t// huh, the property doesn't exist. it's ok to\n\t\t\t\t// remove I suppose.\n\t\t\t\treturn 'delete';\n\t\t\t}\n\t\t\tif (property.type === 'any') return 'delete';\n\t\t\t// map can't be nullable. should it be?\n\t\t\tif (property.type === 'map') return false;\n\t\t\tif (property.nullable) return 'null';\n\t\t}\n\t\t// no other types are deletable\n\t\treturn false;\n\t};\n\n\t/**\n\t * Returns the referent value of an item in the list, used for\n\t * operations which act on items. if the item is an object,\n\t * it will attempt to create an OID reference to it. If it\n\t * is a primitive, it will return the primitive.\n\t */\n\tprivate getItemRefValue = (item: any) => {\n\t\tif (item instanceof Entity) {\n\t\t\treturn createRef(item.oid);\n\t\t}\n\t\tif (item instanceof EntityFile) {\n\t\t\treturn createFileRef(item.id);\n\t\t}\n\t\tif (typeof item === 'object') {\n\t\t\tconst itemOid = maybeGetOid(item);\n\t\t\tif (!itemOid || !this.entityFamily.has(itemOid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot move object ${JSON.stringify(\n\t\t\t\t\t\titem,\n\t\t\t\t\t)} which does not exist in this list`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn createRef(itemOid);\n\t\t} else {\n\t\t\treturn item;\n\t\t}\n\t};\n\n\tset = (\n\t\tkey: any,\n\t\tvalue: any,\n\t\toptions?: {\n\t\t\t/**\n\t\t\t * Forces the creation of a change for this set even if the value is the same\n\t\t\t * as the current value for this key. This has an effect in situations where\n\t\t\t * offline changes from others are interleaved with local changes; when setting\n\t\t\t * a value to its current value (force=true), if that value were retroactively changed from\n\t\t\t * offline changes, the set would put it back to the value specified. If the\n\t\t\t * set is ignored because the value is the same (force=false), then retroactive\n\t\t\t * changes will be preserved.\n\t\t\t */\n\t\t\tforce: boolean;\n\t\t},\n\t) => {\n\t\tassertNotSymbol(key);\n\t\tif (!options?.force && this.get(key) === value) return;\n\n\t\tif (this.isList) {\n\t\t\tthis.addPendingOperations(\n\t\t\t\tthis.patchCreator.createListSet(\n\t\t\t\t\tthis.oid,\n\t\t\t\t\tkey,\n\t\t\t\t\tthis.processInputValue(value, key),\n\t\t\t\t),\n\t\t\t);\n\t\t} else {\n\t\t\tthis.addPendingOperations(\n\t\t\t\tthis.patchCreator.createSet(\n\t\t\t\t\tthis.oid,\n\t\t\t\t\tkey,\n\t\t\t\t\tthis.processInputValue(value, key),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t};\n\n\t/**\n\t * Returns a destructured version of this Entity, where child\n\t * Entities are accessible at their respective keys.\n\t */\n\tgetAll = (): KeyValue => {\n\t\treturn this.view;\n\t};\n\n\tdelete = (key: any) => {\n\t\tif (this.isList) {\n\t\t\tassertNumber(key);\n\t\t\tthis.addPendingOperations(\n\t\t\t\tthis.patchCreator.createListDelete(this.oid, key),\n\t\t\t);\n\t\t} else {\n\t\t\t// the key must be deletable - i.e. optional in the schema.\n\t\t\tconst deleteMode = this.getDeleteMode(key);\n\t\t\tif (!deleteMode) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot delete key ${key.toString()} - the property is not marked as optional in the schema.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (deleteMode === 'delete') {\n\t\t\t\tthis.addPendingOperations(\n\t\t\t\t\tthis.patchCreator.createRemove(this.oid, key),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthis.addPendingOperations(\n\t\t\t\t\tthis.patchCreator.createSet(this.oid, key, null),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n\n\t// object entity methods\n\tkeys = (): string[] => {\n\t\tif (!this.view) return [];\n\t\treturn Object.keys(this.view);\n\t};\n\n\tentries = (): [string, Exclude<KeyValue[keyof KeyValue], undefined>][] => {\n\t\tif (!this.view) return [];\n\t\treturn Object.entries(this.view);\n\t};\n\n\tvalues = (): Exclude<KeyValue[keyof KeyValue], undefined>[] => {\n\t\tif (!this.view) return [];\n\t\treturn Object.values(this.view);\n\t};\n\n\tget size() {\n\t\tif (this.isList) {\n\t\t\treturn this.length;\n\t\t}\n\t\treturn this.keys().length;\n\t}\n\n\tupdate = (\n\t\tdata: any,\n\t\t{\n\t\t\tmerge = true,\n\t\t\treplaceSubObjects = false,\n\t\t\tpreserveUndefined = false,\n\t\t}: {\n\t\t\treplaceSubObjects?: boolean;\n\t\t\tmerge?: boolean;\n\t\t\tpreserveUndefined?: boolean;\n\t\t} = {},\n\t): void => {\n\t\tif (!merge && this.schema.type !== 'any' && this.schema.type !== 'map') {\n\t\t\tthrow new Error(\n\t\t\t\t'Cannot use .update without merge if the field has a strict schema type. merge: false is only available on \"any\" or \"map\" types.',\n\t\t\t);\n\t\t}\n\t\tconst changes: any = {};\n\t\tassignOid(changes, this.oid);\n\t\tfor (const [key, field] of Object.entries(data)) {\n\t\t\tif (this.readonlyKeys.includes(key as any)) {\n\t\t\t\tthrow new Error(`Cannot set readonly key ${key.toString()}`);\n\t\t\t}\n\t\t\t// ignore undefined values unless overridden\n\t\t\tif (field === undefined && !preserveUndefined) continue;\n\n\t\t\tconst fieldSchema = getChildFieldSchema(this.schema, key);\n\t\t\tif (fieldSchema) {\n\t\t\t\ttraverseCollectionFieldsAndApplyDefaults(field, fieldSchema);\n\t\t\t}\n\t\t\tchanges[key] = this.processInputValue(field, key);\n\t\t}\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createDiff(this.getSnapshot(), changes, {\n\t\t\t\tmergeUnknownObjects: !replaceSubObjects,\n\t\t\t\tdefaultUndefined: merge,\n\t\t\t}),\n\t\t);\n\t};\n\n\t// array entity methods\n\tget length(): number {\n\t\treturn this.view.length;\n\t}\n\n\tpush = (value: ListItemInit<Init>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListPush(\n\t\t\t\tthis.oid,\n\t\t\t\tthis.processInputValue(value, this.view.length),\n\t\t\t),\n\t\t);\n\t};\n\n\tinsert = (index: number, value: ListItemInit<Init>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListInsert(\n\t\t\t\tthis.oid,\n\t\t\t\tindex,\n\t\t\t\tthis.processInputValue(value, index),\n\t\t\t),\n\t\t);\n\t};\n\n\tmove = (from: number, to: number): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListMoveByIndex(this.oid, from, to),\n\t\t);\n\t};\n\n\tmoveItem = (item: ListItemValue<KeyValue>, to: number): void => {\n\t\tconst itemRef = this.getItemRefValue(item);\n\t\tif (isRef(itemRef)) {\n\t\t\tthis.addPendingOperations(\n\t\t\t\tthis.patchCreator.createListMoveByRef(this.oid, itemRef, to),\n\t\t\t);\n\t\t} else {\n\t\t\tconst index = this.view.indexOf(item);\n\t\t\tif (index === -1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot move item ${JSON.stringify(\n\t\t\t\t\t\titem,\n\t\t\t\t\t)} which does not exist in this list`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.move(index, to);\n\t\t}\n\t};\n\n\tadd = (value: ListItemValue<KeyValue>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListAdd(\n\t\t\t\tthis.oid,\n\t\t\t\tthis.processInputValue(value, this.view.length),\n\t\t\t),\n\t\t);\n\t};\n\n\tremoveAll = (item: ListItemValue<KeyValue>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListRemove(this.oid, this.getItemRefValue(item)),\n\t\t);\n\t};\n\n\tremoveFirst = (item: ListItemValue<KeyValue>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListRemove(\n\t\t\t\tthis.oid,\n\t\t\t\tthis.getItemRefValue(item),\n\t\t\t\t'first',\n\t\t\t),\n\t\t);\n\t};\n\n\tremoveLast = (item: ListItemValue<KeyValue>): void => {\n\t\tthis.addPendingOperations(\n\t\t\tthis.patchCreator.createListRemove(\n\t\t\t\tthis.oid,\n\t\t\t\tthis.getItemRefValue(item),\n\t\t\t\t'last',\n\t\t\t),\n\t\t);\n\t};\n\n\t// list implements an iterator which maps items to wrapped\n\t// versions\n\t[Symbol.iterator]() {\n\t\tlet index = 0;\n\t\tlet length = this.view?.length;\n\t\treturn {\n\t\t\tnext: () => {\n\t\t\t\tif (index < length) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: this.get(index++) as ListItemValue<KeyValue>,\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t} as const;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tvalue: undefined,\n\t\t\t\t\tdone: true,\n\t\t\t\t} as const;\n\t\t\t},\n\t\t};\n\t}\n\n\tmap = <U>(\n\t\tcallback: (value: ListItemValue<KeyValue>, index: number) => U,\n\t): U[] => {\n\t\treturn this.view.map(callback);\n\t};\n\n\tfilter = (\n\t\tcallback: (value: ListItemValue<KeyValue>, index: number) => boolean,\n\t): ListItemValue<KeyValue>[] => {\n\t\treturn this.view.filter(callback);\n\t};\n\n\thas = (value: ListItemValue<KeyValue>): boolean => {\n\t\tif (!this.isList) {\n\t\t\tthrow new Error('has() is only available on list entities');\n\t\t}\n\t\tconst itemRef = this.getItemRefValue(value);\n\t\tif (isRef(itemRef)) {\n\t\t\treturn this.view.some((item: any) => {\n\t\t\t\tif (isRef(item)) {\n\t\t\t\t\treturn compareRefs(item, itemRef);\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\treturn this.view.includes(value);\n\t\t}\n\t};\n\n\tforEach = (\n\t\tcallback: (value: ListItemValue<KeyValue>, index: number) => void,\n\t): void => {\n\t\tthis.view.forEach(callback);\n\t};\n\n\treduce = <U>(\n\t\tcallback: (\n\t\t\tpreviousValue: U,\n\t\t\tcurrentValue: ListItemValue<KeyValue>,\n\t\t\tindex: number,\n\t\t) => U,\n\t\tinitialValue: U,\n\t): U => {\n\t\treturn this.view.reduce(callback, initialValue);\n\t};\n\n\tsome = (predicate: (value: ListItemValue<KeyValue>) => boolean): boolean => {\n\t\treturn this.view.some(predicate);\n\t};\n\n\tevery = (predicate: (value: ListItemValue<KeyValue>) => boolean): boolean => {\n\t\treturn this.view.every(predicate);\n\t};\n\n\tfind = (\n\t\tpredicate: (value: ListItemValue<KeyValue>) => boolean,\n\t): ListItemValue<KeyValue> | undefined => {\n\t\treturn this.view.find(predicate);\n\t};\n\n\tincludes = this.has;\n\n\t/**\n\t * Deletes this entity. WARNING: this can be tricky to\n\t * use correctly. You must not reference this entity\n\t * instance in any way after the deletion happens, or\n\t * you will get an error!\n\t *\n\t * It's a little easier to delete using client.delete\n\t * if you can manage it with your app's code. For example,\n\t * in React, use hooks.useClient() to get the client and\n\t * call delete from there.\n\t */\n\tdeleteSelf = () => {\n\t\treturn this._deleteSelf();\n\t};\n\n\t// TODO: make these escape hatches unnecessary\n\t__getViewData__ = (oid: ObjectIdentifier, type: 'confirmed' | 'pending') => {\n\t\treturn this.metadataFamily.get(oid).computeView(type === 'confirmed');\n\t};\n\t__getFamilyOids__ = () => this.metadataFamily.getAllOids();\n\n\t__discardPendingOperation__ = (operation: Operation) => {\n\t\tthis.metadataFamily.discardPendingOperation(operation);\n\t\tthis.invalidateCachedView();\n\t};\n}\n\nfunction assertNotSymbol<T>(key: T): asserts key is Exclude<T, symbol> {\n\tif (typeof key === 'symbol') throw new Error(\"Symbol keys aren't supported\");\n}\n\nfunction assertNumber(key: unknown): asserts key is number {\n\tif (typeof key !== 'number')\n\t\tthrow new Error('Only number keys are supported in list entities');\n}\n", "import {\n\tDocumentBaseline,\n\tObjectIdentifier,\n\tOperation,\n\tapplyPatch,\n\tareOidsRelated,\n\tassert,\n\tassignOid,\n\tcloneDeep,\n\tcompareTimestampSchemaVersions,\n\tgetWallClockTime,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { EntityChange } from './types.js';\n\nexport type EntityMetadataView = {\n\tview: any;\n\tfromOlderVersion: boolean;\n\tdeleted: boolean;\n\tempty: boolean;\n\tupdatedAt: number;\n\tlatestTimestamp: string | null;\n\tauthz?: string;\n};\n\nexport class EntityMetadata {\n\tprivate ctx;\n\tprivate baseline: DocumentBaseline | null = null;\n\t// these must be kept in timestamp order.\n\tprivate confirmedOperations: Operation[] = [];\n\tprivate pendingOperations: Operation[] = [];\n\treadonly oid;\n\n\tconstructor({\n\t\toid,\n\t\tctx,\n\t\tconfirmedOperations,\n\t\tpendingOperations,\n\t\tbaseline,\n\t}: {\n\t\toid: ObjectIdentifier;\n\t\tctx: Context;\n\t\tconfirmedOperations?: Operation[];\n\t\tpendingOperations?: Operation[];\n\t\tbaseline?: DocumentBaseline;\n\t}) {\n\t\tassert(oid, 'oid is required');\n\t\tthis.ctx = ctx;\n\t\tthis.oid = oid;\n\t\tif (confirmedOperations) {\n\t\t\tthis.confirmedOperations = confirmedOperations;\n\t\t}\n\t\tif (pendingOperations) {\n\t\t\tthis.pendingOperations = pendingOperations;\n\t\t}\n\t\tif (baseline) {\n\t\t\tthis.baseline = baseline;\n\t\t}\n\t}\n\n\t/**\n\t * Compute the current view of the entity.\n\t */\n\tcomputeView = (omitPending = false): EntityMetadataView => {\n\t\tconst base = cloneDeep(this.baseline?.snapshot ?? undefined);\n\t\tconst baselineTimestamp = this.baseline?.timestamp ?? null;\n\n\t\t// start with the baseline authz, if any. further init ops\n\t\t// may overwrite this.\n\t\tlet authz = this.baseline?.authz;\n\n\t\tconst confirmedResult = this.applyOperations(\n\t\t\t// apply ops to baseline\n\t\t\tbase,\n\t\t\t// deleted if there's no baseline\n\t\t\t!base,\n\t\t\t// we're applying confirmed ops first\n\t\t\tthis.confirmedOperations,\n\t\t\t// latest timestamp is the baseline timestamp, if any\n\t\t\tbaselineTimestamp,\n\t\t\t// only apply ops after the baseline timestamp\n\t\t\tbaselineTimestamp,\n\t\t);\n\t\t// now's the time to declare we saw the future if we did.\n\t\tif (confirmedResult.futureSeen) {\n\t\t\tthis.ctx.globalEvents.emit('futureSeen', confirmedResult.futureSeen);\n\t\t}\n\t\tif (confirmedResult.authz) {\n\t\t\tauthz = confirmedResult.authz;\n\t\t}\n\n\t\tconst pendingResult = omitPending\n\t\t\t? confirmedResult\n\t\t\t: this.applyOperations(\n\t\t\t\t\tconfirmedResult.view,\n\t\t\t\t\tconfirmedResult.deleted,\n\t\t\t\t\t// now we're applying pending operations\n\t\t\t\t\tthis.pendingOperations,\n\t\t\t\t\t// keep our latest timestamp up to date\n\t\t\t\t\tconfirmedResult.latestTimestamp,\n\t\t\t\t\t// we don't use after for pending ops, they're all\n\t\t\t\t\t// logically in the future\n\t\t\t\t\tnull,\n\t\t\t );\n\t\tif (pendingResult.authz) {\n\t\t\tauthz = pendingResult.authz;\n\t\t}\n\n\t\t// before letting this data out into the wild, we need\n\t\t// to associate its oid\n\t\tif (pendingResult.view) {\n\t\t\tassignOid(pendingResult.view, this.oid);\n\t\t}\n\n\t\t// note whether confirmed data has an operation/baseline from the current\n\t\t// schema or not.\n\t\tconst fromOlderVersion =\n\t\t\t!!confirmedResult.latestTimestamp &&\n\t\t\tcompareTimestampSchemaVersions(\n\t\t\t\tconfirmedResult.latestTimestamp,\n\t\t\t\tthis.ctx.getNow(),\n\t\t\t) < 0;\n\n\t\tconst empty =\n\t\t\t!this.baseline &&\n\t\t\t!this.pendingOperations.length &&\n\t\t\t!this.confirmedOperations.length;\n\t\tif (empty) {\n\t\t\tthis.ctx.log('warn', `Tried to load Entity ${this.oid} with no data`);\n\t\t}\n\n\t\tconst updatedAtTimestamp =\n\t\t\tpendingResult.latestTimestamp ??\n\t\t\tconfirmedResult.latestTimestamp ??\n\t\t\tbaselineTimestamp;\n\t\tconst updatedAt = updatedAtTimestamp\n\t\t\t? getWallClockTime(updatedAtTimestamp)\n\t\t\t: 0;\n\n\t\tif (!pendingResult.view && !pendingResult.deleted && !empty) {\n\t\t\tthis.ctx.log(\n\t\t\t\t'warn',\n\t\t\t\t`Entity ${this.oid} has no view, no deleted flag, and not empty`,\n\t\t\t);\n\t\t\tdebugger;\n\t\t}\n\n\t\treturn {\n\t\t\tview: pendingResult.view ?? undefined,\n\t\t\tdeleted: pendingResult.deleted,\n\t\t\tempty,\n\t\t\tfromOlderVersion,\n\t\t\tupdatedAt,\n\t\t\tlatestTimestamp: updatedAtTimestamp,\n\t\t\tauthz,\n\t\t};\n\t};\n\n\taddBaseline = (baseline: DocumentBaseline): void => {\n\t\t// opt out if our baseline is newer\n\t\tif (this.baseline && this.baseline.timestamp >= baseline.timestamp) {\n\t\t\treturn;\n\t\t}\n\t\tthis.baseline = baseline;\n\t\t// we can now drop any confirmed ops older than the baseline\n\t\twhile (this.confirmedOperations[0]?.timestamp < baseline.timestamp) {\n\t\t\tthis.confirmedOperations.shift();\n\t\t}\n\t};\n\n\t/**\n\t * @returns total number of new operations added\n\t */\n\taddConfirmedOperations = (operations: Operation[]): number => {\n\t\tlet totalAdded = 0;\n\t\t// the operations must be inserted in timestamp order\n\t\tfor (const op of operations) {\n\t\t\tconst index = this.confirmedOperations.findIndex(\n\t\t\t\t(o) => o.timestamp >= op.timestamp,\n\t\t\t);\n\t\t\tif (index !== -1) {\n\t\t\t\t// ensure we don't have a duplicate\n\t\t\t\tif (this.confirmedOperations[index].timestamp !== op.timestamp) {\n\t\t\t\t\t// otherwise, insert at the right place\n\t\t\t\t\tthis.confirmedOperations.splice(index, 0, op);\n\t\t\t\t\ttotalAdded++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// otherwise, append\n\t\t\t\tthis.confirmedOperations.push(op);\n\t\t\t\ttotalAdded++;\n\t\t\t}\n\t\t\t// FIXME: seems inefficient\n\t\t\t// remove this incoming op from pending if it's in there\n\t\t\tconst pendingPrior = this.pendingOperations.length;\n\t\t\tthis.discardPendingOperation(op);\n\t\t\ttotalAdded -= pendingPrior - this.pendingOperations.length;\n\t\t}\n\t\treturn totalAdded;\n\t};\n\n\taddPendingOperation = (operation: Operation) => {\n\t\t// check to see if new operation supersedes the previous one\n\t\t// we can assume pending ops are always newer\n\t\tthis.pendingOperations.push(operation);\n\t};\n\n\tdiscardPendingOperation = (operation: Operation) => {\n\t\tthis.pendingOperations = this.pendingOperations.filter(\n\t\t\t(op) => op.timestamp !== operation.timestamp,\n\t\t);\n\t};\n\n\tprivate applyOperations = (\n\t\tbase: any,\n\t\tdeleted: boolean,\n\t\toperations: Operation[],\n\t\tlatestTimestamp: string | null,\n\t\tafter: string | null,\n\t): {\n\t\tview: any;\n\t\tlatestTimestamp: string | null;\n\t\tdeleted: boolean;\n\t\tfutureSeen: string | undefined;\n\t\tauthz?: string;\n\t} => {\n\t\tlet futureSeen: string | undefined = undefined;\n\t\tlet authz: string | undefined = undefined;\n\n\t\tconst now = this.ctx.getNow();\n\t\tfor (const op of operations) {\n\t\t\t// ignore ops before our after cutoff\n\t\t\tif (after && op.timestamp <= after) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// don't apply future ops\n\t\t\tif (compareTimestampSchemaVersions(op.timestamp, now) > 0) {\n\t\t\t\tfutureSeen = op.timestamp;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// we don't actually delete the view when a delete op\n\t\t\t// comes in. the view remains useful for calculating\n\t\t\t// undo operations.\n\t\t\tif (op.data.op === 'delete') {\n\t\t\t\tdeleted = true;\n\t\t\t} else {\n\t\t\t\tbase = applyPatch(base, op.data);\n\t\t\t\tif (op.data.op === 'initialize') {\n\t\t\t\t\tdeleted = false;\n\t\t\t\t\tif (op.authz) {\n\t\t\t\t\t\tauthz = op.authz;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// track the latest timestamp\n\t\t\tif (!latestTimestamp || op.timestamp > latestTimestamp) {\n\t\t\t\tlatestTimestamp = op.timestamp;\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tview: base,\n\t\t\tlatestTimestamp: latestTimestamp ?? null,\n\t\t\tdeleted,\n\t\t\tfutureSeen,\n\t\t\tauthz,\n\t\t};\n\t};\n}\n\n/**\n * Represents the metadata for a group of entities underneath a Document.\n * Metadata is separated out this way so that these classes can be\n * garbage collected when the root Document goes out of scope.\n */\nexport class EntityFamilyMetadata {\n\tprivate ctx;\n\tprivate entities: Map<ObjectIdentifier, EntityMetadata> = new Map();\n\tprivate onPendingOperations;\n\tprivate rootOid: ObjectIdentifier;\n\n\tconstructor({\n\t\tctx,\n\t\tonPendingOperations,\n\t\trootOid,\n\t}: {\n\t\tctx: Context;\n\t\tonPendingOperations: (ops: Operation[]) => void;\n\t\trootOid: ObjectIdentifier;\n\t}) {\n\t\tthis.ctx = ctx;\n\t\tthis.rootOid = rootOid;\n\t\tthis.onPendingOperations = onPendingOperations;\n\t}\n\n\tget = (oid: ObjectIdentifier) => {\n\t\tassert(oid, 'oid is required');\n\t\tif (!this.entities.has(oid)) {\n\t\t\tthis.entities.set(oid, new EntityMetadata({ oid, ctx: this.ctx }));\n\t\t}\n\t\treturn this.entities.get(oid)!;\n\t};\n\n\tgetAllOids = () => {\n\t\treturn Array.from(this.entities.keys());\n\t};\n\n\taddConfirmedData = ({\n\t\tbaselines = [],\n\t\toperations = {},\n\t\tisLocal = false,\n\t}: {\n\t\tbaselines?: DocumentBaseline[];\n\t\toperations?: Record<ObjectIdentifier, Operation[]>;\n\t\tisLocal?: boolean;\n\t}) => {\n\t\tconst changes: Record<ObjectIdentifier, EntityChange> = {};\n\t\tfor (const baseline of baselines) {\n\t\t\tif (!areOidsRelated(this.rootOid, baseline.oid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid baseline for entity ${this.rootOid}: ` +\n\t\t\t\t\t\tJSON.stringify(baseline),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.get(baseline.oid).addBaseline(baseline);\n\t\t}\n\t\tfor (const [oid, ops] of Object.entries(operations)) {\n\t\t\tif (!areOidsRelated(this.rootOid, oid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid operations for entity ${this.rootOid}: ` +\n\t\t\t\t\t\tJSON.stringify(ops),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst added = this.get(oid).addConfirmedOperations(ops);\n\t\t\tif (added !== 0) {\n\t\t\t\tchanges[oid] ??= { oid, isLocal };\n\t\t\t}\n\t\t}\n\t\treturn Object.values(changes);\n\t};\n\n\t/**\n\t * Adds local, unconfirmed operations to the system.\n\t * The API is different here to streamline for the way\n\t * local changes are usually handled, as a list.\n\t */\n\taddPendingData = (operations: Operation[]) => {\n\t\tconst changes: Record<ObjectIdentifier, EntityChange> = {};\n\t\tfor (const op of operations) {\n\t\t\tthis.get(op.oid).addPendingOperation(op);\n\t\t\tchanges[op.oid] ??= { oid: op.oid, isLocal: true };\n\t\t}\n\t\tthis.onPendingOperations(operations);\n\t\treturn Object.values(changes);\n\t};\n\n\treplaceAllData = ({\n\t\toperations = {},\n\t\tbaselines = [],\n\t}: {\n\t\toperations?: Record<ObjectIdentifier, Operation[]>;\n\t\tbaselines?: DocumentBaseline[];\n\t}) => {\n\t\tconst oids = Array.from(this.entities.keys());\n\t\tthis.entities.clear();\n\t\tconst changes: Record<ObjectIdentifier, EntityChange> = {};\n\t\t// changes apply to all the entities we removed things from, too\n\t\tfor (const oid of oids) {\n\t\t\tchanges[oid] = { oid, isLocal: false };\n\t\t}\n\t\tfor (const baseline of baselines) {\n\t\t\tif (!areOidsRelated(this.rootOid, baseline.oid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid baseline for entity ${this.rootOid}: ` +\n\t\t\t\t\t\tJSON.stringify(baseline),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.get(baseline.oid).addBaseline(baseline);\n\t\t\tchanges[baseline.oid] ??= { oid: baseline.oid, isLocal: false };\n\t\t}\n\t\tfor (const [oid, ops] of Object.entries(operations)) {\n\t\t\tif (!areOidsRelated(this.rootOid, oid)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid operations for entity ${this.rootOid}: ` +\n\t\t\t\t\t\tJSON.stringify(ops),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.get(oid).addConfirmedOperations(ops);\n\t\t\tchanges[oid] ??= { oid, isLocal: false };\n\t\t}\n\t\treturn Object.values(changes);\n\t};\n\n\tdiscardPendingOperation = (operation: Operation) => {\n\t\tconst ent = this.entities.get(operation.oid);\n\t\tent?.discardPendingOperation(operation);\n\t};\n}\n", "import {\n\tBatcher,\n\tObjectIdentifier,\n\tOperation,\n\tPropertyName,\n\tgenerateId,\n\tgetOidRoot,\n\tgetUndoOperations,\n\tgroupPatchesByOid,\n\tisSuperseded,\n\toperationSupersedes,\n} from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Context } from '../context.js';\nimport type { EntityStore } from './EntityStore.js';\nimport { Entity } from './Entity.js';\n\nconst DEFAULT_BATCH_KEY = '@@default';\n\nexport interface OperationBatch {\n\trun: (fn: () => void) => this;\n\t/** @deprecated - use commit() */\n\tflush: () => Promise<void>;\n\tcommit: () => Promise<void>;\n\tdiscard: () => void;\n}\n\nexport class OperationBatcher {\n\tprivate batcher;\n\tprivate currentBatchKey = DEFAULT_BATCH_KEY;\n\tprivate defaultBatchTimeout: number;\n\tprivate meta;\n\tprivate ctx;\n\tprivate entities;\n\n\tconstructor({\n\t\tbatchTimeout = 200,\n\t\tmeta,\n\t\tctx,\n\t\tentities,\n\t}: {\n\t\tbatchTimeout?: number;\n\t\tmeta: Metadata;\n\t\tctx: Context;\n\t\tentities: EntityStore;\n\t}) {\n\t\tthis.meta = meta;\n\t\tthis.ctx = ctx;\n\t\tthis.entities = entities;\n\t\tthis.defaultBatchTimeout = batchTimeout;\n\t\tthis.batcher = new Batcher<Operation, { undoable?: boolean }>(\n\t\t\tthis.flushOperations,\n\t\t);\n\t\tthis.batcher.add({\n\t\t\tkey: DEFAULT_BATCH_KEY,\n\t\t\titems: [],\n\t\t\tmax: 100,\n\t\t\ttimeout: batchTimeout,\n\t\t\tuserData: { undoable: true },\n\t\t});\n\t}\n\n\tget isDefaultBatch() {\n\t\treturn this.currentBatchKey === DEFAULT_BATCH_KEY;\n\t}\n\n\tprivate flushOperations = async (\n\t\toperations: Operation[],\n\t\tbatchKey: string,\n\t\tmeta: { undoable?: boolean },\n\t) => {\n\t\tthis.ctx.log(\n\t\t\t'debug',\n\t\t\t'Flushing',\n\t\t\toperations.length,\n\t\t\t'operations from batch',\n\t\t\tbatchKey,\n\t\t\t'to storage / sync',\n\t\t);\n\t\tif (!operations.length) return;\n\n\t\t// next block of logic computes superseding rules to eliminate\n\t\t// operations which are 'overshadowed' by later ones on the same\n\t\t// key.\n\n\t\tconst committed: Operation[] = [];\n\t\tconst supersessions: Record<\n\t\t\tObjectIdentifier,\n\t\t\tSet<boolean | PropertyName>\n\t\t> = {};\n\t\tfor (let i = operations.length - 1; i >= 0; i--) {\n\t\t\tconst op = operations[i];\n\n\t\t\t// check for supersession from later operation which either\n\t\t\t// covers the whole id (true) or this key\n\t\t\tconst existingSupersession = supersessions[op.oid];\n\t\t\tif (existingSupersession && isSuperseded(op, existingSupersession)) {\n\t\t\t\tthis.entities.discardPendingOperation(op);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// determine if this operation supersedes others\n\t\t\tconst supersession = operationSupersedes(op);\n\t\t\tif (supersession !== false) {\n\t\t\t\tif (!supersessions[op.oid]) {\n\t\t\t\t\tsupersessions[op.oid] = new Set<boolean | PropertyName>();\n\t\t\t\t}\n\t\t\t\tsupersessions[op.oid]!.add(supersession);\n\t\t\t}\n\n\t\t\t// add this operation to final list\n\t\t\tcommitted.unshift(op);\n\t\t}\n\n\t\t// rewrite timestamps of all operations to now - this preserves\n\t\t// the linear history of operations which are sent to the server.\n\t\t// even if multiple batches are spun up in parallel and flushed\n\t\t// after delay, the final operations in each one should reflect\n\t\t// when the batch flushed, not when the changes were made.\n\t\t// This also corresponds to user-observed behavior, since unconfirmed\n\t\t// operations are applied universally after confirmed operations locally,\n\t\t// so even operations which were made before a remote operation but\n\t\t// have not been confirmed yet will appear to come after the remote one\n\t\t// despite the provisional timestamp being earlier\n\t\t// NOTE: this MUST be mutating the original operation object! this timestamp\n\t\t// also serves as a unique ID for deduplication later.\n\n\t\t// NOTE: need to rewind back in order to set timestamps correctly.\n\t\t// cannot be done in reversed loop above or timestamps would be\n\t\t// in reverse order.\n\t\tfor (const op of committed) {\n\t\t\top.timestamp = this.meta.now;\n\t\t}\n\t\tawait this.commitOperations(committed, meta);\n\t};\n\n\t/**\n\t * Immediately flushes operations to storage / sync.\n\t * Providing source to second arg skips hydrating related\n\t * Entity from storage, which is useful when that Entity\n\t * isn't in storage (i.e. still creating) or just to speed\n\t * up the commit.\n\t */\n\tcommitOperations = async (\n\t\toperations: Operation[],\n\t\tmeta: { undoable?: boolean; source?: Entity },\n\t) => {\n\t\tif (!operations.length) return;\n\t\t// now is the time to decide on what the undo operations will\n\t\t// look like, based on the confirmed view of the related entities.\n\t\tif (meta.undoable) {\n\t\t\tconst undo = await this.createUndo({\n\t\t\t\tops: operations,\n\t\t\t\tsource: meta.source,\n\t\t\t});\n\t\t\tif (undo) this.ctx.undoHistory.addUndo(undo);\n\t\t}\n\t\t// ship it out to EntityStore to compute final snapshots\n\t\t// write to storage and refresh entities and queries\n\t\tawait this.entities.addData({\n\t\t\toperations,\n\t\t\tbaselines: [],\n\t\t\tisLocal: true,\n\t\t});\n\t};\n\n\t/**\n\t * Adds operations to the active batch.\n\t */\n\taddOperations = (operations: Operation[]) => {\n\t\tif (!operations.length) return;\n\t\tthis.batcher.add({\n\t\t\tkey: this.currentBatchKey,\n\t\t\titems: operations,\n\t\t});\n\t\tthis.ctx.log(\n\t\t\t`debug`,\n\t\t\t'added',\n\t\t\toperations.length,\n\t\t\t'ops to batch',\n\t\t\tthis.currentBatchKey,\n\t\t\t', size = ',\n\t\t\tthis.batcher.getSize(this.currentBatchKey),\n\t\t);\n\t};\n\n\tbatch = ({\n\t\tundoable = true,\n\t\tbatchName = generateId(),\n\t\tmax = null,\n\t\ttimeout = this.defaultBatchTimeout,\n\t}: {\n\t\t/** Allows turning off undo for this batch, making it 'permanent' */\n\t\tundoable?: boolean;\n\t\t/**\n\t\t * Provide a stable name to any invocation of .batch() and the changes made\n\t\t * within run() will all be added to the same batch. If a batch hits the max\n\t\t * limit or timeout and is flushed, the name will be reused for a new batch\n\t\t * automatically. Provide a stable name to make changes from anywhere in your\n\t\t * app to be grouped together in the same batch with the same limit behavior.\n\t\t *\n\t\t * Limit configuration provided to each invocation of .batch() with the same\n\t\t * name will overwrite any other invocation's limit configuration. It's\n\t\t * recommended to provide limits in one place and only provide a name\n\t\t * in others.\n\t\t */\n\t\tbatchName?: string;\n\t\t/**\n\t\t * The maximum number of operations the batch will hold before flushing\n\t\t * automatically. If null, the batch will not flush automatically based\n\t\t * on operation count.\n\t\t */\n\t\tmax?: number | null;\n\t\t/**\n\t\t * The number of milliseconds to wait before flushing the batch automatically.\n\t\t * If null, the batch will not flush automatically based on time. It is not\n\t\t * recommended to set this to null, as an unflushed batch will never be written\n\t\t * to storage or sync. If you do require undefined timing in a batch, make sure\n\t\t * to always call .commit() on the batch yourself.\n\t\t */\n\t\ttimeout?: number | null;\n\t} = {}): OperationBatch => {\n\t\tconst internalBatch = this.batcher.add({\n\t\t\tkey: batchName,\n\t\t\tmax,\n\t\t\ttimeout,\n\t\t\titems: [],\n\t\t\tuserData: { undoable },\n\t\t});\n\t\tconst externalApi = {\n\t\t\trun: (fn: () => void) => {\n\t\t\t\t// while the provided function runs, operations are forwarded\n\t\t\t\t// to the new batch instead of default. this relies on the function\n\t\t\t\t// being synchronous.\n\t\t\t\tthis.currentBatchKey = batchName;\n\t\t\t\tfn();\n\t\t\t\tthis.currentBatchKey = DEFAULT_BATCH_KEY;\n\t\t\t\treturn externalApi;\n\t\t\t},\n\t\t\tcommit: async () => {\n\t\t\t\t// before running a batch, the default operations must be flushed\n\t\t\t\t// this better preserves undo history behavior...\n\t\t\t\t// if we left the default batch open while flushing a named batch,\n\t\t\t\t// then the default batch would be flushed after the named batch,\n\t\t\t\t// and the default batch could contain operations both prior and\n\t\t\t\t// after the named batch. this would result in a confusing undo\n\t\t\t\t// history where the first undo might reverse changes before and\n\t\t\t\t// after a set of other changes.\n\t\t\t\tawait this.batcher.flush(DEFAULT_BATCH_KEY);\n\t\t\t\treturn internalBatch.flush();\n\t\t\t},\n\t\t\tflush: () => externalApi.commit(),\n\t\t\tdiscard: () => {\n\t\t\t\tthis.batcher.discard(batchName);\n\t\t\t},\n\t\t};\n\t\treturn externalApi;\n\t};\n\n\tflushAll = () => Promise.all(this.batcher.flushAll());\n\n\tprivate createUndo = async (data: { ops: Operation[]; source?: Entity }) => {\n\t\t// this can't be done on-demand because we rely on the current\n\t\t// state of the entities to calculate the inverse operations.\n\t\tconst inverseOps = await this.getInverseOperations(data);\n\n\t\tif (!inverseOps.length) return null;\n\n\t\treturn async () => {\n\t\t\tconst redo = await this.createUndo({\n\t\t\t\tops: inverseOps,\n\t\t\t\tsource: data.source,\n\t\t\t});\n\t\t\t// set time to now for all undo operations, they're happening now.\n\t\t\tfor (const op of inverseOps) {\n\t\t\t\top.timestamp = this.meta.now;\n\t\t\t}\n\t\t\tawait this.commitOperations(\n\t\t\t\tinverseOps,\n\t\t\t\t// undos should not generate their own undo operations\n\t\t\t\t// since they already calculate redo as the inverse.\n\t\t\t\t{ undoable: false },\n\t\t\t);\n\t\t\treturn redo;\n\t\t};\n\t};\n\tprivate getInverseOperations = async ({\n\t\tops,\n\t\tsource,\n\t}: {\n\t\tops: Operation[];\n\t\tsource?: Entity;\n\t}) => {\n\t\tconst grouped = groupPatchesByOid(ops);\n\t\tconst inverseOps: Operation[] = [];\n\t\tconst getNow = () => this.meta.now;\n\t\tawait Promise.all(\n\t\t\tObject.entries(grouped).map(async ([oid, patches]): Promise<void> => {\n\t\t\t\tconst entity = source ?? (await this.entities.hydrate(getOidRoot(oid)));\n\t\t\t\t// TODO: this is getting the rebased baseline? how? are ops being submitted early?\n\t\t\t\tconst viewData = entity?.__getViewData__(oid, 'confirmed');\n\t\t\t\tif (!viewData) {\n\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t'warn',\n\t\t\t\t\t\t'could not find entity',\n\t\t\t\t\t\toid,\n\t\t\t\t\t\t'for undo operation',\n\t\t\t\t\t\tops,\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst inverse = getUndoOperations(oid, viewData.view, patches, getNow);\n\t\t\t\tinverseOps.unshift(...inverse);\n\t\t\t}),\n\t\t);\n\t\treturn inverseOps;\n\t};\n}\n", "import {\n\tObjectIdentifier,\n\tdecomposeOid,\n\tgetIndexValues,\n} from '@verdant-web/common';\nimport { IDBService } from '../IDBService.js';\nimport { Context } from '../context.js';\nimport { storeRequestPromise } from '../idb.js';\n\nexport class QueryableStorage extends IDBService {\n\tprivate ctx;\n\n\tconstructor({ ctx }: { ctx: Context }) {\n\t\tsuper(ctx.documentDb, { log: ctx.log });\n\t\tthis.ctx = ctx;\n\t\tthis.addDispose(\n\t\t\tthis.ctx.internalEvents.subscribe('documentDbChanged', (db) => {\n\t\t\t\tthis.db = db;\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * DELETES EVERYTHING IN THE QUERYABLE DATABASE\n\t */\n\treset = async () => {\n\t\tconst allCollections = Object.keys(this.ctx.schema.collections);\n\t\tconst tx = this.createTransaction(allCollections, { mode: 'readwrite' });\n\t\tawait Promise.all(\n\t\t\tallCollections.map((collection) => {\n\t\t\t\tconst store = tx.objectStore(collection);\n\t\t\t\treturn storeRequestPromise(store.clear());\n\t\t\t}),\n\t\t);\n\t\t// notify queries to re-run now.\n\t\tthis.ctx.entityEvents.emit('collectionsChanged', allCollections);\n\t\tthis.ctx.log('info', '\uD83D\uDCA8 Reset queryable storage');\n\t};\n\n\tsaveEntities = async (\n\t\tentities: { oid: ObjectIdentifier; getSnapshot: () => any }[],\n\t\topts?: { abort?: AbortSignal },\n\t) => {\n\t\tif (entities.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet collections = Array.from(\n\t\t\tnew Set(entities.map((e) => decomposeOid(e.oid).collection)),\n\t\t);\n\t\t// we could theoretically receive entities from old schema versions which no\n\t\t// longer have collections. We should ignore these. If we don't, the transaction\n\t\t// will fail, because the object store doesn't exist.\n\t\tconst toRemove = collections.filter((c) => !this.ctx.schema.collections[c]);\n\t\tif (toRemove.length > 0) {\n\t\t\tthis.ctx.log(\n\t\t\t\t'warn',\n\t\t\t\t`Ignoring entities from collections that no longer exist: ${toRemove.join(\n\t\t\t\t\t', ',\n\t\t\t\t)}`,\n\t\t\t);\n\t\t\tconst withRemoved = new Set(collections);\n\t\t\ttoRemove.forEach((c) => withRemoved.delete(c));\n\t\t\tcollections = Array.from(withRemoved);\n\t\t}\n\t\tconst options = {\n\t\t\ttransaction: this.createTransaction(collections, {\n\t\t\t\tmode: 'readwrite',\n\t\t\t\tabort: opts?.abort,\n\t\t\t}),\n\t\t};\n\t\tawait Promise.all(\n\t\t\tentities.map(async (e) => {\n\t\t\t\tconst snapshot = e.getSnapshot();\n\t\t\t\ttry {\n\t\t\t\t\tawait this.saveDocument(e.oid, snapshot, options);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tthis.ctx.log(\n\t\t\t\t\t\t'error',\n\t\t\t\t\t\t`Error saving document ${e.oid} (${JSON.stringify(snapshot)})`,\n\t\t\t\t\t\terr,\n\t\t\t\t\t);\n\t\t\t\t\tif (err instanceof Error) {\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('Unknown error saving document');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\toptions.transaction.commit();\n\t\tthis.ctx.entityEvents.emit('collectionsChanged', collections);\n\t\tfor (const entity of entities) {\n\t\t\tthis.ctx.entityEvents.emit('documentChanged', entity.oid);\n\t\t}\n\t};\n\n\tprivate saveDocument = async (\n\t\toid: ObjectIdentifier,\n\t\tdoc: any,\n\t\t{ transaction }: { transaction?: IDBTransaction },\n\t) => {\n\t\tthis.ctx.log('debug', `Saving document indexes for querying ${oid}`, doc);\n\t\tconst { collection, id } = decomposeOid(oid);\n\t\tif (!doc) {\n\t\t\tawait this.run(collection, (store) => store.delete(id), {\n\t\t\t\tmode: 'readwrite',\n\t\t\t\ttransaction,\n\t\t\t});\n\t\t\tthis.ctx.log('debug', `Deleted document indexes for querying ${oid}`);\n\t\t} else {\n\t\t\tconst schema = this.ctx.schema.collections[collection];\n\t\t\t// no need to validate before storing; the entity's snapshot is already validated.\n\t\t\tconst indexes = getIndexValues(schema, doc);\n\t\t\tawait this.run(collection, (store) => store.put(indexes), {\n\t\t\t\tmode: 'readwrite',\n\t\t\t\ttransaction,\n\t\t\t});\n\t\t\tthis.ctx.log('debug', `Saved document indexes for querying ${oid}`, doc);\n\t\t}\n\t};\n}\n", "import {\n\tDocumentBaseline,\n\tObjectIdentifier,\n\tOperation,\n\tStorageFieldsSchema,\n\tStorageObjectFieldSchema,\n\tassert,\n\tassignOid,\n\tdecomposeOid,\n\tgetOidRoot,\n\tgroupBaselinesByRootOid,\n\tgroupPatchesByOid,\n\tgroupPatchesByRootOid,\n\tisRootOid,\n\tremoveOidsFromAllSubObjects,\n\tAuthorizationKey,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Entity } from './Entity.js';\nimport { Disposable } from '../utils/Disposable.js';\nimport { EntityFamilyMetadata } from './EntityMetadata.js';\nimport { FileManager } from '../files/FileManager.js';\nimport { OperationBatcher } from './OperationBatcher.js';\nimport { QueryableStorage } from '../queries/QueryableStorage.js';\nimport { WeakEvent } from 'weak-event';\nimport { processValueFiles } from '../files/utils.js';\n\nenum AbortReason {\n\tReset,\n}\n\nexport type EntityStoreEventData = {\n\toid: ObjectIdentifier;\n\toperations?: Record<string, Operation[]>;\n\tbaselines?: DocumentBaseline[];\n\tisLocal: boolean;\n};\n\nexport type EntityStoreEvents = {\n\tadd: WeakEvent<EntityStore, EntityStoreEventData>;\n\treplace: WeakEvent<EntityStore, EntityStoreEventData>;\n\tresetAll: WeakEvent<EntityStore, void>;\n};\n\nexport interface IncomingData {\n\toperations?: Operation[];\n\tbaselines?: DocumentBaseline[];\n\treset?: boolean;\n\tisLocal?: boolean;\n}\n\nexport interface EntityCreateOptions {\n\tundoable?: boolean;\n\taccess?: AuthorizationKey;\n}\n\nexport class EntityStore extends Disposable {\n\tprivate ctx;\n\tprivate meta;\n\tprivate files;\n\tprivate batcher;\n\tprivate queryableStorage;\n\tprivate events: EntityStoreEvents = {\n\t\tadd: new WeakEvent(),\n\t\treplace: new WeakEvent(),\n\t\tresetAll: new WeakEvent(),\n\t};\n\tprivate cache = new Map<ObjectIdentifier, WeakRef<Entity>>();\n\tprivate pendingEntityPromises = new Map<\n\t\tObjectIdentifier,\n\t\tPromise<Entity | null>\n\t>();\n\t// halts the current data queue processing\n\tprivate abortDataQueueController = new AbortController();\n\tprivate ongoingResetPromise: Promise<void> | null = null;\n\tprivate entityFinalizationRegistry = new FinalizationRegistry(\n\t\t(oid: ObjectIdentifier) => {\n\t\t\tthis.ctx.log('debug', 'Entity GC', oid);\n\t\t},\n\t);\n\n\tconstructor({\n\t\tctx,\n\t\tmeta,\n\t\tfiles,\n\t}: {\n\t\tctx: Context;\n\t\tmeta: Metadata;\n\t\tfiles: FileManager;\n\t}) {\n\t\tsuper();\n\n\t\tthis.ctx = ctx;\n\t\tthis.meta = meta;\n\t\tthis.files = files;\n\t\tthis.queryableStorage = new QueryableStorage({ ctx });\n\t\tthis.batcher = new OperationBatcher({\n\t\t\tctx,\n\t\t\tmeta,\n\t\t\tentities: this,\n\t\t});\n\t}\n\n\t// expose batch APIs\n\tget batch() {\n\t\treturn this.batcher.batch;\n\t}\n\tget flushAllBatches() {\n\t\treturn this.batcher.flushAll;\n\t}\n\n\t// internal-ish API to load remote / stored data\n\taddData = async (data: IncomingData) => {\n\t\tif (this.disposed) {\n\t\t\tthis.ctx.log('warn', 'EntityStore is disposed, not adding incoming data');\n\t\t\treturn;\n\t\t}\n\t\t// for resets - abort any other changes, reset everything,\n\t\t// then proceed\n\t\tif (data.reset) {\n\t\t\tthis.ctx.log(\n\t\t\t\t'info',\n\t\t\t\t'Resetting local store to replicate remote synced data - dropping any current transactions',\n\t\t\t);\n\t\t\t// cancel any other ongoing data - it will all\n\t\t\t// be replaced by the reset\n\t\t\tthis.abortDataQueueController.abort(AbortReason.Reset);\n\t\t\tthis.abortDataQueueController = new AbortController();\n\t\t\tthis.ongoingResetPromise = this.resetData().finally(() => {\n\t\t\t\tthis.ongoingResetPromise = null;\n\t\t\t\tthis.ctx.globalEvents.emit('resetToServer');\n\t\t\t});\n\t\t}\n\n\t\t// await either the reset we just started, or any that was\n\t\t// in progress when this data came in.\n\t\tif (this.ongoingResetPromise) {\n\t\t\tthis.ctx.log('debug', 'Waiting for ongoing reset to complete');\n\t\t\tawait this.ongoingResetPromise;\n\t\t\tthis.ctx.log('debug', 'Ongoing reset complete');\n\t\t}\n\n\t\tawait this.processData(data);\n\t};\n\n\tempty = async () => {\n\t\tawait this.queryableStorage.reset();\n\t\tthis.events.resetAll.invoke(this);\n\t\tthis.cache.clear();\n\t};\n\n\tprivate resetData = async () => {\n\t\tif (this.disposed) {\n\t\t\tthis.ctx.log('warn', 'EntityStore is disposed, not resetting local data');\n\t\t\treturn;\n\t\t}\n\t\tawait this.meta.reset();\n\t\tawait this.queryableStorage.reset();\n\t\tthis.events.resetAll.invoke(this);\n\t};\n\n\tprivate processData = async (data: IncomingData) => {\n\t\tif (this.disposed) {\n\t\t\tthis.ctx.log(\n\t\t\t\t'warn',\n\t\t\t\t'EntityStore is disposed, not processing incoming data',\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst baselines = data?.baselines ?? [];\n\t\tconst operations = data?.operations ?? [];\n\n\t\tthis.ctx.log('debug', 'Processing incoming data', {\n\t\t\toperations: operations.length,\n\t\t\tbaselines: baselines.length,\n\t\t\treset: !!data.reset,\n\t\t});\n\n\t\tconst allDocumentOids: ObjectIdentifier[] = Array.from(\n\t\t\tnew Set(\n\t\t\t\tbaselines\n\t\t\t\t\t.map((b) => getOidRoot(b.oid))\n\t\t\t\t\t.concat(operations.map((o) => getOidRoot(o.oid))),\n\t\t\t),\n\t\t);\n\t\tconst baselinesGroupedByOid = groupBaselinesByRootOid(baselines);\n\t\tconst operationsGroupedByOid = groupPatchesByRootOid(operations);\n\n\t\tthis.ctx.log('debug', 'Applying data to live entities');\n\t\t// synchronously add/replace data in any open entities via eventing\n\t\tfor (const oid of allDocumentOids) {\n\t\t\tconst baselines = baselinesGroupedByOid[oid];\n\t\t\tconst operations = operationsGroupedByOid[oid] ?? [];\n\t\t\tconst groupedOperations = groupPatchesByOid(operations);\n\t\t\t// what happens if an entity is being hydrated\n\t\t\t// while this is happening? - we wait for the hydration promise\n\t\t\t// to complete, then invoke the event\n\t\t\tconst event = data.reset ? this.events.replace : this.events.add;\n\t\t\tconst hydrationPromise = this.pendingEntityPromises.get(oid);\n\t\t\tif (hydrationPromise) {\n\t\t\t\thydrationPromise.then(() => {\n\t\t\t\t\tevent.invoke(this, {\n\t\t\t\t\t\toid,\n\t\t\t\t\t\tbaselines,\n\t\t\t\t\t\toperations: groupedOperations,\n\t\t\t\t\t\tisLocal: false,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tevent.invoke(this, {\n\t\t\t\t\toid,\n\t\t\t\t\tbaselines,\n\t\t\t\t\toperations: groupedOperations,\n\t\t\t\t\tisLocal: false,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst abortOptions = {\n\t\t\tabort: this.abortDataQueueController.signal,\n\t\t};\n\n\t\t// then, asynchronously add to the database\n\t\t// this also emits messages to sync\n\t\t// TODO: could messages be sent to sync before storage,\n\t\t// so that realtime is lower latency? What would happen\n\t\t// if the storage failed?\n\t\tawait this.meta.insertData(data, abortOptions);\n\n\t\t// recompute all affected documents for querying\n\t\tconst entities = await Promise.all(\n\t\t\tallDocumentOids.map(async (oid) => {\n\t\t\t\tconst entity = await this.hydrate(oid, abortOptions);\n\t\t\t\t// if the entity is not found, we return a stub that\n\t\t\t\t// indicates it's deleted and should be cleared\n\t\t\t\treturn (\n\t\t\t\t\tentity ?? {\n\t\t\t\t\t\toid,\n\t\t\t\t\t\tgetSnapshot(): any {\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\ttry {\n\t\t\tawait this.queryableStorage.saveEntities(entities, abortOptions);\n\t\t} catch (err) {\n\t\t\tif (this.disposed) {\n\t\t\t\tthis.ctx.log(\n\t\t\t\t\t'warn',\n\t\t\t\t\t'Error saving entities to queryable storage - EntityStore is disposed',\n\t\t\t\t\terr,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthis.ctx.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t'Error saving entities to queryable storage',\n\t\t\t\t\terr,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n\n\t// internal-ish API for creating Entities from OIDs\n\t// when query results come in\n\thydrate = async (\n\t\toid: string,\n\t\topts?: { abort: AbortSignal },\n\t): Promise<Entity | null> => {\n\t\tif (!isRootOid(oid)) {\n\t\t\tthrow new Error('Cannot hydrate non-root entity');\n\t\t}\n\n\t\tif (this.cache.has(oid)) {\n\t\t\tthis.ctx.log('debug', 'Hydrating entity from cache', oid);\n\t\t\tconst cached = this.cache.get(oid);\n\t\t\tif (cached) {\n\t\t\t\tconst entity = cached.deref();\n\t\t\t\tif (entity) {\n\t\t\t\t\tif (entity.deleted) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\treturn entity;\n\t\t\t\t} else {\n\t\t\t\t\tthis.ctx.log('debug', \"Removing GC'd entity from cache\", oid);\n\t\t\t\t\tthis.cache.delete(oid);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// we don't want to hydrate two entities in parallel, so\n\t\t// we use a promise to ensure that only one is ever\n\t\t// constructed at a time\n\t\tconst pendingPromise = this.pendingEntityPromises.get(oid);\n\t\tif (!pendingPromise) {\n\t\t\tthis.ctx.log('debug', 'Hydrating entity from storage', oid);\n\t\t\tconst entity = this.constructEntity(oid);\n\t\t\tif (!entity) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst pendingPromise = this.loadEntity(entity, opts);\n\t\t\tpendingPromise.finally(() => {\n\t\t\t\tthis.pendingEntityPromises.delete(oid);\n\t\t\t});\n\t\t\tthis.pendingEntityPromises.set(oid, pendingPromise);\n\t\t\treturn pendingPromise;\n\t\t} else {\n\t\t\tthis.ctx.log('debug', 'Waiting for entity hydration', oid);\n\t\t\treturn pendingPromise;\n\t\t}\n\t};\n\n\tdestroy = async () => {\n\t\tthis.dispose();\n\t\tawait this.batcher.flushAll();\n\t};\n\n\t// public APIs for manipulating entities\n\n\t/**\n\t * Creates a new Entity with the given initial data.\n\t */\n\tcreate = async (\n\t\tinitial: any,\n\t\toid: ObjectIdentifier,\n\t\t{ undoable = true, access }: EntityCreateOptions = {},\n\t) => {\n\t\tthis.ctx.log('debug', 'Creating new entity', oid);\n\t\tconst { collection } = decomposeOid(oid);\n\t\t// remove any OID associations from the initial data\n\t\tremoveOidsFromAllSubObjects(initial);\n\t\t// grab files and replace them with refs\n\t\tconst processed = processValueFiles(initial, this.files.add);\n\n\t\tassignOid(processed, oid);\n\n\t\t// creating a new Entity with no data, then preloading the operations\n\t\tconst entity = this.constructEntity(oid);\n\t\tif (!entity) {\n\t\t\tthrow new Error(\n\t\t\t\t`Could not put new document: no schema exists for collection ${collection}`,\n\t\t\t);\n\t\t}\n\n\t\tconst operations = this.meta.patchCreator.createInitialize(processed, oid);\n\t\tif (access) {\n\t\t\toperations.forEach((op) => {\n\t\t\t\top.authz = access;\n\t\t\t});\n\t\t}\n\t\tawait this.batcher.commitOperations(operations, {\n\t\t\tundoable: !!undoable,\n\t\t\tsource: entity,\n\t\t});\n\n\t\t// TODONE: what happens if you create an entity with an OID that already\n\t\t// exists?\n\t\t// A: it will overwrite the existing entity\n\n\t\t// we still need to synchronously add the initial operations to the Entity\n\t\t// even though they are flowing through the system\n\t\t// FIXME: this could be better aligned to avoid grouping here\n\t\tconst operationsGroupedByOid = groupPatchesByOid(operations);\n\t\tthis.events.add.invoke(this, {\n\t\t\toperations: operationsGroupedByOid,\n\t\t\tisLocal: true,\n\t\t\toid,\n\t\t});\n\t\tthis.cache.set(oid, this.ctx.weakRef(entity));\n\n\t\treturn entity;\n\t};\n\n\tdeleteAll = async (\n\t\toids: ObjectIdentifier[],\n\t\toptions?: { undoable?: boolean },\n\t) => {\n\t\tthis.ctx.log('info', 'Deleting documents', oids);\n\t\tassert(\n\t\t\toids.every((oid) => oid === getOidRoot(oid)),\n\t\t\t'Only root documents may be deleted via client methods',\n\t\t);\n\n\t\tconst entities = await Promise.all(oids.map((oid) => this.hydrate(oid)));\n\n\t\t// remove the entities from cache\n\t\toids.forEach((oid) => {\n\t\t\tthis.cache.delete(oid);\n\t\t\tthis.ctx.log('debug', 'Deleted document from cache', oid);\n\t\t});\n\n\t\tconst operations: Operation[] = [];\n\t\tfor (const entity of entities) {\n\t\t\tif (entity) {\n\t\t\t\tconst oids = entity.__getFamilyOids__();\n\t\t\t\tconst deletes = this.meta.patchCreator.createDeleteAll(oids);\n\t\t\t\tfor (const op of deletes) {\n\t\t\t\t\top.authz = entity.access;\n\t\t\t\t}\n\t\t\t\toperations.push(...deletes);\n\t\t\t}\n\t\t}\n\n\t\tawait this.batcher.commitOperations(operations, {\n\t\t\tundoable: options?.undoable === undefined ? true : options.undoable,\n\t\t});\n\t};\n\n\tdelete = async (oid: ObjectIdentifier, options?: { undoable?: boolean }) => {\n\t\treturn this.deleteAll([oid], options);\n\t};\n\n\tprivate getCollectionSchema = (\n\t\tcollectionName: string,\n\t): {\n\t\tschema: StorageObjectFieldSchema<any> | null;\n\t\treadonlyKeys: string[];\n\t} => {\n\t\tconst schema = this.ctx.schema.collections[collectionName];\n\t\tif (!schema) {\n\t\t\tthis.ctx.log('warn', `Missing schema for collection: ${collectionName}`);\n\t\t\treturn {\n\t\t\t\tschema: null,\n\t\t\t\treadonlyKeys: [],\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t// convert to object schema for compatibility\n\t\t\tschema: {\n\t\t\t\ttype: 'object',\n\t\t\t\tnullable: false,\n\t\t\t\tproperties: schema.fields as any,\n\t\t\t},\n\t\t\treadonlyKeys: [schema.primaryKey],\n\t\t};\n\t};\n\n\t/**\n\t * Constructs an entity from an OID, but does not load it.\n\t */\n\tprivate constructEntity = (oid: string): Entity | null => {\n\t\tconst { collection } = decomposeOid(oid);\n\t\tconst { schema, readonlyKeys } = this.getCollectionSchema(collection);\n\n\t\tif (!schema) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tthrow new Error('Cannot hydrate entity after store has been disposed');\n\t\t}\n\n\t\tconst metadataFamily = new EntityFamilyMetadata({\n\t\t\tctx: this.ctx,\n\t\t\tonPendingOperations: this.onPendingOperations,\n\t\t\trootOid: oid,\n\t\t});\n\n\t\t// this is created synchronously so it's immediately available\n\t\t// to begin capturing incoming data.\n\t\treturn new Entity({\n\t\t\tctx: this.ctx,\n\t\t\toid,\n\t\t\tschema,\n\t\t\treadonlyKeys,\n\t\t\tfiles: this.files,\n\t\t\tmetadataFamily: metadataFamily,\n\t\t\tpatchCreator: this.meta.patchCreator,\n\t\t\tstoreEvents: this.events,\n\t\t\tdeleteSelf: this.delete.bind(this, oid),\n\t\t});\n\t};\n\n\tprivate onPendingOperations = (operations: Operation[]) => {\n\t\tthis.batcher.addOperations(operations);\n\t};\n\n\tdiscardPendingOperation = (operation: Operation) => {\n\t\tconst root = getOidRoot(operation.oid);\n\t\tthis.cache.get(root)?.deref()?.__discardPendingOperation__(operation);\n\t};\n\n\t/**\n\t * Loads initial Entity data from storage\n\t */\n\tprivate loadEntity = async (\n\t\tentity: Entity,\n\t\topts?: { abort: AbortSignal },\n\t): Promise<Entity | null> => {\n\t\tawait this.loadEntityData(entity, opts);\n\n\t\t// only set the cache after loading.\n\t\t// TODO: is this cache/promise stuff redundant?\n\t\tthis.cache.set(entity.oid, this.ctx.weakRef(entity));\n\t\tthis.entityFinalizationRegistry.register(entity, entity.oid);\n\n\t\treturn entity;\n\t};\n\n\tprivate loadEntityData = async (\n\t\tentity: Entity,\n\t\topts?: { abort: AbortSignal },\n\t) => {\n\t\tconst { operations, baselines } = await this.meta.getDocumentData(\n\t\t\tentity.oid,\n\t\t\topts,\n\t\t);\n\n\t\tif (!baselines.length && !Object.keys(operations).length) {\n\t\t\tthis.ctx.log('debug', 'No data found for entity', entity.oid);\n\t\t\treturn null;\n\t\t}\n\n\t\tthis.ctx.log('debug', 'Loaded entity from storage', entity.oid);\n\n\t\tthis.events.replace.invoke(this, {\n\t\t\toid: entity.oid,\n\t\t\tbaselines,\n\t\t\toperations,\n\t\t\tisLocal: false,\n\t\t});\n\n\t\treturn entity;\n\t};\n\n\t/**\n\t * Drops all entities from the cache. Any entities\n\t * referenced will go 'dead'...\n\t */\n\tclearCache = () => {\n\t\tthis.cache.clear();\n\t};\n}\n", "import { FileData } from '@verdant-web/common';\nimport { IDBService } from '../IDBService.js';\nimport { fileToArrayBuffer } from './utils.js';\nimport { getAllFromObjectStores, getSizeOfObjectStore } from '../idb.js';\n\n/**\n * When stored in IDB, replace the file blob with an array buffer\n * since it's more compatible, and replace remote boolean with\n * a string since IDB doesn't support boolean indexes.\n */\nexport interface StoredFileData extends Omit<FileData, 'remote' | 'file'> {\n\tremote: 'true' | 'false';\n\tbuffer?: ArrayBuffer;\n\tdeletedAt: number | null;\n\ttimestamp?: string;\n}\n\nexport interface ReturnedFileData extends FileData {\n\tdeletedAt: number | null;\n}\n\nexport class FileStorage extends IDBService {\n\taddFile = async (\n\t\tfile: FileData,\n\t\t{\n\t\t\ttransaction,\n\t\t\tdownloadRemote = false,\n\t\t}: { transaction?: IDBTransaction; downloadRemote?: boolean } = {},\n\t) => {\n\t\tlet buffer = file.file ? await fileToArrayBuffer(file.file) : undefined;\n\t\tif (!buffer && downloadRemote && file.url) {\n\t\t\ttry {\n\t\t\t\tbuffer = await fetch(file.url, {\n\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\tcredentials: 'include',\n\t\t\t\t}).then((r) => r.arrayBuffer());\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"Failed to download file to cache it locally. The file will still be available using its URL. Check the file server's CORS configuration.\",\n\t\t\t\t\terr,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn this.run(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.put({\n\t\t\t\t\tid: file.id,\n\t\t\t\t\t// IDB doesn't support boolean indexes\n\t\t\t\t\tremote: file.remote ? 'true' : 'false',\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\tname: file.name,\n\t\t\t\t\ttype: file.type,\n\t\t\t\t\turl: file.url,\n\t\t\t\t\tbuffer,\n\t\t\t\t} as StoredFileData);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\tprivate hydrateFileData = (raw: StoredFileData): ReturnedFileData => {\n\t\t(raw as any).remote = raw.remote === 'true';\n\t\tconst buffer = raw.buffer;\n\t\tdelete raw.buffer;\n\t\t(raw as unknown as FileData).file = buffer\n\t\t\t? arrayBufferToBlob(buffer, raw.type)\n\t\t\t: undefined;\n\t\treturn raw as unknown as ReturnedFileData;\n\t};\n\n\tmarkUploaded = async (\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tconst current = await this.getFileRaw(id, { transaction });\n\n\t\tif (!current) {\n\t\t\tthrow new Error('File is not in local database');\n\t\t}\n\n\t\treturn this.run(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.put({\n\t\t\t\t\t...current,\n\t\t\t\t\tremote: 'true',\n\t\t\t\t} as StoredFileData);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\tprivate getFileRaw = async (\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t): Promise<StoredFileData | undefined> => {\n\t\tconst raw = await this.run<StoredFileData>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.get(id);\n\t\t\t},\n\t\t\t{ mode: 'readonly', transaction },\n\t\t);\n\t\tif (!raw) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn raw;\n\t};\n\n\tgetFile = async (\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t): Promise<ReturnedFileData | undefined> => {\n\t\tconst raw = await this.getFileRaw(id, { transaction });\n\t\tif (!raw) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.hydrateFileData(raw);\n\t};\n\n\tdeleteFile(\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) {\n\t\treturn this.run<undefined>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.delete(id);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t}\n\n\tmarkPendingDelete = async (\n\t\tid: string,\n\t\t{ transaction }: { transaction?: IDBTransaction } = {},\n\t) => {\n\t\tconst current = await this.getFileRaw(id, { transaction });\n\n\t\tif (!current) {\n\t\t\tthrow new Error('File is not in local database');\n\t\t}\n\n\t\treturn this.run(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.put({\n\t\t\t\t\t...current,\n\t\t\t\t\tdeletedAt: Date.now(),\n\t\t\t\t} as StoredFileData);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\tlistUnsynced = async () => {\n\t\tconst raw = await this.run<StoredFileData[]>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.index('remote').getAll('false');\n\t\t\t},\n\t\t\t{ mode: 'readonly' },\n\t\t);\n\t\treturn raw.map(this.hydrateFileData);\n\t};\n\n\tresetSyncedStatusSince = async (since: string | null) => {\n\t\tconst tx = this.createTransaction(['files'], { mode: 'readwrite' });\n\t\tconst raw = await this.run<StoredFileData[]>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store.index('remote').getAll('true');\n\t\t\t},\n\t\t\t{ transaction: tx },\n\t\t);\n\n\t\tconst filtered = raw.filter(\n\t\t\t(file) => !file.timestamp || !since || file.timestamp > since,\n\t\t);\n\n\t\tawait Promise.all(\n\t\t\tfiltered.map((file) => {\n\t\t\t\treturn this.run(\n\t\t\t\t\t'files',\n\t\t\t\t\t(store) => {\n\t\t\t\t\t\treturn store.put({\n\t\t\t\t\t\t\t...file,\n\t\t\t\t\t\t\tremote: 'false',\n\t\t\t\t\t\t} as StoredFileData);\n\t\t\t\t\t},\n\t\t\t\t\t{ transaction: tx },\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t};\n\n\titerateOverPendingDelete = (\n\t\titerator: (file: ReturnedFileData, store: IDBObjectStore) => void,\n\t\ttransaction?: IDBTransaction,\n\t) => {\n\t\treturn this.iterate<StoredFileData>(\n\t\t\t'files',\n\t\t\t(store) => {\n\t\t\t\treturn store\n\t\t\t\t\t.index('deletedAt')\n\t\t\t\t\t.openCursor(IDBKeyRange.lowerBound(0, true));\n\t\t\t},\n\t\t\t(value, store) => {\n\t\t\t\titerator(this.hydrateFileData(value), store);\n\t\t\t},\n\t\t\t{ mode: 'readwrite', transaction },\n\t\t);\n\t};\n\n\tgetAll = async () => {\n\t\tconst [files] = await getAllFromObjectStores(this.db, ['files']);\n\t\treturn files.map(this.hydrateFileData);\n\t};\n\n\tstats = async () => {\n\t\treturn {\n\t\t\tsize: await getSizeOfObjectStore(this.db, 'files'),\n\t\t};\n\t};\n}\n\nexport function arrayBufferToBlob(buffer: ArrayBuffer, type: string) {\n\treturn new Blob([buffer], { type });\n}\n", "import { FileData, FileRef } from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Sync } from '../sync/Sync.js';\nimport {\n\tEntityFile,\n\tMARK_FAILED,\n\tMARK_UPLOADED,\n\tUPDATE,\n} from './EntityFile.js';\nimport {\n\tFileStorage,\n\tReturnedFileData,\n\tStoredFileData,\n} from './FileStorage.js';\n\n/**\n * Default: if file was deleted > 3 days ago\n */\nfunction defaultCanCleanup(fileData: ReturnedFileData) {\n\treturn (\n\t\tfileData.deletedAt !== null &&\n\t\tfileData.deletedAt < Date.now() - 1000 * 60 * 24 * 3\n\t);\n}\n\nexport interface FileManagerConfig {\n\t/**\n\t * Override the heuristic for deciding when a deleted file can be cleaned up.\n\t * By default this waits 3 days since deletion, then deletes the file data.\n\t * If the file has been synchronized to a server, it could still be restored\n\t * if the server has not yet deleted it.\n\t */\n\tcanCleanupDeletedFile?: (file: ReturnedFileData) => boolean;\n}\n\nexport class FileManager {\n\tprivate storage;\n\tprivate sync;\n\tprivate context;\n\n\tprivate files = new Map<string, EntityFile>();\n\tprivate config: Required<FileManagerConfig>;\n\tprivate meta: Metadata;\n\n\tprivate maxUploadRetries = 3;\n\tprivate maxDownloadRetries = 3;\n\n\tconstructor({\n\t\tdb,\n\t\tsync,\n\t\tcontext,\n\t\tmeta,\n\t\tconfig = {},\n\t}: {\n\t\tdb: IDBDatabase;\n\t\tsync: Sync;\n\t\tcontext: Context;\n\t\tconfig?: FileManagerConfig;\n\t\tmeta: Metadata;\n\t}) {\n\t\tthis.storage = new FileStorage(db);\n\t\tthis.sync = sync;\n\t\tthis.context = context;\n\t\tthis.meta = meta;\n\t\tthis.config = {\n\t\t\tcanCleanupDeletedFile: defaultCanCleanup,\n\t\t\t...config,\n\t\t};\n\n\t\tthis.sync.subscribe('onlineChange', this.onOnlineChange);\n\t\tthis.meta.subscribe('filesDeleted', this.handleFileRefsDeleted);\n\t\tthis.sync.subscribe('serverReset', this.storage.resetSyncedStatusSince);\n\t\t// check on startup to see if files can be cleaned up\n\t\tthis.tryCleanupDeletedFiles();\n\t}\n\n\tadd = async (file: FileData) => {\n\t\t// this method accepts a FileData which refers to a remote\n\t\t// file, as well as local files. in the case of a remote file,\n\t\t// we actually re-download and upload the file again. this powers\n\t\t// the cloning of documents with files; we clone their filedata\n\t\t// and re-upload to a new file ID. otherwise, when the cloned\n\t\t// filedata was marked deleted, the original file would be deleted\n\t\t// and the clone would refer to a missing file.\n\t\tif (file.url && !file.file) {\n\t\t\tconst blob = await this.downloadRemoteFile(file.url);\n\t\t\t// convert blob to file with name and type\n\t\t\tfile.file = new File([blob], file.name, { type: file.type });\n\t\t}\n\n\t\tfile.remote = false;\n\t\t// immediately cache the file\n\t\tif (!this.files.has(file.id)) {\n\t\t\tconst entityFile = new EntityFile(file.id);\n\t\t\tentityFile[UPDATE](file);\n\t\t\tthis.files.set(file.id, entityFile);\n\t\t} else {\n\t\t\tthis.files.get(file.id);\n\t\t}\n\t\t// write to local storage and send to sync immediately\n\t\tawait this.storage.addFile(file);\n\t\t// send to sync\n\t\tif (file.file && this.sync.status === 'active') {\n\t\t\tawait this.uploadFile(file);\n\t\t}\n\t};\n\n\tprivate uploadFile = async (file: FileData, retries = 0) => {\n\t\tconst result = await this.sync.uploadFile(file);\n\t\tif (result.success) {\n\t\t\tawait this.storage.markUploaded(file.id);\n\t\t\tconst cached = this.files.get(file.id);\n\t\t\tif (cached) {\n\t\t\t\tcached[MARK_UPLOADED]();\n\t\t\t}\n\t\t\tthis.context.log('info', 'File uploaded', file.id);\n\t\t} else {\n\t\t\tif (result.retry && retries < this.maxUploadRetries) {\n\t\t\t\tthis.context.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`Error uploading file ${file.id}, retrying...`,\n\t\t\t\t\tresult.error,\n\t\t\t\t);\n\t\t\t\t// schedule a retry\n\t\t\t\tsetTimeout(this.uploadFile, 1000, file, retries + 1);\n\t\t\t} else {\n\t\t\t\tthis.context.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t`Failed to upload file ${file.id}. Not retrying until next sync.`,\n\t\t\t\t\tresult.error,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate downloadRemoteFile = async (\n\t\turl: string,\n\t\tretries = 0,\n\t): Promise<Blob> => {\n\t\tconst resp = await fetch(url, {\n\t\t\tmethod: 'GET',\n\t\t\tcredentials: 'include',\n\t\t});\n\t\tif (!resp.ok) {\n\t\t\tif (retries < this.maxDownloadRetries) {\n\t\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis.downloadRemoteFile(url, retries + 1).then(resolve, reject);\n\t\t\t\t\t}, 1000);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Failed to download file: ${resp.status}`);\n\t\t\t}\n\t\t}\n\t\tconst blob = await resp.blob();\n\t\treturn blob;\n\t};\n\n\t/**\n\t * Immediately returns an EntityFile to use, then either loads\n\t * the file from cache, local database, or the server.\n\t */\n\tget = (id: string, options?: { downloadRemote?: boolean }) => {\n\t\tif (this.files.has(id)) {\n\t\t\treturn this.files.get(id)!;\n\t\t}\n\t\tconst file = new EntityFile(id, options);\n\t\tthis.files.set(id, file);\n\t\tthis.load(file);\n\t\treturn file;\n\t};\n\n\tprivate load = async (file: EntityFile, retries = 0) => {\n\t\tif (retries > this.maxDownloadRetries) {\n\t\t\tthis.context.log('error', 'Failed to load file after 5 retries');\n\t\t\tfile[MARK_FAILED]();\n\t\t\treturn;\n\t\t}\n\n\t\tconst fileData = await this.storage.getFile(file.id);\n\t\tif (fileData) {\n\t\t\tfile[UPDATE](fileData);\n\t\t} else {\n\t\t\t// maybe we don't have it yet, it might be on the server still.\n\t\t\ttry {\n\t\t\t\tconst result = await this.sync.getFile(file.id);\n\t\t\t\tif (result.success) {\n\t\t\t\t\tfile[UPDATE](result.data);\n\t\t\t\t\tawait this.storage.addFile(result.data, {\n\t\t\t\t\t\tdownloadRemote: file.downloadRemote,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tthis.context.log('error', 'Failed to load file', result);\n\t\t\t\t\tfile[MARK_FAILED]();\n\t\t\t\t\tif (result.retry) {\n\t\t\t\t\t\t// schedule a retry\n\t\t\t\t\t\tsetTimeout(this.load, 1000, file, retries + 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tthis.context.log('error', 'Failed to load file', err);\n\t\t\t\tfile[MARK_FAILED]();\n\t\t\t\t// schedule a retry\n\t\t\t\tsetTimeout(this.load, 1000, file, retries + 1);\n\t\t\t}\n\t\t}\n\t};\n\n\tlistUnsynced = async () => {\n\t\treturn this.storage.listUnsynced();\n\t};\n\n\texportAll = async (downloadRemote = false) => {\n\t\tconst storedFiles = await this.storage.getAll();\n\t\tif (downloadRemote) {\n\t\t\tfor (const storedFile of storedFiles) {\n\t\t\t\t// if it doesn't have a buffer, we need to read\n\t\t\t\t// one from the server\n\t\t\t\tif (!storedFile.file && storedFile.url) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst blob = await fetch(storedFile.url, {\n\t\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t\t\tcredentials: 'include',\n\t\t\t\t\t\t}).then((r) => r.blob());\n\t\t\t\t\t\tstoredFile.file = blob;\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tthis.context.log(\n\t\t\t\t\t\t\t'error',\n\t\t\t\t\t\t\t\"Failed to download file to cache it locally. The file will still be available using its URL. Check the file server's CORS configuration.\",\n\t\t\t\t\t\t\terr,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn storedFiles;\n\t};\n\n\timportAll = async (files: ReturnedFileData[]) => {\n\t\tawait Promise.all(files.map((file) => this.add(file)));\n\t};\n\n\tprivate onOnlineChange = async (online: boolean) => {\n\t\t// if online, try to upload any unsynced files\n\t\tif (online) {\n\t\t\tconst unsynced = await this.listUnsynced();\n\t\t\tawait Promise.all(unsynced.map(this.uploadFile));\n\t\t}\n\t};\n\n\ttryCleanupDeletedFiles = async () => {\n\t\tlet count = 0;\n\t\tlet skipCount = 0;\n\t\tawait this.storage.iterateOverPendingDelete((fileData, store) => {\n\t\t\tif (this.config.canCleanupDeletedFile(fileData)) {\n\t\t\t\tcount++;\n\t\t\t\tstore.delete(fileData.id);\n\t\t\t} else {\n\t\t\t\tskipCount++;\n\t\t\t}\n\t\t});\n\n\t\tthis.context.log(\n\t\t\t'info',\n\t\t\t`Cleaned up ${count} files, skipped ${skipCount} files`,\n\t\t);\n\t};\n\n\tprivate handleFileRefsDeleted = async (fileRefs: FileRef[]) => {\n\t\tconst tx = this.storage.createTransaction(['files'], { mode: 'readwrite' });\n\t\tawait Promise.all(\n\t\t\tfileRefs.map(async (fileRef) => {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.storage.markPendingDelete(fileRef.id, { transaction: tx });\n\t\t\t\t} catch (err) {\n\t\t\t\t\tthis.context.log('error', 'Failed to mark file for deletion', err);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tthis.context.log(\n\t\t\t'info',\n\t\t\t`Marked ${fileRefs.length} files as pending delete`,\n\t\t);\n\t};\n\n\tclose = () => {\n\t\tthis.storage.dispose();\n\t};\n\n\tstats = () => {\n\t\treturn this.storage.stats();\n\t};\n}\n", "import { Migration } from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { getDatabaseVersion, openDatabase } from './db.js';\nimport { runMigrations } from './migrations.js';\nimport { getMigrationPath } from './paths.js';\nimport { OpenDocumentDbContext } from './types.js';\n\nconst globalIDB =\n\ttypeof window !== 'undefined' ? window.indexedDB : (undefined as any);\n\nexport async function openQueryDatabase({\n\tversion,\n\tindexedDB = globalIDB,\n\tmigrations,\n\tmeta,\n\tcontext,\n}: {\n\tversion: number;\n\tmigrations: Migration<any>[];\n\tindexedDB?: IDBFactory;\n\tmeta: Metadata;\n\tcontext: OpenDocumentDbContext;\n}) {\n\tif (context.schema.wip) {\n\t\tthrow new Error('Cannot open a production client with a WIP schema!');\n\t}\n\n\tconst currentVersion = await getDatabaseVersion(\n\t\tindexedDB,\n\t\tcontext.namespace,\n\t\tversion,\n\t\tcontext.log,\n\t);\n\n\tcontext.log(\n\t\t'debug',\n\t\t'Current database version:',\n\t\tcurrentVersion,\n\t\t'target version:',\n\t\tversion,\n\t);\n\n\tconst toRun = getMigrationPath({\n\t\tcurrentVersion,\n\t\ttargetVersion: version,\n\t\tmigrations,\n\t});\n\n\tif (toRun.length > 0) {\n\t\tcontext.log(\n\t\t\t'debug',\n\t\t\t'Migrations to run:',\n\t\t\ttoRun.map((m) => m.version),\n\t\t);\n\t\tawait runMigrations({ context, toRun, meta, indexedDB });\n\t}\n\treturn openDatabase({\n\t\tindexedDB,\n\t\tnamespace: context.namespace,\n\t\tversion,\n\t\tcontext,\n\t});\n}\n", "import { CollectionIndexFilter, hashObject } from '@verdant-web/common';\nimport { Entity } from '../entities/Entity.js';\n\nfunction existsFilter<T>(x: T | null): x is T {\n\treturn x !== null;\n}\n\nexport function filterResultSet(results: any): any {\n\tif (Array.isArray(results)) {\n\t\treturn results.map(filterResultSet).filter(existsFilter);\n\t} else if (results instanceof Entity) {\n\t\treturn results.deleted ? null : results;\n\t} else {\n\t\treturn results;\n\t}\n}\n\nexport function areIndexesEqual(\n\ta?: CollectionIndexFilter,\n\tb?: CollectionIndexFilter,\n) {\n\treturn (!a && !b) || (a && b && hashObject(a) === hashObject(b));\n}\n", "import { EventSubscriber } from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { Entity } from '../entities/Entity.js';\nimport { Disposable } from '../utils/Disposable.js';\nimport { filterResultSet } from './utils.js';\n\nexport type BaseQueryEvents = {\n\tchange: (value: any) => void;\n\tstatusChange: (status: QueryStatus) => void;\n};\n\nexport type BaseQueryOptions<T> = {\n\tcontext: Context;\n\tinitial: T;\n\tcollection: string;\n\tkey: string;\n\tshouldUpdate?: (updatedCollections: string[]) => boolean;\n};\n\nexport type QueryStatus = 'initial' | 'initializing' | 'revalidating' | 'ready';\n\nexport const ON_ALL_UNSUBSCRIBED = Symbol('ON_ALL_UNSUBSCRIBED');\nexport const UPDATE = Symbol('UPDATE');\n\n// export interface BaseQuery<T> {\n// \tsubscribe(event: 'change', callback: (value: T) => void): () => void;\n// \tsubscribe(event: 'statusChange', callback: (status: QueryStatus) => void): () => void;\n// \tsubscribe(callback: (value: T) => void): () => void;\n// }\n\nexport abstract class BaseQuery<T> extends Disposable {\n\tprivate _rawValue;\n\tprivate _value;\n\n\tprivate _events;\n\tprivate _internalUnsubscribes: (() => void)[] = [];\n\tprivate _allUnsubscribedHandler?: (query: BaseQuery<T>) => void;\n\tprivate _status: QueryStatus = 'initial';\n\tprivate _executionPromise: Promise<T> | null = null;\n\n\tprotected context;\n\n\treadonly collection;\n\treadonly key;\n\treadonly isListQuery;\n\n\tconstructor({\n\t\tinitial,\n\t\tcontext,\n\t\tcollection,\n\t\tkey,\n\t\tshouldUpdate,\n\t}: BaseQueryOptions<T>) {\n\t\tsuper();\n\t\tthis._rawValue = initial;\n\t\tthis._value = initial;\n\t\tthis.isListQuery = Array.isArray(initial);\n\t\tthis._events = new EventSubscriber<BaseQueryEvents>(\n\t\t\t(event: keyof BaseQueryEvents) => {\n\t\t\t\tif (event === 'change') this._allUnsubscribedHandler?.(this);\n\t\t\t},\n\t\t);\n\t\tthis.context = context;\n\t\tthis.key = key;\n\t\tthis.collection = collection;\n\t\tconst shouldUpdateFn =\n\t\t\tshouldUpdate ||\n\t\t\t((collections: string[]) => collections.includes(collection));\n\t\tthis.addDispose(\n\t\t\tthis.context.entityEvents.subscribe(\n\t\t\t\t'collectionsChanged',\n\t\t\t\t(collections) => {\n\t\t\t\t\tif (shouldUpdateFn(collections)) {\n\t\t\t\t\t\tthis.context.log('info', 'Updating query', this.key);\n\t\t\t\t\t\t// immediately refilter the result set - deleted\n\t\t\t\t\t\t// entities will already be nulled out\n\t\t\t\t\t\t// this.refreshValue();\n\t\t\t\t\t\tthis.execute();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t\t// TODO: subscribe to document changes and update if necessary.\n\t}\n\n\tget current() {\n\t\treturn this._value;\n\t}\n\n\tget resolved() {\n\t\tif (this.status === 'ready') return Promise.resolve(this._value);\n\t\treturn this._executionPromise ?? this.execute();\n\t}\n\n\tget subscribed() {\n\t\treturn this._events.totalSubscriberCount() > 0;\n\t}\n\n\tget status() {\n\t\treturn this._status;\n\t}\n\n\tprivate set status(v: QueryStatus) {\n\t\tif (this._status === v) return;\n\t\tthis._status = v;\n\t\tthis._events.emit('statusChange', this._status);\n\t}\n\n\tget hasDeleted() {\n\t\tif (this.isListQuery) {\n\t\t\treturn (this._rawValue as any[]).length !== (this._value as any[]).length;\n\t\t}\n\t\treturn !!this._rawValue && !this._value;\n\t}\n\n\t/**\n\t * Subscribe to changes in the query value.\n\t *\n\t * @deprecated use the two parameter form instead\n\t */\n\tsubscribe(callback: (value: T) => void): () => void;\n\t/**\n\t * Subscribe to changes in the query value.\n\t */\n\tsubscribe(event: 'change', callback: (value: T) => void): () => void;\n\t/**\n\t * Subscribe to changes in the query state.\n\t */\n\tsubscribe(\n\t\tevent: 'statusChange',\n\t\tcallback: (status: QueryStatus) => void,\n\t): () => void;\n\tsubscribe(eventOrCallback: any, callback?: any) {\n\t\t// change subscription has special behavior...\n\t\tif (callback === undefined && typeof eventOrCallback === 'function') {\n\t\t\t// accessing for side effects... eh\n\t\t\tthis.resolved;\n\t\t\treturn this._events.subscribe('change', eventOrCallback);\n\t\t} else if (eventOrCallback === 'change' && callback !== undefined) {\n\t\t\t// accessing for side effects... eh\n\t\t\tthis.resolved;\n\t\t\treturn this._events.subscribe('change', callback);\n\t\t} else if (\n\t\t\teventOrCallback === 'statusChange' &&\n\t\t\ttypeof callback === 'function'\n\t\t) {\n\t\t\treturn this._events.subscribe(eventOrCallback, callback);\n\t\t} else {\n\t\t\tthrow new Error('Invalid invocation of Query.subscribe');\n\t\t}\n\t}\n\n\tprotected setValue = (value: T) => {\n\t\tthis._rawValue = value;\n\t\tthis.subscribeToDeleteAndRestore(this._rawValue);\n\t\tconst filtered = filterResultSet(value);\n\n\t\t// prevent excess change notifications by diffing\n\t\t// value by identity for single-value queries,\n\t\t// and by item identity for multi-value\n\t\tlet changed = true;\n\t\t// always fire change when going from initial to ready\n\t\tif (this.status === 'initializing' || this.status === 'initial') {\n\t\t\tchanged = true;\n\t\t} else {\n\t\t\t// compare values by identity, after filtering.\n\t\t\tif (this.isListQuery) {\n\t\t\t\tif (\n\t\t\t\t\t(this._value as any[]).length === (filtered as any[]).length &&\n\t\t\t\t\t(this._value as any[]).every((v, i) => v === (filtered as any[])[i])\n\t\t\t\t) {\n\t\t\t\t\tchanged = false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (this._value === filtered) {\n\t\t\t\t\tchanged = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis._value = filtered;\n\n\t\tif (changed) {\n\t\t\tthis.context.log('debug', 'Query value changed', this.key);\n\t\t\tthis._events.emit('change', this._value);\n\t\t}\n\t\tthis.status = 'ready';\n\t};\n\n\t// re-applies filtering if results have changed\n\tprotected refreshValue = () => {\n\t\tthis.setValue(this._rawValue);\n\t};\n\n\tprivate subscribeToDeleteAndRestore = (value: T) => {\n\t\twhile (this._internalUnsubscribes.length) {\n\t\t\tthis._internalUnsubscribes.pop()?.();\n\t\t}\n\n\t\tif (Array.isArray(value)) {\n\t\t\tvalue.forEach((entity: any) => {\n\t\t\t\tif (entity instanceof Entity) {\n\t\t\t\t\tthis._internalUnsubscribes.push(\n\t\t\t\t\t\tentity.subscribe('delete', this.refreshValue),\n\t\t\t\t\t);\n\t\t\t\t\tthis._internalUnsubscribes.push(\n\t\t\t\t\t\tentity.subscribe('restore', this.refreshValue),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (value instanceof Entity) {\n\t\t\tthis._internalUnsubscribes.push(\n\t\t\t\tvalue.subscribe('delete', this.refreshValue),\n\t\t\t);\n\t\t\tthis._internalUnsubscribes.push(\n\t\t\t\tvalue.subscribe('restore', () => {\n\t\t\t\t\tthis.refreshValue();\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t};\n\n\texecute = () => {\n\t\tthis.context.log('debug', 'Executing query', this.key);\n\n\t\tif (this.status === 'initial') {\n\t\t\tthis.status = 'initializing';\n\t\t} else if (this.status === 'ready') {\n\t\t\tthis.status = 'revalidating';\n\t\t}\n\t\t// no status change needed if already in a 'running' status.\n\n\t\tthis._executionPromise = this.run()\n\t\t\t.then(() => this._value)\n\t\t\t.catch((err) => {\n\t\t\t\tif (err instanceof Error) {\n\t\t\t\t\tif (\n\t\t\t\t\t\terr.name === 'InvalidStateError' ||\n\t\t\t\t\t\terr.name === 'InvalidAccessError'\n\t\t\t\t\t) {\n\t\t\t\t\t\t// possibly accessing db while it's closed. not much we can do.\n\t\t\t\t\t\treturn this._value;\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error('Unknown error executing query');\n\t\t\t\t}\n\t\t\t});\n\t\treturn this._executionPromise;\n\t};\n\tprotected abstract run(): Promise<void>;\n\n\t[ON_ALL_UNSUBSCRIBED] = (handler: (query: BaseQuery<T>) => void) => {\n\t\tthis._allUnsubscribedHandler = handler;\n\t};\n}\n", "import { createOid } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions } from './BaseQuery.js';\n\nexport class GetQuery<T> extends BaseQuery<T | null> {\n\tprivate hydrate;\n\tprivate oid;\n\n\tconstructor({\n\t\tid,\n\t\thydrate,\n\t\t...rest\n\t}: {\n\t\tid: string;\n\t\thydrate: (oid: string) => Promise<T>;\n\t} & Omit<BaseQueryOptions<T | null>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: null,\n\t\t\t...rest,\n\t\t});\n\t\tthis.oid = createOid(rest.collection, id);\n\t\tthis.hydrate = hydrate;\n\t}\n\n\tprotected run = async () => {\n\t\tconst value = await this.hydrate(this.oid);\n\t\tthis.setValue(value);\n\t};\n}\n", "import { CollectionFilter } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';\nimport { findOneOid } from './dbQueries.js';\nimport { areIndexesEqual } from './utils.js';\n\nexport class FindOneQuery<T> extends BaseQuery<T | null> {\n\tprivate index;\n\tprivate hydrate;\n\n\tconstructor({\n\t\tindex,\n\t\thydrate,\n\t\t...rest\n\t}: {\n\t\tindex?: CollectionFilter;\n\t\thydrate: (oid: string) => Promise<T>;\n\t} & Omit<BaseQueryOptions<T | null>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: null,\n\t\t\t...rest,\n\t\t});\n\t\tthis.index = index;\n\t\tthis.hydrate = hydrate;\n\t}\n\n\tprotected run = async () => {\n\t\tconst oid = await findOneOid({\n\t\t\tcollection: this.collection,\n\t\t\tindex: this.index,\n\t\t\tcontext: this.context,\n\t\t});\n\t\tthis.setValue(oid ? await this.hydrate(oid) : null);\n\t};\n\n\t[UPDATE] = (index: CollectionFilter | undefined) => {\n\t\tif (areIndexesEqual(this.index, index)) return;\n\t\tthis.index = index;\n\t\tthis.execute();\n\t};\n}\n", "import { CollectionFilter } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';\nimport { findPageOfOids } from './dbQueries.js';\nimport { areIndexesEqual } from './utils.js';\n\nexport class FindPageQuery<T> extends BaseQuery<T[]> {\n\tprivate index;\n\tprivate hydrate;\n\tprivate _pageSize: number;\n\tprivate _page: number;\n\tprivate _hasNextPage: boolean = false;\n\n\tget pageSize() {\n\t\treturn this._pageSize;\n\t}\n\n\tget page() {\n\t\treturn this._page;\n\t}\n\n\tget hasNextPage() {\n\t\treturn this._hasNextPage;\n\t}\n\n\tget hasPreviousPage() {\n\t\treturn this._page > 0;\n\t}\n\n\tconstructor({\n\t\tindex,\n\t\thydrate,\n\t\tpageSize,\n\t\tpage,\n\t\t...rest\n\t}: {\n\t\tindex?: CollectionFilter;\n\t\thydrate: (oid: string) => Promise<T>;\n\t\tpageSize: number;\n\t\tpage: number;\n\t} & Omit<BaseQueryOptions<T[]>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: [],\n\t\t\t...rest,\n\t\t});\n\t\tthis.index = index;\n\t\tthis.hydrate = hydrate;\n\t\tthis._pageSize = pageSize;\n\t\tthis._page = page;\n\t}\n\n\tprotected run = async () => {\n\t\tconst { result, hasNextPage } = await findPageOfOids({\n\t\t\tcollection: this.collection,\n\t\t\tindex: this.index,\n\t\t\tcontext: this.context,\n\t\t\tlimit: this._pageSize,\n\t\t\toffset: this._page * this._pageSize,\n\t\t});\n\t\tthis._hasNextPage = hasNextPage;\n\t\tthis.setValue(await Promise.all(result.map(this.hydrate)));\n\t};\n\n\tnextPage = async () => {\n\t\tif (!this.hasNextPage) return;\n\n\t\tthis._page++;\n\t\tawait this.run();\n\t};\n\n\tpreviousPage = async () => {\n\t\tif (this._page === 0) return;\n\n\t\tthis._page--;\n\t\tawait this.run();\n\t};\n\n\tsetPage = async (page: number) => {\n\t\tthis._page = page;\n\t\tawait this.run();\n\t};\n\n\t[UPDATE] = (index: CollectionFilter | undefined) => {\n\t\tif (areIndexesEqual(this.index, index)) return;\n\t\tthis.index = index;\n\t\tthis.execute();\n\t};\n}\n", "import { CollectionFilter } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';\nimport { findPageOfOids } from './dbQueries.js';\nimport { areIndexesEqual } from './utils.js';\n\nexport class FindInfiniteQuery<T> extends BaseQuery<T[]> {\n\tprivate index;\n\tprivate hydrate;\n\tprivate _upToPage = 1;\n\tprivate _pageSize: number;\n\tprivate _hasNextPage: boolean = false;\n\n\tget pageSize() {\n\t\treturn this._pageSize;\n\t}\n\n\tget hasMore() {\n\t\treturn this._hasNextPage;\n\t}\n\n\tconstructor({\n\t\thydrate,\n\t\tpageSize,\n\t\tindex,\n\t\t...rest\n\t}: {\n\t\thydrate: (oid: string) => Promise<T>;\n\t\tpageSize: number;\n\t\tindex?: CollectionFilter;\n\t} & Omit<BaseQueryOptions<T[]>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: [],\n\t\t\t...rest,\n\t\t});\n\t\tthis.index = index;\n\t\tthis.hydrate = hydrate;\n\t\tthis._pageSize = pageSize;\n\t}\n\n\tprotected run = async () => {\n\t\tconst { result, hasNextPage } = await findPageOfOids({\n\t\t\tcollection: this.collection,\n\t\t\tcontext: this.context,\n\t\t\tlimit: this._pageSize * this._upToPage,\n\t\t\toffset: 0,\n\t\t\tindex: this.index,\n\t\t});\n\t\tthis._hasNextPage = hasNextPage;\n\t\tthis.setValue(await Promise.all(result.map(this.hydrate)));\n\t};\n\n\tpublic loadMore = async () => {\n\t\tconst { result, hasNextPage } = await findPageOfOids({\n\t\t\tcollection: this.collection,\n\t\t\tcontext: this.context,\n\t\t\tlimit: this._pageSize,\n\t\t\toffset: this._pageSize * this._upToPage,\n\t\t\tindex: this.index,\n\t\t});\n\t\tthis._hasNextPage = hasNextPage;\n\t\tthis._upToPage++;\n\t\tthis.setValue([\n\t\t\t...this.current,\n\t\t\t...(await Promise.all(result.map(this.hydrate))),\n\t\t]);\n\t};\n\n\t[UPDATE] = (index: CollectionFilter | undefined) => {\n\t\tif (areIndexesEqual(this.index, index)) return;\n\t\tthis.index = index;\n\t\tthis.execute();\n\t};\n}\n", "import { CollectionFilter } from '@verdant-web/common';\nimport { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';\nimport { findAllOids } from './dbQueries.js';\nimport { areIndexesEqual } from './utils.js';\n\nexport class FindAllQuery<T> extends BaseQuery<T[]> {\n\tprivate index;\n\tprivate hydrate;\n\n\tconstructor({\n\t\tindex,\n\t\thydrate,\n\t\t...rest\n\t}: {\n\t\tindex?: CollectionFilter;\n\t\thydrate: (oid: string) => Promise<T>;\n\t} & Omit<BaseQueryOptions<T[]>, 'initial'>) {\n\t\tsuper({\n\t\t\tinitial: [],\n\t\t\t...rest,\n\t\t});\n\t\tthis.index = index;\n\t\tthis.hydrate = hydrate;\n\t}\n\n\tprotected run = async () => {\n\t\tconst oids = await findAllOids({\n\t\t\tcollection: this.collection,\n\t\t\tindex: this.index,\n\t\t\tcontext: this.context,\n\t\t});\n\t\tthis.context.log(\n\t\t\t'debug',\n\t\t\t`FindAllQuery: ${oids.length} oids found: ${oids}`,\n\t\t);\n\t\tthis.setValue(await Promise.all(oids.map(this.hydrate)));\n\t};\n\n\t[UPDATE] = (index: CollectionFilter | undefined) => {\n\t\tif (areIndexesEqual(this.index, index)) return;\n\t\tthis.index = index;\n\t\tthis.execute();\n\t};\n}\n", "import {\n\tAuthorizationKey,\n\tCollectionFilter,\n\thashObject,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { EntityStore } from '../entities/EntityStore.js';\nimport { GetQuery } from './GetQuery.js';\nimport { QueryCache } from './QueryCache.js';\nimport { FindOneQuery } from './FindOneQuery.js';\nimport { FindPageQuery } from './FindPageQuery.js';\nimport { FindInfiniteQuery } from './FindInfiniteQuery.js';\nimport { FindAllQuery } from './FindAllQuery.js';\nimport { DocumentManager } from '../entities/DocumentManager.js';\nimport { Entity, ObjectEntity } from '../index.js';\nimport { UPDATE } from './BaseQuery.js';\n\nexport class CollectionQueries<\n\tT extends ObjectEntity<any, any>,\n\tInit,\n\tFilter extends CollectionFilter,\n> {\n\tprivate cache;\n\tprivate collection;\n\tprivate hydrate: (oid: string) => Promise<T>;\n\tprivate context;\n\tprivate documentManager;\n\n\tput: (\n\t\tinit: Init,\n\t\toptions?: { undoable?: boolean; access?: AuthorizationKey },\n\t) => Promise<T>;\n\tdelete: (id: string, options?: { undoable?: boolean }) => Promise<void>;\n\tdeleteAll: (ids: string[], options?: { undoable?: boolean }) => Promise<void>;\n\tclone: (\n\t\tentity: ObjectEntity<any, any>,\n\t\toptions?: {\n\t\t\tundoable?: boolean;\n\t\t\taccess?: AuthorizationKey;\n\t\t\tprimaryKey?: string;\n\t\t},\n\t) => Promise<T>;\n\n\tconstructor({\n\t\tcollection,\n\t\tcache,\n\t\tentities,\n\t\tcontext,\n\t\tdocumentManager,\n\t}: {\n\t\tcollection: string;\n\t\tcache: QueryCache;\n\t\tentities: EntityStore;\n\t\tcontext: Context;\n\t\tdocumentManager: DocumentManager<any>;\n\t}) {\n\t\tthis.cache = cache;\n\t\tthis.collection = collection;\n\t\tthis.hydrate = entities.hydrate as any;\n\t\tthis.context = context;\n\t\tthis.documentManager = documentManager;\n\n\t\tthis.put = this.documentManager.create.bind(\n\t\t\tthis.documentManager,\n\t\t\tthis.collection,\n\t\t);\n\t\tthis.delete = this.documentManager.delete.bind(\n\t\t\tthis.documentManager,\n\t\t\tthis.collection,\n\t\t);\n\t\tthis.deleteAll = this.documentManager.deleteAllFromCollection.bind(\n\t\t\tthis.documentManager,\n\t\t\tthis.collection,\n\t\t);\n\t\tthis.clone = this.documentManager.clone.bind(\n\t\t\tthis.documentManager,\n\t\t\tthis.collection,\n\t\t);\n\t}\n\n\tprivate serializeIndex = (index?: CollectionFilter) => {\n\t\tif (!index) return '';\n\t\treturn hashObject(index);\n\t};\n\n\tget = (id: string) => {\n\t\tconst key = `get:${this.collection}:${id}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew GetQuery<T>({\n\t\t\t\t\tid,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t}),\n\t\t);\n\t};\n\n\tfindOne = ({\n\t\tindex,\n\t\tkey: providedKey,\n\t}: { index?: Filter; key?: string } = {}) => {\n\t\tconst key =\n\t\t\tprovidedKey || `findOne:${this.collection}:${this.serializeIndex(index)}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew FindOneQuery<T>({\n\t\t\t\t\tindex,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t}),\n\t\t\t(existing) => {\n\t\t\t\texisting[UPDATE](index);\n\t\t\t},\n\t\t);\n\t};\n\n\tfindAll = ({\n\t\tindex,\n\t\tkey: providedKey,\n\t}: { index?: Filter; key?: string } = {}) => {\n\t\tconst key =\n\t\t\tprovidedKey || `findAll:${this.collection}:${this.serializeIndex(index)}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew FindAllQuery<T>({\n\t\t\t\t\tindex,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t}),\n\t\t\t(existing) => {\n\t\t\t\texisting[UPDATE](index);\n\t\t\t},\n\t\t);\n\t};\n\n\tfindPage = ({\n\t\tindex,\n\t\tpageSize,\n\t\tpage,\n\t\tkey: providedKey,\n\t}: {\n\t\tindex?: Filter;\n\t\tpageSize: number;\n\t\tpage: number;\n\t\tkey?: string;\n\t}) => {\n\t\tconst key =\n\t\t\tprovidedKey ||\n\t\t\t`findPage:${this.collection}:${this.serializeIndex(index)}:${pageSize}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew FindPageQuery<T>({\n\t\t\t\t\tindex,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t\tpageSize,\n\t\t\t\t\tpage,\n\t\t\t\t}),\n\t\t\t(existing) => {\n\t\t\t\texisting[UPDATE](index);\n\t\t\t},\n\t\t);\n\t};\n\n\tfindAllInfinite = ({\n\t\tindex,\n\t\tpageSize,\n\t\tkey: providedKey,\n\t}: {\n\t\tindex?: Filter;\n\t\tpageSize: number;\n\t\tkey?: string;\n\t}) => {\n\t\tconst key =\n\t\t\tprovidedKey ||\n\t\t\t`findAllInfinite:${this.collection}:${this.serializeIndex(\n\t\t\t\tindex,\n\t\t\t)}:${pageSize}`;\n\t\treturn this.cache.getOrSet(\n\t\t\tkey,\n\t\t\t() =>\n\t\t\t\tnew FindInfiniteQuery<T>({\n\t\t\t\t\tindex,\n\t\t\t\t\tcollection: this.collection,\n\t\t\t\t\thydrate: this.hydrate,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t\tkey,\n\t\t\t\t\tpageSize,\n\t\t\t\t}),\n\t\t\t(existing) => {\n\t\t\t\texisting[UPDATE](index);\n\t\t\t},\n\t\t);\n\t};\n}\n", "import { Context } from '../context.js';\nimport { Disposable } from '../utils/Disposable.js';\nimport { BaseQuery, ON_ALL_UNSUBSCRIBED } from './BaseQuery.js';\n\nexport class QueryCache extends Disposable {\n\tprivate _cache: Map<string, BaseQuery<any>> = new Map();\n\tprivate _evictionTime;\n\tprivate context;\n\n\tconstructor({\n\t\tevictionTime = 5 * 1000,\n\t\tcontext,\n\t}: {\n\t\tevictionTime?: number;\n\t\tcontext: Context;\n\t}) {\n\t\tsuper();\n\n\t\tthis._evictionTime = evictionTime;\n\t\tthis.context = context;\n\t}\n\n\tget<T extends BaseQuery<any>>(key: string): T | null {\n\t\treturn (this._cache.get(key) as T) || null;\n\t}\n\n\tset<V extends BaseQuery<any>>(value: V) {\n\t\tthis._cache.set(value.key, value);\n\t\tvalue[ON_ALL_UNSUBSCRIBED](this.onQueryUnsubscribed);\n\t\treturn value;\n\t}\n\n\tgetOrSet<V extends BaseQuery<any>>(\n\t\tkey: string,\n\t\tcreate: () => V,\n\t\tupdate?: (query: V) => void,\n\t) {\n\t\tconst existing = this.get<V>(key);\n\t\tif (existing) {\n\t\t\tupdate?.(existing);\n\t\t\treturn existing;\n\t\t}\n\t\treturn this.set(create());\n\t}\n\n\tprivate onQueryUnsubscribed = (query: BaseQuery<any>) => {\n\t\tsetTimeout(() => {\n\t\t\tif (query.subscribed) return;\n\t\t\t// double check before evicting... possible the cache\n\t\t\t// got a different version of this query.\n\t\t\tif (this._cache.get(query.key) === query) {\n\t\t\t\tthis._cache.delete(query.key);\n\t\t\t}\n\t\t}, this._evictionTime);\n\t};\n\n\tdropAll = () => {\n\t\tthis._cache.forEach((query) => query.dispose());\n\t\tthis._cache.clear();\n\t};\n\n\tforceRefreshAll = () => {\n\t\tthis._cache.forEach((q) => q.execute());\n\t};\n}\n", "import {\n\tServerMessage,\n\tEventSubscriber,\n\tBatcher,\n\tBatch,\n\tVerdantInternalPresence,\n\tinitialInternalPresence,\n} from '@verdant-web/common';\nimport type { UserInfo } from '../index.js';\nimport {\n\tLocalReplicaInfo,\n\tLocalReplicaStore,\n} from '../metadata/LocalReplicaStore.js';\n\nexport const HANDLE_MESSAGE = Symbol('handleMessage');\n\nexport class PresenceManager<\n\tProfile = any,\n\tPresence = any,\n> extends EventSubscriber<{\n\t/**\n\t * Fired when a particular peer's presence changes\n\t */\n\tpeerChanged: (userId: string, presence: UserInfo<Profile, Presence>) => void;\n\t/**\n\t * Fired immediately when a change to local presence is made. This change may not\n\t * yet have been sent to the server (see: \"update\" event)\n\t */\n\tselfChanged: (presence: UserInfo<Profile, Presence>) => void;\n\t/** Fired when any number of peer presences have changed */\n\tpeersChanged: (peers: Record<string, UserInfo<Profile, Presence>>) => void;\n\t/** Fired when a peer presence goes offline */\n\tpeerLeft: (userId: string, lastPresence: UserInfo<Profile, Presence>) => void;\n\t/** Fired after local presence changes are flushed to the server. */\n\tupdate: (data: {\n\t\tpresence?: Presence;\n\t\tinternal?: VerdantInternalPresence;\n\t}) => void;\n\tload: () => void;\n\t/** Fired on any change to a peer or the local user */\n\tchange: () => void;\n}> {\n\tprivate _peers = {} as Record<string, UserInfo<Profile, Presence>>;\n\tprivate _self = { profile: {} } as UserInfo<Profile, Presence>;\n\t// keep track of own replica IDs - applications may care if we're \"alone\" but with multiple devices.\n\tprivate _selfReplicaIds = new Set<string>();\n\tprivate _peerIds = new Array<string>();\n\tprivate _updateBatcher;\n\tprivate _updateBatch: Batch<{\n\t\tpresence?: Partial<Presence>;\n\t\tinternal?: Partial<VerdantInternalPresence>;\n\t}>;\n\n\tget self() {\n\t\treturn this._self;\n\t}\n\n\tget peers() {\n\t\treturn this._peers;\n\t}\n\n\tget peerIds() {\n\t\treturn this._peerIds;\n\t}\n\n\tget everyone() {\n\t\tconst everyone = { ...this._peers };\n\t\teveryone[this.self.id] = this.self;\n\t\treturn everyone;\n\t}\n\n\tget selfReplicaIds() {\n\t\treturn this._selfReplicaIds;\n\t}\n\n\tconstructor({\n\t\tinitialPresence,\n\t\tupdateBatchTimeout = 200,\n\t\tdefaultProfile,\n\t\treplicaStore,\n\t}: {\n\t\tinitialPresence: Presence;\n\t\tdefaultProfile: Profile;\n\t\tupdateBatchTimeout?: number;\n\t\treplicaStore: LocalReplicaStore;\n\t}) {\n\t\tsuper();\n\t\tthis.self.presence = initialPresence;\n\t\tthis.self.profile = defaultProfile;\n\t\tthis.self.internal = initialInternalPresence;\n\t\tthis.self.id = '';\n\t\tthis.self.replicaId = '';\n\n\t\t// set the local replica ID as soon as it's loaded\n\t\treplicaStore.get().then((info) => {\n\t\t\tthis.self.replicaId = info.id;\n\t\t});\n\n\t\tthis._updateBatcher = new Batcher(this.flushPresenceUpdates);\n\t\tthis._updateBatch = this._updateBatcher.add({\n\t\t\tmax: 25,\n\t\t\ttimeout: updateBatchTimeout,\n\t\t\titems: [],\n\t\t\tkey: 'default',\n\t\t});\n\t}\n\n\t/**\n\t * Decides if an update is for the local user or not. Even if it's a different replica\n\t * than the local one.\n\t *\n\t * If the replicaId matches, we use that first - we may not know the local replica's User ID yet,\n\t * e.g. on the first presence update.\n\t *\n\t * Otherwise, match the user ID to our local copy.\n\t */\n\tprivate isSelf = (\n\t\tlocalReplicaInfo: LocalReplicaInfo,\n\t\tuserInfo: UserInfo<Profile, Presence>,\n\t) => {\n\t\treturn (\n\t\t\tlocalReplicaInfo.id === userInfo.replicaId ||\n\t\t\tthis._selfReplicaIds.has(userInfo.replicaId) ||\n\t\t\tthis._self.id === userInfo.id\n\t\t);\n\t};\n\n\t[HANDLE_MESSAGE] = async (\n\t\tlocalReplicaInfo: LocalReplicaInfo,\n\t\tmessage: ServerMessage,\n\t) => {\n\t\tlet peersChanged = false;\n\t\tlet selfChanged = false;\n\t\tconst peerIdsSet = new Set<string>(this.peerIds);\n\n\t\tif (message.type === 'presence-changed') {\n\t\t\tif (this.isSelf(localReplicaInfo, message.userInfo)) {\n\t\t\t\tthis._self = message.userInfo;\n\t\t\t\tthis._selfReplicaIds.add(message.userInfo.replicaId);\n\t\t\t\tselfChanged = true;\n\t\t\t\tthis.emit('selfChanged', message.userInfo);\n\t\t\t} else {\n\t\t\t\tpeerIdsSet.add(message.userInfo.id);\n\t\t\t\tthis._peers[message.userInfo.id] = message.userInfo;\n\t\t\t\tpeersChanged = true;\n\t\t\t\tthis.emit('peerChanged', message.userInfo.id, message.userInfo);\n\t\t\t}\n\t\t} else if (message.type === 'sync-resp') {\n\t\t\t// reset to provided presence data, which includes all peers.\n\t\t\tthis._peers = {};\n\t\t\tpeerIdsSet.clear();\n\n\t\t\tfor (const [id, userInfo] of Object.entries(message.peerPresence)) {\n\t\t\t\tif (this.isSelf(localReplicaInfo, userInfo)) {\n\t\t\t\t\tthis._self = userInfo;\n\t\t\t\t\tthis._selfReplicaIds.add(userInfo.replicaId);\n\t\t\t\t\tselfChanged = true;\n\t\t\t\t\tthis.emit('selfChanged', userInfo);\n\t\t\t\t} else {\n\t\t\t\t\tpeersChanged = true;\n\t\t\t\t\tpeerIdsSet.add(id);\n\t\t\t\t\tthis._peers[id] = userInfo;\n\t\t\t\t\tthis.emit('peerChanged', id, userInfo);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (message.type === 'presence-offline') {\n\t\t\tpeerIdsSet.delete(message.userId);\n\t\t\tthis._selfReplicaIds.delete(message.replicaId);\n\t\t\tconst lastPresence = this._peers[message.userId];\n\t\t\tdelete this._peers[message.userId];\n\t\t\tpeersChanged = true;\n\t\t\tthis.emit('peerLeft', message.userId, lastPresence);\n\t\t}\n\t\tif (peersChanged) {\n\t\t\t// important that this stays sorted to keep stable order, don't want\n\t\t\t// peers swapping around.\n\t\t\tthis._peerIds = Array.from(peerIdsSet).sort();\n\t\t\tthis.emit('peersChanged', this._peers);\n\t\t}\n\t\tif (peersChanged || selfChanged) {\n\t\t\tthis.emit('change');\n\t\t}\n\t};\n\n\tupdate = async (presence: Partial<Presence>) => {\n\t\tthis._updateBatch.update({\n\t\t\titems: [{ presence }],\n\t\t});\n\t\t// proactively update the local presence\n\t\tthis.self.presence = { ...this.self.presence, ...presence };\n\t\tthis.emit('selfChanged', this.self);\n\t\tthis.emit('change');\n\t};\n\n\tflushPresenceUpdates = (\n\t\tpresenceUpdates: {\n\t\t\tpresence?: Partial<Presence>;\n\t\t\tinternal?: Partial<VerdantInternalPresence>;\n\t\t}[],\n\t) => {\n\t\tconst data = {\n\t\t\tpresence: this.self.presence,\n\t\t\tinternal: this.self.internal,\n\t\t};\n\t\tfor (const update of presenceUpdates) {\n\t\t\tif (update.presence) {\n\t\t\t\tObject.assign(data.presence as any, update.presence);\n\t\t\t}\n\t\t\tif (update.internal) {\n\t\t\t\tObject.assign(data.internal, update.internal);\n\t\t\t}\n\t\t}\n\t\tthis.emit('update', data);\n\t};\n\n\tsetViewId = (viewId: string | undefined) => {\n\t\tthis._updateBatch.update({\n\t\t\titems: [{ internal: { viewId } }],\n\t\t});\n\t\tthis.self.internal.viewId = viewId;\n\t\tthis.emit('selfChanged', this.self);\n\t\tthis.emit('change');\n\t};\n\n\tsetFieldId = (fieldId: string | undefined, timestamp = Date.now()) => {\n\t\tthis._updateBatch.update({\n\t\t\titems: [\n\t\t\t\t{ internal: { lastFieldId: fieldId, lastFieldTimestamp: timestamp } },\n\t\t\t],\n\t\t});\n\t\tthis.self.internal.lastFieldId = fieldId;\n\t\tthis.emit('selfChanged', this.self);\n\t\tthis.emit('change');\n\t};\n\n\t/**\n\t * Get all peers that are in the same view as the local user.\n\t */\n\tgetViewPeers = () => {\n\t\treturn (\n\t\t\tthis._peerIds\n\t\t\t\t.map((id) => this._peers[id])\n\t\t\t\t// undefined view matches all peers. otherwise,\n\t\t\t\t// filter to only those in the same view.\n\t\t\t\t.filter(\n\t\t\t\t\t(peer) =>\n\t\t\t\t\t\tthis.self.internal.viewId === undefined ||\n\t\t\t\t\t\tpeer.internal.viewId === this.self.internal.viewId,\n\t\t\t\t)\n\t\t);\n\t};\n\n\t/**\n\t * Get all peers that have interacted with the specified\n\t * field most recently.\n\t */\n\tgetFieldPeers = (fieldId: string, expirationPeriod = 60 * 1000) => {\n\t\treturn this._peerIds\n\t\t\t.map((id) => this._peers[id])\n\t\t\t.filter(\n\t\t\t\t(peer) =>\n\t\t\t\t\tpeer.internal.lastFieldId === fieldId &&\n\t\t\t\t\tDate.now() - peer.internal.lastFieldTimestamp! < expirationPeriod,\n\t\t\t);\n\t};\n}\n", "import { FileData } from '@verdant-web/common';\nimport { ServerSyncEndpointProvider } from './ServerSyncEndpointProvider.js';\n\nexport interface FileUploadResult {\n\tsuccess: boolean;\n\tretry: boolean;\n\terror?: string;\n}\n\nexport type FilePullResult =\n\t| {\n\t\t\tsuccess: true;\n\t\t\tdata: FileData;\n\t }\n\t| {\n\t\t\tsuccess: false;\n\t\t\tretry: boolean;\n\t\t\terror?: any;\n\t };\n\nexport class FileSync {\n\tprivate endpointProvider: ServerSyncEndpointProvider;\n\tprivate log: (...args: any[]) => any;\n\n\tconstructor({\n\t\tendpointProvider,\n\t\tlog,\n\t}: {\n\t\tendpointProvider: ServerSyncEndpointProvider;\n\t\tlog: (...args: any[]) => any;\n\t}) {\n\t\tthis.endpointProvider = endpointProvider;\n\t\tthis.log = log;\n\t}\n\n\tuploadFile = async (data: FileData): Promise<FileUploadResult> => {\n\t\tconst file = data.file;\n\n\t\tif (!file) {\n\t\t\tthrow new Error('Cannot upload a non-local file');\n\t\t}\n\n\t\t// multipart upload\n\t\tconst { files: fileEndpoint, token } =\n\t\t\tawait this.endpointProvider.getEndpoints();\n\n\t\tconst formData = new FormData();\n\t\tformData.append('file', file);\n\n\t\ttry {\n\t\t\tconst response = await fetch(fileEndpoint + `/${data.id}`, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: formData,\n\t\t\t\tcredentials: 'include',\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (response.ok) {\n\t\t\t\tthis.log('info', 'File upload successful');\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: true,\n\t\t\t\t\tretry: false,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tconst responseText = await response.text();\n\t\t\t\tthis.log('error', 'File upload failed', response.status, responseText);\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\tretry: response.status >= 500,\n\t\t\t\t\terror: `Failed to upload file: ${response.status} ${responseText}`,\n\t\t\t\t};\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tthis.log('error', 'File upload failed', e);\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\tretry: true,\n\t\t\t\terror: (e as Error).message,\n\t\t\t};\n\t\t}\n\t};\n\n\tgetFile = async (id: string): Promise<FilePullResult> => {\n\t\tconst { files: fileEndpoint, token } =\n\t\t\tawait this.endpointProvider.getEndpoints();\n\n\t\ttry {\n\t\t\tconst response = await fetch(fileEndpoint + `/${id}`, {\n\t\t\t\tmethod: 'GET',\n\t\t\t\tcredentials: 'include',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (response.ok) {\n\t\t\t\tconst data = await response.json();\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: true,\n\t\t\t\t\tdata,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tthis.log(\n\t\t\t\t\t'error',\n\t\t\t\t\t'File information fetch failed',\n\t\t\t\t\tresponse.status,\n\t\t\t\t\tawait response.text(),\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\tretry: response.status >= 500 || response.status === 404,\n\t\t\t\t};\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tthis.log('error', 'File information fetch failed', e);\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: e,\n\t\t\t\tretry: true,\n\t\t\t};\n\t\t}\n\t};\n}\n", "import { EventSubscriber } from '@verdant-web/common';\n\nexport class Heartbeat extends EventSubscriber<{\n\tmissed: () => void;\n\tbeat: () => void;\n}> {\n\tprivate _interval: number;\n\tprivate deadlineLength: number;\n\tprivate nextBeat: NodeJS.Timeout | null = null;\n\tprivate deadline: NodeJS.Timeout | null = null;\n\n\tget interval() {\n\t\treturn this._interval;\n\t}\n\n\tconstructor({\n\t\tinterval = 15 * 1000,\n\t\tdeadlineLength = 3 * 1000,\n\t\trestartOnTabFocus = true,\n\t}: {\n\t\tinterval?: number;\n\t\tdeadlineLength?: number;\n\t\trestartOnTabFocus?: boolean;\n\t} = {}) {\n\t\tsuper();\n\t\tthis._interval = interval;\n\t\tthis.deadlineLength = deadlineLength;\n\t\tif (typeof window !== 'undefined' && restartOnTabFocus) {\n\t\t\twindow.addEventListener('pageshow', () => this.start(true));\n\t\t\tdocument.addEventListener('visibilitychange', () => {\n\t\t\t\tif (document.visibilityState === 'visible') {\n\t\t\t\t\tthis.start(true);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tkeepAlive = () => {\n\t\tif (this.deadline) {\n\t\t\tclearTimeout(this.deadline);\n\t\t\tthis.deadline = null;\n\t\t\tthis.start();\n\t\t}\n\t};\n\n\tstart = (immediate = false) => {\n\t\tthis.stop();\n\t\tif (immediate) {\n\t\t\tthis.beat();\n\t\t} else {\n\t\t\tthis.nextBeat = setTimeout(this.beat, this._interval);\n\t\t}\n\t};\n\n\tstop = () => {\n\t\tif (this.nextBeat) {\n\t\t\tclearTimeout(this.nextBeat);\n\t\t}\n\t\tif (this.deadline) {\n\t\t\tclearTimeout(this.deadline);\n\t\t}\n\t};\n\n\tprivate beat = async () => {\n\t\tthis.emit('beat');\n\t\tthis.deadline = setTimeout(this.onDeadline, this.deadlineLength);\n\t};\n\n\tprivate onDeadline = () => {\n\t\tthis.deadline = null;\n\t\tthis.emit('missed');\n\t};\n\n\t/**\n\t * Only takes affect after the next beat\n\t */\n\tsetInterval = (interval: number) => {\n\t\tthis._interval = interval;\n\t};\n}\n", "import {\n\tClientMessage,\n\tEventSubscriber,\n\tPresenceUpdateMessage,\n\tServerMessage,\n\tVerdantErrorCode,\n\tdebounce,\n\tisVerdantErrorResponse,\n\tthrottle,\n} from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { PresenceManager } from './PresenceManager.js';\nimport { Heartbeat } from './Heartbeat.js';\nimport { ServerSyncEndpointProvider } from './ServerSyncEndpointProvider.js';\nimport { SyncTransport, SyncTransportEvents } from './Sync.js';\n\nexport class PushPullSync\n\textends EventSubscriber<SyncTransportEvents>\n\timplements SyncTransport\n{\n\treadonly meta: Metadata;\n\treadonly presence: PresenceManager;\n\tprivate endpointProvider;\n\tprivate heartbeat;\n\tprivate fetch;\n\n\treadonly mode = 'pull';\n\tprivate log;\n\n\tprivate _isConnected = false;\n\tprivate _status: 'active' | 'paused' = 'paused';\n\tprivate _hasSynced = false;\n\n\tconstructor({\n\t\tendpointProvider,\n\t\tmeta,\n\t\tpresence,\n\t\tinterval = 15 * 1000,\n\t\tlog = () => {},\n\t\tfetch = window.fetch.bind(window),\n\t}: {\n\t\tendpointProvider: ServerSyncEndpointProvider;\n\t\tmeta: Metadata;\n\t\tpresence: PresenceManager;\n\t\tinterval?: number;\n\t\tlog?: (...args: any[]) => any;\n\t\tfetch?: typeof window.fetch;\n\t}) {\n\t\tsuper();\n\t\tthis.log = log;\n\t\tthis.meta = meta;\n\t\tthis.presence = presence;\n\t\tthis.endpointProvider = endpointProvider;\n\t\tthis.fetch = fetch;\n\n\t\tthis.heartbeat = new Heartbeat({\n\t\t\tinterval,\n\t\t});\n\t\tthis.heartbeat.subscribe('beat', this.onHeartbeat);\n\t\tthis.heartbeat.subscribe('missed', this.onHeartbeatMissed);\n\t}\n\n\tsetInterval = (interval: number) => {\n\t\tthis.heartbeat.setInterval(interval);\n\t};\n\n\tget interval() {\n\t\treturn this.heartbeat.interval;\n\t}\n\n\tget hasSynced() {\n\t\treturn this._hasSynced;\n\t}\n\n\tprivate sendRequest = async (messages: ClientMessage[]) => {\n\t\tthis.log('Sending sync request', messages);\n\t\ttry {\n\t\t\tconst { http: host, token } = await this.endpointProvider.getEndpoints();\n\t\t\tconst response = await this.fetch(host, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tmessages,\n\t\t\t\t}),\n\t\t\t\tcredentials: 'include',\n\t\t\t});\n\t\t\tif (response.ok) {\n\t\t\t\tthis.heartbeat.keepAlive();\n\t\t\t\tconst json = (await response.json()) as {\n\t\t\t\t\tmessages: ServerMessage[];\n\t\t\t\t};\n\t\t\t\t// for (const message of json.messages) {\n\t\t\t\t// \tthis.handleServerMessage(message);\n\t\t\t\t// }\n\t\t\t\tconst handlePromise = Promise.all(\n\t\t\t\t\tjson.messages.map(this.handleServerMessage),\n\t\t\t\t);\n\t\t\t\tif (!this._isConnected) {\n\t\t\t\t\tthis._isConnected = true;\n\t\t\t\t\tthis.emit('onlineChange', true);\n\t\t\t\t}\n\t\t\t\tawait handlePromise;\n\t\t\t} else {\n\t\t\t\tthis.log('Sync request failed', response.status, await response.text());\n\n\t\t\t\tif (this._isConnected) {\n\t\t\t\t\tthis._isConnected = false;\n\t\t\t\t\tthis.emit('onlineChange', false);\n\t\t\t\t}\n\n\t\t\t\tconst json = await response.json();\n\t\t\t\tif (isVerdantErrorResponse(json)) {\n\t\t\t\t\t// token expired... retry again later after clearing it\n\t\t\t\t\tif (json.code === VerdantErrorCode.TokenExpired) {\n\t\t\t\t\t\tthis.endpointProvider.clearCache();\n\t\t\t\t\t\tthis.heartbeat.keepAlive();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// only keep trying if the error was not 4xx\n\t\t\t\tif (response.status >= 500) {\n\t\t\t\t\tthis.heartbeat.keepAlive();\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (this._isConnected) {\n\t\t\t\tthis._isConnected = false;\n\t\t\t\tthis.emit('onlineChange', false);\n\t\t\t}\n\t\t\tthis.log(error);\n\n\t\t\tthis.heartbeat.keepAlive();\n\t\t}\n\t};\n\n\tprivate handleServerMessage = async (message: ServerMessage) => {\n\t\tif (message.type === 'sync-resp') {\n\t\t\t// we need to ack the nonce to confirm that we received the sync-resp\n\t\t\t// but we can go ahead and preemptively allow ops to be sent\n\t\t\tthis._hasSynced = true;\n\t\t\tif (message.ackThisNonce) {\n\t\t\t\tthis.log('Sending sync ack', message.ackThisNonce);\n\t\t\t\tawait this.sendRequest([\n\t\t\t\t\tawait this.meta.messageCreator.createAck(message.ackThisNonce),\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t\tthis.emit('message', message);\n\t};\n\n\t// reduce rate of presence messages sent; each one would trigger an HTTP\n\t// request, which is not ideal if presence is updating rapidly.\n\tthrottledPresenceUpdate = throttle((message: PresenceUpdateMessage) => {\n\t\tthis.sendRequest([message]);\n\t}, 3000);\n\n\tsend = (message: ClientMessage) => {\n\t\t// only certain messages are sent for pull-based sync.\n\t\tswitch (message.type) {\n\t\t\tcase 'presence-update':\n\t\t\t\treturn this.throttledPresenceUpdate(message);\n\t\t\tcase 'sync':\n\t\t\tcase 'heartbeat':\n\t\t\t\treturn this.sendRequest([message]);\n\t\t\tcase 'op':\n\t\t\t\tif (this._hasSynced) {\n\t\t\t\t\treturn this.sendRequest([message]);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tstart = async () => {\n\t\tif (this.status === 'active') {\n\t\t\treturn;\n\t\t}\n\t\tawait this.endpointProvider.getEndpoints();\n\t\tthis.heartbeat.start(true);\n\t\tthis._status = 'active';\n\t};\n\tstop(): void {\n\t\tthis.heartbeat.stop();\n\t\tthis._status = 'paused';\n\t}\n\n\tdestroy = () => {\n\t\tthis.dispose();\n\t\tthis.stop();\n\t};\n\treconnect(): void {\n\t\tthis.heartbeat.start(true);\n\t}\n\n\tignoreIncoming(): void {\n\t\tthis.stop();\n\t}\n\n\t// on a heartbeat, do a sync\n\tprivate onHeartbeat = async () => {\n\t\t// for HTTP sync we send presence first, so that the sync-resp message\n\t\t// will include the client's own presence info and fill in missing profile\n\t\t// data on the first request. otherwise it would have to wait for the second.\n\t\tthis.sendRequest([\n\t\t\tawait this.meta.messageCreator.createPresenceUpdate(this.presence.self),\n\t\t\tawait this.meta.messageCreator.createSyncStep1(),\n\t\t]);\n\t};\n\n\t// if the server fails to respond in a certain amount of time, we assume\n\t// the connection is lost and go offline.\n\tprivate onHeartbeatMissed = async () => {\n\t\tthis.emit('onlineChange', false);\n\t\tthis.log('Missed heartbeat');\n\t\tthis._isConnected = false;\n\t};\n\n\tsyncOnce = async () => {\n\t\tawait this.sendRequest([await this.meta.messageCreator.createSyncStep1()]);\n\t};\n\n\tget isConnected(): boolean {\n\t\treturn this._isConnected;\n\t}\n\tget status() {\n\t\treturn this._status;\n\t}\n}\n", "/**\n * The code was extracted from:\n * https://github.com/davidchambers/Base64.js\n */\n\nvar chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";\n\nfunction InvalidCharacterError(message) {\n this.message = message;\n}\n\nInvalidCharacterError.prototype = new Error();\nInvalidCharacterError.prototype.name = \"InvalidCharacterError\";\n\nfunction polyfill(input) {\n var str = String(input).replace(/=+$/, \"\");\n if (str.length % 4 == 1) {\n throw new InvalidCharacterError(\n \"'atob' failed: The string to be decoded is not correctly encoded.\"\n );\n }\n for (\n // initialize result and counters\n var bc = 0, bs, buffer, idx = 0, output = \"\";\n // get next character\n (buffer = str.charAt(idx++));\n // character found in table? initialize bit storage and add its ascii value;\n ~buffer &&\n ((bs = bc % 4 ? bs * 64 + buffer : buffer),\n // and if not first of each 4 characters,\n // convert the first 8 bits to one ascii character\n bc++ % 4) ?\n (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) :\n 0\n ) {\n // try to find character in table (0-63, not found => -1)\n buffer = chars.indexOf(buffer);\n }\n return output;\n}\n\nexport default (typeof window !== \"undefined\" &&\n window.atob &&\n window.atob.bind(window)) ||\npolyfill;", "import atob from \"./atob\";\n\nfunction b64DecodeUnicode(str) {\n return decodeURIComponent(\n atob(str).replace(/(.)/g, function(m, p) {\n var code = p.charCodeAt(0).toString(16).toUpperCase();\n if (code.length < 2) {\n code = \"0\" + code;\n }\n return \"%\" + code;\n })\n );\n}\n\nexport default function(str) {\n var output = str.replace(/-/g, \"+\").replace(/_/g, \"/\");\n switch (output.length % 4) {\n case 0:\n break;\n case 2:\n output += \"==\";\n break;\n case 3:\n output += \"=\";\n break;\n default:\n throw \"Illegal base64url string!\";\n }\n\n try {\n return b64DecodeUnicode(output);\n } catch (err) {\n return atob(output);\n }\n}", "\"use strict\";\n\nimport base64_url_decode from \"./base64_url_decode\";\n\nexport function InvalidTokenError(message) {\n this.message = message;\n}\n\nInvalidTokenError.prototype = new Error();\nInvalidTokenError.prototype.name = \"InvalidTokenError\";\n\nexport default function(token, options) {\n if (typeof token !== \"string\") {\n throw new InvalidTokenError(\"Invalid token specified\");\n }\n\n options = options || {};\n var pos = options.header === true ? 0 : 1;\n try {\n return JSON.parse(base64_url_decode(token.split(\".\")[pos]));\n } catch (e) {\n throw new InvalidTokenError(\"Invalid token specified: \" + e.message);\n }\n}", "import { assert, ReplicaType } from '@verdant-web/common';\nimport { default as jwtDecode } from 'jwt-decode';\n\nexport interface ServerSyncEndpointProviderConfig {\n\t/**\n\t * The location of the endpoint used to retrieve an\n\t * authorization token for the client.\n\t */\n\tauthEndpoint?: string;\n\t/**\n\t * A custom function to retrieve authorization\n\t * data. Use whatever fetching mechanism you want.\n\t */\n\tfetchAuth?: () => Promise<{\n\t\taccessToken: string;\n\t}>;\n\t/**\n\t * A spec-compliant fetch implementation. If not provided,\n\t * the global fetch will be used. authEndpoint will\n\t * be used to fetch the token.\n\t */\n\tfetch?: typeof fetch;\n}\n\nexport interface SyncTokenInfo {\n\turl: string;\n\tfileUrl: string;\n\ttype: ReplicaType;\n\tuserId: string;\n\tlibraryId: string;\n\trole?: string;\n}\n\nexport class ServerSyncEndpointProvider {\n\tprivate cached = null as {\n\t\thttp: string;\n\t\twebsocket: string;\n\t\tfiles: string;\n\t\ttoken: string;\n\t} | null;\n\ttokenInfo: SyncTokenInfo | null = null;\n\n\tget type() {\n\t\treturn this.tokenInfo?.type ?? ReplicaType.Realtime;\n\t}\n\n\tconstructor(private config: ServerSyncEndpointProviderConfig) {\n\t\tif (!config.authEndpoint && !config.fetchAuth) {\n\t\t\tthrow new Error(\n\t\t\t\t'Either authEndpoint or fetchAuth must be provided to ServerSyncEndpointProvider',\n\t\t\t);\n\t\t}\n\t}\n\n\tgetEndpoints = async () => {\n\t\tif (this.cached) {\n\t\t\treturn this.cached;\n\t\t}\n\n\t\tlet result: { accessToken: string };\n\t\tif (this.config.fetchAuth) {\n\t\t\tresult = await this.config.fetchAuth();\n\t\t} else {\n\t\t\tconst fetchImpl = this.config.fetch || fetch.bind(window);\n\t\t\tresult = await fetchImpl(this.config.authEndpoint!, {\n\t\t\t\tcredentials: 'include',\n\t\t\t}).then((res) => {\n\t\t\t\tif (!res.ok) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Auth endpoint returned non-200 response: ${res.status}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\treturn res.json();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tassert(result.accessToken, 'No access token provided from auth endpoint');\n\t\tconst decoded = (jwtDecode as any)(result.accessToken);\n\t\tassert(decoded.url, 'No sync endpoint provided from auth endpoint');\n\t\tassert(\n\t\t\tdecoded.type !== undefined,\n\t\t\t'No replica type provided from auth endpoint',\n\t\t);\n\t\tthis.tokenInfo = {\n\t\t\tuserId: decoded.sub,\n\t\t\tlibraryId: decoded.lib,\n\t\t\turl: decoded.url,\n\t\t\tfileUrl: decoded.file,\n\t\t\trole: decoded.role,\n\t\t\ttype: parseInt(decoded.type + '') as ReplicaType,\n\t\t};\n\t\tconst url = new URL(decoded.url);\n\t\turl.protocol = url.protocol.replace('ws', 'http');\n\t\tconst httpEndpoint = url.toString();\n\t\turl.protocol = url.protocol.replace('http', 'ws');\n\t\tconst websocketEndpoint = url.toString();\n\t\tlet fileEndpoint: string = decoded.file;\n\t\tif (!fileEndpoint) {\n\t\t\t// default to http endpoint + '/files';\n\t\t\tconst fileUrl = new URL(httpEndpoint);\n\t\t\tfileUrl.pathname = fileUrl.pathname + '/files';\n\t\t\tfileEndpoint = fileUrl.toString();\n\t\t}\n\t\tthis.cached = {\n\t\t\thttp: httpEndpoint,\n\t\t\twebsocket: websocketEndpoint,\n\t\t\tfiles: fileEndpoint,\n\t\t\ttoken: result.accessToken,\n\t\t};\n\t\treturn this.cached;\n\t};\n\n\tclearCache = () => {\n\t\tthis.cached = null;\n\t};\n}\n", "import { EventSubscriber } from '@verdant-web/common';\n\nexport class BackoffScheduler extends EventSubscriber<{\n\ttrigger: () => void;\n}> {\n\tprivate readonly backoff: Backoff;\n\tprivate timer: NodeJS.Timeout | null = null;\n\tprivate isScheduled = false;\n\n\tconstructor(backoff: Backoff) {\n\t\tsuper();\n\t\tthis.backoff = backoff;\n\t}\n\n\tnext = () => {\n\t\tif (!this.isScheduled) {\n\t\t\tthis.isScheduled = true;\n\t\t\tthis.timer = setTimeout(() => {\n\t\t\t\tthis.emit('trigger');\n\t\t\t\tthis.isScheduled = false;\n\t\t\t\tthis.backoff.next();\n\t\t\t}, this.backoff.current);\n\t\t}\n\t};\n\n\treset = () => {\n\t\tthis.backoff.reset();\n\t\tif (this.timer) {\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = null;\n\t\t}\n\t};\n}\n\nexport class Backoff {\n\tcurrent = 0;\n\tprivate readonly max: number;\n\tprivate readonly factor: number;\n\n\tconstructor(max: number, factor: number) {\n\t\tthis.max = max;\n\t\tthis.factor = factor;\n\t}\n\n\tnext = () => {\n\t\tthis.current = Math.min(this.max, this.current * this.factor);\n\t};\n\n\treset = () => {\n\t\tthis.current = 0;\n\t};\n}\n", "import {\n\tClientMessage,\n\tEventSubscriber,\n\tServerMessage,\n} from '@verdant-web/common';\nimport { Backoff, BackoffScheduler } from '../BackoffScheduler.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { Heartbeat } from './Heartbeat.js';\nimport { PresenceManager } from './PresenceManager.js';\nimport { ServerSyncEndpointProvider } from './ServerSyncEndpointProvider.js';\nimport { SyncTransport, SyncTransportEvents } from './Sync.js';\n\nexport class WebSocketSync\n\textends EventSubscriber<SyncTransportEvents>\n\timplements SyncTransport\n{\n\tprivate meta: Metadata;\n\treadonly presence: PresenceManager;\n\tprivate socket: WebSocket | null = null;\n\t// messages awaiting websocket connection to send\n\tprivate connectQueue: ClientMessage[] = [];\n\t// messages awaiting sync response to send\n\tprivate syncQueue: ClientMessage[] = [];\n\t// messages waiting for sync to finish\n\tprivate incomingQueue: ServerMessage[] = [];\n\tprivate endpointProvider;\n\tprivate _status: 'active' | 'paused' = 'paused';\n\tprivate synced = false;\n\tprivate hasStartedSync = false;\n\tprivate _ignoreIncoming = false;\n\n\treadonly mode = 'realtime';\n\tprivate log = (...args: any[]) => {};\n\n\tprivate heartbeat = new Heartbeat();\n\n\tprivate reconnectScheduler = new BackoffScheduler(\n\t\tnew Backoff(60 * 1000, 1.5),\n\t);\n\n\tconstructor({\n\t\tendpointProvider,\n\t\tmeta,\n\t\tpresence,\n\t\tlog,\n\t}: {\n\t\tendpointProvider: ServerSyncEndpointProvider;\n\t\tmeta: Metadata;\n\t\tpresence: PresenceManager;\n\t\tlog?: (...args: any[]) => any;\n\t}) {\n\t\tsuper();\n\t\tthis.log = log || this.log;\n\t\tthis.endpointProvider = endpointProvider;\n\t\tthis.meta = meta;\n\t\tthis.presence = presence;\n\n\t\tthis.reconnectScheduler.subscribe('trigger', this.initializeSocket);\n\t\tthis.heartbeat.subscribe('beat', this.sendHeartbeat);\n\t}\n\n\tget hasSynced() {\n\t\treturn this.synced;\n\t}\n\n\tprivate onOpen = () => {\n\t\tif (!this.socket) {\n\t\t\tthrow new Error('Invalid sync state: online but socket is null');\n\t\t}\n\t\tthis.synced = false;\n\t\tif (this.connectQueue.length) {\n\t\t\tfor (const msg of this.connectQueue) {\n\t\t\t\tthis.log('Sending queued message', JSON.stringify(msg, null, 2));\n\t\t\t\tthis.socket.send(JSON.stringify(msg));\n\t\t\t}\n\t\t\tthis.connectQueue = [];\n\t\t}\n\t\tthis.log('Sync connected');\n\t\tthis.onOnlineChange(true);\n\t\tthis.reconnectScheduler.reset();\n\t};\n\n\tprivate onOnlineChange = async (online: boolean) => {\n\t\tthis.log('Socket online change', online);\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\t\tif (!online) {\n\t\t\tthis.hasStartedSync = false;\n\t\t\tthis.synced = false;\n\t\t\tthis.heartbeat.stop();\n\t\t} else {\n\t\t\tthis.log('Starting sync');\n\t\t\tthis.hasStartedSync = true;\n\t\t\tthis.synced = false;\n\t\t\tthis.send(\n\t\t\t\tawait this.meta.messageCreator.createPresenceUpdate(this.presence.self),\n\t\t\t);\n\t\t\tthis.send(await this.meta.messageCreator.createSyncStep1());\n\t\t\tthis.heartbeat.start();\n\t\t}\n\t\tthis.emit('onlineChange', online);\n\t};\n\n\tprivate onMessage = async (event: MessageEvent) => {\n\t\tif (this._ignoreIncoming) {\n\t\t\tthis.log(\n\t\t\t\t'Ignoring incoming message (ignore incoming flag set)',\n\t\t\t\tevent.data,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst message = JSON.parse(event.data) as ServerMessage;\n\t\tswitch (message.type) {\n\t\t\tcase 'sync-resp':\n\t\t\t\tif (message.ackThisNonce) {\n\t\t\t\t\t// we need to send the ack to confirm we got the response\n\t\t\t\t\tthis.send(\n\t\t\t\t\t\tawait this.meta.messageCreator.createAck(message.ackThisNonce),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.hasStartedSync = true;\n\t\t\t\tthis.synced = true;\n\t\t\t\tif (this.syncQueue.length) {\n\t\t\t\t\tif (message.overwriteLocalData) {\n\t\t\t\t\t\tthis.log(\n\t\t\t\t\t\t\t'warn',\n\t\t\t\t\t\t\t'Overwriting local data - dropping outgoing message queue',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.syncQueue = [];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfor (const msg of this.syncQueue) {\n\t\t\t\t\t\t\tthis.send(msg);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.syncQueue = [];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.emit('message', message);\n\t\t\t\tif (this.incomingQueue.length) {\n\t\t\t\t\tfor (const msg of this.incomingQueue) {\n\t\t\t\t\t\tthis.emit('message', msg);\n\t\t\t\t\t}\n\t\t\t\t\tthis.incomingQueue = [];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'need-since':\n\t\t\tcase 'presence-changed':\n\t\t\tcase 'presence-offline':\n\t\t\t\tthis.emit('message', message);\n\t\t\t\tbreak;\n\t\t\tcase 'op-re':\n\t\t\t\tif (!this.synced) {\n\t\t\t\t\tthis.log(\n\t\t\t\t\t\t`Enqueueing op-re message because sync hasn't finished yet`,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t);\n\t\t\t\t\tthis.incomingQueue.push(message);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tthis.emit('message', message);\n\t\t\t\tbreak;\n\t\t\tcase 'heartbeat-response':\n\t\t\t\tthis.heartbeat.keepAlive();\n\t\t\t\tthis.emit('message', message);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tif (this.synced) {\n\t\t\t\t\tthis.emit('message', message);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tprivate onError = (event: Event) => {\n\t\tthis.log(event);\n\t\tthis.reconnectScheduler.next();\n\n\t\tthis.log(`Attempting reconnect to websocket sync`);\n\t};\n\n\tprivate onClose = (event: CloseEvent) => {\n\t\tthis.log('Sync disconnected');\n\t\tthis.onOnlineChange(false);\n\t\tthis.onError(event);\n\t};\n\n\tprivate initializeSocket = async () => {\n\t\tconst endpoint = await this.endpointProvider.getEndpoints();\n\t\t// abusing protocols to pass the auth token\n\t\tthis.socket = new WebSocket(endpoint.websocket, ['Bearer', endpoint.token]);\n\t\tthis.socket.addEventListener('message', this.onMessage);\n\t\tthis.socket.addEventListener('open', this.onOpen);\n\t\tthis.socket.addEventListener('error', this.onError);\n\t\tthis.socket.addEventListener('close', this.onClose);\n\t\treturn this.socket;\n\t};\n\n\tprivate sendHeartbeat = async () => {\n\t\tthis.send(await this.meta.messageCreator.createHeartbeat());\n\t};\n\n\treconnect = () => {\n\t\tthis.stop();\n\t\tthis.start();\n\t};\n\n\tprivate canSkipSyncWait = (message: ClientMessage) => {\n\t\treturn (\n\t\t\tmessage.type === 'sync' ||\n\t\t\tmessage.type === 'presence-update' ||\n\t\t\tmessage.type === 'sync-ack' ||\n\t\t\tmessage.type === 'heartbeat'\n\t\t);\n\t};\n\n\tsend = (message: ClientMessage) => {\n\t\tif (this.status !== 'active') return;\n\n\t\t// wait until a sync has started before doing anything other than sync.\n\t\t// new \"op\" messages can arrive before sync has started, so we need to wait\n\t\tif (!this.hasStartedSync && !this.canSkipSyncWait(message)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.canSkipSyncWait(message)) {\n\t\t\tif (this.socket?.readyState === WebSocket.OPEN) {\n\t\t\t\tthis.log('Sending message', JSON.stringify(message, null, 2));\n\t\t\t\tthis.socket!.send(JSON.stringify(message));\n\t\t\t} else {\n\t\t\t\tthis.log(\n\t\t\t\t\t'Enqueueing message until socket is open',\n\t\t\t\t\tJSON.stringify(message, null, 2),\n\t\t\t\t);\n\t\t\t\tthis.connectQueue.push(message);\n\t\t\t}\n\t\t} else if (this.synced) {\n\t\t\tif (this.socket?.readyState === WebSocket.OPEN) {\n\t\t\t\tthis.log('Sending message', JSON.stringify(message, null, 2));\n\t\t\t\tthis.socket.send(JSON.stringify(message));\n\t\t\t}\n\t\t} else if (this.hasStartedSync) {\n\t\t\tthis.log(\n\t\t\t\t'Enqueueing message until synced',\n\t\t\t\tJSON.stringify(message, null, 2),\n\t\t\t);\n\t\t\tthis.syncQueue.push(message);\n\t\t}\n\t};\n\n\tdestroy = () => {\n\t\tthis.dispose();\n\t\tthis.stop();\n\t};\n\n\tstart = async () => {\n\t\tif (this.socket) {\n\t\t\treturn;\n\t\t}\n\t\tawait this.initializeSocket();\n\t\tthis._status = 'active';\n\t};\n\n\tstop = () => {\n\t\tthis.socket?.removeEventListener('message', this.onMessage);\n\t\tthis.socket?.removeEventListener('close', this.onClose);\n\t\tthis.socket?.close();\n\t\tthis.socket = null;\n\t\tthis._status = 'paused';\n\t};\n\n\tignoreIncoming(): void {\n\t\tthis.incomingQueue = [];\n\t\tthis._ignoreIncoming = true;\n\t}\n\n\tget isConnected() {\n\t\treturn this.socket?.readyState === WebSocket.OPEN;\n\t}\n\n\tget status() {\n\t\treturn this._status;\n\t}\n}\n", "export async function attemptToRegisterBackgroundSync() {\n\ttry {\n\t\tconst status = await navigator.permissions.query({\n\t\t\tname: 'periodic-background-sync' as any,\n\t\t});\n\t\tif (status.state === 'granted') {\n\t\t\t// Periodic background sync can be used.\n\t\t\tconst registration = await navigator.serviceWorker.ready;\n\t\t\tif ('periodicSync' in registration) {\n\t\t\t\ttry {\n\t\t\t\t\tawait (registration.periodicSync as any).register('verdant-sync', {\n\t\t\t\t\t\t// An interval of one day.\n\t\t\t\t\t\tminInterval: 24 * 60 * 60 * 1000,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Periodic background sync cannot be used.\n\t\t\t\t\tconsole.warn('Failed to register background sync:', error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Periodic background sync cannot be used.\n\t\t\tconsole.debug('Background sync permission is not granted:', status);\n\t\t}\n\t} catch (error) {\n\t\tconsole.error('Failed to initiate background sync:', error);\n\t}\n}\n", "import {\n\tClientMessage,\n\tDocumentBaseline,\n\tEventSubscriber,\n\tFileData,\n\tOperation,\n\tReplicaType,\n\trewriteAuthzOriginator,\n\tServerMessage,\n\tVerdantError,\n\tVerdantInternalPresence,\n} from '@verdant-web/common';\nimport { Metadata } from '../metadata/Metadata.js';\nimport { HANDLE_MESSAGE, PresenceManager } from './PresenceManager.js';\nimport { FilePullResult, FileSync, FileUploadResult } from './FileSync.js';\nimport { PushPullSync } from './PushPullSync.js';\nimport {\n\tServerSyncEndpointProvider,\n\tServerSyncEndpointProviderConfig,\n} from './ServerSyncEndpointProvider.js';\nimport { WebSocketSync } from './WebSocketSync.js';\nimport { Context } from '../context.js';\nimport { attemptToRegisterBackgroundSync } from './background.js';\n\ntype SyncEvents = {\n\tonlineChange: (isOnline: boolean) => void;\n\tsyncingChange: (syncing: boolean) => void;\n\t/** When the server has lost data and re-requests data from the past */\n\tserverReset: (since: string | null) => void;\n};\n\nexport type SyncTransportEvents = SyncEvents & {\n\tmessage: (message: ServerMessage) => void;\n};\n\nexport interface SyncTransport extends EventSubscriber<SyncTransportEvents> {\n\treadonly presence: PresenceManager;\n\n\treadonly mode: SyncTransportMode;\n\treadonly hasSynced: boolean;\n\n\tsend(message: ClientMessage): void;\n\n\tstart(): Promise<void>;\n\tignoreIncoming(): void;\n\tstop(): void;\n\n\tdestroy(): void;\n\n\treconnect(): void;\n\n\treadonly isConnected: boolean;\n\treadonly status: 'active' | 'paused';\n}\n\nexport interface Sync<Presence = any, Profile = any>\n\textends EventSubscriber<SyncEvents> {\n\tsetMode(mode: SyncTransportMode): void;\n\tsetPullInterval(interval: number): void;\n\treadonly pullInterval: number;\n\tuploadFile(data: FileData): Promise<FileUploadResult>;\n\tgetFile(fileId: string): Promise<FilePullResult>;\n\treadonly presence: PresenceManager<Profile, Presence>;\n\tsend(message: ClientMessage): void;\n\tstart(): Promise<void>;\n\tstop(): void;\n\tignoreIncoming(): void;\n\tdestroy(): void;\n\treconnect(): void;\n\tsyncOnce(): Promise<void>;\n\treadonly isConnected: boolean;\n\treadonly status: 'active' | 'paused';\n\treadonly mode: SyncTransportMode;\n}\n\nexport class NoSync<Presence = any, Profile = any>\n\textends EventSubscriber<SyncEvents>\n\timplements Sync<Presence, Profile>\n{\n\treadonly mode = 'pull';\n\n\tpublic send(): void {}\n\n\tpublic async start(): Promise<void> {}\n\n\tpublic stop(): void {}\n\n\tpublic ignoreIncoming(): void {}\n\n\tpublic destroy = () => {};\n\n\tpublic reconnect(): void {}\n\n\tpublic setMode(): void {}\n\tpublic setPullInterval(): void {}\n\n\tpublic readonly isConnected = false;\n\tpublic readonly status = 'paused';\n\tpublic readonly pullInterval = 0;\n\n\tpublic readonly presence;\n\n\tconstructor({ meta }: { meta: Metadata }) {\n\t\tsuper();\n\t\tthis.presence = new PresenceManager({\n\t\t\tinitialPresence: null as any,\n\t\t\tdefaultProfile: null as any,\n\t\t\treplicaStore: meta.localReplica,\n\t\t});\n\t}\n\n\tuploadFile = async () => {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tretry: false,\n\t\t};\n\t};\n\n\tgetFile = async (): Promise<FilePullResult> => {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tretry: false,\n\t\t};\n\t};\n\n\tsyncOnce: () => Promise<void> = async () => {};\n}\n\nexport type SyncTransportMode = 'realtime' | 'pull';\n\nexport interface ServerSyncOptions<Profile = any, Presence = any>\n\textends ServerSyncEndpointProviderConfig {\n\t/**\n\t * When a client first connects, it will use this presence value.\n\t */\n\tinitialPresence: Presence;\n\t/**\n\t * Before connecting to the server, the local client will have\n\t * this value for their profile data. You can either cache and store\n\t * profile data from a previous connection or provide defaults like\n\t * empty strings.\n\t */\n\tdefaultProfile: Profile;\n\n\t/**\n\t * Provide `false` to disable transport selection. Transport selection\n\t * automatically switches between HTTP and WebSocket based sync depending\n\t * on the number of peers connected. If a user is alone, they will use\n\t * HTTP push/pull to sync changes. If another user joins, both users will\n\t * be upgraded to websockets.\n\t *\n\t * Provide `peers-only` to only automatically use websockets if other\n\t * users connect, but not if another device for the current user connects.\n\t * By default, automatic transport selection will upgrade to websockets if\n\t * another device from the current user connects, but if realtime sync is\n\t * not necessary for such cases, you can save bandwidth by disabling this.\n\t *\n\t * Turning off this feature allows you more control over the transport\n\t * which can be useful for low-power devices or to save server traffic.\n\t * To modify transport modes manually, utilize `client.sync.setMode`.\n\t * The built-in behavior is essentially switching modes based on\n\t * the number of peers detected by client.sync.presence.\n\t */\n\tautomaticTransportSelection?: boolean | 'peers-only';\n\tinitialTransport?: SyncTransportMode;\n\tautoStart?: boolean;\n\t/**\n\t * Optionally specify an interval, in milliseconds, to poll the server\n\t * when in pull mode.\n\t */\n\tpullInterval?: number;\n\t/**\n\t * Presence updates are batched to reduce number of requests / messages\n\t * sent to the server. You can specify the batching time slice, in milliseconds,\n\t */\n\tpresenceUpdateBatchTimeout?: number;\n\t/**\n\t * Experimental: sync messages over a broadcast channel between tabs.\n\t * Fixes tabs not reactively updating to changes when other tabs are open,\n\t * but is not yet thoroughly vetted.\n\t */\n\tuseBroadcastChannel?: boolean;\n\t/**\n\t * Listen for outgoing messages from the client to the server.\n\t * Not sure why you want to do this, but be careful.\n\t */\n\tonOutgoingMessage?: (message: ClientMessage) => void;\n\n\tEXPERIMENTAL_backgroundSync?: boolean;\n}\n\nexport class ServerSync<Presence = any, Profile = any>\n\textends EventSubscriber<SyncEvents>\n\timplements Sync<Presence, Profile>\n{\n\tprivate webSocketSync: WebSocketSync;\n\tprivate pushPullSync: PushPullSync;\n\tprivate fileSync: FileSync;\n\tprivate activeSync: SyncTransport;\n\tprivate endpointProvider;\n\tprivate onData: (data: {\n\t\toperations: Operation[];\n\t\tbaselines?: DocumentBaseline[];\n\t\treset?: boolean;\n\t}) => Promise<void>;\n\tprivate broadcastChannel: BroadcastChannel | null = null;\n\tprivate _activelySyncing = false;\n\n\tprivate meta: Metadata;\n\n\treadonly presence: PresenceManager<Profile, Presence>;\n\n\tprivate onOutgoingMessage?: (message: ClientMessage) => void;\n\n\tprivate log;\n\n\tconstructor(\n\t\t{\n\t\t\tauthEndpoint,\n\t\t\tfetchAuth,\n\t\t\tfetch,\n\t\t\tinitialPresence,\n\t\t\tautomaticTransportSelection = true,\n\t\t\tautoStart,\n\t\t\tinitialTransport,\n\t\t\tpullInterval,\n\t\t\tpresenceUpdateBatchTimeout,\n\t\t\tdefaultProfile,\n\t\t\tuseBroadcastChannel,\n\t\t\tonOutgoingMessage,\n\t\t\tEXPERIMENTAL_backgroundSync,\n\t\t}: ServerSyncOptions<Profile, Presence>,\n\t\t{\n\t\t\tmeta,\n\t\t\tctx,\n\t\t\tonData,\n\t\t}: {\n\t\t\tmeta: Metadata;\n\t\t\tctx: Context;\n\t\t\tonData: (data: {\n\t\t\t\toperations: Operation[];\n\t\t\t\tbaselines?: DocumentBaseline[];\n\t\t\t\treset?: boolean;\n\t\t\t}) => Promise<void>;\n\t\t},\n\t) {\n\t\tsuper();\n\t\tthis.meta = meta;\n\t\tthis.onData = onData;\n\t\tthis.log = ctx.log;\n\t\tthis.onOutgoingMessage = onOutgoingMessage;\n\t\tthis.presence = new PresenceManager({\n\t\t\tinitialPresence,\n\t\t\tdefaultProfile,\n\t\t\tupdateBatchTimeout: presenceUpdateBatchTimeout,\n\t\t\treplicaStore: meta.localReplica,\n\t\t});\n\t\tthis.endpointProvider = new ServerSyncEndpointProvider({\n\t\t\tauthEndpoint,\n\t\t\tfetchAuth,\n\t\t\tfetch,\n\t\t});\n\n\t\tthis.webSocketSync = new WebSocketSync({\n\t\t\tendpointProvider: this.endpointProvider,\n\t\t\tmeta,\n\t\t\tpresence: this.presence,\n\t\t\tlog: ctx.log,\n\t\t});\n\t\tthis.pushPullSync = new PushPullSync({\n\t\t\tendpointProvider: this.endpointProvider,\n\t\t\tmeta,\n\t\t\tpresence: this.presence,\n\t\t\tlog: ctx.log,\n\t\t\tinterval: pullInterval,\n\t\t\tfetch,\n\t\t});\n\t\tthis.fileSync = new FileSync({\n\t\t\tendpointProvider: this.endpointProvider,\n\t\t\tlog: ctx.log,\n\t\t});\n\t\tif (useBroadcastChannel && 'BroadcastChannel' in window) {\n\t\t\tthis.broadcastChannel = new BroadcastChannel(`verdant-${ctx.namespace}`);\n\t\t\tthis.broadcastChannel.addEventListener(\n\t\t\t\t'message',\n\t\t\t\tthis.handleBroadcastChannelMessage,\n\t\t\t);\n\t\t}\n\t\tif (initialTransport === 'realtime') {\n\t\t\tthis.activeSync = this.webSocketSync;\n\t\t} else {\n\t\t\tthis.activeSync = this.pushPullSync;\n\t\t}\n\n\t\tthis.presence.subscribe('update', this.handlePresenceUpdate);\n\n\t\tthis.meta.subscribe('message', this.send);\n\n\t\tthis.webSocketSync.subscribe('message', this.handleMessage);\n\t\tthis.webSocketSync.subscribe('onlineChange', this.handleOnlineChange);\n\n\t\tthis.pushPullSync.subscribe('message', this.handleMessage);\n\t\tthis.pushPullSync.subscribe('onlineChange', this.handleOnlineChange);\n\n\t\tif (automaticTransportSelection && this.canDoRealtime) {\n\t\t\t// automatically shift between transport modes depending\n\t\t\t// on whether any peers are present (matching view if\n\t\t\t// applicable)\n\t\t\tconst decideIfUpgrade = () => {\n\t\t\t\tif (switchoverTimeout) {\n\t\t\t\t\tclearTimeout(switchoverTimeout);\n\t\t\t\t}\n\t\t\t\tconst hasPeers = this.presence.getViewPeers().length > 0;\n\t\t\t\tconst shouldUpgrade =\n\t\t\t\t\thasPeers ||\n\t\t\t\t\t(automaticTransportSelection !== 'peers-only' &&\n\t\t\t\t\t\tthis.presence.selfReplicaIds.size > 1);\n\t\t\t\tif (shouldUpgrade && this.mode === 'pull') {\n\t\t\t\t\tthis.setMode('realtime');\n\t\t\t\t} else if (!shouldUpgrade && this.mode === 'realtime') {\n\t\t\t\t\t// wait 1 second then switch to pull mode if still empty\n\t\t\t\t\tswitchoverTimeout = setTimeout(() => {\n\t\t\t\t\t\tif (this.presence.getViewPeers().length === 0) {\n\t\t\t\t\t\t\tthis.setMode('pull');\n\t\t\t\t\t\t}\n\t\t\t\t\t}, 1000);\n\t\t\t\t}\n\t\t\t};\n\t\t\tlet switchoverTimeout: NodeJS.Timeout;\n\t\t\tthis.presence.subscribe('peersChanged', decideIfUpgrade);\n\t\t\tif (automaticTransportSelection !== 'peers-only') {\n\t\t\t\tthis.presence.subscribe('selfChanged', decideIfUpgrade);\n\t\t\t}\n\t\t}\n\n\t\tif (autoStart) {\n\t\t\tthis.start();\n\t\t}\n\n\t\tif (EXPERIMENTAL_backgroundSync) {\n\t\t\tattemptToRegisterBackgroundSync();\n\t\t}\n\t}\n\n\tget canDoRealtime() {\n\t\treturn (\n\t\t\tthis.endpointProvider.type === ReplicaType.Realtime ||\n\t\t\tthis.endpointProvider.type === ReplicaType.PassiveRealtime ||\n\t\t\tthis.endpointProvider.type === ReplicaType.ReadOnlyRealtime\n\t\t);\n\t}\n\n\tget syncing() {\n\t\treturn this._activelySyncing;\n\t}\n\n\tprivate handleBroadcastChannelMessage = (event: MessageEvent) => {\n\t\tif (event.data.type === 'sync') {\n\t\t\tthis.handleMessage(event.data.message, { source: 'broadcastChannel' });\n\t\t}\n\t};\n\n\tprivate onTokenExpired = () => {\n\t\tthis.endpointProvider.clearCache();\n\t};\n\n\tprivate handleMessage = async (\n\t\tmessage: ServerMessage,\n\t\t{ source }: { source: 'network' | 'broadcastChannel' } = {\n\t\t\tsource: 'network',\n\t\t},\n\t) => {\n\t\t// TODO: move this into metadata\n\t\tif (message.type === 'op-re' || message.type === 'sync-resp') {\n\t\t\tfor (const op of message.operations) {\n\t\t\t\tthis.meta.time.update(op.timestamp);\n\t\t\t}\n\t\t}\n\n\t\tthis.log('debug', 'sync message', JSON.stringify(message, null, 2));\n\t\tswitch (message.type) {\n\t\t\tcase 'op-re':\n\t\t\t\tawait this.onData({\n\t\t\t\t\toperations: message.operations,\n\t\t\t\t\tbaselines: message.baselines,\n\t\t\t\t});\n\t\t\t\tif (message.globalAckTimestamp) {\n\t\t\t\t\tawait this.meta.setGlobalAck(message.globalAckTimestamp);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'global-ack':\n\t\t\t\tawait this.meta.setGlobalAck(message.timestamp);\n\t\t\t\tbreak;\n\t\t\tcase 'sync-resp':\n\t\t\t\tthis._activelySyncing = true;\n\t\t\t\tthis.emit('syncingChange', true);\n\t\t\t\tawait this.onData({\n\t\t\t\t\toperations: message.operations,\n\t\t\t\t\tbaselines: message.baselines,\n\t\t\t\t\treset: message.overwriteLocalData,\n\t\t\t\t});\n\n\t\t\t\tif (message.globalAckTimestamp) {\n\t\t\t\t\tawait this.meta.setGlobalAck(message.globalAckTimestamp);\n\t\t\t\t}\n\n\t\t\t\tawait this.meta.updateLastSynced(message.ackedTimestamp);\n\t\t\t\tthis._activelySyncing = false;\n\t\t\t\tthis.emit('syncingChange', false);\n\t\t\t\tbreak;\n\t\t\tcase 'need-since':\n\t\t\t\tthis.emit('serverReset', message.since);\n\t\t\t\tthis.activeSync.send(\n\t\t\t\t\tawait this.meta.messageCreator.createSyncStep1(message.since),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'server-ack':\n\t\t\t\tawait this.meta.updateLastSynced(message.timestamp);\n\t\t}\n\n\t\t// avoid rebroadcasting messages\n\t\tif (source === 'network') {\n\t\t\tthis.broadcastChannel?.postMessage({\n\t\t\t\ttype: 'sync',\n\t\t\t\tmessage,\n\t\t\t});\n\t\t}\n\n\t\t// update presence if necessary\n\t\tthis.presence[HANDLE_MESSAGE](await this.meta.localReplica.get(), message);\n\t};\n\tprivate handleOnlineChange = (online: boolean) => {\n\t\tthis.emit('onlineChange', online);\n\t};\n\tprivate handlePresenceUpdate = async (data: {\n\t\tpresence?: Presence;\n\t\tinternal?: VerdantInternalPresence;\n\t}) => {\n\t\tthis.send(await this.meta.messageCreator.createPresenceUpdate(data));\n\t};\n\n\tsetMode = (transport: SyncTransportMode) => {\n\t\tif (transport === 'realtime' && !this.canDoRealtime) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot switch to realtime mode, because the current auth token does not allow it`,\n\t\t\t);\n\t\t}\n\n\t\tlet newSync: SyncTransport;\n\t\tif (transport === 'realtime') {\n\t\t\tnewSync = this.webSocketSync;\n\t\t} else {\n\t\t\tnewSync = this.pushPullSync;\n\t\t}\n\n\t\tif (newSync === this.activeSync) return;\n\t\tthis.log('debug', 'switching to', transport, 'mode');\n\n\t\t// transfer state to new sync\n\t\tif (this.activeSync.status === 'active') {\n\t\t\tnewSync.start();\n\t\t}\n\t\tthis.activeSync.stop();\n\t\tthis.activeSync = newSync;\n\t};\n\n\tsetPullInterval = (interval: number) => {\n\t\tthis.pushPullSync.setInterval(interval);\n\t};\n\n\tget pullInterval() {\n\t\treturn this.pushPullSync.interval;\n\t}\n\n\tsend = async (message: ClientMessage) => {\n\t\tif (this.activeSync.status === 'active') {\n\t\t\t// before sync, replace 'originator' authz subjects\n\t\t\t// with token userId. This is the easiest place to\n\t\t\t// do this and allows the rest of the system to be\n\t\t\t// ambivalent about user identity when assigning\n\t\t\t// authorization for the current user.\n\t\t\tconst userId = this.endpointProvider.tokenInfo?.userId;\n\t\t\tif (!userId) {\n\t\t\t\tthrow new VerdantError(\n\t\t\t\t\tVerdantError.Code.Unexpected,\n\t\t\t\t\tundefined,\n\t\t\t\t\t'Active sync has invalid token info',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (message.type === 'sync' || message.type === 'op') {\n\t\t\t\trewriteAuthzOriginator(message, userId);\n\t\t\t}\n\t\t\tawait this.activeSync.send(message);\n\t\t\tthis.onOutgoingMessage?.(message);\n\t\t}\n\t};\n\n\tuploadFile = async (info: FileData) => {\n\t\tthis.log('info', 'Uploading file', {\n\t\t\tname: info.name,\n\t\t\ttype: info.type,\n\t\t\tid: info.id,\n\t\t\tsize: info.file?.size,\n\t\t});\n\t\tif (this.activeSync.status === 'active') {\n\t\t\treturn this.fileSync.uploadFile(info);\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\tretry: false,\n\t\t\t\terror: 'Sync is not active',\n\t\t\t};\n\t\t}\n\t};\n\n\tgetFile = async (id: string) => {\n\t\t// TODO: should this error? or just try anyway?\n\t\tif (this.activeSync.status === 'active') {\n\t\t\treturn this.fileSync.getFile(id);\n\t\t} else {\n\t\t\tthrow new Error('Offline, cannot retrieve remote file details');\n\t\t}\n\t};\n\n\tpublic start = () => {\n\t\treturn this.activeSync.start();\n\t};\n\n\tpublic stop = () => {\n\t\treturn this.activeSync.stop();\n\t};\n\n\tpublic ignoreIncoming(): void {\n\t\tthis.activeSync.ignoreIncoming();\n\t}\n\n\tpublic destroy = () => {\n\t\tthis.dispose();\n\t\tthis.webSocketSync.destroy();\n\t\tthis.pushPullSync.destroy();\n\t};\n\n\tpublic reconnect = () => {\n\t\treturn this.activeSync.reconnect();\n\t};\n\n\t/**\n\t * Runs one isolated sync cycle over HTTP. This is useful for\n\t * syncing via a periodic background job in a service worker,\n\t * which keeps a client up to date while the app isn't open.\n\t */\n\tpublic syncOnce = () => {\n\t\treturn this.pushPullSync.syncOnce();\n\t};\n\n\tpublic get isConnected(): boolean {\n\t\treturn this.activeSync.isConnected;\n\t}\n\n\tpublic get status() {\n\t\treturn this.activeSync.status;\n\t}\n\n\tpublic get mode() {\n\t\treturn this.activeSync.mode;\n\t}\n}\n", "import {\n\tDocumentBaseline,\n\tgetTimestampSchemaVersion,\n\tOperation,\n} from '@verdant-web/common';\n\nexport function getLatestVersion(data: {\n\toperations: Operation[];\n\tbaselines?: DocumentBaseline[];\n}) {\n\tconst timestamps = data.operations\n\t\t.map((op) => op.timestamp)\n\t\t.concat(data.baselines?.map((b) => b.timestamp) ?? []);\n\tconst latestVersion = timestamps.reduce((v, ts) => {\n\t\tconst tsVersion = getTimestampSchemaVersion(ts);\n\t\tif (tsVersion > v) {\n\t\t\treturn tsVersion;\n\t\t}\n\t\treturn v;\n\t}, 0);\n\n\treturn latestVersion;\n}\n", "import {\n\tdebounce,\n\tDocumentBaseline,\n\tEventSubscriber,\n\tgetTimestampSchemaVersion,\n\tMigration,\n\tOperation,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { DocumentManager } from '../entities/DocumentManager.js';\nimport { EntityStore } from '../entities/EntityStore.js';\nimport { FileManager, FileManagerConfig } from '../files/FileManager.js';\nimport { ReturnedFileData } from '../files/FileStorage.js';\nimport {\n\tcloseDatabase,\n\tdeleteAllDatabases,\n\tgetSizeOfObjectStore,\n} from '../idb.js';\nimport {\n\tExportData,\n\tMetadata,\n\tsupportLegacyExport,\n} from '../metadata/Metadata.js';\nimport { openQueryDatabase } from '../migration/openQueryDatabase.js';\nimport { CollectionQueries } from '../queries/CollectionQueries.js';\nimport { QueryCache } from '../queries/QueryCache.js';\nimport { NoSync, ServerSync, ServerSyncOptions, Sync } from '../sync/Sync.js';\nimport { getLatestVersion } from '../utils/versions.js';\n\ninterface ClientConfig<Presence = any> {\n\tsyncConfig?: ServerSyncOptions<Presence>;\n\tmigrations: Migration[];\n\tfiles?: FileManagerConfig;\n}\n\n// not actually used below, but helpful for internal code which\n// might rely on this stuff...\nexport type ClientWithCollections = Client & {\n\t[key: string]: CollectionQueries<any, any, any>;\n};\n\nexport class Client<Presence = any, Profile = any> extends EventSubscriber<{\n\t/**\n\t * Called when a change from a future version of the application has\n\t * been witnessed. These changes are not applied but it indicates\n\t * the app has been updated and a peer is using a newer version.\n\t * You should listen to this event and prompt the user to reload\n\t * their client, or reload it for them.\n\t *\n\t * This event may be called multiple times.\n\t */\n\tfutureSeen: () => void;\n\t/**\n\t * The server requested this replica reset its state\n\t * completely. This can happen when the replica has\n\t * been offline for too long and reconnects.\n\t */\n\tresetToServer: () => void;\n\t/**\n\t * These are errors that, as a developer, you should subscribe to\n\t * and prompt users to contact you for resolution. Usually these errors\n\t * indicate the client is in an unrecoverable state.\n\t */\n\tdeveloperError: (err: Error) => void;\n}> {\n\treadonly meta: Metadata;\n\tprivate _entities: EntityStore;\n\tprivate _queryCache: QueryCache;\n\tprivate _documentManager: DocumentManager<any>;\n\tprivate _fileManager: FileManager;\n\tprivate _closed = false;\n\n\treadonly collectionNames: string[];\n\n\tprivate _sync!: Sync<Presence, Profile>;\n\n\tget sync() {\n\t\treturn this._sync;\n\t}\n\n\tget entities() {\n\t\treturn this._entities;\n\t}\n\n\tget documentManager() {\n\t\treturn this._documentManager;\n\t}\n\n\tconstructor(\n\t\tprivate config: ClientConfig,\n\t\tprivate context: Context,\n\t\tcomponents: { meta: Metadata },\n\t) {\n\t\tsuper();\n\t\tthis.meta = components.meta;\n\t\tthis.collectionNames = Object.keys(context.schema.collections);\n\t\tthis._sync =\n\t\t\tthis.config.syncConfig && !context.schema.wip\n\t\t\t\t? new ServerSync<Presence, Profile>(this.config.syncConfig, {\n\t\t\t\t\t\tmeta: this.meta,\n\t\t\t\t\t\tonData: this.addData,\n\t\t\t\t\t\tctx: this.context,\n\t\t\t\t })\n\t\t\t\t: new NoSync<Presence, Profile>({ meta: this.meta });\n\t\tif (context.schema.wip && this.config.syncConfig) {\n\t\t\tcontext.log(\n\t\t\t\t'warn',\n\t\t\t\t'\u26A0\uFE0F\u26A0\uFE0F Sync is disabled for WIP schemas. Commit your schema changes to start syncing again. \u26A0\uFE0F\u26A0\uFE0F',\n\t\t\t);\n\t\t}\n\n\t\tthis._fileManager = new FileManager({\n\t\t\tdb: this.metaDb,\n\t\t\tsync: this.sync,\n\t\t\tcontext: this.context,\n\t\t\tconfig: this.config.files,\n\t\t\tmeta: this.meta,\n\t\t});\n\t\tthis._queryCache = new QueryCache({\n\t\t\tcontext,\n\t\t});\n\t\tthis._entities = new EntityStore({\n\t\t\tctx: this.context,\n\t\t\tmeta: this.meta,\n\t\t\tfiles: this._fileManager,\n\t\t});\n\t\tthis._documentManager = new DocumentManager(this.schema, this._entities);\n\n\t\tconst notifyFutureSeen = debounce(() => {\n\t\t\tthis.emit('futureSeen');\n\t\t}, 300);\n\t\tthis.context.globalEvents.subscribe('futureSeen', notifyFutureSeen);\n\t\tthis.context.globalEvents.subscribe('resetToServer', () => {\n\t\t\tthis.emit('resetToServer');\n\t\t});\n\n\t\tthis.watchForVersionChange();\n\n\t\tthis.metaDb.addEventListener('versionchange', () => {\n\t\t\tthis.context.log?.(\n\t\t\t\t'warn',\n\t\t\t\t`Another tab has requested a version change for ${this.namespace}`,\n\t\t\t);\n\t\t\tthis.metaDb.close();\n\t\t\tif (typeof window !== 'undefined') {\n\t\t\t\twindow.location.reload();\n\t\t\t}\n\t\t});\n\n\t\t// self-assign collection shortcuts. these are not typed\n\t\t// here but are typed in the generated code...\n\t\tfor (const [name, _collection] of Object.entries(\n\t\t\tcontext.schema.collections,\n\t\t)) {\n\t\t\tconst collectionName = name;\n\t\t\t(this as any)[collectionName] = new CollectionQueries({\n\t\t\t\tcollection: collectionName,\n\t\t\t\tcache: this._queryCache,\n\t\t\t\tcontext: this.context,\n\t\t\t\tentities: this.entities,\n\t\t\t\tdocumentManager: this.documentManager,\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate watchForVersionChange = () => {\n\t\tthis.documentDb.addEventListener('versionchange', () => {\n\t\t\tthis.context.log?.(\n\t\t\t\t'warn',\n\t\t\t\t`Another tab has requested a version change for ${this.namespace}`,\n\t\t\t);\n\t\t\tthis.documentDb.close();\n\t\t\tif (typeof window !== 'undefined') {\n\t\t\t\twindow.location.reload();\n\t\t\t}\n\t\t});\n\t};\n\n\tprivate importingPromise = Promise.resolve();\n\tprivate addData = async (data: {\n\t\toperations: Operation[];\n\t\tbaselines?: DocumentBaseline[];\n\t\treset?: boolean;\n\t}) => {\n\t\t// always wait for an ongoing import to complete before handling data.\n\t\tawait this.importingPromise;\n\n\t\ttry {\n\t\t\tconst schemaVersion = data.reset\n\t\t\t\t? getLatestVersion(data)\n\t\t\t\t: this.schema.version;\n\n\t\t\tif (schemaVersion < this.schema.version) {\n\t\t\t\t/**\n\t\t\t\t * Edge case: the server has an older version of the library\n\t\t\t\t * than the client schema, but it wants the client to reset.\n\t\t\t\t *\n\t\t\t\t * This happens when a truant or new client loads up newest client\n\t\t\t\t * code with a new schema version, but the last sync to the\n\t\t\t\t * server was from an old version. It's particularly a problem\n\t\t\t\t * if the new schema drops collections, since the IDB table for\n\t\t\t\t * that collection will no longer exist, so loading in old data\n\t\t\t\t * will result in an error.\n\t\t\t\t *\n\t\t\t\t * To handle this, we treat the reset data as if it were an import\n\t\t\t\t * of exported data. The import procedure handles older\n\t\t\t\t * schema versions by resetting the database to the imported\n\t\t\t\t * version, then migrating up to the current version.\n\t\t\t\t */\n\t\t\t\tthis.context.log(\n\t\t\t\t\t'warn',\n\t\t\t\t\t'Incoming reset sync data is from an old schema version',\n\t\t\t\t\tschemaVersion,\n\t\t\t\t\t`(current ${this.schema.version})`,\n\t\t\t\t);\n\t\t\t\t// run through the import flow to properly handle old versions\n\t\t\t\treturn await this.import({\n\t\t\t\t\tdata: {\n\t\t\t\t\t\toperations: data.operations,\n\t\t\t\t\t\tbaselines: data.baselines ?? [],\n\t\t\t\t\t\t// keep existing\n\t\t\t\t\t\tlocalReplica: undefined,\n\t\t\t\t\t\tschemaVersion,\n\t\t\t\t\t},\n\t\t\t\t\tfileData: [],\n\t\t\t\t\tfiles: [],\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\treturn await this._entities.addData(data);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthis.context.log('critical', 'Sync failed', err);\n\t\t\tthis.emit(\n\t\t\t\t'developerError',\n\t\t\t\tnew Error('Sync failed, see logs or cause', {\n\t\t\t\t\tcause: err,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tthrow err;\n\t\t}\n\t};\n\n\tget documentDb() {\n\t\treturn this.context.documentDb;\n\t}\n\n\tget metaDb() {\n\t\treturn this.context.metaDb;\n\t}\n\n\tget schema() {\n\t\treturn this.context.schema;\n\t}\n\n\tget namespace() {\n\t\treturn this.context.namespace;\n\t}\n\n\tget undoHistory() {\n\t\treturn this.context.undoHistory;\n\t}\n\n\t/**\n\t * Batch multiple operations together to be executed in a single transaction.\n\t * The changes made will not be included in the same undo history step as\n\t * any other changes made outside of the batch. You can also disable undo\n\t * for your batch to omit changes from undo history.\n\t *\n\t * Provide a batch name to apply multiple changes to the same batch\n\t * across different invocations. Batches will automatically flush after\n\t * a short delay or if they reach a maximum size.\n\t */\n\tget batch() {\n\t\treturn this.entities.batch;\n\t}\n\n\tstats = async (): Promise<ClientStats> => {\n\t\tconst collectionNames = Object.keys(this.schema.collections);\n\t\tlet collections = {} as Record<string, { count: number; size: number }>;\n\t\tif (this.disposed) {\n\t\t\treturn {} as any;\n\t\t}\n\t\tfor (const collectionName of collectionNames) {\n\t\t\ttry {\n\t\t\t\tcollections[collectionName] = await getSizeOfObjectStore(\n\t\t\t\t\tthis.documentDb,\n\t\t\t\t\tcollectionName,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\tthis.context.log?.('error', err);\n\t\t\t}\n\t\t}\n\t\tif (this.disposed) {\n\t\t\treturn { collections } as any;\n\t\t}\n\t\tconst meta = await this.meta.stats();\n\t\tconst storage =\n\t\t\ttypeof navigator !== 'undefined' &&\n\t\t\ttypeof navigator.storage !== 'undefined' &&\n\t\t\t'estimate' in navigator.storage\n\t\t\t\t? await navigator.storage.estimate()\n\t\t\t\t: undefined;\n\n\t\tconst files = await this._fileManager.stats();\n\n\t\t// determine data:metadata ratio for total size of all collections vs metadata\n\t\tconst totalCollectionsSize = Object.values(collections).reduce(\n\t\t\t(acc, { size }) => acc + size,\n\t\t\t0,\n\t\t);\n\t\tconst totalMetaSize = meta.baselinesSize.size + meta.operationsSize.size;\n\t\tconst metaToDataRatio = totalMetaSize / totalCollectionsSize;\n\n\t\treturn {\n\t\t\tcollections,\n\t\t\tmeta,\n\t\t\tstorage,\n\t\t\ttotalMetaSize,\n\t\t\ttotalCollectionsSize,\n\t\t\tmetaToDataRatio,\n\t\t\tfiles,\n\t\t\tquotaUsage:\n\t\t\t\tstorage?.usage && storage?.quota\n\t\t\t\t\t? storage.usage / storage.quota\n\t\t\t\t\t: undefined,\n\t\t};\n\t};\n\n\tclose = async () => {\n\t\tthis._closed = true;\n\t\tthis.sync.ignoreIncoming();\n\t\tawait this._entities.flushAllBatches();\n\t\tthis._fileManager.close();\n\t\tthis.sync.stop();\n\t\tthis.sync.destroy();\n\t\t// this step does have the potential to flush\n\t\t// changes to storage, so don't close metadata db yet\n\t\tawait this._entities.destroy();\n\n\t\tthis.meta.close();\n\n\t\t// the idea here is to flush the microtask queue -\n\t\t// we may have queued tasks related to queries that\n\t\t// we want to settle before closing the databases\n\t\t// to avoid invalid state errors\n\t\tawait new Promise<void>(async (resolve) => {\n\t\t\tawait closeDatabase(this.documentDb);\n\t\t\tawait closeDatabase(this.metaDb);\n\t\t\tresolve();\n\t\t});\n\n\t\tthis.context.log?.('info', 'Client closed');\n\t};\n\n\t__dangerous__resetLocal = async () => {\n\t\tthis.sync.stop();\n\t\tawait deleteAllDatabases(this.namespace, indexedDB);\n\t};\n\n\texport = async (\n\t\t{ downloadRemoteFiles }: { downloadRemoteFiles?: boolean } = {\n\t\t\tdownloadRemoteFiles: true,\n\t\t},\n\t) => {\n\t\tthis.context.log('info', 'Exporting data...');\n\t\tconst metaExport = await this.meta.export();\n\t\tconst filesExport = await this._fileManager.exportAll(downloadRemoteFiles);\n\t\t// split files into data and files\n\t\tconst fileData: Array<Omit<ReturnedFileData, 'file'>> = [];\n\t\tconst files: Array<File> = [];\n\n\t\tfor (const fileExport of filesExport) {\n\t\t\tconst file = fileExport.file;\n\t\t\tdelete fileExport.file;\n\t\t\tfileData.push(fileExport);\n\t\t\tif (file) {\n\t\t\t\t// rename with ID\n\t\t\t\tconst asFile = new File(\n\t\t\t\t\t[file],\n\t\t\t\t\tthis.getFileExportName(fileExport.name, fileExport.id),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: fileExport.type,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tfiles.push(asFile);\n\t\t\t} else {\n\t\t\t\tthis.context.log(\n\t\t\t\t\t'warn',\n\t\t\t\t\t`File ${fileExport.id} was could not be loaded locally or from the server. It will be missing in the export.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tdata: metaExport,\n\t\t\tfileData,\n\t\t\tfiles,\n\t\t};\n\t};\n\n\tprivate getFileExportName = (originalFileName: string, id: string) => {\n\t\treturn `${id}___${originalFileName}`;\n\t};\n\n\tprivate parseFileExportname = (name: string) => {\n\t\tconst [id, originalFileName] = name.split('___');\n\t\treturn { id, originalFileName };\n\t};\n\n\timport = async ({\n\t\tdata: rawData,\n\t\tfileData,\n\t\tfiles,\n\t}: {\n\t\tdata: ExportData;\n\t\tfileData: Array<Omit<ReturnedFileData, 'file'>>;\n\t\tfiles: File[];\n\t}) => {\n\t\t/**\n\t\t * Importing is a pretty involved procedure because of the possibility of\n\t\t * importing an export from an older version of the schema. We can't add\n\t\t * data from older schemas because the indexes may have changed or whole\n\t\t * collections may have been since deleted, leaving no corresponding IDB\n\t\t * tables.\n\t\t *\n\t\t * Since IDB doesn't allow us to go backwards, and we are resetting all\n\t\t * data anyways, the import procedure blows away the current queryable DB\n\t\t * and restarts from the imported schema version. It then migrates up\n\t\t * to the latest (current) version. These migrations are added to the imported\n\t\t * data to produce the final state.\n\t\t */\n\n\t\t// register importing promise to halt other data handling\n\t\tlet resolve = () => {};\n\t\tthis.importingPromise = new Promise<void>((res) => {\n\t\t\tresolve = res;\n\t\t});\n\n\t\tconst data = supportLegacyExport(rawData);\n\t\tthis.context.log('info', 'Importing data...');\n\t\t// close the document DB\n\t\tawait closeDatabase(this.context.documentDb);\n\n\t\tawait this.meta.resetFrom(data);\n\t\t// re-attach files to their file data and import\n\t\tconst fileToIdMap = new Map(\n\t\t\tfiles.map((file) => {\n\t\t\t\tconst { id } = this.parseFileExportname(file.name);\n\t\t\t\treturn [id, file];\n\t\t\t}),\n\t\t);\n\t\tconst importedFiles: ReturnedFileData[] = fileData.map((fileData) => {\n\t\t\tconst file = fileToIdMap.get(fileData.id);\n\n\t\t\treturn {\n\t\t\t\t...fileData,\n\t\t\t\tfile,\n\t\t\t};\n\t\t});\n\t\tawait this._fileManager.importAll(importedFiles);\n\t\t// now delete the document DB, open it to the specified version\n\t\t// and run migrations to get it to the latest version\n\t\tconst version = data.schemaVersion;\n\t\tconst deleteReq = indexedDB.deleteDatabase(\n\t\t\t[this.namespace, 'collections'].join('_'),\n\t\t);\n\t\tawait new Promise((resolve, reject) => {\n\t\t\tdeleteReq.onsuccess = resolve;\n\t\t\tdeleteReq.onerror = reject;\n\t\t});\n\t\t// reset our context to the imported schema for now\n\t\tconst currentSchema = this.context.schema;\n\t\tif (currentSchema.version !== version) {\n\t\t\tconst oldSchema = this.context.oldSchemas?.find(\n\t\t\t\t(s) => s.version === version,\n\t\t\t);\n\t\t\tif (!oldSchema) {\n\t\t\t\tthis.emit(\n\t\t\t\t\t'developerError',\n\t\t\t\t\tnew Error(`Could not find schema for version ${version}`),\n\t\t\t\t);\n\t\t\t\tthrow new Error(`Could not find schema for version ${version}`);\n\t\t\t}\n\n\t\t\tthis.context.schema = oldSchema;\n\t\t}\n\t\t// now open the document DB empty at the specified version\n\t\t// and initialize it from the meta DB\n\t\tthis.context.documentDb = await openQueryDatabase({\n\t\t\tmeta: this.meta,\n\t\t\tmigrations: this.config.migrations,\n\t\t\tcontext: this.context,\n\t\t\tversion,\n\t\t});\n\t\tthis.context.internalEvents.emit('documentDbChanged', this.documentDb);\n\t\t// re-initialize data\n\t\tthis.context.log('info', 'Re-initializing data from imported data...');\n\t\tawait this._entities.addData({\n\t\t\toperations: data.operations,\n\t\t\tbaselines: data.baselines,\n\t\t\treset: true,\n\t\t});\n\t\t// close the database and reopen to latest version, applying\n\t\t// migrations\n\t\tawait closeDatabase(this.context.documentDb);\n\t\tthis.context.log('info', 'Migrating up to latest schema...');\n\t\t// put the schema back\n\t\tthis.context.schema = currentSchema;\n\t\tthis.context.documentDb = await openQueryDatabase({\n\t\t\tmeta: this.meta,\n\t\t\tmigrations: this.config.migrations,\n\t\t\tcontext: this.context,\n\t\t\tversion: currentSchema.version,\n\t\t});\n\t\tthis.context.internalEvents.emit('documentDbChanged', this.documentDb);\n\t\t// re-establish watcher on database\n\t\tthis.watchForVersionChange();\n\n\t\t// finally... clear out memory cache of entities and\n\t\t// re-run all active queries.\n\t\tthis.entities.clearCache();\n\t\tthis._queryCache.forceRefreshAll();\n\n\t\tresolve();\n\t};\n\n\t/**\n\t * Export all data, then re-import it. This might resolve\n\t * some issues with the local database, but it should\n\t * only be done as a second-to-last resort. The last resort\n\t * would be __dangerous__resetLocal on ClientDescriptor, which\n\t * clears all local data.\n\t *\n\t * Unlike __dangerous__resetLocal, this method allows local-only\n\t * clients to recover data, whereas __dangerous__resetLocal only\n\t * lets networked clients recover from the server.\n\t */\n\t__dangerous__hardReset = async () => {\n\t\tconst exportData = await this.export();\n\t\tawait this.import(exportData);\n\t};\n\n\t/**\n\t * Immediately runs the file deletion process. This is useful\n\t * for testing, mostly. Or if your client is long-lived, since\n\t * normally this cleanup only runs on startup.\n\t *\n\t * Note this still follows the file deletion heuristic configured\n\t * on the client. So if you clean up files 3 days after delete,\n\t * invoking this manually will not skip that 3 day waiting period.\n\t */\n\t__cleanupFilesImmediately = () => {\n\t\treturn this._fileManager.tryCleanupDeletedFiles();\n\t};\n\n\t/**\n\t * Manually triggers storage rebasing. Follows normal\n\t * rebasing rules. Rebases already happen automatically\n\t * during normal operation, so you probably don't need this.\n\t */\n\t__manualRebase = () => this.meta.manualRebase();\n}\n\nexport interface ClientStats {\n\tcollections: Record<string, { count: number; size: number }>;\n\tmeta: {\n\t\tbaselinesSize: { count: number; size: number };\n\t\toperationsSize: { count: number; size: number };\n\t};\n\tfiles: {\n\t\tsize: { count: number; size: number };\n\t};\n\tstorage: StorageEstimate | undefined;\n\ttotalMetaSize: number;\n\ttotalCollectionsSize: number;\n\tmetaToDataRatio: number;\n\tquotaUsage: number | undefined;\n}\n", "/**\n * This exists since I'm a little anxious about using WeakRef in production\n * and want to be able to roll it back quickly to debug issues. Basically by adding\n * import { WeakRef } from 'FakeWeakRef' to the top of the file, we can switch back\n * to using a simple object reference.\n */\n\nexport class FakeWeakRef<T extends symbol | object> {\n\tconstructor(value: T) {\n\t\tthis.value = value;\n\t}\n\n\tvalue: T;\n\n\tderef(): T | undefined {\n\t\treturn this.value;\n\t}\n}\n", "export const METADATA_VERSION_KEY = Symbol('metadataVersion');\n", "import {\n\tEventSubscriber,\n\tMigration,\n\tOperation,\n\tStorageSchema,\n\thashObject,\n} from '@verdant-web/common';\nimport { Context } from '../context.js';\nimport { FileManagerConfig } from '../files/FileManager.js';\nimport { Metadata } from '../metadata/Metadata.js';\nimport {\n\topenMetadataDatabase,\n\topenWIPMetadataDatabase,\n} from '../metadata/openMetadataDatabase.js';\nimport { openWIPDatabase } from '../migration/openWIPDatabase.js';\nimport { ServerSyncOptions } from '../sync/Sync.js';\nimport { UndoHistory } from '../UndoHistory.js';\nimport { Client } from './Client.js';\nimport {\n\tdeleteAllDatabases,\n\tdeleteDatabase,\n\tgetAllDatabaseNamesAndVersions,\n} from '../idb.js';\nimport { FakeWeakRef } from '../FakeWeakRef.js';\nimport { METADATA_VERSION_KEY } from './constants.js';\nimport { openQueryDatabase } from '../migration/openQueryDatabase.js';\n\nexport interface ClientDescriptorOptions<Presence = any, Profile = any> {\n\t/** The schema used to create this client */\n\tschema: StorageSchema<any>;\n\toldSchemas?: StorageSchema<any>[];\n\t/** Migrations, in order, to upgrade to each successive version of the schema */\n\tmigrations: Migration<any>[];\n\t/** Provide a sync config to turn on synchronization with a server */\n\tsync?: ServerSyncOptions<Profile, Presence>;\n\t/** Optionally override the IndexedDB implementation */\n\tindexedDb?: IDBFactory;\n\t/**\n\t * Namespaces are used to separate data from different clients in IndexedDB.\n\t */\n\tnamespace: string;\n\t/**\n\t * Provide your own UndoHistory to have a unified undo system across multiple\n\t * clients if you so desire.\n\t */\n\tundoHistory?: UndoHistory;\n\t/**\n\t * Provide a log function to log internal debug messages\n\t */\n\tlog?: (\n\t\tlevel: 'debug' | 'info' | 'warn' | 'error' | 'critical',\n\t\t...args: any[]\n\t) => void;\n\tdisableRebasing?: boolean;\n\t/**\n\t * Provide a specific schema number to override the schema version\n\t * in the database. This is useful for testing migrations or recovering\n\t * from a mistakenly deployed incorrect schema. A specific version is required\n\t * so that you don't leave this on accidentally for all new schemas.\n\t */\n\toverrideSchemaConflict?: number;\n\t/**\n\t * Configuration for file management\n\t */\n\tfiles?: FileManagerConfig;\n\n\t/**\n\t * Listen for operations as they are applied to the database.\n\t * Wouldn't recommend using this unless you know what you're doing.\n\t * It's a very hot code path...\n\t */\n\tonOperation?: (operation: Operation) => void;\n\t/**\n\t * Enables experimental WeakRef usage to cull documents\n\t * from cache that aren't being used. This is a performance\n\t * optimization which has been tested under all Verdant's test\n\t * suites but I still want to keep testing it in the real world\n\t * before turning it on.\n\t */\n\tEXPERIMENTAL_weakRefs?: boolean;\n\n\t// not for public use\n\t[METADATA_VERSION_KEY]?: number;\n}\n\n/**\n * Since storage initialization is async, this class wraps the core\n * Storage creation promise and exposes some metadata which can\n * be useful immediately.\n */\nexport class ClientDescriptor<\n\tPresence = any,\n\tProfile = any,\n\tClientImpl extends Client = Client<Presence, Profile>,\n> {\n\tprivate readonly _readyPromise: Promise<ClientImpl>;\n\t// assertions because these are defined by plucking them from\n\t// Promise initializer\n\tprivate resolveReady!: (storage: ClientImpl) => void;\n\tprivate rejectReady!: (err: Error) => void;\n\tprivate _resolvedValue: ClientImpl | undefined;\n\tprivate _initializing = false;\n\tprivate _namespace: string;\n\n\tget namespace() {\n\t\treturn this._namespace;\n\t}\n\n\tconstructor(\n\t\tprivate readonly init: ClientDescriptorOptions<Presence, Profile>,\n\t) {\n\t\tthis._readyPromise = new Promise((resolve, reject) => {\n\t\t\tthis.resolveReady = resolve;\n\t\t\tthis.rejectReady = reject;\n\t\t});\n\t\tthis._namespace = init.namespace;\n\t}\n\n\tprivate initialize = async (init: ClientDescriptorOptions) => {\n\t\t// if server-side and no alternative IndexedDB implementation was provided,\n\t\t// we can't initialize the storage\n\t\tif (typeof window === 'undefined' && !init.indexedDb) {\n\t\t\tthrow new Error(\n\t\t\t\t'A verdant client was initialized in an environment without IndexedDB. If you are using verdant in a server-rendered framework, you must enforce that all clients are initialized on the client-side, or you must provide some mock interface of IDBFactory to the ClientDescriptor options.',\n\t\t\t);\n\t\t}\n\n\t\tif (this._initializing || this._resolvedValue) {\n\t\t\treturn this._readyPromise;\n\t\t}\n\t\tthis._initializing = true;\n\t\ttry {\n\t\t\tlet storage: ClientImpl;\n\t\t\tif (init.schema.wip) {\n\t\t\t\tstorage = await this.initializeWIPDatabases(init);\n\t\t\t} else {\n\t\t\t\tstorage = await this.initializeDatabases(init);\n\t\t\t\tthis.cleanupWIPDatabases(init);\n\t\t\t}\n\n\t\t\tthis.resolveReady(storage);\n\t\t\tthis._resolvedValue = storage;\n\t\t\treturn storage;\n\t\t} catch (err) {\n\t\t\tif (err instanceof Error) {\n\t\t\t\tthis.rejectReady(err as Error);\n\t\t\t\tthrow err;\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unknown error initializing storage');\n\t\t\t}\n\t\t} finally {\n\t\t\tthis._initializing = false;\n\t\t}\n\t};\n\n\tprivate initializeDatabases = async (init: ClientDescriptorOptions) => {\n\t\tconst metadataVersion = init[METADATA_VERSION_KEY];\n\t\tconst { db: metaDb } = await openMetadataDatabase({\n\t\t\tindexedDB: init.indexedDb,\n\t\t\tlog: init.log,\n\t\t\tnamespace: init.namespace,\n\t\t\tmetadataVersion,\n\t\t});\n\n\t\tconst context: Omit<Context, 'documentDb' | 'getNow'> = {\n\t\t\tnamespace: this._namespace,\n\t\t\tmetaDb,\n\t\t\tschema: init.schema,\n\t\t\tlog: init.log || (() => {}),\n\t\t\tundoHistory: init.undoHistory || new UndoHistory(),\n\t\t\tentityEvents: new EventSubscriber(),\n\t\t\tglobalEvents: new EventSubscriber(),\n\t\t\tinternalEvents: new EventSubscriber(),\n\t\t\tweakRef: (value) => {\n\t\t\t\tif (init.EXPERIMENTAL_weakRefs) {\n\t\t\t\t\treturn new WeakRef(value);\n\t\t\t\t} else {\n\t\t\t\t\treturn new FakeWeakRef(value) as unknown as WeakRef<typeof value>;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmigrations: init.migrations,\n\t\t\toldSchemas: init.oldSchemas,\n\t\t};\n\t\tconst meta = new Metadata({\n\t\t\tcontext,\n\t\t\tdisableRebasing: init.disableRebasing,\n\t\t\tonOperation: init.onOperation,\n\t\t});\n\n\t\t// verify schema integrity\n\t\tawait meta.updateSchema(init.schema, init.overrideSchemaConflict);\n\n\t\tconst contextWithNow: Omit<Context, 'documentDb'> = Object.assign(context, {\n\t\t\tgetNow: () => meta.now,\n\t\t});\n\n\t\tconst documentDb = await openQueryDatabase({\n\t\t\tcontext: contextWithNow,\n\t\t\tversion: init.schema.version,\n\t\t\tmeta,\n\t\t\tmigrations: init.migrations,\n\t\t\tindexedDB: init.indexedDb,\n\t\t});\n\n\t\tconst fullContext: Context = Object.assign(contextWithNow, { documentDb });\n\n\t\tconst storage = new Client(\n\t\t\t{\n\t\t\t\tsyncConfig: init.sync,\n\t\t\t\tmigrations: init.migrations,\n\t\t\t\tfiles: init.files,\n\t\t\t},\n\t\t\tfullContext,\n\t\t\t{\n\t\t\t\tmeta,\n\t\t\t},\n\t\t) as ClientImpl;\n\n\t\treturn storage;\n\t};\n\n\tprivate initializeWIPDatabases = async (init: ClientDescriptorOptions) => {\n\t\tconst schemaHash = hashObject(init.schema);\n\t\tconsole.info(`WIP schema in use. Opening database with hash ${schemaHash}`);\n\n\t\tconst wipNamespace = `@@wip_${init.namespace}_${schemaHash}`;\n\t\tconst { db: metaDb } = await openWIPMetadataDatabase({\n\t\t\tindexedDB: init.indexedDb,\n\t\t\tlog: init.log,\n\t\t\tnamespace: init.namespace,\n\t\t\twipNamespace: wipNamespace,\n\t\t});\n\n\t\tconst context: Omit<Context, 'documentDb' | 'getNow'> = {\n\t\t\tnamespace: this._namespace,\n\t\t\tmetaDb,\n\t\t\tschema: init.schema,\n\t\t\tlog: init.log || (() => {}),\n\t\t\tundoHistory: init.undoHistory || new UndoHistory(),\n\t\t\tentityEvents: new EventSubscriber(),\n\t\t\tglobalEvents: new EventSubscriber(),\n\t\t\tinternalEvents: new EventSubscriber(),\n\t\t\tweakRef: (value) => {\n\t\t\t\tif (init.EXPERIMENTAL_weakRefs) {\n\t\t\t\t\treturn new WeakRef(value);\n\t\t\t\t} else {\n\t\t\t\t\treturn new FakeWeakRef(value) as unknown as WeakRef<typeof value>;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmigrations: init.migrations,\n\t\t\toldSchemas: init.oldSchemas,\n\t\t};\n\t\tconst meta = new Metadata({\n\t\t\tcontext,\n\t\t\tdisableRebasing: init.disableRebasing,\n\t\t});\n\n\t\tconst contextWithNow: Omit<Context, 'documentDb'> = Object.assign(context, {\n\t\t\tgetNow: () => meta.now,\n\t\t});\n\n\t\t// verify schema integrity\n\t\tawait meta.updateSchema(init.schema, init.overrideSchemaConflict);\n\n\t\tconst documentDb = await openWIPDatabase({\n\t\t\tcontext: contextWithNow,\n\t\t\tversion: init.schema.version,\n\t\t\tmeta,\n\t\t\tmigrations: init.migrations,\n\t\t\tindexedDB: init.indexedDb,\n\t\t\twipNamespace,\n\t\t});\n\n\t\tconst fullContext: Context = Object.assign(contextWithNow, { documentDb });\n\n\t\tconst storage = new Client(\n\t\t\t{\n\t\t\t\tsyncConfig: init.sync,\n\t\t\t\tmigrations: init.migrations,\n\t\t\t\tfiles: init.files,\n\t\t\t},\n\t\t\tfullContext,\n\t\t\t{\n\t\t\t\tmeta,\n\t\t\t},\n\t\t) as ClientImpl;\n\n\t\treturn storage;\n\t};\n\n\tprivate cleanupWIPDatabases = async (init: ClientDescriptorOptions) => {\n\t\tconst databaseInfo = await getAllDatabaseNamesAndVersions(init.indexedDb);\n\t\tconst wipDatabases = databaseInfo\n\t\t\t.filter((db) => db.name?.startsWith('@@wip_'))\n\t\t\t.map((db) => db.name!);\n\t\t// don't clear a current WIP database.\n\t\tconst wipDatabasesToDelete = wipDatabases.filter(\n\t\t\t(db) =>\n\t\t\t\t!db.startsWith(`@@wip_${init.namespace}_${hashObject(init.schema)}`),\n\t\t);\n\t\tfor (const db of wipDatabasesToDelete) {\n\t\t\tawait deleteDatabase(db, init.indexedDb);\n\t\t}\n\t};\n\n\tget current() {\n\t\t// exposing an immediate value if already resolved lets us\n\t\t// skip the promise microtask when accessing this externally if\n\t\t// the initialization has been completed.\n\t\treturn this._resolvedValue;\n\t}\n\n\tget readyPromise() {\n\t\treturn this._readyPromise;\n\t}\n\n\tget schema() {\n\t\treturn this.init.schema;\n\t}\n\n\topen = () => this.initialize(this.init);\n\n\tclose = async () => {\n\t\tif (this._resolvedValue) {\n\t\t\tthis._resolvedValue.close();\n\t\t}\n\t\tif (this._initializing) {\n\t\t\t(await this._readyPromise).close();\n\t\t}\n\t};\n\n\t__dangerous__resetLocal = async () => {\n\t\tawait deleteAllDatabases(this.namespace);\n\t};\n}\n", "import cuid from 'cuid';\n\nexport function id(short?: boolean) {\n\tif (short) return cuid.slug();\n\treturn cuid();\n}\n", "import { authz } from '@verdant-web/common';\n\nexport const authorization = {\n\tprivate: authz.onlyMe(),\n\tpublic: undefined,\n};\n", "export function cliSync<Presence extends any = any>(\n\tlibraryId: string,\n\t{\n\t\tport = 3242,\n\t\tinitialPresence = {} as any,\n\t}: { port?: number; initialPresence?: Presence } = {},\n) {\n\tlet userId = localStorage.getItem('verdant-userId');\n\tif (!userId) {\n\t\tuserId = `user-${Math.random().toString(36).slice(2)}`;\n\t\tlocalStorage.setItem('verdant-userId', userId);\n\t}\n\treturn {\n\t\tdefaultProfile: { id: userId },\n\t\tinitialPresence,\n\t\tauthEndpoint: `http://localhost:${port}/auth/${libraryId}?userId=${userId}`,\n\t};\n}\n", "import * as everything from './index.js';\n\n(window as any).Verdant = everything;\n"],
|
|
5
|
+
"mappings": "8qBAAA,IAAAA,GAAAC,GAAA,CAAAC,GAAAC,KAAA,CAAAA,GAAO,QAAU,SAAcC,EAAKC,EAAM,CACxC,IAAIC,EAAI,YAAcF,EACtB,OAAOE,EAAE,OAAOA,E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,MAAM,KAAK,eAAe,MAAM,CAEnC,EAEA,6BAA0B,SAAY,CACrC,MAAM4B,GAAmB,KAAK,SAAS,CACxC,EA9NC,KAAK,cAAgB,IAAI,QAAQ,CAACC,EAASC,IAAW,CACrD,KAAK,aAAeD,EACpB,KAAK,YAAcC,CACpB,CAAC,EACD,KAAK,WAAa9B,EAAK,SACxB,CAZA,IAAI,WAAY,CACf,OAAO,KAAK,UACb,CAuMA,IAAI,SAAU,CAIb,OAAO,KAAK,cACb,CAEA,IAAI,cAAe,CAClB,OAAO,KAAK,aACb,CAEA,IAAI,QAAS,CACZ,OAAO,KAAK,KAAK,MAClB,CAgBD,EC9UA,IAAA+B,GAAiB,WAEV,SAASC,GAAGC,EAAiB,CACnC,OAAIA,EAAc,GAAAC,QAAK,KAAK,KACrB,GAAAA,SAAK,CACb,CCHO,IAAMC,GAAgB,CAC5B,QAASC,GAAM,OAAO,EACtB,OAAQ,MACT,ECLO,SAASC,GACfC,EACA,CACC,KAAAC,EAAO,KACP,gBAAAC,EAAkB,CAAC,CACpB,EAAmD,CAAC,EACnD,CACD,IAAIC,EAAS,aAAa,QAAQ,gBAAgB,EAClD,OAAKA,IACJA,EAAS,QAAQ,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,GACpD,aAAa,QAAQ,iBAAkBA,CAAM,GAEvC,CACN,eAAgB,CAAE,GAAIA,CAAO,EAC7B,gBAAAD,EACA,aAAc,oBAAoBD,CAAI,SAASD,CAAS,WAAWG,CAAM,EAC1E,CACD,CCfC,OAAe,QAAUC",
|
|
6
6
|
"names": ["require_pad", "__commonJSMin", "exports", "module", "num", "size", "s", "require_fingerprint_browser", "__commonJSMin", "exports", "module", "pad", "env", "globalCount", "mimeTypesLength", "clientId", "require_getRandomValue_browser", "__commonJSMin", "exports", "module", "getRandomValue", "crypto", "lim", "require_cuid", "__commonJSMin", "exports", "module", "fingerprint", "pad", "getRandomValue", "c", "blockSize", "base", "discreteValues", "randomBlock", "safeCounter", "cuid", "letter", "timestamp", "counter", "print", "random", "date", "stringToCheck", "stringLength", "require_object_hash", "__commonJSMin", "exports", "module", "e", "t", "r", "o", "i", "u", "s", "n", "a", "w", "b", "m", "c", "d", "h", "p", "g", "y", "l", "f", "O", "H", "j", "C", "v", "_", "E", "I", "A", "Y", "B", "F", "L", "U", "D", "x", "T", "M", "k", "N", "S", "tslib_es6_exports", "__export", "__addDisposableResource", "__assign", "__asyncDelegator", "__asyncGenerator", "__asyncValues", "__await", "__awaiter", "__classPrivateFieldGet", "__classPrivateFieldIn", "__classPrivateFieldSet", "__createBinding", "__decorate", "__disposeResources", "__esDecorate", "__exportStar", "__extends", "__generator", "__importDefault", "__importStar", "__makeTemplateObject", "__metadata", "__param", "__propKey", "__read", "__rest", "__runInitializers", "__setFunctionName", "__spread", "__spreadArray", "__spreadArrays", "__values", "tslib_es6_default", "d", "b", "extendStatics", "__", "s", "e", "t", "p", "i", "decorators", "target", "key", "desc", "c", "r", "paramIndex", "decorator", "ctor", "descriptorIn", "contextIn", "initializers", "extraInitializers", "accept", "f", "kind", "descriptor", "_", "done", "context", "result", "thisArg", "value", "useValue", "x", "name", "prefix", "metadataKey", "metadataValue", "_arguments", "P", "generator", "adopt", "resolve", "reject", "fulfilled", "step", "rejected", "body", "y", "g", "verb", "n", "v", "op", "m", "o", "ar", "error", "il", "k", "a", "j", "jl", "to", "from", "pack", "l", "q", "resume", "settle", "fulfill", "cooked", "raw", "mod", "__setModuleDefault", "receiver", "state", "env", "async", "dispose", "fail", "_SuppressedError", "next", "rec", "init_tslib_es6", "__esmMin", "k2", "suppressed", "message", "require_typed_event_interfaces", "__commonJSMin", "exports", "eventHandlerSafeInvoke", "handler", "sender", "args", "error", "exports", "eventHandlerSafeInvokeAsync", "invokeEventHandlers", "handlers", "options", "succeeded", "invokeEventHandlersAsync", "handlerPromises", "typed_event_functional_1", "DEFAULT_INVOCATION_OPTS", "TypedEvent", "handler", "sender", "args", "options", "handlerToRemove", "handlerIdx", "exports", "tslib_1", "exports", "FinalizationRegistryMissingError", "exports", "errors_1", "WeakHandlerHolder", "finalizer", "err", "eventSource", "handler", "handlerRef", "refToUse", "ref", "exports", "base_event_1", "weak_event_finalization_1", "typed_event_functional_1", "DEFAULT_INVOCATION_OPTS", "WeakEvent", "heldValue", "sender", "args", "options", "handlerRef", "dereferencedHandler", "succeeded", "error", "handlerPromises", "handler", "ref", "handlerIdx", "exports", "tslib_1", "exports", "tslib_1", "exports", "src_exports", "__export", "Client", "ClientDescriptor", "Entity", "EntityFile", "MigrationPathError", "ServerSync", "UndoHistory", "authorization", "cliSync", "collection", "createDefaultMigration", "createMigration", "id", "migrate", "schema", "import_cuid", "VERSION_BLOCK_LENGTH", "ENCODING_NUMBER_RADIX", "encodeVersion", "version", "OLD_encodeVersion", "HybridLogicalClockTimestampProvider", "generateNodeId", "version", "getHlcNow", "OLD_encodeVersion", "OLD_serializeHlcTimestamp", "remoteTimestamp", "hlcString", "VERSION_BLOCK_LENGTH", "updateFromRemote", "deserializeHlcTimestamp", "raw", "encodeVersion", "serializeHlcTimestamp", "getWallClockTime", "ClockDriftError", "args", "OverflowError", "COUNTER_BLOCK_LENGTH", "NODE_BLOCK_LENGTH", "MAX_CLOCK_DRIFT", "TIME_BLOCK_LENGTH", "cuid", "ts", "dateString", "ENCODING_NUMBER_RADIX", "counter", "node", "prev", "wallTime", "newWallTime", "newCounter", "local", "remote", "newTime", "maxCounter", "clock", "time", "counterNum", "OLD_serializeHlcTimestamp", "ts", "dateString", "counter", "node", "getTimestampSchemaVersion", "timestamp", "VERSION_BLOCK_LENGTH", "compareTimestampSchemaVersions", "a", "b", "getWallClockTime", "deserializeHlcTimestamp", "getRandomValues", "rnds8", "rng", "regex_default", "validate", "uuid", "regex_default", "validate_default", "byteToHex", "i", "stringify", "arr", "offset", "uuid", "validate_default", "stringify_default", "v4", "options", "buf", "offset", "rnds", "rng", "i", "stringify_default", "v4_default", "isRef", "obj", "isObjectRef", "isFileRef", "compareRefs", "a", "b", "SEGMENT_SEPARATOR", "RANDOM_SEPARATOR", "oidMap", "getOid", "obj", "oid", "maybeGetOid", "assert", "isObject", "assignOid", "hasOid", "removeOid", "ensureOid", "rootOid", "createSubId", "createSubOid", "ensureCompatibleOid", "existingOid", "areOidsRelated", "SANITIZE_PLACEHOLDERS", "sanitizeFragment", "id", "unsanitizeFragment", "createOid", "collection", "documentId", "subId", "root", "createOidSubId", "decomposeOid", "coreId", "others", "idOrLegacyPathId", "random", "assignOidsToAllSubObjects", "obj", "createSubId", "rootOid", "getOid", "item", "i", "isObject", "isRef", "ensureCompatibleOid", "key", "removeOidsFromAllSubObjects", "removeOid", "createOidSubId", "v4_default", "createRef", "oid", "normalize", "refs", "copy", "assignOid", "value", "isObjectRef", "isFileRef", "itemOid", "getOidRoot", "oid", "RANDOM_SEPARATOR", "getOidSubIdRange", "root", "lastSubId", "createSubOid", "areOidsRelated", "oidA", "oidB", "getOidRoot", "isRootOid", "oid", "RANDOM_SEPARATOR", "import_object_hash", "orderedReplacer", "_", "v", "ka", "kb", "stableStringify", "obj", "cloneDeep", "copyOids", "isObject", "oid", "maybeGetOid", "clone", "key", "value", "assignOid", "hashObject", "hash", "roughSizeOfObject", "object", "objectList", "stack", "bytes", "i", "assert", "condition", "message", "generateId", "length", "v4_default", "findLastIndex", "array", "predicate", "debounce", "fn", "wait", "timeout", "args", "context", "throttle", "lastTime", "trailingTimeout", "now", "isFileRef", "value", "createFileRef", "id", "isFile", "value", "isFileData", "isObject", "LEGACY_OID_KEY", "OID_KEY", "maybeGetOidProperty", "obj", "isObject", "removeOidProperty", "copyOidFromPropertyToSystem", "oid", "assignOid", "removeOidPropertiesFromAllSubObjects", "key", "convertLegacyOid", "oid", "collection", "id", "subId", "decomposeOid", "createOid", "MATCH_LEGACY_OID_JSON_STRING", "replaceLegacyOidsInJsonString", "string", "match", "legacyOid", "replaceLegacyOidsInObject", "obj", "getLegacyDotOidSubIdRange", "root", "getOidRoot", "isOidKey", "key", "OID_KEY", "LEGACY_OID_KEY", "isObjectRef", "obj", "isDiffableObject", "val", "isObject", "isRef", "compareNonDiffable", "a", "b", "compareRefs", "diffToPatches", "from", "to", "getNow", "createSubId", "patches", "options", "authz", "oid", "getOid", "diffItems", "key", "value", "oldValue", "isList", "addAuthzToOp", "oldValueOid", "maybeGetOid", "valueOid", "areOidsRelated", "cloneDeep", "createSubOid", "assignOid", "ensureOid", "assert", "initialToPatches", "createRef", "i", "deletedItemsAtEnd", "oldKeys", "isOidKey", "initialToPatches", "initial", "rootOid", "getNow", "createSubId", "patches", "options", "assignOid", "assignOidsToAllSubObjects", "normalized", "normalize", "key", "value", "op", "removeOid", "addAuthzToOp", "addAuthzToOp", "op", "authz", "groupPatchesByOid", "patches", "grouped", "patch", "groupPatchesByRootOid", "root", "getOidRoot", "groupBaselinesByRootOid", "baselines", "listCheck", "obj", "maybeGetOid", "applyPatch", "base", "deletedRefs", "baseAsAny", "index", "spliceResult", "checkRef", "field", "isRef", "valueToRemove", "isObjectRef", "findLastIndex", "item", "v", "compareRefs", "isObject", "cloneDeep", "substituteRefsWithObjects", "base", "refs", "used", "i", "item", "dereference", "isObject", "isFileRef", "assert", "maybeGetOid", "key", "input", "isObjectRef", "resolved", "assignOid", "operationSupersedes", "op", "isSuperseded", "supersession", "pickValidOperationKeys", "operation", "ReplicaType", "import_cuid", "objectField", "args", "arrayField", "stringField", "numberField", "booleanField", "anyField", "mapField", "fileField", "idField", "cuid", "fields", "import_cuid", "isMatchIndexFilter", "filter", "isRangeIndexFilter", "isCompoundIndexFilter", "isStartsWithIndexFilter", "isSortIndexFilter", "isNullable", "field", "hasDefault", "getDefault", "addFieldDefaults", "collection", "value", "key", "field", "defaultValue", "getFieldDefault", "isNullable", "traverseCollectionFieldsAndApplyDefaults", "subField", "item", "OID_KEY", "LEGACY_OID_KEY", "property", "removeExtraProperties", "fieldValue", "traverseCollectionFieldsAndRemoveExtraProperties", "isObject", "validateEntity", "schema", "entity", "key", "value", "OID_KEY", "err", "validateEntityField", "field", "fieldPath", "depth", "requireDefaults", "isNullable", "hasDefault", "formatField", "isObject", "subField", "item", "isFile", "isFileData", "constrainEntity", "constrained", "constrainEntityField", "validationProblem", "getChildFieldSchema", "schema", "key", "_a", "collection", "_a", "synthetics", "indexes", "input", "__rest", "finalIndexes", "key", "field", "schema", "fields", "cuid", "COMPOUND_INDEX_SEPARATOR", "COMPOUND_INDEX_LOWER_BOUND_SEPARATOR", "COMPOUND_INDEX_UPPER_BOUND_SEPARATOR", "createCompoundIndexValue", "fields", "value", "expandArrayIndex", "createUpperBoundIndexValue", "createLowerBoundIndexValue", "field", "newValue", "previousValue", "fieldValue", "item", "isDirectSynthetic", "index", "computeSynthetics", "schema", "obj", "result", "name", "property", "sanitizeIndexValue", "computeCompoundIndices", "doc", "acc", "indexKey", "key", "computeIndexedFields", "getIndexValues", "basicIndexes", "NULL_INDEX_VALUE", "sanitizeIndexValue", "value", "emptySchema", "migrate", "oldSchemaOrNewSchema", "newSchemaOrProcedure", "procedureIfTwoSchemas", "isProcedureSecondArgument", "oldSchema", "newSchema", "procedure", "changedCollections", "key", "stableStringify", "removedCollections", "addedCollections", "autoMigratedCollections", "collection", "oldFields", "newFields", "_a", "_b", "addedIndexes", "removedIndexes", "changed", "oldIndexes", "getIndexes", "newIndexes", "added", "index", "i", "removed", "withDefaults", "collectionName", "val", "addFieldDefaults", "autoMigration", "removeExtraProperties", "engine", "migratedCollections", "strategy", "auto", "wrapped", "baseValue", "assignOid", "getOid", "name", "unmigrated", "getIndexes", "collection", "key", "fieldName", "createDefaultMigration", "schema", "newSchema", "migrate", "info", "old", "createMigration", "maybeOldSchema", "maybeNewSchemaOrProcedure", "maybeProcedure", "isProcedureSecondArgument", "oldSchema", "emptySchema", "procedure", "assert", "changedCollections", "addedCollections", "removedCollections", "addedIndexes", "removedIndexes", "autoMigratedCollections", "autoMigration", "getMigrationInfo", "engine", "migratedCollections", "strategy", "auto", "wrapped", "val", "baseValue", "assignOid", "getOid", "result", "validationError", "validateEntity", "name", "unmigrated", "stableStringify", "oldFields", "newFields", "hasDefault", "changed", "oldIndexes", "newIndexes", "added", "index", "i", "removed", "collectionName", "addFieldDefaults", "removeExtraProperties", "initialInternalPresence", "PatchCreator", "getNow", "createSubId", "value", "isObject", "isRef", "from", "to", "options", "diffToPatches", "obj", "oid", "initialToPatches", "key", "itemOid", "createSubOid", "createRef", "index", "only", "count", "fromIndex", "toIndex", "oids", "EventSubscriber", "_onAllUnsubscribed", "event", "_a", "acc", "count", "callback", "key", "generateId", "subscribers", "args", "c", "events", "getUndoOperations", "oid", "initial", "operations", "getNow", "state", "cloneDeep", "undoOperations", "operation", "undo", "getUndoOperation", "applyPatch", "data", "index", "indexesOfValue", "Batcher", "flusher", "key", "batch", "userData", "items", "max", "timeout", "Batch", "startedAt", "needsSchedule", "memoByKeys", "fn", "getKeys", "cachedKeys", "cachedResult", "args", "keys", "key", "i", "VerdantErrorCode", "VerdantError", "code", "cause", "message", "status", "isVerdantErrorResponse", "body", "encode", "str", "decode", "authz", "userId", "ORIGINATOR_SUBJECT", "encoded", "parts", "rewriteAuthzOriginator", "data", "newSubject", "operations", "baselines", "op", "baseline", "globalIDB", "isAbortError", "err", "storeRequestPromise", "request", "resolve", "reject", "getSizeOfObjectStore", "database", "storeName", "resolve", "reject", "tx", "cursorReq", "count", "size", "e", "cursor", "roughSizeOfObject", "isAbortError", "getAllFromObjectStores", "db", "stores", "transaction", "promises", "store", "objectStore", "storeRequestPromise", "closeDatabase", "deleteAllDatabases", "namespace", "indexedDB", "globalIDB", "req1", "req2", "deleteDatabase", "name", "getAllDatabaseNamesAndVersions", "createAbortableTransaction", "storeNames", "mode", "abortSignal", "log", "abort", "Disposable", "dispose", "IDBService", "Disposable", "db", "log", "storeNames", "opts", "tx", "createAbortableTransaction", "storeName", "getRequest", "store", "request", "storeRequestPromise", "getRequests", "requests", "iterator", "req", "resolve", "reject", "cursor", "isAbortError", "AckInfoStore", "IDBService", "result", "store", "ack", "BaselinesStore", "IDBService", "db", "opts", "oid", "mode", "transaction", "baselines", "baseline", "iterator", "store", "root", "getOidRoot", "start", "end", "getOidSubIdRange", "dotStart", "dotEnd", "getLegacyDotOidSubIdRange", "collection", "docOids", "timestamp", "range", "import_cuid", "LocalReplicaStore", "IDBService", "transaction", "lookup", "store", "replicaInfo", "cuid", "data", "localReplicaInfo", "localInfo", "MessageCreator", "meta", "init", "localInfo", "pickValidOperationKeys", "targetVersion", "op", "since", "localReplicaInfo", "provideChangesSince", "operations", "affectedDocs", "patch", "getOidRoot", "baselines", "data", "nonce", "OperationsStore", "IDBService", "db", "opts", "oid", "iterator", "to", "from", "after", "mode", "providedTx", "store", "index", "startTimestamp", "start", "createCompoundIndexValue", "createLowerBoundIndexValue", "end", "createUpperBoundIndexValue", "range", "request", "resolve", "reject", "previousTimestamp", "event", "cursor", "value", "assert", "isAbortError", "collection", "transaction", "before", "patches", "patch", "getOidRoot", "operations", "affected", "op", "SchemaStore", "db", "currentVersion", "request", "value", "storeRequestPromise", "schema", "Metadata", "EventSubscriber", "disableRebasing", "context", "onOperation", "HybridLogicalClockTimestampProvider", "stores", "opts", "createAbortableTransaction", "oid", "oids", "documentOid", "getOidRoot", "assert", "transaction", "baseline", "patch", "options", "baselines", "objectMap", "assignOid", "op", "obj", "newObj", "applyPatch", "root", "substituteRefsWithObjects", "operations", "authz", "timestamp", "localReplicaInfo", "operation", "message", "affectedDocumentOids", "affectedOidSet", "data", "globalAckTimestamp", "lastTimestamp", "toRebase", "operationCount", "newBaselines", "upTo", "providedTx", "replicaId", "current", "operationsApplied", "deletedRefs", "store", "newBaseline", "fileRefs", "isFileRef", "schema", "overrideConflict", "storedSchema", "ackInfo", "db", "getAllFromObjectStores", "localReplica", "storeRequestPromise", "operationsSize", "getSizeOfObjectStore", "baselinesSize", "SchemaStore", "OperationsStore", "BaselinesStore", "LocalReplicaStore", "AckInfoStore", "MessageCreator", "PatchCreator", "supportLegacyExport", "exportData", "migrations", "version1", "version2", "version3", "version4", "version5", "version6", "openMetadataDatabase", "indexedDB", "namespace", "log", "metadataVersion", "resolve", "reject", "request", "wasInitialized", "event", "db", "tx", "toRun", "migration", "openWIPMetadataDatabase", "wipNamespace", "result", "prodDb", "baselines", "operations", "info", "storeRequestPromise", "wipTx", "wipBaselines", "wipOperations", "wipInfo", "baseline", "operation", "infoItem", "closeDatabase", "baselinesStore", "operationsStore", "infoStore", "cursorReq", "cursor", "isLocal_timestamp", "documentOid_timestamp", "value", "files", "converted", "replaceLegacyOidsInObject", "getDatabaseVersion", "indexedDB", "namespace", "version", "log", "openAndGetVersion", "resolve", "reject", "currentVersion", "database", "request", "event", "transaction", "db", "closeDatabase", "upgradeDatabase", "indexedDb", "upgrader", "openAndUpgrade", "wasUpgraded", "acquireLock", "procedure", "openDatabase", "globalIDB", "context", "copyAll", "sourceDatabase", "targetDatabase", "sourceStoreNames", "i", "copyFromTransaction", "copyFromStores", "name", "allObjects", "store", "storeRequestPromise", "copyToTransaction", "copyToStores", "obj", "matchIndexToIdbKeyRange", "filter", "sanitizeIndexValue", "sortIndexToIdbKeyRange", "rangeIndexToIdbKeyRange", "lower", "upper", "compoundIndexToIdbKeyRange", "schema", "collection", "indexDefinition", "assert", "matchedKeys", "a", "b", "key", "matchedValues", "createCompoundIndexValue", "createLowerBoundIndexValue", "createUpperBoundIndexValue", "startsWithIndexToIdbKeyRange", "getRange", "index", "isRangeIndexFilter", "isMatchIndexFilter", "isSortIndexFilter", "isStartsWithIndexFilter", "getStore", "db", "collection", "write", "findOneOid", "index", "context", "store", "source", "range", "getRange", "direction", "request", "resolve", "reject", "cursor", "createOid", "isAbortError", "findAllOids", "results", "findPageOfOids", "limit", "offset", "hasDoneOffset", "hasNextPage", "visited", "getMigrationMutations", "migration", "meta", "getMigrationNow", "newOids", "acc", "collectionName", "doc", "options", "addFieldDefaults", "primaryKey", "oid", "createOid", "initialToPatches", "id", "rootOid", "authz", "allOids", "getMigrationQueries", "context", "filter", "findOneOid", "oids", "findAllOids", "getMigrationEngine", "queries", "mutations", "deleteCollection", "collection", "awaitables", "strategy", "docs", "getOid", "assert", "original", "cloneDeep", "newValue", "removeOidPropertiesFromAllSubObjects", "assignOidsToAllSubObjects", "patches", "diffToPatches", "getInitialMigrationEngine", "globalIDB", "runMigrations", "context", "toRun", "meta", "indexedDB", "namespace", "acquireLock", "migration", "engine", "getInitialMigrationEngine", "originalDatabase", "openDatabase", "getMigrationEngine", "err", "closeDatabase", "upgradedDatabase", "applySchemaToDatabase", "docsWithUnappliedMigrations", "getDocsWithUnappliedMigrations", "collection", "readStore", "oids", "getAllKeys", "key", "createOid", "oid", "decomposeOid", "views", "snap", "e", "s", "snapshot", "view", "getIndexValues", "writeStore", "putView", "id", "deleteView", "col", "i", "store", "resolve", "reject", "request", "event", "currentVersion", "_", "unappliedOperations", "op", "getOidRoot", "upgradeDatabase", "transaction", "db", "newCollection", "newIndex", "oldIndex", "removedCollection", "MigrationPathError", "message", "getMigrationPath", "currentVersion", "targetVersion", "migrations", "path", "getNextPathStep", "MigrationPathError", "fromHere", "m", "a", "b", "next", "nextPath", "globalIDB", "openWIPDatabase", "version", "indexedDB", "migrations", "meta", "context", "wipNamespace", "currentWIPVersion", "getDatabaseVersion", "initialToRun", "getMigrationPath", "runMigrations", "mainDatabase", "openDatabase", "wipDatabase", "copyAll", "toRun", "UndoHistory", "EventSubscriber", "next", "redo", "undo", "undoPoint", "redoPoint", "DocumentManager", "schema", "entities", "collection", "init", "primaryKeyName", "primaryKey", "assert", "createOid", "collectionName", "addFieldDefaults", "constrainEntity", "options", "widenedOptions", "defaulted", "validated", "oid", "collectionSchema", "ids", "entity", "isRootOid", "snapshot", "import_cuid", "createFileData", "file", "cuid", "processValueFiles", "value", "onFileIdentified", "isFile", "data", "createFileRef", "isFileData", "cloned", "i", "key", "fileToArrayBuffer", "resolve", "reject", "reader", "UPDATE", "MARK_FAILED", "MARK_UPLOADED", "_a", "_b", "_c", "EntityFile", "EventSubscriber", "id", "downloadRemote", "fileData", "EntityCache", "initial", "init", "entity", "Entity", "oid", "id", "options", "file", "EntityFile", "entityFieldSubscriber", "entity", "field", "subscriber", "valueHolder", "handler", "info", "newValue", "Entity", "_Entity", "EventSubscriber", "oid", "schema", "childCache", "parent", "ctx", "metadataFamily", "readonlyKeys", "files", "patchCreator", "storeEvents", "deleteSelf", "_store", "data", "child", "childView", "key", "fieldSchema", "getChildFieldSchema", "assert", "memoByKeys", "validateEntityField", "mapper", "view", "mapped", "value", "EntityFile", "assignOid", "acc", "operations", "op", "changes", "change", "ev", "other", "target", "event", "callback", "entityFieldSubscriber", "assertNotSymbol", "isRef", "isFileRef", "file", "hasDefault", "getDefault", "isNullable", "init", "existing", "isFile", "cloneDeep", "traverseCollectionFieldsAndApplyDefaults", "validationError", "processValueFiles", "property", "item", "createRef", "createFileRef", "itemOid", "maybeGetOid", "options", "assertNumber", "deleteMode", "merge", "replaceSubObjects", "preserveUndefined", "field", "index", "from", "to", "itemRef", "compareRefs", "initialValue", "predicate", "type", "operation", "EntityCache", "rawView", "isObject", "i", "keys", "latest", "childTimestamp", "length", "EntityMetadata", "oid", "ctx", "confirmedOperations", "pendingOperations", "baseline", "omitPending", "base", "cloneDeep", "baselineTimestamp", "authz", "confirmedResult", "pendingResult", "assignOid", "fromOlderVersion", "compareTimestampSchemaVersions", "empty", "updatedAtTimestamp", "updatedAt", "getWallClockTime", "operations", "totalAdded", "op", "index", "o", "pendingPrior", "operation", "deleted", "latestTimestamp", "after", "futureSeen", "now", "applyPatch", "assert", "EntityFamilyMetadata", "onPendingOperations", "rootOid", "baselines", "isLocal", "changes", "areOidsRelated", "ops", "oids", "DEFAULT_BATCH_KEY", "OperationBatcher", "batchTimeout", "meta", "ctx", "entities", "operations", "batchKey", "committed", "supersessions", "i", "op", "existingSupersession", "isSuperseded", "supersession", "operationSupersedes", "undo", "undoable", "batchName", "generateId", "max", "timeout", "internalBatch", "externalApi", "fn", "data", "inverseOps", "redo", "ops", "source", "grouped", "groupPatchesByOid", "getNow", "oid", "patches", "viewData", "getOidRoot", "inverse", "getUndoOperations", "Batcher", "QueryableStorage", "IDBService", "ctx", "allCollections", "tx", "collection", "store", "storeRequestPromise", "entities", "opts", "collections", "e", "decomposeOid", "toRemove", "c", "withRemoved", "options", "snapshot", "err", "entity", "oid", "doc", "transaction", "id", "schema", "indexes", "getIndexValues", "db", "import_weak_event", "EntityStore", "Disposable", "ctx", "meta", "files", "oid", "data", "baselines", "operations", "allDocumentOids", "b", "getOidRoot", "o", "baselinesGroupedByOid", "groupBaselinesByRootOid", "operationsGroupedByOid", "groupPatchesByRootOid", "groupedOperations", "groupPatchesByOid", "event", "hydrationPromise", "abortOptions", "entities", "err", "opts", "isRootOid", "cached", "entity", "pendingPromise", "initial", "undoable", "access", "collection", "decomposeOid", "removeOidsFromAllSubObjects", "processed", "processValueFiles", "assignOid", "op", "oids", "options", "assert", "deletes", "collectionName", "schema", "readonlyKeys", "metadataFamily", "EntityFamilyMetadata", "Entity", "operation", "root", "QueryableStorage", "OperationBatcher", "FileStorage", "IDBService", "file", "transaction", "downloadRemote", "buffer", "fileToArrayBuffer", "r", "err", "store", "raw", "arrayBufferToBlob", "id", "current", "since", "tx", "filtered", "iterator", "value", "files", "getAllFromObjectStores", "getSizeOfObjectStore", "type", "defaultCanCleanup", "fileData", "FileManager", "db", "sync", "context", "meta", "config", "file", "blob", "UPDATE", "entityFile", "EntityFile", "retries", "result", "cached", "MARK_UPLOADED", "url", "resp", "resolve", "reject", "id", "options", "MARK_FAILED", "err", "downloadRemote", "storedFiles", "storedFile", "r", "files", "online", "unsynced", "count", "skipCount", "store", "fileRefs", "tx", "fileRef", "FileStorage", "globalIDB", "openQueryDatabase", "version", "indexedDB", "migrations", "meta", "context", "currentVersion", "getDatabaseVersion", "toRun", "getMigrationPath", "m", "runMigrations", "openDatabase", "existsFilter", "x", "filterResultSet", "results", "Entity", "areIndexesEqual", "a", "b", "hashObject", "ON_ALL_UNSUBSCRIBED", "UPDATE", "_a", "BaseQuery", "Disposable", "initial", "context", "collection", "key", "shouldUpdate", "value", "filtered", "filterResultSet", "changed", "v", "i", "entity", "Entity", "err", "handler", "EventSubscriber", "event", "shouldUpdateFn", "collections", "eventOrCallback", "callback", "GetQuery", "BaseQuery", "id", "hydrate", "rest", "value", "createOid", "_a", "FindOneQuery", "BaseQuery", "index", "hydrate", "rest", "oid", "findOneOid", "areIndexesEqual", "UPDATE", "_a", "FindPageQuery", "BaseQuery", "index", "hydrate", "pageSize", "page", "rest", "result", "hasNextPage", "findPageOfOids", "areIndexesEqual", "UPDATE", "_a", "FindInfiniteQuery", "BaseQuery", "hydrate", "pageSize", "index", "rest", "result", "hasNextPage", "findPageOfOids", "areIndexesEqual", "UPDATE", "_a", "FindAllQuery", "BaseQuery", "index", "hydrate", "rest", "oids", "findAllOids", "areIndexesEqual", "UPDATE", "CollectionQueries", "collection", "cache", "entities", "context", "documentManager", "index", "hashObject", "id", "key", "GetQuery", "providedKey", "FindOneQuery", "existing", "UPDATE", "FindAllQuery", "pageSize", "page", "FindPageQuery", "FindInfiniteQuery", "QueryCache", "Disposable", "evictionTime", "context", "query", "q", "key", "value", "ON_ALL_UNSUBSCRIBED", "create", "update", "existing", "HANDLE_MESSAGE", "_a", "PresenceManager", "EventSubscriber", "initialPresence", "updateBatchTimeout", "defaultProfile", "replicaStore", "localReplicaInfo", "userInfo", "message", "peersChanged", "selfChanged", "peerIdsSet", "id", "lastPresence", "presence", "presenceUpdates", "data", "update", "viewId", "fieldId", "timestamp", "peer", "expirationPeriod", "initialInternalPresence", "info", "Batcher", "everyone", "FileSync", "endpointProvider", "log", "data", "file", "fileEndpoint", "token", "formData", "response", "responseText", "e", "id", "Heartbeat", "EventSubscriber", "interval", "deadlineLength", "restartOnTabFocus", "immediate", "PushPullSync", "EventSubscriber", "endpointProvider", "meta", "presence", "interval", "log", "fetch", "messages", "host", "token", "response", "json", "handlePromise", "isVerdantErrorResponse", "VerdantErrorCode", "error", "message", "throttle", "Heartbeat", "InvalidCharacterError", "message", "this", "prototype", "Error", "name", "r", "window", "atob", "bind", "input", "str", "String", "replace", "length", "bs", "buffer", "bc", "idx", "output", "charAt", "fromCharCode", "indexOf", "t", "decodeURIComponent", "m", "p", "code", "charCodeAt", "toString", "toUpperCase", "err", "InvalidTokenError", "o", "token", "options", "pos", "header", "JSON", "parse", "base64_url_decode", "split", "e", "jwt_decode_esm_default", "ServerSyncEndpointProvider", "config", "result", "res", "assert", "decoded", "jwt_decode_esm_default", "url", "httpEndpoint", "websocketEndpoint", "fileEndpoint", "fileUrl", "ReplicaType", "BackoffScheduler", "EventSubscriber", "backoff", "Backoff", "max", "factor", "WebSocketSync", "EventSubscriber", "endpointProvider", "meta", "presence", "log", "args", "Heartbeat", "BackoffScheduler", "Backoff", "msg", "online", "event", "message", "endpoint", "attemptToRegisterBackgroundSync", "status", "registration", "error", "NoSync", "EventSubscriber", "meta", "PresenceManager", "ServerSync", "authEndpoint", "fetchAuth", "fetch", "initialPresence", "automaticTransportSelection", "autoStart", "initialTransport", "pullInterval", "presenceUpdateBatchTimeout", "defaultProfile", "useBroadcastChannel", "onOutgoingMessage", "EXPERIMENTAL_backgroundSync", "ctx", "onData", "event", "message", "source", "op", "HANDLE_MESSAGE", "online", "data", "transport", "newSync", "interval", "userId", "VerdantError", "rewriteAuthzOriginator", "info", "id", "ServerSyncEndpointProvider", "WebSocketSync", "PushPullSync", "FileSync", "decideIfUpgrade", "switchoverTimeout", "shouldUpgrade", "attemptToRegisterBackgroundSync", "ReplicaType", "getLatestVersion", "data", "op", "b", "v", "ts", "tsVersion", "getTimestampSchemaVersion", "Client", "EventSubscriber", "config", "context", "components", "data", "schemaVersion", "getLatestVersion", "err", "collectionNames", "collections", "collectionName", "getSizeOfObjectStore", "meta", "storage", "files", "totalCollectionsSize", "acc", "size", "totalMetaSize", "metaToDataRatio", "resolve", "closeDatabase", "deleteAllDatabases", "downloadRemoteFiles", "metaExport", "filesExport", "fileData", "fileExport", "file", "asFile", "originalFileName", "id", "name", "rawData", "res", "supportLegacyExport", "fileToIdMap", "importedFiles", "version", "deleteReq", "reject", "currentSchema", "oldSchema", "s", "openQueryDatabase", "exportData", "ServerSync", "NoSync", "FileManager", "QueryCache", "EntityStore", "DocumentManager", "notifyFutureSeen", "debounce", "_collection", "CollectionQueries", "FakeWeakRef", "value", "METADATA_VERSION_KEY", "ClientDescriptor", "init", "storage", "err", "metadataVersion", "METADATA_VERSION_KEY", "metaDb", "openMetadataDatabase", "context", "UndoHistory", "EventSubscriber", "value", "FakeWeakRef", "meta", "Metadata", "contextWithNow", "documentDb", "openQueryDatabase", "fullContext", "Client", "schemaHash", "hashObject", "wipNamespace", "openWIPMetadataDatabase", "openWIPDatabase", "wipDatabasesToDelete", "getAllDatabaseNamesAndVersions", "db", "deleteDatabase", "deleteAllDatabases", "resolve", "reject", "import_cuid", "id", "short", "cuid", "authorization", "authz", "cliSync", "libraryId", "port", "initialPresence", "userId", "src_exports"]
|
|
7
7
|
}
|