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

Typescript support? #11

Open
webriq opened this issue May 24, 2022 · 25 comments
Open

Typescript support? #11

webriq opened this issue May 24, 2022 · 25 comments
Labels
enhancement New feature or request

Comments

@webriq
Copy link

webriq commented May 24, 2022

No description provided.

@ericingram
Copy link
Contributor

Hi @webriq - this is something the team is working on with the next major version, but no precise ETA yet

@joshuaberube
Copy link

Hey there, just bumping this with the same question– any ETA now that its been a few weeks?

@stafyniaksacha
Copy link

stafyniaksacha commented Aug 3, 2022

This should work as a workaround:

// types/swell-node.d.ts
import EventEmitter from "node:events"

declare module 'swell-node' {
  type Callback<D, T> = (error: unknown, data?: D, response?: T) => void | Promise<void>
  interface SwellNodeClientParams {
    clientId?: string,
    clientKey?: string,
    host?: string,
    port?: string,
    verifyCert?: boolean,
    version?: string,
    session?: any,
    route?: any,
    timeout?: number,
    routeClientId?: string,
    cache?: boolean,
    debug?: boolean,
  }
  interface SwellNodeClient extends EventEmitter {
    params: any
    server: any
    cache: any
    authed: boolean

    new (clientId: string, clientKey: string, options?: SwellNodeClientParams, callback?: (arg: this) => void | Promise<void>): SwellNodeClient
    static create (clientId: string, clientKey: string, options?: SwellNodeClientParams, callback?: (arg: this) => void | Promise<void>): SwellNodeClient
    init(clientId: string, clientKey: string, options?: SwellNodeClientParams): SwellNodeClient
    connect(callback: (arg: this) => void | Promise<void>): void
    request<T = any>(method: string, url: string, data?: any): Promise<T>
    get<T = any>(url: string, data?: any): Promise<T>
    post<T = any>(url: string, data?: any): Promise<T>
    put<T = any>(url: string, data?: any): Promise<T>
    delete<T = any>(url: string, data?: any): Promise<T>
  }

  export function createClient(
    clientId: string, 
    clientKey: string, 
    options?: SwellNodeClientParams, 
    callback?: (arg: this) => void
  ): SwellNodeClient
}

usage:

import { createClient } from 'swell-node'
const swell = createClient() 

@matthewlynch
Copy link

For anyone getting an error similar to error TS7016: Could not find a declaration file for module 'swell-node'. when you've included @stafyniaksacha suggested file in your compilerOptions.typeRoots.

I had to move the EventEmitter import inside of the module declaration like this:

// types/index.d.ts
declare module "swell-node" {
  import EventEmitter from "node:events";

  type Callback<D, T> = (
    error: unknown,
    data?: D,
    response?: T
  ) => void | Promise<void>;

  interface SwellNodeClientParams {
    clientId?: string;
    clientKey?: string;
    host?: string;
    port?: string;
    verifyCert?: boolean;
    version?: string;
    session?: any;
    route?: any;
    timeout?: number;
    routeClientId?: string;
    cache?: boolean;
    debug?: boolean;
  }

  interface SwellNodeClient extends EventEmitter {
    params: any;
    server: any;
    cache: any;
    authed: boolean;

    new (
      clientId: string,
      clientKey: string,
      options?: SwellNodeClientParams,
      callback?: (arg: this) => void | Promise<void>
    ): SwellNodeClient;
    create(
      clientId: string,
      clientKey: string,
      options?: SwellNodeClientParams,
      callback?: (arg: this) => void | Promise<void>
    ): SwellNodeClient;
    init(
      clientId: string,
      clientKey: string,
      options?: SwellNodeClientParams
    ): SwellNodeClient;
    connect(callback: (arg: this) => void | Promise<void>): void;
    request<T = any>(method: string, url: string, data?: any): Promise<T>;
    get<T = any>(url: string, data?: any): Promise<T>;
    post<T = any>(url: string, data?: any): Promise<T>;
    put<T = any>(url: string, data?: any): Promise<T>;
    delete<T = any>(url: string, data?: any): Promise<T>;
  }

  export function createClient(
    clientId: string,
    clientKey: string,
    options?: SwellNodeClientParams,
    callback?: (arg: this) => void
  ): SwellNodeClient;
}

