fauna / fauna-js

Javascript driver for Fauna v10 (current)
https://fauna.com
Other
37 stars 7 forks source link

Add encoding/decoding for Fauna Bytes #260

Closed ptpaterson closed 6 months ago

ptpaterson commented 7 months ago

Ticket(s): FE-4855

Problem

Fauna supports a Bytes type which is transmitted as a base-64-encoded string https://docs.fauna.com/fauna/current/reference/fql_reference/types#bytes

We also had a type issue where JS Date could not be used as a query argument, so I added Date to arg type as well as a test.

Solution

Add encoding and decoding of the Bytes type

Result

ArrayBuffers and Uint8Array (as well as Node's Buffer since that extends Uint8Array) classes are encoded to Fauna Bytes. Attempting to encode any other TypedArray results in an error.

Fauna Bytes are decoded into Uint8Array, which can be used to create the desired type.

See tests for examples.

Out of scope

N/A

Testing

Added unit and integration tests.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.