@voidwalkers/void-client
v0.1.23
Published
Client lib for Void Walkers Void
Downloads
4
Readme
Client lib for Void Walkers Void
Initialize client
void-cli init
void-cli config print client
import VoidClient from '@voidwalkers/void-client';
const voidClient = new VoidClient({
project: {
slug: 'test',
tokenPublic: 'token'
}
});
Auth
await voidClient.auth.signUpCustom({ // Example payload. Depends on implementation
email: '[email protected]',
password: 'test1234'
});
const user = await voidClient.auth.getCurrentUser();
console.log(user); // {id: 'UUID'}
await voidClient.auth.signOut(true); // Ignores missing session, false by default
await voidClient.auth.signInCustom({ // Example payload. Depends on implementation
email: '[email protected]',
password: 'test1234'
});
Functions
import {registerHttpFunction} from '@voidwalkers/void-functions';
registerCallFunction('echo', (data, context) => ({context, data}));
void-cli deploy -F echo
const result = await voidClient.function('echo')({hello: 'world'});
console.log(result); // {context: {projectUser: {id: 'UUID'}}, data: {hello: 'world'}}
Mongo
await voidClient.mongo.collection('items').deleteMany({type: 'box'});
await voidClient.mongo.collection('items').deleteOne({_id: 'MONGO_ID'});
await voidClient.mongo.collection('items').find({type: 'box'}, {
// limit, skip, sort, projection
});
await voidClient.mongo.collection('items').findOne({_id: 'MONGO_ID'});
await voidClient.mongo.collection('items').findOneAndUpdate({_id: 'MONGO_ID'}, {
$set: {
name: 'updated box'
}
}, {
// upsert, includeResultMetadata, projection, returnDocument
});
await voidClient.mongo.collection('items').insertMany([{
type: 'box',
name: 'box 1'
}, {
type: 'box',
name: 'box 2'
}]);
await voidClient.mongo.collection('items').insertOne({
type: 'box',
name: 'empty box'
});
await voidClient.mongo.collection('items').replaceOne({_id: 'MONGO_ID'}, {
type: 'bag',
name: 'a bag'
}, {
// upsert
});
await voidClient.mongo.collection('items').updateMany({_id: 'MONGO_ID'}, {
$set: {
name: 'updated box'
}
}, {
// upsert
});
await voidClient.mongo.collection('items').updateOne({_id: 'MONGO_ID'}, {
$set: {
name: 'updated box'
}
}, {
// upsert
});
voidClient.mongo.collection('items').watch({
type: 'box'
}, ({data, type}) => {
// type: "insert" | "update" | "delete"
// data: document involved
}, {
// let, projection
});
// Use database other than "default"
const candiesCollection = voidClient.mongo.db('another').collection('goods');
Storage
void-cli storage buckets create photos -t public
await voidClient.storage.bucket('photos').createFile(
blobOrStream,
'kitten-1.jpg',
['kittens', 'tiny'] // Optional, default []
); // https://void.void-walkers.com/projects/test/buckets/public/photos/kittens/tiny/kitten-1.jpg
await voidClient.storage.bucket('photos').deleteFile(
'kitten-1.jpg',
['kittens', 'tiny'] // Optional, default []
);
await voidClient.storage.bucket('photos').listFiles({
limit: 100, // Optional, default 50
offset: 200, // Optional, default 0
name: 'kitten-1.jpeg', // Optional, default null
prefix: ['kittens', 'tiny'] // Optional, default []
});
await voidClient.storage.bucket('photos').updateFile(
blobOrStream,
'kitten-1.jpg',
['kittens', 'tiny'] // Optional, default []
);