@cadenza.io/service 1.21.16 → 1.22.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/dist/index.js +70 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -192,7 +192,6 @@ var DeputyTask = class extends import_core.Task {
|
|
|
192
192
|
},
|
|
193
193
|
...ctx
|
|
194
194
|
};
|
|
195
|
-
console.log("DEPUTY CONTEXT", deputyContext);
|
|
196
195
|
return this.taskFunction(deputyContext, emit, progressCallback);
|
|
197
196
|
}
|
|
198
197
|
};
|
|
@@ -1181,7 +1180,7 @@ var RestController = class _RestController {
|
|
|
1181
1180
|
try {
|
|
1182
1181
|
ctx2 = req.body;
|
|
1183
1182
|
deputyExecId = ctx2.__metadata.__deputyExecId;
|
|
1184
|
-
console.log("delegation", deputyExecId, ctx2);
|
|
1183
|
+
console.log("Rest delegation", deputyExecId, ctx2);
|
|
1185
1184
|
} catch (e) {
|
|
1186
1185
|
console.error("Error in delegation", e);
|
|
1187
1186
|
res.send({
|
|
@@ -1195,7 +1194,7 @@ var RestController = class _RestController {
|
|
|
1195
1194
|
CadenzaService.createEphemeralMetaTask(
|
|
1196
1195
|
"Resolve delegation",
|
|
1197
1196
|
(endCtx) => {
|
|
1198
|
-
console.log("Resolve delegation", endCtx);
|
|
1197
|
+
console.log("Resolve Rest delegation", endCtx);
|
|
1199
1198
|
const metadata = endCtx.__metadata;
|
|
1200
1199
|
delete endCtx.__metadata;
|
|
1201
1200
|
res.json({
|
|
@@ -1216,7 +1215,7 @@ var RestController = class _RestController {
|
|
|
1216
1215
|
let ctx2;
|
|
1217
1216
|
try {
|
|
1218
1217
|
ctx2 = req.body;
|
|
1219
|
-
console.log("SIGNAL RECEIVED", ctx2);
|
|
1218
|
+
console.log("SIGNAL RECEIVED", ctx2.__signalName);
|
|
1220
1219
|
if (!CadenzaService.broker.listObservedSignals().includes(ctx2.__signalName)) {
|
|
1221
1220
|
res.send({
|
|
1222
1221
|
...ctx2,
|
|
@@ -1372,7 +1371,7 @@ var RestController = class _RestController {
|
|
|
1372
1371
|
const handshakeTask = CadenzaService.createMetaTask(
|
|
1373
1372
|
`Send Handshake to ${URL}`,
|
|
1374
1373
|
async (ctx2, emit2) => {
|
|
1375
|
-
console.log("Sending handshake", ctx2);
|
|
1374
|
+
console.log("Sending Rest handshake", ctx2);
|
|
1376
1375
|
try {
|
|
1377
1376
|
const response = await this.fetchDataWithTimeout(
|
|
1378
1377
|
`${URL}/handshake`,
|
|
@@ -1385,7 +1384,7 @@ var RestController = class _RestController {
|
|
|
1385
1384
|
},
|
|
1386
1385
|
1e3
|
|
1387
1386
|
);
|
|
1388
|
-
console.log("Handshake result", response);
|
|
1387
|
+
console.log("Rest Handshake result", response);
|
|
1389
1388
|
if (response.__status !== "success") {
|
|
1390
1389
|
const error = response.__error ?? `Failed to connect to service ${serviceName} ${ctx2.serviceInstanceId}`;
|
|
1391
1390
|
console.error(error);
|
|
@@ -1421,7 +1420,7 @@ var RestController = class _RestController {
|
|
|
1421
1420
|
if (ctx2.__remoteRoutineName === void 0) {
|
|
1422
1421
|
return;
|
|
1423
1422
|
}
|
|
1424
|
-
console.log("Delegating", ctx2);
|
|
1423
|
+
console.log("Delegating via REST", ctx2);
|
|
1425
1424
|
let resultContext;
|
|
1426
1425
|
try {
|
|
1427
1426
|
const response = await (0, import_node_fetch.default)(`${URL}/delegation`, {
|
|
@@ -1583,12 +1582,19 @@ var SocketController = class _SocketController {
|
|
|
1583
1582
|
}
|
|
1584
1583
|
console.log("SocketServer: Setting up");
|
|
1585
1584
|
const server = new import_socket.Server(ctx.__httpsServer ?? ctx.__httpServer, {
|
|
1586
|
-
|
|
1585
|
+
pingInterval: 3e4,
|
|
1586
|
+
pingTimeout: 2e4,
|
|
1587
|
+
maxHttpBufferSize: 1e7,
|
|
1587
1588
|
// 10MB large payloads
|
|
1589
|
+
connectionStateRecovery: {
|
|
1590
|
+
maxDisconnectionDuration: 2 * 60 * 1e3,
|
|
1591
|
+
// 2min
|
|
1592
|
+
skipMiddlewares: true
|
|
1593
|
+
// Optional: bypass rate limiter on recover
|
|
1594
|
+
}
|
|
1588
1595
|
});
|
|
1589
1596
|
const profile = ctx.__securityProfile ?? "medium";
|
|
1590
1597
|
server.use((socket, next) => {
|
|
1591
|
-
console.log("Middleware running for socket:", socket.id);
|
|
1592
1598
|
const origin = socket?.handshake?.headers?.origin;
|
|
1593
1599
|
const allowedOrigins = ["*"];
|
|
1594
1600
|
const networkType = ctx.__networkType ?? "internal";
|
|
@@ -1605,13 +1611,6 @@ var SocketController = class _SocketController {
|
|
|
1605
1611
|
const limiter = new import_rate_limiter_flexible2.RateLimiterMemory(limiterOptions[profile]);
|
|
1606
1612
|
const clientKey = socket?.handshake?.address || "unknown";
|
|
1607
1613
|
socket.use((packet, packetNext) => {
|
|
1608
|
-
console.log(
|
|
1609
|
-
"Incoming packet:",
|
|
1610
|
-
packet[0],
|
|
1611
|
-
"from socket:",
|
|
1612
|
-
socket.id,
|
|
1613
|
-
clientKey
|
|
1614
|
-
);
|
|
1615
1614
|
limiter.consume(clientKey).then(() => packetNext()).catch((rej) => {
|
|
1616
1615
|
if (rej.msBeforeNext > 0) {
|
|
1617
1616
|
console.log(
|
|
@@ -1753,9 +1752,6 @@ var SocketController = class _SocketController {
|
|
|
1753
1752
|
__wsId: ws.id
|
|
1754
1753
|
});
|
|
1755
1754
|
});
|
|
1756
|
-
ws.onAny((event) => {
|
|
1757
|
-
console.log("SocketServer: Any", event);
|
|
1758
|
-
});
|
|
1759
1755
|
} catch (e) {
|
|
1760
1756
|
console.error("SocketServer: Error in socket event", e);
|
|
1761
1757
|
}
|
|
@@ -1789,22 +1785,50 @@ var SocketController = class _SocketController {
|
|
|
1789
1785
|
console.log("SocketClient: Connecting to", serviceName, URL);
|
|
1790
1786
|
const socket = (0, import_socket2.io)(URL, {
|
|
1791
1787
|
reconnection: true,
|
|
1792
|
-
reconnectionAttempts:
|
|
1793
|
-
reconnectionDelay:
|
|
1788
|
+
reconnectionAttempts: 5,
|
|
1789
|
+
reconnectionDelay: 2e3,
|
|
1794
1790
|
reconnectionDelayMax: 1e4,
|
|
1795
1791
|
randomizationFactor: 0.5,
|
|
1796
|
-
|
|
1797
|
-
|
|
1792
|
+
transports: ["websocket"],
|
|
1793
|
+
autoConnect: false
|
|
1798
1794
|
});
|
|
1799
|
-
const
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1795
|
+
const emitWhenReady = (event, data, timeoutMs = 2e4, ack) => {
|
|
1796
|
+
return new Promise((resolve, reject) => {
|
|
1797
|
+
const tryEmit = () => {
|
|
1798
|
+
if (!socket.connected) {
|
|
1799
|
+
socket.once("connect", tryEmit);
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1802
|
+
let timer;
|
|
1803
|
+
if (timeoutMs !== 0) {
|
|
1804
|
+
timer = setTimeout(() => {
|
|
1805
|
+
console.error(`${event} timed out`);
|
|
1806
|
+
reject(new Error(`${event} timed out`));
|
|
1807
|
+
}, timeoutMs);
|
|
1808
|
+
}
|
|
1809
|
+
socket.timeout(timeoutMs).emit(event, data, (err, response) => {
|
|
1810
|
+
if (err) {
|
|
1811
|
+
console.log("Timeout error:", err);
|
|
1812
|
+
response = {
|
|
1813
|
+
__error: `Timeout error: ${err}`,
|
|
1814
|
+
errored: true,
|
|
1815
|
+
...ctx,
|
|
1816
|
+
...ctx.__metadata
|
|
1817
|
+
};
|
|
1818
|
+
resolve(response);
|
|
1819
|
+
return;
|
|
1820
|
+
}
|
|
1821
|
+
if (timer) clearTimeout(timer);
|
|
1822
|
+
if (ack) ack(response);
|
|
1823
|
+
resolve(response);
|
|
1824
|
+
});
|
|
1825
|
+
};
|
|
1826
|
+
if (socket.connected) {
|
|
1827
|
+
tryEmit();
|
|
1828
|
+
} else {
|
|
1829
|
+
socket.once("connect", tryEmit);
|
|
1830
|
+
}
|
|
1806
1831
|
});
|
|
1807
|
-
return originalEmit.apply(this, [event, ...args]);
|
|
1808
1832
|
};
|
|
1809
1833
|
socket.on("connect", () => {
|
|
1810
1834
|
console.log("SocketClient: CONNECTED", socket.id);
|
|
@@ -1848,12 +1872,6 @@ var SocketController = class _SocketController {
|
|
|
1848
1872
|
console.error("SocketClient: error", err);
|
|
1849
1873
|
CadenzaService.broker.emit("meta.socket_client.error", err);
|
|
1850
1874
|
});
|
|
1851
|
-
socket.onAny((event) => {
|
|
1852
|
-
console.log("SocketClient: Any", event);
|
|
1853
|
-
});
|
|
1854
|
-
socket.onAnyOutgoing((event) => {
|
|
1855
|
-
console.log("Outgoing packet", event);
|
|
1856
|
-
});
|
|
1857
1875
|
socket.on("disconnect", () => {
|
|
1858
1876
|
console.log("SocketClient: Disconnected", URL);
|
|
1859
1877
|
CadenzaService.broker.emit(`meta.socket_client.disconnected:${fetchId}`, {
|
|
@@ -1861,13 +1879,15 @@ var SocketController = class _SocketController {
|
|
|
1861
1879
|
serviceAddress,
|
|
1862
1880
|
servicePort
|
|
1863
1881
|
});
|
|
1882
|
+
handshake = false;
|
|
1864
1883
|
});
|
|
1884
|
+
socket.connect();
|
|
1865
1885
|
CadenzaService.createEphemeralMetaTask(
|
|
1866
1886
|
`Handshake with ${URL}`,
|
|
1867
|
-
(
|
|
1887
|
+
async () => {
|
|
1868
1888
|
console.log("SocketClient: HANDSHAKING", URL);
|
|
1869
1889
|
handshake = true;
|
|
1870
|
-
|
|
1890
|
+
await emitWhenReady(
|
|
1871
1891
|
"handshake",
|
|
1872
1892
|
{
|
|
1873
1893
|
serviceInstanceId: CadenzaService.serviceRegistry.serviceInstanceId,
|
|
@@ -1875,8 +1895,9 @@ var SocketController = class _SocketController {
|
|
|
1875
1895
|
isFrontend: isBrowser,
|
|
1876
1896
|
__status: "success"
|
|
1877
1897
|
},
|
|
1898
|
+
1e4,
|
|
1878
1899
|
(result) => {
|
|
1879
|
-
console.log("handshake result", result);
|
|
1900
|
+
console.log("Socket handshake result", result);
|
|
1880
1901
|
}
|
|
1881
1902
|
);
|
|
1882
1903
|
},
|
|
@@ -1891,8 +1912,11 @@ var SocketController = class _SocketController {
|
|
|
1891
1912
|
return new Promise((resolve, reject) => {
|
|
1892
1913
|
delete ctx2.__isSubMeta;
|
|
1893
1914
|
console.log("Socket Delegate:", socket.connected, ctx2);
|
|
1894
|
-
|
|
1895
|
-
|
|
1915
|
+
emitWhenReady(
|
|
1916
|
+
"delegation",
|
|
1917
|
+
ctx2,
|
|
1918
|
+
2e4,
|
|
1919
|
+
(resultContext) => {
|
|
1896
1920
|
console.log("Resolved socket delegate", resultContext);
|
|
1897
1921
|
const metadata = resultContext.__metadata;
|
|
1898
1922
|
delete resultContext.__metadata;
|
|
@@ -1904,11 +1928,8 @@ var SocketController = class _SocketController {
|
|
|
1904
1928
|
}
|
|
1905
1929
|
);
|
|
1906
1930
|
resolve(resultContext);
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1909
|
-
console.log("Socket Delegate Error:", e);
|
|
1910
|
-
reject(e);
|
|
1911
|
-
}
|
|
1931
|
+
}
|
|
1932
|
+
);
|
|
1912
1933
|
});
|
|
1913
1934
|
},
|
|
1914
1935
|
`Delegate flow to service ${serviceName} with address ${URL}`
|
|
@@ -1919,23 +1940,8 @@ var SocketController = class _SocketController {
|
|
|
1919
1940
|
if (ctx2.__signalName === void 0) {
|
|
1920
1941
|
return;
|
|
1921
1942
|
}
|
|
1922
|
-
return new Promise((resolve
|
|
1923
|
-
|
|
1924
|
-
if (err) {
|
|
1925
|
-
console.log("socket error:", err);
|
|
1926
|
-
response = {
|
|
1927
|
-
__error: `Timeout error: ${err}`,
|
|
1928
|
-
errored: true,
|
|
1929
|
-
...ctx2,
|
|
1930
|
-
...ctx2.__metadata
|
|
1931
|
-
};
|
|
1932
|
-
emit(
|
|
1933
|
-
`meta.socket_client.signal_transmission_failed`,
|
|
1934
|
-
response
|
|
1935
|
-
);
|
|
1936
|
-
resolve(response);
|
|
1937
|
-
return;
|
|
1938
|
-
}
|
|
1943
|
+
return new Promise((resolve) => {
|
|
1944
|
+
emitWhenReady("signal", ctx2, 1e4, (response) => {
|
|
1939
1945
|
if (ctx2.__routineExecId) {
|
|
1940
1946
|
emit(
|
|
1941
1947
|
`meta.socket_client.transmitted:${ctx2.__routineExecId}`,
|
|
@@ -2047,7 +2053,6 @@ var SignalController = class _SignalController {
|
|
|
2047
2053
|
ctx.__emitterSignalName = __signalName;
|
|
2048
2054
|
ctx.__signalName = "meta.signal_controller.foreign_signal_registered";
|
|
2049
2055
|
ctx.__remoteServiceName = serviceName;
|
|
2050
|
-
console.log("REMOTE SIGNAL DETECTED", ctx);
|
|
2051
2056
|
if (serviceName === "*") {
|
|
2052
2057
|
emit("meta.signal_controller.wildcard_signal_registered", ctx);
|
|
2053
2058
|
} else {
|
|
@@ -2078,11 +2083,6 @@ var SignalController = class _SignalController {
|
|
|
2078
2083
|
).doAfter(CadenzaService.serviceRegistry.getRemoteSignalsTask);
|
|
2079
2084
|
CadenzaService.createMetaTask("Handle foreign signal registration", (ctx) => {
|
|
2080
2085
|
const { __emitterSignalName, __listenerServiceName } = ctx;
|
|
2081
|
-
console.log(
|
|
2082
|
-
"CREATING SIGNAL TRANSMISSION",
|
|
2083
|
-
__emitterSignalName,
|
|
2084
|
-
__listenerServiceName
|
|
2085
|
-
);
|
|
2086
2086
|
CadenzaService.createSignalTransmissionTask(
|
|
2087
2087
|
__emitterSignalName,
|
|
2088
2088
|
__listenerServiceName
|
|
@@ -2903,7 +2903,6 @@ var DatabaseController = class _DatabaseController {
|
|
|
2903
2903
|
}
|
|
2904
2904
|
}
|
|
2905
2905
|
}
|
|
2906
|
-
console.log("DDL applied");
|
|
2907
2906
|
return true;
|
|
2908
2907
|
},
|
|
2909
2908
|
"Applies generated DDL to the database"
|
|
@@ -3573,7 +3572,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
3573
3572
|
for (const task of __tasks) {
|
|
3574
3573
|
if (task.registered) continue;
|
|
3575
3574
|
task.registered = true;
|
|
3576
|
-
console.log("REGISTERING TASK", task.name);
|
|
3577
3575
|
const { __functionString, __getTagCallback } = task.export();
|
|
3578
3576
|
emit("meta.sync_controller.task_added", {
|
|
3579
3577
|
data: {
|