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

Y'all want some types? #709

Open
toddtarsi opened this issue Feb 28, 2024 · 0 comments
Open

Y'all want some types? #709

toddtarsi opened this issue Feb 28, 2024 · 0 comments

Comments

@toddtarsi
Copy link
Contributor

I wrote a small .d.ts for part of the codebase, and I'd love it if it was on definitelyTyped instead. Would you want me to open this there or anything? I figure even if its only a tiny part of the code, it might be nice to have as a starting point.

type SoapOptions = {
  timeout?: number;
  time?: boolean;
} & Record<string, unknown>;

type SoapReturnCallback<TYPE> = (
  error: any,
  envelope: string,
  result?: {
    return: TYPE;
  },
  soapHeader: any
) => void;

type SoapReturnPromise<TYPE> = Promise<{
  envelope: string;
  result?: {
    return: TYPE;
  };
  soapHeader: any;
}>;

interface SoapOperation<FN extends Function> {
  (
    args: Parameters<FN>[0],
    opts?: SoapOptions,
    extraHeaders?: any
  ): SoapReturnPromise<ReturnType<FN>>;
  (
    args: Parameters<FN>[0],
    callback: SoapReturnCallback<ReturnType<FN>>,
    opts?: SoapOptions,
    extraHeaders?: any
  ): void;
  (
    args: Parameters<FN>[0],
    opts: SoapOptions | undefined,
    callback: SoapReturnCallback<ReturnType<FN>>
  ): void;
  (
    args: Parameters<FN>[0],
    opts: SoapOptions | undefined,
    extraHeaders: any,
    callback: SoapReturnCallback<ReturnType<FN>>
  ): void;
}

/**
 * Converts a function map into a SOAP API
 */
export type SoapAPI<API extends {}> = {
  [Prop in keyof API]: API[Prop] extends Function
    ? SoapOperation<API[Prop]>
    : SoapAPI<API[Prop]>;
};

declare module 'strong-soap' {
  export const soap: {
    BasicAuthSecurity: new (username: string, password: string) => {};
    Client: new <API>() => SoapAPI<API> & {
      describe(): any;
      setEndpoint(endpoint: string): void;
      setSecurity(security: BasicAuthSecurity): void;
    };
    createClient<T>(
      url: string,
      options: {endpoint?: string} & Record<string, unknown>,
      callback: (err: Error, client: InstanceOf<Client<T>>) => void,
      endpoint?: string
    ): void;
    createClient<T>(
      url: string,
      callback: (err: Error, client: InstanceOf<Client<T>>) => void,
      endpoint?: string
    ): void;
  };
}
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

1 participant