@aurabase/realtime 0.7.1 → 0.7.3
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.cjs +32 -4
- package/dist/index.js +32 -4
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -412,7 +412,9 @@ var AuraChannel = class {
|
|
|
412
412
|
/** Send the subscribe message to the server. */
|
|
413
413
|
_doSubscribe() {
|
|
414
414
|
if (!this._sendFn) return;
|
|
415
|
-
const pgFilters = this._listeners.filter(
|
|
415
|
+
const pgFilters = this._listeners.filter(
|
|
416
|
+
(l) => l.type === "postgres_changes"
|
|
417
|
+
).map((l) => l.filter);
|
|
416
418
|
const msg = {
|
|
417
419
|
type: "subscribe",
|
|
418
420
|
channel: this.fullName,
|
|
@@ -534,6 +536,9 @@ var AuraChannel = class {
|
|
|
534
536
|
send(message) {
|
|
535
537
|
return new Promise((resolve) => {
|
|
536
538
|
if (message.payload && Object.prototype.hasOwnProperty.call(message.payload, "event")) {
|
|
539
|
+
console.warn(
|
|
540
|
+
`[aurabase] Warning: Broadcast payload contains reserved key 'event'. Broadcast rejected with status 'invalid_payload'. Use a distinct property like 'action'.`
|
|
541
|
+
);
|
|
537
542
|
resolve("invalid_payload");
|
|
538
543
|
return;
|
|
539
544
|
}
|
|
@@ -652,12 +657,35 @@ var AuraChannel = class {
|
|
|
652
657
|
if (!this._subscribed) break;
|
|
653
658
|
const presMsg = msg;
|
|
654
659
|
if (presMsg.presences) {
|
|
655
|
-
this._presenceState
|
|
660
|
+
const oldState = this._presenceState || {};
|
|
661
|
+
const newState = {};
|
|
656
662
|
for (const p of presMsg.presences) {
|
|
657
663
|
const key = p.user_id || p.client_id;
|
|
658
|
-
if (!
|
|
659
|
-
|
|
664
|
+
if (!newState[key]) newState[key] = [];
|
|
665
|
+
newState[key].push(p);
|
|
666
|
+
}
|
|
667
|
+
for (const key of Object.keys(newState)) {
|
|
668
|
+
const newPres = newState[key];
|
|
669
|
+
const oldPres = oldState[key];
|
|
670
|
+
if (!oldPres) {
|
|
671
|
+
for (const l of this._listeners) {
|
|
672
|
+
if (l.type === "presence" && l.filter.event === "join") {
|
|
673
|
+
l.callback({ key, currentPresences: newPres, newPresences: newPres });
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
for (const key of Object.keys(oldState)) {
|
|
679
|
+
if (!newState[key]) {
|
|
680
|
+
const leftPres = oldState[key];
|
|
681
|
+
for (const l of this._listeners) {
|
|
682
|
+
if (l.type === "presence" && l.filter.event === "leave") {
|
|
683
|
+
l.callback({ key, currentPresences: [], leftPresences: leftPres });
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
660
687
|
}
|
|
688
|
+
this._presenceState = newState;
|
|
661
689
|
for (const l of this._listeners) {
|
|
662
690
|
if (l.type === "presence" && l.filter.event === "sync") {
|
|
663
691
|
l.callback(this._presenceState);
|
package/dist/index.js
CHANGED
|
@@ -410,7 +410,9 @@ var AuraChannel = class {
|
|
|
410
410
|
/** Send the subscribe message to the server. */
|
|
411
411
|
_doSubscribe() {
|
|
412
412
|
if (!this._sendFn) return;
|
|
413
|
-
const pgFilters = this._listeners.filter(
|
|
413
|
+
const pgFilters = this._listeners.filter(
|
|
414
|
+
(l) => l.type === "postgres_changes"
|
|
415
|
+
).map((l) => l.filter);
|
|
414
416
|
const msg = {
|
|
415
417
|
type: "subscribe",
|
|
416
418
|
channel: this.fullName,
|
|
@@ -532,6 +534,9 @@ var AuraChannel = class {
|
|
|
532
534
|
send(message) {
|
|
533
535
|
return new Promise((resolve) => {
|
|
534
536
|
if (message.payload && Object.prototype.hasOwnProperty.call(message.payload, "event")) {
|
|
537
|
+
console.warn(
|
|
538
|
+
`[aurabase] Warning: Broadcast payload contains reserved key 'event'. Broadcast rejected with status 'invalid_payload'. Use a distinct property like 'action'.`
|
|
539
|
+
);
|
|
535
540
|
resolve("invalid_payload");
|
|
536
541
|
return;
|
|
537
542
|
}
|
|
@@ -650,12 +655,35 @@ var AuraChannel = class {
|
|
|
650
655
|
if (!this._subscribed) break;
|
|
651
656
|
const presMsg = msg;
|
|
652
657
|
if (presMsg.presences) {
|
|
653
|
-
this._presenceState
|
|
658
|
+
const oldState = this._presenceState || {};
|
|
659
|
+
const newState = {};
|
|
654
660
|
for (const p of presMsg.presences) {
|
|
655
661
|
const key = p.user_id || p.client_id;
|
|
656
|
-
if (!
|
|
657
|
-
|
|
662
|
+
if (!newState[key]) newState[key] = [];
|
|
663
|
+
newState[key].push(p);
|
|
664
|
+
}
|
|
665
|
+
for (const key of Object.keys(newState)) {
|
|
666
|
+
const newPres = newState[key];
|
|
667
|
+
const oldPres = oldState[key];
|
|
668
|
+
if (!oldPres) {
|
|
669
|
+
for (const l of this._listeners) {
|
|
670
|
+
if (l.type === "presence" && l.filter.event === "join") {
|
|
671
|
+
l.callback({ key, currentPresences: newPres, newPresences: newPres });
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
for (const key of Object.keys(oldState)) {
|
|
677
|
+
if (!newState[key]) {
|
|
678
|
+
const leftPres = oldState[key];
|
|
679
|
+
for (const l of this._listeners) {
|
|
680
|
+
if (l.type === "presence" && l.filter.event === "leave") {
|
|
681
|
+
l.callback({ key, currentPresences: [], leftPresences: leftPres });
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
658
685
|
}
|
|
686
|
+
this._presenceState = newState;
|
|
659
687
|
for (const l of this._listeners) {
|
|
660
688
|
if (l.type === "presence" && l.filter.event === "sync") {
|
|
661
689
|
l.callback(this._presenceState);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurabase/realtime",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Service temps réel du SDK Aurabase (postgres_changes, broadcast, presence)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"realtime"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@aurabase/core": "0.7.
|
|
48
|
+
"@aurabase/core": "0.7.3"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "20.14.15",
|