3box-js icon indicating copy to clipboard operation
3box-js copied to clipboard

Missing TypeScript definitions

Open tibetsprague opened this issue 7 years ago • 6 comments
trafficstars

Would love to see TypeScript definitions for this project.

tibetsprague avatar Oct 26 '18 21:10 tibetsprague

Any update on this? Happy to help out anyway I can!

eshohet avatar Feb 24 '20 17:02 eshohet

Hey @eshohet No progress on this yet. Would be awesome if you wanted to help out! What do you need? :)

oed avatar Feb 27 '20 09:02 oed

We've got some partial typings, but it'd be much nicer if it was a bit more strict in the sense that I could know the return type of, for example, space.private.get(key). Right now it's just string, object or undefined but if could be of a template type then static code analysis for ts would work way better.

// TODO: specify templates to make things easier

declare module '3box' {
    declare interface Space {
        private: BoxPrivate;
        syncDone: () => Promise<void>;
    }
    interface BoxPrivate {
        get: (key: string, opts?: any) => Promise<string | object | undefined>;
        set: (key: string, value: string) => Promise<boolean>;
        remove: (key: string) => Promise<boolean>;
    }
    interface BoxVerified {
        Verified: () => BoxVerified;
        DID: () => string;
        github: () => any;
        addGithub: (gistUrl: string) => any;
        twitter: () => any;
        addTwitter: (claim: string) => any;
        email: () => any;
        addEmail: (claim: string) => any;
    }

    interface BoxThreadOpts_getPosts {
        gt?: string;
        gte?: string;
        lt?: string;
        lte?: string;
        limit?: number;
        reverse?: boolean;
    }

    interface BoxThread {
        BoxThread: () => BoxThread;
        post: (message: string) => string;
        getPosts: (opts?: BoxThreadOpts_getPosts) => Array<any>;
        onNewPost: (newPostFn: () => undefined) => undefined;
    }

    interface BoxSpaceOpts_joinThread {
        noAutoSub?: boolean;
    }

    interface BoxSpace {
        public: BoxKeyValueStore;
        private: BoxKeyValueStore;
        joinThread: (name: string, opts?: BoxSpaceOpts_joinThread) => BoxThread;
        subscribeThread: (name: string) => undefined;
        unsubscribeThread: (name: string) => undefined;
        subscribedThreads: () => Array<string>;
        BoxSpace: () => BoxSpace;
    }

    interface BoxKeyValueStore {
        BoxKeyValueStore: () => BoxKeyValueStore;
        log: Array<any>;
        get: (key: any) => any;
        getMetadata: (key: any) => BoxKeyValueStoreMetadata | undefined;
        set: (key: any, value: any) => boolean;
        remove: (key: any) => boolean;
    }

    class BoxStaticIdUtils {
        verifyClaim: () => any;
        isMuportDID: (address: any) => any | boolean;
        isClaim: (claim: any, opts: any) => Promise<boolean>;
    }

    interface BoxObjectOpts_OpenSpace {
        consentCallback?: () => any;
        onSyncDone?: () => any;
    }

    interface BoxObjectOpts_GetProfile {
        addressServer?: string;
        ipfs?: any; //ipfs object
        useCacheService?: boolean;
        profileServer?: string;
    }

    interface BoxObjectOpts_GetProfiles {
        profileServer?: string;
    }

    interface BoxObjectOpts_GetSpace {
        profileServer?: string;
        metadata?: string;
    }

    interface BoxObjectOpts_GetThread {
        profileServer?: string;
    }

    interface BoxObjectOpts_ListSpaces {
        profileServer?: string;
    }

    interface BoxObjectOpts_profileGraphQL {
        graphqlServer?: string;
    }

    interface BoxObjectOpts_openBox {
        consentCallback?: () => any;
        pinningNode?: string;
        ipfs?: any; // ipfsobj
        addressServer?: string;
    }

    class BoxInstance {
        public: BoxKeyValueStore;
        private: BoxKeyValueStore;
        verified: BoxVerified;
        spaces: any;
        openSpace: (name: string, opts?: BoxObjectOpts_OpenSpace) => Promise<Space>;
        onSyncDone: (cb: () => undefined) => null;
        logout: () => any;
    }

    const idUtils: BoxStaticIdUtils;
    const getProfile: (address: any, opts?: BoxObjectOpts_GetProfile) => Promise<any>;
    const getProfiles: (address: Array<any>, opts?: BoxObjectOpts_GetProfiles) => undefined;
    const getSpace: (address: any, name: any, opts?: BoxObjectOpts_GetSpace) => undefined;
    const getThread: (space: Space, name: any, opts?: BoxObjectOpts_GetThread) => Array<string>;
    const listSpaces: (address: any, opts?: BoxObjectOpts_ListSpaces) => undefined;
    const profileGraphQL: (query: any, opts?: BoxObjectOpts_profileGraphQL) => undefined;
    const getVerifiedAccounts: (profile: any) => undefined;
    const openBox: (address: any, ethereumProvider: any, opts?: BoxObjectOpts_openBox) => BoxInstance;
    const isLoggedIn: (address: any) => undefined;
}

eshohet avatar Feb 27 '20 19:02 eshohet

That looks pretty good @eshohet! The thing with return type of space.private.get(key) is that the developer can choose to put whatever they want in there (both objects and strings). We don't really have any restrictions, so it wouldn't make sense to have a strict type for it I think.

oed avatar Mar 16 '20 10:03 oed

Installing @types/3box resolved my typescript issue.

https://www.npmjs.com/package/@types/3box

alexkeating avatar Jun 09 '21 12:06 alexkeating

hey @alexkeating, thanks for using 3Box. Just to let you know, we're beginning to deprecate this codebase in favor of IDX. Would love to know what you're working on so we can help point you in the right direction. You can join the IDX/Ceramic Discord server and let us know. Also, here are the IDX Docs

michaelsena avatar Jun 09 '21 13:06 michaelsena