@hydevs/hypb
Version:
<img src="https://github.com/Hydevs-Corp/Hypb/blob/9308ab4c17196e5c0083c983a528326fd2cba867/.github/assets/banner.png" alt="usehooks-ts banner" align="center" />
51 lines (50 loc) • 1.57 kB
JavaScript
import Pocketbase from 'pocketbase';
class HypbSingleton {
constructor() {
this._userCollection = 'users';
}
initPB(pbOrUrl, params = {
autoCancellation: false,
userCollection: 'users',
}) {
if (params.userCollection)
this.userCollection = params.userCollection;
if (pbOrUrl instanceof Pocketbase) {
this._pb = pbOrUrl;
params && this.pb.autoCancellation(!!(params === null || params === void 0 ? void 0 : params.autoCancellation));
return;
}
this._pb = new Pocketbase(pbOrUrl);
params && this.pb.autoCancellation(!!(params === null || params === void 0 ? void 0 : params.autoCancellation));
}
get pb() {
if (!this._pb) {
throw new Error('Pocketbase not initialized');
}
return this._pb;
}
get userCollection() {
if (!this._userCollection) {
throw new Error('Pocketbase not initialized');
}
return this._userCollection;
}
set userCollection(collection) {
this._userCollection = collection;
}
setNotificationSystem(ns) {
this.notificationSystem = ns;
}
notify(level, message) {
if (!this.notificationSystem)
return;
this.notificationSystem[level](message);
}
collection(collectionName) {
if (!this._pb) {
throw new Error('Pocketbase not initialized');
}
return this._pb.collection(collectionName);
}
}
export const Hypb = new HypbSingleton();