npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@magda/utils

v4.2.4

Published

MAGDA Common Utils

Downloads

192

Readme

MAGDA Common Utils

This package includes the following common utilities that may help magda miniors / connectors development:

/**
 * Checks to see whether the passed argv has a jwtSecret object. If not,
 * tries to add one by looking at the JWT_SECRET env var and failing that,
 * the jwtSecret value in package.json config.
 *
 * If it can't find one and required is true (or unprovided), this will
 * throw an Error.
 */
export declare function addJwtSecretFromEnvVar<T>(
  argv: {
    [key in keyof Arguments<T>]: Arguments<T>[key];
  },
  required?: boolean
): {
  [key in keyof Arguments<T>]: Arguments<T>[key];
};

export declare function arrayToMaybe<T>(rows: T[]): Maybe<T>;

export declare class AsyncPage<T> {
  readonly requestNextPage: CreateAsyncPage<T>;
  readonly data: T;
  readonly hasData: boolean;
  static create<T>(next: (data: T) => Promise<T>): AsyncPage<T>;
  static single<T>(value: T): AsyncPage<T>;
  static singlePromise<T>(valuePromise: Promise<T>): AsyncPage<T>;
  static none<T>(): AsyncPage<T>;
  constructor(data: T, hasData: boolean, requestNextPage: CreateAsyncPage<T>);
  map<TResult>(selector: (data: T) => TResult): AsyncPage<TResult>;
  forEach(callback: (data: T) => void): Promise<void>;
  take(n: number): AsyncPage<T>;
}

export declare function asyncPageToArray<T>(page: AsyncPage<T[]>): Promise<T[]>;

export declare class BadRequestError extends ServiceError {
  constructor(statusCode: number, errorResponse: ApiError, e: any);
}

export declare function buildJwt(
  jwtSecret: string,
  userId: string,
  session?: any
): string;

export declare const coerceJson: (
  param: string
) => (json?: string | object | any[]) => any;

declare interface CreateAsyncPage<T> {
  (): Promise<AsyncPage<T>>;
}

export declare function createNoCacheFetchOptions(
  fetchOptions?: RequestInit
): {
  body?: BodyInit;
  cache?: RequestCache;
  credentials?: RequestCredentials;
  headers?: HeadersInit;
  integrity?: string;
  keepalive?: boolean;
  method?: string;
  mode?: RequestMode;
  redirect?: RequestRedirect;
  referrer?: string;
  referrerPolicy?: ReferrerPolicy;
  signal?: AbortSignal;
  window?: null;
};

/**
 * Creates a {@link ServiceError} from the result of a failed call to an API generated
 * by swagger-codegen.  The result typically includes `response` (with a status code) and
 * a `body` (the JSON the server returned with the error), but may be other things if,
 * e.g., an exception occurred while attempting to invoke the service.
 *
 * @export
 * @param {*} e The result of the failed call.
 * @returns {Error} An Error created from the failed result.
 */
export declare function createServiceError(e: any): Error;

export declare function encodeURIComponentWithApost(string: string): string;

export declare function fetchRequest<T = any, CT = string>(
  method: string,
  url: string,
  body?: any,
  contentType?: CT | RequestContentType | undefined | null,
  returnHeaders?: false,
  extraRequestOptions?: RequestInit
): Promise<T>;

export declare function fetchRequest<T = any, CT = string>(
  method: string,
  url: string,
  body?: any,
  contentType?: CT | RequestContentType | undefined | null,
  returnHeaders?: true,
  extraRequestOptions?: RequestInit
): Promise<[T, Headers]>;

export declare function forEachAsync<T>(
  page: AsyncPage<T[]>,
  maxConcurrency: number,
  callbackFn: (data: T) => Promise<void>
): Promise<void>;

export declare function formatServiceError(
  baseMessage: string,
  e: any,
  retriesLeft: number
): string;

export declare function getMinikubeIP(): string;

/**
 * Get the access url of a storage api resource from [pseudo storage api resource URL](https://github.com/magda-io/magda/issues/3000)
 * If the input url is not a pseudo storage api resource URL, return the input url directly
 *
 * @export
 * @param {string} resourceUrl pseudo storage api resource URL or ordinary HTTP access url
 * @param {string} storageApiBaseUrl storage api base url
 * @param {string} datasetsBucket datasets storage bucket name
 * @return {*}
 */
export declare function getStorageApiResourceAccessUrl(
  resourceUrl: string,
  storageApiBaseUrl: string,
  datasetsBucket: string
): string;

export declare const isUuid: (id: any) => boolean;

export declare function retry<T = any>(
  op: () => Promise<T>,
  delaySeconds: number,
  retries: number,
  onRetry: (e: any, retries: number) => any,
  shouldRetry?: (e: any) => boolean
): Promise<T>;

export declare function retryBackoff<T>(
  op: () => Promise<T>,
  delaySeconds: number,
  retries: number,
  onRetry: (e: any, retries: number) => any,
  easing?: (delaySeconds: number) => number
): Promise<T>;

export declare function runLater<TResult>(
  milliseconds: number,
  functionToRunLater: () => Promise<TResult> | TResult
): Promise<TResult>;

export declare class ServiceError extends Error {
  e: any;
  constructor(message: string, e: any);
}

export declare function unionToThrowable<T>(input: T | Error | ServerError): T;