cross-tab-worker-databus 0.7.0 → 0.10.0
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/CHANGELOG.md +28 -1
- package/README.md +1 -0
- package/README.zh.md +1 -0
- package/dist/centrifuge-protocol.d.ts +8 -0
- package/dist/centrifuge-protocol.d.ts.map +1 -1
- package/dist/centrifuge-session.d.ts.map +1 -1
- package/dist/centrifuge.d.ts +2 -1
- package/dist/centrifuge.d.ts.map +1 -1
- package/dist/centrifuge.js +31 -10
- package/dist/centrifuge.js.map +2 -2
- package/dist/centrifuge.shared.worker.js +38 -4
- package/dist/centrifuge.shared.worker.js.map +3 -3
- package/dist/centrifuge.worker.js +38 -4
- package/dist/centrifuge.worker.js.map +3 -3
- package/dist/{chunk-SI7N5KNJ.js → chunk-ZOPNTR4E.js} +128 -22
- package/dist/chunk-ZOPNTR4E.js.map +7 -0
- package/dist/cjs/centrifuge.cjs +157 -30
- package/dist/cjs/centrifuge.cjs.map +4 -4
- package/dist/cjs/index.cjs +166 -28
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/core/cluster.d.ts +4 -3
- package/dist/core/cluster.d.ts.map +1 -1
- package/dist/core/data-bus.d.ts +20 -2
- package/dist/core/data-bus.d.ts.map +1 -1
- package/dist/core/publication.d.ts +10 -0
- package/dist/core/publication.d.ts.map +1 -0
- package/dist/core/replay-persistence.d.ts +2 -0
- package/dist/core/replay-persistence.d.ts.map +1 -1
- package/dist/core/trace.d.ts +2 -11
- package/dist/core/trace.d.ts.map +1 -1
- package/dist/core/types.d.ts +25 -6
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -8
- package/dist/index.js.map +2 -2
- package/dist/websocket.d.ts +2 -2
- package/dist/websocket.d.ts.map +1 -1
- package/docs/api.md +35 -4
- package/docs/architecture.md +3 -1
- package/docs/transports.md +9 -5
- package/docs/zh/api.md +35 -4
- package/docs/zh/architecture.md +3 -1
- package/docs/zh/transports.md +8 -4
- package/package.json +1 -1
- package/dist/chunk-SI7N5KNJ.js.map +0 -7
|
@@ -4981,6 +4981,26 @@ Centrifuge.SubscriptionState = SubscriptionState;
|
|
|
4981
4981
|
Centrifuge.State = State;
|
|
4982
4982
|
Centrifuge.UnauthorizedError = UnauthorizedError;
|
|
4983
4983
|
|
|
4984
|
+
// src/core/publication.ts
|
|
4985
|
+
function parseDataBusPublication(value, fallbackTopic) {
|
|
4986
|
+
if (!value || typeof value !== "object") {
|
|
4987
|
+
return fallbackTopic ? { topic: fallbackTopic, data: value } : null;
|
|
4988
|
+
}
|
|
4989
|
+
const frame = value;
|
|
4990
|
+
const nested = frame.publication && typeof frame.publication === "object" ? frame.publication : null;
|
|
4991
|
+
const publication = nested ?? frame;
|
|
4992
|
+
const topic = typeof publication.topic === "string" ? publication.topic : fallbackTopic;
|
|
4993
|
+
if (!topic) return null;
|
|
4994
|
+
const hasMetadataEnvelope = fallbackTopic !== void 0 && Object.prototype.hasOwnProperty.call(publication, "data") && (typeof publication.messageId === "string" || typeof publication.timestamp === "number");
|
|
4995
|
+
const data = nested || fallbackTopic === void 0 || hasMetadataEnvelope ? publication.data : value;
|
|
4996
|
+
return {
|
|
4997
|
+
topic,
|
|
4998
|
+
data,
|
|
4999
|
+
...typeof publication.messageId === "string" ? { messageId: publication.messageId } : {},
|
|
5000
|
+
...typeof publication.timestamp === "number" ? { timestamp: publication.timestamp } : {}
|
|
5001
|
+
};
|
|
5002
|
+
}
|
|
5003
|
+
|
|
4984
5004
|
// src/centrifuge-session.ts
|
|
4985
5005
|
var CentrifugeSession = class {
|
|
4986
5006
|
constructor(sink) {
|
|
@@ -5005,7 +5025,7 @@ var CentrifugeSession = class {
|
|
|
5005
5025
|
return;
|
|
5006
5026
|
case "PUBLISH":
|
|
5007
5027
|
case "PUBLISH_BIN":
|
|
5008
|
-
this.publish(message.topic, message.data);
|
|
5028
|
+
this.publish(message.topic, message.data, message.messageId, message.timestamp);
|
|
5009
5029
|
return;
|
|
5010
5030
|
case "STOP":
|
|
5011
5031
|
this.stop();
|
|
@@ -5070,9 +5090,15 @@ var CentrifugeSession = class {
|
|
|
5070
5090
|
subscription.unsubscribe();
|
|
5071
5091
|
}
|
|
5072
5092
|
/** Publish a message to the Centrifuge channel. */
|
|
5073
|
-
publish(topic, data) {
|
|
5093
|
+
publish(topic, data, messageId, timestamp) {
|
|
5074
5094
|
if (!this.client) return this.postError(new Error("Centrifuge client is not initialized."));
|
|
5075
|
-
void
|
|
5095
|
+
const hasMetadata = messageId !== void 0 || timestamp !== void 0;
|
|
5096
|
+
const payload = hasMetadata ? {
|
|
5097
|
+
data,
|
|
5098
|
+
...messageId === void 0 ? {} : { messageId },
|
|
5099
|
+
...timestamp === void 0 ? {} : { timestamp }
|
|
5100
|
+
} : data;
|
|
5101
|
+
void this.client.publish(topic, payload).catch((error) => this.postError(error));
|
|
5076
5102
|
}
|
|
5077
5103
|
/** Forward a publication to the transport. Binary payloads take the
|
|
5078
5104
|
* zero-copy `MESSAGE_BIN` path when `transferable` is enabled; everything
|
|
@@ -5084,7 +5110,15 @@ var CentrifugeSession = class {
|
|
|
5084
5110
|
this.post({ type: "MESSAGE_BIN", topic, data }, [data]);
|
|
5085
5111
|
return;
|
|
5086
5112
|
}
|
|
5087
|
-
|
|
5113
|
+
const publication = parseDataBusPublication(data, topic);
|
|
5114
|
+
if (!publication) return;
|
|
5115
|
+
this.post({
|
|
5116
|
+
type: "MESSAGE",
|
|
5117
|
+
topic: publication.topic,
|
|
5118
|
+
data: publication.data,
|
|
5119
|
+
...publication.messageId === void 0 ? {} : { messageId: publication.messageId },
|
|
5120
|
+
...publication.timestamp === void 0 ? {} : { timestamp: publication.timestamp }
|
|
5121
|
+
});
|
|
5088
5122
|
}
|
|
5089
5123
|
/** Disconnect the client and clear all subscriptions. */
|
|
5090
5124
|
stop() {
|