()
| 3 | import { collectionSchema } from './utils/model'; |
| 4 | |
| 5 | export async function init() { |
| 6 | try { |
| 7 | await client.collections().create(collectionSchema); |
| 8 | } catch (error: any) { |
| 9 | if (error.name === 'ObjectAlreadyExists' || error.httpStatus === 409) { |
| 10 | console.error({ error: JSON.stringify(error) }); |
| 11 | } else { |
| 12 | if (error.message === 'connect ECONNREFUSED 127.0.0.1:8108') { |
| 13 | console.log('-----------------------'); |
| 14 | console.log( |
| 15 | 'Please ensure that you have a typesense server running at port 8108' |
| 16 | ); |
| 17 | console.log( |
| 18 | 'Step 1. Find out how to install typesense locally from their docs.' |
| 19 | ); |
| 20 | console.log( |
| 21 | 'Step 2. Then run the following command, choose your own data dir.' |
| 22 | ); |
| 23 | console.log( |
| 24 | './typesense-server --data-dir=/MyDataDir --api-key=xyz --api-port=8108' |
| 25 | ); |
| 26 | console.log('-----------------------'); |
| 27 | } |
| 28 | throw error; |
| 29 | } |
| 30 | } |
| 31 | return await createSearchOnlyKey(collectionSchema.name); |
| 32 | } |
| 33 | |
| 34 | if (require.main === module) { |
| 35 | init().then((key) => { |
no test coverage detected