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

@fraym/crud

v0.20.1

Published

nodejs client implementation for our crud service

Downloads

76

Readme

crud-nodejs

Client implementation in javascript for the CRUD service.

Installation

npm i @fraym/crud

GraphQL

You can access the graphQL api at http://crud:3000/delivery/graphql. There is a sandbox available at http://crud:3000/delivery/graphql/sandbox.

You need to add the Tenant-Id header in order to use the graphQL Endpoint and the sandbox.

Config

Use a .env file or env variables to configure cte clients and the command:

CRUD_SERVER_ADDRESS=127.0.0.1:9000

Usage

Create the client

const deliveryClient = await newDeliveryClient();

Authorization

All delivery client functions make use of the AuthData object. This data is used to check access for the desired action.

You can add the FRAYM_AUTH_OWNER scope in case you are performing an action that is no subject to restrictions.

Fields:

  • tenantId: Id of the tenant to use
  • scopes: Slice of scopes to use for the action
  • data: Data that is used in directives like @filterFromJwtData

Event Metadata

You can specify the correlation and causation IDs for the upsert and delete functions. The eventMetadata parameter is optional for all these functions and has the following structure:

const eventMetadata = {
    correlationId: "some-correlation-id",
    causationId: "some-causation-id",
};

Create data

The name of YourCrudType has to equal your type name in your schema (also in casing).

const response = await client.create<any>("YourCrudType", authData, {
    // values here
});

The response contains the following fields:

In case of no validation errors:

  • data: The new data after your create action

In case of validation errors:

  • validationErrors: List of global validation errors that are not related to a single field
  • fieldValidationErrors: Validation errors mapped by the name of the field that they relate to

Update data

The name of YourCrudType has to equal your type name in your schema (also in casing).

const response = await client.update<any>("YourCrudType", authData, {
    // values here
});

The response contains the following fields:

In case of no validation errors:

  • data: The new data after your create action

In case of validation errors:

  • validationErrors: List of global validation errors that are not related to a single field
  • fieldValidationErrors: Validation errors mapped by the name of the field that they relate to

Delete data

The name of YourCrudType has to equal your type name in your schema (also in casing).

Delete data matching a specific ID:

const numberOfDeletedEntries = await client.deleteDataById("YourCrudType", authData, "id");

Delete data matching a filter (see filter parameter for getDataList for details):

const numberOfDeletedEntries = await client.deleteDataByFilter("YourCrudType", authData, {
    fields: {
        fieldName: {
            operation: "equals",
            type: "Int",
            value: 123,
        },
    },
});

Get a single data element

A filter could look like this:

const filter := {
	fields: {
        fieldName: {
            operation: "equals",
            type: "Int",
            value: 123,
        },
    },
}

The name of YourCrudType has to equal your type name in your schema (also in casing). The id has to match the id of the data that you want to get.

const data = await client.getData(
    "YourCrudType",
    authData,
    "id",
    filter,
    returnEmptyDataIfNotFound
);

Get (paginated / filtered / ordered) data

The name of YourCrudType has to equal your type name in your schema (also in casing).

No pagination:

const dataList = await client.getDataList("YourCrudType", authData);

The dataList response contains the following fields:

  • limit: The pagination limit
  • page: The pagination page
  • total: The total amount of elements matching the given filter
  • data: The selected data

With pagination:

const limit = 50; // elements to query per page
const page = 1; // number of the page you want to select, first page starts at: 1
const dataList = await client.getDataList("YourCrudType", authData, limit, page);

With filter:

const dataList = await client.getDataList("YourCrudType", authData, undefined, undefined, {
    fields: {
        fieldName: {
            operation: "equals",
            type: "Int",
            value: 123,
        },
    },
});

All Filters are evaluated by:

  • checking that all field filters match
  • checking that all and filters match
  • checking that one of the or filters match

Avaliable types:

  • String
  • ID
  • DateTime
  • Int
  • Float
  • Boolean

Avaliable operators for all types:

  • equals
  • notEquals

Avaliable options for the filter type DateTime:

  • inArray
  • notInArray
  • after
  • before

Avaliable options for the filter type String and ID:

  • inArray
  • notInArray

Avaliable options for the filter type Int and Float:

  • lessThan
  • greaterThan
  • lessThanOrEqual
  • greaterThanOrEqual

With order:

All order definitions are prioritized in the order that they are defined (the first definition is prioritized over the second).

const dataList = await client.getDataList(
    "YourCrudType",
    authData,
    undefined,
    undefined,
    undefined,
    [
        {
            field: "fieldName",
            descending: true, // omit this value for asc order
        },
    ]
);

Gracefully close the client

You won't lose any data if you don't. Use it for your peace of mind.

client.close();