@fluid-experimental/property-common 0.59.3003 → 0.59.4000

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.
@@ -158,7 +158,7 @@ class Collection {
158
158
  let filterCb;
159
159
  if (lodash_1.default.isArray(in_filterKey)) {
160
160
  filterCb = function (in_key, in_item) {
161
- if (in_filterKey.indexOf(in_key) >= 0) {
161
+ if (in_filterKey.includes(in_key)) {
162
162
  rtn.add(in_key, in_item);
163
163
  }
164
164
  };
@@ -1 +1 @@
1
- {"version":3,"file":"collection.js","sourceRoot":"","sources":["../../src/datastructures/collection.ts"],"names":[],"mappings":";;;;;;AAAA;;;GAGG;AACH,4DAA4D;AAC5D;;GAEG;AACH,oDAAuB;AAEvB,MAAM,IAAI,GAAG;IACT,aAAa,EAAE,0CAA0C;IACzD,kBAAkB,EAAE,iCAAiC;IACrD,kBAAkB,EAAE,mDAAmD;IACvE,aAAa,EAAE,yBAAyB;IACxC,eAAe,EAAE,2BAA2B;IAC5C,aAAa,EAAE,sCAAsC;CACxD,CAAC;AAEF,MAAa,UAAU;IAInB;;;;;OAKG;IACH,YAAsB,QAAQ,qBAAqB,EAAY,KAAqB;QAA9D,UAAK,GAAL,KAAK,CAAwB;QAAY,UAAK,GAAL,KAAK,CAAgB;QAT1E,WAAM,GAA0B,EAAE,CAAC;QACnC,WAAM,GAAwB,EAAE,CAAC;IAS3C,CAAC;IAED,4BAA4B;IAC5B,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC;IAC9B,OAAO,CAAC,QAAQ,IAAI,CAAC;IAErB,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,IAAW,IAAI;QACX,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,M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C;YACjC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;SACtB,CAAC;IACN,CAAC;IAED;;;OAGG;IACH,KAAK;QACD,IAAI,gBAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YACxB,OAAO,IAAI,CAAC;SACf;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE1B,uEAAuE;QACvE,uBAAuB;QAEvB,gBAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;YAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAI,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,aAA4B;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC;QAEhC,gBAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YACtB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;CACJ;AAjaD,gCAiaC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n/* eslint accessor-pairs: [2, { \"getWithoutSet\": false }] */\n/**\n * @fileoverview Collection class definition\n */\nimport _ from \"lodash\";\n\nconst MSGS = {\n TYPE_MISMATCH: \"Type does not match this collection type\",\n KEY_ALREADY_EXISTS: \"Collection key already exists. \",\n KEY_DOES_NOT_EXIST: \"Collection key does not exist in this collection.\",\n MUST_GIVE_KEY: \"Collection missing key.\",\n MUST_GIVE_VALUE: \"Collection missing value.\",\n KEY_NOT_VALID: \"Key must be of type String or Number\",\n};\n\nexport class Collection<T> {\n protected _items: { [key: string]: T; } = {};\n protected _order: (string | number)[] = [];\n\n /**\n * @param _name - a friendly name to describe this collection. If undefined\n * the collection will have a default \"Untitled Collection\" assigned to its name.\n * @param _type - optional parameter pointing to the constructor\n * of a type this Collection will host.\n */\n constructor(protected _name = \"Untitled Collection\", protected _type?: new () => any) {\n }\n\n // Pass-thru binding handles\n onAdd(in_key, in_value) { }\n onRemove(in_key, in_value) { }\n onClear(in_items) { }\n\n public get items() {\n return this._items;\n }\n\n public get keys() {\n return Object.keys(this._items);\n }\n\n /**\n * @param in_key - Key to store the value under\n * @param in_value - Value to store in the collection\n * @returns Return the value passed in\n */\n add(in_key: number | string, in_value: T): T {\n this._checkType(in_value);\n this._checkIsNewKey(in_key);\n\n this._items[in_key] = in_value;\n this._order.push(in_key);\n\n this.onAdd(in_key, in_value);\n\n return in_value;\n }\n\n /**\n * Checks if in_value's type is equal to this Collection type. If this collection\n * has no type set, the check will pass.\n *\n * @param in_value - A value that is equal to the type managed by this collection.\n * @returns Return true if the type is a valid type for this\n * collection, throw otherwise.\n */\n private _checkType(in_value: T) {\n if (this._type && !(in_value instanceof this._type)) {\n throw new Error(MSGS.TYPE_MISMATCH);\n } else {\n return true;\n }\n }\n\n /**\n * Bulk add items.\n * @param in_items - List of key-value pairs to be stored in the collection\n * @returns this collection after add\n */\n bulkAdd(in_items: { [key: string]: T; }) {\n _.each(in_items, (item, key) => {\n this.add(key, item);\n });\n return this;\n }\n\n /**\n * Bulk remove items.\n * @param in_items - List of key-value items to be removed\n * @returns this collection after add\n */\n bulkRemove(in_items: { [key: string]: T; }) {\n _.each(in_items, (item, key) => {\n this.remove(key);\n });\n\n return this;\n }\n\n /**\n * Test if this collection is empty\n * @returns true if empty, false otherwise\n * */\n isEmpty() {\n return _.isEmpty(this._items);\n }\n\n /**\n * Return the first item in the collection, null if empty\n * @returns first item, or undefined if empty\n * */\n getFirstItem(): T | undefined {\n const index = _.first(this._order);\n return index === undefined ? index : this._items[index];\n }\n\n /**\n * Return the last item in the collection, null if empty\n * @returns - last item, or undefined if empty\n * */\n getLastItem(): T | undefined {\n const index = _.last(this._order);\n return index === undefined ? index : this._items[index];\n }\n\n /**\n * @returns Returns the type of collection (Array, etc.)\n */\n getType() {\n return this._type;\n }\n\n /**\n * @returns Returns the name of the collection\n */\n getName(): string {\n return this._name;\n }\n\n /**\n * Filter out by function\n * @param in_filterFunction - with arguments key and item\n * @returns New filtered collection\n */\n filter(in_filterFunction: (key: string, item: T) => boolean): Collection<T> {\n const rtn = new Collection<T>();\n\n const filterCb = function(in_key, in_item) {\n const keeper = in_filterFunction(in_key, in_item);\n if (keeper) {\n rtn.add(in_key, in_item);\n }\n };\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Filter out all keys NOT matching the in_filterKey\n * @param in_filterKey - a single key or an array of keys, if the\n * item matches any of the keys it will be filtered in.\n * @returns New filtered collection with all the items\n * matching at least one key.\n */\n filterByKey(in_filterKey: string | string[]): Collection<T> {\n const rtn = new Collection<T>();\n\n let filterCb;\n\n if (_.isArray(in_filterKey)) {\n filterCb = function(in_key, in_item) {\n if (in_filterKey.indexOf(in_key) >= 0) {\n rtn.add(in_key, in_item);\n }\n };\n } else {\n // if in_filterKey is an array\n filterCb = function(in_key, in_item) {\n if (in_key === in_filterKey) {\n rtn.add(in_key, in_item);\n }\n };\n }\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Filter out all keys NOT matching the in_filterValue\n * @param in_filterValue - Value to filter on\n * @returns Return a filtered collection\n */\n filterByValue(in_filterValue: T): Collection<T> {\n const rtn = new Collection<T>();\n\n const filterCb = function(in_key, in_item) {\n if (in_item === in_filterValue) {\n rtn.add(in_key, in_item);\n }\n };\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Remove an item from this Collection. This method returns a Boolean indicating\n * the success or failure of the removal. This is practical because if we were\n * to throw an error when the key doesn't exist, it would require additional\n * checks by the caller to make sure this key exists prior to removal. Which\n * would make the attempt of removal more verbose and also costly because the\n * caller would have to keep a list – somewhere else – of the things he can\n * and cannot remove.\n *\n * @param in_key - the key we wish to remove\n * @returns true if the key exists and was removed, false otherwise.\n */\n remove(in_key: number | string): boolean {\n if (!this.has(in_key)) {\n return false;\n }\n\n const remember = this._items[in_key];\n\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._items[in_key];\n this._order.splice(this._order.indexOf(in_key), 1);\n\n this.onRemove(in_key, remember);\n\n return true;\n }\n\n /**\n * Return the number of items in this Collection\n * @returns the number of items in the collection\n */\n getCount(): number {\n return this._order.length;\n }\n\n /**\n * Returns this collection as an ordered Array\n * @returns Array including the values\n */\n getAsArray() {\n const rtnArr: T[] = new Array(this.getCount());\n\n for (let i = 0; i < this._order.length; i++) {\n rtnArr[i] = this._items[this._order[i]];\n }\n\n return rtnArr;\n }\n\n /**\n * @param in_key - the key we are looking for\n * @returns true if the item exists\n */\n has(in_key: string | number): boolean {\n return Object.prototype.hasOwnProperty.call(this._items, in_key);\n }\n\n /**\n * Return an item associated with the given key\n * @param in_key - the key for the item in this\n * Collection\n * @returns The item\n */\n item(in_key: number | string) {\n return this._items[in_key];\n }\n\n /**\n * Checks if this is a new key in the collection. Throw if already exists.\n * @param in_key - The key to check against\n * @returns true if key is new\n */\n private _checkIsNewKey(in_key: number | string) {\n if (this.has(in_key)) {\n throw new Error(`${MSGS.KEY_ALREADY_EXISTS} ${in_key}`);\n }\n\n return true;\n }\n\n /**\n * Checks if the key exists in the collection. Throw if not.\n * @param in_key - the key to check against\n * @returns true if key exists\n */\n private _checkKeyExists(in_key: number | string) {\n if (!this.has(in_key)) {\n throw new Error(`${MSGS.KEY_DOES_NOT_EXIST} ${in_key}`);\n }\n\n return true;\n }\n\n /**\n * Set an existing key to a value. If key doesn't exist this call will throw\n * an error.\n * @param in_key - the key we want to modify\n * @param in_value - the value we are to set at this key\n * @returns the value passed in\n */\n set(in_key: string, in_value: T) {\n this._checkKeyExists(in_key);\n\n this._items[in_key] = in_value;\n\n return in_value;\n }\n\n /**\n * Iterate over this collection and run the callback with passing the key and\n * item in the iteration loop.\n * @param in_callback - a function that we will call on each item\n * of this collection. If the callback returns false then the iteration will exit early.\n */\n iterate(in_callback) {\n for (const key of this._order) {\n const continu = in_callback(key, this._items[key]);\n if (continu === false) {\n break;\n }\n }\n }\n\n /**\n * Iterate over this collection starting from the tail and run the callback with passing the key and\n * item in the iteration loop.\n * @param in_callback - a function that we will call on each item\n * of this collection. If the callback returns false then the iteration will exit early.\n */\n iterateFromTail(in_callback) {\n let key; let continu;\n for (let i = this._order.length - 1; i >= 0; i--) {\n key = this._order[i];\n continu = in_callback(key, this._items[key]);\n if (continu === false) {\n break;\n }\n }\n }\n\n /**\n * @returns Return an object containing the items of this collection\n */\n getItems(): { [key: string]: T; } {\n const result = {};\n\n _.each(this._items, function(item, key) {\n result[key] = item;\n });\n\n return result;\n }\n\n /**\n * Return the list of keys\n * @returns List of keys\n */\n getKeys(): string[] {\n return Object.keys(this._items);\n }\n\n /**\n * Method used to get the first element in the collection along with its key.\n */\n peak() {\n return {\n item: this._items[this._order[0]],\n key: this._order[0],\n };\n }\n\n /**\n * Clear this collection\n * @returns this collection\n */\n clear() {\n if (_.isEmpty(this._items)) {\n return this;\n }\n\n this.onClear(this._items);\n\n // Best to just iterate through and remove everything, so that OnRemove\n // handlers are called.\n\n _.each(this.getKeys(), (key) => {\n this.remove(key);\n });\n\n return this;\n }\n\n /**\n * Copy the items of in_collection to this collection.\n * @param in_collection - the collection we want to\n * copy from.\n * @returns new Collection\n */\n clone(): Collection<T> {\n const newCol = new Collection<T>(this._name, this._type);\n newCol.bulkAdd(this._items);\n return newCol;\n }\n\n /**\n * Copy the items of in_collection to this collection.\n * @param in_collection - the collection we want to\n * copy from.\n */\n copy(in_collection: Collection<T>) {\n this.clear();\n const its = in_collection.items;\n\n _.each(its, (item, key) => {\n this.add(key, item);\n });\n }\n\n get values() {\n return this.getAsArray();\n }\n}\n"]}
1
+ {"version":3,"file":"collection.js","sourceRoot":"","sources":["../../src/datastructures/collection.ts"],"names":[],"mappings":";;;;;;AAAA;;;GAGG;AACH,4DAA4D;AAC5D;;GAEG;AACH,oDAAuB;AAEvB,MAAM,IAAI,GAAG;IACT,aAAa,EAAE,0CAA0C;IACzD,kBAAkB,EAAE,iCAAiC;IACrD,kBAAkB,EAAE,mDAAmD;IACvE,aAAa,EAAE,yBAAyB;IACxC,eAAe,EAAE,2BAA2B;IAC5C,aAAa,EAAE,sCAAsC;CACxD,CAAC;AAEF,MAAa,UAAU;IAInB;;;;;OAKG;IACH,YAAsB,QAAQ,qBAAqB,EAAY,KAAqB;QAA9D,UAAK,GAAL,KAAK,CAAwB;QAAY,UAAK,GAAL,KAAK,CAAgB;QAT1E,WAAM,GAA0B,EAAE,CAAC;QACnC,WAAM,GAAwB,EAAE,CAAC;IAS3C,CAAC;IAED,4BAA4B;IAC5B,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC;IAC9B,OAAO,CAAC,QAAQ,IAAI,CAAC;IAErB,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,IAAW,IAAI;QACX,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,MAAuB,EAAE,QAAW;QACpC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC1B,IAAI,CAAC,cAAc,CAAC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,IAAI,gBAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YACxB,OAAO,IAAI,CAAC;SACf;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE1B,uEAAuE;QACvE,uBAAuB;QAEvB,gBAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;YAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAI,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,aAA4B;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC;QAEhC,gBAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YACtB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;CACJ;AAjaD,gCAiaC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n/* eslint accessor-pairs: [2, { \"getWithoutSet\": false }] */\n/**\n * @fileoverview Collection class definition\n */\nimport _ from \"lodash\";\n\nconst MSGS = {\n TYPE_MISMATCH: \"Type does not match this collection type\",\n KEY_ALREADY_EXISTS: \"Collection key already exists. \",\n KEY_DOES_NOT_EXIST: \"Collection key does not exist in this collection.\",\n MUST_GIVE_KEY: \"Collection missing key.\",\n MUST_GIVE_VALUE: \"Collection missing value.\",\n KEY_NOT_VALID: \"Key must be of type String or Number\",\n};\n\nexport class Collection<T> {\n protected _items: { [key: string]: T; } = {};\n protected _order: (string | number)[] = [];\n\n /**\n * @param _name - a friendly name to describe this collection. If undefined\n * the collection will have a default \"Untitled Collection\" assigned to its name.\n * @param _type - optional parameter pointing to the constructor\n * of a type this Collection will host.\n */\n constructor(protected _name = \"Untitled Collection\", protected _type?: new () => any) {\n }\n\n // Pass-thru binding handles\n onAdd(in_key, in_value) { }\n onRemove(in_key, in_value) { }\n onClear(in_items) { }\n\n public get items() {\n return this._items;\n }\n\n public get keys() {\n return Object.keys(this._items);\n }\n\n /**\n * @param in_key - Key to store the value under\n * @param in_value - Value to store in the collection\n * @returns Return the value passed in\n */\n add(in_key: number | string, in_value: T): T {\n this._checkType(in_value);\n this._checkIsNewKey(in_key);\n\n this._items[in_key] = in_value;\n this._order.push(in_key);\n\n this.onAdd(in_key, in_value);\n\n return in_value;\n }\n\n /**\n * Checks if in_value's type is equal to this Collection type. If this collection\n * has no type set, the check will pass.\n *\n * @param in_value - A value that is equal to the type managed by this collection.\n * @returns Return true if the type is a valid type for this\n * collection, throw otherwise.\n */\n private _checkType(in_value: T) {\n if (this._type && !(in_value instanceof this._type)) {\n throw new Error(MSGS.TYPE_MISMATCH);\n } else {\n return true;\n }\n }\n\n /**\n * Bulk add items.\n * @param in_items - List of key-value pairs to be stored in the collection\n * @returns this collection after add\n */\n bulkAdd(in_items: { [key: string]: T; }) {\n _.each(in_items, (item, key) => {\n this.add(key, item);\n });\n return this;\n }\n\n /**\n * Bulk remove items.\n * @param in_items - List of key-value items to be removed\n * @returns this collection after add\n */\n bulkRemove(in_items: { [key: string]: T; }) {\n _.each(in_items, (item, key) => {\n this.remove(key);\n });\n\n return this;\n }\n\n /**\n * Test if this collection is empty\n * @returns true if empty, false otherwise\n * */\n isEmpty() {\n return _.isEmpty(this._items);\n }\n\n /**\n * Return the first item in the collection, null if empty\n * @returns first item, or undefined if empty\n * */\n getFirstItem(): T | undefined {\n const index = _.first(this._order);\n return index === undefined ? index : this._items[index];\n }\n\n /**\n * Return the last item in the collection, null if empty\n * @returns - last item, or undefined if empty\n * */\n getLastItem(): T | undefined {\n const index = _.last(this._order);\n return index === undefined ? index : this._items[index];\n }\n\n /**\n * @returns Returns the type of collection (Array, etc.)\n */\n getType() {\n return this._type;\n }\n\n /**\n * @returns Returns the name of the collection\n */\n getName(): string {\n return this._name;\n }\n\n /**\n * Filter out by function\n * @param in_filterFunction - with arguments key and item\n * @returns New filtered collection\n */\n filter(in_filterFunction: (key: string, item: T) => boolean): Collection<T> {\n const rtn = new Collection<T>();\n\n const filterCb = function(in_key, in_item) {\n const keeper = in_filterFunction(in_key, in_item);\n if (keeper) {\n rtn.add(in_key, in_item);\n }\n };\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Filter out all keys NOT matching the in_filterKey\n * @param in_filterKey - a single key or an array of keys, if the\n * item matches any of the keys it will be filtered in.\n * @returns New filtered collection with all the items\n * matching at least one key.\n */\n filterByKey(in_filterKey: string | string[]): Collection<T> {\n const rtn = new Collection<T>();\n\n let filterCb;\n\n if (_.isArray(in_filterKey)) {\n filterCb = function(in_key, in_item) {\n if (in_filterKey.includes(in_key)) {\n rtn.add(in_key, in_item);\n }\n };\n } else {\n // if in_filterKey is an array\n filterCb = function(in_key, in_item) {\n if (in_key === in_filterKey) {\n rtn.add(in_key, in_item);\n }\n };\n }\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Filter out all keys NOT matching the in_filterValue\n * @param in_filterValue - Value to filter on\n * @returns Return a filtered collection\n */\n filterByValue(in_filterValue: T): Collection<T> {\n const rtn = new Collection<T>();\n\n const filterCb = function(in_key, in_item) {\n if (in_item === in_filterValue) {\n rtn.add(in_key, in_item);\n }\n };\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Remove an item from this Collection. This method returns a Boolean indicating\n * the success or failure of the removal. This is practical because if we were\n * to throw an error when the key doesn't exist, it would require additional\n * checks by the caller to make sure this key exists prior to removal. Which\n * would make the attempt of removal more verbose and also costly because the\n * caller would have to keep a list – somewhere else – of the things he can\n * and cannot remove.\n *\n * @param in_key - the key we wish to remove\n * @returns true if the key exists and was removed, false otherwise.\n */\n remove(in_key: number | string): boolean {\n if (!this.has(in_key)) {\n return false;\n }\n\n const remember = this._items[in_key];\n\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._items[in_key];\n this._order.splice(this._order.indexOf(in_key), 1);\n\n this.onRemove(in_key, remember);\n\n return true;\n }\n\n /**\n * Return the number of items in this Collection\n * @returns the number of items in the collection\n */\n getCount(): number {\n return this._order.length;\n }\n\n /**\n * Returns this collection as an ordered Array\n * @returns Array including the values\n */\n getAsArray() {\n const rtnArr: T[] = new Array(this.getCount());\n\n for (let i = 0; i < this._order.length; i++) {\n rtnArr[i] = this._items[this._order[i]];\n }\n\n return rtnArr;\n }\n\n /**\n * @param in_key - the key we are looking for\n * @returns true if the item exists\n */\n has(in_key: string | number): boolean {\n return Object.prototype.hasOwnProperty.call(this._items, in_key);\n }\n\n /**\n * Return an item associated with the given key\n * @param in_key - the key for the item in this\n * Collection\n * @returns The item\n */\n item(in_key: number | string) {\n return this._items[in_key];\n }\n\n /**\n * Checks if this is a new key in the collection. Throw if already exists.\n * @param in_key - The key to check against\n * @returns true if key is new\n */\n private _checkIsNewKey(in_key: number | string) {\n if (this.has(in_key)) {\n throw new Error(`${MSGS.KEY_ALREADY_EXISTS} ${in_key}`);\n }\n\n return true;\n }\n\n /**\n * Checks if the key exists in the collection. Throw if not.\n * @param in_key - the key to check against\n * @returns true if key exists\n */\n private _checkKeyExists(in_key: number | string) {\n if (!this.has(in_key)) {\n throw new Error(`${MSGS.KEY_DOES_NOT_EXIST} ${in_key}`);\n }\n\n return true;\n }\n\n /**\n * Set an existing key to a value. If key doesn't exist this call will throw\n * an error.\n * @param in_key - the key we want to modify\n * @param in_value - the value we are to set at this key\n * @returns the value passed in\n */\n set(in_key: string, in_value: T) {\n this._checkKeyExists(in_key);\n\n this._items[in_key] = in_value;\n\n return in_value;\n }\n\n /**\n * Iterate over this collection and run the callback with passing the key and\n * item in the iteration loop.\n * @param in_callback - a function that we will call on each item\n * of this collection. If the callback returns false then the iteration will exit early.\n */\n iterate(in_callback) {\n for (const key of this._order) {\n const continu = in_callback(key, this._items[key]);\n if (continu === false) {\n break;\n }\n }\n }\n\n /**\n * Iterate over this collection starting from the tail and run the callback with passing the key and\n * item in the iteration loop.\n * @param in_callback - a function that we will call on each item\n * of this collection. If the callback returns false then the iteration will exit early.\n */\n iterateFromTail(in_callback) {\n let key; let continu;\n for (let i = this._order.length - 1; i >= 0; i--) {\n key = this._order[i];\n continu = in_callback(key, this._items[key]);\n if (continu === false) {\n break;\n }\n }\n }\n\n /**\n * @returns Return an object containing the items of this collection\n */\n getItems(): { [key: string]: T; } {\n const result = {};\n\n _.each(this._items, function(item, key) {\n result[key] = item;\n });\n\n return result;\n }\n\n /**\n * Return the list of keys\n * @returns List of keys\n */\n getKeys(): string[] {\n return Object.keys(this._items);\n }\n\n /**\n * Method used to get the first element in the collection along with its key.\n */\n peak() {\n return {\n item: this._items[this._order[0]],\n key: this._order[0],\n };\n }\n\n /**\n * Clear this collection\n * @returns this collection\n */\n clear() {\n if (_.isEmpty(this._items)) {\n return this;\n }\n\n this.onClear(this._items);\n\n // Best to just iterate through and remove everything, so that OnRemove\n // handlers are called.\n\n _.each(this.getKeys(), (key) => {\n this.remove(key);\n });\n\n return this;\n }\n\n /**\n * Copy the items of in_collection to this collection.\n * @param in_collection - the collection we want to\n * copy from.\n * @returns new Collection\n */\n clone(): Collection<T> {\n const newCol = new Collection<T>(this._name, this._type);\n newCol.bulkAdd(this._items);\n return newCol;\n }\n\n /**\n * Copy the items of in_collection to this collection.\n * @param in_collection - the collection we want to\n * copy from.\n */\n copy(in_collection: Collection<T>) {\n this.clear();\n const its = in_collection.items;\n\n _.each(its, (item, key) => {\n this.add(key, item);\n });\n }\n\n get values() {\n return this.getAsArray();\n }\n}\n"]}
@@ -53,7 +53,7 @@ class HTTPError extends Error {
53
53
  const isFirefox = typeof window !== "undefined" &&
54
54
  typeof window.navigator !== "undefined" &&
55
55
  typeof window.navigator.userAgent !== "undefined" &&
56
- window.navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
56
+ window.navigator.userAgent.toLowerCase().includes("firefox");
57
57
  return isFirefox ? `${this.message}, stack:${stack}` : `stack:${stack}`;
58
58
  }
59
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"httpError.js","sourceRoot":"","sources":["../../src/error_objects/httpError.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,iDAA8C;AAE9C;;;;;;;;GAQG;AACH,MAAa,SAAU,SAAQ,KAAK;IAChC,YACW,KAAc,EACd,UAAmB,EACnB,aAAsB,EACtB,MAAe,EACf,GAAY,EACZ,QAAQ,CAAC;QAEhB,KAAK,EAAE,CAAC;QAPD,UAAK,GAAL,KAAK,CAAS;QACd,eAAU,GAAV,UAAU,CAAS;QACnB,kBAAa,GAAb,aAAa,CAAS;QACtB,WAAM,GAAN,MAAM,CAAS;QACf,QAAG,GAAH,GAAG,CAAS;QACZ,UAAK,GAAL,KAAK,CAAI;QAGhB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACpF,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IACjD,CAAC;IAID,OAAO;QACH,OAAO,2BAAY,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AC3C,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW;YACvC,OAAO,MAAM,CAAC,SAAS,CAAC,SAAS,KAAK,WAAW;YACjD,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QAErE,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC;IAC5E,CAAC;;AAlDL,8BAmDC;AAnCU,eAAK,GAAG,2BAAY,CAAC,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { FlaggedError } from \"./flaggedError\";\n\n/**\n * Class extending Error with HTTP-specific error information like statusCode and statusMessage\n * @param title - The error title\n * @param statusCode - A numeric HTTP status code\n * @param statusMessage - A string message representing the response status message\n * @param method - The HTTP method used in the request\n * @param url - The URL that the request was sent to\n * @param flags - Flags that characterize the error. See {@link FlaggedError.FLAGS}.\n */\nexport class HTTPError extends Error {\n constructor(\n public title?: string,\n public statusCode?: number,\n public statusMessage?: string,\n public method?: string,\n public url?: string,\n public flags = 0,\n ) {\n super();\n Object.setPrototypeOf(this, HTTPError.prototype);\n this.name = \"HTTPError\";\n this.message = this._generateMessage(title, statusCode, statusMessage, method, url);\n this.stack = (new Error(this.message)).stack;\n }\n\n static FLAGS = FlaggedError.FLAGS;\n\n isQuiet(): boolean {\n return FlaggedError.prototype.isQuiet.call(this);\n }\n\n isTransient(): boolean {\n return FlaggedError.prototype.isTransient.call(this);\n }\n\n private _generateMessage(title, statusCode, statusMessage, method, url) {\n const titleStr = (title === undefined) ? \"\" : String(title);\n const statusCodeStr = (statusCode === undefined) ? \"\" : String(statusCode);\n const statusMessageStr = (statusMessage === undefined) ? \"\" : String(statusMessage);\n const methodStr = (method === undefined) ? \"\" : String(method);\n const urlStr = (url === undefined) ? \"\" : String(url);\n\n return `HTTPError: ${titleStr}, statusCode:${statusCodeStr}, ` +\n `statusMessage:${statusMessageStr}, method:${methodStr}, url:${urlStr}`;\n }\n\n /**\n * Returns a string representing the HTTPError object\n * @returns a string representing the HTTPError object\n */\n toString(): string {\n const stack = (this.stack === undefined) ? \"\" : String(this.stack);\n\n const isFirefox = typeof window !== \"undefined\" &&\n typeof window.navigator !== \"undefined\" &&\n typeof window.navigator.userAgent !== \"undefined\" &&\n window.navigator.userAgent.toLowerCase().indexOf(\"firefox\") > -1;\n\n return isFirefox ? `${this.message}, stack:${stack}` : `stack:${stack}`;\n }\n}\n"]}
1
+ {"version":3,"file":"httpError.js","sourceRoot":"","sources":["../../src/error_objects/httpError.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,iDAA8C;AAE9C;;;;;;;;GAQG;AACH,MAAa,SAAU,SAAQ,KAAK;IAChC,YACW,KAAc,EACd,UAAmB,EACnB,aAAsB,EACtB,MAAe,EACf,GAAY,EACZ,QAAQ,CAAC;QAEhB,KAAK,EAAE,CAAC;QAPD,UAAK,GAAL,KAAK,CAAS;QACd,eAAU,GAAV,UAAU,CAAS;QACnB,kBAAa,GAAb,aAAa,CAAS;QACtB,WAAM,GAAN,MAAM,CAAS;QACf,QAAG,GAAH,GAAG,CAAS;QACZ,UAAK,GAAL,KAAK,CAAI;QAGhB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACpF,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IACjD,CAAC;IAID,OAAO;QACH,OAAO,2BAAY,CAA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C,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW;YACvC,OAAO,MAAM,CAAC,SAAS,CAAC,SAAS,KAAK,WAAW;YACjD,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAEjE,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC;IAC5E,CAAC;;AAlDL,8BAmDC;AAnCU,eAAK,GAAG,2BAAY,CAAC,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { FlaggedError } from \"./flaggedError\";\n\n/**\n * Class extending Error with HTTP-specific error information like statusCode and statusMessage\n * @param title - The error title\n * @param statusCode - A numeric HTTP status code\n * @param statusMessage - A string message representing the response status message\n * @param method - The HTTP method used in the request\n * @param url - The URL that the request was sent to\n * @param flags - Flags that characterize the error. See {@link FlaggedError.FLAGS}.\n */\nexport class HTTPError extends Error {\n constructor(\n public title?: string,\n public statusCode?: number,\n public statusMessage?: string,\n public method?: string,\n public url?: string,\n public flags = 0,\n ) {\n super();\n Object.setPrototypeOf(this, HTTPError.prototype);\n this.name = \"HTTPError\";\n this.message = this._generateMessage(title, statusCode, statusMessage, method, url);\n this.stack = (new Error(this.message)).stack;\n }\n\n static FLAGS = FlaggedError.FLAGS;\n\n isQuiet(): boolean {\n return FlaggedError.prototype.isQuiet.call(this);\n }\n\n isTransient(): boolean {\n return FlaggedError.prototype.isTransient.call(this);\n }\n\n private _generateMessage(title, statusCode, statusMessage, method, url) {\n const titleStr = (title === undefined) ? \"\" : String(title);\n const statusCodeStr = (statusCode === undefined) ? \"\" : String(statusCode);\n const statusMessageStr = (statusMessage === undefined) ? \"\" : String(statusMessage);\n const methodStr = (method === undefined) ? \"\" : String(method);\n const urlStr = (url === undefined) ? \"\" : String(url);\n\n return `HTTPError: ${titleStr}, statusCode:${statusCodeStr}, ` +\n `statusMessage:${statusMessageStr}, method:${methodStr}, url:${urlStr}`;\n }\n\n /**\n * Returns a string representing the HTTPError object\n * @returns a string representing the HTTPError object\n */\n toString(): string {\n const stack = (this.stack === undefined) ? \"\" : String(this.stack);\n\n const isFirefox = typeof window !== \"undefined\" &&\n typeof window.navigator !== \"undefined\" &&\n typeof window.navigator.userAgent !== \"undefined\" &&\n window.navigator.userAgent.toLowerCase().includes(\"firefox\");\n\n return isFirefox ? `${this.message}, stack:${stack}` : `stack:${stack}`;\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluid-experimental/property-common";
8
- export declare const pkgVersion = "0.59.3003";
8
+ export declare const pkgVersion = "0.59.4000";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluid-experimental/property-common";
11
- exports.pkgVersion = "0.59.3003";
11
+ exports.pkgVersion = "0.59.4000";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,qCAAqC,CAAC;AAChD,QAAA,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluid-experimental/property-common\";\nexport const pkgVersion = \"0.59.3003\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,qCAAqC,CAAC;AAChD,QAAA,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluid-experimental/property-common\";\nexport const pkgVersion = \"0.59.4000\";\n"]}
@@ -152,7 +152,7 @@ export class Collection {
152
152
  let filterCb;
153
153
  if (_.isArray(in_filterKey)) {
154
154
  filterCb = function (in_key, in_item) {
155
- if (in_filterKey.indexOf(in_key) >= 0) {
155
+ if (in_filterKey.includes(in_key)) {
156
156
  rtn.add(in_key, in_item);
157
157
  }
158
158
  };
@@ -1 +1 @@
1
- {"version":3,"file":"collection.js","sourceRoot":"","sources":["../../src/datastructures/collection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,4DAA4D;AAC5D;;GAEG;AACH,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,MAAM,IAAI,GAAG;IACT,aAAa,EAAE,0CAA0C;IACzD,kBAAkB,EAAE,iCAAiC;IACrD,kBAAkB,EAAE,mDAAmD;IACvE,aAAa,EAAE,yBAAyB;IACxC,eAAe,EAAE,2BAA2B;IAC5C,aAAa,EAAE,sCAAsC;CACxD,CAAC;AAEF,MAAM,OAAO,UAAU;IAInB;;;;;OAKG;IACH,YAAsB,QAAQ,qBAAqB,EAAY,KAAqB;QAA9D,UAAK,GAAL,KAAK,CAAwB;QAAY,UAAK,GAAL,KAAK,CAAgB;QAT1E,WAAM,GAA0B,EAAE,CAAC;QACnC,WAAM,GAAwB,EAAE,CAAC;IAS3C,CAAC;IAED,4BAA4B;IAC5B,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC;IAC9B,OAAO,CAAC,QAAQ,IAAI,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,EAAE,CAAC;IAC7B,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n/* eslint accessor-pairs: [2, { \"getWithoutSet\": false }] */\n/**\n * @fileoverview Collection class definition\n */\nimport _ from \"lodash\";\n\nconst MSGS = {\n TYPE_MISMATCH: \"Type does not match this collection type\",\n KEY_ALREADY_EXISTS: \"Collection key already exists. \",\n KEY_DOES_NOT_EXIST: \"Collection key does not exist in this collection.\",\n MUST_GIVE_KEY: \"Collection missing key.\",\n MUST_GIVE_VALUE: \"Collection missing value.\",\n KEY_NOT_VALID: \"Key must be of type String or Number\",\n};\n\nexport class Collection<T> {\n protected _items: { [key: string]: T; } = {};\n protected _order: (string | number)[] = [];\n\n /**\n * @param _name - a friendly name to describe this collection. If undefined\n * the collection will have a default \"Untitled Collection\" assigned to its name.\n * @param _type - optional parameter pointing to the constructor\n * of a type this Collection will host.\n */\n constructor(protected _name = \"Untitled Collection\", protected _type?: new () => any) {\n }\n\n // Pass-thru binding handles\n onAdd(in_key, in_value) { }\n onRemove(in_key, in_value) { }\n onClear(in_items) { }\n\n public get items() {\n return this._items;\n }\n\n public get keys() {\n return Object.keys(this._items);\n }\n\n /**\n * @param in_key - Key to store the value under\n * @param in_value - Value to store in the collection\n * @returns Return the value passed in\n */\n add(in_key: number | string, in_value: T): T {\n this._checkType(in_value);\n this._checkIsNewKey(in_key);\n\n this._items[in_key] = in_value;\n this._order.push(in_key);\n\n this.onAdd(in_key, in_value);\n\n return in_value;\n }\n\n /**\n * Checks if in_value's type is equal to this Collection type. If this collection\n * has no type set, the check will pass.\n *\n * @param in_value - A value that is equal to the type managed by this collection.\n * @returns Return true if the type is a valid type for this\n * collection, throw otherwise.\n */\n private _checkType(in_value: T) {\n if (this._type && !(in_value instanceof this._type)) {\n throw new Error(MSGS.TYPE_MISMATCH);\n } else {\n return true;\n }\n }\n\n /**\n * Bulk add items.\n * @param in_items - List of key-value pairs to be stored in the collection\n * @returns this collection after add\n */\n bulkAdd(in_items: { [key: string]: T; }) {\n _.each(in_items, (item, key) => {\n this.add(key, item);\n });\n return this;\n }\n\n /**\n * Bulk remove items.\n * @param in_items - List of key-value items to be removed\n * @returns this collection after add\n */\n bulkRemove(in_items: { [key: string]: T; }) {\n _.each(in_items, (item, key) => {\n this.remove(key);\n });\n\n return this;\n }\n\n /**\n * Test if this collection is empty\n * @returns true if empty, false otherwise\n * */\n isEmpty() {\n return _.isEmpty(this._items);\n }\n\n /**\n * Return the first item in the collection, null if empty\n * @returns first item, or undefined if empty\n * */\n getFirstItem(): T | undefined {\n const index = _.first(this._order);\n return index === undefined ? index : this._items[index];\n }\n\n /**\n * Return the last item in the collection, null if empty\n * @returns - last item, or undefined if empty\n * */\n getLastItem(): T | undefined {\n const index = _.last(this._order);\n return index === undefined ? index : this._items[index];\n }\n\n /**\n * @returns Returns the type of collection (Array, etc.)\n */\n getType() {\n return this._type;\n }\n\n /**\n * @returns Returns the name of the collection\n */\n getName(): string {\n return this._name;\n }\n\n /**\n * Filter out by function\n * @param in_filterFunction - with arguments key and item\n * @returns New filtered collection\n */\n filter(in_filterFunction: (key: string, item: T) => boolean): Collection<T> {\n const rtn = new Collection<T>();\n\n const filterCb = function(in_key, in_item) {\n const keeper = in_filterFunction(in_key, in_item);\n if (keeper) {\n rtn.add(in_key, in_item);\n }\n };\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Filter out all keys NOT matching the in_filterKey\n * @param in_filterKey - a single key or an array of keys, if the\n * item matches any of the keys it will be filtered in.\n * @returns New filtered collection with all the items\n * matching at least one key.\n */\n filterByKey(in_filterKey: string | string[]): Collection<T> {\n const rtn = new Collection<T>();\n\n let filterCb;\n\n if (_.isArray(in_filterKey)) {\n filterCb = function(in_key, in_item) {\n if (in_filterKey.indexOf(in_key) >= 0) {\n rtn.add(in_key, in_item);\n }\n };\n } else {\n // if in_filterKey is an array\n filterCb = function(in_key, in_item) {\n if (in_key === in_filterKey) {\n rtn.add(in_key, in_item);\n }\n };\n }\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Filter out all keys NOT matching the in_filterValue\n * @param in_filterValue - Value to filter on\n * @returns Return a filtered collection\n */\n filterByValue(in_filterValue: T): Collection<T> {\n const rtn = new Collection<T>();\n\n const filterCb = function(in_key, in_item) {\n if (in_item === in_filterValue) {\n rtn.add(in_key, in_item);\n }\n };\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Remove an item from this Collection. This method returns a Boolean indicating\n * the success or failure of the removal. This is practical because if we were\n * to throw an error when the key doesn't exist, it would require additional\n * checks by the caller to make sure this key exists prior to removal. Which\n * would make the attempt of removal more verbose and also costly because the\n * caller would have to keep a list – somewhere else – of the things he can\n * and cannot remove.\n *\n * @param in_key - the key we wish to remove\n * @returns true if the key exists and was removed, false otherwise.\n */\n remove(in_key: number | string): boolean {\n if (!this.has(in_key)) {\n return false;\n }\n\n const remember = this._items[in_key];\n\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._items[in_key];\n this._order.splice(this._order.indexOf(in_key), 1);\n\n this.onRemove(in_key, remember);\n\n return true;\n }\n\n /**\n * Return the number of items in this Collection\n * @returns the number of items in the collection\n */\n getCount(): number {\n return this._order.length;\n }\n\n /**\n * Returns this collection as an ordered Array\n * @returns Array including the values\n */\n getAsArray() {\n const rtnArr: T[] = new Array(this.getCount());\n\n for (let i = 0; i < this._order.length; i++) {\n rtnArr[i] = this._items[this._order[i]];\n }\n\n return rtnArr;\n }\n\n /**\n * @param in_key - the key we are looking for\n * @returns true if the item exists\n */\n has(in_key: string | number): boolean {\n return Object.prototype.hasOwnProperty.call(this._items, in_key);\n }\n\n /**\n * Return an item associated with the given key\n * @param in_key - the key for the item in this\n * Collection\n * @returns The item\n */\n item(in_key: number | string) {\n return this._items[in_key];\n }\n\n /**\n * Checks if this is a new key in the collection. Throw if already exists.\n * @param in_key - The key to check against\n * @returns true if key is new\n */\n private _checkIsNewKey(in_key: number | string) {\n if (this.has(in_key)) {\n throw new Error(`${MSGS.KEY_ALREADY_EXISTS} ${in_key}`);\n }\n\n return true;\n }\n\n /**\n * Checks if the key exists in the collection. Throw if not.\n * @param in_key - the key to check against\n * @returns true if key exists\n */\n private _checkKeyExists(in_key: number | string) {\n if (!this.has(in_key)) {\n throw new Error(`${MSGS.KEY_DOES_NOT_EXIST} ${in_key}`);\n }\n\n return true;\n }\n\n /**\n * Set an existing key to a value. If key doesn't exist this call will throw\n * an error.\n * @param in_key - the key we want to modify\n * @param in_value - the value we are to set at this key\n * @returns the value passed in\n */\n set(in_key: string, in_value: T) {\n this._checkKeyExists(in_key);\n\n this._items[in_key] = in_value;\n\n return in_value;\n }\n\n /**\n * Iterate over this collection and run the callback with passing the key and\n * item in the iteration loop.\n * @param in_callback - a function that we will call on each item\n * of this collection. If the callback returns false then the iteration will exit early.\n */\n iterate(in_callback) {\n for (const key of this._order) {\n const continu = in_callback(key, this._items[key]);\n if (continu === false) {\n break;\n }\n }\n }\n\n /**\n * Iterate over this collection starting from the tail and run the callback with passing the key and\n * item in the iteration loop.\n * @param in_callback - a function that we will call on each item\n * of this collection. If the callback returns false then the iteration will exit early.\n */\n iterateFromTail(in_callback) {\n let key; let continu;\n for (let i = this._order.length - 1; i >= 0; i--) {\n key = this._order[i];\n continu = in_callback(key, this._items[key]);\n if (continu === false) {\n break;\n }\n }\n }\n\n /**\n * @returns Return an object containing the items of this collection\n */\n getItems(): { [key: string]: T; } {\n const result = {};\n\n _.each(this._items, function(item, key) {\n result[key] = item;\n });\n\n return result;\n }\n\n /**\n * Return the list of keys\n * @returns List of keys\n */\n getKeys(): string[] {\n return Object.keys(this._items);\n }\n\n /**\n * Method used to get the first element in the collection along with its key.\n */\n peak() {\n return {\n item: this._items[this._order[0]],\n key: this._order[0],\n };\n }\n\n /**\n * Clear this collection\n * @returns this collection\n */\n clear() {\n if (_.isEmpty(this._items)) {\n return this;\n }\n\n this.onClear(this._items);\n\n // Best to just iterate through and remove everything, so that OnRemove\n // handlers are called.\n\n _.each(this.getKeys(), (key) => {\n this.remove(key);\n });\n\n return this;\n }\n\n /**\n * Copy the items of in_collection to this collection.\n * @param in_collection - the collection we want to\n * copy from.\n * @returns new Collection\n */\n clone(): Collection<T> {\n const newCol = new Collection<T>(this._name, this._type);\n newCol.bulkAdd(this._items);\n return newCol;\n }\n\n /**\n * Copy the items of in_collection to this collection.\n * @param in_collection - the collection we want to\n * copy from.\n */\n copy(in_collection: Collection<T>) {\n this.clear();\n const its = in_collection.items;\n\n _.each(its, (item, key) => {\n this.add(key, item);\n });\n }\n\n get values() {\n return this.getAsArray();\n }\n}\n"]}
1
+ {"version":3,"file":"collection.js","sourceRoot":"","sources":["../../src/datastructures/collection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,4DAA4D;AAC5D;;GAEG;AACH,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,MAAM,IAAI,GAAG;IACT,aAAa,EAAE,0CAA0C;IACzD,kBAAkB,EAAE,iCAAiC;IACrD,kBAAkB,EAAE,mDAAmD;IACvE,aAAa,EAAE,yBAAyB;IACxC,eAAe,EAAE,2BAA2B;IAC5C,aAAa,EAAE,sCAAsC;CACxD,CAAC;AAEF,MAAM,OAAO,UAAU;IAInB;;;;;OAKG;IACH,YAAsB,QAAQ,qBAAqB,EAAY,KAAqB;QAA9D,UAAK,GAAL,KAAK,CAAwB;QAAY,UAAK,GAAL,KAAK,CAAgB;QAT1E,WAAM,GAA0B,EAAE,CAAC;QACnC,WAAM,GAAwB,EAAE,CAAC;IAS3C,CAAC;IAED,4BAA4B;IAC5B,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC;IAC9B,OAAO,CAAC,QAAQ,IAAI,CAAC;IAErB,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,IAAW,IAAI;QACX,OAAO,MA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H,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACjC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;SACtB,CAAC;IACN,CAAC;IAED;;;OAGG;IACH,KAAK;QACD,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YACxB,OAAO,IAAI,CAAC;SACf;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE1B,uEAAuE;QACvE,uBAAuB;QAEvB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;YAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAI,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,aAA4B;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC;QAEhC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YACtB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n/* eslint accessor-pairs: [2, { \"getWithoutSet\": false }] */\n/**\n * @fileoverview Collection class definition\n */\nimport _ from \"lodash\";\n\nconst MSGS = {\n TYPE_MISMATCH: \"Type does not match this collection type\",\n KEY_ALREADY_EXISTS: \"Collection key already exists. \",\n KEY_DOES_NOT_EXIST: \"Collection key does not exist in this collection.\",\n MUST_GIVE_KEY: \"Collection missing key.\",\n MUST_GIVE_VALUE: \"Collection missing value.\",\n KEY_NOT_VALID: \"Key must be of type String or Number\",\n};\n\nexport class Collection<T> {\n protected _items: { [key: string]: T; } = {};\n protected _order: (string | number)[] = [];\n\n /**\n * @param _name - a friendly name to describe this collection. If undefined\n * the collection will have a default \"Untitled Collection\" assigned to its name.\n * @param _type - optional parameter pointing to the constructor\n * of a type this Collection will host.\n */\n constructor(protected _name = \"Untitled Collection\", protected _type?: new () => any) {\n }\n\n // Pass-thru binding handles\n onAdd(in_key, in_value) { }\n onRemove(in_key, in_value) { }\n onClear(in_items) { }\n\n public get items() {\n return this._items;\n }\n\n public get keys() {\n return Object.keys(this._items);\n }\n\n /**\n * @param in_key - Key to store the value under\n * @param in_value - Value to store in the collection\n * @returns Return the value passed in\n */\n add(in_key: number | string, in_value: T): T {\n this._checkType(in_value);\n this._checkIsNewKey(in_key);\n\n this._items[in_key] = in_value;\n this._order.push(in_key);\n\n this.onAdd(in_key, in_value);\n\n return in_value;\n }\n\n /**\n * Checks if in_value's type is equal to this Collection type. If this collection\n * has no type set, the check will pass.\n *\n * @param in_value - A value that is equal to the type managed by this collection.\n * @returns Return true if the type is a valid type for this\n * collection, throw otherwise.\n */\n private _checkType(in_value: T) {\n if (this._type && !(in_value instanceof this._type)) {\n throw new Error(MSGS.TYPE_MISMATCH);\n } else {\n return true;\n }\n }\n\n /**\n * Bulk add items.\n * @param in_items - List of key-value pairs to be stored in the collection\n * @returns this collection after add\n */\n bulkAdd(in_items: { [key: string]: T; }) {\n _.each(in_items, (item, key) => {\n this.add(key, item);\n });\n return this;\n }\n\n /**\n * Bulk remove items.\n * @param in_items - List of key-value items to be removed\n * @returns this collection after add\n */\n bulkRemove(in_items: { [key: string]: T; }) {\n _.each(in_items, (item, key) => {\n this.remove(key);\n });\n\n return this;\n }\n\n /**\n * Test if this collection is empty\n * @returns true if empty, false otherwise\n * */\n isEmpty() {\n return _.isEmpty(this._items);\n }\n\n /**\n * Return the first item in the collection, null if empty\n * @returns first item, or undefined if empty\n * */\n getFirstItem(): T | undefined {\n const index = _.first(this._order);\n return index === undefined ? index : this._items[index];\n }\n\n /**\n * Return the last item in the collection, null if empty\n * @returns - last item, or undefined if empty\n * */\n getLastItem(): T | undefined {\n const index = _.last(this._order);\n return index === undefined ? index : this._items[index];\n }\n\n /**\n * @returns Returns the type of collection (Array, etc.)\n */\n getType() {\n return this._type;\n }\n\n /**\n * @returns Returns the name of the collection\n */\n getName(): string {\n return this._name;\n }\n\n /**\n * Filter out by function\n * @param in_filterFunction - with arguments key and item\n * @returns New filtered collection\n */\n filter(in_filterFunction: (key: string, item: T) => boolean): Collection<T> {\n const rtn = new Collection<T>();\n\n const filterCb = function(in_key, in_item) {\n const keeper = in_filterFunction(in_key, in_item);\n if (keeper) {\n rtn.add(in_key, in_item);\n }\n };\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Filter out all keys NOT matching the in_filterKey\n * @param in_filterKey - a single key or an array of keys, if the\n * item matches any of the keys it will be filtered in.\n * @returns New filtered collection with all the items\n * matching at least one key.\n */\n filterByKey(in_filterKey: string | string[]): Collection<T> {\n const rtn = new Collection<T>();\n\n let filterCb;\n\n if (_.isArray(in_filterKey)) {\n filterCb = function(in_key, in_item) {\n if (in_filterKey.includes(in_key)) {\n rtn.add(in_key, in_item);\n }\n };\n } else {\n // if in_filterKey is an array\n filterCb = function(in_key, in_item) {\n if (in_key === in_filterKey) {\n rtn.add(in_key, in_item);\n }\n };\n }\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Filter out all keys NOT matching the in_filterValue\n * @param in_filterValue - Value to filter on\n * @returns Return a filtered collection\n */\n filterByValue(in_filterValue: T): Collection<T> {\n const rtn = new Collection<T>();\n\n const filterCb = function(in_key, in_item) {\n if (in_item === in_filterValue) {\n rtn.add(in_key, in_item);\n }\n };\n\n this.iterate(filterCb);\n\n return rtn;\n }\n\n /**\n * Remove an item from this Collection. This method returns a Boolean indicating\n * the success or failure of the removal. This is practical because if we were\n * to throw an error when the key doesn't exist, it would require additional\n * checks by the caller to make sure this key exists prior to removal. Which\n * would make the attempt of removal more verbose and also costly because the\n * caller would have to keep a list – somewhere else – of the things he can\n * and cannot remove.\n *\n * @param in_key - the key we wish to remove\n * @returns true if the key exists and was removed, false otherwise.\n */\n remove(in_key: number | string): boolean {\n if (!this.has(in_key)) {\n return false;\n }\n\n const remember = this._items[in_key];\n\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._items[in_key];\n this._order.splice(this._order.indexOf(in_key), 1);\n\n this.onRemove(in_key, remember);\n\n return true;\n }\n\n /**\n * Return the number of items in this Collection\n * @returns the number of items in the collection\n */\n getCount(): number {\n return this._order.length;\n }\n\n /**\n * Returns this collection as an ordered Array\n * @returns Array including the values\n */\n getAsArray() {\n const rtnArr: T[] = new Array(this.getCount());\n\n for (let i = 0; i < this._order.length; i++) {\n rtnArr[i] = this._items[this._order[i]];\n }\n\n return rtnArr;\n }\n\n /**\n * @param in_key - the key we are looking for\n * @returns true if the item exists\n */\n has(in_key: string | number): boolean {\n return Object.prototype.hasOwnProperty.call(this._items, in_key);\n }\n\n /**\n * Return an item associated with the given key\n * @param in_key - the key for the item in this\n * Collection\n * @returns The item\n */\n item(in_key: number | string) {\n return this._items[in_key];\n }\n\n /**\n * Checks if this is a new key in the collection. Throw if already exists.\n * @param in_key - The key to check against\n * @returns true if key is new\n */\n private _checkIsNewKey(in_key: number | string) {\n if (this.has(in_key)) {\n throw new Error(`${MSGS.KEY_ALREADY_EXISTS} ${in_key}`);\n }\n\n return true;\n }\n\n /**\n * Checks if the key exists in the collection. Throw if not.\n * @param in_key - the key to check against\n * @returns true if key exists\n */\n private _checkKeyExists(in_key: number | string) {\n if (!this.has(in_key)) {\n throw new Error(`${MSGS.KEY_DOES_NOT_EXIST} ${in_key}`);\n }\n\n return true;\n }\n\n /**\n * Set an existing key to a value. If key doesn't exist this call will throw\n * an error.\n * @param in_key - the key we want to modify\n * @param in_value - the value we are to set at this key\n * @returns the value passed in\n */\n set(in_key: string, in_value: T) {\n this._checkKeyExists(in_key);\n\n this._items[in_key] = in_value;\n\n return in_value;\n }\n\n /**\n * Iterate over this collection and run the callback with passing the key and\n * item in the iteration loop.\n * @param in_callback - a function that we will call on each item\n * of this collection. If the callback returns false then the iteration will exit early.\n */\n iterate(in_callback) {\n for (const key of this._order) {\n const continu = in_callback(key, this._items[key]);\n if (continu === false) {\n break;\n }\n }\n }\n\n /**\n * Iterate over this collection starting from the tail and run the callback with passing the key and\n * item in the iteration loop.\n * @param in_callback - a function that we will call on each item\n * of this collection. If the callback returns false then the iteration will exit early.\n */\n iterateFromTail(in_callback) {\n let key; let continu;\n for (let i = this._order.length - 1; i >= 0; i--) {\n key = this._order[i];\n continu = in_callback(key, this._items[key]);\n if (continu === false) {\n break;\n }\n }\n }\n\n /**\n * @returns Return an object containing the items of this collection\n */\n getItems(): { [key: string]: T; } {\n const result = {};\n\n _.each(this._items, function(item, key) {\n result[key] = item;\n });\n\n return result;\n }\n\n /**\n * Return the list of keys\n * @returns List of keys\n */\n getKeys(): string[] {\n return Object.keys(this._items);\n }\n\n /**\n * Method used to get the first element in the collection along with its key.\n */\n peak() {\n return {\n item: this._items[this._order[0]],\n key: this._order[0],\n };\n }\n\n /**\n * Clear this collection\n * @returns this collection\n */\n clear() {\n if (_.isEmpty(this._items)) {\n return this;\n }\n\n this.onClear(this._items);\n\n // Best to just iterate through and remove everything, so that OnRemove\n // handlers are called.\n\n _.each(this.getKeys(), (key) => {\n this.remove(key);\n });\n\n return this;\n }\n\n /**\n * Copy the items of in_collection to this collection.\n * @param in_collection - the collection we want to\n * copy from.\n * @returns new Collection\n */\n clone(): Collection<T> {\n const newCol = new Collection<T>(this._name, this._type);\n newCol.bulkAdd(this._items);\n return newCol;\n }\n\n /**\n * Copy the items of in_collection to this collection.\n * @param in_collection - the collection we want to\n * copy from.\n */\n copy(in_collection: Collection<T>) {\n this.clear();\n const its = in_collection.items;\n\n _.each(its, (item, key) => {\n this.add(key, item);\n });\n }\n\n get values() {\n return this.getAsArray();\n }\n}\n"]}
@@ -50,7 +50,7 @@ export class HTTPError extends Error {
50
50
  const isFirefox = typeof window !== "undefined" &&
51
51
  typeof window.navigator !== "undefined" &&
52
52
  typeof window.navigator.userAgent !== "undefined" &&
53
- window.navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
53
+ window.navigator.userAgent.toLowerCase().includes("firefox");
54
54
  return isFirefox ? `${this.message}, stack:${stack}` : `stack:${stack}`;
55
55
  }
56
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"httpError.js","sourceRoot":"","sources":["../../src/error_objects/httpError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAChC,YACW,KAAc,EACd,UAAmB,EACnB,aAAsB,EACtB,MAAe,EACf,GAAY,EACZ,QAAQ,CAAC;QAEhB,KAAK,EAAE,CAAC;QAPD,UAAK,GAAL,KAAK,CAAS;QACd,eAAU,GAAV,UAAU,CAAS;QACnB,kBAAa,GAAb,aAAa,CAAS;QACtB,WAAM,GAAN,MAAM,CAAS;QACf,QAAG,GAAH,GAAG,CAAS;QACZ,UAAK,GAAL,KAAK,CAAI;QAGhB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,KA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Q;QACJ,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEnE,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW;YAC3C,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW;YACvC,OAAO,MAAM,CAAC,SAAS,CAAC,SAAS,KAAK,WAAW;YACjD,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QAErE,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC;IAC5E,CAAC;;AAlCM,eAAK,GAAG,YAAY,CAAC,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { FlaggedError } from \"./flaggedError\";\n\n/**\n * Class extending Error with HTTP-specific error information like statusCode and statusMessage\n * @param title - The error title\n * @param statusCode - A numeric HTTP status code\n * @param statusMessage - A string message representing the response status message\n * @param method - The HTTP method used in the request\n * @param url - The URL that the request was sent to\n * @param flags - Flags that characterize the error. See {@link FlaggedError.FLAGS}.\n */\nexport class HTTPError extends Error {\n constructor(\n public title?: string,\n public statusCode?: number,\n public statusMessage?: string,\n public method?: string,\n public url?: string,\n public flags = 0,\n ) {\n super();\n Object.setPrototypeOf(this, HTTPError.prototype);\n this.name = \"HTTPError\";\n this.message = this._generateMessage(title, statusCode, statusMessage, method, url);\n this.stack = (new Error(this.message)).stack;\n }\n\n static FLAGS = FlaggedError.FLAGS;\n\n isQuiet(): boolean {\n return FlaggedError.prototype.isQuiet.call(this);\n }\n\n isTransient(): boolean {\n return FlaggedError.prototype.isTransient.call(this);\n }\n\n private _generateMessage(title, statusCode, statusMessage, method, url) {\n const titleStr = (title === undefined) ? \"\" : String(title);\n const statusCodeStr = (statusCode === undefined) ? \"\" : String(statusCode);\n const statusMessageStr = (statusMessage === undefined) ? \"\" : String(statusMessage);\n const methodStr = (method === undefined) ? \"\" : String(method);\n const urlStr = (url === undefined) ? \"\" : String(url);\n\n return `HTTPError: ${titleStr}, statusCode:${statusCodeStr}, ` +\n `statusMessage:${statusMessageStr}, method:${methodStr}, url:${urlStr}`;\n }\n\n /**\n * Returns a string representing the HTTPError object\n * @returns a string representing the HTTPError object\n */\n toString(): string {\n const stack = (this.stack === undefined) ? \"\" : String(this.stack);\n\n const isFirefox = typeof window !== \"undefined\" &&\n typeof window.navigator !== \"undefined\" &&\n typeof window.navigator.userAgent !== \"undefined\" &&\n window.navigator.userAgent.toLowerCase().indexOf(\"firefox\") > -1;\n\n return isFirefox ? `${this.message}, stack:${stack}` : `stack:${stack}`;\n }\n}\n"]}
1
+ {"version":3,"file":"httpError.js","sourceRoot":"","sources":["../../src/error_objects/httpError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAChC,YACW,KAAc,EACd,UAAmB,EACnB,aAAsB,EACtB,MAAe,EACf,GAAY,EACZ,QAAQ,CAAC;QAEhB,KAAK,EAAE,CAAC;QAPD,UAAK,GAAL,KAAK,CAAS;QACd,eAAU,GAAV,UAAU,CAAS;QACnB,kBAAa,GAAb,aAAa,CAAS;QACtB,WAAM,GAAN,MAAM,CAAS;QACf,QAAG,GAAH,GAAG,CAAS;QACZ,UAAK,GAAL,KAAK,CAAI;QAGhB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,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;;OAGG;IACH,QAAQ;QACJ,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEnE,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW;YAC3C,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW;YACvC,OAAO,MAAM,CAAC,SAAS,CAAC,SAAS,KAAK,WAAW;YACjD,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAEjE,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC;IAC5E,CAAC;;AAlCM,eAAK,GAAG,YAAY,CAAC,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { FlaggedError } from \"./flaggedError\";\n\n/**\n * Class extending Error with HTTP-specific error information like statusCode and statusMessage\n * @param title - The error title\n * @param statusCode - A numeric HTTP status code\n * @param statusMessage - A string message representing the response status message\n * @param method - The HTTP method used in the request\n * @param url - The URL that the request was sent to\n * @param flags - Flags that characterize the error. See {@link FlaggedError.FLAGS}.\n */\nexport class HTTPError extends Error {\n constructor(\n public title?: string,\n public statusCode?: number,\n public statusMessage?: string,\n public method?: string,\n public url?: string,\n public flags = 0,\n ) {\n super();\n Object.setPrototypeOf(this, HTTPError.prototype);\n this.name = \"HTTPError\";\n this.message = this._generateMessage(title, statusCode, statusMessage, method, url);\n this.stack = (new Error(this.message)).stack;\n }\n\n static FLAGS = FlaggedError.FLAGS;\n\n isQuiet(): boolean {\n return FlaggedError.prototype.isQuiet.call(this);\n }\n\n isTransient(): boolean {\n return FlaggedError.prototype.isTransient.call(this);\n }\n\n private _generateMessage(title, statusCode, statusMessage, method, url) {\n const titleStr = (title === undefined) ? \"\" : String(title);\n const statusCodeStr = (statusCode === undefined) ? \"\" : String(statusCode);\n const statusMessageStr = (statusMessage === undefined) ? \"\" : String(statusMessage);\n const methodStr = (method === undefined) ? \"\" : String(method);\n const urlStr = (url === undefined) ? \"\" : String(url);\n\n return `HTTPError: ${titleStr}, statusCode:${statusCodeStr}, ` +\n `statusMessage:${statusMessageStr}, method:${methodStr}, url:${urlStr}`;\n }\n\n /**\n * Returns a string representing the HTTPError object\n * @returns a string representing the HTTPError object\n */\n toString(): string {\n const stack = (this.stack === undefined) ? \"\" : String(this.stack);\n\n const isFirefox = typeof window !== \"undefined\" &&\n typeof window.navigator !== \"undefined\" &&\n typeof window.navigator.userAgent !== \"undefined\" &&\n window.navigator.userAgent.toLowerCase().includes(\"firefox\");\n\n return isFirefox ? `${this.message}, stack:${stack}` : `stack:${stack}`;\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluid-experimental/property-common";
8
- export declare const pkgVersion = "0.59.3003";
8
+ export declare const pkgVersion = "0.59.4000";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluid-experimental/property-common";
8
- export const pkgVersion = "0.59.3003";
8
+ export const pkgVersion = "0.59.4000";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,qCAAqC,CAAC;AAC7D,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluid-experimental/property-common\";\nexport const pkgVersion = \"0.59.3003\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,qCAAqC,CAAC;AAC7D,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluid-experimental/property-common\";\nexport const pkgVersion = \"0.59.4000\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-experimental/property-common",
3
- "version": "0.59.3003",
3
+ "version": "0.59.4000",
4
4
  "description": "common functions used in properties",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -70,11 +70,11 @@
70
70
  "devDependencies": {
71
71
  "@fluidframework/build-common": "^0.23.0",
72
72
  "@fluidframework/eslint-config-fluid": "^0.28.2000",
73
- "@fluidframework/mocha-test-setup": "^0.59.3003",
73
+ "@fluidframework/mocha-test-setup": "^0.59.4000",
74
74
  "@microsoft/api-extractor": "^7.22.2",
75
75
  "@rushstack/eslint-config": "^2.5.1",
76
76
  "@types/debug": "^4.1.5",
77
- "@types/mocha": "^8.2.2",
77
+ "@types/mocha": "^9.1.1",
78
78
  "@types/node": "^14.18.0",
79
79
  "@typescript-eslint/eslint-plugin": "~5.9.0",
80
80
  "@typescript-eslint/parser": "~5.9.0",
@@ -87,12 +87,14 @@
87
87
  "eslint-plugin-eslint-comments": "~3.2.0",
88
88
  "eslint-plugin-import": "~2.25.4",
89
89
  "eslint-plugin-jest": "~26.1.3",
90
+ "eslint-plugin-jsdoc": "~39.3.0",
90
91
  "eslint-plugin-mocha": "~10.0.3",
91
92
  "eslint-plugin-promise": "~6.0.0",
92
93
  "eslint-plugin-react": "~7.28.0",
93
94
  "eslint-plugin-tsdoc": "~0.2.14",
94
95
  "eslint-plugin-unicorn": "~40.0.0",
95
- "mocha": "^8.4.0",
96
+ "eslint-plugin-unused-imports": "~2.0.0",
97
+ "mocha": "^10.0.0",
96
98
  "nock": "^10.0.1",
97
99
  "nyc": "^15.0.0",
98
100
  "rimraf": "^2.6.2",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-internal/platform-dependent",
3
- "version": "0.59.3003",
3
+ "version": "0.59.4000",
4
4
  "private": true,
5
5
  "description": "Helper package that separates code for browser and server.",
6
6
  "homepage": "https://fluidframework.com",
@@ -175,7 +175,7 @@ export class Collection<T> {
175
175
 
176
176
  if (_.isArray(in_filterKey)) {
177
177
  filterCb = function(in_key, in_item) {
178
- if (in_filterKey.indexOf(in_key) >= 0) {
178
+ if (in_filterKey.includes(in_key)) {
179
179
  rtn.add(in_key, in_item);
180
180
  }
181
181
  };
@@ -60,7 +60,7 @@ export class HTTPError extends Error {
60
60
  const isFirefox = typeof window !== "undefined" &&
61
61
  typeof window.navigator !== "undefined" &&
62
62
  typeof window.navigator.userAgent !== "undefined" &&
63
- window.navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
63
+ window.navigator.userAgent.toLowerCase().includes("firefox");
64
64
 
65
65
  return isFirefox ? `${this.message}, stack:${stack}` : `stack:${stack}`;
66
66
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluid-experimental/property-common";
9
- export const pkgVersion = "0.59.3003";
9
+ export const pkgVersion = "0.59.4000";