@@ -568,6 +568,8 @@ const createAttribute = (databaseId, collectionId, attribute) => {
568568 onDelete: attribute.onDelete,
569569 parseOutput: false
570570 })
571+ default:
572+ throw new Error(`Unsupported attribute type: ${attribute.type}`);
571573 }
572574}
573575
@@ -685,6 +687,8 @@ const updateAttribute = (databaseId, collectionId, attribute) => {
685687 onDelete: attribute.onDelete,
686688 parseOutput: false
687689 })
690+ default:
691+ throw new Error(`Unsupported attribute type: ${attribute.type}`);
688692 }
689693}
690694const deleteAttribute = async (collection, attribute, isIndex = false) => {
@@ -708,6 +712,33 @@ const deleteAttribute = async (collection, attribute, isIndex = false) => {
708712 });
709713}
710714
715+ const isEqual = (a, b) => {
716+ if (a === b) return true;
717+
718+ if (a && b && typeof a === 'object' && typeof b === 'object') {
719+ if (a.constructor && a.constructor.name === 'BigNumber' &&
720+ b.constructor && b.constructor.name === 'BigNumber') {
721+ return a.eq(b);
722+ }
723+
724+ if (typeof a.equals === 'function') {
725+ return a.equals(b);
726+ }
727+
728+ if (typeof a.eq === 'function') {
729+ return a.eq(b);
730+ }
731+ }
732+
733+ if (typeof a === 'number' && typeof b === 'number') {
734+ if (isNaN(a) && isNaN(b)) return true;
735+ if (!isFinite(a) && !isFinite(b)) return a === b;
736+ return Math.abs(a - b) < Number.EPSILON;
737+ }
738+
739+ return false;
740+ };
741+
711742const compareAttribute = (remote, local, reason, key) => {
712743 if (isEmpty(remote) && isEmpty(local)) {
713744 return reason;
@@ -718,7 +749,7 @@ const compareAttribute = (remote, local, reason, key) => {
718749 const bol = reason === '' ? '' : '\n';
719750 reason += `${bol}${key} changed from ${chalk.red(remote)} to ${chalk.green(local)}`;
720751 }
721- } else if (remote !== local) {
752+ } else if (!isEqual( remote, local) ) {
722753 const bol = reason === '' ? '' : '\n';
723754 reason += `${bol}${key} changed from ${chalk.red(remote)} to ${chalk.green(local)}`;
724755 }
@@ -733,16 +764,16 @@ const compareAttribute = (remote, local, reason, key) => {
733764 * @param remote
734765 * @param local
735766 * @param collection
736- * @param recraeting when true will check only non-changeable keys
767+ * @param recreating when true will check only non-changeable keys
737768 * @returns {undefined|{reason: string, action: *, attribute, key: string}}
738769 */
739- const checkAttributeChanges = (remote, local, collection, recraeting = true) => {
770+ const checkAttributeChanges = (remote, local, collection, recreating = true) => {
740771 if (local === undefined) {
741772 return undefined;
742773 }
743774
744775 const keyName = `${chalk.yellow(local.key)} in ${collection.name} (${collection['$id']})`;
745- const action = chalk.cyan(recraeting ? 'recreating' : 'changing');
776+ const action = chalk.cyan(recreating ? 'recreating' : 'changing');
746777 let reason = '';
747778 let attribute = remote;
748779
@@ -752,17 +783,17 @@ const checkAttributeChanges = (remote, local, collection, recraeting = true) =>
752783 }
753784
754785 if (changeableKeys.includes(key)) {
755- if (!recraeting ) {
756- reason + = compareAttribute(remote[key], local[key], reason, key)
786+ if (!recreating ) {
787+ reason = compareAttribute(remote[key], local[key], reason, key)
757788 }
758789 continue;
759790 }
760791
761- if (!recraeting ) {
792+ if (!recreating ) {
762793 continue;
763794 }
764795
765- reason + = compareAttribute(remote[key], local[key], reason, key)
796+ reason = compareAttribute(remote[key], local[key], reason, key)
766797 }
767798
768799 return reason === '' ? undefined : { key: keyName, attribute, reason, action };
0 commit comments