How can i bind this?

const StorageManager = require("xyz");

const { Storage } = new StorageManager(config)

Storage({
  path: 'test'
})

I have this code to bind, Storage() function can accept any object
i have tried this binding:

type fnType<'a> = 'a => T.t
type initReturn = {"Storage": fnType<'a>}
@new @module external init: folderOptions => initReturn = "xye"

let folder = init({
  redis: {
    prefix: "storage:file:",
    password: Env.redis_password,
    ip: Env.redis_ip,
  },
})["Storage"]

But it give me the error "Unbound type parameter 'a "

How can i make this work,keeping Storage() function accepting any parameter?

Not sure I fully follow what you’re after, but here’s an example:

module Storage = {
  // TODO: Fill in
  type t = unit
}

module StorageManager = {
  type t

  type redisConfig = {prefix?: string, password?: string, ip?: string}
  type config = {redis?: redisConfig}

  @new @module("xyz")
  external make: config => t = "default"

  @send external storage: (t, {..}) => Storage.t = "Storage"
}

let storageManager = StorageManager.make({
  redis: {prefix: "storage:file:", password: "password", ip: "ip"},
})

storageManager->StorageManager.storage({"path": "test"})

Compiles to:

// Generated by ReScript, PLEASE EDIT WITH CARE

import Xyz from "xyz";

var $$Storage = {};

var StorageManager = {};

var storageManager = new Xyz({
      redis: {
        prefix: "storage:file:",
        password: "password",
        ip: "ip"
      }
    });

storageManager.Storage({
      path: "test"
    });

export {
  $$Storage ,
  StorageManager ,
  storageManager ,
}
/* storageManager Not a pure module */

Playground link: ReScript Playground

2 Likes