typesense / typesense-js

JavaScript / TypeScript client for Typesense
https://typesense.org/docs/api
Apache License 2.0
393 stars 74 forks source link

Import with empty array fails #188

Open davideaimar opened 8 months ago

davideaimar commented 8 months ago

Description

Calling the import function with an empty array fails.

Steps to reproduce

Initialize a collection and try to call import with an empty array:

const documents = [];

return await tsClient
  .collections<T>('testcollection')
  .documents()
  .import(documents); // this fails

Expected Behavior

It doesn't fail.

Actual Behavior

It fails with this error:

/Users/<path-to-project>/node_modules/typesense/src/Typesense/Documents.ts:342
        .map((r) => JSON.parse(r)) as ImportResponse[];
         ^
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at /Users/<path-to-project>/node_modules/typesense/src/Typesense/Documents.ts:342:26
    at Array.map (<anonymous>)
    at Documents.<anonymous> (/Users/<path-to-project>/node_modules/typesense/src/Typesense/Documents.ts:342:10)
    at step (/Users/<path-to-project>/node_modules/typesense/lib/Typesense/Documents.js:48:23)
    at Object.next (/Users/<path-to-project>/node_modules/typesense/lib/Typesense/Documents.js:29:53)
    at fulfilled (/Users/<path-to-project>/node_modules/typesense/lib/Typesense/Documents.js:20:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Metadata

Typesense Version: 0.25.1

OS: Run in Docker