Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ function isEmptyObject<T>(obj: T | EmptyValue): obj is EmptyValue {
// Mostly copied from https://medium.com/@lubaka.a/how-to-remove-lodash-performance-improvement-b306669ad0e1

/**
* Checks whether the given value can be merged. It has to be an object, but not an array, RegExp or Date.
* Checks whether the given value can be merged. It has to be an object, but not an array, RegExp, Date or Blob.
*/
function isMergeableObject(value: unknown): value is Record<string, unknown> {
const isNonNullObject = value != null ? typeof value === 'object' : false;
return isNonNullObject && !(value instanceof RegExp) && !(value instanceof Date) && !Array.isArray(value);
return isNonNullObject && !(value instanceof RegExp) && !(value instanceof Date) && !(value instanceof Blob) && !Array.isArray(value);
}

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ function fastMerge<TValue>(target: TValue, source: TValue, shouldRemoveNestedNul

/** Deep removes the nested null values from the given value. */
function removeNestedNullValues<TValue extends OnyxInput<OnyxKey> | null>(value: TValue): TValue {
if (typeof value === 'object' && !Array.isArray(value)) {
if (isMergeableObject(value)) {
const objectValue = value as Record<string, unknown>;
return fastMerge(objectValue, objectValue) as TValue;
}
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/onyxBlobTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type {Connection} from '../../lib';
import Onyx from '../../lib/Onyx';

// Define test keys
const ONYX_KEYS = {
TEST_BLOB: 'testBlob',
};

describe('Onyx Blob Handling', () => {
let connection: Connection | undefined;

afterEach(() => {
if (connection) {
Onyx.disconnect(connection);
}
return Onyx.clear();
});

it('should store and retrieve a Blob with the correct content', async () => {
// Define the test content
const blobTestContent = 'test blob content';
let testBlobValue: unknown;

// Create a test Blob with the expected content
const testBlob = new Blob([blobTestContent], {type: 'text/plain'});

// Connect to the test key
connection = Onyx.connect({
key: ONYX_KEYS.TEST_BLOB,
initWithStoredValues: false,
callback: (value) => {
testBlobValue = value;
},
});

// Set the Blob value
await Onyx.set(ONYX_KEYS.TEST_BLOB, testBlob);

// Verify that the value is an instance of Blob
expect(testBlobValue instanceof Blob).toBeTruthy();
});
});