@prsm/arc-client
TypeScript icon, indicating that this package has built-in type declarations

1.3.11 • Public • Published

arc-client

NPM version

arc-client uses @prsm/duplex in order to communicate with a @prsm/arc-server over TCP.

Quickstart

import { ArcClient } from "@prsm/arc-client";

const arc = new ArcClient({
  host: "localhost",
  port: 3351,
  secure: false,
  username: "root",
  password: "toor"
});

// try to authenticate using the provided username and password
// returns true if successful, false if not
const success = await arc.auth();

await arc.query({ collection: "planets", operation: "drop" });

await arc.query({
  collection: "planets",
  operation: "insert",
  data: {
    query: [
      { name: "Mercury" },
      { name: "Venus" },
      { name: "Earth" },
      { name: "Mars" }
    ],
  },
});

const result = await arc.query({
  collection: "planets",
  operation: "find",
  data: {
    query: { name: { $includes: "M" } },
  },
});

// [
//   {
//     name: 'Mercury',
//     _created_at: 1681253769538,
//     _updated_at: 1681253769538,
//     _id: 'a-lgcv332a-0cd148-c4-923c-4'
//   },
//   {
//     name: 'Mars',
//     _created_at: 1681253769539,
//     _updated_at: 1681253769539,
//     _id: 'a-lgcv332b-0cd14b-c7-923c-7'
//   }
// ]

Use collectionWrapper(collectionName: string) to receive a more simplified API if your collection name doesn't change over time. This provides the same API as a standard @prsm/arc Collection, with the one exception being that this interface is async.

const planets = arc.collectionWrapper("planets");

await planets.drop();
await planets.insert([{ name: "Mercury" }, { name: "Venus" }, { name: "Earth" }, { name: "Mars" }]);
await planets.find({ name: { $includes: "M" } });

Events

// authentication failure, error includes reason
arc.emitter.on("autherror", (error: string) => {});

// authentication was a success
arc.emitter.on("authsuccess", () => {});

Handling the connection

To disconnect an active session, call close on the client:

arc.close();

After closing the connection, you can reconnect by calling connect:

arc.connect();

// you will need to reauthenticate at this point
await arc.auth();

Readme

Keywords

none

Package Sidebar

Install

npm i @prsm/arc-client

Weekly Downloads

2

Version

1.3.11

License

none

Unpacked Size

8.28 kB

Total Files

6

Last publish

Collaborators

  • nvmsy