1.3.11 • Published 1 year ago
@prsm/arc-client v1.3.11
arc-client
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();
1.3.10
1 year ago
1.3.9
1 year ago
1.3.8
1 year ago
1.3.11
1 year ago
1.3.7
2 years ago
1.3.6
2 years ago
1.3.5
2 years ago
1.3.4
2 years ago
1.3.3
2 years ago
1.3.2
2 years ago
1.3.1
2 years ago
1.3.0
2 years ago
1.2.9
2 years ago
1.2.8
2 years ago
1.2.7
2 years ago
1.2.6
2 years ago
1.2.5
2 years ago
1.2.4
2 years ago
1.2.3
2 years ago
1.2.2
2 years ago
1.2.1
2 years ago
1.2.0
2 years ago