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

showsourcing-api-lib

v0.2.14

Published

api for the showsourcing front end to interface with apollo and appsync

Downloads

84

Readme

This readme is not up to date

Showsourcing front-end api

Features

  • simple api
  • local db
  • search / filters
  • synchronisation
  • model generation
  • logging

Overview

ApiClient is the entry point that generates all other services. Most of the time you'll work with the ApiClient.db which is the driver to access the local database.

  • ApiClient: entry point, is responsible of configuration
  • ApiDb: performs Crud operation on the local DB
  • ApiSynchronizer: local synchronization with the server DB
  • ApiCache: is responsible of cache access

Installation

The package is a wrapper above app sync. It does the configuration on its own and also exports the different services furnished by appsync. Therefor you don't need to configure, import or even install the followings: amplify, app-sync & apollo-client.

You just need to npm i

Generate queries and mutations

amplify pull --appId d1c62vlrmdaq59 --envName antoine
amplify add codegen

amplify pull
amplify codegen
amplify codegen models

Usage


import { ApiClient } from '@cedric_showsourcing/showsourcing-frontend-api';

export const client = new ApiClient({
  awsExport: environment.awsExport,
  mutationMap: {
    Product: { update: gql(updateProduct), create: gql(createProduct) }
  },
  syncMap: {
    Product: {
      base: {
        query: gql(syncProducts),
        __typename: 'ModelProductConnection'
      }
    }
  }
});
client.sync();
export const db = client.db;
db.get('Product', 'some-id').subscribe(product => console.log(product));
db.find('Product').data$.subscribe(products => console.log(products));
client.Auth.signIn('[email protected]', 'Test1234').then(_ => {
  client.synchronizer.sync();
});

ApiDB

Here are the methods of to perform operations on the DB

  /** get one entity by id */
  get(typename: Typename, id: string): Observable<any>

  /**
   * find entities in the cache
   * @param typename: the type you want to find
   * @param filters: recursive object to filter entities e.g. {and: [{property: 'name', contains: 'hello'}, ...]}
   * @param pagination: the slice of entities e.g. {page: 0, limit: 25}
   * @param sort: how the entities are sorted e.g. {direction: 'ASC', property: 'name'}
   * @returns a single response (first()) trough an observable.
   */
  find(
    typename: Typename,
    sort?: SortType,
    filters?: FilterType,
    pagination: PaginationType = { page: 0, limit: 25 }
  ): IApiResponse<any>

  /** update many entities in backend and update the cache */
  update(typename: Typename, entities: EntityFields[]): Observable<any[]>

  /** delete many entities in backend and update the cache */
  delete(typename: Typename, entities: any[]): Observable<any[]>

  /** create many entities in backend and update the cache */
  create(typename: Typename, entities: any[]): Observable<any[]>

Logging

Set log level

You can set the log level in the options of the client

export const client = new ApiClient({
  awsExport: environment.awsExport,
  logLevel: LogLevel.DEBUG,
  // ...
});

Here are is the legend for logging:

/** colors */
const COLOR_LOCAL = 'color: gold; background: #3b2d44; padding: 4px';
const COLOR_LOCAL_RESPONSE = 'color: lime; background: #3b2d44; padding: 4px';
const COLOR_SERVER_RESPONSE = 'color: pink; background: #3b2d44; padding: 4px';
/** icons */
const iconQuery = '🍌';
const iconMutation = '🍇';

Scripts

build models from datastore models:

the src/generated/models folder can be replaced with new models generated by amplify. then the command line npm run models should use the src/generated/models to create a file in src/models/index.ts with the models usable by the client.