Skip to content

A fork of typesense-js, with parts of it changed to be compatible with Deno.

License

Notifications You must be signed in to change notification settings

bradenmacdonald/typesense-deno

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeSense-deno

This is a fork of typesense-js, with parts of it changed to be compatible with Deno.

It's based on typesense-js 1.1.3, and has mostly the same API. Refer to the TypeSense documentation for details.

Not implemented:

  • exportStream
  • delete(id: string) (but delete(query: DeleteQuery) is implemented)

Usage example

In typesense-client.ts:

import { Client, Errors, SearchClient } from "https://raw.githubusercontent.com/bradenmacdonald/typesense-deno/v1.1.3-deno/mod.ts";

// Use a promise to initialize the client as needed, rather than at import time.
let clientPromise: Promise<Client> | undefined;

export function getTypeSenseClient(): Promise<Client> {
    if (clientPromise === undefined) {
        clientPromise = new Promise((resolve) => {
            const client = new Client({
                nodes: [{
                    host: "localhost",
                    port: "8108",
                    protocol: "http",
                }],
                apiKey: "setme",
                connectionTimeoutSeconds: 2,
            });
            resolve(client);
        });
    }
    return clientPromise;
}

In your other files:

import { getTypeSenseClient } from "./typesense-client.ts";
const client = await getTypeSenseClient();
client.collections().create({ ... });

About

A fork of typesense-js, with parts of it changed to be compatible with Deno.

Resources

License

Stars

Watchers

Forks

Packages

No packages published