@logeshswell logeshswell added the enhancement New feature or request label Sep 27, 2022
@vettloffah
Copy link

What's up with swell? Are they doing ok? Every time I find a thread with Swell saying they are working on something, there is no follow up several months later. Is typescript support really an "enhancement" in almost 2023?

@ericingram
Copy link
Contributor

A lot of competing priorities, but this one is now being worked on actively!

@vettloffah
Copy link

vettloffah commented Nov 22, 2022

To implement the above while using the swell.init() function I had to add it as an exported function in the declaration file:

// ...
export function init(
      clientId: string,
      clientKey: string,
      options?: SwellNodeClientParams
  ): SwellNodeClient;
// ...

@kasperaamodt
Copy link

Anything happening here? It's been months...

@nllewellyn12
Copy link

Its been a few more months now... Pleaseeeeee give us TS support

@ericingram
Copy link
Contributor

We started developing a new version of Swell.js with typescript late last year, but had to shift priorities. There were a bunch of improvements in the process however including full TS support using GraphQL.

No ETA as of right now

@MoSattler
Copy link

Thats a shame! We're looking for a tool to outsource or cart experience, but not having TS is a deal breaker.

@vettloffah
Copy link

It has really caused a lot of headaches not having typescript support. Especially since the data models vary between front end and back end. I understand swell has been working on other features like an app marketplace but for those of us trying to run a business on swell, the core infrastructure should really be a priority. Including API reliability, speed, typescript support etc.

@MoSattler
Copy link

MoSattler commented Sep 27, 2023

I was considering to guard the api calls with Zod, but it's just too much of a hassle, unfortunately.

The backend API doesn't support GQL neither, right?

@johnrisby
Copy link

johnrisby commented Oct 17, 2023

Is there any progress at all - and an ETA - on typescript support for swell-node ? It really is a basic requirement. Thanks

@ericingram
Copy link
Contributor

It’s not a focus internally right now as the SDKs need to be refactored generally

@johnrisby
Copy link

It’s not a focus internally right now as the SDKs need to be refactored generally

And there's nothing internally you use that could be released, even with a warning that it's not complete etc? Even just as a base to work from? Thanks Eric.

@vaneworks
Copy link

Is this library dead or something? Last comment on this issue was around a year ago and apparently Typescript support is not a major priority in an age where TS support is almost mandatory for the NextJS/Vercel metagame.

"Not a focus internally" is a bad business move because poor DX means I find another library/service that gives me the safety I want without a workaround.

@ericingram
Copy link
Contributor

This is not in wide use currently as most developers have preferred to build their own HTTP handlers. We even started using a different repo for internal services: https://github.com/swellstores/swell-node-http

I do think we'll eventually get back to building a first-class backend node library, but it's not critical right now since there are many other ways to work with the Swell API.

@MoSattler
Copy link

Just a single data point, but FWIW It's the reason why we dropped swell altogether.

@vaneworks
Copy link

You do know the trend right now is to fetch on the server then pass to client right? I don't know what could be more critical for increasing usage of your platform other than to work on a client using preferred way of fetching data with javascript right now.

I'll be dropping this too as it will hard to debug later if the platform API changes due to a lack of type safety.

@vettloffah
Copy link

vettloffah commented Oct 2, 2024 via email

@ericingram
Copy link
Contributor

@MoSattler @vaneworks @vettloffah We just now updated the implementation of this library to use HTTP instead of our TCP wire protocol (essentially swapped with https://github.com/swellstores/swell-node-http). The library itself now uses Typescript, but if you're looking for TS types on API results (models) then it's not quite there yet. The issue is that each store can have its own models so we need to implement a type generation step, which is tricky and wouldn't be internally prioritized for some time.

@MoSattler
Copy link

Hey @ericingram, thanks for the update!

Unfortunately, we had to move away from Swell due to the lack of TypeScript support, which was a key requirement for us.

@vettloffah
Copy link

vettloffah commented Oct 24, 2024 via email

@ericingram
Copy link
Contributor

@vettloffah makes sense, that's what we'll do. We actually had a working version of TS typegen internally a while ago but it never got released. I'll look to see if it's something we could add soon.

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

No branches or pull requests