@coasys/ad4m-connect 0.13.1-staging.1 → 0.13.1-staging.2
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/core.js +2606 -721
- package/dist/core.js.map +3 -3
- package/dist/index.js +2606 -721
- package/dist/index.js.map +3 -3
- package/dist/utils.js +1 -1
- package/dist/web.js +1145 -479
- package/dist/web.js.map +3 -3
- package/package.json +3 -3
package/dist/core.js
CHANGED
|
@@ -39,7 +39,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// ../package.json
|
|
42
|
-
var version = "0.13.1-staging.
|
|
42
|
+
var version = "0.13.1-staging.2";
|
|
43
43
|
|
|
44
44
|
// src/utils.ts
|
|
45
45
|
function isEmbedded() {
|
|
@@ -260,6 +260,7 @@ function callSafely(callback, label, ...args) {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
var READ_METHODS = /* @__PURE__ */ new Set([
|
|
263
|
+
"agent.byDIDs",
|
|
263
264
|
"agent.byDid",
|
|
264
265
|
"agent.entanglementProofPreflight",
|
|
265
266
|
"agent.get",
|
|
@@ -287,8 +288,11 @@ var READ_METHODS = /* @__PURE__ */ new Set([
|
|
|
287
288
|
"neighbourhood.hasTelepresence",
|
|
288
289
|
"neighbourhood.onlineAgents",
|
|
289
290
|
"neighbourhood.otherAgents",
|
|
291
|
+
"neighbourhood.ownOnlineStatus",
|
|
290
292
|
"perspective.all",
|
|
291
293
|
"perspective.evaluateGetters",
|
|
294
|
+
"perspective.flowFired",
|
|
295
|
+
"perspective.flowStates",
|
|
292
296
|
"perspective.flowValidOutputs",
|
|
293
297
|
"perspective.get",
|
|
294
298
|
"perspective.getAllShacl",
|
|
@@ -323,6 +327,14 @@ var READ_METHODS = /* @__PURE__ */ new Set([
|
|
|
323
327
|
"runtime.unytWalletBalance",
|
|
324
328
|
"runtime.unytWalletHistory",
|
|
325
329
|
"runtime.verifySignature",
|
|
330
|
+
"sfu.cascadeStatus",
|
|
331
|
+
"sfu.getConfig",
|
|
332
|
+
"sfu.listRooms",
|
|
333
|
+
"sfu.qualityPreferences",
|
|
334
|
+
"sfu.servesAllMembers",
|
|
335
|
+
"sfu.sfuPeerForNeighbourhood",
|
|
336
|
+
"sfu.sfuPeersForNeighbourhood",
|
|
337
|
+
"sfu.status",
|
|
326
338
|
"user.list",
|
|
327
339
|
"user.multiUserEnabled",
|
|
328
340
|
"user.wallet"
|
|
@@ -881,7 +893,7 @@ var AgentStatus = class {
|
|
|
881
893
|
}
|
|
882
894
|
}
|
|
883
895
|
};
|
|
884
|
-
var __classPrivateFieldSet$
|
|
896
|
+
var __classPrivateFieldSet$d = function(receiver, state, value, kind, f) {
|
|
885
897
|
if (kind === "m")
|
|
886
898
|
throw new TypeError("Private method is not writable");
|
|
887
899
|
if (kind === "a" && !f)
|
|
@@ -890,7 +902,7 @@ var __classPrivateFieldSet$c = function(receiver, state, value, kind, f) {
|
|
|
890
902
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
891
903
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
892
904
|
};
|
|
893
|
-
var __classPrivateFieldGet$
|
|
905
|
+
var __classPrivateFieldGet$d = function(receiver, state, kind, f) {
|
|
894
906
|
if (kind === "a" && !f)
|
|
895
907
|
throw new TypeError("Private accessor was defined without a getter");
|
|
896
908
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -910,15 +922,15 @@ var IDBCache = class {
|
|
|
910
922
|
_IDBCache_storeName.set(this, void 0);
|
|
911
923
|
_IDBCache_dbPromise.set(this, null);
|
|
912
924
|
_IDBCache_version.set(this, 1);
|
|
913
|
-
__classPrivateFieldSet$
|
|
914
|
-
__classPrivateFieldSet$
|
|
925
|
+
__classPrivateFieldSet$d(this, _IDBCache_dbName, dbName, "f");
|
|
926
|
+
__classPrivateFieldSet$d(this, _IDBCache_storeName, storeName, "f");
|
|
915
927
|
}
|
|
916
928
|
async get(key) {
|
|
917
929
|
try {
|
|
918
|
-
const db = await __classPrivateFieldGet$
|
|
930
|
+
const db = await __classPrivateFieldGet$d(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
919
931
|
return new Promise((resolve) => {
|
|
920
|
-
const tx = db.transaction(__classPrivateFieldGet$
|
|
921
|
-
const store = tx.objectStore(__classPrivateFieldGet$
|
|
932
|
+
const tx = db.transaction(__classPrivateFieldGet$d(this, _IDBCache_storeName, "f"), "readonly");
|
|
933
|
+
const store = tx.objectStore(__classPrivateFieldGet$d(this, _IDBCache_storeName, "f"));
|
|
922
934
|
const req = store.get(key);
|
|
923
935
|
req.onsuccess = () => resolve(req.result ?? void 0);
|
|
924
936
|
req.onerror = () => resolve(void 0);
|
|
@@ -929,10 +941,10 @@ var IDBCache = class {
|
|
|
929
941
|
}
|
|
930
942
|
async put(key, value) {
|
|
931
943
|
try {
|
|
932
|
-
const db = await __classPrivateFieldGet$
|
|
944
|
+
const db = await __classPrivateFieldGet$d(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
933
945
|
return new Promise((resolve) => {
|
|
934
|
-
const tx = db.transaction(__classPrivateFieldGet$
|
|
935
|
-
const store = tx.objectStore(__classPrivateFieldGet$
|
|
946
|
+
const tx = db.transaction(__classPrivateFieldGet$d(this, _IDBCache_storeName, "f"), "readwrite");
|
|
947
|
+
const store = tx.objectStore(__classPrivateFieldGet$d(this, _IDBCache_storeName, "f"));
|
|
936
948
|
store.put(value, key);
|
|
937
949
|
tx.oncomplete = () => resolve();
|
|
938
950
|
tx.onerror = () => resolve();
|
|
@@ -942,10 +954,10 @@ var IDBCache = class {
|
|
|
942
954
|
}
|
|
943
955
|
async delete(key) {
|
|
944
956
|
try {
|
|
945
|
-
const db = await __classPrivateFieldGet$
|
|
957
|
+
const db = await __classPrivateFieldGet$d(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
946
958
|
return new Promise((resolve) => {
|
|
947
|
-
const tx = db.transaction(__classPrivateFieldGet$
|
|
948
|
-
const store = tx.objectStore(__classPrivateFieldGet$
|
|
959
|
+
const tx = db.transaction(__classPrivateFieldGet$d(this, _IDBCache_storeName, "f"), "readwrite");
|
|
960
|
+
const store = tx.objectStore(__classPrivateFieldGet$d(this, _IDBCache_storeName, "f"));
|
|
949
961
|
store.delete(key);
|
|
950
962
|
tx.oncomplete = () => resolve();
|
|
951
963
|
tx.onerror = () => resolve();
|
|
@@ -955,10 +967,10 @@ var IDBCache = class {
|
|
|
955
967
|
}
|
|
956
968
|
async clear() {
|
|
957
969
|
try {
|
|
958
|
-
const db = await __classPrivateFieldGet$
|
|
970
|
+
const db = await __classPrivateFieldGet$d(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
959
971
|
return new Promise((resolve) => {
|
|
960
|
-
const tx = db.transaction(__classPrivateFieldGet$
|
|
961
|
-
const store = tx.objectStore(__classPrivateFieldGet$
|
|
972
|
+
const tx = db.transaction(__classPrivateFieldGet$d(this, _IDBCache_storeName, "f"), "readwrite");
|
|
973
|
+
const store = tx.objectStore(__classPrivateFieldGet$d(this, _IDBCache_storeName, "f"));
|
|
962
974
|
store.clear();
|
|
963
975
|
tx.oncomplete = () => resolve();
|
|
964
976
|
tx.onerror = () => resolve();
|
|
@@ -968,10 +980,10 @@ var IDBCache = class {
|
|
|
968
980
|
}
|
|
969
981
|
};
|
|
970
982
|
_IDBCache_dbName = /* @__PURE__ */ new WeakMap(), _IDBCache_storeName = /* @__PURE__ */ new WeakMap(), _IDBCache_dbPromise = /* @__PURE__ */ new WeakMap(), _IDBCache_version = /* @__PURE__ */ new WeakMap(), _IDBCache_instances = /* @__PURE__ */ new WeakSet(), _IDBCache_open = function _IDBCache_open2() {
|
|
971
|
-
if (!__classPrivateFieldGet$
|
|
972
|
-
__classPrivateFieldSet$
|
|
973
|
-
const storeName = __classPrivateFieldGet$
|
|
974
|
-
const req = indexedDB.open(__classPrivateFieldGet$
|
|
983
|
+
if (!__classPrivateFieldGet$d(this, _IDBCache_dbPromise, "f")) {
|
|
984
|
+
__classPrivateFieldSet$d(this, _IDBCache_dbPromise, new Promise((resolve, reject) => {
|
|
985
|
+
const storeName = __classPrivateFieldGet$d(this, _IDBCache_storeName, "f");
|
|
986
|
+
const req = indexedDB.open(__classPrivateFieldGet$d(this, _IDBCache_dbName, "f"), __classPrivateFieldGet$d(this, _IDBCache_version, "f"));
|
|
975
987
|
req.onupgradeneeded = () => {
|
|
976
988
|
const db = req.result;
|
|
977
989
|
if (!db.objectStoreNames.contains(storeName)) {
|
|
@@ -982,7 +994,7 @@ _IDBCache_dbName = /* @__PURE__ */ new WeakMap(), _IDBCache_storeName = /* @__PU
|
|
|
982
994
|
req.onerror = () => reject(req.error);
|
|
983
995
|
}), "f");
|
|
984
996
|
}
|
|
985
|
-
return __classPrivateFieldGet$
|
|
997
|
+
return __classPrivateFieldGet$d(this, _IDBCache_dbPromise, "f");
|
|
986
998
|
};
|
|
987
999
|
var NullCache = class {
|
|
988
1000
|
async get(_key) {
|
|
@@ -1004,7 +1016,7 @@ function createPersistentCache(dbName, storeName) {
|
|
|
1004
1016
|
}
|
|
1005
1017
|
return new NullCache();
|
|
1006
1018
|
}
|
|
1007
|
-
var __classPrivateFieldSet$
|
|
1019
|
+
var __classPrivateFieldSet$c = function(receiver, state, value, kind, f) {
|
|
1008
1020
|
if (kind === "m")
|
|
1009
1021
|
throw new TypeError("Private method is not writable");
|
|
1010
1022
|
if (kind === "a" && !f)
|
|
@@ -1013,7 +1025,7 @@ var __classPrivateFieldSet$b = function(receiver, state, value, kind, f) {
|
|
|
1013
1025
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1014
1026
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1015
1027
|
};
|
|
1016
|
-
var __classPrivateFieldGet$
|
|
1028
|
+
var __classPrivateFieldGet$c = function(receiver, state, kind, f) {
|
|
1017
1029
|
if (kind === "a" && !f)
|
|
1018
1030
|
throw new TypeError("Private accessor was defined without a getter");
|
|
1019
1031
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -1040,74 +1052,74 @@ var AgentClient = class {
|
|
|
1040
1052
|
_AgentClient_persistent.set(this, void 0);
|
|
1041
1053
|
_AgentClient_selfDid.set(this, null);
|
|
1042
1054
|
_AgentClient_onAgentUpdated.set(this, (event) => {
|
|
1043
|
-
__classPrivateFieldGet$
|
|
1055
|
+
__classPrivateFieldGet$c(this, _AgentClient_instances, "m", _AgentClient_cacheAgent).call(this, Agent.fromWire(event.agent));
|
|
1044
1056
|
});
|
|
1045
|
-
__classPrivateFieldSet$
|
|
1046
|
-
__classPrivateFieldSet$
|
|
1057
|
+
__classPrivateFieldSet$c(this, _AgentClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
|
|
1058
|
+
__classPrivateFieldSet$c(this, _AgentClient_persistent, createPersistentCache("ad4m-agent-cache", "agents"), "f");
|
|
1047
1059
|
}
|
|
1048
1060
|
async me() {
|
|
1049
|
-
const agentObject = toAgent(await __classPrivateFieldGet$
|
|
1050
|
-
if (agentObject.did && !__classPrivateFieldGet$
|
|
1051
|
-
__classPrivateFieldSet$
|
|
1061
|
+
const agentObject = toAgent(await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.get", {}));
|
|
1062
|
+
if (agentObject.did && !__classPrivateFieldGet$c(this, _AgentClient_selfDid, "f")) {
|
|
1063
|
+
__classPrivateFieldSet$c(this, _AgentClient_selfDid, agentObject.did, "f");
|
|
1052
1064
|
}
|
|
1053
1065
|
return agentObject;
|
|
1054
1066
|
}
|
|
1055
1067
|
async status() {
|
|
1056
|
-
const agentStatus = await __classPrivateFieldGet$
|
|
1068
|
+
const agentStatus = await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.status", {});
|
|
1057
1069
|
return new AgentStatus(agentStatus);
|
|
1058
1070
|
}
|
|
1059
1071
|
async generate(passphrase, options) {
|
|
1060
|
-
const result = await __classPrivateFieldGet$
|
|
1072
|
+
const result = await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.generate", { passphrase }, options);
|
|
1061
1073
|
return new AgentStatus(result);
|
|
1062
1074
|
}
|
|
1063
1075
|
async import(args) {
|
|
1064
|
-
const result = await __classPrivateFieldGet$
|
|
1076
|
+
const result = await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.import", { ...args });
|
|
1065
1077
|
return new AgentStatus(result);
|
|
1066
1078
|
}
|
|
1067
1079
|
async lock(passphrase) {
|
|
1068
|
-
const result = await __classPrivateFieldGet$
|
|
1080
|
+
const result = await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.lock", { passphrase });
|
|
1069
1081
|
return new AgentStatus(result);
|
|
1070
1082
|
}
|
|
1071
1083
|
async unlock(passphrase, holochain = true, options) {
|
|
1072
|
-
const result = await __classPrivateFieldGet$
|
|
1084
|
+
const result = await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.unlock", { passphrase, holochain }, options);
|
|
1073
1085
|
return new AgentStatus(result);
|
|
1074
1086
|
}
|
|
1075
1087
|
async byDID(did) {
|
|
1076
|
-
__classPrivateFieldGet$
|
|
1088
|
+
__classPrivateFieldGet$c(this, _AgentClient_instances, "m", _AgentClient_listen).call(this);
|
|
1077
1089
|
const now = Date.now();
|
|
1078
|
-
const cached = __classPrivateFieldGet$
|
|
1090
|
+
const cached = __classPrivateFieldGet$c(this, _AgentClient_memCache, "f").get(did);
|
|
1079
1091
|
if (cached) {
|
|
1080
|
-
const isSelf = did === __classPrivateFieldGet$
|
|
1092
|
+
const isSelf = did === __classPrivateFieldGet$c(this, _AgentClient_selfDid, "f");
|
|
1081
1093
|
if (isSelf || now - cached.ts < AgentClient.REMOTE_AGENT_TTL_MS) {
|
|
1082
1094
|
return cached.promise;
|
|
1083
1095
|
}
|
|
1084
1096
|
}
|
|
1085
1097
|
const promise = (async () => {
|
|
1086
|
-
const entry = await __classPrivateFieldGet$
|
|
1098
|
+
const entry = await __classPrivateFieldGet$c(this, _AgentClient_persistent, "f").get(did);
|
|
1087
1099
|
if (entry?.agent && now - (entry.ts ?? 0) < AgentClient.REMOTE_AGENT_TTL_L2_MS) {
|
|
1088
1100
|
return entry.agent;
|
|
1089
1101
|
}
|
|
1090
|
-
const result = toAgent(await __classPrivateFieldGet$
|
|
1091
|
-
__classPrivateFieldGet$
|
|
1102
|
+
const result = toAgent(await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.byDid", { did }));
|
|
1103
|
+
__classPrivateFieldGet$c(this, _AgentClient_persistent, "f").put(did, { agent: result, ts: Date.now() });
|
|
1092
1104
|
return result;
|
|
1093
1105
|
})();
|
|
1094
|
-
__classPrivateFieldGet$
|
|
1106
|
+
__classPrivateFieldGet$c(this, _AgentClient_memCache, "f").set(did, { promise, ts: now });
|
|
1095
1107
|
promise.catch(() => {
|
|
1096
|
-
if (__classPrivateFieldGet$
|
|
1097
|
-
__classPrivateFieldGet$
|
|
1108
|
+
if (__classPrivateFieldGet$c(this, _AgentClient_memCache, "f").get(did)?.promise === promise) {
|
|
1109
|
+
__classPrivateFieldGet$c(this, _AgentClient_memCache, "f").delete(did);
|
|
1098
1110
|
}
|
|
1099
1111
|
});
|
|
1100
1112
|
return promise;
|
|
1101
1113
|
}
|
|
1102
1114
|
setSelfDid(did) {
|
|
1103
|
-
__classPrivateFieldSet$
|
|
1115
|
+
__classPrivateFieldSet$c(this, _AgentClient_selfDid, did, "f");
|
|
1104
1116
|
}
|
|
1105
1117
|
invalidateByDid(did) {
|
|
1106
|
-
__classPrivateFieldGet$
|
|
1107
|
-
__classPrivateFieldGet$
|
|
1118
|
+
__classPrivateFieldGet$c(this, _AgentClient_memCache, "f").delete(did);
|
|
1119
|
+
__classPrivateFieldGet$c(this, _AgentClient_persistent, "f").delete(did);
|
|
1108
1120
|
}
|
|
1109
1121
|
clearByDidCache() {
|
|
1110
|
-
__classPrivateFieldGet$
|
|
1122
|
+
__classPrivateFieldGet$c(this, _AgentClient_memCache, "f").clear();
|
|
1111
1123
|
}
|
|
1112
1124
|
async updatePublicPerspective(perspective) {
|
|
1113
1125
|
const publicPerspective = {
|
|
@@ -1118,71 +1130,71 @@ var AgentClient = class {
|
|
|
1118
1130
|
proof: { key: proof.key, signature: proof.signature, valid: proof.valid, invalid: proof.invalid }
|
|
1119
1131
|
}))
|
|
1120
1132
|
};
|
|
1121
|
-
const agent = toAgent(await __classPrivateFieldGet$
|
|
1122
|
-
__classPrivateFieldGet$
|
|
1133
|
+
const agent = toAgent(await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.updateProfile", { publicPerspective }));
|
|
1134
|
+
__classPrivateFieldGet$c(this, _AgentClient_instances, "m", _AgentClient_cacheAgent).call(this, agent);
|
|
1123
1135
|
return agent;
|
|
1124
1136
|
}
|
|
1125
1137
|
async mutatePublicPerspective({ additions, removals }) {
|
|
1126
|
-
const added = additions.length > 0 ? await __classPrivateFieldGet$
|
|
1138
|
+
const added = additions.length > 0 ? await __classPrivateFieldGet$c(this, _AgentClient_instances, "m", _AgentClient_signLinks).call(this, additions) : [];
|
|
1127
1139
|
const { perspective } = await this.me();
|
|
1128
1140
|
const kept = (perspective?.links ?? []).filter((link) => !removals.some((r) => linkEqual(link, r)));
|
|
1129
1141
|
return this.updatePublicPerspective({ links: [...kept, ...added] });
|
|
1130
1142
|
}
|
|
1131
1143
|
async updateDirectMessageLanguage(directMessageLanguage) {
|
|
1132
|
-
const agent = toAgent(await __classPrivateFieldGet$
|
|
1133
|
-
__classPrivateFieldGet$
|
|
1144
|
+
const agent = toAgent(await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.updateProfile", { dmLanguage: directMessageLanguage }));
|
|
1145
|
+
__classPrivateFieldGet$c(this, _AgentClient_instances, "m", _AgentClient_cacheAgent).call(this, agent);
|
|
1134
1146
|
return agent;
|
|
1135
1147
|
}
|
|
1136
1148
|
async addEntanglementProofs(proofs) {
|
|
1137
|
-
return __classPrivateFieldGet$
|
|
1149
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.addEntanglementProofs", { proofs });
|
|
1138
1150
|
}
|
|
1139
1151
|
async deleteEntanglementProofs(proofs) {
|
|
1140
|
-
return __classPrivateFieldGet$
|
|
1152
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.deleteEntanglementProofs", { proofs });
|
|
1141
1153
|
}
|
|
1142
1154
|
async getEntanglementProofs() {
|
|
1143
|
-
return __classPrivateFieldGet$
|
|
1155
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.getEntanglementProofs", {});
|
|
1144
1156
|
}
|
|
1145
1157
|
async entanglementProofPreFlight(deviceKey, deviceKeyType) {
|
|
1146
|
-
return __classPrivateFieldGet$
|
|
1158
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.entanglementProofPreflight", { deviceKey, deviceKeyType });
|
|
1147
1159
|
}
|
|
1148
1160
|
async requestCapability(authInfo) {
|
|
1149
|
-
return __classPrivateFieldGet$
|
|
1161
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.requestCapability", { authInfo });
|
|
1150
1162
|
}
|
|
1151
1163
|
async permitCapability(auth) {
|
|
1152
|
-
return __classPrivateFieldGet$
|
|
1164
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.permitCapability", { auth });
|
|
1153
1165
|
}
|
|
1154
1166
|
async generateJwt(requestId, rand) {
|
|
1155
|
-
return __classPrivateFieldGet$
|
|
1167
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.generateJwt", { requestId, rand });
|
|
1156
1168
|
}
|
|
1157
1169
|
async getApps() {
|
|
1158
|
-
return __classPrivateFieldGet$
|
|
1170
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.getApps", {});
|
|
1159
1171
|
}
|
|
1160
1172
|
async removeApp(requestId) {
|
|
1161
|
-
return __classPrivateFieldGet$
|
|
1173
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.removeApp", { id: requestId });
|
|
1162
1174
|
}
|
|
1163
1175
|
async revokeToken(requestId) {
|
|
1164
|
-
return __classPrivateFieldGet$
|
|
1176
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.revokeToken", { token: requestId });
|
|
1165
1177
|
}
|
|
1166
1178
|
async isLocked() {
|
|
1167
|
-
return __classPrivateFieldGet$
|
|
1179
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.isLocked", {});
|
|
1168
1180
|
}
|
|
1169
1181
|
async signMessage(message) {
|
|
1170
|
-
return __classPrivateFieldGet$
|
|
1182
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("agent.sign", { message });
|
|
1171
1183
|
}
|
|
1172
1184
|
async createUser(email, password) {
|
|
1173
|
-
return __classPrivateFieldGet$
|
|
1185
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("user.create", { email, password });
|
|
1174
1186
|
}
|
|
1175
1187
|
async loginUser(email, password) {
|
|
1176
|
-
return __classPrivateFieldGet$
|
|
1188
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("user.login", { email, password });
|
|
1177
1189
|
}
|
|
1178
1190
|
async requestLoginVerification(email, appInfo) {
|
|
1179
|
-
return __classPrivateFieldGet$
|
|
1191
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("user.requestVerification", { email, appInfo });
|
|
1180
1192
|
}
|
|
1181
1193
|
async verifyEmailCode(email, code2, verificationType) {
|
|
1182
|
-
return __classPrivateFieldGet$
|
|
1194
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("user.verifyEmail", { email, code: code2, verificationType });
|
|
1183
1195
|
}
|
|
1184
1196
|
async hostingUserInfo() {
|
|
1185
|
-
const info = (await __classPrivateFieldGet$
|
|
1197
|
+
const info = (await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("hosting.info", {})).userInfo ?? {
|
|
1186
1198
|
email: "",
|
|
1187
1199
|
credits: null,
|
|
1188
1200
|
hotWalletAddress: null,
|
|
@@ -1191,34 +1203,34 @@ var AgentClient = class {
|
|
|
1191
1203
|
return new HostingUserInfo(info.email, info.freeAccess ? "unlimited" : String(info.credits ?? 0), info.hotWalletAddress || void 0, !!info.freeAccess);
|
|
1192
1204
|
}
|
|
1193
1205
|
async computeLog(since, limit, userEmail) {
|
|
1194
|
-
return __classPrivateFieldGet$
|
|
1206
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("runtime.computeLog", { since, limit, userEmail });
|
|
1195
1207
|
}
|
|
1196
1208
|
async setHotWalletAddress(address) {
|
|
1197
|
-
return __classPrivateFieldGet$
|
|
1209
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("hosting.setHotWallet", { address });
|
|
1198
1210
|
}
|
|
1199
1211
|
async requestPayment(amountHOT) {
|
|
1200
|
-
return __classPrivateFieldGet$
|
|
1212
|
+
return __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("hosting.requestPayment", { amountHOT });
|
|
1201
1213
|
}
|
|
1202
1214
|
};
|
|
1203
1215
|
_AgentClient_apiClient = /* @__PURE__ */ new WeakMap(), _AgentClient_memCache = /* @__PURE__ */ new WeakMap(), _AgentClient_persistent = /* @__PURE__ */ new WeakMap(), _AgentClient_selfDid = /* @__PURE__ */ new WeakMap(), _AgentClient_onAgentUpdated = /* @__PURE__ */ new WeakMap(), _AgentClient_instances = /* @__PURE__ */ new WeakSet(), _AgentClient_cacheAgent = function _AgentClient_cacheAgent2(agent) {
|
|
1204
1216
|
if (!agent.did)
|
|
1205
1217
|
return;
|
|
1206
|
-
__classPrivateFieldGet$
|
|
1207
|
-
__classPrivateFieldGet$
|
|
1208
|
-
__classPrivateFieldGet$
|
|
1218
|
+
__classPrivateFieldGet$c(this, _AgentClient_memCache, "f").set(agent.did, { promise: Promise.resolve(agent), ts: Date.now() });
|
|
1219
|
+
__classPrivateFieldGet$c(this, _AgentClient_persistent, "f").put(agent.did, { agent, ts: Date.now() });
|
|
1220
|
+
__classPrivateFieldGet$c(this, _AgentClient_instances, "m", _AgentClient_listen).call(this);
|
|
1209
1221
|
}, _AgentClient_signLinks = async function _AgentClient_signLinks2(links) {
|
|
1210
|
-
const { uuid } = await __classPrivateFieldGet$
|
|
1222
|
+
const { uuid } = await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("perspective.create", { name: "Agent Perspective Proxy" });
|
|
1211
1223
|
try {
|
|
1212
|
-
return (await __classPrivateFieldGet$
|
|
1224
|
+
return (await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("perspective.addLinks", { uuid, links, status: "SHARED" })).map(LinkExpression.fromWire);
|
|
1213
1225
|
} finally {
|
|
1214
|
-
await __classPrivateFieldGet$
|
|
1226
|
+
await __classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").call("perspective.remove", { uuid });
|
|
1215
1227
|
}
|
|
1216
1228
|
}, _AgentClient_listen = function _AgentClient_listen2() {
|
|
1217
|
-
__classPrivateFieldGet$
|
|
1229
|
+
__classPrivateFieldGet$c(this, _AgentClient_apiClient, "f").on("agent-updated", __classPrivateFieldGet$c(this, _AgentClient_onAgentUpdated, "f"));
|
|
1218
1230
|
};
|
|
1219
1231
|
AgentClient.REMOTE_AGENT_TTL_MS = 5 * 6e4;
|
|
1220
1232
|
AgentClient.REMOTE_AGENT_TTL_L2_MS = 5 * 6e4;
|
|
1221
|
-
var __classPrivateFieldSet$
|
|
1233
|
+
var __classPrivateFieldSet$b = function(receiver, state, value, kind, f) {
|
|
1222
1234
|
if (kind === "m")
|
|
1223
1235
|
throw new TypeError("Private method is not writable");
|
|
1224
1236
|
if (kind === "a" && !f)
|
|
@@ -1227,7 +1239,7 @@ var __classPrivateFieldSet$a = function(receiver, state, value, kind, f) {
|
|
|
1227
1239
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1228
1240
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1229
1241
|
};
|
|
1230
|
-
var __classPrivateFieldGet$
|
|
1242
|
+
var __classPrivateFieldGet$b = function(receiver, state, kind, f) {
|
|
1231
1243
|
if (kind === "a" && !f)
|
|
1232
1244
|
throw new TypeError("Private accessor was defined without a getter");
|
|
1233
1245
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -1238,34 +1250,34 @@ var _LanguageClient_apiClient;
|
|
|
1238
1250
|
var LanguageClient = class {
|
|
1239
1251
|
constructor(baseUrl, token, sharedApiClient) {
|
|
1240
1252
|
_LanguageClient_apiClient.set(this, void 0);
|
|
1241
|
-
__classPrivateFieldSet$
|
|
1253
|
+
__classPrivateFieldSet$b(this, _LanguageClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
|
|
1242
1254
|
}
|
|
1243
1255
|
async byAddress(address) {
|
|
1244
|
-
return __classPrivateFieldGet$
|
|
1256
|
+
return __classPrivateFieldGet$b(this, _LanguageClient_apiClient, "f").call("language.get", { address });
|
|
1245
1257
|
}
|
|
1246
1258
|
async byFilter(filter) {
|
|
1247
|
-
return __classPrivateFieldGet$
|
|
1259
|
+
return __classPrivateFieldGet$b(this, _LanguageClient_apiClient, "f").call("language.all", { filter });
|
|
1248
1260
|
}
|
|
1249
1261
|
async all() {
|
|
1250
|
-
return __classPrivateFieldGet$
|
|
1262
|
+
return __classPrivateFieldGet$b(this, _LanguageClient_apiClient, "f").call("language.all", {});
|
|
1251
1263
|
}
|
|
1252
1264
|
async writeSettings(languageAddress, settings) {
|
|
1253
|
-
return __classPrivateFieldGet$
|
|
1265
|
+
return __classPrivateFieldGet$b(this, _LanguageClient_apiClient, "f").call("language.writeSettings", { address: languageAddress, settings });
|
|
1254
1266
|
}
|
|
1255
1267
|
async applyTemplateAndPublish(sourceLanguageHash, templateData, options) {
|
|
1256
|
-
return __classPrivateFieldGet$
|
|
1268
|
+
return __classPrivateFieldGet$b(this, _LanguageClient_apiClient, "f").call("language.applyTemplate", { sourceLanguageHash, templateData }, options);
|
|
1257
1269
|
}
|
|
1258
1270
|
async publish(languagePath, languageMeta, options) {
|
|
1259
|
-
return __classPrivateFieldGet$
|
|
1271
|
+
return __classPrivateFieldGet$b(this, _LanguageClient_apiClient, "f").call("language.publish", { languagePath, languageMeta }, options);
|
|
1260
1272
|
}
|
|
1261
1273
|
async meta(address) {
|
|
1262
|
-
return __classPrivateFieldGet$
|
|
1274
|
+
return __classPrivateFieldGet$b(this, _LanguageClient_apiClient, "f").call("language.meta", { address });
|
|
1263
1275
|
}
|
|
1264
1276
|
async source(address) {
|
|
1265
|
-
return __classPrivateFieldGet$
|
|
1277
|
+
return __classPrivateFieldGet$b(this, _LanguageClient_apiClient, "f").call("language.source", { address });
|
|
1266
1278
|
}
|
|
1267
1279
|
async remove(address) {
|
|
1268
|
-
return __classPrivateFieldGet$
|
|
1280
|
+
return __classPrivateFieldGet$b(this, _LanguageClient_apiClient, "f").call("language.remove", { address });
|
|
1269
1281
|
}
|
|
1270
1282
|
};
|
|
1271
1283
|
_LanguageClient_apiClient = /* @__PURE__ */ new WeakMap();
|
|
@@ -1307,7 +1319,7 @@ function neighbourhoodExpressionFromWire(wire) {
|
|
|
1307
1319
|
const meta = new Perspective(wire.data.meta.links.map(LinkExpression.fromWire));
|
|
1308
1320
|
return new NeighbourhoodExpression(wire.author, wire.timestamp, new Neighbourhood(wire.data.linkLanguage, meta), wire.proof);
|
|
1309
1321
|
}
|
|
1310
|
-
var __classPrivateFieldSet$
|
|
1322
|
+
var __classPrivateFieldSet$a = function(receiver, state, value, kind, f) {
|
|
1311
1323
|
if (kind === "m")
|
|
1312
1324
|
throw new TypeError("Private method is not writable");
|
|
1313
1325
|
if (kind === "a" && !f)
|
|
@@ -1316,7 +1328,7 @@ var __classPrivateFieldSet$9 = function(receiver, state, value, kind, f) {
|
|
|
1316
1328
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1317
1329
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1318
1330
|
};
|
|
1319
|
-
var __classPrivateFieldGet$
|
|
1331
|
+
var __classPrivateFieldGet$a = function(receiver, state, kind, f) {
|
|
1320
1332
|
if (kind === "a" && !f)
|
|
1321
1333
|
throw new TypeError("Private accessor was defined without a getter");
|
|
1322
1334
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -1331,43 +1343,47 @@ var NeighbourhoodClient = class {
|
|
|
1331
1343
|
_NeighbourhoodClient_apiClient.set(this, void 0);
|
|
1332
1344
|
_NeighbourhoodClient_signalHandlers.set(this, /* @__PURE__ */ new Map());
|
|
1333
1345
|
_NeighbourhoodClient_signalUnsubscribers.set(this, /* @__PURE__ */ new Map());
|
|
1334
|
-
__classPrivateFieldSet$
|
|
1346
|
+
__classPrivateFieldSet$a(this, _NeighbourhoodClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
|
|
1335
1347
|
}
|
|
1336
1348
|
async publishFromPerspective(perspectiveUUID, linkLanguage, meta, options) {
|
|
1337
|
-
return __classPrivateFieldGet$
|
|
1349
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.publish", {
|
|
1338
1350
|
perspectiveUuid: perspectiveUUID,
|
|
1339
1351
|
linkLanguage,
|
|
1340
1352
|
meta: Perspective.toWire(meta)
|
|
1341
1353
|
}, options);
|
|
1342
1354
|
}
|
|
1343
1355
|
async joinFromUrl(url, options) {
|
|
1344
|
-
return PerspectiveHandle.fromWire(await __classPrivateFieldGet$
|
|
1356
|
+
return PerspectiveHandle.fromWire(await __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.join", { url }, options));
|
|
1345
1357
|
}
|
|
1346
1358
|
async otherAgents(perspectiveUUID) {
|
|
1347
|
-
return __classPrivateFieldGet$
|
|
1359
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.otherAgents", { uuid: perspectiveUUID });
|
|
1348
1360
|
}
|
|
1349
1361
|
async hasTelepresenceAdapter(perspectiveUUID) {
|
|
1350
|
-
return __classPrivateFieldGet$
|
|
1362
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.hasTelepresence", { uuid: perspectiveUUID });
|
|
1351
1363
|
}
|
|
1352
1364
|
async onlineAgents(perspectiveUUID) {
|
|
1353
|
-
const agents = await __classPrivateFieldGet$
|
|
1365
|
+
const agents = await __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.onlineAgents", { uuid: perspectiveUUID });
|
|
1354
1366
|
return agents.map(({ did, status }) => ({ did, status: PerspectiveExpression.fromWire(status) }));
|
|
1355
1367
|
}
|
|
1368
|
+
async ownOnlineStatus(perspectiveUUID) {
|
|
1369
|
+
const status = await __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.ownOnlineStatus", { uuid: perspectiveUUID });
|
|
1370
|
+
return status ? PerspectiveExpression.fromWire(status) : null;
|
|
1371
|
+
}
|
|
1356
1372
|
async setOnlineStatus(perspectiveUUID, status) {
|
|
1357
|
-
return __classPrivateFieldGet$
|
|
1373
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.setOnlineStatus", { uuid: perspectiveUUID, status: Perspective.toWire(status) });
|
|
1358
1374
|
}
|
|
1359
1375
|
async setOnlineStatusU(perspectiveUUID, status) {
|
|
1360
|
-
return __classPrivateFieldGet$
|
|
1376
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.setOnlineStatus", { uuid: perspectiveUUID, status, signed: false });
|
|
1361
1377
|
}
|
|
1362
1378
|
async sendSignal(perspectiveUUID, remoteAgentDid, payload) {
|
|
1363
|
-
return __classPrivateFieldGet$
|
|
1379
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.sendSignal", {
|
|
1364
1380
|
uuid: perspectiveUUID,
|
|
1365
1381
|
remoteAgentDid,
|
|
1366
1382
|
payload: Perspective.toWire(payload)
|
|
1367
1383
|
});
|
|
1368
1384
|
}
|
|
1369
1385
|
async sendSignalU(perspectiveUUID, remoteAgentDid, payload) {
|
|
1370
|
-
return __classPrivateFieldGet$
|
|
1386
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.sendSignal", {
|
|
1371
1387
|
uuid: perspectiveUUID,
|
|
1372
1388
|
remoteAgentDid,
|
|
1373
1389
|
payload,
|
|
@@ -1375,14 +1391,14 @@ var NeighbourhoodClient = class {
|
|
|
1375
1391
|
});
|
|
1376
1392
|
}
|
|
1377
1393
|
async sendBroadcast(perspectiveUUID, payload, loopback = false) {
|
|
1378
|
-
return __classPrivateFieldGet$
|
|
1394
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.sendBroadcast", {
|
|
1379
1395
|
uuid: perspectiveUUID,
|
|
1380
1396
|
payload: Perspective.toWire(payload),
|
|
1381
1397
|
loopback
|
|
1382
1398
|
});
|
|
1383
1399
|
}
|
|
1384
1400
|
async sendBroadcastU(perspectiveUUID, payload, loopback = false) {
|
|
1385
|
-
return __classPrivateFieldGet$
|
|
1401
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("neighbourhood.sendBroadcast", {
|
|
1386
1402
|
uuid: perspectiveUUID,
|
|
1387
1403
|
payload,
|
|
1388
1404
|
loopback,
|
|
@@ -1390,7 +1406,7 @@ var NeighbourhoodClient = class {
|
|
|
1390
1406
|
});
|
|
1391
1407
|
}
|
|
1392
1408
|
dispatchSignal(perspectiveUUID, signal) {
|
|
1393
|
-
const handlers = __classPrivateFieldGet$
|
|
1409
|
+
const handlers = __classPrivateFieldGet$a(this, _NeighbourhoodClient_signalHandlers, "f").get(perspectiveUUID);
|
|
1394
1410
|
if (handlers) {
|
|
1395
1411
|
for (const handler of handlers) {
|
|
1396
1412
|
try {
|
|
@@ -1401,42 +1417,1680 @@ var NeighbourhoodClient = class {
|
|
|
1401
1417
|
}
|
|
1402
1418
|
}
|
|
1403
1419
|
}
|
|
1404
|
-
async subscribeToSignals(perspectiveUUID) {
|
|
1405
|
-
const unsub = __classPrivateFieldGet$
|
|
1406
|
-
__classPrivateFieldGet$
|
|
1407
|
-
await __classPrivateFieldGet$
|
|
1420
|
+
async subscribeToSignals(perspectiveUUID) {
|
|
1421
|
+
const unsub = __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").on("signal", (event) => this.dispatchSignal(perspectiveUUID, PerspectiveExpression.fromWire(event.signal)), { perspective: perspectiveUUID });
|
|
1422
|
+
__classPrivateFieldGet$a(this, _NeighbourhoodClient_signalUnsubscribers, "f").set(perspectiveUUID, unsub);
|
|
1423
|
+
await __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").watchApplied();
|
|
1424
|
+
}
|
|
1425
|
+
async addSignalHandler(perspectiveUUID, handler) {
|
|
1426
|
+
let handlersForPerspective = __classPrivateFieldGet$a(this, _NeighbourhoodClient_signalHandlers, "f").get(perspectiveUUID);
|
|
1427
|
+
if (!handlersForPerspective) {
|
|
1428
|
+
handlersForPerspective = [];
|
|
1429
|
+
__classPrivateFieldGet$a(this, _NeighbourhoodClient_signalHandlers, "f").set(perspectiveUUID, handlersForPerspective);
|
|
1430
|
+
handlersForPerspective.push(handler);
|
|
1431
|
+
await this.subscribeToSignals(perspectiveUUID);
|
|
1432
|
+
} else {
|
|
1433
|
+
handlersForPerspective.push(handler);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
removeSignalHandler(perspectiveUUID, handler) {
|
|
1437
|
+
const handlersForPerspective = __classPrivateFieldGet$a(this, _NeighbourhoodClient_signalHandlers, "f").get(perspectiveUUID);
|
|
1438
|
+
if (handlersForPerspective) {
|
|
1439
|
+
const index = handlersForPerspective.indexOf(handler);
|
|
1440
|
+
if (index > -1) {
|
|
1441
|
+
handlersForPerspective.splice(index, 1);
|
|
1442
|
+
}
|
|
1443
|
+
if (handlersForPerspective.length === 0) {
|
|
1444
|
+
__classPrivateFieldGet$a(this, _NeighbourhoodClient_signalHandlers, "f").delete(perspectiveUUID);
|
|
1445
|
+
const unsub = __classPrivateFieldGet$a(this, _NeighbourhoodClient_signalUnsubscribers, "f").get(perspectiveUUID);
|
|
1446
|
+
if (unsub) {
|
|
1447
|
+
unsub();
|
|
1448
|
+
__classPrivateFieldGet$a(this, _NeighbourhoodClient_signalUnsubscribers, "f").delete(perspectiveUUID);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
async sfuStartRoom(neighbourhoodUrl, roomName) {
|
|
1454
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.startRoom", { neighbourhoodUrl, roomName });
|
|
1455
|
+
}
|
|
1456
|
+
async sfuStopRoom(neighbourhoodUrl, roomName) {
|
|
1457
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.stopRoom", { neighbourhoodUrl, roomName });
|
|
1458
|
+
}
|
|
1459
|
+
async sfuListRooms() {
|
|
1460
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.listRooms", {});
|
|
1461
|
+
}
|
|
1462
|
+
async sfuCallJoin(neighbourhoodUrl, roomName, sdpOffer) {
|
|
1463
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.callJoin", {
|
|
1464
|
+
neighbourhoodUrl,
|
|
1465
|
+
roomName,
|
|
1466
|
+
sdpOffer
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
async sfuCallLeave(neighbourhoodUrl, roomName) {
|
|
1470
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.callLeave", { neighbourhoodUrl, roomName });
|
|
1471
|
+
}
|
|
1472
|
+
async sfuCallSetQualityPreference(neighbourhoodUrl, roomName, preference) {
|
|
1473
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.callSetQualityPreference", {
|
|
1474
|
+
neighbourhoodUrl,
|
|
1475
|
+
roomName,
|
|
1476
|
+
preference
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
async sfuCallAnswerServerOffer(neighbourhoodUrl, roomName, sdpAnswer) {
|
|
1480
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.callAnswerServerOffer", {
|
|
1481
|
+
neighbourhoodUrl,
|
|
1482
|
+
roomName,
|
|
1483
|
+
sdpAnswer
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
async sfuGetConfig(neighbourhoodUrl) {
|
|
1487
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.getConfig", { neighbourhoodUrl });
|
|
1488
|
+
}
|
|
1489
|
+
async sfuSetConfig(neighbourhoodUrl, config) {
|
|
1490
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.setConfig", { neighbourhoodUrl, config });
|
|
1491
|
+
}
|
|
1492
|
+
async sfuPeerForNeighbourhood(neighbourhoodUrl) {
|
|
1493
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.sfuPeerForNeighbourhood", { neighbourhoodUrl });
|
|
1494
|
+
}
|
|
1495
|
+
async sfuPeersForNeighbourhood(neighbourhoodUrl) {
|
|
1496
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.sfuPeersForNeighbourhood", { neighbourhoodUrl });
|
|
1497
|
+
}
|
|
1498
|
+
async sfuAddIceCandidate(neighbourhoodUrl, roomName, candidate) {
|
|
1499
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.addIceCandidate", {
|
|
1500
|
+
neighbourhoodUrl,
|
|
1501
|
+
roomName,
|
|
1502
|
+
candidate
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
async sfuSendData(neighbourhoodUrl, roomName, channelLabel, data, binary = false) {
|
|
1506
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.sendData", {
|
|
1507
|
+
neighbourhoodUrl,
|
|
1508
|
+
roomName,
|
|
1509
|
+
channelLabel,
|
|
1510
|
+
data,
|
|
1511
|
+
binary
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
subscribeSfuDataChannel(callback) {
|
|
1515
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").on("sfu-data", (message) => callback(message));
|
|
1516
|
+
}
|
|
1517
|
+
subscribeSfuRoomRoster(callback) {
|
|
1518
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").on("sfu-room-roster", (roster) => callback(roster));
|
|
1519
|
+
}
|
|
1520
|
+
subscribeSfuCallRenegotiationOffer(targetDid, callback) {
|
|
1521
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").on("sfu-call-renegotiation-offer", (event) => {
|
|
1522
|
+
if (event.targetDid !== targetDid)
|
|
1523
|
+
return;
|
|
1524
|
+
callback({
|
|
1525
|
+
targetDid: event.targetDid,
|
|
1526
|
+
neighbourhoodUrl: event.neighbourhoodUrl,
|
|
1527
|
+
roomName: event.roomName,
|
|
1528
|
+
sdpOffer: event.sdpOffer,
|
|
1529
|
+
trackMapping: event.trackMapping
|
|
1530
|
+
});
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
subscribeSfuMigrateEvent(targetDid, callback) {
|
|
1534
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").on("sfu-migrate", (event) => {
|
|
1535
|
+
if (event.targetDid !== targetDid)
|
|
1536
|
+
return;
|
|
1537
|
+
callback({
|
|
1538
|
+
targetDid: event.targetDid,
|
|
1539
|
+
neighbourhoodUrl: event.neighbourhoodUrl,
|
|
1540
|
+
roomName: event.roomName,
|
|
1541
|
+
migrateToDid: event.migrateToDid
|
|
1542
|
+
});
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
async sfuServesAllMembers(perspectiveId) {
|
|
1546
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.servesAllMembers", { uuid: perspectiveId });
|
|
1547
|
+
}
|
|
1548
|
+
async callerDid() {
|
|
1549
|
+
return (await __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("agent.status", {})).did;
|
|
1550
|
+
}
|
|
1551
|
+
async sfuStatus() {
|
|
1552
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.status", {});
|
|
1553
|
+
}
|
|
1554
|
+
async sfuCascadeStatus() {
|
|
1555
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.cascadeStatus", {});
|
|
1556
|
+
}
|
|
1557
|
+
async sfuQualityPreferences() {
|
|
1558
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.qualityPreferences", {});
|
|
1559
|
+
}
|
|
1560
|
+
async sfuEnsureMembership(neighbourhoodUrl, did) {
|
|
1561
|
+
return __classPrivateFieldGet$a(this, _NeighbourhoodClient_apiClient, "f").call("sfu.ensureMembership", {
|
|
1562
|
+
neighbourhoodUrl,
|
|
1563
|
+
did
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
_NeighbourhoodClient_apiClient = /* @__PURE__ */ new WeakMap(), _NeighbourhoodClient_signalHandlers = /* @__PURE__ */ new WeakMap(), _NeighbourhoodClient_signalUnsubscribers = /* @__PURE__ */ new WeakMap();
|
|
1568
|
+
var DEFAULT_ICE_SERVERS$1 = [
|
|
1569
|
+
{ urls: "stun:stun.l.google.com:19302" }
|
|
1570
|
+
];
|
|
1571
|
+
var SfuManager = class {
|
|
1572
|
+
constructor(neighbourhood, roomId, agentDid, neighbourhoodUrl, iceConfig, sfuConfig) {
|
|
1573
|
+
this.callbacks = /* @__PURE__ */ new Map();
|
|
1574
|
+
this.reconnectAttempts = 0;
|
|
1575
|
+
this.reconnecting = false;
|
|
1576
|
+
this.generation = 0;
|
|
1577
|
+
this.midToParticipant = /* @__PURE__ */ new Map();
|
|
1578
|
+
this.departed = /* @__PURE__ */ new Set();
|
|
1579
|
+
this.senders = /* @__PURE__ */ new Map();
|
|
1580
|
+
this.replacedTracks = /* @__PURE__ */ new Map();
|
|
1581
|
+
this.qualityPreference = null;
|
|
1582
|
+
this.offerQueue = Promise.resolve();
|
|
1583
|
+
this.renegotiationUnsubscribe = null;
|
|
1584
|
+
this.rosterUnsubscribe = null;
|
|
1585
|
+
this.dataChannelUnsubscribe = null;
|
|
1586
|
+
this.disconnectedTimer = null;
|
|
1587
|
+
this.neighbourhood = neighbourhood;
|
|
1588
|
+
this.neighbourhoodUrl = neighbourhoodUrl || "";
|
|
1589
|
+
this.roomId = roomId;
|
|
1590
|
+
this.agentDid = agentDid;
|
|
1591
|
+
this.state = {
|
|
1592
|
+
topology: "sfu",
|
|
1593
|
+
roomId,
|
|
1594
|
+
participantId: null,
|
|
1595
|
+
sfuPeerDid: null,
|
|
1596
|
+
participants: /* @__PURE__ */ new Map(),
|
|
1597
|
+
localStream: null,
|
|
1598
|
+
peerConnection: null
|
|
1599
|
+
};
|
|
1600
|
+
let servers = [];
|
|
1601
|
+
if (iceConfig?.servers && iceConfig.servers.length > 0) {
|
|
1602
|
+
servers = iceConfig.servers;
|
|
1603
|
+
} else if (sfuConfig?.iceServers && sfuConfig.iceServers.length > 0) {
|
|
1604
|
+
servers = sfuConfig.iceServers.map((s) => ({
|
|
1605
|
+
urls: s.urls,
|
|
1606
|
+
username: s.username,
|
|
1607
|
+
credential: s.credential
|
|
1608
|
+
}));
|
|
1609
|
+
}
|
|
1610
|
+
this.iceServers = servers.length > 0 ? servers : DEFAULT_ICE_SERVERS$1;
|
|
1611
|
+
}
|
|
1612
|
+
async reconnect() {
|
|
1613
|
+
const stream = this.state.localStream;
|
|
1614
|
+
if (!stream || this.reconnecting)
|
|
1615
|
+
return;
|
|
1616
|
+
const generation = this.generation;
|
|
1617
|
+
if (++this.reconnectAttempts > SfuManager.MAX_RECONNECTS) {
|
|
1618
|
+
this.emit("error", new Error("SFU reconnect attempts exhausted"));
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
console.info(`SFU: connection failed, reconnecting (${this.reconnectAttempts}/${SfuManager.MAX_RECONNECTS})`);
|
|
1622
|
+
this.reconnecting = true;
|
|
1623
|
+
try {
|
|
1624
|
+
const deadline = Date.now() + SfuManager.REJOIN_WINDOW_MS;
|
|
1625
|
+
for (let delay = 1e3; ; delay = Math.min(delay * 2, 1e4)) {
|
|
1626
|
+
this.releaseServerEvents();
|
|
1627
|
+
if (this.state.peerConnection) {
|
|
1628
|
+
this.state.peerConnection.close();
|
|
1629
|
+
this.state.peerConnection = null;
|
|
1630
|
+
}
|
|
1631
|
+
try {
|
|
1632
|
+
await this.neighbourhood.sfuCallLeave(this.neighbourhoodUrl, this.roomId);
|
|
1633
|
+
} catch {
|
|
1634
|
+
}
|
|
1635
|
+
if (generation !== this.generation)
|
|
1636
|
+
return;
|
|
1637
|
+
this.resetParticipants();
|
|
1638
|
+
try {
|
|
1639
|
+
await this.join(stream);
|
|
1640
|
+
if (this.qualityPreference)
|
|
1641
|
+
await this.setQualityPreference(this.qualityPreference);
|
|
1642
|
+
return;
|
|
1643
|
+
} catch (e) {
|
|
1644
|
+
if (generation !== this.generation)
|
|
1645
|
+
return;
|
|
1646
|
+
if (Date.now() + delay > deadline) {
|
|
1647
|
+
console.error("SFU reconnect failed:", e);
|
|
1648
|
+
this.emit("error", e);
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
console.warn(`SFU: rejoin failed, retrying in ${delay} ms:`, e);
|
|
1652
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1653
|
+
if (generation !== this.generation)
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
} finally {
|
|
1658
|
+
this.reconnecting = false;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
on(event, callback) {
|
|
1662
|
+
if (!this.callbacks.has(event)) {
|
|
1663
|
+
this.callbacks.set(event, []);
|
|
1664
|
+
}
|
|
1665
|
+
this.callbacks.get(event).push(callback);
|
|
1666
|
+
}
|
|
1667
|
+
off(event, callback) {
|
|
1668
|
+
if (!callback) {
|
|
1669
|
+
this.callbacks.delete(event);
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
const cbs = this.callbacks.get(event);
|
|
1673
|
+
if (cbs) {
|
|
1674
|
+
const idx = cbs.indexOf(callback);
|
|
1675
|
+
if (idx !== -1)
|
|
1676
|
+
cbs.splice(idx, 1);
|
|
1677
|
+
if (cbs.length === 0)
|
|
1678
|
+
this.callbacks.delete(event);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
emit(event, ...args) {
|
|
1682
|
+
const cbs = this.callbacks.get(event);
|
|
1683
|
+
if (cbs) {
|
|
1684
|
+
for (const cb of cbs) {
|
|
1685
|
+
try {
|
|
1686
|
+
cb(...args);
|
|
1687
|
+
} catch (e) {
|
|
1688
|
+
console.error(`SFU event handler error (${event}):`, e);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
async join(localStream) {
|
|
1694
|
+
this.state.localStream = localStream;
|
|
1695
|
+
const pc = new RTCPeerConnection({ iceServers: this.iceServers });
|
|
1696
|
+
this.state.peerConnection = pc;
|
|
1697
|
+
pc.oniceconnectionstatechange = () => {
|
|
1698
|
+
if (this.state.peerConnection !== pc)
|
|
1699
|
+
return;
|
|
1700
|
+
if (pc.iceConnectionState === "failed") {
|
|
1701
|
+
if (this.disconnectedTimer) {
|
|
1702
|
+
clearTimeout(this.disconnectedTimer);
|
|
1703
|
+
this.disconnectedTimer = null;
|
|
1704
|
+
}
|
|
1705
|
+
this.reconnect();
|
|
1706
|
+
} else if (pc.iceConnectionState === "disconnected") {
|
|
1707
|
+
if (!this.disconnectedTimer) {
|
|
1708
|
+
this.disconnectedTimer = setTimeout(() => {
|
|
1709
|
+
this.disconnectedTimer = null;
|
|
1710
|
+
if (this.state.peerConnection === pc && pc.iceConnectionState === "disconnected") {
|
|
1711
|
+
this.reconnect();
|
|
1712
|
+
}
|
|
1713
|
+
}, SfuManager.DISCONNECT_GRACE_MS);
|
|
1714
|
+
}
|
|
1715
|
+
} else {
|
|
1716
|
+
if (pc.iceConnectionState === "connected" || pc.iceConnectionState === "completed") {
|
|
1717
|
+
this.reconnectAttempts = 0;
|
|
1718
|
+
}
|
|
1719
|
+
if (this.disconnectedTimer) {
|
|
1720
|
+
clearTimeout(this.disconnectedTimer);
|
|
1721
|
+
this.disconnectedTimer = null;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
this.senders.clear();
|
|
1726
|
+
for (const kind of ["audio", "video"]) {
|
|
1727
|
+
const track = this.replacedTracks.has(kind) ? this.replacedTracks.get(kind) : localStream.getTracks().find((t) => t.kind === kind);
|
|
1728
|
+
const transceiver = pc.addTransceiver(track ?? kind, {
|
|
1729
|
+
direction: "sendonly",
|
|
1730
|
+
streams: [localStream],
|
|
1731
|
+
...kind === "video" ? {
|
|
1732
|
+
sendEncodings: [
|
|
1733
|
+
{ rid: "high", maxBitrate: 15e5 },
|
|
1734
|
+
{ rid: "medium", maxBitrate: 5e5, scaleResolutionDownBy: 2 },
|
|
1735
|
+
{ rid: "low", maxBitrate: 15e4, scaleResolutionDownBy: 4 }
|
|
1736
|
+
]
|
|
1737
|
+
} : {}
|
|
1738
|
+
});
|
|
1739
|
+
this.senders.set(kind, transceiver.sender);
|
|
1740
|
+
}
|
|
1741
|
+
pc.ontrack = (event) => {
|
|
1742
|
+
if (this.state.peerConnection !== pc)
|
|
1743
|
+
return;
|
|
1744
|
+
const mid = event.transceiver?.mid;
|
|
1745
|
+
const did = mid ? this.midToParticipant.get(mid) : void 0;
|
|
1746
|
+
if (!did || did === this.agentDid || this.departed.has(did))
|
|
1747
|
+
return;
|
|
1748
|
+
const participant = this.ensureParticipant(did);
|
|
1749
|
+
participant.stream.addTrack(event.track);
|
|
1750
|
+
this.refreshKinds(participant);
|
|
1751
|
+
this.emit("stream-added", participant.stream, event.track);
|
|
1752
|
+
event.track.addEventListener("ended", () => {
|
|
1753
|
+
participant.stream.removeTrack(event.track);
|
|
1754
|
+
this.refreshKinds(participant);
|
|
1755
|
+
this.emit("stream-removed", participant.stream, event.track);
|
|
1756
|
+
});
|
|
1757
|
+
};
|
|
1758
|
+
const pendingCandidates = [];
|
|
1759
|
+
let joinComplete = false;
|
|
1760
|
+
pc.onicecandidate = (event) => {
|
|
1761
|
+
if (!event.candidate)
|
|
1762
|
+
return;
|
|
1763
|
+
if (joinComplete) {
|
|
1764
|
+
this.neighbourhood.sfuAddIceCandidate(this.neighbourhoodUrl, this.roomId, event.candidate.candidate).catch((err2) => {
|
|
1765
|
+
console.error("SFU: failed to trickle ICE candidate:", err2);
|
|
1766
|
+
});
|
|
1767
|
+
} else {
|
|
1768
|
+
pendingCandidates.push(event.candidate.candidate);
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
const offer = await pc.createOffer();
|
|
1772
|
+
await pc.setLocalDescription(offer);
|
|
1773
|
+
const sdpOffer = JSON.stringify(pc.localDescription);
|
|
1774
|
+
let markJoined;
|
|
1775
|
+
const joined = new Promise((resolve) => {
|
|
1776
|
+
markJoined = resolve;
|
|
1777
|
+
});
|
|
1778
|
+
this.subscribeServerEvents(pc, joined);
|
|
1779
|
+
let session;
|
|
1780
|
+
try {
|
|
1781
|
+
session = await this.neighbourhood.sfuCallJoin(this.neighbourhoodUrl, this.roomId, sdpOffer);
|
|
1782
|
+
} catch (err2) {
|
|
1783
|
+
markJoined();
|
|
1784
|
+
this.abandon(pc);
|
|
1785
|
+
throw err2;
|
|
1786
|
+
}
|
|
1787
|
+
this.state.participantId = session.participantId;
|
|
1788
|
+
try {
|
|
1789
|
+
const answer = JSON.parse(session.sdpAnswer);
|
|
1790
|
+
await pc.setRemoteDescription(new RTCSessionDescription(answer));
|
|
1791
|
+
} catch (err2) {
|
|
1792
|
+
markJoined();
|
|
1793
|
+
this.abandon(pc);
|
|
1794
|
+
throw err2;
|
|
1795
|
+
}
|
|
1796
|
+
markJoined();
|
|
1797
|
+
this.applyRoster(session.streamMapping.map((entry) => entry.slice(entry.indexOf(":") + 1)), false);
|
|
1798
|
+
joinComplete = true;
|
|
1799
|
+
for (const candidate of pendingCandidates) {
|
|
1800
|
+
this.neighbourhood.sfuAddIceCandidate(this.neighbourhoodUrl, this.roomId, candidate).catch((err2) => {
|
|
1801
|
+
console.error("SFU: failed to trickle buffered ICE candidate:", err2);
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
releaseServerEvents() {
|
|
1806
|
+
this.renegotiationUnsubscribe?.();
|
|
1807
|
+
this.renegotiationUnsubscribe = null;
|
|
1808
|
+
this.rosterUnsubscribe?.();
|
|
1809
|
+
this.rosterUnsubscribe = null;
|
|
1810
|
+
}
|
|
1811
|
+
abandon(pc) {
|
|
1812
|
+
this.releaseServerEvents();
|
|
1813
|
+
pc.close();
|
|
1814
|
+
if (this.state.peerConnection === pc)
|
|
1815
|
+
this.state.peerConnection = null;
|
|
1816
|
+
}
|
|
1817
|
+
subscribeServerEvents(pc, joined) {
|
|
1818
|
+
const previous = [this.renegotiationUnsubscribe, this.rosterUnsubscribe];
|
|
1819
|
+
const ours = (e) => e.neighbourhoodUrl === this.neighbourhoodUrl && e.roomName === this.roomId;
|
|
1820
|
+
this.renegotiationUnsubscribe = this.neighbourhood.subscribeSfuCallRenegotiationOffer(this.agentDid, (event) => {
|
|
1821
|
+
if (!ours(event))
|
|
1822
|
+
return;
|
|
1823
|
+
this.offerQueue = this.offerQueue.then(() => joined).then(() => this.applyServerOffer(pc, event));
|
|
1824
|
+
});
|
|
1825
|
+
this.rosterUnsubscribe = this.neighbourhood.subscribeSfuRoomRoster((roster) => {
|
|
1826
|
+
if (!ours(roster) || this.state.peerConnection !== pc)
|
|
1827
|
+
return;
|
|
1828
|
+
void joined.then(() => {
|
|
1829
|
+
if (this.state.peerConnection === pc)
|
|
1830
|
+
this.applyRoster(roster.participants, true);
|
|
1831
|
+
});
|
|
1832
|
+
});
|
|
1833
|
+
for (const unsubscribe of previous)
|
|
1834
|
+
unsubscribe?.();
|
|
1835
|
+
}
|
|
1836
|
+
async applyServerOffer(pc, event) {
|
|
1837
|
+
if (this.state.peerConnection !== pc)
|
|
1838
|
+
return;
|
|
1839
|
+
for (const entry of event.trackMapping ?? []) {
|
|
1840
|
+
this.midToParticipant.set(entry.mid, entry.agentDid);
|
|
1841
|
+
}
|
|
1842
|
+
try {
|
|
1843
|
+
await pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(event.sdpOffer)));
|
|
1844
|
+
await pc.setLocalDescription(await pc.createAnswer());
|
|
1845
|
+
await this.neighbourhood.sfuCallAnswerServerOffer(this.neighbourhoodUrl, event.roomName, JSON.stringify(pc.localDescription));
|
|
1846
|
+
} catch (err2) {
|
|
1847
|
+
if (this.state.peerConnection !== pc)
|
|
1848
|
+
return;
|
|
1849
|
+
console.warn("SFU: renegotiation failed, rebuilding the connection:", err2);
|
|
1850
|
+
void this.reconnect();
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
applyRoster(dids, complete) {
|
|
1854
|
+
const present = new Set(dids.filter((did) => did !== this.agentDid));
|
|
1855
|
+
for (const did of present) {
|
|
1856
|
+
this.departed.delete(did);
|
|
1857
|
+
this.ensureParticipant(did);
|
|
1858
|
+
}
|
|
1859
|
+
if (!complete)
|
|
1860
|
+
return;
|
|
1861
|
+
for (const [did, participant] of [...this.state.participants]) {
|
|
1862
|
+
if (present.has(did))
|
|
1863
|
+
continue;
|
|
1864
|
+
this.state.participants.delete(did);
|
|
1865
|
+
this.departed.add(did);
|
|
1866
|
+
for (const [mid, owner] of this.midToParticipant) {
|
|
1867
|
+
if (owner === did)
|
|
1868
|
+
this.midToParticipant.delete(mid);
|
|
1869
|
+
}
|
|
1870
|
+
this.emit("participant-left", participant);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
ensureParticipant(did) {
|
|
1874
|
+
let participant = this.state.participants.get(did);
|
|
1875
|
+
if (!participant) {
|
|
1876
|
+
participant = {
|
|
1877
|
+
did,
|
|
1878
|
+
stream: new MediaStream(),
|
|
1879
|
+
hasAudio: false,
|
|
1880
|
+
hasVideo: false,
|
|
1881
|
+
isActiveSpeaker: false
|
|
1882
|
+
};
|
|
1883
|
+
this.state.participants.set(did, participant);
|
|
1884
|
+
this.emit("participant-joined", participant);
|
|
1885
|
+
}
|
|
1886
|
+
return participant;
|
|
1887
|
+
}
|
|
1888
|
+
refreshKinds(participant) {
|
|
1889
|
+
participant.hasAudio = participant.stream.getAudioTracks().length > 0;
|
|
1890
|
+
participant.hasVideo = participant.stream.getVideoTracks().length > 0;
|
|
1891
|
+
}
|
|
1892
|
+
async leave() {
|
|
1893
|
+
this.generation++;
|
|
1894
|
+
this.releaseServerEvents();
|
|
1895
|
+
if (this.disconnectedTimer) {
|
|
1896
|
+
clearTimeout(this.disconnectedTimer);
|
|
1897
|
+
this.disconnectedTimer = null;
|
|
1898
|
+
}
|
|
1899
|
+
this.senders.clear();
|
|
1900
|
+
this.replacedTracks.clear();
|
|
1901
|
+
this.qualityPreference = null;
|
|
1902
|
+
if (this.dataChannelUnsubscribe) {
|
|
1903
|
+
try {
|
|
1904
|
+
this.dataChannelUnsubscribe();
|
|
1905
|
+
} catch {
|
|
1906
|
+
}
|
|
1907
|
+
this.dataChannelUnsubscribe = null;
|
|
1908
|
+
}
|
|
1909
|
+
if (this.state.peerConnection) {
|
|
1910
|
+
this.state.peerConnection.close();
|
|
1911
|
+
this.state.peerConnection = null;
|
|
1912
|
+
}
|
|
1913
|
+
try {
|
|
1914
|
+
await this.neighbourhood.sfuCallLeave(this.neighbourhoodUrl, this.roomId);
|
|
1915
|
+
} catch (e) {
|
|
1916
|
+
console.error("Error leaving SFU call:", e);
|
|
1917
|
+
}
|
|
1918
|
+
this.resetParticipants();
|
|
1919
|
+
}
|
|
1920
|
+
resetParticipants() {
|
|
1921
|
+
for (const [, participant] of this.state.participants) {
|
|
1922
|
+
this.emit("participant-left", participant);
|
|
1923
|
+
}
|
|
1924
|
+
this.state.participants.clear();
|
|
1925
|
+
this.state.participantId = null;
|
|
1926
|
+
this.midToParticipant.clear();
|
|
1927
|
+
this.departed.clear();
|
|
1928
|
+
}
|
|
1929
|
+
async setQualityPreference(preference) {
|
|
1930
|
+
this.qualityPreference = preference;
|
|
1931
|
+
if (!this.state.participantId) {
|
|
1932
|
+
console.warn("Cannot set quality preference: not connected to SFU");
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1935
|
+
try {
|
|
1936
|
+
await this.neighbourhood.sfuCallSetQualityPreference(this.neighbourhoodUrl, this.roomId, preference);
|
|
1937
|
+
} catch (e) {
|
|
1938
|
+
console.error("Failed to set quality preference:", e);
|
|
1939
|
+
this.emit("error", e);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
getState() {
|
|
1943
|
+
return this.state;
|
|
1944
|
+
}
|
|
1945
|
+
getParticipants() {
|
|
1946
|
+
return Array.from(this.state.participants.values());
|
|
1947
|
+
}
|
|
1948
|
+
async replaceTrack(kind, track) {
|
|
1949
|
+
this.replacedTracks.set(kind, track);
|
|
1950
|
+
if (this.state.peerConnection)
|
|
1951
|
+
await this.senders.get(kind)?.replaceTrack(track);
|
|
1952
|
+
}
|
|
1953
|
+
async sendData(channelLabel, data, binary = false) {
|
|
1954
|
+
if (!this.state.participantId) {
|
|
1955
|
+
console.warn("Cannot send data: not connected to SFU");
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
try {
|
|
1959
|
+
await this.neighbourhood.sfuSendData(this.neighbourhoodUrl, this.roomId, channelLabel, data, binary);
|
|
1960
|
+
} catch (e) {
|
|
1961
|
+
console.error("SFU: sendData failed:", e);
|
|
1962
|
+
this.emit("error", e);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
subscribeDataChannel(callback) {
|
|
1966
|
+
if (this.dataChannelUnsubscribe) {
|
|
1967
|
+
try {
|
|
1968
|
+
this.dataChannelUnsubscribe();
|
|
1969
|
+
} catch {
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
this.dataChannelUnsubscribe = this.neighbourhood.subscribeSfuDataChannel(callback);
|
|
1973
|
+
return () => {
|
|
1974
|
+
if (this.dataChannelUnsubscribe) {
|
|
1975
|
+
try {
|
|
1976
|
+
this.dataChannelUnsubscribe();
|
|
1977
|
+
} catch {
|
|
1978
|
+
}
|
|
1979
|
+
this.dataChannelUnsubscribe = null;
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
}
|
|
1983
|
+
async destroy() {
|
|
1984
|
+
try {
|
|
1985
|
+
await this.leave();
|
|
1986
|
+
} catch (e) {
|
|
1987
|
+
console.error("Error during SFU destroy:", e);
|
|
1988
|
+
}
|
|
1989
|
+
this.callbacks.clear();
|
|
1990
|
+
this.midToParticipant.clear();
|
|
1991
|
+
}
|
|
1992
|
+
};
|
|
1993
|
+
SfuManager.MAX_RECONNECTS = 3;
|
|
1994
|
+
SfuManager.REJOIN_WINDOW_MS = 12e4;
|
|
1995
|
+
SfuManager.DISCONNECT_GRACE_MS = 1e4;
|
|
1996
|
+
var CALL_PROTOCOL_VERSION = 1;
|
|
1997
|
+
function parseCallMessage(payload) {
|
|
1998
|
+
if (typeof payload !== "object" || payload === null)
|
|
1999
|
+
return null;
|
|
2000
|
+
const msg = payload;
|
|
2001
|
+
if (msg.v !== CALL_PROTOCOL_VERSION)
|
|
2002
|
+
return null;
|
|
2003
|
+
if (typeof msg.call !== "string" || !msg.call)
|
|
2004
|
+
return null;
|
|
2005
|
+
const envelope = { v: msg.v, call: msg.call };
|
|
2006
|
+
if (typeof msg.gen === "string" && msg.gen)
|
|
2007
|
+
envelope.gen = msg.gen;
|
|
2008
|
+
if (typeof msg.peerGen === "string" && msg.peerGen)
|
|
2009
|
+
envelope.peerGen = msg.peerGen;
|
|
2010
|
+
if (msg.kind === "description") {
|
|
2011
|
+
const description = msg.description;
|
|
2012
|
+
if (typeof description !== "object" || description === null)
|
|
2013
|
+
return null;
|
|
2014
|
+
const { type, sdp } = description;
|
|
2015
|
+
if (type !== "offer" && type !== "answer" && type !== "pranswer" && type !== "rollback")
|
|
2016
|
+
return null;
|
|
2017
|
+
if (sdp !== void 0 && typeof sdp !== "string")
|
|
2018
|
+
return null;
|
|
2019
|
+
const offer = msg.offer;
|
|
2020
|
+
return {
|
|
2021
|
+
...envelope,
|
|
2022
|
+
kind: "description",
|
|
2023
|
+
description: { type, sdp },
|
|
2024
|
+
...Number.isSafeInteger(offer) ? { offer } : {}
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
if (msg.kind === "ice") {
|
|
2028
|
+
const candidate = msg.candidate;
|
|
2029
|
+
if (typeof candidate !== "object" || candidate === null)
|
|
2030
|
+
return null;
|
|
2031
|
+
return { ...envelope, kind: "ice", candidate };
|
|
2032
|
+
}
|
|
2033
|
+
if (msg.kind === "reset")
|
|
2034
|
+
return { ...envelope, kind: "reset" };
|
|
2035
|
+
if (msg.kind === "data") {
|
|
2036
|
+
const { label, data, binary } = msg;
|
|
2037
|
+
if (typeof label !== "string" || typeof data !== "string")
|
|
2038
|
+
return null;
|
|
2039
|
+
return { ...envelope, kind: "data", label, data, binary: !!binary };
|
|
2040
|
+
}
|
|
2041
|
+
return null;
|
|
2042
|
+
}
|
|
2043
|
+
var RTC_PREDICATE = "ad4m://session/rtc";
|
|
2044
|
+
var TARGET_ALL = "*";
|
|
2045
|
+
function createTelepresenceChannel(proxy, selfDid) {
|
|
2046
|
+
const resultListeners = /* @__PURE__ */ new Set();
|
|
2047
|
+
let subscribed = Promise.resolve();
|
|
2048
|
+
const report = (result) => {
|
|
2049
|
+
for (const cb of resultListeners) {
|
|
2050
|
+
try {
|
|
2051
|
+
cb(result);
|
|
2052
|
+
} catch (e) {
|
|
2053
|
+
console.error("mesh: publish result listener error:", e);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
};
|
|
2057
|
+
return {
|
|
2058
|
+
publish(payload, to) {
|
|
2059
|
+
const started = Date.now();
|
|
2060
|
+
let sent;
|
|
2061
|
+
try {
|
|
2062
|
+
sent = proxy.sendBroadcastU({
|
|
2063
|
+
links: [{
|
|
2064
|
+
source: JSON.stringify(payload),
|
|
2065
|
+
predicate: RTC_PREDICATE,
|
|
2066
|
+
target: to?.agentId ?? TARGET_ALL
|
|
2067
|
+
}]
|
|
2068
|
+
});
|
|
2069
|
+
} catch (err2) {
|
|
2070
|
+
sent = Promise.reject(err2);
|
|
2071
|
+
}
|
|
2072
|
+
sent.then((ok) => report({ ok: ok !== false, ms: Date.now() - started }), (err2) => {
|
|
2073
|
+
console.error("mesh: telepresence publish failed:", err2);
|
|
2074
|
+
report({ ok: false, ms: Date.now() - started });
|
|
2075
|
+
});
|
|
2076
|
+
},
|
|
2077
|
+
onMessage(cb) {
|
|
2078
|
+
const handler = (signal) => {
|
|
2079
|
+
const link = signal?.data?.links?.[0];
|
|
2080
|
+
if (!link?.author)
|
|
2081
|
+
return;
|
|
2082
|
+
if (signal.proof?.valid !== true || link.proof?.valid !== true)
|
|
2083
|
+
return;
|
|
2084
|
+
if (link.author !== signal.author)
|
|
2085
|
+
return;
|
|
2086
|
+
const { source, predicate, target } = link.data ?? {};
|
|
2087
|
+
if (typeof predicate !== "string" || predicate !== RTC_PREDICATE)
|
|
2088
|
+
return;
|
|
2089
|
+
if (target && target !== TARGET_ALL && target !== selfDid)
|
|
2090
|
+
return;
|
|
2091
|
+
if (link.author === selfDid)
|
|
2092
|
+
return;
|
|
2093
|
+
let parsed;
|
|
2094
|
+
try {
|
|
2095
|
+
parsed = JSON.parse(source);
|
|
2096
|
+
} catch {
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
cb(link.author, parsed);
|
|
2100
|
+
};
|
|
2101
|
+
subscribed = proxy.addSignalHandler(handler).catch((err2) => {
|
|
2102
|
+
console.warn("mesh: signal handler registration failed \u2014 inbound traffic will get missed:", err2);
|
|
2103
|
+
});
|
|
2104
|
+
return () => proxy.removeSignalHandler(handler);
|
|
2105
|
+
},
|
|
2106
|
+
listening: () => subscribed,
|
|
2107
|
+
onPublishResult(cb) {
|
|
2108
|
+
resultListeners.add(cb);
|
|
2109
|
+
return () => resultListeners.delete(cb);
|
|
2110
|
+
}
|
|
2111
|
+
};
|
|
2112
|
+
}
|
|
2113
|
+
var DEFAULT_ICE_SERVERS = [
|
|
2114
|
+
{ urls: ["stun:stun.l.google.com:19302", "stun:stun1.l.google.com:19302"] }
|
|
2115
|
+
];
|
|
2116
|
+
var HANDSHAKE_GRACE_MS = 1e4;
|
|
2117
|
+
var RECOVERY_INTERVAL_MS = 8e3;
|
|
2118
|
+
var DISCONNECT_GRACE_MS = 5e3;
|
|
2119
|
+
var MAX_RECOVERY_ATTEMPTS = 4;
|
|
2120
|
+
var SWEEP_INTERVAL_MS = 2e3;
|
|
2121
|
+
var REPAIR_SPACING_MS = 1500;
|
|
2122
|
+
var MAX_EARLY_CANDIDATES = 64;
|
|
2123
|
+
var MAX_RETIRED_PER_PEER = 16;
|
|
2124
|
+
var MAX_PENDING_PEERS = 16;
|
|
2125
|
+
var MAX_PENDING_PER_PEER = 32;
|
|
2126
|
+
var newGeneration = () => Math.random().toString(36).slice(2, 10);
|
|
2127
|
+
var isLive = (track) => track.readyState !== "ended" && !track.muted;
|
|
2128
|
+
var MeshManager = class {
|
|
2129
|
+
constructor(options) {
|
|
2130
|
+
this.sweep = null;
|
|
2131
|
+
this.callbacks = /* @__PURE__ */ new Map();
|
|
2132
|
+
this.slots = /* @__PURE__ */ new Map();
|
|
2133
|
+
this.states = /* @__PURE__ */ new Map();
|
|
2134
|
+
this.outbound = /* @__PURE__ */ new Map();
|
|
2135
|
+
this.outboundStream = null;
|
|
2136
|
+
this.closed = false;
|
|
2137
|
+
this.channelUnsubscribe = null;
|
|
2138
|
+
this.unwatchPublish = null;
|
|
2139
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
2140
|
+
this.retired = /* @__PURE__ */ new Map();
|
|
2141
|
+
this.dataListeners = /* @__PURE__ */ new Set();
|
|
2142
|
+
this.outstanding = 0;
|
|
2143
|
+
this.lastRepairAt = 0;
|
|
2144
|
+
this.renegotiationRepairs = /* @__PURE__ */ new Map();
|
|
2145
|
+
this.channel = options.channel;
|
|
2146
|
+
this.callId = options.callId;
|
|
2147
|
+
this.selfId = options.selfId;
|
|
2148
|
+
this.configuration = {
|
|
2149
|
+
iceServers: options.iceServers?.length ? options.iceServers : DEFAULT_ICE_SERVERS,
|
|
2150
|
+
iceCandidatePoolSize: 1
|
|
2151
|
+
};
|
|
2152
|
+
this.createPeerConnection = options.createPeerConnection ?? ((configuration) => new RTCPeerConnection(configuration));
|
|
2153
|
+
this.now = options.now ?? (() => Date.now());
|
|
2154
|
+
this.sweepMs = options.sweepMs ?? SWEEP_INTERVAL_MS;
|
|
2155
|
+
}
|
|
2156
|
+
on(event, callback) {
|
|
2157
|
+
if (!this.callbacks.has(event))
|
|
2158
|
+
this.callbacks.set(event, []);
|
|
2159
|
+
this.callbacks.get(event).push(callback);
|
|
2160
|
+
}
|
|
2161
|
+
off(event, callback) {
|
|
2162
|
+
if (!callback) {
|
|
2163
|
+
this.callbacks.delete(event);
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2166
|
+
const cbs = this.callbacks.get(event);
|
|
2167
|
+
if (cbs) {
|
|
2168
|
+
const idx = cbs.indexOf(callback);
|
|
2169
|
+
if (idx !== -1)
|
|
2170
|
+
cbs.splice(idx, 1);
|
|
2171
|
+
if (cbs.length === 0)
|
|
2172
|
+
this.callbacks.delete(event);
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
emit(event, ...args) {
|
|
2176
|
+
const cbs = this.callbacks.get(event);
|
|
2177
|
+
if (cbs)
|
|
2178
|
+
for (const cb of cbs) {
|
|
2179
|
+
try {
|
|
2180
|
+
cb(...args);
|
|
2181
|
+
} catch (e) {
|
|
2182
|
+
console.error(`mesh event handler error (${event}):`, e);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
fail(context, error) {
|
|
2187
|
+
this.emit("error", new Error(`${context}: ${error}`));
|
|
2188
|
+
}
|
|
2189
|
+
participant(peerId, slot) {
|
|
2190
|
+
return {
|
|
2191
|
+
did: peerId,
|
|
2192
|
+
stream: slot.stream,
|
|
2193
|
+
hasAudio: slot.stream.getAudioTracks().some(isLive),
|
|
2194
|
+
hasVideo: slot.stream.getVideoTracks().some(isLive),
|
|
2195
|
+
isActiveSpeaker: false
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2198
|
+
async join(localStream) {
|
|
2199
|
+
this.outboundStream = new MediaStream();
|
|
2200
|
+
for (const track of localStream.getAudioTracks()) {
|
|
2201
|
+
this.outbound.set("audio", track);
|
|
2202
|
+
this.outboundStream.addTrack(track);
|
|
2203
|
+
}
|
|
2204
|
+
for (const track of localStream.getVideoTracks()) {
|
|
2205
|
+
this.outbound.set("video", track);
|
|
2206
|
+
this.outboundStream.addTrack(track);
|
|
2207
|
+
}
|
|
2208
|
+
if (typeof this.channel.onPublishResult === "function") {
|
|
2209
|
+
this.unwatchPublish = this.channel.onPublishResult(() => {
|
|
2210
|
+
this.outstanding = Math.max(0, this.outstanding - 1);
|
|
2211
|
+
queueMicrotask(() => this.tick());
|
|
2212
|
+
});
|
|
2213
|
+
}
|
|
2214
|
+
this.channelUnsubscribe = this.channel.onMessage((from, payload) => {
|
|
2215
|
+
if (this.closed || from === this.selfId)
|
|
2216
|
+
return;
|
|
2217
|
+
const message = parseCallMessage(payload);
|
|
2218
|
+
if (!message || message.call !== this.callId)
|
|
2219
|
+
return;
|
|
2220
|
+
const to = payload.to;
|
|
2221
|
+
if (typeof to === "string" && to !== TARGET_ALL && to !== this.selfId)
|
|
2222
|
+
return;
|
|
2223
|
+
const slot = this.slots.get(from);
|
|
2224
|
+
if (message.kind === "data") {
|
|
2225
|
+
if (slot)
|
|
2226
|
+
this.handleData(from, message);
|
|
2227
|
+
return;
|
|
2228
|
+
}
|
|
2229
|
+
if (!slot) {
|
|
2230
|
+
this.hold(from, message);
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
this.enqueue(from, slot, message);
|
|
2234
|
+
});
|
|
2235
|
+
await this.channel.listening?.();
|
|
2236
|
+
this.publish({ v: CALL_PROTOCOL_VERSION, call: this.callId, warm: true });
|
|
2237
|
+
if (this.sweepMs > 0)
|
|
2238
|
+
this.sweep = setInterval(() => this.tick(), this.sweepMs);
|
|
2239
|
+
}
|
|
2240
|
+
async leave() {
|
|
2241
|
+
this.closed = true;
|
|
2242
|
+
if (this.sweep) {
|
|
2243
|
+
clearInterval(this.sweep);
|
|
2244
|
+
this.sweep = null;
|
|
2245
|
+
}
|
|
2246
|
+
this.unwatchPublish?.();
|
|
2247
|
+
this.unwatchPublish = null;
|
|
2248
|
+
if (this.channelUnsubscribe) {
|
|
2249
|
+
this.channelUnsubscribe();
|
|
2250
|
+
this.channelUnsubscribe = null;
|
|
2251
|
+
}
|
|
2252
|
+
this.pending.clear();
|
|
2253
|
+
this.renegotiationRepairs.clear();
|
|
2254
|
+
for (const peerId of [...this.slots.keys()])
|
|
2255
|
+
this.removePeer(peerId);
|
|
2256
|
+
this.outbound.clear();
|
|
2257
|
+
this.outboundStream = null;
|
|
2258
|
+
}
|
|
2259
|
+
async destroy() {
|
|
2260
|
+
await this.leave();
|
|
2261
|
+
this.callbacks.clear();
|
|
2262
|
+
this.dataListeners.clear();
|
|
2263
|
+
}
|
|
2264
|
+
setRoster(peerIds) {
|
|
2265
|
+
if (this.closed)
|
|
2266
|
+
return;
|
|
2267
|
+
const wanted = new Set(peerIds.filter((id) => id !== this.selfId));
|
|
2268
|
+
for (const peerId of [...this.slots.keys()]) {
|
|
2269
|
+
if (!wanted.has(peerId))
|
|
2270
|
+
this.removePeer(peerId);
|
|
2271
|
+
}
|
|
2272
|
+
for (const peerId of wanted) {
|
|
2273
|
+
if (this.slots.has(peerId))
|
|
2274
|
+
continue;
|
|
2275
|
+
const slot = this.connect(peerId);
|
|
2276
|
+
this.emit("participant-joined", this.participant(peerId, slot));
|
|
2277
|
+
this.release(peerId, slot);
|
|
2278
|
+
}
|
|
2279
|
+
for (const peerId of [...this.pending.keys()]) {
|
|
2280
|
+
if (!wanted.has(peerId))
|
|
2281
|
+
this.pending.delete(peerId);
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
getParticipants() {
|
|
2285
|
+
return [...this.slots].map(([peerId, slot]) => this.participant(peerId, slot));
|
|
2286
|
+
}
|
|
2287
|
+
peerStates() {
|
|
2288
|
+
return new Map(this.states);
|
|
2289
|
+
}
|
|
2290
|
+
reconnect(peerId) {
|
|
2291
|
+
const slot = this.slots.get(peerId);
|
|
2292
|
+
if (this.closed || !slot)
|
|
2293
|
+
return;
|
|
2294
|
+
slot.attempts = 0;
|
|
2295
|
+
this.renegotiationRepairs.delete(peerId);
|
|
2296
|
+
this.rebuild(peerId, { announce: true, rung: "rebuild" });
|
|
2297
|
+
}
|
|
2298
|
+
async transportOf(peerId) {
|
|
2299
|
+
const slot = this.slots.get(peerId);
|
|
2300
|
+
if (!slot || typeof slot.pc.getStats !== "function")
|
|
2301
|
+
return null;
|
|
2302
|
+
try {
|
|
2303
|
+
const reports = [];
|
|
2304
|
+
(await slot.pc.getStats()).forEach((report) => reports.push(report));
|
|
2305
|
+
const winner = reports.find((report) => report.type === "candidate-pair" && report.state === "succeeded");
|
|
2306
|
+
const localId = winner?.localCandidateId;
|
|
2307
|
+
if (!localId)
|
|
2308
|
+
return null;
|
|
2309
|
+
const local = reports.find((report) => report.type === "local-candidate" && report.id === localId);
|
|
2310
|
+
return local?.candidateType ?? null;
|
|
2311
|
+
} catch (error) {
|
|
2312
|
+
this.fail(`reading transport stats for ${peerId}`, error);
|
|
2313
|
+
return null;
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
async replaceTrack(kind, track) {
|
|
2317
|
+
const previous = this.outbound.get(kind);
|
|
2318
|
+
this.outbound.set(kind, track);
|
|
2319
|
+
if (this.outboundStream) {
|
|
2320
|
+
if (previous)
|
|
2321
|
+
this.outboundStream.removeTrack(previous);
|
|
2322
|
+
if (track)
|
|
2323
|
+
this.outboundStream.addTrack(track);
|
|
2324
|
+
}
|
|
2325
|
+
if (this.closed)
|
|
2326
|
+
return;
|
|
2327
|
+
await Promise.all([...this.slots.entries()].map(async ([peerId, slot]) => {
|
|
2328
|
+
try {
|
|
2329
|
+
const sender = slot.senders.get(kind);
|
|
2330
|
+
if (sender) {
|
|
2331
|
+
await sender.replaceTrack(track);
|
|
2332
|
+
} else if (track) {
|
|
2333
|
+
slot.senders.set(kind, slot.pc.addTrack(track, this.outboundStream));
|
|
2334
|
+
}
|
|
2335
|
+
} catch (error) {
|
|
2336
|
+
this.fail(`replacing ${kind} track for ${peerId}`, error);
|
|
2337
|
+
}
|
|
2338
|
+
}));
|
|
2339
|
+
}
|
|
2340
|
+
sendData(label, data, binary = false) {
|
|
2341
|
+
this.publish({ v: CALL_PROTOCOL_VERSION, call: this.callId, to: TARGET_ALL, kind: "data", label, data, binary });
|
|
2342
|
+
}
|
|
2343
|
+
subscribeDataChannel(callback) {
|
|
2344
|
+
this.dataListeners.add(callback);
|
|
2345
|
+
return () => this.dataListeners.delete(callback);
|
|
2346
|
+
}
|
|
2347
|
+
handleData(from, message) {
|
|
2348
|
+
const msg = {
|
|
2349
|
+
senderDid: from,
|
|
2350
|
+
neighbourhoodUrl: "",
|
|
2351
|
+
roomName: this.callId,
|
|
2352
|
+
channelLabel: message.label,
|
|
2353
|
+
binary: message.binary,
|
|
2354
|
+
data: message.data
|
|
2355
|
+
};
|
|
2356
|
+
for (const cb of this.dataListeners) {
|
|
2357
|
+
try {
|
|
2358
|
+
cb(msg);
|
|
2359
|
+
} catch (e) {
|
|
2360
|
+
console.error("mesh: data listener error:", e);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
publish(payload, to) {
|
|
2365
|
+
if (this.unwatchPublish)
|
|
2366
|
+
this.outstanding += 1;
|
|
2367
|
+
this.channel.publish(payload, to);
|
|
2368
|
+
}
|
|
2369
|
+
send(to, message) {
|
|
2370
|
+
this.publish({ v: CALL_PROTOCOL_VERSION, call: this.callId, to, ...message }, { agentId: to });
|
|
2371
|
+
}
|
|
2372
|
+
stamp(slot) {
|
|
2373
|
+
return slot.remoteGeneration ? { gen: slot.generation, peerGen: slot.remoteGeneration } : { gen: slot.generation };
|
|
2374
|
+
}
|
|
2375
|
+
sendFrom(peerId, slot, message) {
|
|
2376
|
+
this.send(peerId, { ...message, ...this.stamp(slot) });
|
|
2377
|
+
}
|
|
2378
|
+
sendDescription(peerId, slot) {
|
|
2379
|
+
const { type, sdp } = slot.pc.localDescription;
|
|
2380
|
+
const offer = type === "offer" ? ++slot.offers : slot.remoteOffer;
|
|
2381
|
+
slot.lastSent = { kind: "description", description: { type, sdp }, ...offer !== void 0 ? { offer } : {} };
|
|
2382
|
+
this.sendFrom(peerId, slot, slot.lastSent);
|
|
2383
|
+
}
|
|
2384
|
+
retire(peerId, generation) {
|
|
2385
|
+
if (!generation)
|
|
2386
|
+
return;
|
|
2387
|
+
const list = this.retired.get(peerId) ?? [];
|
|
2388
|
+
if (list.includes(generation))
|
|
2389
|
+
return;
|
|
2390
|
+
list.push(generation);
|
|
2391
|
+
if (list.length > MAX_RETIRED_PER_PEER)
|
|
2392
|
+
list.shift();
|
|
2393
|
+
this.retired.set(peerId, list);
|
|
2394
|
+
}
|
|
2395
|
+
connect(peerId) {
|
|
2396
|
+
const existing = this.slots.get(peerId);
|
|
2397
|
+
if (existing)
|
|
2398
|
+
return existing;
|
|
2399
|
+
const pc = this.createPeerConnection(this.configuration);
|
|
2400
|
+
const slot = {
|
|
2401
|
+
pc,
|
|
2402
|
+
generation: newGeneration(),
|
|
2403
|
+
remoteGeneration: null,
|
|
2404
|
+
polite: this.selfId > peerId,
|
|
2405
|
+
makingOffer: false,
|
|
2406
|
+
ignoreOffer: false,
|
|
2407
|
+
stream: new MediaStream(),
|
|
2408
|
+
senders: /* @__PURE__ */ new Map(),
|
|
2409
|
+
work: Promise.resolve(),
|
|
2410
|
+
remoteReady: false,
|
|
2411
|
+
earlyCandidates: [],
|
|
2412
|
+
lastSent: null,
|
|
2413
|
+
offers: 0,
|
|
2414
|
+
remoteOffer: void 0,
|
|
2415
|
+
lastResent: null,
|
|
2416
|
+
everConnected: false,
|
|
2417
|
+
offeredAt: 0,
|
|
2418
|
+
renegotiating: false,
|
|
2419
|
+
offerDeferred: false,
|
|
2420
|
+
since: this.now(),
|
|
2421
|
+
lastAttempt: 0,
|
|
2422
|
+
attempts: 0,
|
|
2423
|
+
disconnectedAt: 0
|
|
2424
|
+
};
|
|
2425
|
+
this.slots.set(peerId, slot);
|
|
2426
|
+
const negotiate = async () => {
|
|
2427
|
+
if (pc.remoteDescription?.type === "offer" && !slot.everConnected) {
|
|
2428
|
+
slot.offerDeferred = true;
|
|
2429
|
+
return;
|
|
2430
|
+
}
|
|
2431
|
+
slot.offerDeferred = false;
|
|
2432
|
+
try {
|
|
2433
|
+
slot.makingOffer = true;
|
|
2434
|
+
await pc.setLocalDescription({ type: "offer" });
|
|
2435
|
+
slot.offeredAt = this.now();
|
|
2436
|
+
slot.renegotiating = pc.connectionState === "connected";
|
|
2437
|
+
this.sendDescription(peerId, slot);
|
|
2438
|
+
} catch (error) {
|
|
2439
|
+
if (pc.signalingState === "stable")
|
|
2440
|
+
this.fail(`negotiating with ${peerId}`, error);
|
|
2441
|
+
} finally {
|
|
2442
|
+
slot.makingOffer = false;
|
|
2443
|
+
}
|
|
2444
|
+
};
|
|
2445
|
+
pc.onnegotiationneeded = negotiate;
|
|
2446
|
+
pc.onicecandidate = ({ candidate }) => {
|
|
2447
|
+
if (candidate)
|
|
2448
|
+
this.sendFrom(peerId, slot, { kind: "ice", candidate: candidate.toJSON() });
|
|
2449
|
+
};
|
|
2450
|
+
pc.ontrack = ({ track }) => {
|
|
2451
|
+
slot.stream.addTrack(track);
|
|
2452
|
+
const current = () => this.slots.get(peerId) === slot;
|
|
2453
|
+
const updated = () => {
|
|
2454
|
+
if (current())
|
|
2455
|
+
this.emit("participant-updated", this.participant(peerId, slot));
|
|
2456
|
+
};
|
|
2457
|
+
track.addEventListener("ended", () => {
|
|
2458
|
+
slot.stream.removeTrack(track);
|
|
2459
|
+
if (!current())
|
|
2460
|
+
return;
|
|
2461
|
+
this.emit("stream-removed", slot.stream, track);
|
|
2462
|
+
updated();
|
|
2463
|
+
});
|
|
2464
|
+
track.addEventListener("mute", updated);
|
|
2465
|
+
track.addEventListener("unmute", updated);
|
|
2466
|
+
this.emit("stream-added", slot.stream, track);
|
|
2467
|
+
};
|
|
2468
|
+
pc.onconnectionstatechange = () => {
|
|
2469
|
+
const state = pc.connectionState;
|
|
2470
|
+
this.states.set(peerId, state);
|
|
2471
|
+
if (state === "connected") {
|
|
2472
|
+
slot.everConnected = true;
|
|
2473
|
+
slot.attempts = 0;
|
|
2474
|
+
slot.disconnectedAt = 0;
|
|
2475
|
+
slot.earlyCandidates = slot.earlyCandidates.filter((held) => held.gen && held.gen !== slot.remoteGeneration);
|
|
2476
|
+
if (slot.offerDeferred && pc.signalingState === "stable")
|
|
2477
|
+
void negotiate();
|
|
2478
|
+
}
|
|
2479
|
+
if (state === "disconnected" && !slot.disconnectedAt)
|
|
2480
|
+
slot.disconnectedAt = this.now();
|
|
2481
|
+
if (state === "connected" || state === "failed")
|
|
2482
|
+
slot.disconnectedAt = 0;
|
|
2483
|
+
this.emit("peer-state", peerId, state);
|
|
2484
|
+
if (state === "failed")
|
|
2485
|
+
this.tick();
|
|
2486
|
+
};
|
|
2487
|
+
for (const kind of ["audio", "video"]) {
|
|
2488
|
+
try {
|
|
2489
|
+
slot.senders.set(kind, pc.addTransceiver(kind, {
|
|
2490
|
+
direction: "sendrecv",
|
|
2491
|
+
streams: this.outboundStream ? [this.outboundStream] : []
|
|
2492
|
+
}).sender);
|
|
2493
|
+
} catch (error) {
|
|
2494
|
+
this.fail(`preparing ${kind} for ${peerId}`, error);
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
for (const [kind, track] of this.outbound) {
|
|
2498
|
+
if (!track)
|
|
2499
|
+
continue;
|
|
2500
|
+
const sender = slot.senders.get(kind);
|
|
2501
|
+
if (!sender)
|
|
2502
|
+
continue;
|
|
2503
|
+
void sender.replaceTrack(track).catch((error) => this.fail(`sending ${kind} to ${peerId}`, error));
|
|
2504
|
+
}
|
|
2505
|
+
return slot;
|
|
2506
|
+
}
|
|
2507
|
+
disconnect(peerId) {
|
|
2508
|
+
const slot = this.slots.get(peerId);
|
|
2509
|
+
if (!slot)
|
|
2510
|
+
return;
|
|
2511
|
+
slot.pc.onnegotiationneeded = null;
|
|
2512
|
+
slot.pc.onicecandidate = null;
|
|
2513
|
+
slot.pc.ontrack = null;
|
|
2514
|
+
slot.pc.onconnectionstatechange = null;
|
|
2515
|
+
try {
|
|
2516
|
+
slot.pc.close();
|
|
2517
|
+
} catch (error) {
|
|
2518
|
+
this.fail(`closing connection to ${peerId}`, error);
|
|
2519
|
+
}
|
|
2520
|
+
this.slots.delete(peerId);
|
|
2521
|
+
this.states.delete(peerId);
|
|
2522
|
+
this.retire(peerId, slot.remoteGeneration);
|
|
2523
|
+
this.pending.delete(peerId);
|
|
2524
|
+
}
|
|
2525
|
+
removePeer(peerId) {
|
|
2526
|
+
const slot = this.slots.get(peerId);
|
|
2527
|
+
if (!slot)
|
|
2528
|
+
return;
|
|
2529
|
+
this.disconnect(peerId);
|
|
2530
|
+
this.renegotiationRepairs.delete(peerId);
|
|
2531
|
+
this.emit("participant-left", this.participant(peerId, slot));
|
|
2532
|
+
}
|
|
2533
|
+
hold(peerId, message) {
|
|
2534
|
+
if (!this.pending.has(peerId) && this.pending.size >= MAX_PENDING_PEERS)
|
|
2535
|
+
return;
|
|
2536
|
+
const queue = this.pending.get(peerId) ?? [];
|
|
2537
|
+
queue.push(message);
|
|
2538
|
+
while (queue.length > MAX_PENDING_PER_PEER) {
|
|
2539
|
+
const spare = queue.findIndex((held) => held.kind !== "description" && held.kind !== "reset");
|
|
2540
|
+
queue.splice(spare === -1 ? 0 : spare, 1);
|
|
2541
|
+
}
|
|
2542
|
+
this.pending.set(peerId, queue);
|
|
2543
|
+
}
|
|
2544
|
+
release(peerId, slot) {
|
|
2545
|
+
const queue = this.pending.get(peerId);
|
|
2546
|
+
if (!queue)
|
|
2547
|
+
return;
|
|
2548
|
+
this.pending.delete(peerId);
|
|
2549
|
+
for (const message of queue)
|
|
2550
|
+
this.enqueue(peerId, slot, message);
|
|
2551
|
+
}
|
|
2552
|
+
enqueue(peerId, slot, message) {
|
|
2553
|
+
slot.work = slot.work.then(async () => {
|
|
2554
|
+
if (this.closed)
|
|
2555
|
+
return;
|
|
2556
|
+
const current = this.slots.get(peerId);
|
|
2557
|
+
if (!current)
|
|
2558
|
+
return;
|
|
2559
|
+
if (current !== slot) {
|
|
2560
|
+
if (message.gen)
|
|
2561
|
+
this.enqueue(peerId, current, message);
|
|
2562
|
+
return;
|
|
2563
|
+
}
|
|
2564
|
+
await this.handle(peerId, slot, message);
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
placeOf(peerId, slot, message) {
|
|
2568
|
+
if (message.peerGen && message.peerGen !== slot.generation)
|
|
2569
|
+
return "stale";
|
|
2570
|
+
if (!message.gen)
|
|
2571
|
+
return "current";
|
|
2572
|
+
if (this.retired.get(peerId)?.includes(message.gen))
|
|
2573
|
+
return "stale";
|
|
2574
|
+
if (!slot.remoteGeneration || slot.remoteGeneration === message.gen)
|
|
2575
|
+
return "current";
|
|
2576
|
+
return "newer";
|
|
2577
|
+
}
|
|
2578
|
+
async handle(peerId, slot, message) {
|
|
2579
|
+
try {
|
|
2580
|
+
const place = this.placeOf(peerId, slot, message);
|
|
2581
|
+
if (place === "stale")
|
|
2582
|
+
return;
|
|
2583
|
+
if (place === "current" && message.gen && !slot.remoteGeneration)
|
|
2584
|
+
slot.remoteGeneration = message.gen;
|
|
2585
|
+
if (message.kind === "reset") {
|
|
2586
|
+
this.retire(peerId, message.gen);
|
|
2587
|
+
this.rebuild(peerId, { announce: false, rung: "rebuild" });
|
|
2588
|
+
return;
|
|
2589
|
+
}
|
|
2590
|
+
if (place === "newer") {
|
|
2591
|
+
if (message.kind === "ice") {
|
|
2592
|
+
if (slot.earlyCandidates.length < MAX_EARLY_CANDIDATES) {
|
|
2593
|
+
slot.earlyCandidates.push({ gen: message.gen, candidate: message.candidate });
|
|
2594
|
+
}
|
|
2595
|
+
return;
|
|
2596
|
+
}
|
|
2597
|
+
const next = this.rebuild(peerId, { announce: false, rung: "rebuild" });
|
|
2598
|
+
next.earlyCandidates = slot.earlyCandidates.filter((held) => held.gen === message.gen);
|
|
2599
|
+
if (message.kind === "description" && message.description.type === "offer") {
|
|
2600
|
+
next.remoteGeneration = message.gen ?? null;
|
|
2601
|
+
next.work = this.handle(peerId, next, message);
|
|
2602
|
+
}
|
|
2603
|
+
return;
|
|
2604
|
+
}
|
|
2605
|
+
if (message.kind === "description") {
|
|
2606
|
+
const { description } = message;
|
|
2607
|
+
if (description.type === "offer" && message.offer !== void 0 && slot.remoteOffer !== void 0 && message.offer < slot.remoteOffer)
|
|
2608
|
+
return;
|
|
2609
|
+
const collision = description.type === "offer" && (slot.makingOffer || slot.pc.signalingState !== "stable");
|
|
2610
|
+
slot.ignoreOffer = !slot.polite && collision;
|
|
2611
|
+
if (slot.ignoreOffer)
|
|
2612
|
+
return;
|
|
2613
|
+
if (description.type === "answer" && slot.pc.signalingState === "stable")
|
|
2614
|
+
return;
|
|
2615
|
+
if (description.type === "answer" && message.offer !== void 0 && message.offer !== slot.offers)
|
|
2616
|
+
return;
|
|
2617
|
+
await slot.pc.setRemoteDescription(description);
|
|
2618
|
+
if (description.type === "offer")
|
|
2619
|
+
slot.remoteOffer = message.offer;
|
|
2620
|
+
if (description.type === "answer" && slot.renegotiating) {
|
|
2621
|
+
this.renegotiationRepairs.delete(peerId);
|
|
2622
|
+
if (slot.pc.connectionState === "connected")
|
|
2623
|
+
slot.attempts = 0;
|
|
2624
|
+
}
|
|
2625
|
+
slot.offeredAt = 0;
|
|
2626
|
+
slot.renegotiating = false;
|
|
2627
|
+
slot.remoteReady = true;
|
|
2628
|
+
await this.flushCandidates(peerId, slot);
|
|
2629
|
+
if (description.type === "offer") {
|
|
2630
|
+
await slot.pc.setLocalDescription({ type: "answer" });
|
|
2631
|
+
this.sendDescription(peerId, slot);
|
|
2632
|
+
}
|
|
2633
|
+
return;
|
|
2634
|
+
}
|
|
2635
|
+
if (message.kind !== "ice")
|
|
2636
|
+
return;
|
|
2637
|
+
if (!slot.remoteReady) {
|
|
2638
|
+
if (slot.earlyCandidates.length < MAX_EARLY_CANDIDATES) {
|
|
2639
|
+
slot.earlyCandidates.push({ gen: message.gen, candidate: message.candidate });
|
|
2640
|
+
}
|
|
2641
|
+
return;
|
|
2642
|
+
}
|
|
2643
|
+
try {
|
|
2644
|
+
await slot.pc.addIceCandidate(message.candidate);
|
|
2645
|
+
} catch (error) {
|
|
2646
|
+
if (!slot.ignoreOffer)
|
|
2647
|
+
throw error;
|
|
2648
|
+
}
|
|
2649
|
+
} catch (error) {
|
|
2650
|
+
this.fail(`handling ${message.kind} from ${peerId}`, error);
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
async flushCandidates(peerId, slot) {
|
|
2654
|
+
if (!slot.earlyCandidates.length)
|
|
2655
|
+
return;
|
|
2656
|
+
const mine = (held) => !held.gen || held.gen === slot.remoteGeneration;
|
|
2657
|
+
const ready = slot.earlyCandidates.filter(mine).map((held) => held.candidate);
|
|
2658
|
+
slot.earlyCandidates = slot.earlyCandidates.filter((held) => !mine(held));
|
|
2659
|
+
for (const candidate of ready) {
|
|
2660
|
+
try {
|
|
2661
|
+
await slot.pc.addIceCandidate(candidate);
|
|
2662
|
+
} catch (error) {
|
|
2663
|
+
this.fail(`applying a held candidate from ${peerId}`, error);
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
rebuild(peerId, opts) {
|
|
2668
|
+
const previous = this.slots.get(peerId);
|
|
2669
|
+
const attempts = (previous?.attempts ?? 0) + 1;
|
|
2670
|
+
const farewell = previous ? this.stamp(previous) : {};
|
|
2671
|
+
this.disconnect(peerId);
|
|
2672
|
+
if (opts.announce)
|
|
2673
|
+
this.send(peerId, { kind: "reset", ...farewell });
|
|
2674
|
+
const slot = this.connect(peerId);
|
|
2675
|
+
slot.attempts = attempts;
|
|
2676
|
+
slot.lastAttempt = this.now();
|
|
2677
|
+
this.emit("participant-updated", this.participant(peerId, slot));
|
|
2678
|
+
this.emit("peer-recovery", peerId, { rung: opts.rung, attempts });
|
|
2679
|
+
return slot;
|
|
2680
|
+
}
|
|
2681
|
+
repair(peerId, slot) {
|
|
2682
|
+
slot.lastAttempt = this.now();
|
|
2683
|
+
const attempts = slot.attempts + 1;
|
|
2684
|
+
slot.attempts = attempts;
|
|
2685
|
+
const state = slot.pc.connectionState;
|
|
2686
|
+
const canRestart = typeof slot.pc.restartIce === "function";
|
|
2687
|
+
if ((state === "failed" || state === "disconnected") && canRestart && slot.remoteReady) {
|
|
2688
|
+
try {
|
|
2689
|
+
slot.pc.restartIce();
|
|
2690
|
+
this.emit("peer-recovery", peerId, { rung: "ice-restart", attempts });
|
|
2691
|
+
return;
|
|
2692
|
+
} catch (error) {
|
|
2693
|
+
this.fail(`restarting ice with ${peerId}`, error);
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
const unanswered = slot.offeredAt > 0 && slot.pc.signalingState === "have-local-offer";
|
|
2697
|
+
if (state === "connected") {
|
|
2698
|
+
this.renegotiationRepairs.set(peerId, (this.renegotiationRepairs.get(peerId) ?? 0) + 1);
|
|
2699
|
+
}
|
|
2700
|
+
if ((!slot.everConnected || unanswered) && slot.lastSent && slot.lastSent.description.sdp !== slot.lastResent) {
|
|
2701
|
+
slot.lastResent = slot.lastSent.description.sdp ?? null;
|
|
2702
|
+
this.sendFrom(peerId, slot, slot.lastSent);
|
|
2703
|
+
this.emit("peer-recovery", peerId, { rung: "resend", attempts });
|
|
2704
|
+
return;
|
|
2705
|
+
}
|
|
2706
|
+
slot.attempts = attempts - 1;
|
|
2707
|
+
this.rebuild(peerId, { announce: true, rung: "rebuild" });
|
|
2708
|
+
}
|
|
2709
|
+
dueForRepair(peerId, slot, at) {
|
|
2710
|
+
const state = slot.pc.connectionState;
|
|
2711
|
+
if (slot.attempts >= MAX_RECOVERY_ATTEMPTS)
|
|
2712
|
+
return false;
|
|
2713
|
+
if (state === "connected") {
|
|
2714
|
+
if (!slot.offeredAt || slot.pc.signalingState !== "have-local-offer")
|
|
2715
|
+
return false;
|
|
2716
|
+
if ((this.renegotiationRepairs.get(peerId) ?? 0) >= MAX_RECOVERY_ATTEMPTS)
|
|
2717
|
+
return false;
|
|
2718
|
+
return at - Math.max(slot.offeredAt, slot.lastAttempt) >= RECOVERY_INTERVAL_MS;
|
|
2719
|
+
}
|
|
2720
|
+
const patience = slot.polite ? 2 : 1;
|
|
2721
|
+
if (state === "disconnected" && slot.disconnectedAt) {
|
|
2722
|
+
return at - slot.disconnectedAt >= DISCONNECT_GRACE_MS * patience;
|
|
2723
|
+
}
|
|
2724
|
+
if (state === "failed") {
|
|
2725
|
+
return at - Math.max(slot.lastAttempt, slot.since) >= RECOVERY_INTERVAL_MS * patience;
|
|
2726
|
+
}
|
|
2727
|
+
const from = slot.lastAttempt || slot.since;
|
|
2728
|
+
const deadline = slot.lastAttempt ? RECOVERY_INTERVAL_MS : HANDSHAKE_GRACE_MS;
|
|
2729
|
+
return at - from >= deadline * patience;
|
|
2730
|
+
}
|
|
2731
|
+
tick() {
|
|
2732
|
+
if (this.closed)
|
|
2733
|
+
return;
|
|
2734
|
+
if (this.outstanding > 0)
|
|
2735
|
+
return;
|
|
2736
|
+
const at = this.now();
|
|
2737
|
+
if (this.lastRepairAt && at - this.lastRepairAt < REPAIR_SPACING_MS)
|
|
2738
|
+
return;
|
|
2739
|
+
for (const [peerId, slot] of [...this.slots]) {
|
|
2740
|
+
if (!this.dueForRepair(peerId, slot, at))
|
|
2741
|
+
continue;
|
|
2742
|
+
this.lastRepairAt = at;
|
|
2743
|
+
this.repair(peerId, slot);
|
|
2744
|
+
break;
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
};
|
|
2748
|
+
var CALL_PRESENCE_PREDICATE = "ad4m://session/in-call";
|
|
2749
|
+
var ROSTER_POLL_INTERVAL_MS = 3e3;
|
|
2750
|
+
function createSession(config) {
|
|
2751
|
+
const { api, roomId, agentDid, neighbourhoodUrl, topology, sfuConfig, iceServers, channel, setOnlineStatus, ownOnlineStatus, onlineAgents, localSfuStatus, sfuServesAllMembers } = config;
|
|
2752
|
+
let state = "idle";
|
|
2753
|
+
let sfuManager = null;
|
|
2754
|
+
let meshManager = null;
|
|
2755
|
+
let rosterInterval = null;
|
|
2756
|
+
let polling = false;
|
|
2757
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
2758
|
+
const trackListeners = [];
|
|
2759
|
+
const dataListeners = [];
|
|
2760
|
+
let dataUnsubscribe = null;
|
|
2761
|
+
function emit(event, ...args) {
|
|
2762
|
+
const cbs = callbacks.get(event);
|
|
2763
|
+
if (cbs)
|
|
2764
|
+
for (const cb of cbs)
|
|
2765
|
+
cb(...args);
|
|
2766
|
+
}
|
|
2767
|
+
function setState(next) {
|
|
2768
|
+
state = next;
|
|
2769
|
+
emit("state-changed", next);
|
|
2770
|
+
}
|
|
2771
|
+
async function resolveTopology() {
|
|
2772
|
+
if (topology === "sfu")
|
|
2773
|
+
return "sfu";
|
|
2774
|
+
if (topology === "mesh")
|
|
2775
|
+
return "mesh";
|
|
2776
|
+
if (sfuConfig) {
|
|
2777
|
+
return sfuConfig.mode === "mesh" ? "mesh" : "sfu";
|
|
2778
|
+
}
|
|
2779
|
+
if (!localSfuStatus?.isPublic || !sfuServesAllMembers)
|
|
2780
|
+
return "mesh";
|
|
2781
|
+
try {
|
|
2782
|
+
return await sfuServesAllMembers() ? "sfu" : "mesh";
|
|
2783
|
+
} catch (err2) {
|
|
2784
|
+
console.warn("session: SFU membership check failed, using mesh:", err2);
|
|
2785
|
+
return "mesh";
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
let statusBeforeCall = [];
|
|
2789
|
+
let announced = false;
|
|
2790
|
+
async function ownLinksWithoutCall() {
|
|
2791
|
+
const status = ownOnlineStatus ? await ownOnlineStatus() : null;
|
|
2792
|
+
const links = [];
|
|
2793
|
+
for (const link of status?.data?.links ?? []) {
|
|
2794
|
+
const l = link.data;
|
|
2795
|
+
if (!l?.source || l.target === void 0)
|
|
2796
|
+
continue;
|
|
2797
|
+
if (l.predicate === CALL_PRESENCE_PREDICATE && l.target === roomId)
|
|
2798
|
+
continue;
|
|
2799
|
+
links.push({ source: l.source, target: l.target, ...l.predicate ? { predicate: l.predicate } : {} });
|
|
2800
|
+
}
|
|
2801
|
+
return links;
|
|
2802
|
+
}
|
|
2803
|
+
async function announceCallPresence() {
|
|
2804
|
+
if (!setOnlineStatus)
|
|
2805
|
+
return;
|
|
2806
|
+
try {
|
|
2807
|
+
statusBeforeCall = await ownLinksWithoutCall().catch((err2) => {
|
|
2808
|
+
console.warn("session: reading own status failed:", err2);
|
|
2809
|
+
return [];
|
|
2810
|
+
});
|
|
2811
|
+
const presence = { source: agentDid, predicate: CALL_PRESENCE_PREDICATE, target: roomId };
|
|
2812
|
+
await setOnlineStatus({ links: [...statusBeforeCall, presence] });
|
|
2813
|
+
announced = true;
|
|
2814
|
+
} catch (err2) {
|
|
2815
|
+
console.warn("session: call-presence announcement failed:", err2);
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
async function withdrawCallPresence() {
|
|
2819
|
+
if (!setOnlineStatus || !announced)
|
|
2820
|
+
return;
|
|
2821
|
+
announced = false;
|
|
2822
|
+
try {
|
|
2823
|
+
const links = await ownLinksWithoutCall().catch((err2) => {
|
|
2824
|
+
console.warn("session: reading own status failed:", err2);
|
|
2825
|
+
return statusBeforeCall;
|
|
2826
|
+
});
|
|
2827
|
+
await setOnlineStatus({ links });
|
|
2828
|
+
} catch (err2) {
|
|
2829
|
+
console.warn("session: withdrawing call presence failed:", err2);
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
async function pollRoster() {
|
|
2833
|
+
const mesh = meshManager;
|
|
2834
|
+
if (!mesh || !onlineAgents || polling)
|
|
2835
|
+
return;
|
|
2836
|
+
polling = true;
|
|
2837
|
+
try {
|
|
2838
|
+
const agents = await onlineAgents();
|
|
2839
|
+
if (meshManager !== mesh)
|
|
2840
|
+
return;
|
|
2841
|
+
const inCall = [];
|
|
2842
|
+
for (const agent of agents) {
|
|
2843
|
+
if (agent.did === agentDid)
|
|
2844
|
+
continue;
|
|
2845
|
+
for (const link of agent.status?.data?.links ?? []) {
|
|
2846
|
+
const l = link.data;
|
|
2847
|
+
if (l?.predicate === CALL_PRESENCE_PREDICATE && l.target === roomId) {
|
|
2848
|
+
inCall.push(agent.did);
|
|
2849
|
+
break;
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
mesh.setRoster(inCall);
|
|
2854
|
+
} catch (err2) {
|
|
2855
|
+
console.warn("session: roster poll failed:", err2);
|
|
2856
|
+
} finally {
|
|
2857
|
+
polling = false;
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
function startRosterPolling() {
|
|
2861
|
+
void pollRoster();
|
|
2862
|
+
rosterInterval = setInterval(() => void pollRoster(), ROSTER_POLL_INTERVAL_MS);
|
|
1408
2863
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
__classPrivateFieldGet$9(this, _NeighbourhoodClient_signalHandlers, "f").set(perspectiveUUID, handlersForPerspective);
|
|
1414
|
-
handlersForPerspective.push(handler);
|
|
1415
|
-
await this.subscribeToSignals(perspectiveUUID);
|
|
1416
|
-
} else {
|
|
1417
|
-
handlersForPerspective.push(handler);
|
|
2864
|
+
function stopRosterPolling() {
|
|
2865
|
+
if (rosterInterval !== null) {
|
|
2866
|
+
clearInterval(rosterInterval);
|
|
2867
|
+
rosterInterval = null;
|
|
1418
2868
|
}
|
|
1419
2869
|
}
|
|
1420
|
-
|
|
1421
|
-
const
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
2870
|
+
function wireMeshEvents(mesh) {
|
|
2871
|
+
for (const event of ["participant-joined", "participant-left", "participant-updated", "peer-state", "peer-recovery", "error"]) {
|
|
2872
|
+
mesh.on(event, (...args) => emit(event, ...args));
|
|
2873
|
+
}
|
|
2874
|
+
mesh.on("stream-added", (stream, track) => {
|
|
2875
|
+
emit("stream-added", stream, track);
|
|
2876
|
+
for (const cb of trackListeners)
|
|
2877
|
+
cb(stream, track);
|
|
2878
|
+
});
|
|
2879
|
+
mesh.on("stream-removed", (stream, track) => {
|
|
2880
|
+
emit("stream-removed", stream, track);
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
function wireSfuEvents(sfu) {
|
|
2884
|
+
for (const event of ["topology-changed", "participant-joined", "participant-left", "active-speaker", "error"]) {
|
|
2885
|
+
sfu.on(event, (...args) => emit(event, ...args));
|
|
2886
|
+
}
|
|
2887
|
+
sfu.on("stream-added", (stream, track) => {
|
|
2888
|
+
emit("stream-added", stream, track);
|
|
2889
|
+
for (const cb of trackListeners)
|
|
2890
|
+
cb(stream, track);
|
|
2891
|
+
});
|
|
2892
|
+
sfu.on("stream-removed", (stream, track) => {
|
|
2893
|
+
emit("stream-removed", stream, track);
|
|
2894
|
+
});
|
|
2895
|
+
}
|
|
2896
|
+
const session = {
|
|
2897
|
+
async join(localStream) {
|
|
2898
|
+
if (state === "closed")
|
|
2899
|
+
throw new Error("Session destroyed");
|
|
2900
|
+
if (state === "active" || state === "joining")
|
|
2901
|
+
throw new Error("Session already active");
|
|
2902
|
+
setState("joining");
|
|
2903
|
+
const topo = await resolveTopology();
|
|
2904
|
+
if (topo === "mesh") {
|
|
2905
|
+
if (!channel) {
|
|
2906
|
+
throw new Error("Mesh topology requires a signalling channel \u2014 pass a channel via SessionImplConfig or use topology 'sfu'");
|
|
1433
2907
|
}
|
|
2908
|
+
const meshIce = [];
|
|
2909
|
+
if (iceServers && iceServers.length > 0) {
|
|
2910
|
+
for (const s of iceServers) {
|
|
2911
|
+
meshIce.push({
|
|
2912
|
+
urls: s.urls,
|
|
2913
|
+
...s.username ? { username: s.username } : {},
|
|
2914
|
+
...s.credential ? { credential: s.credential } : {}
|
|
2915
|
+
});
|
|
2916
|
+
}
|
|
2917
|
+
} else if (sfuConfig?.iceServers && sfuConfig.iceServers.length > 0) {
|
|
2918
|
+
for (const s of sfuConfig.iceServers) {
|
|
2919
|
+
meshIce.push({
|
|
2920
|
+
urls: s.urls,
|
|
2921
|
+
...s.username ? { username: s.username } : {},
|
|
2922
|
+
...s.credential ? { credential: s.credential } : {}
|
|
2923
|
+
});
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
const mesh = new MeshManager({
|
|
2927
|
+
channel,
|
|
2928
|
+
callId: roomId,
|
|
2929
|
+
selfId: agentDid,
|
|
2930
|
+
...meshIce.length > 0 ? { iceServers: meshIce } : {}
|
|
2931
|
+
});
|
|
2932
|
+
meshManager = mesh;
|
|
2933
|
+
wireMeshEvents(mesh);
|
|
2934
|
+
dataUnsubscribe = mesh.subscribeDataChannel((msg) => {
|
|
2935
|
+
for (const cb of dataListeners)
|
|
2936
|
+
cb(msg);
|
|
2937
|
+
});
|
|
2938
|
+
await mesh.join(localStream);
|
|
2939
|
+
await announceCallPresence();
|
|
2940
|
+
startRosterPolling();
|
|
2941
|
+
emit("topology-changed", "mesh");
|
|
2942
|
+
setState("active");
|
|
2943
|
+
return;
|
|
2944
|
+
}
|
|
2945
|
+
const iceConfig = iceServers && iceServers.length > 0 ? { servers: iceServers.map((s) => ({ urls: s.urls, ...s.username ? { username: s.username } : {}, ...s.credential ? { credential: s.credential } : {} })) } : void 0;
|
|
2946
|
+
sfuManager = new SfuManager(api, roomId, agentDid, neighbourhoodUrl, iceConfig, sfuConfig);
|
|
2947
|
+
wireSfuEvents(sfuManager);
|
|
2948
|
+
dataUnsubscribe = sfuManager.subscribeDataChannel((msg) => {
|
|
2949
|
+
for (const cb of dataListeners)
|
|
2950
|
+
cb(msg);
|
|
2951
|
+
});
|
|
2952
|
+
await sfuManager.join(localStream);
|
|
2953
|
+
emit("topology-changed", "sfu");
|
|
2954
|
+
setState("active");
|
|
2955
|
+
},
|
|
2956
|
+
async leave() {
|
|
2957
|
+
if (state !== "active")
|
|
2958
|
+
return;
|
|
2959
|
+
setState("leaving");
|
|
2960
|
+
stopRosterPolling();
|
|
2961
|
+
await withdrawCallPresence();
|
|
2962
|
+
if (dataUnsubscribe) {
|
|
2963
|
+
dataUnsubscribe();
|
|
2964
|
+
dataUnsubscribe = null;
|
|
2965
|
+
}
|
|
2966
|
+
if (meshManager) {
|
|
2967
|
+
await meshManager.leave();
|
|
2968
|
+
meshManager = null;
|
|
2969
|
+
}
|
|
2970
|
+
if (sfuManager) {
|
|
2971
|
+
await sfuManager.leave();
|
|
2972
|
+
sfuManager = null;
|
|
2973
|
+
}
|
|
2974
|
+
setState("idle");
|
|
2975
|
+
},
|
|
2976
|
+
get participants() {
|
|
2977
|
+
if (meshManager) {
|
|
2978
|
+
return meshManager.getParticipants().map((p) => ({
|
|
2979
|
+
agentDid: p.did,
|
|
2980
|
+
stream: p.stream,
|
|
2981
|
+
hasAudio: p.hasAudio,
|
|
2982
|
+
hasVideo: p.hasVideo,
|
|
2983
|
+
isActiveSpeaker: p.isActiveSpeaker
|
|
2984
|
+
}));
|
|
2985
|
+
}
|
|
2986
|
+
if (sfuManager) {
|
|
2987
|
+
return sfuManager.getParticipants().map((p) => ({
|
|
2988
|
+
agentDid: p.did,
|
|
2989
|
+
stream: p.stream,
|
|
2990
|
+
hasAudio: p.hasAudio,
|
|
2991
|
+
hasVideo: p.hasVideo,
|
|
2992
|
+
isActiveSpeaker: p.isActiveSpeaker
|
|
2993
|
+
}));
|
|
2994
|
+
}
|
|
2995
|
+
return [];
|
|
2996
|
+
},
|
|
2997
|
+
onTrack(cb) {
|
|
2998
|
+
trackListeners.push(cb);
|
|
2999
|
+
return () => {
|
|
3000
|
+
const idx = trackListeners.indexOf(cb);
|
|
3001
|
+
if (idx !== -1)
|
|
3002
|
+
trackListeners.splice(idx, 1);
|
|
3003
|
+
};
|
|
3004
|
+
},
|
|
3005
|
+
async replaceTrack(kind, track) {
|
|
3006
|
+
if (meshManager) {
|
|
3007
|
+
await meshManager.replaceTrack(kind, track);
|
|
3008
|
+
return;
|
|
3009
|
+
}
|
|
3010
|
+
if (sfuManager) {
|
|
3011
|
+
await sfuManager.replaceTrack(kind, track);
|
|
3012
|
+
return;
|
|
3013
|
+
}
|
|
3014
|
+
throw new Error("Session not active");
|
|
3015
|
+
},
|
|
3016
|
+
async setQualityPreference(pref) {
|
|
3017
|
+
if (meshManager)
|
|
3018
|
+
return;
|
|
3019
|
+
if (!sfuManager)
|
|
3020
|
+
throw new Error("Session not active");
|
|
3021
|
+
await sfuManager.setQualityPreference(pref);
|
|
3022
|
+
},
|
|
3023
|
+
async sendData(label, data, binary = false) {
|
|
3024
|
+
if (meshManager) {
|
|
3025
|
+
meshManager.sendData(label, data, binary);
|
|
3026
|
+
return;
|
|
3027
|
+
}
|
|
3028
|
+
if (!sfuManager)
|
|
3029
|
+
throw new Error("Session not active");
|
|
3030
|
+
await sfuManager.sendData(label, data, binary);
|
|
3031
|
+
},
|
|
3032
|
+
onData(cb) {
|
|
3033
|
+
dataListeners.push(cb);
|
|
3034
|
+
return () => {
|
|
3035
|
+
const idx = dataListeners.indexOf(cb);
|
|
3036
|
+
if (idx !== -1)
|
|
3037
|
+
dataListeners.splice(idx, 1);
|
|
3038
|
+
};
|
|
3039
|
+
},
|
|
3040
|
+
peerStates() {
|
|
3041
|
+
return meshManager ? meshManager.peerStates() : /* @__PURE__ */ new Map();
|
|
3042
|
+
},
|
|
3043
|
+
reconnect(did) {
|
|
3044
|
+
meshManager?.reconnect(did);
|
|
3045
|
+
},
|
|
3046
|
+
async transportOf(did) {
|
|
3047
|
+
return meshManager ? meshManager.transportOf(did) : null;
|
|
3048
|
+
},
|
|
3049
|
+
getState() {
|
|
3050
|
+
return state;
|
|
3051
|
+
},
|
|
3052
|
+
on(event, cb) {
|
|
3053
|
+
if (!callbacks.has(event))
|
|
3054
|
+
callbacks.set(event, []);
|
|
3055
|
+
callbacks.get(event).push(cb);
|
|
3056
|
+
},
|
|
3057
|
+
off(event, cb) {
|
|
3058
|
+
if (!cb) {
|
|
3059
|
+
callbacks.delete(event);
|
|
3060
|
+
return;
|
|
1434
3061
|
}
|
|
3062
|
+
const cbs = callbacks.get(event);
|
|
3063
|
+
if (cbs) {
|
|
3064
|
+
const idx = cbs.indexOf(cb);
|
|
3065
|
+
if (idx !== -1)
|
|
3066
|
+
cbs.splice(idx, 1);
|
|
3067
|
+
if (cbs.length === 0)
|
|
3068
|
+
callbacks.delete(event);
|
|
3069
|
+
}
|
|
3070
|
+
},
|
|
3071
|
+
async destroy() {
|
|
3072
|
+
const mesh = meshManager;
|
|
3073
|
+
const sfu = sfuManager;
|
|
3074
|
+
if (state === "active" || state === "joining")
|
|
3075
|
+
await session.leave();
|
|
3076
|
+
stopRosterPolling();
|
|
3077
|
+
if (mesh) {
|
|
3078
|
+
await mesh.destroy();
|
|
3079
|
+
}
|
|
3080
|
+
if (sfu) {
|
|
3081
|
+
await sfu.destroy();
|
|
3082
|
+
}
|
|
3083
|
+
meshManager = null;
|
|
3084
|
+
sfuManager = null;
|
|
3085
|
+
setState("closed");
|
|
3086
|
+
callbacks.clear();
|
|
3087
|
+
trackListeners.length = 0;
|
|
3088
|
+
dataListeners.length = 0;
|
|
1435
3089
|
}
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
var __classPrivateFieldSet$
|
|
3090
|
+
};
|
|
3091
|
+
return session;
|
|
3092
|
+
}
|
|
3093
|
+
var __classPrivateFieldSet$9 = function(receiver, state, value, kind, f) {
|
|
1440
3094
|
if (kind === "m")
|
|
1441
3095
|
throw new TypeError("Private method is not writable");
|
|
1442
3096
|
if (kind === "a" && !f)
|
|
@@ -1445,7 +3099,7 @@ var __classPrivateFieldSet$8 = function(receiver, state, value, kind, f) {
|
|
|
1445
3099
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1446
3100
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1447
3101
|
};
|
|
1448
|
-
var __classPrivateFieldGet$
|
|
3102
|
+
var __classPrivateFieldGet$9 = function(receiver, state, kind, f) {
|
|
1449
3103
|
if (kind === "a" && !f)
|
|
1450
3104
|
throw new TypeError("Private accessor was defined without a getter");
|
|
1451
3105
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -1454,48 +3108,160 @@ var __classPrivateFieldGet$8 = function(receiver, state, kind, f) {
|
|
|
1454
3108
|
};
|
|
1455
3109
|
var _NeighbourhoodProxy_client;
|
|
1456
3110
|
var _NeighbourhoodProxy_pID;
|
|
3111
|
+
var _NeighbourhoodProxy_agentDid;
|
|
3112
|
+
var _NeighbourhoodProxy_sessions;
|
|
3113
|
+
var _NeighbourhoodProxy_sfuStatusCache;
|
|
1457
3114
|
var NeighbourhoodProxy = class {
|
|
1458
|
-
constructor(client, pID) {
|
|
3115
|
+
constructor(client, pID, agentDid = "") {
|
|
1459
3116
|
_NeighbourhoodProxy_client.set(this, void 0);
|
|
1460
3117
|
_NeighbourhoodProxy_pID.set(this, void 0);
|
|
1461
|
-
|
|
1462
|
-
|
|
3118
|
+
_NeighbourhoodProxy_agentDid.set(this, void 0);
|
|
3119
|
+
_NeighbourhoodProxy_sessions.set(
|
|
3120
|
+
this,
|
|
3121
|
+
[]
|
|
3122
|
+
);
|
|
3123
|
+
_NeighbourhoodProxy_sfuStatusCache.set(this, null);
|
|
3124
|
+
__classPrivateFieldSet$9(this, _NeighbourhoodProxy_client, client, "f");
|
|
3125
|
+
__classPrivateFieldSet$9(this, _NeighbourhoodProxy_pID, pID, "f");
|
|
3126
|
+
__classPrivateFieldSet$9(this, _NeighbourhoodProxy_agentDid, agentDid, "f");
|
|
1463
3127
|
}
|
|
1464
3128
|
async otherAgents() {
|
|
1465
|
-
return await __classPrivateFieldGet$
|
|
3129
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").otherAgents(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"));
|
|
1466
3130
|
}
|
|
1467
3131
|
async hasTelepresenceAdapter() {
|
|
1468
|
-
return await __classPrivateFieldGet$
|
|
3132
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").hasTelepresenceAdapter(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"));
|
|
1469
3133
|
}
|
|
1470
3134
|
async onlineAgents() {
|
|
1471
|
-
return await __classPrivateFieldGet$
|
|
3135
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").onlineAgents(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"));
|
|
3136
|
+
}
|
|
3137
|
+
async ownOnlineStatus() {
|
|
3138
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").ownOnlineStatus(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"));
|
|
1472
3139
|
}
|
|
1473
3140
|
async setOnlineStatus(status) {
|
|
1474
|
-
return await __classPrivateFieldGet$
|
|
3141
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").setOnlineStatus(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"), status);
|
|
1475
3142
|
}
|
|
1476
3143
|
async setOnlineStatusU(status) {
|
|
1477
|
-
return await __classPrivateFieldGet$
|
|
3144
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").setOnlineStatusU(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"), status);
|
|
1478
3145
|
}
|
|
1479
3146
|
async sendSignal(remoteAgentDid, payload) {
|
|
1480
|
-
return await __classPrivateFieldGet$
|
|
3147
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sendSignal(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"), remoteAgentDid, payload);
|
|
1481
3148
|
}
|
|
1482
3149
|
async sendSignalU(remoteAgentDid, payload) {
|
|
1483
|
-
return await __classPrivateFieldGet$
|
|
3150
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sendSignalU(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"), remoteAgentDid, payload);
|
|
1484
3151
|
}
|
|
1485
3152
|
async sendBroadcast(payload, loopback = false) {
|
|
1486
|
-
return await __classPrivateFieldGet$
|
|
3153
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sendBroadcast(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"), payload, loopback);
|
|
1487
3154
|
}
|
|
1488
3155
|
async sendBroadcastU(payload, loopback = false) {
|
|
1489
|
-
return await __classPrivateFieldGet$
|
|
3156
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sendBroadcastU(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"), payload, loopback);
|
|
1490
3157
|
}
|
|
1491
3158
|
async addSignalHandler(handler) {
|
|
1492
|
-
await __classPrivateFieldGet$
|
|
3159
|
+
await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").addSignalHandler(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"), handler);
|
|
1493
3160
|
}
|
|
1494
3161
|
removeSignalHandler(handler) {
|
|
1495
|
-
__classPrivateFieldGet$
|
|
3162
|
+
__classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").removeSignalHandler(__classPrivateFieldGet$9(this, _NeighbourhoodProxy_pID, "f"), handler);
|
|
3163
|
+
}
|
|
3164
|
+
get sessions() {
|
|
3165
|
+
return __classPrivateFieldGet$9(this, _NeighbourhoodProxy_sessions, "f");
|
|
3166
|
+
}
|
|
3167
|
+
async createSession(roomName, options) {
|
|
3168
|
+
if (!__classPrivateFieldGet$9(this, _NeighbourhoodProxy_agentDid, "f")) {
|
|
3169
|
+
__classPrivateFieldSet$9(this, _NeighbourhoodProxy_agentDid, await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").callerDid() ?? "", "f");
|
|
3170
|
+
}
|
|
3171
|
+
if (!__classPrivateFieldGet$9(this, _NeighbourhoodProxy_agentDid, "f")) {
|
|
3172
|
+
throw new Error("Cannot create a call session: the executor reports no agent DID");
|
|
3173
|
+
}
|
|
3174
|
+
if (!__classPrivateFieldGet$9(this, _NeighbourhoodProxy_sfuStatusCache, "f")) {
|
|
3175
|
+
try {
|
|
3176
|
+
__classPrivateFieldSet$9(this, _NeighbourhoodProxy_sfuStatusCache, await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuStatus(), "f");
|
|
3177
|
+
} catch {
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
const proxy = this;
|
|
3181
|
+
const session = createSession({
|
|
3182
|
+
api: __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f"),
|
|
3183
|
+
roomId: roomName,
|
|
3184
|
+
agentDid: __classPrivateFieldGet$9(this, _NeighbourhoodProxy_agentDid, "f"),
|
|
3185
|
+
neighbourhoodUrl: options?.neighbourhoodUrl ?? "",
|
|
3186
|
+
topology: options?.topology ?? "auto",
|
|
3187
|
+
sfuConfig: options?.sfuConfig,
|
|
3188
|
+
iceServers: options?.iceServers,
|
|
3189
|
+
localSfuStatus: __classPrivateFieldGet$9(this, _NeighbourhoodProxy_sfuStatusCache, "f") ?? void 0,
|
|
3190
|
+
sfuServesAllMembers: () => __classPrivateFieldGet$9(proxy, _NeighbourhoodProxy_client, "f").sfuServesAllMembers(__classPrivateFieldGet$9(proxy, _NeighbourhoodProxy_pID, "f")),
|
|
3191
|
+
channel: createTelepresenceChannel(proxy, __classPrivateFieldGet$9(proxy, _NeighbourhoodProxy_agentDid, "f")),
|
|
3192
|
+
ownOnlineStatus: () => proxy.ownOnlineStatus(),
|
|
3193
|
+
setOnlineStatus: (status) => proxy.setOnlineStatusU(status),
|
|
3194
|
+
onlineAgents: () => proxy.onlineAgents()
|
|
3195
|
+
});
|
|
3196
|
+
__classPrivateFieldGet$9(this, _NeighbourhoodProxy_sessions, "f").push(session);
|
|
3197
|
+
session.on("state-changed", (state) => {
|
|
3198
|
+
if (state === "closed") {
|
|
3199
|
+
const idx = __classPrivateFieldGet$9(this, _NeighbourhoodProxy_sessions, "f").indexOf(session);
|
|
3200
|
+
if (idx !== -1)
|
|
3201
|
+
__classPrivateFieldGet$9(this, _NeighbourhoodProxy_sessions, "f").splice(idx, 1);
|
|
3202
|
+
}
|
|
3203
|
+
});
|
|
3204
|
+
return session;
|
|
3205
|
+
}
|
|
3206
|
+
async sfuConfig(neighbourhoodUrl) {
|
|
3207
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuGetConfig(neighbourhoodUrl);
|
|
3208
|
+
}
|
|
3209
|
+
async setSfuConfig(neighbourhoodUrl, config) {
|
|
3210
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuSetConfig(neighbourhoodUrl, config);
|
|
3211
|
+
}
|
|
3212
|
+
async sfuPeer(neighbourhoodUrl) {
|
|
3213
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuPeerForNeighbourhood(neighbourhoodUrl);
|
|
3214
|
+
}
|
|
3215
|
+
async sfuPeers(neighbourhoodUrl) {
|
|
3216
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuPeersForNeighbourhood(neighbourhoodUrl);
|
|
3217
|
+
}
|
|
3218
|
+
async sfuStartRoom(neighbourhoodUrl, roomName) {
|
|
3219
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuStartRoom(neighbourhoodUrl, roomName);
|
|
3220
|
+
}
|
|
3221
|
+
async sfuStopRoom(neighbourhoodUrl, roomName) {
|
|
3222
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuStopRoom(neighbourhoodUrl, roomName);
|
|
3223
|
+
}
|
|
3224
|
+
async sfuListRooms() {
|
|
3225
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuListRooms();
|
|
3226
|
+
}
|
|
3227
|
+
async callJoin(neighbourhoodUrl, roomName, sdpOffer) {
|
|
3228
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuCallJoin(neighbourhoodUrl, roomName, sdpOffer);
|
|
3229
|
+
}
|
|
3230
|
+
async callLeave(neighbourhoodUrl, roomName) {
|
|
3231
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuCallLeave(neighbourhoodUrl, roomName);
|
|
3232
|
+
}
|
|
3233
|
+
async callSetQualityPreference(neighbourhoodUrl, roomName, preference) {
|
|
3234
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuCallSetQualityPreference(neighbourhoodUrl, roomName, preference);
|
|
3235
|
+
}
|
|
3236
|
+
async callAnswerServerOffer(neighbourhoodUrl, roomName, sdpAnswer) {
|
|
3237
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuCallAnswerServerOffer(neighbourhoodUrl, roomName, sdpAnswer);
|
|
3238
|
+
}
|
|
3239
|
+
subscribeCallRenegotiationOffer(targetDid, callback) {
|
|
3240
|
+
return __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").subscribeSfuCallRenegotiationOffer(targetDid, callback);
|
|
3241
|
+
}
|
|
3242
|
+
subscribeMigrateEvent(targetDid, callback) {
|
|
3243
|
+
return __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").subscribeSfuMigrateEvent(targetDid, callback);
|
|
3244
|
+
}
|
|
3245
|
+
async addIceCandidate(neighbourhoodUrl, roomName, candidate) {
|
|
3246
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuAddIceCandidate(neighbourhoodUrl, roomName, candidate);
|
|
3247
|
+
}
|
|
3248
|
+
async sendData(neighbourhoodUrl, roomName, channelLabel, data, binary = false) {
|
|
3249
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuSendData(neighbourhoodUrl, roomName, channelLabel, data, binary);
|
|
3250
|
+
}
|
|
3251
|
+
subscribeDataChannel(callback) {
|
|
3252
|
+
return __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").subscribeSfuDataChannel(callback);
|
|
3253
|
+
}
|
|
3254
|
+
async sfuCascadeStatus() {
|
|
3255
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuCascadeStatus();
|
|
3256
|
+
}
|
|
3257
|
+
async sfuQualityPreferences() {
|
|
3258
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuQualityPreferences();
|
|
3259
|
+
}
|
|
3260
|
+
async sfuEnsureMembership(neighbourhoodUrl, did) {
|
|
3261
|
+
return await __classPrivateFieldGet$9(this, _NeighbourhoodProxy_client, "f").sfuEnsureMembership(neighbourhoodUrl, did);
|
|
1496
3262
|
}
|
|
1497
3263
|
};
|
|
1498
|
-
_NeighbourhoodProxy_client = /* @__PURE__ */ new WeakMap(), _NeighbourhoodProxy_pID = /* @__PURE__ */ new WeakMap();
|
|
3264
|
+
_NeighbourhoodProxy_client = /* @__PURE__ */ new WeakMap(), _NeighbourhoodProxy_pID = /* @__PURE__ */ new WeakMap(), _NeighbourhoodProxy_agentDid = /* @__PURE__ */ new WeakMap(), _NeighbourhoodProxy_sessions = /* @__PURE__ */ new WeakMap(), _NeighbourhoodProxy_sfuStatusCache = /* @__PURE__ */ new WeakMap();
|
|
1499
3265
|
var LinkQuery = class {
|
|
1500
3266
|
constructor(obj) {
|
|
1501
3267
|
if (obj) {
|
|
@@ -1529,7 +3295,7 @@ var LinkQuery = class {
|
|
|
1529
3295
|
return true;
|
|
1530
3296
|
}
|
|
1531
3297
|
};
|
|
1532
|
-
var __classPrivateFieldSet$
|
|
3298
|
+
var __classPrivateFieldSet$8 = function(receiver, state, value, kind, f) {
|
|
1533
3299
|
if (kind === "m")
|
|
1534
3300
|
throw new TypeError("Private method is not writable");
|
|
1535
3301
|
if (kind === "a" && !f)
|
|
@@ -1538,7 +3304,7 @@ var __classPrivateFieldSet$7 = function(receiver, state, value, kind, f) {
|
|
|
1538
3304
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1539
3305
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1540
3306
|
};
|
|
1541
|
-
var __classPrivateFieldGet$
|
|
3307
|
+
var __classPrivateFieldGet$8 = function(receiver, state, kind, f) {
|
|
1542
3308
|
if (kind === "a" && !f)
|
|
1543
3309
|
throw new TypeError("Private accessor was defined without a getter");
|
|
1544
3310
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -1561,44 +3327,44 @@ var Literal = class {
|
|
|
1561
3327
|
if (url.startsWith("literal://"))
|
|
1562
3328
|
throw new Error("literal:// format is no longer supported. Use literal: instead.");
|
|
1563
3329
|
const l = new Literal();
|
|
1564
|
-
__classPrivateFieldSet$
|
|
3330
|
+
__classPrivateFieldSet$8(l, _Literal_url, url, "f");
|
|
1565
3331
|
return l;
|
|
1566
3332
|
}
|
|
1567
3333
|
static from(literal2) {
|
|
1568
3334
|
const l = new Literal();
|
|
1569
|
-
__classPrivateFieldSet$
|
|
3335
|
+
__classPrivateFieldSet$8(l, _Literal_literal, literal2, "f");
|
|
1570
3336
|
return l;
|
|
1571
3337
|
}
|
|
1572
3338
|
toUrl() {
|
|
1573
|
-
if (__classPrivateFieldGet$
|
|
1574
|
-
return __classPrivateFieldGet$
|
|
1575
|
-
if (__classPrivateFieldGet$
|
|
3339
|
+
if (__classPrivateFieldGet$8(this, _Literal_url, "f") && __classPrivateFieldGet$8(this, _Literal_literal, "f") === void 0)
|
|
3340
|
+
return __classPrivateFieldGet$8(this, _Literal_url, "f");
|
|
3341
|
+
if (__classPrivateFieldGet$8(this, _Literal_literal, "f") === void 0)
|
|
1576
3342
|
throw new Error("Can't turn empty Literal into URL");
|
|
1577
3343
|
let encoded;
|
|
1578
|
-
switch (typeof __classPrivateFieldGet$
|
|
3344
|
+
switch (typeof __classPrivateFieldGet$8(this, _Literal_literal, "f")) {
|
|
1579
3345
|
case "string":
|
|
1580
|
-
encoded = `string:${encodeRFC3986URIComponent(__classPrivateFieldGet$
|
|
3346
|
+
encoded = `string:${encodeRFC3986URIComponent(__classPrivateFieldGet$8(this, _Literal_literal, "f"))}`;
|
|
1581
3347
|
break;
|
|
1582
3348
|
case "number":
|
|
1583
|
-
encoded = `number:${encodeRFC3986URIComponent(__classPrivateFieldGet$
|
|
3349
|
+
encoded = `number:${encodeRFC3986URIComponent(__classPrivateFieldGet$8(this, _Literal_literal, "f"))}`;
|
|
1584
3350
|
break;
|
|
1585
3351
|
case "boolean":
|
|
1586
|
-
encoded = `boolean:${encodeRFC3986URIComponent(__classPrivateFieldGet$
|
|
3352
|
+
encoded = `boolean:${encodeRFC3986URIComponent(__classPrivateFieldGet$8(this, _Literal_literal, "f"))}`;
|
|
1587
3353
|
break;
|
|
1588
3354
|
case "object":
|
|
1589
|
-
encoded = `json:${encodeRFC3986URIComponent(JSON.stringify(__classPrivateFieldGet$
|
|
3355
|
+
encoded = `json:${encodeRFC3986URIComponent(JSON.stringify(__classPrivateFieldGet$8(this, _Literal_literal, "f")))}`;
|
|
1590
3356
|
break;
|
|
1591
3357
|
}
|
|
1592
3358
|
return `literal:${encoded}`;
|
|
1593
3359
|
}
|
|
1594
3360
|
get() {
|
|
1595
|
-
if (__classPrivateFieldGet$
|
|
1596
|
-
return __classPrivateFieldGet$
|
|
1597
|
-
if (!__classPrivateFieldGet$
|
|
3361
|
+
if (__classPrivateFieldGet$8(this, _Literal_literal, "f") !== void 0)
|
|
3362
|
+
return __classPrivateFieldGet$8(this, _Literal_literal, "f");
|
|
3363
|
+
if (!__classPrivateFieldGet$8(this, _Literal_url, "f"))
|
|
1598
3364
|
throw new Error("Can't render empty Literal");
|
|
1599
|
-
if (!__classPrivateFieldGet$
|
|
3365
|
+
if (!__classPrivateFieldGet$8(this, _Literal_url, "f").startsWith("literal:"))
|
|
1600
3366
|
throw new Error("Can't render Literal from non-literal URL");
|
|
1601
|
-
const body = __classPrivateFieldGet$
|
|
3367
|
+
const body = __classPrivateFieldGet$8(this, _Literal_url, "f").substring(8);
|
|
1602
3368
|
if (body.startsWith("string:")) {
|
|
1603
3369
|
return decodeURIComponent(body.substring(7));
|
|
1604
3370
|
}
|
|
@@ -1842,6 +3608,16 @@ function parseTransform(json, propShapeId) {
|
|
|
1842
3608
|
}
|
|
1843
3609
|
return parsed;
|
|
1844
3610
|
}
|
|
3611
|
+
function parseAlias(raw) {
|
|
3612
|
+
try {
|
|
3613
|
+
const parsed = JSON.parse(decodeURIComponent(raw));
|
|
3614
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed) && Object.values(parsed).every((v) => typeof v === "string")) {
|
|
3615
|
+
return parsed;
|
|
3616
|
+
}
|
|
3617
|
+
} catch {
|
|
3618
|
+
}
|
|
3619
|
+
return void 0;
|
|
3620
|
+
}
|
|
1845
3621
|
function isCollection(p) {
|
|
1846
3622
|
return p.collection ?? (p.relationKind === "hasMany" || p.relationKind === "belongsToMany");
|
|
1847
3623
|
}
|
|
@@ -1971,6 +3747,13 @@ var SHACLShape = class {
|
|
|
1971
3747
|
target: `literal:string:${this.interpretationHint}`
|
|
1972
3748
|
});
|
|
1973
3749
|
}
|
|
3750
|
+
if (this.isAbstract) {
|
|
3751
|
+
links.push({
|
|
3752
|
+
source: this.nodeShapeUri,
|
|
3753
|
+
predicate: "ad4m://abstract",
|
|
3754
|
+
target: "literal:true"
|
|
3755
|
+
});
|
|
3756
|
+
}
|
|
1974
3757
|
for (let i = 0; i < this.properties.length; i++) {
|
|
1975
3758
|
const prop = this.properties[i];
|
|
1976
3759
|
let propShapeId;
|
|
@@ -2186,6 +3969,13 @@ var SHACLShape = class {
|
|
|
2186
3969
|
target: `literal:string:true`
|
|
2187
3970
|
});
|
|
2188
3971
|
}
|
|
3972
|
+
if (prop.alias && Object.keys(prop.alias).length > 0) {
|
|
3973
|
+
links.push({
|
|
3974
|
+
source: propShapeId,
|
|
3975
|
+
predicate: "ad4m://alias",
|
|
3976
|
+
target: `literal:string:${encodeURIComponent(JSON.stringify(prop.alias))}`
|
|
3977
|
+
});
|
|
3978
|
+
}
|
|
2189
3979
|
}
|
|
2190
3980
|
return links;
|
|
2191
3981
|
}
|
|
@@ -2219,6 +4009,8 @@ var SHACLShape = class {
|
|
|
2219
4009
|
shape.constructor_actions = json(shapeUri, "ad4m://constructor");
|
|
2220
4010
|
shape.destructor_actions = json(shapeUri, "ad4m://destructor");
|
|
2221
4011
|
shape.interpretationHint = str(shapeUri, "ad4m://interpretation_hint");
|
|
4012
|
+
if (bool(shapeUri, "ad4m://abstract"))
|
|
4013
|
+
shape.isAbstract = true;
|
|
2222
4014
|
for (const propLink of links.filter((l) => l.source === shapeUri && l.predicate === "sh://property")) {
|
|
2223
4015
|
const id = propLink.target;
|
|
2224
4016
|
const path2 = target(id, "sh://path");
|
|
@@ -2230,6 +4022,7 @@ var SHACLShape = class {
|
|
|
2230
4022
|
const hasValue = target(id, "sh://hasValue");
|
|
2231
4023
|
const identity = str(id, "ad4m://identity");
|
|
2232
4024
|
const transform = str(id, "ad4m://transform");
|
|
4025
|
+
const alias = str(id, "ad4m://alias");
|
|
2233
4026
|
const prop = {
|
|
2234
4027
|
name,
|
|
2235
4028
|
path: path2,
|
|
@@ -2260,7 +4053,8 @@ var SHACLShape = class {
|
|
|
2260
4053
|
filter: bool(id, "ad4m://filter"),
|
|
2261
4054
|
interpretationHint: str(id, "ad4m://interpretation_hint"),
|
|
2262
4055
|
identity: identity === void 0 ? void 0 : identity === "true",
|
|
2263
|
-
transform: transform === void 0 ? void 0 : parseTransform(transform, id)
|
|
4056
|
+
transform: transform === void 0 ? void 0 : parseTransform(transform, id),
|
|
4057
|
+
alias: alias === void 0 ? void 0 : parseAlias(alias)
|
|
2264
4058
|
};
|
|
2265
4059
|
shape.addProperty(Object.fromEntries(Object.entries(prop).filter(([, v]) => v !== void 0)));
|
|
2266
4060
|
}
|
|
@@ -2272,6 +4066,7 @@ var SHACLShape = class {
|
|
|
2272
4066
|
target_class: this.targetClass,
|
|
2273
4067
|
parent_shapes: this.parentShapes.length > 0 ? this.parentShapes : void 0,
|
|
2274
4068
|
interpretation_hint: this.interpretationHint,
|
|
4069
|
+
abstract: this.isAbstract || void 0,
|
|
2275
4070
|
properties: this.properties.map((p) => ({
|
|
2276
4071
|
path: p.path,
|
|
2277
4072
|
name: p.name,
|
|
@@ -2302,6 +4097,7 @@ var SHACLShape = class {
|
|
|
2302
4097
|
transform: p.transform,
|
|
2303
4098
|
interpretation_hint: p.interpretationHint,
|
|
2304
4099
|
identity: p.identity,
|
|
4100
|
+
alias: p.alias,
|
|
2305
4101
|
ordering: p.ordering
|
|
2306
4102
|
})),
|
|
2307
4103
|
constructor_actions: this.constructor_actions,
|
|
@@ -2344,7 +4140,8 @@ var SHACLShape = class {
|
|
|
2344
4140
|
transform: p.transform,
|
|
2345
4141
|
interpretationHint: p.interpretation_hint,
|
|
2346
4142
|
identity: p.identity,
|
|
2347
|
-
ordering: p.ordering
|
|
4143
|
+
ordering: p.ordering,
|
|
4144
|
+
alias: p.alias
|
|
2348
4145
|
});
|
|
2349
4146
|
}
|
|
2350
4147
|
if (json.constructor_actions) {
|
|
@@ -2361,10 +4158,13 @@ var SHACLShape = class {
|
|
|
2361
4158
|
if (json.interpretation_hint) {
|
|
2362
4159
|
shape.interpretationHint = json.interpretation_hint;
|
|
2363
4160
|
}
|
|
4161
|
+
if (json.abstract) {
|
|
4162
|
+
shape.isAbstract = true;
|
|
4163
|
+
}
|
|
2364
4164
|
return shape;
|
|
2365
4165
|
}
|
|
2366
4166
|
};
|
|
2367
|
-
function buildSHACL(subjectName, target, properties, allRelationsMeta, conformanceFilterFn, seedCache, interpretationHint) {
|
|
4167
|
+
function buildSHACL(subjectName, target, properties, allRelationsMeta, conformanceFilterFn, seedCache, interpretationHint, isAbstract) {
|
|
2368
4168
|
const obj = target.prototype;
|
|
2369
4169
|
let namespace = "ad4m://";
|
|
2370
4170
|
if (Object.keys(properties).length > 0) {
|
|
@@ -2390,6 +4190,9 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
|
|
|
2390
4190
|
if (interpretationHint) {
|
|
2391
4191
|
shape.interpretationHint = interpretationHint;
|
|
2392
4192
|
}
|
|
4193
|
+
if (isAbstract) {
|
|
4194
|
+
shape.isAbstract = true;
|
|
4195
|
+
}
|
|
2393
4196
|
if (seedCache) {
|
|
2394
4197
|
seedCache({ shape, name: subjectName });
|
|
2395
4198
|
}
|
|
@@ -2473,6 +4276,9 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
|
|
|
2473
4276
|
if (propMeta.identity) {
|
|
2474
4277
|
propShape.identity = true;
|
|
2475
4278
|
}
|
|
4279
|
+
if (propMeta.alias) {
|
|
4280
|
+
propShape.alias = propMeta.alias;
|
|
4281
|
+
}
|
|
2476
4282
|
if (propMeta.prologSetter) {
|
|
2477
4283
|
console.warn(`[SHACL Generation] Custom Prolog setter for property '${propName}' in class '${subjectName}' is not yet supported. The property will be created without setter actions. Consider using standard writable properties or provide explicit SHACL JSON.`);
|
|
2478
4284
|
} else if (propMeta.writable && propMeta.through) {
|
|
@@ -2537,6 +4343,9 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
|
|
|
2537
4343
|
if (relMeta.interpretationHint) {
|
|
2538
4344
|
relShape.interpretationHint = relMeta.interpretationHint;
|
|
2539
4345
|
}
|
|
4346
|
+
if (relMeta.alias) {
|
|
4347
|
+
relShape.alias = relMeta.alias;
|
|
4348
|
+
}
|
|
2540
4349
|
if (relMeta.readOnly) {
|
|
2541
4350
|
relShape.writable = false;
|
|
2542
4351
|
} else if (relMeta.predicate) {
|
|
@@ -2795,15 +4604,45 @@ function Optional(opts) {
|
|
|
2795
4604
|
readOnly: opts.readOnly ?? false
|
|
2796
4605
|
});
|
|
2797
4606
|
}
|
|
4607
|
+
function checkImplements(name, target, abstractClass) {
|
|
4608
|
+
const abstractName = abstractClass?.className ?? abstractClass?.prototype?.className;
|
|
4609
|
+
if (!abstractName || !abstractClass.isAbstract) {
|
|
4610
|
+
throw new Error(`${name} implements ${abstractName ?? abstractClass?.name ?? String(abstractClass)}, which is not an abstract class: declare it with @Model({ abstract: true })`);
|
|
4611
|
+
}
|
|
4612
|
+
const names = (ctor) => {
|
|
4613
|
+
const relations = getRelationsMetadata(ctor);
|
|
4614
|
+
const properties = Object.keys(getPropertiesMetadata(ctor)).filter((p) => !relations[p]);
|
|
4615
|
+
return { properties, relations: Object.keys(relations) };
|
|
4616
|
+
};
|
|
4617
|
+
const answersTo = (entries, keys) => new Set(keys.map((k) => entries[k]?.alias?.[abstractName] ?? k));
|
|
4618
|
+
const wanted = names(abstractClass);
|
|
4619
|
+
const own = names(target);
|
|
4620
|
+
const ownProperties = answersTo(getPropertiesMetadata(target), own.properties);
|
|
4621
|
+
const ownRelations = answersTo(getRelationsMetadata(target), own.relations);
|
|
4622
|
+
for (const p of wanted.properties) {
|
|
4623
|
+
if (!ownProperties.has(p)) {
|
|
4624
|
+
throw new Error(`${name} implements ${abstractName} but has no property or alias named \`${p}\``);
|
|
4625
|
+
}
|
|
4626
|
+
}
|
|
4627
|
+
for (const r of wanted.relations) {
|
|
4628
|
+
if (!ownRelations.has(r)) {
|
|
4629
|
+
throw new Error(`${name} implements ${abstractName} but has no relation or alias named \`${r}\``);
|
|
4630
|
+
}
|
|
4631
|
+
}
|
|
4632
|
+
}
|
|
2798
4633
|
function Model$1(opts) {
|
|
2799
4634
|
return function(target) {
|
|
2800
4635
|
target.prototype.className = opts.name;
|
|
2801
4636
|
target.className = opts.name;
|
|
4637
|
+
target.isAbstract = !!opts.abstract;
|
|
4638
|
+
for (const abstractClass of opts.implements ?? []) {
|
|
4639
|
+
checkImplements(opts.name, target, abstractClass);
|
|
4640
|
+
}
|
|
2802
4641
|
target.generateSDNA = function() {
|
|
2803
4642
|
return buildSDNA(opts.name, target.prototype, getPropertiesMetadata(target), getRelationsMetadata(target));
|
|
2804
4643
|
};
|
|
2805
4644
|
target.generateSHACL = function() {
|
|
2806
|
-
return getMemoizedSHACL(target, (seed) => buildSHACL(opts.name, target, getPropertiesMetadata(target), getRelationsMetadata(target), buildConformanceFilter, seed, opts.interpretationHint));
|
|
4645
|
+
return getMemoizedSHACL(target, (seed) => buildSHACL(opts.name, target, getPropertiesMetadata(target), getRelationsMetadata(target), buildConformanceFilter, seed, opts.interpretationHint, !!opts.abstract));
|
|
2807
4646
|
};
|
|
2808
4647
|
Object.defineProperty(target, "type", { configurable: true });
|
|
2809
4648
|
};
|
|
@@ -2856,6 +4695,7 @@ function HasMany(first, second) {
|
|
|
2856
4695
|
...opts.instantiateAs && { instantiateAs: opts.instantiateAs },
|
|
2857
4696
|
...opts.ordering && { ordering: opts.ordering },
|
|
2858
4697
|
...opts.interpretationHint && { interpretationHint: opts.interpretationHint },
|
|
4698
|
+
...opts.alias && { alias: opts.alias },
|
|
2859
4699
|
...opts.readOnly && { readOnly: true }
|
|
2860
4700
|
};
|
|
2861
4701
|
const relKey = key;
|
|
@@ -2907,6 +4747,187 @@ function invalidatePerspectiveCache(perspectiveUUID) {
|
|
|
2907
4747
|
}
|
|
2908
4748
|
}
|
|
2909
4749
|
}
|
|
4750
|
+
var __classPrivateFieldSet$7 = function(receiver, state, value, kind, f) {
|
|
4751
|
+
if (kind === "m")
|
|
4752
|
+
throw new TypeError("Private method is not writable");
|
|
4753
|
+
if (kind === "a" && !f)
|
|
4754
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
4755
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
4756
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
4757
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
4758
|
+
};
|
|
4759
|
+
var __classPrivateFieldGet$7 = function(receiver, state, kind, f) {
|
|
4760
|
+
if (kind === "a" && !f)
|
|
4761
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
4762
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
4763
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4764
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
4765
|
+
};
|
|
4766
|
+
var _LiveQuery_instances;
|
|
4767
|
+
var _LiveQuery_client;
|
|
4768
|
+
var _LiveQuery_uuid;
|
|
4769
|
+
var _LiveQuery_open;
|
|
4770
|
+
var _LiveQuery_onResult;
|
|
4771
|
+
var _LiveQuery_id;
|
|
4772
|
+
var _LiveQuery_revision;
|
|
4773
|
+
var _LiveQuery_result;
|
|
4774
|
+
var _LiveQuery_started;
|
|
4775
|
+
var _LiveQuery_disposed;
|
|
4776
|
+
var _LiveQuery_generation;
|
|
4777
|
+
var _LiveQuery_latest;
|
|
4778
|
+
var _LiveQuery_buffer;
|
|
4779
|
+
var _LiveQuery_unlisten;
|
|
4780
|
+
var _LiveQuery_unreconnect;
|
|
4781
|
+
var _LiveQuery_start;
|
|
4782
|
+
var _LiveQuery_replace;
|
|
4783
|
+
var _LiveQuery_receive;
|
|
4784
|
+
var _LiveQuery_resync;
|
|
4785
|
+
function applyUpdate(result, update) {
|
|
4786
|
+
if ("result" in update)
|
|
4787
|
+
return update.result;
|
|
4788
|
+
if (update.ids) {
|
|
4789
|
+
const byId = new Map(result.instances.map((i) => [i.id, i]));
|
|
4790
|
+
for (const instance of update.upsert)
|
|
4791
|
+
byId.set(instance.id, instance);
|
|
4792
|
+
const instances = update.ids.map((id) => {
|
|
4793
|
+
if (!byId.has(id))
|
|
4794
|
+
throw new Error(`Live query update names unknown instance ${id}`);
|
|
4795
|
+
return byId.get(id);
|
|
4796
|
+
});
|
|
4797
|
+
return { ...result, instances, totalCount: update.totalCount };
|
|
4798
|
+
}
|
|
4799
|
+
const toRemove = /* @__PURE__ */ new Map();
|
|
4800
|
+
for (const row of update.removed) {
|
|
4801
|
+
const key = JSON.stringify(row);
|
|
4802
|
+
toRemove.set(key, (toRemove.get(key) ?? 0) + 1);
|
|
4803
|
+
}
|
|
4804
|
+
const kept = result.filter((row) => {
|
|
4805
|
+
const key = JSON.stringify(row);
|
|
4806
|
+
const n = toRemove.get(key);
|
|
4807
|
+
if (!n)
|
|
4808
|
+
return true;
|
|
4809
|
+
toRemove.set(key, n - 1);
|
|
4810
|
+
return false;
|
|
4811
|
+
});
|
|
4812
|
+
return [...kept, ...update.added];
|
|
4813
|
+
}
|
|
4814
|
+
var LiveQuery = class {
|
|
4815
|
+
constructor(client, uuid, open, onResult) {
|
|
4816
|
+
_LiveQuery_instances.add(this);
|
|
4817
|
+
_LiveQuery_client.set(this, void 0);
|
|
4818
|
+
_LiveQuery_uuid.set(this, void 0);
|
|
4819
|
+
_LiveQuery_open.set(this, void 0);
|
|
4820
|
+
_LiveQuery_onResult.set(this, void 0);
|
|
4821
|
+
_LiveQuery_id.set(this, void 0);
|
|
4822
|
+
_LiveQuery_revision.set(this, 0);
|
|
4823
|
+
_LiveQuery_result.set(this, void 0);
|
|
4824
|
+
_LiveQuery_started.set(this, false);
|
|
4825
|
+
_LiveQuery_disposed.set(this, false);
|
|
4826
|
+
_LiveQuery_generation.set(this, 0);
|
|
4827
|
+
_LiveQuery_latest.set(this, void 0);
|
|
4828
|
+
_LiveQuery_buffer.set(this, null);
|
|
4829
|
+
_LiveQuery_unlisten.set(this, void 0);
|
|
4830
|
+
_LiveQuery_unreconnect.set(this, void 0);
|
|
4831
|
+
__classPrivateFieldSet$7(this, _LiveQuery_client, client, "f");
|
|
4832
|
+
__classPrivateFieldSet$7(this, _LiveQuery_uuid, uuid, "f");
|
|
4833
|
+
__classPrivateFieldSet$7(this, _LiveQuery_open, open, "f");
|
|
4834
|
+
__classPrivateFieldSet$7(this, _LiveQuery_onResult, onResult, "f");
|
|
4835
|
+
__classPrivateFieldSet$7(this, _LiveQuery_unlisten, client.onQueryUpdate((update) => __classPrivateFieldGet$7(this, _LiveQuery_instances, "m", _LiveQuery_receive).call(this, update)), "f");
|
|
4836
|
+
__classPrivateFieldSet$7(this, _LiveQuery_unreconnect, client.onReconnect(() => {
|
|
4837
|
+
this.start().catch((e) => console.error("Error re-opening live query after reconnect:", e));
|
|
4838
|
+
}), "f");
|
|
4839
|
+
}
|
|
4840
|
+
get id() {
|
|
4841
|
+
return __classPrivateFieldGet$7(this, _LiveQuery_id, "f");
|
|
4842
|
+
}
|
|
4843
|
+
get result() {
|
|
4844
|
+
return __classPrivateFieldGet$7(this, _LiveQuery_result, "f");
|
|
4845
|
+
}
|
|
4846
|
+
start() {
|
|
4847
|
+
var _a;
|
|
4848
|
+
__classPrivateFieldSet$7(this, _LiveQuery_latest, __classPrivateFieldGet$7(this, _LiveQuery_instances, "m", _LiveQuery_start).call(this, __classPrivateFieldSet$7(this, _LiveQuery_generation, (_a = __classPrivateFieldGet$7(this, _LiveQuery_generation, "f"), ++_a), "f")), "f");
|
|
4849
|
+
return __classPrivateFieldGet$7(this, _LiveQuery_latest, "f");
|
|
4850
|
+
}
|
|
4851
|
+
dispose() {
|
|
4852
|
+
var _a;
|
|
4853
|
+
__classPrivateFieldSet$7(this, _LiveQuery_disposed, true, "f");
|
|
4854
|
+
__classPrivateFieldSet$7(this, _LiveQuery_generation, (_a = __classPrivateFieldGet$7(this, _LiveQuery_generation, "f"), _a++, _a), "f");
|
|
4855
|
+
__classPrivateFieldGet$7(this, _LiveQuery_unlisten, "f").call(this);
|
|
4856
|
+
__classPrivateFieldGet$7(this, _LiveQuery_unreconnect, "f").call(this);
|
|
4857
|
+
if (__classPrivateFieldGet$7(this, _LiveQuery_id, "f"))
|
|
4858
|
+
__classPrivateFieldGet$7(this, _LiveQuery_client, "f").disposeQuerySubscription(__classPrivateFieldGet$7(this, _LiveQuery_uuid, "f"), __classPrivateFieldGet$7(this, _LiveQuery_id, "f")).catch(() => {
|
|
4859
|
+
});
|
|
4860
|
+
}
|
|
4861
|
+
};
|
|
4862
|
+
_LiveQuery_client = /* @__PURE__ */ new WeakMap(), _LiveQuery_uuid = /* @__PURE__ */ new WeakMap(), _LiveQuery_open = /* @__PURE__ */ new WeakMap(), _LiveQuery_onResult = /* @__PURE__ */ new WeakMap(), _LiveQuery_id = /* @__PURE__ */ new WeakMap(), _LiveQuery_revision = /* @__PURE__ */ new WeakMap(), _LiveQuery_result = /* @__PURE__ */ new WeakMap(), _LiveQuery_started = /* @__PURE__ */ new WeakMap(), _LiveQuery_disposed = /* @__PURE__ */ new WeakMap(), _LiveQuery_generation = /* @__PURE__ */ new WeakMap(), _LiveQuery_latest = /* @__PURE__ */ new WeakMap(), _LiveQuery_buffer = /* @__PURE__ */ new WeakMap(), _LiveQuery_unlisten = /* @__PURE__ */ new WeakMap(), _LiveQuery_unreconnect = /* @__PURE__ */ new WeakMap(), _LiveQuery_instances = /* @__PURE__ */ new WeakSet(), _LiveQuery_start = async function _LiveQuery_start2(generation) {
|
|
4863
|
+
__classPrivateFieldSet$7(this, _LiveQuery_buffer, [], "f");
|
|
4864
|
+
let subscribed;
|
|
4865
|
+
try {
|
|
4866
|
+
subscribed = await __classPrivateFieldGet$7(this, _LiveQuery_open, "f").call(this);
|
|
4867
|
+
} catch (e) {
|
|
4868
|
+
if (generation === __classPrivateFieldGet$7(this, _LiveQuery_generation, "f"))
|
|
4869
|
+
__classPrivateFieldSet$7(this, _LiveQuery_buffer, null, "f");
|
|
4870
|
+
throw e;
|
|
4871
|
+
}
|
|
4872
|
+
if (__classPrivateFieldGet$7(this, _LiveQuery_disposed, "f") || generation !== __classPrivateFieldGet$7(this, _LiveQuery_generation, "f")) {
|
|
4873
|
+
__classPrivateFieldGet$7(this, _LiveQuery_client, "f").disposeQuerySubscription(__classPrivateFieldGet$7(this, _LiveQuery_uuid, "f"), subscribed.subscriptionId).catch(() => {
|
|
4874
|
+
});
|
|
4875
|
+
return __classPrivateFieldGet$7(this, _LiveQuery_disposed, "f") ? __classPrivateFieldGet$7(this, _LiveQuery_result, "f") ?? subscribed.result : __classPrivateFieldGet$7(this, _LiveQuery_latest, "f");
|
|
4876
|
+
}
|
|
4877
|
+
__classPrivateFieldSet$7(this, _LiveQuery_id, subscribed.subscriptionId, "f");
|
|
4878
|
+
__classPrivateFieldGet$7(this, _LiveQuery_instances, "m", _LiveQuery_replace).call(this, subscribed.revision, subscribed.result);
|
|
4879
|
+
return __classPrivateFieldGet$7(this, _LiveQuery_result, "f");
|
|
4880
|
+
}, _LiveQuery_replace = function _LiveQuery_replace2(revision, result) {
|
|
4881
|
+
__classPrivateFieldSet$7(this, _LiveQuery_revision, revision, "f");
|
|
4882
|
+
__classPrivateFieldSet$7(this, _LiveQuery_result, result, "f");
|
|
4883
|
+
const buffered = __classPrivateFieldGet$7(this, _LiveQuery_buffer, "f") ?? [];
|
|
4884
|
+
__classPrivateFieldSet$7(this, _LiveQuery_buffer, null, "f");
|
|
4885
|
+
if (__classPrivateFieldGet$7(this, _LiveQuery_started, "f"))
|
|
4886
|
+
__classPrivateFieldGet$7(this, _LiveQuery_onResult, "f").call(this, result);
|
|
4887
|
+
__classPrivateFieldSet$7(this, _LiveQuery_started, true, "f");
|
|
4888
|
+
for (const update of buffered)
|
|
4889
|
+
__classPrivateFieldGet$7(this, _LiveQuery_instances, "m", _LiveQuery_receive).call(this, update);
|
|
4890
|
+
}, _LiveQuery_receive = function _LiveQuery_receive2(update) {
|
|
4891
|
+
if (__classPrivateFieldGet$7(this, _LiveQuery_buffer, "f")) {
|
|
4892
|
+
__classPrivateFieldGet$7(this, _LiveQuery_buffer, "f").push(update);
|
|
4893
|
+
return;
|
|
4894
|
+
}
|
|
4895
|
+
if ("lagged" in update) {
|
|
4896
|
+
if (__classPrivateFieldGet$7(this, _LiveQuery_id, "f"))
|
|
4897
|
+
__classPrivateFieldGet$7(this, _LiveQuery_instances, "m", _LiveQuery_resync).call(this);
|
|
4898
|
+
return;
|
|
4899
|
+
}
|
|
4900
|
+
if (update.subscriptionId !== __classPrivateFieldGet$7(this, _LiveQuery_id, "f") || update.revision <= __classPrivateFieldGet$7(this, _LiveQuery_revision, "f"))
|
|
4901
|
+
return;
|
|
4902
|
+
if (update.revision !== __classPrivateFieldGet$7(this, _LiveQuery_revision, "f") + 1) {
|
|
4903
|
+
__classPrivateFieldGet$7(this, _LiveQuery_instances, "m", _LiveQuery_resync).call(this);
|
|
4904
|
+
return;
|
|
4905
|
+
}
|
|
4906
|
+
let result;
|
|
4907
|
+
try {
|
|
4908
|
+
result = applyUpdate(__classPrivateFieldGet$7(this, _LiveQuery_result, "f"), update);
|
|
4909
|
+
} catch {
|
|
4910
|
+
__classPrivateFieldGet$7(this, _LiveQuery_instances, "m", _LiveQuery_resync).call(this);
|
|
4911
|
+
return;
|
|
4912
|
+
}
|
|
4913
|
+
__classPrivateFieldSet$7(this, _LiveQuery_revision, update.revision, "f");
|
|
4914
|
+
__classPrivateFieldSet$7(this, _LiveQuery_result, result, "f");
|
|
4915
|
+
__classPrivateFieldGet$7(this, _LiveQuery_onResult, "f").call(this, __classPrivateFieldGet$7(this, _LiveQuery_result, "f"));
|
|
4916
|
+
}, _LiveQuery_resync = function _LiveQuery_resync2() {
|
|
4917
|
+
const generation = __classPrivateFieldGet$7(this, _LiveQuery_generation, "f");
|
|
4918
|
+
const id = __classPrivateFieldGet$7(this, _LiveQuery_id, "f");
|
|
4919
|
+
__classPrivateFieldSet$7(this, _LiveQuery_buffer, [], "f");
|
|
4920
|
+
__classPrivateFieldGet$7(this, _LiveQuery_client, "f").resyncSubscription(__classPrivateFieldGet$7(this, _LiveQuery_uuid, "f"), id).then(({ revision, result }) => {
|
|
4921
|
+
if (!__classPrivateFieldGet$7(this, _LiveQuery_disposed, "f") && generation === __classPrivateFieldGet$7(this, _LiveQuery_generation, "f"))
|
|
4922
|
+
__classPrivateFieldGet$7(this, _LiveQuery_instances, "m", _LiveQuery_replace).call(this, revision, result);
|
|
4923
|
+
}, () => {
|
|
4924
|
+
if (!__classPrivateFieldGet$7(this, _LiveQuery_disposed, "f") && generation === __classPrivateFieldGet$7(this, _LiveQuery_generation, "f")) {
|
|
4925
|
+
__classPrivateFieldGet$7(this, _LiveQuery_client, "f").disposeQuerySubscription(__classPrivateFieldGet$7(this, _LiveQuery_uuid, "f"), id).catch(() => {
|
|
4926
|
+
});
|
|
4927
|
+
this.start().catch((e) => console.error("Error re-opening live query:", e));
|
|
4928
|
+
}
|
|
4929
|
+
});
|
|
4930
|
+
};
|
|
2910
4931
|
function isModelQueryShape(v) {
|
|
2911
4932
|
if (typeof v !== "object" || v === null || typeof v.className !== "string" || v.className.length === 0) {
|
|
2912
4933
|
return false;
|
|
@@ -3361,6 +5382,13 @@ SHACLFlow.STATE_AND_TRANSITION_PREDICATES = [
|
|
|
3361
5382
|
"ad4m://toState",
|
|
3362
5383
|
"ad4m://transitionActions"
|
|
3363
5384
|
];
|
|
5385
|
+
var __classPrivateFieldGet$6 = function(receiver, state, kind, f) {
|
|
5386
|
+
if (kind === "a" && !f)
|
|
5387
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
5388
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
5389
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5390
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5391
|
+
};
|
|
3364
5392
|
var __classPrivateFieldSet$6 = function(receiver, state, value, kind, f) {
|
|
3365
5393
|
if (kind === "m")
|
|
3366
5394
|
throw new TypeError("Private method is not writable");
|
|
@@ -3370,33 +5398,13 @@ var __classPrivateFieldSet$6 = function(receiver, state, value, kind, f) {
|
|
|
3370
5398
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
3371
5399
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
3372
5400
|
};
|
|
3373
|
-
var __classPrivateFieldGet$6 = function(receiver, state, kind, f) {
|
|
3374
|
-
if (kind === "a" && !f)
|
|
3375
|
-
throw new TypeError("Private accessor was defined without a getter");
|
|
3376
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
3377
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
3378
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
3379
|
-
};
|
|
3380
5401
|
var _QuerySubscriptionProxy_instances;
|
|
3381
|
-
var
|
|
3382
|
-
var _QuerySubscriptionProxy_subscriptionId;
|
|
3383
|
-
var _QuerySubscriptionProxy_client;
|
|
5402
|
+
var _QuerySubscriptionProxy_live;
|
|
3384
5403
|
var _QuerySubscriptionProxy_callbacks;
|
|
3385
|
-
var _QuerySubscriptionProxy_keepaliveTimer;
|
|
3386
|
-
var _QuerySubscriptionProxy_unsubscribe;
|
|
3387
|
-
var _QuerySubscriptionProxy_reconnectUnsub;
|
|
3388
|
-
var _QuerySubscriptionProxy_latestResult;
|
|
3389
|
-
var _QuerySubscriptionProxy_disposed;
|
|
3390
5404
|
var _QuerySubscriptionProxy_initialized;
|
|
3391
5405
|
var _QuerySubscriptionProxy_initResolve;
|
|
3392
5406
|
var _QuerySubscriptionProxy_initReject;
|
|
3393
|
-
var
|
|
3394
|
-
var _QuerySubscriptionProxy_query;
|
|
3395
|
-
var _QuerySubscriptionProxy_generation;
|
|
3396
|
-
var _QuerySubscriptionProxy_deliverResult;
|
|
3397
|
-
var _QuerySubscriptionProxy_startKeepalive;
|
|
3398
|
-
var _QuerySubscriptionProxy_notifyCallbacks;
|
|
3399
|
-
var _QuerySubscriptionProxy_releaseHold;
|
|
5407
|
+
var _QuerySubscriptionProxy_deliver;
|
|
3400
5408
|
var _PerspectiveProxy_handle;
|
|
3401
5409
|
var _PerspectiveProxy_client;
|
|
3402
5410
|
var _PerspectiveProxy_releases;
|
|
@@ -3417,198 +5425,49 @@ function extractNamespaceFromUri(uri) {
|
|
|
3417
5425
|
var QuerySubscriptionProxy = class {
|
|
3418
5426
|
constructor(uuid, query, client) {
|
|
3419
5427
|
_QuerySubscriptionProxy_instances.add(this);
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
_QuerySubscriptionProxy_client.set(this, void 0);
|
|
3423
|
-
_QuerySubscriptionProxy_callbacks.set(this, void 0);
|
|
3424
|
-
_QuerySubscriptionProxy_keepaliveTimer.set(this, void 0);
|
|
3425
|
-
_QuerySubscriptionProxy_unsubscribe.set(this, void 0);
|
|
3426
|
-
_QuerySubscriptionProxy_reconnectUnsub.set(this, void 0);
|
|
3427
|
-
_QuerySubscriptionProxy_latestResult.set(this, void 0);
|
|
3428
|
-
_QuerySubscriptionProxy_disposed.set(this, false);
|
|
5428
|
+
_QuerySubscriptionProxy_live.set(this, void 0);
|
|
5429
|
+
_QuerySubscriptionProxy_callbacks.set(this, /* @__PURE__ */ new Set());
|
|
3429
5430
|
_QuerySubscriptionProxy_initialized.set(this, void 0);
|
|
3430
5431
|
_QuerySubscriptionProxy_initResolve.set(this, void 0);
|
|
3431
5432
|
_QuerySubscriptionProxy_initReject.set(this, void 0);
|
|
3432
|
-
|
|
3433
|
-
_QuerySubscriptionProxy_query.set(this, void 0);
|
|
3434
|
-
_QuerySubscriptionProxy_generation.set(this, 0);
|
|
3435
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_uuid, uuid, "f");
|
|
3436
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_query, query, "f");
|
|
3437
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_client, client, "f");
|
|
3438
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_callbacks, /* @__PURE__ */ new Set(), "f");
|
|
3439
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_latestResult, null, "f");
|
|
5433
|
+
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_live, new LiveQuery(client, uuid, () => client.subscribeQuery(uuid, query), (result) => __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliver).call(this, result)), "f");
|
|
3440
5434
|
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initialized, new Promise((resolve, reject) => {
|
|
3441
5435
|
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initResolve, resolve, "f");
|
|
3442
5436
|
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initReject, reject, "f");
|
|
3443
5437
|
}), "f");
|
|
5438
|
+
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initialized, "f").catch(() => {
|
|
5439
|
+
});
|
|
3444
5440
|
}
|
|
3445
5441
|
async subscribe() {
|
|
3446
|
-
var _a;
|
|
3447
|
-
const generation = __classPrivateFieldSet$6(this, _QuerySubscriptionProxy_generation, (_a = __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f"), ++_a), "f");
|
|
3448
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_reconnectUnsub, "f")) {
|
|
3449
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_reconnectUnsub, "f").call(this);
|
|
3450
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_reconnectUnsub, void 0, "f");
|
|
3451
|
-
}
|
|
3452
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_unsubscribe, "f")) {
|
|
3453
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_unsubscribe, "f").call(this);
|
|
3454
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_unsubscribe, void 0, "f");
|
|
3455
|
-
}
|
|
3456
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initTimeoutId, "f")) {
|
|
3457
|
-
clearTimeout(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initTimeoutId, "f"));
|
|
3458
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initTimeoutId, void 0, "f");
|
|
3459
|
-
}
|
|
3460
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_keepaliveTimer, "f")) {
|
|
3461
|
-
clearTimeout(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_keepaliveTimer, "f"));
|
|
3462
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_keepaliveTimer, void 0, "f");
|
|
3463
|
-
}
|
|
3464
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_releaseHold).call(this);
|
|
3465
5442
|
try {
|
|
3466
|
-
|
|
3467
|
-
initialResult = await __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").subscribeQuery(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_query, "f"));
|
|
3468
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_disposed, "f") || __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f") !== generation) {
|
|
3469
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").disposeQuerySubscription(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_uuid, "f"), initialResult.subscriptionId).catch((e) => console.error("Error disposing superseded query subscription:", e));
|
|
3470
|
-
return;
|
|
3471
|
-
}
|
|
3472
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_subscriptionId, initialResult.subscriptionId, "f");
|
|
3473
|
-
if (initialResult.result !== void 0) {
|
|
3474
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliverResult).call(this, initialResult.result);
|
|
3475
|
-
} else {
|
|
3476
|
-
console.warn("\u26A0\uFE0F No initial result returned from subscribeQuery!");
|
|
3477
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initTimeoutId, setTimeout(() => {
|
|
3478
|
-
console.error("Subscription initialization timed out after 30 seconds. Resubscribing...");
|
|
3479
|
-
this.subscribe().catch((error) => {
|
|
3480
|
-
console.error("Error during subscription retry after timeout:", error);
|
|
3481
|
-
});
|
|
3482
|
-
}, 3e4), "f");
|
|
3483
|
-
}
|
|
3484
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_unsubscribe, __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").subscribeToQueryUpdates(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_subscriptionId, "f"), (updateResult) => __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliverResult).call(this, updateResult)), "f");
|
|
5443
|
+
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliver).call(this, await __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_live, "f").start());
|
|
3485
5444
|
} catch (error) {
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initReject, "f").call(this, error);
|
|
3489
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initResolve, void 0, "f");
|
|
3490
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initReject, void 0, "f");
|
|
3491
|
-
}
|
|
3492
|
-
if (!__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_disposed, "f") && __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f") === generation && __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").onReconnect) {
|
|
3493
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_reconnectUnsub, __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").onReconnect(() => {
|
|
3494
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_disposed, "f"))
|
|
3495
|
-
return;
|
|
3496
|
-
console.log("WebSocket reconnected \u2014 retrying failed subscription for query:", __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_query, "f"));
|
|
3497
|
-
this.subscribe().catch((e) => {
|
|
3498
|
-
console.error("Error during subscription retry after reconnect:", e);
|
|
3499
|
-
});
|
|
3500
|
-
}), "f");
|
|
3501
|
-
}
|
|
5445
|
+
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initReject, "f")?.call(this, error);
|
|
5446
|
+
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initResolve, __classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initReject, void 0, "f"), "f");
|
|
3502
5447
|
throw error;
|
|
3503
5448
|
}
|
|
3504
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_startKeepalive).call(this, generation);
|
|
3505
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").onReconnect) {
|
|
3506
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_reconnectUnsub, __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").onReconnect(async () => {
|
|
3507
|
-
var _a2;
|
|
3508
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_disposed, "f"))
|
|
3509
|
-
return;
|
|
3510
|
-
const swapGeneration = __classPrivateFieldSet$6(this, _QuerySubscriptionProxy_generation, (_a2 = __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f"), ++_a2), "f");
|
|
3511
|
-
console.log("WebSocket reconnected \u2014 re-establishing server subscription for query:", __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_query, "f"));
|
|
3512
|
-
try {
|
|
3513
|
-
const newInitial = await __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").subscribeQuery(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_query, "f"));
|
|
3514
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_disposed, "f") || __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f") !== swapGeneration) {
|
|
3515
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").disposeQuerySubscription(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_uuid, "f"), newInitial.subscriptionId).catch((e) => console.error("Error disposing superseded query subscription:", e));
|
|
3516
|
-
return;
|
|
3517
|
-
}
|
|
3518
|
-
const newSubId = newInitial.subscriptionId;
|
|
3519
|
-
const newUnsub = __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").subscribeToQueryUpdates(newSubId, (updateResult) => __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliverResult).call(this, updateResult));
|
|
3520
|
-
const oldUnsub = __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_unsubscribe, "f");
|
|
3521
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_unsubscribe, newUnsub, "f");
|
|
3522
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_releaseHold).call(this);
|
|
3523
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_subscriptionId, newSubId, "f");
|
|
3524
|
-
if (oldUnsub)
|
|
3525
|
-
oldUnsub();
|
|
3526
|
-
clearTimeout(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_keepaliveTimer, "f"));
|
|
3527
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_startKeepalive).call(this, swapGeneration);
|
|
3528
|
-
if (newInitial.result !== void 0) {
|
|
3529
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliverResult).call(this, newInitial.result);
|
|
3530
|
-
}
|
|
3531
|
-
} catch (error) {
|
|
3532
|
-
console.error("Error re-establishing subscription after reconnect:", error);
|
|
3533
|
-
if (!__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_disposed, "f") && __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f") === swapGeneration) {
|
|
3534
|
-
clearTimeout(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_keepaliveTimer, "f"));
|
|
3535
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_startKeepalive).call(this, swapGeneration);
|
|
3536
|
-
}
|
|
3537
|
-
}
|
|
3538
|
-
}), "f");
|
|
3539
|
-
}
|
|
3540
5449
|
}
|
|
3541
5450
|
get id() {
|
|
3542
|
-
return __classPrivateFieldGet$6(this,
|
|
5451
|
+
return __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_live, "f").id;
|
|
3543
5452
|
}
|
|
3544
5453
|
get initialized() {
|
|
3545
5454
|
return __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initialized, "f");
|
|
3546
5455
|
}
|
|
3547
5456
|
get result() {
|
|
3548
|
-
return __classPrivateFieldGet$6(this,
|
|
5457
|
+
return __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_live, "f").result;
|
|
3549
5458
|
}
|
|
3550
5459
|
onResult(callback) {
|
|
3551
5460
|
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_callbacks, "f").add(callback);
|
|
3552
5461
|
return () => __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_callbacks, "f").delete(callback);
|
|
3553
5462
|
}
|
|
3554
5463
|
dispose() {
|
|
3555
|
-
|
|
3556
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_disposed, true, "f");
|
|
3557
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_generation, (_a = __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f"), _a++, _a), "f");
|
|
3558
|
-
clearTimeout(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_keepaliveTimer, "f"));
|
|
3559
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_unsubscribe, "f")) {
|
|
3560
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_unsubscribe, "f").call(this);
|
|
3561
|
-
}
|
|
3562
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_reconnectUnsub, "f")) {
|
|
3563
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_reconnectUnsub, "f").call(this);
|
|
3564
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_reconnectUnsub, void 0, "f");
|
|
3565
|
-
}
|
|
5464
|
+
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_live, "f").dispose();
|
|
3566
5465
|
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_callbacks, "f").clear();
|
|
3567
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initTimeoutId, "f")) {
|
|
3568
|
-
clearTimeout(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initTimeoutId, "f"));
|
|
3569
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initTimeoutId, void 0, "f");
|
|
3570
|
-
}
|
|
3571
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_releaseHold).call(this);
|
|
3572
5466
|
}
|
|
3573
5467
|
};
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initTimeoutId, void 0, "f");
|
|
3578
|
-
}
|
|
3579
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initResolve, "f")) {
|
|
3580
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initResolve, "f").call(this, true);
|
|
3581
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initResolve, void 0, "f");
|
|
3582
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initReject, void 0, "f");
|
|
3583
|
-
}
|
|
3584
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_latestResult, result, "f");
|
|
3585
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, result);
|
|
3586
|
-
}, _QuerySubscriptionProxy_startKeepalive = function _QuerySubscriptionProxy_startKeepalive2(generation) {
|
|
3587
|
-
const keepaliveLoop = async () => {
|
|
3588
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_disposed, "f") || __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f") !== generation)
|
|
3589
|
-
return;
|
|
3590
|
-
try {
|
|
3591
|
-
await __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").keepAliveQuery(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_subscriptionId, "f"));
|
|
3592
|
-
} catch (e) {
|
|
3593
|
-
if (__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_disposed, "f") || __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f") !== generation)
|
|
3594
|
-
return;
|
|
3595
|
-
console.error("Error in keepalive:", e);
|
|
3596
|
-
console.log("Reinitializing subscription for query:", __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_query, "f"));
|
|
3597
|
-
try {
|
|
3598
|
-
await this.subscribe();
|
|
3599
|
-
console.log("Subscription reinitialized");
|
|
3600
|
-
} catch (resubscribeError) {
|
|
3601
|
-
console.error("Error during resubscription from keepalive:", resubscribeError);
|
|
3602
|
-
return;
|
|
3603
|
-
}
|
|
3604
|
-
return;
|
|
3605
|
-
}
|
|
3606
|
-
if (!__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_disposed, "f") && __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_generation, "f") === generation) {
|
|
3607
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_keepaliveTimer, setTimeout(keepaliveLoop, 3e4), "f");
|
|
3608
|
-
}
|
|
3609
|
-
};
|
|
3610
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_keepaliveTimer, setTimeout(keepaliveLoop, 3e4), "f");
|
|
3611
|
-
}, _QuerySubscriptionProxy_notifyCallbacks = function _QuerySubscriptionProxy_notifyCallbacks2(result) {
|
|
5468
|
+
_QuerySubscriptionProxy_live = /* @__PURE__ */ new WeakMap(), _QuerySubscriptionProxy_callbacks = /* @__PURE__ */ new WeakMap(), _QuerySubscriptionProxy_initialized = /* @__PURE__ */ new WeakMap(), _QuerySubscriptionProxy_initResolve = /* @__PURE__ */ new WeakMap(), _QuerySubscriptionProxy_initReject = /* @__PURE__ */ new WeakMap(), _QuerySubscriptionProxy_instances = /* @__PURE__ */ new WeakSet(), _QuerySubscriptionProxy_deliver = function _QuerySubscriptionProxy_deliver2(result) {
|
|
5469
|
+
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_initResolve, "f")?.call(this, true);
|
|
5470
|
+
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initResolve, __classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initReject, void 0, "f"), "f");
|
|
3612
5471
|
for (const callback of __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_callbacks, "f")) {
|
|
3613
5472
|
try {
|
|
3614
5473
|
callback(result);
|
|
@@ -3616,12 +5475,6 @@ _QuerySubscriptionProxy_uuid = /* @__PURE__ */ new WeakMap(), _QuerySubscription
|
|
|
3616
5475
|
console.error("Error in query subscription callback:", e);
|
|
3617
5476
|
}
|
|
3618
5477
|
}
|
|
3619
|
-
}, _QuerySubscriptionProxy_releaseHold = function _QuerySubscriptionProxy_releaseHold2() {
|
|
3620
|
-
const subscriptionId = __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_subscriptionId, "f");
|
|
3621
|
-
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_subscriptionId, void 0, "f");
|
|
3622
|
-
if (subscriptionId) {
|
|
3623
|
-
__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_client, "f").disposeQuerySubscription(__classPrivateFieldGet$6(this, _QuerySubscriptionProxy_uuid, "f"), subscriptionId).catch((e) => console.error("Error disposing query subscription:", e));
|
|
3624
|
-
}
|
|
3625
5478
|
};
|
|
3626
5479
|
var PerspectiveProxy = class {
|
|
3627
5480
|
get client() {
|
|
@@ -3727,6 +5580,15 @@ var PerspectiveProxy = class {
|
|
|
3727
5580
|
async flowValidOutputs(flow, state) {
|
|
3728
5581
|
return await __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f").flowValidOutputs(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid, flow, state);
|
|
3729
5582
|
}
|
|
5583
|
+
async flowStates(instances) {
|
|
5584
|
+
return await __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f").flowStates(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid, instances);
|
|
5585
|
+
}
|
|
5586
|
+
async flowFired(instance) {
|
|
5587
|
+
return await __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f").flowFired(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid, instance);
|
|
5588
|
+
}
|
|
5589
|
+
onFlowStateChanged(handler) {
|
|
5590
|
+
return this.on("flow-state-changed", handler);
|
|
5591
|
+
}
|
|
3730
5592
|
async mintFlowReceipt(instanceUri) {
|
|
3731
5593
|
return await __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f").mintFlowReceipt(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid, instanceUri);
|
|
3732
5594
|
}
|
|
@@ -3949,6 +5811,8 @@ var PerspectiveProxy = class {
|
|
|
3949
5811
|
async ensureSubjectClasses(jsClasses) {
|
|
3950
5812
|
const entries = [];
|
|
3951
5813
|
for (const jsClass of jsClasses) {
|
|
5814
|
+
if (Object.prototype.hasOwnProperty.call(jsClass, "builtinUri"))
|
|
5815
|
+
continue;
|
|
3952
5816
|
const className = jsClass.className || jsClass.prototype?.className || jsClass.name;
|
|
3953
5817
|
if (__classPrivateFieldGet$6(this, _PerspectiveProxy_ensuredSubjectClasses, "f").has(className))
|
|
3954
5818
|
continue;
|
|
@@ -4100,6 +5964,10 @@ var PerspectiveProxy = class {
|
|
|
4100
5964
|
}
|
|
4101
5965
|
return exprAddr;
|
|
4102
5966
|
}
|
|
5967
|
+
async updateSubject(className, exprAddr, values, batchId) {
|
|
5968
|
+
await __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f").updateSubject(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid, className, exprAddr, JSON.stringify(values), batchId);
|
|
5969
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid);
|
|
5970
|
+
}
|
|
4103
5971
|
async getSubjectData(subjectClass, exprAddr) {
|
|
4104
5972
|
if (typeof subjectClass === "string") {
|
|
4105
5973
|
return JSON.parse(await __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f").getSubjectData(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ className: subjectClass }), exprAddr));
|
|
@@ -4137,7 +6005,20 @@ var PerspectiveProxy = class {
|
|
|
4137
6005
|
return null;
|
|
4138
6006
|
}
|
|
4139
6007
|
async removeSubject(subjectClass, exprAddr, batchId) {
|
|
6008
|
+
const ctor = subjectClass?.constructor;
|
|
6009
|
+
if (typeof subjectClass === "object" && ctor && Object.prototype.hasOwnProperty.call(ctor, "builtinUri")) {
|
|
6010
|
+
await __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f").removeSubject(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid, ctor.builtinUri, exprAddr, batchId);
|
|
6011
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid);
|
|
6012
|
+
return;
|
|
6013
|
+
}
|
|
4140
6014
|
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
|
|
6015
|
+
const shapePattern = new RegExp(`[/:#]${this.escapeRegExp(className)}Shape$`);
|
|
6016
|
+
const markers = await this.get(new LinkQuery({ predicate: "ad4m://abstract" }));
|
|
6017
|
+
if (markers.some((link) => shapePattern.test(link.data.source))) {
|
|
6018
|
+
await __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f").removeSubject(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid, className, exprAddr, batchId);
|
|
6019
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$6(this, _PerspectiveProxy_handle, "f").uuid);
|
|
6020
|
+
return;
|
|
6021
|
+
}
|
|
4141
6022
|
let actions = await this.getActionsFromSHACL(className, "ad4m://destructor");
|
|
4142
6023
|
if (!actions) {
|
|
4143
6024
|
throw `No destructor found for subject class: ${className}. Make sure the class was registered with SHACL.`;
|
|
@@ -4357,6 +6238,8 @@ var PerspectiveProxy = class {
|
|
|
4357
6238
|
return this.ensureSubjectClass(jsClass);
|
|
4358
6239
|
}
|
|
4359
6240
|
async ensureSubjectClass(jsClass) {
|
|
6241
|
+
if (Object.prototype.hasOwnProperty.call(jsClass, "builtinUri"))
|
|
6242
|
+
return;
|
|
4360
6243
|
const className = jsClass.className || jsClass.prototype?.className || jsClass.name;
|
|
4361
6244
|
if (__classPrivateFieldGet$6(this, _PerspectiveProxy_ensuredSubjectClasses, "f").has(className))
|
|
4362
6245
|
return;
|
|
@@ -4502,17 +6385,10 @@ var PerspectiveProxy = class {
|
|
|
4502
6385
|
get ai() {
|
|
4503
6386
|
return __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f").aiClient;
|
|
4504
6387
|
}
|
|
4505
|
-
async subscribeInfer(query) {
|
|
4506
|
-
const subscriptionProxy = new QuerySubscriptionProxy(this.uuid, query, __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f"));
|
|
4507
|
-
await subscriptionProxy.subscribe();
|
|
4508
|
-
await subscriptionProxy.initialized;
|
|
4509
|
-
return subscriptionProxy;
|
|
4510
|
-
}
|
|
4511
6388
|
async subscribeQuery(query) {
|
|
4512
|
-
const
|
|
4513
|
-
await
|
|
4514
|
-
|
|
4515
|
-
return subscriptionProxy;
|
|
6389
|
+
const subscription = new QuerySubscriptionProxy(this.uuid, query, __classPrivateFieldGet$6(this, _PerspectiveProxy_client, "f"));
|
|
6390
|
+
await subscription.subscribe();
|
|
6391
|
+
return subscription;
|
|
4516
6392
|
}
|
|
4517
6393
|
};
|
|
4518
6394
|
_PerspectiveProxy_handle = /* @__PURE__ */ new WeakMap(), _PerspectiveProxy_client = /* @__PURE__ */ new WeakMap(), _PerspectiveProxy_releases = /* @__PURE__ */ new WeakMap(), _PerspectiveProxy_ensuredSubjectClasses = /* @__PURE__ */ new WeakMap(), _PerspectiveProxy_overlaysInFlight = /* @__PURE__ */ new WeakMap();
|
|
@@ -4536,16 +6412,8 @@ var _PerspectiveClient_apiClient;
|
|
|
4536
6412
|
var _PerspectiveClient_expressionClient;
|
|
4537
6413
|
var _PerspectiveClient_neighbourhoodClient;
|
|
4538
6414
|
var _PerspectiveClient_aiClient;
|
|
4539
|
-
function
|
|
4540
|
-
|
|
4541
|
-
if (typeof finalResult === "string") {
|
|
4542
|
-
try {
|
|
4543
|
-
finalResult = JSON.parse(finalResult);
|
|
4544
|
-
} catch (e) {
|
|
4545
|
-
console.error(errorContext, e);
|
|
4546
|
-
}
|
|
4547
|
-
}
|
|
4548
|
-
return finalResult;
|
|
6415
|
+
function classParams(className) {
|
|
6416
|
+
return Array.isArray(className) ? { class_names: className } : { class_name: className };
|
|
4549
6417
|
}
|
|
4550
6418
|
var PerspectiveClient = class {
|
|
4551
6419
|
constructor(baseUrl, token, sharedApiClient) {
|
|
@@ -4615,33 +6483,20 @@ var PerspectiveClient = class {
|
|
|
4615
6483
|
const result = await __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.querySparql", { uuid, engine: "sparql", query }, options);
|
|
4616
6484
|
return JSON.parse(result);
|
|
4617
6485
|
}
|
|
4618
|
-
async subscribeQuery(uuid, query) {
|
|
4619
|
-
|
|
4620
|
-
const { subscriptionId, result } = response;
|
|
4621
|
-
const parsed = normalizeQueryResult(result, "Error parsing subscribeQuery result:");
|
|
4622
|
-
return { subscriptionId, result: parsed };
|
|
4623
|
-
}
|
|
4624
|
-
async perspectiveKeepAliveQuery(uuid, subscriptionId) {
|
|
4625
|
-
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.keepAliveQuery", { uuid, subscriptionId });
|
|
4626
|
-
}
|
|
4627
|
-
async perspectiveDisposeQuerySubscription(uuid, subscriptionId) {
|
|
4628
|
-
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.disposeQuery", { uuid, subscriptionId });
|
|
6486
|
+
async subscribeQuery(uuid, query) {
|
|
6487
|
+
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.subscribeQuery", { uuid, query });
|
|
4629
6488
|
}
|
|
4630
|
-
|
|
4631
|
-
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").on("query-subscription-update",
|
|
4632
|
-
if (event.subscriptionId !== subscriptionId)
|
|
4633
|
-
return;
|
|
4634
|
-
onData(normalizeQueryResult(event.result, "Error parsing query subscription:"));
|
|
4635
|
-
});
|
|
6489
|
+
onQueryUpdate(cb) {
|
|
6490
|
+
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").on("query-subscription-update", cb);
|
|
4636
6491
|
}
|
|
4637
|
-
async
|
|
4638
|
-
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.
|
|
6492
|
+
async resyncSubscription(uuid, subscriptionId) {
|
|
6493
|
+
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.resyncSubscription", { uuid, subscriptionId });
|
|
4639
6494
|
}
|
|
4640
6495
|
async disposeQuerySubscription(uuid, subscriptionId) {
|
|
4641
6496
|
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.disposeQuery", { uuid, subscriptionId });
|
|
4642
6497
|
}
|
|
4643
6498
|
async modelQuery(uuid, className, queryJson, options) {
|
|
4644
|
-
const resultJson = await __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.modelQuery", { uuid,
|
|
6499
|
+
const resultJson = await __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.modelQuery", { uuid, ...classParams(className), query_json: queryJson }, options);
|
|
4645
6500
|
return JSON.parse(resultJson);
|
|
4646
6501
|
}
|
|
4647
6502
|
async subjectClassesOf(uuid, uris) {
|
|
@@ -4657,11 +6512,7 @@ var PerspectiveClient = class {
|
|
|
4657
6512
|
return JSON.parse(resultJson);
|
|
4658
6513
|
}
|
|
4659
6514
|
async modelSubscribe(uuid, className, queryJson) {
|
|
4660
|
-
|
|
4661
|
-
return {
|
|
4662
|
-
subscriptionId: response.subscription_id,
|
|
4663
|
-
result: JSON.parse(response.result)
|
|
4664
|
-
};
|
|
6515
|
+
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.modelSubscribe", { uuid, ...classParams(className), query_json: queryJson });
|
|
4665
6516
|
}
|
|
4666
6517
|
async add(name) {
|
|
4667
6518
|
const handle = await __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.create", { name });
|
|
@@ -4753,6 +6604,12 @@ var PerspectiveClient = class {
|
|
|
4753
6604
|
async flowValidOutputs(uuid, flow, state) {
|
|
4754
6605
|
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.flowValidOutputs", { uuid, flow, state });
|
|
4755
6606
|
}
|
|
6607
|
+
async flowStates(uuid, instances) {
|
|
6608
|
+
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.flowStates", { uuid, instances });
|
|
6609
|
+
}
|
|
6610
|
+
async flowFired(uuid, instance) {
|
|
6611
|
+
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.flowFired", { uuid, instance });
|
|
6612
|
+
}
|
|
4756
6613
|
async mintFlowReceipt(uuid, instanceUri) {
|
|
4757
6614
|
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.mintFlowReceipt", { uuid, instanceUri });
|
|
4758
6615
|
}
|
|
@@ -4782,6 +6639,12 @@ var PerspectiveClient = class {
|
|
|
4782
6639
|
async createSubject(uuid, subjectClass, expressionAddress, initialValues, batchId) {
|
|
4783
6640
|
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.createSubject", { uuid, subjectClass, expressionAddress, initialValues, batchId });
|
|
4784
6641
|
}
|
|
6642
|
+
async updateSubject(uuid, subjectClass, expressionAddress, values, batchId) {
|
|
6643
|
+
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.updateSubject", { uuid, subjectClass, expressionAddress, values, batchId });
|
|
6644
|
+
}
|
|
6645
|
+
async removeSubject(uuid, subjectClass, expressionAddress, batchId) {
|
|
6646
|
+
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.removeSubject", { uuid, subjectClass, expressionAddress, batchId });
|
|
6647
|
+
}
|
|
4785
6648
|
async getSubjectData(uuid, subjectClass, expressionAddress) {
|
|
4786
6649
|
return __classPrivateFieldGet$5(this, _PerspectiveClient_apiClient, "f").call("perspective.getSubjectData", { uuid, subjectClass, expressionAddress });
|
|
4787
6650
|
}
|
|
@@ -10114,26 +11977,54 @@ function buildSPARQLWhereFilters(metadata, _allRelationsMetadata, where) {
|
|
|
10114
11977
|
return { joins, filters };
|
|
10115
11978
|
}
|
|
10116
11979
|
var ModelQueryBuilder = class {
|
|
10117
|
-
constructor(perspective, ctor, query) {
|
|
11980
|
+
constructor(perspective, ctor, query, unionClasses) {
|
|
10118
11981
|
this.queryParams = {};
|
|
10119
11982
|
this.modelClassName = null;
|
|
10120
|
-
this.subscriptionChain = Promise.resolve();
|
|
10121
11983
|
this.perspective = perspective;
|
|
10122
11984
|
this.ctor = ctor;
|
|
10123
11985
|
if (query)
|
|
10124
11986
|
this.queryParams = query;
|
|
11987
|
+
if (unionClasses)
|
|
11988
|
+
this.unionClasses = unionClasses;
|
|
11989
|
+
}
|
|
11990
|
+
prepare(params) {
|
|
11991
|
+
if (this.unionClasses) {
|
|
11992
|
+
const { classNames, queryJson } = this.ctor.prepareUnionQueryParams(this.unionClasses, params);
|
|
11993
|
+
return { className: classNames, queryJson };
|
|
11994
|
+
}
|
|
11995
|
+
return this.ctor.prepareModelQueryParams(params, this.modelClassName);
|
|
11996
|
+
}
|
|
11997
|
+
execute(params) {
|
|
11998
|
+
if (this.unionClasses) {
|
|
11999
|
+
return this.ctor.executeUnionQuery(this.perspective, this.unionClasses, params);
|
|
12000
|
+
}
|
|
12001
|
+
return this.ctor.executeModelQuery(this.perspective, params, this.modelClassName);
|
|
12002
|
+
}
|
|
12003
|
+
parse(raw) {
|
|
12004
|
+
const { include, properties } = this.queryParams;
|
|
12005
|
+
if (this.unionClasses) {
|
|
12006
|
+
return this.ctor.parseUnionResult(this.unionClasses, this.perspective, raw, include, properties);
|
|
12007
|
+
}
|
|
12008
|
+
return this.ctor.parseModelResult(this.perspective, raw, include, properties);
|
|
10125
12009
|
}
|
|
10126
12010
|
dispose() {
|
|
10127
|
-
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10136
|
-
|
|
12011
|
+
if (this.currentSubscription) {
|
|
12012
|
+
this.currentSubscription.dispose();
|
|
12013
|
+
this.currentSubscription = void 0;
|
|
12014
|
+
}
|
|
12015
|
+
}
|
|
12016
|
+
async live(params, onResult) {
|
|
12017
|
+
const { className, queryJson } = this.prepare(params);
|
|
12018
|
+
const live = new LiveQuery(this.perspective.client, this.perspective.uuid, () => this.perspective.modelSubscribe(className, queryJson), onResult);
|
|
12019
|
+
this.currentSubscription = live;
|
|
12020
|
+
try {
|
|
12021
|
+
return { live, initial: await live.start() };
|
|
12022
|
+
} catch (e) {
|
|
12023
|
+
live.dispose();
|
|
12024
|
+
if (this.currentSubscription === live)
|
|
12025
|
+
this.currentSubscription = void 0;
|
|
12026
|
+
throw e;
|
|
12027
|
+
}
|
|
10137
12028
|
}
|
|
10138
12029
|
where(conditions) {
|
|
10139
12030
|
this.queryParams.where = conditions;
|
|
@@ -10208,7 +12099,7 @@ var ModelQueryBuilder = class {
|
|
|
10208
12099
|
return this.executeSparqlQuery();
|
|
10209
12100
|
}
|
|
10210
12101
|
async executeSparqlQuery() {
|
|
10211
|
-
const { results } = await this.
|
|
12102
|
+
const { results } = await this.execute(this.queryParams);
|
|
10212
12103
|
return results;
|
|
10213
12104
|
}
|
|
10214
12105
|
async first() {
|
|
@@ -10218,82 +12109,25 @@ var ModelQueryBuilder = class {
|
|
|
10218
12109
|
this.queryParams.limit = savedLimit;
|
|
10219
12110
|
return results[0] ?? null;
|
|
10220
12111
|
}
|
|
10221
|
-
subscribe(callback) {
|
|
10222
|
-
|
|
10223
|
-
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
const
|
|
10227
|
-
const { className, queryJson } = ctor.prepareModelQueryParams(this.queryParams, this.modelClassName);
|
|
10228
|
-
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson);
|
|
10229
|
-
const parseResults = (raw) => {
|
|
10230
|
-
return ctor.parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
|
|
10231
|
-
};
|
|
10232
|
-
const initialResults = parseResults(initialModelResult);
|
|
10233
|
-
let lastResultFingerprint = null;
|
|
10234
|
-
const buildFingerprint = (results) => {
|
|
10235
|
-
if (results.length === 0)
|
|
10236
|
-
return "0:";
|
|
10237
|
-
return JSON.stringify(results, (_, v) => typeof v === "function" ? void 0 : v);
|
|
10238
|
-
};
|
|
10239
|
-
lastResultFingerprint = buildFingerprint(initialResults);
|
|
10240
|
-
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
12112
|
+
async subscribe(callback) {
|
|
12113
|
+
this.dispose();
|
|
12114
|
+
const parseResults = (raw) => this.parse(raw);
|
|
12115
|
+
const fingerprint = (results) => JSON.stringify(results, (_, v) => typeof v === "function" ? void 0 : v);
|
|
12116
|
+
let lastFingerprint = null;
|
|
12117
|
+
const { initial } = await this.live(this.queryParams, (raw) => {
|
|
10241
12118
|
try {
|
|
10242
|
-
const results = parseResults(
|
|
10243
|
-
const fp =
|
|
10244
|
-
if (fp ===
|
|
12119
|
+
const results = parseResults(raw);
|
|
12120
|
+
const fp = fingerprint(results);
|
|
12121
|
+
if (fp === lastFingerprint)
|
|
10245
12122
|
return;
|
|
10246
|
-
|
|
10247
|
-
lastResultFingerprint = fp;
|
|
12123
|
+
lastFingerprint = fp;
|
|
10248
12124
|
callback(results);
|
|
10249
12125
|
} catch (e) {
|
|
10250
12126
|
console.error("Model subscription update parse error:", e);
|
|
10251
12127
|
}
|
|
10252
12128
|
});
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
let resubscribeAttempts = 0;
|
|
10256
|
-
const MAX_RESUBSCRIBE_ATTEMPTS = 5;
|
|
10257
|
-
const keepaliveLoop = async () => {
|
|
10258
|
-
if (disposed)
|
|
10259
|
-
return;
|
|
10260
|
-
try {
|
|
10261
|
-
await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
|
|
10262
|
-
resubscribeAttempts = 0;
|
|
10263
|
-
} catch (e) {
|
|
10264
|
-
console.warn(`Model subscription keepalive failed for ${subscriptionId}:`, e);
|
|
10265
|
-
if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
10266
|
-
resubscribeAttempts++;
|
|
10267
|
-
const backoffMs = Math.min(1e3 * Math.pow(2, resubscribeAttempts), 6e4);
|
|
10268
|
-
console.warn(`Resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
|
|
10269
|
-
await new Promise((r) => setTimeout(r, backoffMs));
|
|
10270
|
-
try {
|
|
10271
|
-
unsubscribe();
|
|
10272
|
-
await this.subscribe(callback);
|
|
10273
|
-
} catch (resubErr) {
|
|
10274
|
-
console.error("Model subscription resubscribe failed:", resubErr);
|
|
10275
|
-
}
|
|
10276
|
-
} else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
10277
|
-
console.error(`Model subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
|
|
10278
|
-
}
|
|
10279
|
-
return;
|
|
10280
|
-
}
|
|
10281
|
-
if (!disposed) {
|
|
10282
|
-
keepaliveTimer = setTimeout(keepaliveLoop, 3e4);
|
|
10283
|
-
}
|
|
10284
|
-
};
|
|
10285
|
-
keepaliveTimer = setTimeout(keepaliveLoop, 3e4);
|
|
10286
|
-
this.currentSubscription = {
|
|
10287
|
-
dispose: () => {
|
|
10288
|
-
disposed = true;
|
|
10289
|
-
if (keepaliveTimer)
|
|
10290
|
-
clearTimeout(keepaliveTimer);
|
|
10291
|
-
unsubscribe();
|
|
10292
|
-
return this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).then(() => {
|
|
10293
|
-
}, () => {
|
|
10294
|
-
});
|
|
10295
|
-
}
|
|
10296
|
-
};
|
|
12129
|
+
const initialResults = parseResults(initial);
|
|
12130
|
+
lastFingerprint = fingerprint(initialResults);
|
|
10297
12131
|
for (const inst of initialResults) {
|
|
10298
12132
|
inst.takeSnapshot?.(this.queryParams.include);
|
|
10299
12133
|
}
|
|
@@ -10303,100 +12137,33 @@ var ModelQueryBuilder = class {
|
|
|
10303
12137
|
return this.subscribe(callback);
|
|
10304
12138
|
}
|
|
10305
12139
|
async count() {
|
|
10306
|
-
const { totalCount } = await this.
|
|
12140
|
+
const { totalCount } = await this.execute({ ...this.queryParams, limit: 0 });
|
|
10307
12141
|
return totalCount;
|
|
10308
12142
|
}
|
|
10309
12143
|
async countSparql() {
|
|
10310
12144
|
return await this.count();
|
|
10311
12145
|
}
|
|
10312
|
-
countSubscribe(callback) {
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
await this.dispose();
|
|
10317
|
-
const countParams = { ...this.queryParams, limit: 0 };
|
|
10318
|
-
const { className, queryJson } = this.ctor.prepareModelQueryParams(countParams, this.modelClassName);
|
|
10319
|
-
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson);
|
|
10320
|
-
const parseCount = (raw) => {
|
|
10321
|
-
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
10322
|
-
return data.totalCount ?? 0;
|
|
10323
|
-
};
|
|
10324
|
-
const initialCount = parseCount(initialModelResult);
|
|
10325
|
-
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
10326
|
-
try {
|
|
10327
|
-
callback(parseCount(rawResult));
|
|
10328
|
-
} catch (e) {
|
|
10329
|
-
console.error("Count subscription update parse error:", e);
|
|
10330
|
-
}
|
|
10331
|
-
});
|
|
10332
|
-
let disposed = false;
|
|
10333
|
-
let keepaliveTimer;
|
|
10334
|
-
let resubscribeAttempts = 0;
|
|
10335
|
-
const MAX_RESUBSCRIBE_ATTEMPTS = 5;
|
|
10336
|
-
const keepaliveLoop = async () => {
|
|
10337
|
-
if (disposed)
|
|
10338
|
-
return;
|
|
10339
|
-
try {
|
|
10340
|
-
await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
|
|
10341
|
-
resubscribeAttempts = 0;
|
|
10342
|
-
} catch (e) {
|
|
10343
|
-
console.warn(`Count subscription keepalive failed for ${subscriptionId}:`, e);
|
|
10344
|
-
if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
10345
|
-
resubscribeAttempts++;
|
|
10346
|
-
const backoffMs = Math.min(1e3 * Math.pow(2, resubscribeAttempts), 6e4);
|
|
10347
|
-
console.warn(`Count resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
|
|
10348
|
-
await new Promise((r) => setTimeout(r, backoffMs));
|
|
10349
|
-
try {
|
|
10350
|
-
unsubscribe();
|
|
10351
|
-
await this.countSubscribe(callback);
|
|
10352
|
-
} catch (resubErr) {
|
|
10353
|
-
console.error("Count subscription resubscribe failed:", resubErr);
|
|
10354
|
-
}
|
|
10355
|
-
} else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
10356
|
-
console.error(`Count subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
|
|
10357
|
-
}
|
|
10358
|
-
return;
|
|
10359
|
-
}
|
|
10360
|
-
if (!disposed) {
|
|
10361
|
-
keepaliveTimer = setTimeout(keepaliveLoop, 3e4);
|
|
10362
|
-
}
|
|
10363
|
-
};
|
|
10364
|
-
keepaliveTimer = setTimeout(keepaliveLoop, 3e4);
|
|
10365
|
-
this.currentSubscription = {
|
|
10366
|
-
dispose: () => {
|
|
10367
|
-
disposed = true;
|
|
10368
|
-
if (keepaliveTimer)
|
|
10369
|
-
clearTimeout(keepaliveTimer);
|
|
10370
|
-
unsubscribe();
|
|
10371
|
-
return this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).then(() => {
|
|
10372
|
-
}, () => {
|
|
10373
|
-
});
|
|
10374
|
-
}
|
|
10375
|
-
};
|
|
10376
|
-
return initialCount;
|
|
12146
|
+
async countSubscribe(callback) {
|
|
12147
|
+
this.dispose();
|
|
12148
|
+
const { initial } = await this.live({ ...this.queryParams, limit: 0 }, (raw) => callback(raw.totalCount ?? 0));
|
|
12149
|
+
return initial.totalCount ?? 0;
|
|
10377
12150
|
}
|
|
10378
12151
|
async countSubscribeSparql(callback) {
|
|
10379
12152
|
return this.countSubscribe(callback);
|
|
10380
12153
|
}
|
|
10381
12154
|
async paginate(pageSize, pageNumber) {
|
|
10382
12155
|
const paginationQuery = { ...this.queryParams || {}, limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
|
|
10383
|
-
const { results, totalCount } = await this.
|
|
12156
|
+
const { results, totalCount } = await this.execute(paginationQuery);
|
|
10384
12157
|
return { results, totalCount, pageSize, pageNumber };
|
|
10385
12158
|
}
|
|
10386
12159
|
async paginateSparql(pageSize, pageNumber) {
|
|
10387
12160
|
return await this.paginate(pageSize, pageNumber);
|
|
10388
12161
|
}
|
|
10389
|
-
paginateSubscribe(pageSize, pageNumber, callback) {
|
|
10390
|
-
|
|
10391
|
-
}
|
|
10392
|
-
async paginateSubscribeNow(pageSize, pageNumber, callback) {
|
|
10393
|
-
await this.dispose();
|
|
10394
|
-
const ctor = this.ctor;
|
|
12162
|
+
async paginateSubscribe(pageSize, pageNumber, callback) {
|
|
12163
|
+
this.dispose();
|
|
10395
12164
|
const subscriptionParams = { ...this.queryParams || {} };
|
|
10396
12165
|
delete subscriptionParams.limit;
|
|
10397
12166
|
delete subscriptionParams.offset;
|
|
10398
|
-
const { className, queryJson } = ctor.prepareModelQueryParams(subscriptionParams, this.modelClassName);
|
|
10399
|
-
const { subscriptionId } = await this.perspective.modelSubscribe(className, queryJson);
|
|
10400
12167
|
const paginatedQuery = {
|
|
10401
12168
|
...this.queryParams || {},
|
|
10402
12169
|
limit: pageSize,
|
|
@@ -10406,81 +12173,40 @@ var ModelQueryBuilder = class {
|
|
|
10406
12173
|
let disposed = false;
|
|
10407
12174
|
let fetching = false;
|
|
10408
12175
|
let pending = false;
|
|
10409
|
-
let coalesced = 0;
|
|
10410
12176
|
const processResults = async () => {
|
|
10411
12177
|
if (disposed)
|
|
10412
12178
|
return;
|
|
10413
12179
|
if (fetching) {
|
|
10414
12180
|
pending = true;
|
|
10415
|
-
coalesced++;
|
|
10416
12181
|
return;
|
|
10417
12182
|
}
|
|
10418
12183
|
fetching = true;
|
|
10419
12184
|
try {
|
|
10420
|
-
const { results: results2, totalCount: totalCount2 } = await
|
|
12185
|
+
const { results: results2, totalCount: totalCount2 } = await this.execute(paginatedQuery);
|
|
10421
12186
|
if (!disposed)
|
|
10422
12187
|
callback({ results: results2, totalCount: totalCount2, pageSize, pageNumber });
|
|
10423
12188
|
} finally {
|
|
10424
12189
|
fetching = false;
|
|
10425
12190
|
if (pending) {
|
|
10426
|
-
const dispatches = coalesced;
|
|
10427
12191
|
pending = false;
|
|
10428
|
-
coalesced = 0;
|
|
10429
|
-
if (!disposed) {
|
|
10430
|
-
console.debug(`[ModelQueryBuilder.paginateSubscribe] ${dispatches} dispatch(es) during read for ${subscriptionId}, coalesced into one trailing fetch`);
|
|
10431
|
-
}
|
|
10432
12192
|
processResults().catch((e) => console.error("Paginate subscription error:", e));
|
|
10433
12193
|
}
|
|
10434
12194
|
}
|
|
10435
12195
|
};
|
|
10436
|
-
const
|
|
10437
|
-
console.debug(`[ModelQueryBuilder.paginateSubscribe] Update received for ${subscriptionId}, re-fetching paginated data...`);
|
|
12196
|
+
const { live } = await this.live(subscriptionParams, () => {
|
|
10438
12197
|
processResults().catch((e) => console.error("Paginate subscription error:", e));
|
|
10439
12198
|
});
|
|
10440
|
-
|
|
10441
|
-
|
|
10442
|
-
|
|
10443
|
-
|
|
10444
|
-
|
|
10445
|
-
return;
|
|
10446
|
-
try {
|
|
10447
|
-
await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
|
|
10448
|
-
resubscribeAttempts = 0;
|
|
10449
|
-
} catch (e) {
|
|
10450
|
-
console.warn(`Paginate subscription keepalive failed for ${subscriptionId}:`, e);
|
|
10451
|
-
if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
10452
|
-
resubscribeAttempts++;
|
|
10453
|
-
const backoffMs = Math.min(1e3 * Math.pow(2, resubscribeAttempts), 6e4);
|
|
10454
|
-
console.warn(`Paginate resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
|
|
10455
|
-
await new Promise((r) => setTimeout(r, backoffMs));
|
|
10456
|
-
try {
|
|
10457
|
-
unsubscribe();
|
|
10458
|
-
await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
10459
|
-
} catch (resubErr) {
|
|
10460
|
-
console.error("Paginate subscription resubscribe failed:", resubErr);
|
|
10461
|
-
}
|
|
10462
|
-
} else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
10463
|
-
console.error(`Paginate subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
|
|
12199
|
+
if (this.currentSubscription === live) {
|
|
12200
|
+
this.currentSubscription = {
|
|
12201
|
+
dispose: () => {
|
|
12202
|
+
disposed = true;
|
|
12203
|
+
live.dispose();
|
|
10464
12204
|
}
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
};
|
|
10471
|
-
keepaliveTimer = setTimeout(keepaliveLoop, 3e4);
|
|
10472
|
-
this.currentSubscription = {
|
|
10473
|
-
dispose: () => {
|
|
10474
|
-
disposed = true;
|
|
10475
|
-
if (keepaliveTimer)
|
|
10476
|
-
clearTimeout(keepaliveTimer);
|
|
10477
|
-
unsubscribe();
|
|
10478
|
-
return this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).then(() => {
|
|
10479
|
-
}, () => {
|
|
10480
|
-
});
|
|
10481
|
-
}
|
|
10482
|
-
};
|
|
10483
|
-
const { results, totalCount } = await ctor.executeModelQuery(this.perspective, paginatedQuery, this.modelClassName);
|
|
12205
|
+
};
|
|
12206
|
+
} else {
|
|
12207
|
+
disposed = true;
|
|
12208
|
+
}
|
|
12209
|
+
const { results, totalCount } = await this.execute(paginatedQuery);
|
|
10484
12210
|
return { results, totalCount, pageSize, pageNumber };
|
|
10485
12211
|
}
|
|
10486
12212
|
async paginateSubscribeSparql(pageSize, pageNumber, callback) {
|
|
@@ -10965,9 +12691,13 @@ var Ad4mModel = class {
|
|
|
10965
12691
|
const allRelMeta = getRelationsMetadata(this);
|
|
10966
12692
|
return buildSPARQLQuery(metadata, allRelMeta, query, this);
|
|
10967
12693
|
}
|
|
12694
|
+
static queriedAs() {
|
|
12695
|
+
const builtinUri = Object.prototype.hasOwnProperty.call(this, "builtinUri") ? this.builtinUri : void 0;
|
|
12696
|
+
return builtinUri || this.getModelMetadata().className;
|
|
12697
|
+
}
|
|
10968
12698
|
static prepareModelQueryParams(query = {}, classNameOverride) {
|
|
10969
12699
|
const metadata = this.getModelMetadata();
|
|
10970
|
-
const className = classNameOverride ||
|
|
12700
|
+
const className = classNameOverride || this.queriedAs();
|
|
10971
12701
|
if (query.includeAll) {
|
|
10972
12702
|
const allRelMeta = getRelationsMetadata(this);
|
|
10973
12703
|
const expanded = {};
|
|
@@ -11044,6 +12774,91 @@ var Ad4mModel = class {
|
|
|
11044
12774
|
return [];
|
|
11045
12775
|
return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
|
|
11046
12776
|
}
|
|
12777
|
+
static prepareUnionQueryParams(classes, query = {}) {
|
|
12778
|
+
if (!classes.length)
|
|
12779
|
+
throw new Error("A query over several classes needs at least one class");
|
|
12780
|
+
const { parent, preferClasses, ...rest } = query;
|
|
12781
|
+
const inputs = classes.map((c) => JSON.parse(c.prepareModelQueryParams(rest).queryJson));
|
|
12782
|
+
const tags = /* @__PURE__ */ new Map();
|
|
12783
|
+
const collectTags = (node, path2) => {
|
|
12784
|
+
if (!node || typeof node !== "object")
|
|
12785
|
+
return;
|
|
12786
|
+
for (const [k, v] of Object.entries(node)) {
|
|
12787
|
+
if (k === "targetClassName" && typeof v === "string") {
|
|
12788
|
+
const seen = tags.get(path2);
|
|
12789
|
+
if (seen !== void 0 && seen !== v) {
|
|
12790
|
+
throw new Error(`projection '${path2}': the classes resolve it to different target classes (${seen}, ${v}); query those classes separately`);
|
|
12791
|
+
}
|
|
12792
|
+
tags.set(path2, v);
|
|
12793
|
+
} else {
|
|
12794
|
+
collectTags(v, path2 ? `${path2}.${k}` : k);
|
|
12795
|
+
}
|
|
12796
|
+
}
|
|
12797
|
+
};
|
|
12798
|
+
for (const input of inputs) {
|
|
12799
|
+
collectTags(input.include, "include");
|
|
12800
|
+
collectTags(input.projections, "projections");
|
|
12801
|
+
}
|
|
12802
|
+
const merged = { ...inputs[0] };
|
|
12803
|
+
if (preferClasses)
|
|
12804
|
+
merged.preferClasses = preferClasses;
|
|
12805
|
+
for (const key of ["include", "projections"]) {
|
|
12806
|
+
const combined = Object.assign({}, ...inputs.map((i) => i[key] ?? {}).reverse());
|
|
12807
|
+
if (Object.keys(combined).length)
|
|
12808
|
+
merged[key] = combined;
|
|
12809
|
+
else
|
|
12810
|
+
delete merged[key];
|
|
12811
|
+
}
|
|
12812
|
+
if (parent) {
|
|
12813
|
+
const scopes = [];
|
|
12814
|
+
let firstError;
|
|
12815
|
+
for (const c of classes) {
|
|
12816
|
+
try {
|
|
12817
|
+
scopes.push(JSON.stringify(JSON.parse(c.prepareModelQueryParams({ parent }).queryJson).parent));
|
|
12818
|
+
} catch (e) {
|
|
12819
|
+
firstError ?? (firstError = e);
|
|
12820
|
+
}
|
|
12821
|
+
}
|
|
12822
|
+
if (!scopes.length)
|
|
12823
|
+
throw firstError;
|
|
12824
|
+
if (new Set(scopes).size > 1) {
|
|
12825
|
+
throw new Error("parent(): the classes resolve the parent scope to different predicates; pass the predicate itself (or a `field`) so they share one scope");
|
|
12826
|
+
}
|
|
12827
|
+
merged.parent = JSON.parse(scopes[0]);
|
|
12828
|
+
}
|
|
12829
|
+
return {
|
|
12830
|
+
classNames: classes.map((c) => c.queriedAs()),
|
|
12831
|
+
queryJson: JSON.stringify(merged)
|
|
12832
|
+
};
|
|
12833
|
+
}
|
|
12834
|
+
static parseUnionResult(classes, perspective, raw, include, properties) {
|
|
12835
|
+
const data = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
12836
|
+
const arr = data.instances || data;
|
|
12837
|
+
if (!Array.isArray(arr))
|
|
12838
|
+
return [];
|
|
12839
|
+
const byName = new Map(classes.map((c) => [c.getModelMetadata().className, c]));
|
|
12840
|
+
return arr.map((json) => {
|
|
12841
|
+
const cls = byName.get(json?.[SUBJECT_CLASS_KEY]);
|
|
12842
|
+
return cls ? jsonToModelInstance(cls, perspective, json, include, properties) : json;
|
|
12843
|
+
});
|
|
12844
|
+
}
|
|
12845
|
+
static async executeUnionQuery(perspective, classes, query = {}, options) {
|
|
12846
|
+
const { classNames, queryJson } = Ad4mModel.prepareUnionQueryParams(classes, query);
|
|
12847
|
+
const result = await perspective.modelQuery(classNames, queryJson, options);
|
|
12848
|
+
const results = Ad4mModel.parseUnionResult(classes, perspective, result, query.include, query.properties);
|
|
12849
|
+
const snapshotRelations = query.include ? Object.fromEntries(Object.entries(query.include).filter(([k]) => !k.startsWith("$"))) : void 0;
|
|
12850
|
+
for (const inst of results) {
|
|
12851
|
+
inst.takeSnapshot?.(snapshotRelations && Object.keys(snapshotRelations).length > 0 ? snapshotRelations : void 0);
|
|
12852
|
+
}
|
|
12853
|
+
return { results, totalCount: result.totalCount };
|
|
12854
|
+
}
|
|
12855
|
+
static async findAllOf(perspective, classes, query, options) {
|
|
12856
|
+
const { results } = await Ad4mModel.executeUnionQuery(perspective, classes, query ?? {}, options);
|
|
12857
|
+
return results;
|
|
12858
|
+
}
|
|
12859
|
+
static queryOf(perspective, classes, query) {
|
|
12860
|
+
return new ModelQueryBuilder(perspective, Ad4mModel, query, classes);
|
|
12861
|
+
}
|
|
11047
12862
|
static async executeModelQuery(perspective, query = {}, classNameOverride, options) {
|
|
11048
12863
|
const { className, queryJson } = this.prepareModelQueryParams(query, classNameOverride);
|
|
11049
12864
|
const result = await perspective.modelQuery(className, queryJson, options);
|
|
@@ -11112,12 +12927,22 @@ var Ad4mModel = class {
|
|
|
11112
12927
|
return value.id;
|
|
11113
12928
|
return String(value);
|
|
11114
12929
|
}
|
|
12930
|
+
async relationThroughAbstract(abstractName, key, action, value, batchId) {
|
|
12931
|
+
const ids = (Array.isArray(value) ? value : [value]).map((v) => this.resolveRelationId(v));
|
|
12932
|
+
await this._perspective.updateSubject(abstractName, this._baseExpression, { [key]: { action, value: ids } }, batchId);
|
|
12933
|
+
}
|
|
11115
12934
|
async setRelationValues(key, value, batchId) {
|
|
11116
12935
|
const metadata = this.getRelationOptions(key);
|
|
11117
12936
|
if (!metadata) {
|
|
11118
12937
|
console.warn(`Relation "${key}" has no metadata, skipping`);
|
|
11119
12938
|
return;
|
|
11120
12939
|
}
|
|
12940
|
+
const abstractName = this.abstractName();
|
|
12941
|
+
if (abstractName) {
|
|
12942
|
+
if (value != null)
|
|
12943
|
+
await this.relationThroughAbstract(abstractName, key, "setter", value, batchId);
|
|
12944
|
+
return;
|
|
12945
|
+
}
|
|
11121
12946
|
const actions = this.generateRelationAction(key, "setter");
|
|
11122
12947
|
if (value != null) {
|
|
11123
12948
|
if (Array.isArray(value)) {
|
|
@@ -11133,6 +12958,12 @@ var Ad4mModel = class {
|
|
|
11133
12958
|
console.warn(`Relation "${key}" has no metadata, skipping`);
|
|
11134
12959
|
return;
|
|
11135
12960
|
}
|
|
12961
|
+
const abstractName = this.abstractName();
|
|
12962
|
+
if (abstractName) {
|
|
12963
|
+
if (value != null)
|
|
12964
|
+
await this.relationThroughAbstract(abstractName, key, "adder", value, batchId);
|
|
12965
|
+
return;
|
|
12966
|
+
}
|
|
11136
12967
|
const actions = this.generateRelationAction(key, "adder");
|
|
11137
12968
|
if (value != null) {
|
|
11138
12969
|
if (Array.isArray(value)) {
|
|
@@ -11148,6 +12979,12 @@ var Ad4mModel = class {
|
|
|
11148
12979
|
console.warn(`Relation "${key}" has no metadata, skipping`);
|
|
11149
12980
|
return;
|
|
11150
12981
|
}
|
|
12982
|
+
const abstractName = this.abstractName();
|
|
12983
|
+
if (abstractName) {
|
|
12984
|
+
if (value != null)
|
|
12985
|
+
await this.relationThroughAbstract(abstractName, key, "remover", value, batchId);
|
|
12986
|
+
return;
|
|
12987
|
+
}
|
|
11151
12988
|
const actions = this.generateRelationAction(key, "remover");
|
|
11152
12989
|
if (value != null) {
|
|
11153
12990
|
if (Array.isArray(value)) {
|
|
@@ -11159,7 +12996,12 @@ var Ad4mModel = class {
|
|
|
11159
12996
|
}
|
|
11160
12997
|
async save(batchId) {
|
|
11161
12998
|
if (this._snapshot) {
|
|
11162
|
-
|
|
12999
|
+
const abstractName2 = this.abstractName();
|
|
13000
|
+
if (abstractName2) {
|
|
13001
|
+
await this.perspective.updateSubject(abstractName2, this._baseExpression, this.changedValuesForDispatch(), batchId);
|
|
13002
|
+
} else {
|
|
13003
|
+
await this.innerUpdate(true, batchId);
|
|
13004
|
+
}
|
|
11163
13005
|
if (batchId) {
|
|
11164
13006
|
this.takeSnapshot();
|
|
11165
13007
|
} else {
|
|
@@ -11167,6 +13009,10 @@ var Ad4mModel = class {
|
|
|
11167
13009
|
}
|
|
11168
13010
|
return;
|
|
11169
13011
|
}
|
|
13012
|
+
const abstractName = this.abstractName();
|
|
13013
|
+
if (abstractName) {
|
|
13014
|
+
throw new Error(`'${abstractName}' is an abstract class and cannot be created. Create an instance of a class that has its properties; querying '${abstractName}' reads it.`);
|
|
13015
|
+
}
|
|
11170
13016
|
let batchCreatedHere = false;
|
|
11171
13017
|
if (!batchId) {
|
|
11172
13018
|
batchId = await this.perspective.createBatch();
|
|
@@ -11204,6 +13050,26 @@ var Ad4mModel = class {
|
|
|
11204
13050
|
this.takeSnapshot();
|
|
11205
13051
|
}
|
|
11206
13052
|
}
|
|
13053
|
+
abstractName() {
|
|
13054
|
+
const ctor = this.constructor;
|
|
13055
|
+
return ctor.isAbstract ? ctor.queriedAs() : void 0;
|
|
13056
|
+
}
|
|
13057
|
+
changedValues() {
|
|
13058
|
+
return Object.fromEntries(this.changedFields().map((key) => [key, this[key]]));
|
|
13059
|
+
}
|
|
13060
|
+
changedValuesForDispatch() {
|
|
13061
|
+
const relations = this.constructor.getModelMetadata().relations;
|
|
13062
|
+
const ids = (value) => Array.isArray(value) ? value.map((v) => this.resolveRelationId(v)) : this.resolveRelationId(value);
|
|
13063
|
+
return Object.fromEntries(Object.entries(this.changedValues()).map(([key, value]) => {
|
|
13064
|
+
if (!relations[key] || value == null)
|
|
13065
|
+
return [key, value];
|
|
13066
|
+
if (value.action) {
|
|
13067
|
+
const action = ["adder", "remover", "setter"].includes(value.action) ? value.action : "setter";
|
|
13068
|
+
return [key, { action, value: ids(value.value) }];
|
|
13069
|
+
}
|
|
13070
|
+
return [key, ids(value)];
|
|
13071
|
+
}));
|
|
13072
|
+
}
|
|
11207
13073
|
cleanCopy() {
|
|
11208
13074
|
const ctor = this.constructor;
|
|
11209
13075
|
const metadata = ctor.getModelMetadata();
|
|
@@ -11330,7 +13196,7 @@ var Ad4mModel = class {
|
|
|
11330
13196
|
}
|
|
11331
13197
|
async delete(batchId) {
|
|
11332
13198
|
const metadata = this.constructor.getModelMetadata();
|
|
11333
|
-
const hasDestructor = Object.values(metadata.properties).some((p) => p.required || p.flag || p.initial !== void 0);
|
|
13199
|
+
const hasDestructor = !!this.abstractName() || Object.values(metadata.properties).some((p) => p.required || p.flag || p.initial !== void 0);
|
|
11334
13200
|
if (hasDestructor) {
|
|
11335
13201
|
await this._perspective.removeSubject(this, this._baseExpression, batchId);
|
|
11336
13202
|
} else {
|
|
@@ -11582,7 +13448,7 @@ var ExceptionType;
|
|
|
11582
13448
|
})(ExceptionType || (ExceptionType = {}));
|
|
11583
13449
|
var LanguageExpression = class extends ExpressionGeneric() {
|
|
11584
13450
|
};
|
|
11585
|
-
var __decorate$
|
|
13451
|
+
var __decorate$2 = function(decorators, target, key, desc) {
|
|
11586
13452
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11587
13453
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
11588
13454
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -11592,7 +13458,7 @@ var __decorate$1 = function(decorators, target, key, desc) {
|
|
|
11592
13458
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11593
13459
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11594
13460
|
};
|
|
11595
|
-
var __metadata$
|
|
13461
|
+
var __metadata$2 = function(k, v) {
|
|
11596
13462
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
11597
13463
|
return Reflect.metadata(k, v);
|
|
11598
13464
|
};
|
|
@@ -11608,71 +13474,71 @@ var AutoProcessorConfig = class AutoProcessorConfig2 extends Ad4mModel {
|
|
|
11608
13474
|
this.claimTtlMs = "60000";
|
|
11609
13475
|
}
|
|
11610
13476
|
};
|
|
11611
|
-
__decorate$
|
|
13477
|
+
__decorate$2([
|
|
11612
13478
|
Property({ through: "ad4m://processor_id", required: true, identity: true }),
|
|
11613
|
-
__metadata$
|
|
13479
|
+
__metadata$2("design:type", String)
|
|
11614
13480
|
], AutoProcessorConfig.prototype, "processorId", void 0);
|
|
11615
|
-
__decorate$
|
|
13481
|
+
__decorate$2([
|
|
11616
13482
|
Property({ through: "ad4m://source_scope_query", required: true }),
|
|
11617
|
-
__metadata$
|
|
13483
|
+
__metadata$2("design:type", String)
|
|
11618
13484
|
], AutoProcessorConfig.prototype, "sourceScopeQuery", void 0);
|
|
11619
|
-
__decorate$
|
|
13485
|
+
__decorate$2([
|
|
11620
13486
|
Optional({ through: "ad4m://base_prefix" }),
|
|
11621
|
-
__metadata$
|
|
13487
|
+
__metadata$2("design:type", String)
|
|
11622
13488
|
], AutoProcessorConfig.prototype, "basePrefix", void 0);
|
|
11623
|
-
__decorate$
|
|
13489
|
+
__decorate$2([
|
|
11624
13490
|
HasMany({ through: "ad4m://interpretation_class", datatype: "xsd:string" }),
|
|
11625
|
-
__metadata$
|
|
13491
|
+
__metadata$2("design:type", Array)
|
|
11626
13492
|
], AutoProcessorConfig.prototype, "interpretationClasses", void 0);
|
|
11627
|
-
__decorate$
|
|
13493
|
+
__decorate$2([
|
|
11628
13494
|
HasMany({ through: "ad4m://flow", datatype: "xsd:string" }),
|
|
11629
|
-
__metadata$
|
|
13495
|
+
__metadata$2("design:type", Array)
|
|
11630
13496
|
], AutoProcessorConfig.prototype, "flows", void 0);
|
|
11631
|
-
__decorate$
|
|
13497
|
+
__decorate$2([
|
|
11632
13498
|
Property({ through: "ad4m://debounce_ms", required: true }),
|
|
11633
|
-
__metadata$
|
|
13499
|
+
__metadata$2("design:type", String)
|
|
11634
13500
|
], AutoProcessorConfig.prototype, "debounceMs", void 0);
|
|
11635
|
-
__decorate$
|
|
13501
|
+
__decorate$2([
|
|
11636
13502
|
Optional({ through: "ad4m://batch_min" }),
|
|
11637
|
-
__metadata$
|
|
13503
|
+
__metadata$2("design:type", String)
|
|
11638
13504
|
], AutoProcessorConfig.prototype, "batchMin", void 0);
|
|
11639
|
-
__decorate$
|
|
13505
|
+
__decorate$2([
|
|
11640
13506
|
Property({ through: "ad4m://batch_max", required: true }),
|
|
11641
|
-
__metadata$
|
|
13507
|
+
__metadata$2("design:type", String)
|
|
11642
13508
|
], AutoProcessorConfig.prototype, "batchMax", void 0);
|
|
11643
|
-
__decorate$
|
|
13509
|
+
__decorate$2([
|
|
11644
13510
|
Optional({ through: "ad4m://max_wait_ms" }),
|
|
11645
|
-
__metadata$
|
|
13511
|
+
__metadata$2("design:type", String)
|
|
11646
13512
|
], AutoProcessorConfig.prototype, "maxWaitMs", void 0);
|
|
11647
|
-
__decorate$
|
|
13513
|
+
__decorate$2([
|
|
11648
13514
|
Property({ through: "ad4m://claim_ttl_ms", required: true }),
|
|
11649
|
-
__metadata$
|
|
13515
|
+
__metadata$2("design:type", String)
|
|
11650
13516
|
], AutoProcessorConfig.prototype, "claimTtlMs", void 0);
|
|
11651
|
-
__decorate$
|
|
13517
|
+
__decorate$2([
|
|
11652
13518
|
Optional({ through: "ad4m://source_window_ms" }),
|
|
11653
|
-
__metadata$
|
|
13519
|
+
__metadata$2("design:type", String)
|
|
11654
13520
|
], AutoProcessorConfig.prototype, "sourceWindowMs", void 0);
|
|
11655
|
-
__decorate$
|
|
13521
|
+
__decorate$2([
|
|
11656
13522
|
Optional({ through: "ad4m://dedup_strategy" }),
|
|
11657
|
-
__metadata$
|
|
13523
|
+
__metadata$2("design:type", String)
|
|
11658
13524
|
], AutoProcessorConfig.prototype, "dedupStrategy", void 0);
|
|
11659
|
-
__decorate$
|
|
13525
|
+
__decorate$2([
|
|
11660
13526
|
Optional({ through: "ad4m://existing_scope" }),
|
|
11661
|
-
__metadata$
|
|
13527
|
+
__metadata$2("design:type", String)
|
|
11662
13528
|
], AutoProcessorConfig.prototype, "existingScope", void 0);
|
|
11663
|
-
__decorate$
|
|
13529
|
+
__decorate$2([
|
|
11664
13530
|
Optional({ through: "ad4m://mint_scope" }),
|
|
11665
|
-
__metadata$
|
|
13531
|
+
__metadata$2("design:type", String)
|
|
11666
13532
|
], AutoProcessorConfig.prototype, "mintScope", void 0);
|
|
11667
|
-
__decorate$
|
|
13533
|
+
__decorate$2([
|
|
11668
13534
|
Optional({ through: "ad4m://max_tool_calls" }),
|
|
11669
|
-
__metadata$
|
|
13535
|
+
__metadata$2("design:type", String)
|
|
11670
13536
|
], AutoProcessorConfig.prototype, "maxToolCalls", void 0);
|
|
11671
|
-
__decorate$
|
|
13537
|
+
__decorate$2([
|
|
11672
13538
|
Optional({ through: "ad4m://emit_debug_events", resolveLanguage: "literal" }),
|
|
11673
|
-
__metadata$
|
|
13539
|
+
__metadata$2("design:type", String)
|
|
11674
13540
|
], AutoProcessorConfig.prototype, "emitDebugEvents", void 0);
|
|
11675
|
-
AutoProcessorConfig = __decorate$
|
|
13541
|
+
AutoProcessorConfig = __decorate$2([
|
|
11676
13542
|
Model$1({ name: "AutoProcessor" })
|
|
11677
13543
|
], AutoProcessorConfig);
|
|
11678
13544
|
var InterpretationRun = class InterpretationRun2 extends Ad4mModel {
|
|
@@ -11682,39 +13548,39 @@ var InterpretationRun = class InterpretationRun2 extends Ad4mModel {
|
|
|
11682
13548
|
this.sources = [];
|
|
11683
13549
|
}
|
|
11684
13550
|
};
|
|
11685
|
-
__decorate$
|
|
13551
|
+
__decorate$2([
|
|
11686
13552
|
Property({ through: "ad4m://interp/run_id", required: true, identity: true }),
|
|
11687
|
-
__metadata$
|
|
13553
|
+
__metadata$2("design:type", String)
|
|
11688
13554
|
], InterpretationRun.prototype, "runId", void 0);
|
|
11689
|
-
__decorate$
|
|
13555
|
+
__decorate$2([
|
|
11690
13556
|
Optional({ through: "ad4m://interp/model" }),
|
|
11691
|
-
__metadata$
|
|
13557
|
+
__metadata$2("design:type", String)
|
|
11692
13558
|
], InterpretationRun.prototype, "model", void 0);
|
|
11693
|
-
__decorate$
|
|
13559
|
+
__decorate$2([
|
|
11694
13560
|
Optional({ through: "ad4m://interp/prompt_version" }),
|
|
11695
|
-
__metadata$
|
|
13561
|
+
__metadata$2("design:type", String)
|
|
11696
13562
|
], InterpretationRun.prototype, "promptVersion", void 0);
|
|
11697
|
-
__decorate$
|
|
13563
|
+
__decorate$2([
|
|
11698
13564
|
Optional({ through: "ad4m://interp/ran_at" }),
|
|
11699
|
-
__metadata$
|
|
13565
|
+
__metadata$2("design:type", String)
|
|
11700
13566
|
], InterpretationRun.prototype, "ranAt", void 0);
|
|
11701
|
-
__decorate$
|
|
13567
|
+
__decorate$2([
|
|
11702
13568
|
Optional({ through: "ad4m://interp/processor" }),
|
|
11703
|
-
__metadata$
|
|
13569
|
+
__metadata$2("design:type", String)
|
|
11704
13570
|
], InterpretationRun.prototype, "processor", void 0);
|
|
11705
|
-
__decorate$
|
|
13571
|
+
__decorate$2([
|
|
11706
13572
|
HasMany({ through: "ad4m://interp/sources", datatype: "xsd:string" }),
|
|
11707
|
-
__metadata$
|
|
13573
|
+
__metadata$2("design:type", Array)
|
|
11708
13574
|
], InterpretationRun.prototype, "sources", void 0);
|
|
11709
|
-
__decorate$
|
|
13575
|
+
__decorate$2([
|
|
11710
13576
|
Optional({ through: "ad4m://interp/debug_prompt", resolveLanguage: "literal" }),
|
|
11711
|
-
__metadata$
|
|
13577
|
+
__metadata$2("design:type", String)
|
|
11712
13578
|
], InterpretationRun.prototype, "debugPrompt", void 0);
|
|
11713
|
-
__decorate$
|
|
13579
|
+
__decorate$2([
|
|
11714
13580
|
Optional({ through: "ad4m://interp/debug_response", resolveLanguage: "literal" }),
|
|
11715
|
-
__metadata$
|
|
13581
|
+
__metadata$2("design:type", String)
|
|
11716
13582
|
], InterpretationRun.prototype, "debugResponse", void 0);
|
|
11717
|
-
InterpretationRun = __decorate$
|
|
13583
|
+
InterpretationRun = __decorate$2([
|
|
11718
13584
|
Model$1({ name: "InterpretationRun" })
|
|
11719
13585
|
], InterpretationRun);
|
|
11720
13586
|
var InterpretationOverlay = class InterpretationOverlay2 extends Ad4mModel {
|
|
@@ -11723,18 +13589,18 @@ var InterpretationOverlay = class InterpretationOverlay2 extends Ad4mModel {
|
|
|
11723
13589
|
this.kind = "";
|
|
11724
13590
|
}
|
|
11725
13591
|
};
|
|
11726
|
-
__decorate$
|
|
13592
|
+
__decorate$2([
|
|
11727
13593
|
Property({ through: "ad4m://interp/kind", required: true }),
|
|
11728
|
-
__metadata$
|
|
13594
|
+
__metadata$2("design:type", String)
|
|
11729
13595
|
], InterpretationOverlay.prototype, "kind", void 0);
|
|
11730
|
-
__decorate$
|
|
13596
|
+
__decorate$2([
|
|
11731
13597
|
Optional({ through: "ad4m://interp/run" }),
|
|
11732
|
-
__metadata$
|
|
13598
|
+
__metadata$2("design:type", String)
|
|
11733
13599
|
], InterpretationOverlay.prototype, "run", void 0);
|
|
11734
|
-
InterpretationOverlay = __decorate$
|
|
13600
|
+
InterpretationOverlay = __decorate$2([
|
|
11735
13601
|
Model$1({ name: "InterpretationOverlay" })
|
|
11736
13602
|
], InterpretationOverlay);
|
|
11737
|
-
var __decorate = function(decorators, target, key, desc) {
|
|
13603
|
+
var __decorate$1 = function(decorators, target, key, desc) {
|
|
11738
13604
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11739
13605
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
11740
13606
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -11744,7 +13610,7 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
11744
13610
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11745
13611
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11746
13612
|
};
|
|
11747
|
-
var __metadata = function(k, v) {
|
|
13613
|
+
var __metadata$1 = function(k, v) {
|
|
11748
13614
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
11749
13615
|
return Reflect.metadata(k, v);
|
|
11750
13616
|
};
|
|
@@ -11765,59 +13631,55 @@ var FlowTransitionProposal = class FlowTransitionProposal2 extends Ad4mModel {
|
|
|
11765
13631
|
this.acceptedBy = [];
|
|
11766
13632
|
}
|
|
11767
13633
|
};
|
|
11768
|
-
__decorate([
|
|
13634
|
+
__decorate$1([
|
|
11769
13635
|
Property({ through: "ad4m://flow/instance", required: true, identity: true }),
|
|
11770
|
-
__metadata("design:type", String)
|
|
13636
|
+
__metadata$1("design:type", String)
|
|
11771
13637
|
], FlowTransitionProposal.prototype, "flowInstance", void 0);
|
|
11772
|
-
__decorate([
|
|
13638
|
+
__decorate$1([
|
|
11773
13639
|
Property({ through: "ad4m://flow/from_state", required: true }),
|
|
11774
|
-
__metadata("design:type", String)
|
|
13640
|
+
__metadata$1("design:type", String)
|
|
11775
13641
|
], FlowTransitionProposal.prototype, "fromState", void 0);
|
|
11776
|
-
__decorate([
|
|
13642
|
+
__decorate$1([
|
|
11777
13643
|
Property({ through: "ad4m://flow/to_state", required: true }),
|
|
11778
|
-
__metadata("design:type", String)
|
|
13644
|
+
__metadata$1("design:type", String)
|
|
11779
13645
|
], FlowTransitionProposal.prototype, "toState", void 0);
|
|
11780
|
-
__decorate([
|
|
13646
|
+
__decorate$1([
|
|
11781
13647
|
Property({ through: "ad4m://flow/proposer", required: true, getter: PROPOSER_GETTER, datatype: "xsd:string" }),
|
|
11782
|
-
__metadata("design:type", String)
|
|
13648
|
+
__metadata$1("design:type", String)
|
|
11783
13649
|
], FlowTransitionProposal.prototype, "proposer", void 0);
|
|
11784
|
-
__decorate([
|
|
13650
|
+
__decorate$1([
|
|
11785
13651
|
HasMany({ through: "ad4m://flow/evidence", datatype: "xsd:string" }),
|
|
11786
|
-
__metadata("design:type", Array)
|
|
13652
|
+
__metadata$1("design:type", Array)
|
|
11787
13653
|
], FlowTransitionProposal.prototype, "evidence", void 0);
|
|
11788
|
-
__decorate([
|
|
13654
|
+
__decorate$1([
|
|
11789
13655
|
Property({ through: "ad4m://flow/evidence_hashes", required: true }),
|
|
11790
|
-
__metadata("design:type", String)
|
|
13656
|
+
__metadata$1("design:type", String)
|
|
11791
13657
|
], FlowTransitionProposal.prototype, "evidenceHashes", void 0);
|
|
11792
|
-
__decorate([
|
|
13658
|
+
__decorate$1([
|
|
11793
13659
|
HasMany({ through: "ad4m://flow/output", datatype: "xsd:string" }),
|
|
11794
|
-
__metadata("design:type", Array)
|
|
13660
|
+
__metadata$1("design:type", Array)
|
|
11795
13661
|
], FlowTransitionProposal.prototype, "outputs", void 0);
|
|
11796
|
-
__decorate([
|
|
13662
|
+
__decorate$1([
|
|
11797
13663
|
Property({ through: "ad4m://flow/outputs_hash" }),
|
|
11798
|
-
__metadata("design:type", String)
|
|
13664
|
+
__metadata$1("design:type", String)
|
|
11799
13665
|
], FlowTransitionProposal.prototype, "outputsHash", void 0);
|
|
11800
|
-
__decorate([
|
|
13666
|
+
__decorate$1([
|
|
11801
13667
|
Property({ through: "ad4m://flow/nonce" }),
|
|
11802
|
-
__metadata("design:type", String)
|
|
13668
|
+
__metadata$1("design:type", String)
|
|
11803
13669
|
], FlowTransitionProposal.prototype, "nonce", void 0);
|
|
11804
|
-
__decorate([
|
|
13670
|
+
__decorate$1([
|
|
11805
13671
|
Optional({ through: "ad4m://flow/run_uri" }),
|
|
11806
|
-
__metadata("design:type", String)
|
|
13672
|
+
__metadata$1("design:type", String)
|
|
11807
13673
|
], FlowTransitionProposal.prototype, "runUri", void 0);
|
|
11808
|
-
__decorate([
|
|
13674
|
+
__decorate$1([
|
|
11809
13675
|
Optional({ through: "ad4m://flow/rationale" }),
|
|
11810
|
-
__metadata("design:type", String)
|
|
13676
|
+
__metadata$1("design:type", String)
|
|
11811
13677
|
], FlowTransitionProposal.prototype, "rationale", void 0);
|
|
11812
|
-
__decorate([
|
|
13678
|
+
__decorate$1([
|
|
11813
13679
|
HasMany({ through: "ad4m://acceptedBy", getter: ACCEPTED_BY_GETTER, readOnly: true }),
|
|
11814
|
-
__metadata("design:type", Array)
|
|
13680
|
+
__metadata$1("design:type", Array)
|
|
11815
13681
|
], FlowTransitionProposal.prototype, "acceptedBy", void 0);
|
|
11816
|
-
__decorate([
|
|
11817
|
-
Optional({ through: "ad4m://flow/resolved_as", readOnly: true, local: true }),
|
|
11818
|
-
__metadata("design:type", String)
|
|
11819
|
-
], FlowTransitionProposal.prototype, "resolvedAs", void 0);
|
|
11820
|
-
FlowTransitionProposal = __decorate([
|
|
13682
|
+
FlowTransitionProposal = __decorate$1([
|
|
11821
13683
|
Model$1({ name: "FlowTransitionProposal" })
|
|
11822
13684
|
], FlowTransitionProposal);
|
|
11823
13685
|
var FlowInstanceRecord = class FlowInstanceRecord2 extends Ad4mModel {
|
|
@@ -11825,24 +13687,47 @@ var FlowInstanceRecord = class FlowInstanceRecord2 extends Ad4mModel {
|
|
|
11825
13687
|
super(...arguments);
|
|
11826
13688
|
this.flowUri = "";
|
|
11827
13689
|
this.subject = "";
|
|
11828
|
-
this.currentState = "";
|
|
11829
13690
|
}
|
|
11830
13691
|
};
|
|
11831
|
-
__decorate([
|
|
13692
|
+
__decorate$1([
|
|
11832
13693
|
Property({ through: "ad4m://flow/flow_uri", required: true, identity: true }),
|
|
11833
|
-
__metadata("design:type", String)
|
|
13694
|
+
__metadata$1("design:type", String)
|
|
11834
13695
|
], FlowInstanceRecord.prototype, "flowUri", void 0);
|
|
11835
|
-
__decorate([
|
|
13696
|
+
__decorate$1([
|
|
11836
13697
|
Property({ through: "ad4m://flow/base", required: true }),
|
|
11837
|
-
__metadata("design:type", String)
|
|
13698
|
+
__metadata$1("design:type", String)
|
|
11838
13699
|
], FlowInstanceRecord.prototype, "subject", void 0);
|
|
11839
|
-
__decorate([
|
|
11840
|
-
Property({ through: "ad4m://flow/current_state", local: true }),
|
|
11841
|
-
__metadata("design:type", String)
|
|
11842
|
-
], FlowInstanceRecord.prototype, "currentState", void 0);
|
|
11843
|
-
FlowInstanceRecord = __decorate([
|
|
13700
|
+
FlowInstanceRecord = __decorate$1([
|
|
11844
13701
|
Model$1({ name: "FlowInstance" })
|
|
11845
13702
|
], FlowInstanceRecord);
|
|
13703
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
13704
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13705
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
13706
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
13707
|
+
else
|
|
13708
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
13709
|
+
if (d = decorators[i])
|
|
13710
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13711
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13712
|
+
};
|
|
13713
|
+
var __metadata = function(k, v) {
|
|
13714
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13715
|
+
return Reflect.metadata(k, v);
|
|
13716
|
+
};
|
|
13717
|
+
var TextContent = class TextContent2 extends Ad4mModel {
|
|
13718
|
+
constructor() {
|
|
13719
|
+
super(...arguments);
|
|
13720
|
+
this.text = "";
|
|
13721
|
+
}
|
|
13722
|
+
};
|
|
13723
|
+
TextContent.builtinUri = "ad4m://TextContent";
|
|
13724
|
+
__decorate([
|
|
13725
|
+
Property({ through: "ad4m://text" }),
|
|
13726
|
+
__metadata("design:type", String)
|
|
13727
|
+
], TextContent.prototype, "text", void 0);
|
|
13728
|
+
TextContent = __decorate([
|
|
13729
|
+
Model$1({ name: "TextContent", abstract: true })
|
|
13730
|
+
], TextContent);
|
|
11846
13731
|
var PerspectiveDiffExpression = class extends ExpressionGeneric() {
|
|
11847
13732
|
};
|
|
11848
13733
|
var _SmartLiteral_perspective;
|