From b6ef7ef6850f0d8ad8d20d6ef3f60bb70e7b1705 Mon Sep 17 00:00:00 2001 From: Michael Mitchell Date: Sun, 31 Oct 2021 16:03:21 +1100 Subject: [PATCH] refactor: remove custom inspection --- README.md | 19 +++++++++---------- redite.d.ts | 2 -- src/Redite.js | 22 ---------------------- test/other.test.js | 35 ----------------------------------- 4 files changed, 9 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 78022ce..b5cd1c6 100644 --- a/README.md +++ b/README.md @@ -87,16 +87,15 @@ console.log(me.email); // Ovyerus@users.noreply.github.com `new Redite([options])` -| Name | Type | Default | Description | -| ----------------------------- | ------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------- | -| options.client | ioredis.Redis | `new Redis(options.url)` | The Redis connection to piggyback off of. | -| options.url | String | | The Redis URL to use for the automatically created connection. Not used if a client is passed. | -| options.serialise | Function | `JSON.stringify` | Function that takes in a JS object and returns a string that can be sent to Redis. | -| options.parse | Function | `JSON.parse` | Function that takes in a string and returns the JS object that it represents. | -| options.deletedString | String | `@__DELETED__@` | String to use as a temporary placeholder when deleting root indexes in a list. | -| options.unref | Boolean | `true` | Whether to run `.unref` on the Redis client, which allows Node to exit if the connection is idle. | -| options.customInspection | Boolean | `false` | Whether to use a custom inspection for the Redis URL and Redis connection to hide potentially sensitive data. | -| options.ignoreUndefinedValues | Boolean | `false` | Whether to ignore `undefined` as a base value when setting values. | +| Name | Type | Default | Description | +| ----------------------------- | ------------- | ------------------------ | ------------------------------------------------------------------------------------------------- | +| options.client | ioredis.Redis | `new Redis(options.url)` | The Redis connection to piggyback off of. | +| options.url | String | | The Redis URL to use for the automatically created connection. Not used if a client is passed. | +| options.serialise | Function | `JSON.stringify` | Function that takes in a JS object and returns a string that can be sent to Redis. | +| options.parse | Function | `JSON.parse` | Function that takes in a string and returns the JS object that it represents. | +| options.deletedString | String | `@__DELETED__@` | String to use as a temporary placeholder when deleting root indexes in a list. | +| options.unref | Boolean | `true` | Whether to run `.unref` on the Redis client, which allows Node to exit if the connection is idle. | +| options.ignoreUndefinedValues | Boolean | `false` | Whether to ignore `undefined` as a base value when setting values. | #### **Accessing Objects** diff --git a/redite.d.ts b/redite.d.ts index d603316..bf42abc 100644 --- a/redite.d.ts +++ b/redite.d.ts @@ -33,7 +33,6 @@ interface RediteOptions { serialise?: (value: any) => string; parse?: (value: string) => any; deletedString?: string; - customInspection?: boolean; ignoreUndefinedValues?: boolean; } @@ -102,7 +101,6 @@ declare namespace r { $serialise: (value: any) => string; $parse: (value: string) => any; $deletedString: string; - $customInspection: boolean; $ignoreUndefinedValues: boolean; constructor(options?: RediteOptions); diff --git a/src/Redite.js b/src/Redite.js index 483e318..eb12257 100644 --- a/src/Redite.js +++ b/src/Redite.js @@ -1,7 +1,5 @@ const Redis = require("ioredis"); -const util = require("util"); - const ChildWrapper = require("./ChildWrapper"); const { NonMutatingMethods, SupportedArrayMethods } = require("./Constants"); @@ -27,7 +25,6 @@ function genTree(stack) { * @prop {Function} $parse Data parser function. * @prop {String} $deletedString Temporary string used when deleting items from a list. * @prop {Boolean} $ignoreUndefinedValues Whether to ignore `undefined` when setting values. - * @prop {Boolean} $customInspection Whether to give a custom object for `util.inspect`. */ class Redite { constructor(options = {}) { @@ -36,7 +33,6 @@ class Redite { this.$parse = options.parse || JSON.parse; this.$deletedString = options.deletedString || "@__DELETED__@"; this.$ignoreUndefinedValues = options.ignoreUndefinedValues || false; - this.$customInspection = options.customInspection || false; // (https://stackoverflow.com/a/40714458/8778928) // eslint-disable-next-line no-constructor-return @@ -75,24 +71,6 @@ class Redite { }); } - [util.inspect.custom]() { - if (!this.$customInspection) return this; - else { - const scope = this; - - return new (class Redite { - constructor() { - this.$redis = ""; - this.$serialise = scope.$serialise; - this.$parse = scope.$parse; - this.$deletedString = scope.$deletedString; - this.$customInspection = scope.$customInspection; - this.$ignoreUndefinedValues = scope.$ignoreUndefinedValues; - } - })(); - } - } - /** * Get an object from Redis. * You should probably get an object through a simulated object tree. diff --git a/test/other.test.js b/test/other.test.js index 16790df..3d6bcb2 100644 --- a/test/other.test.js +++ b/test/other.test.js @@ -2,10 +2,6 @@ const Redis = require("ioredis"); -const { - inspect: { custom }, -} = require("util"); - const Redite = require("../"); const { redisUrl, TestHash } = require("./lib/consts"); @@ -13,7 +9,6 @@ const { redisUrl, TestHash } = require("./lib/consts"); const client = new Redis(redisUrl); const wrapper = new Redite({ client, - customInspection: true, ignoreUndefinedValues: true, }); @@ -31,7 +26,6 @@ describe("Extra coverage", () => { expect(db.$serialise).toBe(JSON.stringify); expect(db.$parse).toBe(JSON.parse); expect(db.$deletedString).toBe("@__DELETED__@"); - expect(db.$customInspection).toBe(false); expect(db.$ignoreUndefinedValues).toBe(false); db.$redis.disconnect(); @@ -103,33 +97,4 @@ describe("Extra coverage", () => { ); }); }); - - describe("Custom inspection", () => { - it("should be a function", () => { - expect(wrapper[custom]).toBeInstanceOf(Function); - }); - - it("should return a new class called `Redite`", () => { - expect(wrapper[custom]().constructor.name).toBe("Redite"); - }); - - it('should have regular values, with `redis` set to ""', () => { - const res = wrapper[custom](); - - expect(res.$redis).toBe(""); - expect(res.$serialise).toBe(wrapper.$serialise); - expect(res.$parse).toBe(wrapper.$parse); - expect(res.$deletedString).toBe(wrapper.$deletedString); - expect(res.$customInspection).toBe(wrapper.$customInspection); - expect(res.$ignoreUndefinedValues).toBe(wrapper.$ignoreUndefinedValues); - }); - - it("should return the regular Redite instance if disabled", () => { - const db = new Redite(); - - expect(db[custom]()).toBe(db); - - db.$redis.disconnect(); - }); - }); });