@aurabase/realtime 0.7.3 → 0.7.5
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 +42 -7
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +42 -7
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -501,6 +501,7 @@ var AuraChannel = class {
|
|
|
501
501
|
this._closedEmitted = true;
|
|
502
502
|
this._subscribeCallback?.("CLOSED");
|
|
503
503
|
}
|
|
504
|
+
return Promise.resolve("ok");
|
|
504
505
|
}
|
|
505
506
|
// ─── Broadcast ──────────────────────────────────────────────────────────
|
|
506
507
|
/**
|
|
@@ -535,6 +536,21 @@ var AuraChannel = class {
|
|
|
535
536
|
*/
|
|
536
537
|
send(message) {
|
|
537
538
|
return new Promise((resolve) => {
|
|
539
|
+
if (message.payload) {
|
|
540
|
+
try {
|
|
541
|
+
const payloadStr = JSON.stringify(message.payload);
|
|
542
|
+
if (payloadStr.length > 256 * 1024) {
|
|
543
|
+
console.warn(
|
|
544
|
+
`[aurabase] Warning: Broadcast payload exceeds maximum allowed size (256 KB). Broadcast rejected with status 'invalid_payload'.`
|
|
545
|
+
);
|
|
546
|
+
resolve("invalid_payload");
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
} catch {
|
|
550
|
+
resolve("invalid_payload");
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
538
554
|
if (message.payload && Object.prototype.hasOwnProperty.call(message.payload, "event")) {
|
|
539
555
|
console.warn(
|
|
540
556
|
`[aurabase] Warning: Broadcast payload contains reserved key 'event'. Broadcast rejected with status 'invalid_payload'. Use a distinct property like 'action'.`
|
|
@@ -618,9 +634,21 @@ var AuraChannel = class {
|
|
|
618
634
|
}
|
|
619
635
|
return Promise.resolve("ok");
|
|
620
636
|
}
|
|
621
|
-
/** Stop tracking presence.
|
|
637
|
+
/** Stop tracking presence. Émet un départ explicite de présence. */
|
|
622
638
|
untrack() {
|
|
623
|
-
|
|
639
|
+
if (!this._sendFn) return Promise.resolve("error");
|
|
640
|
+
try {
|
|
641
|
+
const delivered = this._sendFn(
|
|
642
|
+
JSON.stringify({
|
|
643
|
+
type: "presence_leave",
|
|
644
|
+
channel: this.fullName
|
|
645
|
+
})
|
|
646
|
+
) !== false;
|
|
647
|
+
if (!delivered) return Promise.resolve("error");
|
|
648
|
+
} catch {
|
|
649
|
+
return Promise.resolve("error");
|
|
650
|
+
}
|
|
651
|
+
return Promise.resolve("ok");
|
|
624
652
|
}
|
|
625
653
|
/** Get the current presence state for this channel. */
|
|
626
654
|
presenceState() {
|
|
@@ -635,6 +663,11 @@ var AuraChannel = class {
|
|
|
635
663
|
if (subMsg.subscription_id) this._subscriptionId = subMsg.subscription_id;
|
|
636
664
|
this._serverState = "subscribed";
|
|
637
665
|
this._clearSubscribeTimeout();
|
|
666
|
+
if (Array.isArray(subMsg.history) && subMsg.history.length > 0) {
|
|
667
|
+
for (const ev of subMsg.history) {
|
|
668
|
+
this._dispatchEvent(ev);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
638
671
|
this._emitStatus("SUBSCRIBED");
|
|
639
672
|
break;
|
|
640
673
|
}
|
|
@@ -828,6 +861,8 @@ var AuraChannel = class {
|
|
|
828
861
|
const cdcType = eventTypeString.toUpperCase();
|
|
829
862
|
const recordNew = cdcType === "DELETE" ? null : rawRecord;
|
|
830
863
|
const recordOld = cdcType === "INSERT" ? null : rawOldRecord;
|
|
864
|
+
const rawSchema = cdcPayload.schema ?? filter.schema ?? "public";
|
|
865
|
+
const normalizedSchema = rawSchema.startsWith("project_") ? "public" : rawSchema;
|
|
831
866
|
const enrichedPayload = {
|
|
832
867
|
...cdcPayload,
|
|
833
868
|
record: rawRecord,
|
|
@@ -835,13 +870,13 @@ var AuraChannel = class {
|
|
|
835
870
|
new: recordNew,
|
|
836
871
|
old: recordOld,
|
|
837
872
|
eventType: cdcType,
|
|
838
|
-
schema:
|
|
873
|
+
schema: normalizedSchema,
|
|
839
874
|
table: cdcPayload.table ?? filter.table ?? "",
|
|
840
875
|
commit_timestamp: cdcPayload.commit_timestamp ?? event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
841
876
|
};
|
|
842
877
|
const enrichedEvent = {
|
|
843
878
|
...event,
|
|
844
|
-
schema:
|
|
879
|
+
schema: normalizedSchema,
|
|
845
880
|
table: cdcPayload.table ?? filter.table ?? "",
|
|
846
881
|
commit_timestamp: cdcPayload.commit_timestamp ?? event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
847
882
|
errors: cdcPayload.errors,
|
|
@@ -1658,7 +1693,7 @@ var RealtimeService = class _RealtimeService {
|
|
|
1658
1693
|
this._reconnectAttempts = 0;
|
|
1659
1694
|
this._awaitingPong = false;
|
|
1660
1695
|
for (const channel of this._channels.values()) {
|
|
1661
|
-
channel.unsubscribe();
|
|
1696
|
+
void channel.unsubscribe();
|
|
1662
1697
|
}
|
|
1663
1698
|
this._channels.clear();
|
|
1664
1699
|
if (this._ws) {
|
|
@@ -1694,7 +1729,7 @@ var RealtimeService = class _RealtimeService {
|
|
|
1694
1729
|
const name = typeof channel === "string" ? channel : channel.name;
|
|
1695
1730
|
const ch = this._channels.get(name);
|
|
1696
1731
|
if (ch) {
|
|
1697
|
-
ch.unsubscribe();
|
|
1732
|
+
void ch.unsubscribe();
|
|
1698
1733
|
this._channels.delete(name);
|
|
1699
1734
|
}
|
|
1700
1735
|
}
|
|
@@ -1705,7 +1740,7 @@ var RealtimeService = class _RealtimeService {
|
|
|
1705
1740
|
/** Remove all channels and subscriptions. */
|
|
1706
1741
|
removeAllChannels() {
|
|
1707
1742
|
for (const ch of this._channels.values()) {
|
|
1708
|
-
ch.unsubscribe();
|
|
1743
|
+
void ch.unsubscribe();
|
|
1709
1744
|
}
|
|
1710
1745
|
this._channels.clear();
|
|
1711
1746
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -221,7 +221,7 @@ declare class AuraChannel {
|
|
|
221
221
|
*/
|
|
222
222
|
_signalError(err: Error): void;
|
|
223
223
|
/** Unsubscribe from the channel. */
|
|
224
|
-
unsubscribe():
|
|
224
|
+
unsubscribe(): Promise<'ok'>;
|
|
225
225
|
/**
|
|
226
226
|
* Envoie un message broadcast sur le canal.
|
|
227
227
|
*
|
|
@@ -263,7 +263,7 @@ declare class AuraChannel {
|
|
|
263
263
|
* ```
|
|
264
264
|
*/
|
|
265
265
|
track(state: Record<string, unknown>): Promise<'ok' | 'error'>;
|
|
266
|
-
/** Stop tracking presence.
|
|
266
|
+
/** Stop tracking presence. Émet un départ explicite de présence. */
|
|
267
267
|
untrack(): Promise<'ok' | 'error'>;
|
|
268
268
|
/** Get the current presence state for this channel. */
|
|
269
269
|
presenceState(): PresenceState;
|
package/dist/index.d.ts
CHANGED
|
@@ -221,7 +221,7 @@ declare class AuraChannel {
|
|
|
221
221
|
*/
|
|
222
222
|
_signalError(err: Error): void;
|
|
223
223
|
/** Unsubscribe from the channel. */
|
|
224
|
-
unsubscribe():
|
|
224
|
+
unsubscribe(): Promise<'ok'>;
|
|
225
225
|
/**
|
|
226
226
|
* Envoie un message broadcast sur le canal.
|
|
227
227
|
*
|
|
@@ -263,7 +263,7 @@ declare class AuraChannel {
|
|
|
263
263
|
* ```
|
|
264
264
|
*/
|
|
265
265
|
track(state: Record<string, unknown>): Promise<'ok' | 'error'>;
|
|
266
|
-
/** Stop tracking presence.
|
|
266
|
+
/** Stop tracking presence. Émet un départ explicite de présence. */
|
|
267
267
|
untrack(): Promise<'ok' | 'error'>;
|
|
268
268
|
/** Get the current presence state for this channel. */
|
|
269
269
|
presenceState(): PresenceState;
|
package/dist/index.js
CHANGED
|
@@ -499,6 +499,7 @@ var AuraChannel = class {
|
|
|
499
499
|
this._closedEmitted = true;
|
|
500
500
|
this._subscribeCallback?.("CLOSED");
|
|
501
501
|
}
|
|
502
|
+
return Promise.resolve("ok");
|
|
502
503
|
}
|
|
503
504
|
// ─── Broadcast ──────────────────────────────────────────────────────────
|
|
504
505
|
/**
|
|
@@ -533,6 +534,21 @@ var AuraChannel = class {
|
|
|
533
534
|
*/
|
|
534
535
|
send(message) {
|
|
535
536
|
return new Promise((resolve) => {
|
|
537
|
+
if (message.payload) {
|
|
538
|
+
try {
|
|
539
|
+
const payloadStr = JSON.stringify(message.payload);
|
|
540
|
+
if (payloadStr.length > 256 * 1024) {
|
|
541
|
+
console.warn(
|
|
542
|
+
`[aurabase] Warning: Broadcast payload exceeds maximum allowed size (256 KB). Broadcast rejected with status 'invalid_payload'.`
|
|
543
|
+
);
|
|
544
|
+
resolve("invalid_payload");
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
} catch {
|
|
548
|
+
resolve("invalid_payload");
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
536
552
|
if (message.payload && Object.prototype.hasOwnProperty.call(message.payload, "event")) {
|
|
537
553
|
console.warn(
|
|
538
554
|
`[aurabase] Warning: Broadcast payload contains reserved key 'event'. Broadcast rejected with status 'invalid_payload'. Use a distinct property like 'action'.`
|
|
@@ -616,9 +632,21 @@ var AuraChannel = class {
|
|
|
616
632
|
}
|
|
617
633
|
return Promise.resolve("ok");
|
|
618
634
|
}
|
|
619
|
-
/** Stop tracking presence.
|
|
635
|
+
/** Stop tracking presence. Émet un départ explicite de présence. */
|
|
620
636
|
untrack() {
|
|
621
|
-
|
|
637
|
+
if (!this._sendFn) return Promise.resolve("error");
|
|
638
|
+
try {
|
|
639
|
+
const delivered = this._sendFn(
|
|
640
|
+
JSON.stringify({
|
|
641
|
+
type: "presence_leave",
|
|
642
|
+
channel: this.fullName
|
|
643
|
+
})
|
|
644
|
+
) !== false;
|
|
645
|
+
if (!delivered) return Promise.resolve("error");
|
|
646
|
+
} catch {
|
|
647
|
+
return Promise.resolve("error");
|
|
648
|
+
}
|
|
649
|
+
return Promise.resolve("ok");
|
|
622
650
|
}
|
|
623
651
|
/** Get the current presence state for this channel. */
|
|
624
652
|
presenceState() {
|
|
@@ -633,6 +661,11 @@ var AuraChannel = class {
|
|
|
633
661
|
if (subMsg.subscription_id) this._subscriptionId = subMsg.subscription_id;
|
|
634
662
|
this._serverState = "subscribed";
|
|
635
663
|
this._clearSubscribeTimeout();
|
|
664
|
+
if (Array.isArray(subMsg.history) && subMsg.history.length > 0) {
|
|
665
|
+
for (const ev of subMsg.history) {
|
|
666
|
+
this._dispatchEvent(ev);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
636
669
|
this._emitStatus("SUBSCRIBED");
|
|
637
670
|
break;
|
|
638
671
|
}
|
|
@@ -826,6 +859,8 @@ var AuraChannel = class {
|
|
|
826
859
|
const cdcType = eventTypeString.toUpperCase();
|
|
827
860
|
const recordNew = cdcType === "DELETE" ? null : rawRecord;
|
|
828
861
|
const recordOld = cdcType === "INSERT" ? null : rawOldRecord;
|
|
862
|
+
const rawSchema = cdcPayload.schema ?? filter.schema ?? "public";
|
|
863
|
+
const normalizedSchema = rawSchema.startsWith("project_") ? "public" : rawSchema;
|
|
829
864
|
const enrichedPayload = {
|
|
830
865
|
...cdcPayload,
|
|
831
866
|
record: rawRecord,
|
|
@@ -833,13 +868,13 @@ var AuraChannel = class {
|
|
|
833
868
|
new: recordNew,
|
|
834
869
|
old: recordOld,
|
|
835
870
|
eventType: cdcType,
|
|
836
|
-
schema:
|
|
871
|
+
schema: normalizedSchema,
|
|
837
872
|
table: cdcPayload.table ?? filter.table ?? "",
|
|
838
873
|
commit_timestamp: cdcPayload.commit_timestamp ?? event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
839
874
|
};
|
|
840
875
|
const enrichedEvent = {
|
|
841
876
|
...event,
|
|
842
|
-
schema:
|
|
877
|
+
schema: normalizedSchema,
|
|
843
878
|
table: cdcPayload.table ?? filter.table ?? "",
|
|
844
879
|
commit_timestamp: cdcPayload.commit_timestamp ?? event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
845
880
|
errors: cdcPayload.errors,
|
|
@@ -1656,7 +1691,7 @@ var RealtimeService = class _RealtimeService {
|
|
|
1656
1691
|
this._reconnectAttempts = 0;
|
|
1657
1692
|
this._awaitingPong = false;
|
|
1658
1693
|
for (const channel of this._channels.values()) {
|
|
1659
|
-
channel.unsubscribe();
|
|
1694
|
+
void channel.unsubscribe();
|
|
1660
1695
|
}
|
|
1661
1696
|
this._channels.clear();
|
|
1662
1697
|
if (this._ws) {
|
|
@@ -1692,7 +1727,7 @@ var RealtimeService = class _RealtimeService {
|
|
|
1692
1727
|
const name = typeof channel === "string" ? channel : channel.name;
|
|
1693
1728
|
const ch = this._channels.get(name);
|
|
1694
1729
|
if (ch) {
|
|
1695
|
-
ch.unsubscribe();
|
|
1730
|
+
void ch.unsubscribe();
|
|
1696
1731
|
this._channels.delete(name);
|
|
1697
1732
|
}
|
|
1698
1733
|
}
|
|
@@ -1703,7 +1738,7 @@ var RealtimeService = class _RealtimeService {
|
|
|
1703
1738
|
/** Remove all channels and subscriptions. */
|
|
1704
1739
|
removeAllChannels() {
|
|
1705
1740
|
for (const ch of this._channels.values()) {
|
|
1706
|
-
ch.unsubscribe();
|
|
1741
|
+
void ch.unsubscribe();
|
|
1707
1742
|
}
|
|
1708
1743
|
this._channels.clear();
|
|
1709
1744
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurabase/realtime",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
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,13 +45,13 @@
|
|
|
45
45
|
"realtime"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@aurabase/core": "0.7.
|
|
48
|
+
"@aurabase/core": "0.7.5"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "20.14.15",
|
|
52
52
|
"tsup": "^8.0.0",
|
|
53
53
|
"typescript": "^5.5.0",
|
|
54
|
-
"vitest": "^4.1.
|
|
54
|
+
"vitest": "^4.1.12"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsup",
|