Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typesense module for Deno #95

Open
Sembiance opened this issue Dec 28, 2021 · 3 comments
Open

typesense module for Deno #95

Sembiance opened this issue Dec 28, 2021 · 3 comments

Comments

@Sembiance
Copy link

It would be awesome if there was a Deno compatible typesense module.

You can almost directly import * as Typsense from src/Typesense.ts but there are some issue:

  • Deno requires all local imports to have explict .ts extensions
    So instead of import ApiCall from './ApiCall' use import ApiCall from './ApiCall.ts'
    Also Errors, instead of import { ObjectNotFound } from './Errors' use import { ObjectNotFound } from './Errors/ObjectNotFound.ts'

  • Keys.ts needs modified to use the hmac and base64 modules from Deno:
    Change: import { createHmac } from 'crypto' to

import {hmac} from "https://deno.land/x/[email protected]/mod.ts";
import {encode as base64Encode} from "https://deno.land/[email protected]/encoding/base64.ts"

And change lines

const digest = Buffer.from(createHmac('sha256', searchKey).update(paramsJSON).digest('base64'))
return Buffer.from(rawScopedKey).toString('base64')

to

const digest = hmac("sha256", searchKey, paramsJSON, "utf8", "base64")
return base64Encode(rawScopedKey);
  • Configuration.js needs a loglevel replacement. I just used a stub:
this.logger =
{
	trace : v => console.log(v),
	debug : v => console.log(v),
	info : v => console.info(v),
	warn : v => console.warn(v),
	error : v => console.error(v),
	log : v => console.log(v),
	setLevel : () => {}
}

This is where I gave up because there are at least 3 remaining issues:

  • Documents.ts needs a ReadStream Deno equilivant

  • All of axios needs replaced in ApiCall.ts Maybe you could use the Deno version https://github.com/roonie007/axiod but much more ideally you could use the built in Deno fetch support

  • Lastly, there may be other 'nodejs' specific APIs being used in the code that I didn't look for

@jasonbosco
Copy link
Member

Thank you for the initial exploration @Sembiance!

CC: @harisarang since you also mentioned you were interested in exploring a Deno version of the library. I'll intro you both in our Slack community to potentially collaborate.

@bradenmacdonald
Copy link

bradenmacdonald commented Jan 28, 2022

@Sembiance I needed a TypeSense Deno client, so I implemented one this week: https://github.com/bradenmacdonald/typesense-deno

Thanks a lot for the research you put in this thread, it saved me some time! If you're curious about the exact changes it took, you can see them in this commit

My use case is fairly limited (indexing documents and generating restricted API keys), so I haven't tested it thoroughly but the parts I am using are working well.

@jasonbosco Let me know if you'd like to move it to the typesense org on GitHub or change it in any way. I'd also like to publish it on https://deno.land/x since that's where most Deno users would look for something like this.

It's also possible to do work to have one version of the code that compiles out to work for either Node or Deno (as I have done with e.g. the Neo4j JavaScript driver), but that can be more work and I think a separate deno-optimized version is preferable in this case :)

@muhaimincs
Copy link

Any new version for 2024?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants