@telestack/db-sdk 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -0
- package/dist/index.js +34 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -128,6 +128,10 @@ export declare class Query<T = any> {
|
|
|
128
128
|
user: string;
|
|
129
129
|
clientId: string;
|
|
130
130
|
}) => void): () => void;
|
|
131
|
+
/** Broadcast a transient signal to this collection (bypasses database) */
|
|
132
|
+
signal(data: any): Promise<void>;
|
|
133
|
+
/** Listen for transient signals on this collection */
|
|
134
|
+
onSignal(callback: (data: any) => void): () => void;
|
|
131
135
|
}
|
|
132
136
|
/**
|
|
133
137
|
* CollectionReference extends Query with add() and doc() methods
|
package/dist/index.js
CHANGED
|
@@ -516,6 +516,40 @@ export class Query {
|
|
|
516
516
|
sub.removeAllListeners();
|
|
517
517
|
};
|
|
518
518
|
}
|
|
519
|
+
/** Broadcast a transient signal to this collection (bypasses database) */
|
|
520
|
+
async signal(data) {
|
|
521
|
+
const centrifuge = this.client.getCentrifuge();
|
|
522
|
+
if (!centrifuge)
|
|
523
|
+
return;
|
|
524
|
+
const channel = `collection:${this.path.replace(/\//g, '_')}`;
|
|
525
|
+
let sub = centrifuge.getSubscription(channel);
|
|
526
|
+
if (!sub) {
|
|
527
|
+
sub = centrifuge.newSubscription(channel);
|
|
528
|
+
sub.subscribe();
|
|
529
|
+
}
|
|
530
|
+
await sub.publish({ type: 'SIGNAL', data, userId: this.client.config.userId });
|
|
531
|
+
}
|
|
532
|
+
/** Listen for transient signals on this collection */
|
|
533
|
+
onSignal(callback) {
|
|
534
|
+
const centrifuge = this.client.getCentrifuge();
|
|
535
|
+
if (!centrifuge)
|
|
536
|
+
return () => { };
|
|
537
|
+
const channel = `collection:${this.path.replace(/\//g, '_')}`;
|
|
538
|
+
let sub = centrifuge.getSubscription(channel);
|
|
539
|
+
if (!sub) {
|
|
540
|
+
sub = centrifuge.newSubscription(channel);
|
|
541
|
+
}
|
|
542
|
+
const handler = (ctx) => {
|
|
543
|
+
if (ctx.data.type === 'SIGNAL') {
|
|
544
|
+
callback({ ...ctx.data.data, _userId: ctx.data.userId });
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
sub.on('publication', handler);
|
|
548
|
+
sub.subscribe();
|
|
549
|
+
return () => {
|
|
550
|
+
sub.off('publication', handler);
|
|
551
|
+
};
|
|
552
|
+
}
|
|
519
553
|
}
|
|
520
554
|
/**
|
|
521
555
|
* CollectionReference extends Query with add() and doc() methods
|