@dxos/client-services 0.8.4-main.406dc2a → 0.8.4-main.422d1c7879
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/lib/browser/{chunk-TF7KXCT7.mjs → chunk-J7VTDH4K.mjs} +3459 -3082
- package/dist/lib/browser/chunk-J7VTDH4K.mjs.map +7 -0
- package/dist/lib/browser/chunk-NQSC7HOE.mjs +22 -0
- package/dist/lib/browser/chunk-NQSC7HOE.mjs.map +7 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +584 -187
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/browser.mjs +126 -0
- package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/node.mjs +66 -0
- package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +70 -80
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-XJAHJBOC.mjs → chunk-2WCRQW4E.mjs} +3111 -2603
- package/dist/lib/node-esm/chunk-2WCRQW4E.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs +22 -0
- package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +584 -187
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs +126 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs +66 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +70 -80
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts +2 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/devtools.d.ts +2 -2
- package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +1 -2
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts +6 -6
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +7 -6
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +6 -10
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +8 -11
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +6 -5
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +7 -4
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts +3 -3
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +3 -3
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +4 -3
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/locks/index.d.ts +1 -1
- package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts +4 -0
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +5 -4
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/client-rpc-server.d.ts +5 -5
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
- package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
- package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
- package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
- package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
- package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +13 -8
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +20 -7
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/archive-format.d.ts +9 -0
- package/dist/types/src/packlets/space-export/archive-format.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/index.d.ts +4 -1
- package/dist/types/src/packlets/space-export/index.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts +23 -0
- package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts +36 -0
- package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +7 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +28 -16
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +26 -9
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts +2 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -6
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +17 -7
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +6 -5
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.d.ts +41 -4
- package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-session.d.ts +2 -4
- package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +70 -55
- package/src/index.ts +1 -0
- package/src/packlets/agents/edge-agent-manager.ts +8 -5
- package/src/packlets/agents/edge-agent-service.ts +4 -2
- package/src/packlets/devices/devices-service.test.ts +0 -1
- package/src/packlets/devtools/devtools.ts +2 -3
- package/src/packlets/diagnostics/diagnostics.ts +1 -2
- package/src/packlets/diagnostics/index.ts +1 -1
- package/src/packlets/identity/authenticator.ts +2 -2
- package/src/packlets/identity/contacts-service.ts +0 -1
- package/src/packlets/identity/identity-manager.test.ts +5 -5
- package/src/packlets/identity/identity-manager.ts +21 -18
- package/src/packlets/identity/identity-recovery-manager.ts +22 -18
- package/src/packlets/identity/identity-service.test.ts +6 -27
- package/src/packlets/identity/identity-service.ts +13 -81
- package/src/packlets/identity/identity.test.ts +2 -2
- package/src/packlets/identity/identity.ts +11 -34
- package/src/packlets/invitations/device-invitation-protocol.ts +8 -7
- package/src/packlets/invitations/edge-invitation-handler.ts +9 -5
- package/src/packlets/invitations/invitation-guest-extenstion.ts +6 -4
- package/src/packlets/invitations/invitation-host-extension.ts +6 -4
- package/src/packlets/invitations/invitation-protocol.ts +7 -4
- package/src/packlets/invitations/invitation-state.ts +0 -10
- package/src/packlets/invitations/invitations-handler.test.ts +4 -5
- package/src/packlets/invitations/invitations-handler.ts +69 -13
- package/src/packlets/invitations/invitations-manager.ts +40 -15
- package/src/packlets/invitations/invitations-service.ts +9 -9
- package/src/packlets/invitations/space-invitation-protocol.test.ts +17 -16
- package/src/packlets/invitations/space-invitation-protocol.ts +11 -16
- package/src/packlets/locks/index.ts +1 -1
- package/src/packlets/logging/logging-service.ts +20 -16
- package/src/packlets/network/network-service.test.ts +0 -1
- package/src/packlets/network/network-service.ts +10 -8
- package/src/packlets/services/client-rpc-server.ts +19 -16
- package/src/packlets/services/feed-syncer.test.ts +340 -0
- package/src/packlets/services/feed-syncer.ts +337 -0
- package/src/packlets/services/platform.ts +7 -1
- package/src/packlets/services/service-context.test.ts +3 -2
- package/src/packlets/services/service-context.ts +137 -51
- package/src/packlets/services/service-host.test.ts +8 -8
- package/src/packlets/services/service-host.ts +69 -31
- package/src/packlets/services/service-registry.test.ts +0 -1
- package/src/packlets/space-export/archive-format.ts +42 -0
- package/src/packlets/space-export/index.ts +4 -1
- package/src/packlets/space-export/serialized-space-reader.ts +111 -0
- package/src/packlets/space-export/serialized-space-writer.ts +253 -0
- package/src/packlets/space-export/space-archive-reader.ts +64 -3
- package/src/packlets/space-export/space-archive-writer.ts +41 -3
- package/src/packlets/space-export/space-archive.test.ts +461 -0
- package/src/packlets/spaces/data-space-manager.test.ts +79 -13
- package/src/packlets/spaces/data-space-manager.ts +114 -109
- package/src/packlets/spaces/data-space.ts +58 -33
- package/src/packlets/spaces/edge-feed-replicator.test.ts +1 -1
- package/src/packlets/spaces/edge-feed-replicator.ts +11 -9
- package/src/packlets/spaces/epoch-migrations.ts +5 -5
- package/src/packlets/spaces/genesis.ts +6 -1
- package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.ts +10 -9
- package/src/packlets/spaces/spaces-service.test.ts +18 -11
- package/src/packlets/spaces/spaces-service.ts +123 -24
- package/src/packlets/storage/storage.ts +4 -4
- package/src/packlets/testing/invitation-utils.ts +10 -6
- package/src/packlets/testing/test-builder.ts +36 -10
- package/src/packlets/worker/worker-runtime.ts +179 -17
- package/src/packlets/worker/worker-session.ts +12 -18
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-TF7KXCT7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XJAHJBOC.mjs.map +0 -7
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
- package/src/packlets/identity/default-space-state-machine.ts +0 -44
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
import "../../chunk-QCWEHHJW.mjs";
|
|
3
|
+
|
|
4
|
+
// src/packlets/diagnostics/browser-diagnostics-broadcast.ts
|
|
5
|
+
import { Trigger } from "@dxos/async";
|
|
6
|
+
import { log } from "@dxos/log";
|
|
7
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
|
|
8
|
+
var CHANNEL_NAME = "dxos.diagnostics.broadcast";
|
|
9
|
+
var createCollectDiagnosticsBroadcastSender = () => {
|
|
10
|
+
return {
|
|
11
|
+
broadcastDiagnosticsRequest: async () => {
|
|
12
|
+
let expectedResponse = "probe-ack";
|
|
13
|
+
let channel;
|
|
14
|
+
try {
|
|
15
|
+
const trigger = new Trigger();
|
|
16
|
+
channel = new BroadcastChannel(CHANNEL_NAME);
|
|
17
|
+
channel.onmessage = (msg) => {
|
|
18
|
+
if (expectedResponse === msg.data.type) {
|
|
19
|
+
trigger.wake(msg.data);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
channel.postMessage({
|
|
23
|
+
type: "probe"
|
|
24
|
+
});
|
|
25
|
+
await trigger.wait({
|
|
26
|
+
timeout: 200
|
|
27
|
+
});
|
|
28
|
+
expectedResponse = "receive-diagnostics";
|
|
29
|
+
trigger.reset();
|
|
30
|
+
channel.postMessage({
|
|
31
|
+
type: "request-diagnostics"
|
|
32
|
+
});
|
|
33
|
+
const diagnostics = await trigger.wait({
|
|
34
|
+
timeout: 5e3
|
|
35
|
+
});
|
|
36
|
+
return diagnostics.payload;
|
|
37
|
+
} catch (e) {
|
|
38
|
+
const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
|
|
39
|
+
return {
|
|
40
|
+
expectedResponse,
|
|
41
|
+
errorDescription
|
|
42
|
+
};
|
|
43
|
+
} finally {
|
|
44
|
+
safeClose(channel);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
var createCollectDiagnosticsBroadcastHandler = (systemService) => {
|
|
50
|
+
let channel;
|
|
51
|
+
return {
|
|
52
|
+
start: () => {
|
|
53
|
+
channel = new BroadcastChannel(CHANNEL_NAME);
|
|
54
|
+
channel.onmessage = async (message) => {
|
|
55
|
+
try {
|
|
56
|
+
if (message.data.type === "probe") {
|
|
57
|
+
channel?.postMessage({
|
|
58
|
+
type: "probe-ack"
|
|
59
|
+
});
|
|
60
|
+
} else if (message.data.type === "request-diagnostics") {
|
|
61
|
+
const diagnostics = await systemService.getDiagnostics({});
|
|
62
|
+
channel?.postMessage({
|
|
63
|
+
type: "receive-diagnostics",
|
|
64
|
+
payload: diagnostics
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
log.catch(error, void 0, {
|
|
69
|
+
F: __dxlog_file,
|
|
70
|
+
L: 77,
|
|
71
|
+
S: void 0,
|
|
72
|
+
C: (f, a) => f(...a)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
stop: () => {
|
|
78
|
+
safeClose(channel);
|
|
79
|
+
channel = void 0;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
var safeClose = (channel) => {
|
|
84
|
+
try {
|
|
85
|
+
channel?.close();
|
|
86
|
+
} catch (e) {
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
createCollectDiagnosticsBroadcastHandler,
|
|
91
|
+
createCollectDiagnosticsBroadcastSender
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=browser-diagnostics-broadcast.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/packlets/diagnostics/browser-diagnostics-broadcast.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Trigger } from '@dxos/async';\nimport { log } from '@dxos/log';\nimport { type SystemService } from '@dxos/protocols/proto/dxos/client/services';\n\nimport {\n type CollectDiagnosticsBroadcastHandler,\n type CollectDiagnosticsBroadcastSender,\n} from './diagnostics-collector';\n\nconst CHANNEL_NAME = 'dxos.diagnostics.broadcast';\n\nenum MessageType {\n PROBE = 'probe',\n PROBE_ACK = 'probe-ack',\n REQUEST_DIAGNOSTICS = 'request-diagnostics',\n RECEIVE_DIAGNOSTICS = 'receive-diagnostics',\n}\n\ninterface Message {\n type: MessageType;\n payload?: any;\n}\n\nexport const createCollectDiagnosticsBroadcastSender = (): CollectDiagnosticsBroadcastSender => {\n return {\n broadcastDiagnosticsRequest: async () => {\n let expectedResponse = MessageType.PROBE_ACK;\n let channel: BroadcastChannel | undefined;\n try {\n const trigger = new Trigger<Message>();\n channel = new BroadcastChannel(CHANNEL_NAME);\n channel.onmessage = (msg) => {\n if (expectedResponse === msg.data.type) {\n trigger.wake(msg.data);\n }\n };\n channel.postMessage({ type: MessageType.PROBE });\n await trigger.wait({ timeout: 200 });\n expectedResponse = MessageType.RECEIVE_DIAGNOSTICS;\n trigger.reset();\n channel.postMessage({ type: MessageType.REQUEST_DIAGNOSTICS });\n const diagnostics = await trigger.wait({ timeout: 5000 });\n return diagnostics.payload;\n } catch (e) {\n const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);\n return { expectedResponse, errorDescription };\n } finally {\n safeClose(channel);\n }\n },\n };\n};\n\nexport const createCollectDiagnosticsBroadcastHandler = (\n systemService: SystemService,\n): CollectDiagnosticsBroadcastHandler => {\n let channel: BroadcastChannel | undefined;\n return {\n start: () => {\n channel = new BroadcastChannel(CHANNEL_NAME);\n channel.onmessage = async (message) => {\n try {\n if (message.data.type === MessageType.PROBE) {\n channel?.postMessage({ type: MessageType.PROBE_ACK });\n } else if (message.data.type === MessageType.REQUEST_DIAGNOSTICS) {\n const diagnostics = await systemService.getDiagnostics({});\n channel?.postMessage({\n type: MessageType.RECEIVE_DIAGNOSTICS,\n payload: diagnostics,\n });\n }\n } catch (error) {\n log.catch(error);\n }\n };\n },\n stop: () => {\n safeClose(channel);\n channel = undefined;\n },\n };\n};\n\nconst safeClose = (channel?: BroadcastChannel) => {\n try {\n channel?.close();\n } catch (e) {\n // ignored\n }\n};\n"],
|
|
5
|
+
"mappings": ";;;;AAIA,SAASA,eAAe;AACxB,SAASC,WAAW;;AAQpB,IAAMC,eAAe;AAcd,IAAMC,0CAA0C,MAAA;AACrD,SAAO;IACLC,6BAA6B,YAAA;AAC3B,UAAIC,mBAAAA;AACJ,UAAIC;AACJ,UAAI;AACF,cAAMC,UAAU,IAAIC,QAAAA;AACpBF,kBAAU,IAAIG,iBAAiBC,YAAAA;AAC/BJ,gBAAQK,YAAY,CAACC,QAAAA;AACnB,cAAIP,qBAAqBO,IAAIC,KAAKC,MAAM;AACtCP,oBAAQQ,KAAKH,IAAIC,IAAI;UACvB;QACF;AACAP,gBAAQU,YAAY;UAAEF,MAAI;QAAoB,CAAA;AAC9C,cAAMP,QAAQU,KAAK;UAAEC,SAAS;QAAI,CAAA;AAClCb,2BAAAA;AACAE,gBAAQY,MAAK;AACbb,gBAAQU,YAAY;UAAEF,MAAI;QAAkC,CAAA;AAC5D,cAAMM,cAAc,MAAMb,QAAQU,KAAK;UAAEC,SAAS;QAAK,CAAA;AACvD,eAAOE,YAAYC;MACrB,SAASC,GAAG;AACV,cAAMC,mBAAmBD,aAAaE,QAAQF,EAAEG,UAAUC,KAAKC,UAAUL,CAAAA;AACzE,eAAO;UAAEjB;UAAkBkB;QAAiB;MAC9C,UAAA;AACEK,kBAAUtB,OAAAA;MACZ;IACF;EACF;AACF;AAEO,IAAMuB,2CAA2C,CACtDC,kBAAAA;AAEA,MAAIxB;AACJ,SAAO;IACLyB,OAAO,MAAA;AACLzB,gBAAU,IAAIG,iBAAiBC,YAAAA;AAC/BJ,cAAQK,YAAY,OAAOc,YAAAA;AACzB,YAAI;AACF,cAAIA,QAAQZ,KAAKC,SAAI,SAAwB;AAC3CR,qBAASU,YAAY;cAAEF,MAAI;YAAwB,CAAA;UACrD,WAAWW,QAAQZ,KAAKC,SAAI,uBAAsC;AAChE,kBAAMM,cAAc,MAAMU,cAAcE,eAAe,CAAC,CAAA;AACxD1B,qBAASU,YAAY;cACnBF,MAAI;cACJO,SAASD;YACX,CAAA;UACF;QACF,SAASa,OAAO;AACdC,cAAIC,MAAMF,OAAAA,QAAAA;;;;;;QACZ;MACF;IACF;IACAG,MAAM,MAAA;AACJR,gBAAUtB,OAAAA;AACVA,gBAAU+B;IACZ;EACF;AACF;AAEA,IAAMT,YAAY,CAACtB,YAAAA;AACjB,MAAI;AACFA,aAASgC,MAAAA;EACX,SAAShB,GAAG;EAEZ;AACF;",
|
|
6
|
+
"names": ["Trigger", "log", "CHANNEL_NAME", "createCollectDiagnosticsBroadcastSender", "broadcastDiagnosticsRequest", "expectedResponse", "channel", "trigger", "Trigger", "BroadcastChannel", "CHANNEL_NAME", "onmessage", "msg", "data", "type", "wake", "postMessage", "wait", "timeout", "reset", "diagnostics", "payload", "e", "errorDescription", "Error", "message", "JSON", "stringify", "safeClose", "createCollectDiagnosticsBroadcastHandler", "systemService", "start", "getDiagnostics", "error", "log", "catch", "stop", "undefined", "close"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
import {
|
|
3
|
+
createCollectDiagnosticsBroadcastHandler,
|
|
4
|
+
createCollectDiagnosticsBroadcastSender
|
|
5
|
+
} from "../../chunk-NQSC7HOE.mjs";
|
|
6
|
+
import "../../chunk-QCWEHHJW.mjs";
|
|
7
|
+
export {
|
|
8
|
+
createCollectDiagnosticsBroadcastHandler,
|
|
9
|
+
createCollectDiagnosticsBroadcastSender
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=diagnostics-broadcast.mjs.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
import "../../chunk-QCWEHHJW.mjs";
|
|
3
|
+
|
|
4
|
+
// src/packlets/locks/browser.ts
|
|
5
|
+
import { Trigger, asyncTimeout } from "@dxos/async";
|
|
6
|
+
import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
|
|
7
|
+
import { log, logInfo } from "@dxos/log";
|
|
8
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
9
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
11
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
12
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
+
}
|
|
14
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
|
|
15
|
+
var Lock = class {
|
|
16
|
+
_broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
17
|
+
_lockKey;
|
|
18
|
+
_onAcquire;
|
|
19
|
+
_onRelease;
|
|
20
|
+
_releaseTrigger = new Trigger();
|
|
21
|
+
constructor({ lockKey, onAcquire, onRelease }) {
|
|
22
|
+
this._lockKey = lockKey;
|
|
23
|
+
this._onAcquire = onAcquire;
|
|
24
|
+
this._onRelease = onRelease;
|
|
25
|
+
this._broadcastChannel.onmessage = this._onMessage.bind(this);
|
|
26
|
+
}
|
|
27
|
+
get lockKey() {
|
|
28
|
+
return this._lockKey;
|
|
29
|
+
}
|
|
30
|
+
async acquire() {
|
|
31
|
+
this._broadcastChannel.postMessage({
|
|
32
|
+
message: "acquiring"
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
log("aquiring lock...", void 0, {
|
|
36
|
+
F: __dxlog_file,
|
|
37
|
+
L: 42,
|
|
38
|
+
S: this,
|
|
39
|
+
C: (f, a) => f(...a)
|
|
40
|
+
});
|
|
41
|
+
await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
|
|
42
|
+
log("acquired lock", void 0, {
|
|
43
|
+
F: __dxlog_file,
|
|
44
|
+
L: 44,
|
|
45
|
+
S: this,
|
|
46
|
+
C: (f, a) => f(...a)
|
|
47
|
+
});
|
|
48
|
+
} catch {
|
|
49
|
+
log("stealing lock...", void 0, {
|
|
50
|
+
F: __dxlog_file,
|
|
51
|
+
L: 46,
|
|
52
|
+
S: this,
|
|
53
|
+
C: (f, a) => f(...a)
|
|
54
|
+
});
|
|
55
|
+
await this._requestLock(true);
|
|
56
|
+
log("stolen lock", void 0, {
|
|
57
|
+
F: __dxlog_file,
|
|
58
|
+
L: 48,
|
|
59
|
+
S: this,
|
|
60
|
+
C: (f, a) => f(...a)
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async release() {
|
|
65
|
+
this._releaseTrigger.wake();
|
|
66
|
+
}
|
|
67
|
+
_onMessage(event) {
|
|
68
|
+
if (event.data.message === "acquiring") {
|
|
69
|
+
this._releaseTrigger.wake();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async _requestLock(steal = false) {
|
|
73
|
+
log("requesting lock...", {
|
|
74
|
+
steal
|
|
75
|
+
}, {
|
|
76
|
+
F: __dxlog_file,
|
|
77
|
+
L: 63,
|
|
78
|
+
S: this,
|
|
79
|
+
C: (f, a) => f(...a)
|
|
80
|
+
});
|
|
81
|
+
const acquired = new Trigger();
|
|
82
|
+
void navigator.locks.request(this._lockKey, {
|
|
83
|
+
steal
|
|
84
|
+
}, async () => {
|
|
85
|
+
await this._onAcquire?.();
|
|
86
|
+
acquired.wake();
|
|
87
|
+
this._releaseTrigger = new Trigger();
|
|
88
|
+
await this._releaseTrigger.wait();
|
|
89
|
+
log("releasing lock...", void 0, {
|
|
90
|
+
F: __dxlog_file,
|
|
91
|
+
L: 72,
|
|
92
|
+
S: this,
|
|
93
|
+
C: (f, a) => f(...a)
|
|
94
|
+
});
|
|
95
|
+
await this._onRelease?.();
|
|
96
|
+
log("released lock", void 0, {
|
|
97
|
+
F: __dxlog_file,
|
|
98
|
+
L: 74,
|
|
99
|
+
S: this,
|
|
100
|
+
C: (f, a) => f(...a)
|
|
101
|
+
});
|
|
102
|
+
}).catch(async () => {
|
|
103
|
+
await this._onRelease?.();
|
|
104
|
+
});
|
|
105
|
+
await acquired.wait();
|
|
106
|
+
log("recieved lock", {
|
|
107
|
+
steal
|
|
108
|
+
}, {
|
|
109
|
+
F: __dxlog_file,
|
|
110
|
+
L: 81,
|
|
111
|
+
S: this,
|
|
112
|
+
C: (f, a) => f(...a)
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
_ts_decorate([
|
|
117
|
+
logInfo
|
|
118
|
+
], Lock.prototype, "lockKey", null);
|
|
119
|
+
var isLocked = (lockPath) => {
|
|
120
|
+
throw new Error("Not implemented");
|
|
121
|
+
};
|
|
122
|
+
export {
|
|
123
|
+
Lock,
|
|
124
|
+
isLocked
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=browser.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/packlets/locks/browser.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Trigger, asyncTimeout } from '@dxos/async';\nimport { RESOURCE_LOCK_TIMEOUT } from '@dxos/client-protocol';\nimport { log, logInfo } from '@dxos/log';\n\nimport { type ResourceLock, type ResourceLockOptions } from './resource-lock';\n\nenum Message {\n ACQUIRING = 'acquiring',\n}\n\n// TODO(mykola): Factor out.\n// TODO(burdon): Extend to support locking for web and NodeJS (use npm lockfile). Use to lock agents.\nexport class Lock implements ResourceLock {\n private readonly _broadcastChannel = new BroadcastChannel('vault-resource-lock');\n private readonly _lockKey: string;\n private readonly _onAcquire: ResourceLockOptions['onAcquire'];\n private readonly _onRelease: ResourceLockOptions['onRelease'];\n private _releaseTrigger = new Trigger();\n\n constructor({ lockKey, onAcquire, onRelease }: ResourceLockOptions) {\n this._lockKey = lockKey;\n this._onAcquire = onAcquire;\n this._onRelease = onRelease;\n this._broadcastChannel.onmessage = this._onMessage.bind(this);\n }\n\n @logInfo\n get lockKey() {\n return this._lockKey;\n }\n\n async acquire(): Promise<void> {\n this._broadcastChannel.postMessage({\n message: Message.ACQUIRING,\n });\n\n try {\n log('aquiring lock...');\n await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);\n log('acquired lock');\n } catch {\n log('stealing lock...');\n await this._requestLock(true);\n log('stolen lock');\n }\n }\n\n async release(): Promise<void> {\n this._releaseTrigger.wake();\n }\n\n private _onMessage(event: MessageEvent<any>): void {\n if (event.data.message === Message.ACQUIRING) {\n this._releaseTrigger.wake();\n }\n }\n\n private async _requestLock(steal = false): Promise<void> {\n log('requesting lock...', { steal });\n const acquired = new Trigger();\n\n void navigator.locks\n .request(this._lockKey, { steal }, async () => {\n await this._onAcquire?.();\n acquired.wake();\n this._releaseTrigger = new Trigger();\n await this._releaseTrigger.wait();\n log('releasing lock...');\n await this._onRelease?.();\n log('released lock');\n })\n .catch(async () => {\n await this._onRelease?.();\n });\n\n await acquired.wait();\n log('recieved lock', { steal });\n }\n}\n\n// TODO(mykola): Implement.\nexport const isLocked = (lockPath: string) => {\n throw new Error('Not implemented');\n};\n"],
|
|
5
|
+
"mappings": ";;;;AAIA,SAASA,SAASC,oBAAoB;AACtC,SAASC,6BAA6B;AACtC,SAASC,KAAKC,eAAe;;;;;;;;AAUtB,IAAMC,OAAN,MAAMA;EACMC,oBAAoB,IAAIC,iBAAiB,qBAAA;EACzCC;EACAC;EACAC;EACTC,kBAAkB,IAAIC,QAAAA;EAE9B,YAAY,EAAEC,SAASC,WAAWC,UAAS,GAAyB;AAClE,SAAKP,WAAWK;AAChB,SAAKJ,aAAaK;AAClB,SAAKJ,aAAaK;AAClB,SAAKT,kBAAkBU,YAAY,KAAKC,WAAWC,KAAK,IAAI;EAC9D;EAEA,IACIL,UAAU;AACZ,WAAO,KAAKL;EACd;EAEA,MAAMW,UAAyB;AAC7B,SAAKb,kBAAkBc,YAAY;MACjCC,SAAO;IACT,CAAA;AAEA,QAAI;AACFC,UAAI,oBAAA,QAAA;;;;;;AACJ,YAAMC,aAAa,KAAKC,aAAY,GAAIC,qBAAAA;AACxCH,UAAI,iBAAA,QAAA;;;;;;IACN,QAAQ;AACNA,UAAI,oBAAA,QAAA;;;;;;AACJ,YAAM,KAAKE,aAAa,IAAA;AACxBF,UAAI,eAAA,QAAA;;;;;;IACN;EACF;EAEA,MAAMI,UAAyB;AAC7B,SAAKf,gBAAgBgB,KAAI;EAC3B;EAEQV,WAAWW,OAAgC;AACjD,QAAIA,MAAMC,KAAKR,YAAO,aAAwB;AAC5C,WAAKV,gBAAgBgB,KAAI;IAC3B;EACF;EAEA,MAAcH,aAAaM,QAAQ,OAAsB;AACvDR,QAAI,sBAAsB;MAAEQ;IAAM,GAAA;;;;;;AAClC,UAAMC,WAAW,IAAInB,QAAAA;AAErB,SAAKoB,UAAUC,MACZC,QAAQ,KAAK1B,UAAU;MAAEsB;IAAM,GAAG,YAAA;AACjC,YAAM,KAAKrB,aAAU;AACrBsB,eAASJ,KAAI;AACb,WAAKhB,kBAAkB,IAAIC,QAAAA;AAC3B,YAAM,KAAKD,gBAAgBwB,KAAI;AAC/Bb,UAAI,qBAAA,QAAA;;;;;;AACJ,YAAM,KAAKZ,aAAU;AACrBY,UAAI,iBAAA,QAAA;;;;;;IACN,CAAA,EACCc,MAAM,YAAA;AACL,YAAM,KAAK1B,aAAU;IACvB,CAAA;AAEF,UAAMqB,SAASI,KAAI;AACnBb,QAAI,iBAAiB;MAAEQ;IAAM,GAAA;;;;;;EAC/B;AACF;;;;AAGO,IAAMO,WAAW,CAACC,aAAAA;AACvB,QAAM,IAAIC,MAAM,iBAAA;AAClB;",
|
|
6
|
+
"names": ["Trigger", "asyncTimeout", "RESOURCE_LOCK_TIMEOUT", "log", "logInfo", "Lock", "_broadcastChannel", "BroadcastChannel", "_lockKey", "_onAcquire", "_onRelease", "_releaseTrigger", "Trigger", "lockKey", "onAcquire", "onRelease", "onmessage", "_onMessage", "bind", "acquire", "postMessage", "message", "log", "asyncTimeout", "_requestLock", "RESOURCE_LOCK_TIMEOUT", "release", "wake", "event", "data", "steal", "acquired", "navigator", "locks", "request", "wait", "catch", "isLocked", "lockPath", "Error"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
import "../../chunk-QCWEHHJW.mjs";
|
|
3
|
+
|
|
4
|
+
// src/packlets/locks/node.ts
|
|
5
|
+
import { invariant } from "@dxos/invariant";
|
|
6
|
+
import { LockFile } from "@dxos/lock-file";
|
|
7
|
+
import { log, logInfo } from "@dxos/log";
|
|
8
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
9
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
11
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
12
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
+
}
|
|
14
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
|
|
15
|
+
var Lock = class {
|
|
16
|
+
_lockPath;
|
|
17
|
+
_onAcquire;
|
|
18
|
+
_onRelease;
|
|
19
|
+
_fileHandle;
|
|
20
|
+
constructor({ lockKey: lockPath, onAcquire, onRelease }) {
|
|
21
|
+
this._lockPath = lockPath;
|
|
22
|
+
this._onAcquire = onAcquire;
|
|
23
|
+
this._onRelease = onRelease;
|
|
24
|
+
}
|
|
25
|
+
get lockKey() {
|
|
26
|
+
return this._lockPath;
|
|
27
|
+
}
|
|
28
|
+
async acquire() {
|
|
29
|
+
log("acquiring lock...", void 0, {
|
|
30
|
+
F: __dxlog_file,
|
|
31
|
+
L: 32,
|
|
32
|
+
S: this,
|
|
33
|
+
C: (f, a) => f(...a)
|
|
34
|
+
});
|
|
35
|
+
this._fileHandle = await LockFile.acquire(this._lockPath);
|
|
36
|
+
await this._onAcquire?.();
|
|
37
|
+
log("acquired lock", void 0, {
|
|
38
|
+
F: __dxlog_file,
|
|
39
|
+
L: 37,
|
|
40
|
+
S: this,
|
|
41
|
+
C: (f, a) => f(...a)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async release() {
|
|
45
|
+
await this._onRelease?.();
|
|
46
|
+
invariant(this._fileHandle, "Lock is not acquired", {
|
|
47
|
+
F: __dxlog_file,
|
|
48
|
+
L: 42,
|
|
49
|
+
S: this,
|
|
50
|
+
A: [
|
|
51
|
+
"this._fileHandle",
|
|
52
|
+
"'Lock is not acquired'"
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
await LockFile.release(this._fileHandle);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
_ts_decorate([
|
|
59
|
+
logInfo
|
|
60
|
+
], Lock.prototype, "lockKey", null);
|
|
61
|
+
var isLocked = (lockPath) => LockFile.isLocked(lockPath);
|
|
62
|
+
export {
|
|
63
|
+
Lock,
|
|
64
|
+
isLocked
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=node.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/packlets/locks/node.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type FileHandle } from 'node:fs/promises';\n\nimport { invariant } from '@dxos/invariant';\nimport { LockFile } from '@dxos/lock-file';\nimport { log, logInfo } from '@dxos/log';\n\nimport { type ResourceLock, type ResourceLockOptions } from './resource-lock';\n\n// TODO(mykola): Factor out.\nexport class Lock implements ResourceLock {\n private readonly _lockPath: string;\n private readonly _onAcquire: ResourceLockOptions['onAcquire'];\n private readonly _onRelease: ResourceLockOptions['onRelease'];\n private _fileHandle?: FileHandle;\n\n constructor({ lockKey: lockPath, onAcquire, onRelease }: ResourceLockOptions) {\n this._lockPath = lockPath;\n this._onAcquire = onAcquire;\n this._onRelease = onRelease;\n }\n\n @logInfo\n get lockKey() {\n return this._lockPath;\n }\n\n async acquire(): Promise<void> {\n log('acquiring lock...');\n this._fileHandle = await LockFile.acquire(this._lockPath);\n\n await this._onAcquire?.();\n\n log('acquired lock');\n }\n\n async release(): Promise<void> {\n await this._onRelease?.();\n invariant(this._fileHandle, 'Lock is not acquired');\n await LockFile.release(this._fileHandle);\n }\n}\n\nexport const isLocked = (lockPath: string) => LockFile.isLocked(lockPath);\n"],
|
|
5
|
+
"mappings": ";;;;AAMA,SAASA,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,KAAKC,eAAe;;;;;;;;AAKtB,IAAMC,OAAN,MAAMA;EACMC;EACAC;EACAC;EACTC;EAER,YAAY,EAAEC,SAASC,UAAUC,WAAWC,UAAS,GAAyB;AAC5E,SAAKP,YAAYK;AACjB,SAAKJ,aAAaK;AAClB,SAAKJ,aAAaK;EACpB;EAEA,IACIH,UAAU;AACZ,WAAO,KAAKJ;EACd;EAEA,MAAMQ,UAAyB;AAC7BX,QAAI,qBAAA,QAAA;;;;;;AACJ,SAAKM,cAAc,MAAMP,SAASY,QAAQ,KAAKR,SAAS;AAExD,UAAM,KAAKC,aAAU;AAErBJ,QAAI,iBAAA,QAAA;;;;;;EACN;EAEA,MAAMY,UAAyB;AAC7B,UAAM,KAAKP,aAAU;AACrBP,cAAU,KAAKQ,aAAa,wBAAA;;;;;;;;;AAC5B,UAAMP,SAASa,QAAQ,KAAKN,WAAW;EACzC;AACF;;;;AAEO,IAAMO,WAAW,CAACL,aAAqBT,SAASc,SAASL,QAAAA;",
|
|
6
|
+
"names": ["invariant", "LockFile", "log", "logInfo", "Lock", "_lockPath", "_onAcquire", "_onRelease", "_fileHandle", "lockKey", "lockPath", "onAcquire", "onRelease", "acquire", "release", "isLocked"]
|
|
7
|
+
}
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
InvitationsManager,
|
|
7
7
|
ServiceContext,
|
|
8
8
|
SpaceInvitationProtocol
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-J7VTDH4K.mjs";
|
|
10
|
+
import "../chunk-NQSC7HOE.mjs";
|
|
11
|
+
import "../chunk-QCWEHHJW.mjs";
|
|
10
12
|
|
|
11
13
|
// src/packlets/testing/credential-utils.ts
|
|
12
14
|
import { createCredential } from "@dxos/credentials";
|
|
@@ -27,13 +29,14 @@ var createMockCredential = async ({ signer, issuer }) => createCredential({
|
|
|
27
29
|
// src/packlets/testing/invitation-utils.ts
|
|
28
30
|
import { Trigger } from "@dxos/async";
|
|
29
31
|
import { InvitationEncoder } from "@dxos/client-protocol";
|
|
32
|
+
import { Context } from "@dxos/context";
|
|
30
33
|
import { invariant } from "@dxos/invariant";
|
|
31
34
|
import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
|
|
32
35
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/testing/invitation-utils.ts";
|
|
33
36
|
var sanitizeInvitation = (invitation) => {
|
|
34
37
|
return InvitationEncoder.decode(InvitationEncoder.encode(invitation));
|
|
35
38
|
};
|
|
36
|
-
var performInvitation = ({ host, guest, options, hooks,
|
|
39
|
+
var performInvitation = ({ host, guest, guestDeviceProfile, options, hooks, codeInputDelay }) => {
|
|
37
40
|
let guestError = false;
|
|
38
41
|
let guestConnected = false;
|
|
39
42
|
let wereConnected = false;
|
|
@@ -65,7 +68,7 @@ var performInvitation = ({ host, guest, options, hooks, guestDeviceProfile, code
|
|
|
65
68
|
}
|
|
66
69
|
invariant(hostInvitation.swarmKey.equals(guestInvitation.swarmKey), void 0, {
|
|
67
70
|
F: __dxlog_file,
|
|
68
|
-
L:
|
|
71
|
+
L: 99,
|
|
69
72
|
S: void 0,
|
|
70
73
|
A: [
|
|
71
74
|
"hostInvitation.swarmKey!.equals(guestInvitation.swarmKey!)",
|
|
@@ -197,12 +200,15 @@ var performInvitation = ({ host, guest, options, hooks, guestDeviceProfile, code
|
|
|
197
200
|
];
|
|
198
201
|
};
|
|
199
202
|
var createInvitation = async (host, options) => {
|
|
200
|
-
options
|
|
203
|
+
options ??= {
|
|
201
204
|
authMethod: Invitation.AuthMethod.NONE,
|
|
202
205
|
...options ?? {}
|
|
203
|
-
}
|
|
206
|
+
};
|
|
204
207
|
if (host instanceof ServiceContext) {
|
|
205
|
-
return host.invitationsManager.createInvitation({
|
|
208
|
+
return host.invitationsManager.createInvitation(new Context(void 0, {
|
|
209
|
+
F: __dxlog_file,
|
|
210
|
+
L: 233
|
|
211
|
+
}), {
|
|
206
212
|
kind: Invitation.Kind.SPACE,
|
|
207
213
|
...options
|
|
208
214
|
});
|
|
@@ -212,7 +218,10 @@ var createInvitation = async (host, options) => {
|
|
|
212
218
|
var acceptInvitation = (guest, invitation, guestDeviceProfile) => {
|
|
213
219
|
invitation = sanitizeInvitation(invitation);
|
|
214
220
|
if (guest instanceof ServiceContext) {
|
|
215
|
-
return guest.invitationsManager.acceptInvitation({
|
|
221
|
+
return guest.invitationsManager.acceptInvitation(new Context(void 0, {
|
|
222
|
+
F: __dxlog_file,
|
|
223
|
+
L: 250
|
|
224
|
+
}), {
|
|
216
225
|
invitation,
|
|
217
226
|
deviceProfile: guestDeviceProfile
|
|
218
227
|
});
|
|
@@ -221,7 +230,10 @@ var acceptInvitation = (guest, invitation, guestDeviceProfile) => {
|
|
|
221
230
|
};
|
|
222
231
|
|
|
223
232
|
// src/packlets/testing/test-builder.ts
|
|
224
|
-
import
|
|
233
|
+
import * as Reactivity from "@effect/experimental/Reactivity";
|
|
234
|
+
import * as Layer from "effect/Layer";
|
|
235
|
+
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
236
|
+
import { Context as Context2 } from "@dxos/context";
|
|
225
237
|
import { CredentialGenerator, createCredentialSignerWithChain } from "@dxos/credentials";
|
|
226
238
|
import { failUndefined } from "@dxos/debug";
|
|
227
239
|
import { EchoHost, MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
|
|
@@ -232,26 +244,16 @@ import { MemorySignalManager, MemorySignalManagerContext } from "@dxos/messaging
|
|
|
232
244
|
import { MemoryTransportFactory, SwarmNetworkManager } from "@dxos/network-manager";
|
|
233
245
|
import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
234
246
|
import { StorageType, createStorage } from "@dxos/random-access-storage";
|
|
247
|
+
import { layerMemory as sqliteLayerMemory } from "@dxos/sql-sqlite/platform";
|
|
248
|
+
import * as SqlTransaction from "@dxos/sql-sqlite/SqlTransaction";
|
|
235
249
|
import { BlobStore } from "@dxos/teleport-extension-object-sync";
|
|
236
|
-
function _define_property(obj, key, value) {
|
|
237
|
-
if (key in obj) {
|
|
238
|
-
Object.defineProperty(obj, key, {
|
|
239
|
-
value,
|
|
240
|
-
enumerable: true,
|
|
241
|
-
configurable: true,
|
|
242
|
-
writable: true
|
|
243
|
-
});
|
|
244
|
-
} else {
|
|
245
|
-
obj[key] = value;
|
|
246
|
-
}
|
|
247
|
-
return obj;
|
|
248
|
-
}
|
|
249
250
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/testing/test-builder.ts";
|
|
250
251
|
var createServiceHost = (config, signalManagerContext) => {
|
|
251
252
|
return new ClientServicesHost({
|
|
252
253
|
config,
|
|
253
254
|
signalManager: new MemorySignalManager(signalManagerContext),
|
|
254
|
-
transportFactory: MemoryTransportFactory
|
|
255
|
+
transportFactory: MemoryTransportFactory,
|
|
256
|
+
runtime: ManagedRuntime.make(SqlTransaction.layer.pipe(Layer.provideMerge(sqliteLayerMemory), Layer.provideMerge(Reactivity.layer)).pipe(Layer.orDie)).runtimeEffect
|
|
255
257
|
});
|
|
256
258
|
};
|
|
257
259
|
var createServiceContext = async ({ signalManagerFactory = async () => {
|
|
@@ -259,7 +261,7 @@ var createServiceContext = async ({ signalManagerFactory = async () => {
|
|
|
259
261
|
return new MemorySignalManager(signalContext);
|
|
260
262
|
}, storage = createStorage({
|
|
261
263
|
type: StorageType.RAM
|
|
262
|
-
}),
|
|
264
|
+
}), runtimeProps } = {}) => {
|
|
263
265
|
const signalManager = await signalManagerFactory();
|
|
264
266
|
const networkManager = new SwarmNetworkManager({
|
|
265
267
|
signalManager,
|
|
@@ -267,13 +269,14 @@ var createServiceContext = async ({ signalManagerFactory = async () => {
|
|
|
267
269
|
});
|
|
268
270
|
const level = createTestLevel();
|
|
269
271
|
await level.open();
|
|
270
|
-
|
|
271
|
-
|
|
272
|
+
const runtime = ManagedRuntime.make(SqlTransaction.layer.pipe(Layer.provideMerge(sqliteLayerMemory), Layer.provideMerge(Reactivity.layer)).pipe(Layer.orDie)).runtimeEffect;
|
|
273
|
+
return new ServiceContext(storage, level, networkManager, signalManager, void 0, void 0, runtime, {
|
|
274
|
+
invitationConnectionDefaultProps: {
|
|
272
275
|
teleport: {
|
|
273
276
|
controlHeartbeatInterval: 200
|
|
274
277
|
}
|
|
275
278
|
},
|
|
276
|
-
...
|
|
279
|
+
...runtimeProps
|
|
277
280
|
});
|
|
278
281
|
};
|
|
279
282
|
var createPeers = async (numPeers, signalManagerFactory) => {
|
|
@@ -285,9 +288,9 @@ var createPeers = async (numPeers, signalManagerFactory) => {
|
|
|
285
288
|
const peer = await createServiceContext({
|
|
286
289
|
signalManagerFactory
|
|
287
290
|
});
|
|
288
|
-
await peer.open(new
|
|
291
|
+
await peer.open(new Context2(void 0, {
|
|
289
292
|
F: __dxlog_file2,
|
|
290
|
-
L:
|
|
293
|
+
L: 87
|
|
291
294
|
}));
|
|
292
295
|
return peer;
|
|
293
296
|
}));
|
|
@@ -297,6 +300,11 @@ var createIdentity = async (peer) => {
|
|
|
297
300
|
return peer;
|
|
298
301
|
};
|
|
299
302
|
var TestBuilder = class {
|
|
303
|
+
signalContext = new MemorySignalManagerContext();
|
|
304
|
+
_ctx = new Context2(void 0, {
|
|
305
|
+
F: __dxlog_file2,
|
|
306
|
+
L: 100
|
|
307
|
+
});
|
|
300
308
|
createPeer(peerOptions) {
|
|
301
309
|
const peer = new TestPeer(this.signalContext, peerOptions);
|
|
302
310
|
this._ctx.onDispose(async () => peer.destroy());
|
|
@@ -305,35 +313,34 @@ var TestBuilder = class {
|
|
|
305
313
|
async destroy() {
|
|
306
314
|
await this._ctx.dispose();
|
|
307
315
|
}
|
|
308
|
-
constructor() {
|
|
309
|
-
_define_property(this, "signalContext", new MemorySignalManagerContext());
|
|
310
|
-
_define_property(this, "_ctx", new Context(void 0, {
|
|
311
|
-
F: __dxlog_file2,
|
|
312
|
-
L: 83
|
|
313
|
-
}));
|
|
314
|
-
}
|
|
315
316
|
};
|
|
316
317
|
var TestPeer = class {
|
|
318
|
+
_signalContext;
|
|
319
|
+
_opts;
|
|
320
|
+
_props = {};
|
|
321
|
+
_runtime = ManagedRuntime.make(SqlTransaction.layer.pipe(Layer.provideMerge(sqliteLayerMemory), Layer.provideMerge(Reactivity.layer)).pipe(Layer.orDie));
|
|
322
|
+
constructor(_signalContext, _opts = {
|
|
323
|
+
dataStore: StorageType.RAM
|
|
324
|
+
}) {
|
|
325
|
+
this._signalContext = _signalContext;
|
|
326
|
+
this._opts = _opts;
|
|
327
|
+
}
|
|
317
328
|
get props() {
|
|
318
329
|
return this._props;
|
|
319
330
|
}
|
|
320
331
|
get storage() {
|
|
321
|
-
|
|
322
|
-
return (_this__props = this._props).storage ?? (_this__props.storage = createStorage({
|
|
332
|
+
return this._props.storage ??= createStorage({
|
|
323
333
|
type: this._opts.dataStore
|
|
324
|
-
})
|
|
334
|
+
});
|
|
325
335
|
}
|
|
326
336
|
get keyring() {
|
|
327
|
-
|
|
328
|
-
return (_this__props = this._props).keyring ?? (_this__props.keyring = new Keyring(this.storage.createDirectory("keyring")));
|
|
337
|
+
return this._props.keyring ??= new Keyring(this.storage.createDirectory("keyring"));
|
|
329
338
|
}
|
|
330
339
|
get level() {
|
|
331
|
-
|
|
332
|
-
return (_this__props = this._props).level ?? (_this__props.level = createTestLevel());
|
|
340
|
+
return this._props.level ??= createTestLevel();
|
|
333
341
|
}
|
|
334
342
|
get feedStore() {
|
|
335
|
-
|
|
336
|
-
return (_this__props = this._props).feedStore ?? (_this__props.feedStore = new FeedStore({
|
|
343
|
+
return this._props.feedStore ??= new FeedStore({
|
|
337
344
|
factory: new FeedFactory({
|
|
338
345
|
root: this.storage.createDirectory("feeds"),
|
|
339
346
|
signer: this.keyring,
|
|
@@ -341,48 +348,42 @@ var TestPeer = class {
|
|
|
341
348
|
valueEncoding
|
|
342
349
|
}
|
|
343
350
|
})
|
|
344
|
-
})
|
|
351
|
+
});
|
|
345
352
|
}
|
|
346
353
|
get metadataStore() {
|
|
347
|
-
|
|
348
|
-
return (_this__props = this._props).metadataStore ?? (_this__props.metadataStore = new MetadataStore(this.storage.createDirectory("metadata")));
|
|
354
|
+
return this._props.metadataStore ??= new MetadataStore(this.storage.createDirectory("metadata"));
|
|
349
355
|
}
|
|
350
356
|
get blobStore() {
|
|
351
|
-
|
|
352
|
-
return (_this__props = this._props).blobStore ?? (_this__props.blobStore = new BlobStore(this.storage.createDirectory("blobs")));
|
|
357
|
+
return this._props.blobStore ??= new BlobStore(this.storage.createDirectory("blobs"));
|
|
353
358
|
}
|
|
354
359
|
get networkManager() {
|
|
355
|
-
|
|
356
|
-
return (_this__props = this._props).networkManager ?? (_this__props.networkManager = new SwarmNetworkManager({
|
|
360
|
+
return this._props.networkManager ??= new SwarmNetworkManager({
|
|
357
361
|
signalManager: new MemorySignalManager(this._signalContext),
|
|
358
362
|
transportFactory: MemoryTransportFactory
|
|
359
|
-
})
|
|
363
|
+
});
|
|
360
364
|
}
|
|
361
365
|
get spaceManager() {
|
|
362
|
-
|
|
363
|
-
return (_this__props = this._props).spaceManager ?? (_this__props.spaceManager = new SpaceManager({
|
|
366
|
+
return this._props.spaceManager ??= new SpaceManager({
|
|
364
367
|
feedStore: this.feedStore,
|
|
365
368
|
networkManager: this.networkManager,
|
|
366
369
|
metadataStore: this.metadataStore,
|
|
367
370
|
blobStore: this.blobStore
|
|
368
|
-
})
|
|
371
|
+
});
|
|
369
372
|
}
|
|
370
373
|
get identity() {
|
|
371
374
|
return this._props.signingContext ?? failUndefined();
|
|
372
375
|
}
|
|
373
376
|
get echoHost() {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
})
|
|
377
|
+
return this._props.echoHost ??= new EchoHost({
|
|
378
|
+
kv: this.level,
|
|
379
|
+
runtime: this._runtime.runtimeEffect
|
|
380
|
+
});
|
|
378
381
|
}
|
|
379
382
|
get meshEchoReplicator() {
|
|
380
|
-
|
|
381
|
-
return (_this__props = this._props).meshEchoReplicator ?? (_this__props.meshEchoReplicator = new MeshEchoReplicator());
|
|
383
|
+
return this._props.meshEchoReplicator ??= new MeshEchoReplicator();
|
|
382
384
|
}
|
|
383
385
|
get dataSpaceManager() {
|
|
384
|
-
|
|
385
|
-
return (_this__props = this._props).dataSpaceManager ?? (_this__props.dataSpaceManager = new DataSpaceManager({
|
|
386
|
+
return this._props.dataSpaceManager ??= new DataSpaceManager({
|
|
386
387
|
spaceManager: this.spaceManager,
|
|
387
388
|
metadataStore: this.metadataStore,
|
|
388
389
|
keyring: this.keyring,
|
|
@@ -393,22 +394,20 @@ var TestPeer = class {
|
|
|
393
394
|
edgeConnection: void 0,
|
|
394
395
|
meshReplicator: this.meshEchoReplicator,
|
|
395
396
|
echoEdgeReplicator: void 0,
|
|
396
|
-
|
|
397
|
-
})
|
|
397
|
+
runtimeProps: this._opts.dataSpaceProps
|
|
398
|
+
});
|
|
398
399
|
}
|
|
399
400
|
get invitationsManager() {
|
|
400
|
-
|
|
401
|
-
return (_this__props = this._props).invitationsManager ?? (_this__props.invitationsManager = new InvitationsManager(new InvitationsHandler(this.networkManager), (invitation) => {
|
|
401
|
+
return this._props.invitationsManager ??= new InvitationsManager(new InvitationsHandler(this.networkManager), (invitation) => {
|
|
402
402
|
if (invitation.kind === Invitation2.Kind.SPACE) {
|
|
403
403
|
return new SpaceInvitationProtocol(this.dataSpaceManager, this.identity, this.keyring, invitation.spaceKey);
|
|
404
404
|
} else {
|
|
405
405
|
throw new Error("not implemented");
|
|
406
406
|
}
|
|
407
|
-
}, this.metadataStore)
|
|
407
|
+
}, this.metadataStore);
|
|
408
408
|
}
|
|
409
409
|
async createIdentity() {
|
|
410
|
-
|
|
411
|
-
(_this__props = this._props).signingContext ?? (_this__props.signingContext = await createSigningContext(this.keyring));
|
|
410
|
+
this._props.signingContext ??= await createSigningContext(this.keyring);
|
|
412
411
|
this.networkManager.setPeerInfo({
|
|
413
412
|
identityKey: this._props.signingContext.identityKey.toHex(),
|
|
414
413
|
peerKey: this._props.signingContext.deviceKey.toHex()
|
|
@@ -417,16 +416,7 @@ var TestPeer = class {
|
|
|
417
416
|
async destroy() {
|
|
418
417
|
await this.level.close();
|
|
419
418
|
await this.storage.reset();
|
|
420
|
-
|
|
421
|
-
constructor(_signalContext, _opts = {
|
|
422
|
-
dataStore: StorageType.RAM
|
|
423
|
-
}) {
|
|
424
|
-
_define_property(this, "_signalContext", void 0);
|
|
425
|
-
_define_property(this, "_opts", void 0);
|
|
426
|
-
_define_property(this, "_props", void 0);
|
|
427
|
-
this._signalContext = _signalContext;
|
|
428
|
-
this._opts = _opts;
|
|
429
|
-
this._props = {};
|
|
419
|
+
await this._runtime.dispose();
|
|
430
420
|
}
|
|
431
421
|
};
|
|
432
422
|
var createSigningContext = async (keyring) => {
|