@dxos/client-services 0.1.29-next.ed4ce05 → 0.1.29
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-ILMYW75X.mjs → chunk-ZIQUYEJS.mjs} +183 -94
- package/dist/lib/browser/{chunk-ILMYW75X.mjs.map → chunk-ZIQUYEJS.mjs.map} +4 -4
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +1 -1
- package/dist/lib/node/index.cjs +191 -104
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +196 -100
- package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
- package/dist/types/src/packlets/services/client-rpc-server.d.ts +22 -0
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -0
- package/dist/types/src/packlets/services/local-client-services.d.ts +2 -1
- package/dist/types/src/packlets/services/local-client-services.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +21 -6
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-registry.d.ts +3 -1
- package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts +2 -2
- package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +0 -1
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/worker-session.d.ts +4 -4
- package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
- package/package.json +30 -30
- package/src/packlets/services/client-rpc-server.ts +91 -0
- package/src/packlets/services/local-client-services.ts +4 -0
- package/src/packlets/services/service-host.ts +51 -10
- package/src/packlets/services/service-registry.ts +9 -1
- package/src/packlets/system/system-service.ts +3 -3
- package/src/packlets/tests/shared-worker.test.ts +39 -42
- package/src/packlets/vault/iframe-host-runtime.ts +25 -34
- package/src/packlets/vault/worker-runtime.ts +5 -15
- package/src/packlets/vault/worker-session.ts +40 -28
|
@@ -64,7 +64,7 @@ var createMockCredential = async ({ signer, issuer }) => (0, import_credentials.
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
// packages/sdk/client-services/src/packlets/testing/host-test-builder.ts
|
|
67
|
-
var
|
|
67
|
+
var import_client7 = require("@dxos/client");
|
|
68
68
|
var import_credentials13 = require("@dxos/credentials");
|
|
69
69
|
var import_echo_pipeline6 = require("@dxos/echo-pipeline");
|
|
70
70
|
var import_testing = require("@dxos/echo-pipeline/testing");
|
|
@@ -77,8 +77,8 @@ var import_random_access_storage2 = require("@dxos/random-access-storage");
|
|
|
77
77
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
78
78
|
var import_node_assert12 = __toESM(require("node:assert"));
|
|
79
79
|
var import_async19 = require("@dxos/async");
|
|
80
|
-
var
|
|
81
|
-
var
|
|
80
|
+
var import_client6 = require("@dxos/client");
|
|
81
|
+
var import_debug7 = require("@dxos/debug");
|
|
82
82
|
var import_echo_pipeline5 = require("@dxos/echo-pipeline");
|
|
83
83
|
var import_log15 = require("@dxos/log");
|
|
84
84
|
var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
|
|
@@ -2732,7 +2732,8 @@ var SystemServiceImpl = class {
|
|
|
2732
2732
|
this._onReset = onReset;
|
|
2733
2733
|
}
|
|
2734
2734
|
async getConfig() {
|
|
2735
|
-
|
|
2735
|
+
var _a, _b;
|
|
2736
|
+
return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
|
|
2736
2737
|
}
|
|
2737
2738
|
async updateStatus({ status }) {
|
|
2738
2739
|
await this._onUpdateStatus(status);
|
|
@@ -2760,19 +2761,70 @@ var SystemServiceImpl = class {
|
|
|
2760
2761
|
|
|
2761
2762
|
// packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
|
|
2762
2763
|
var import_async14 = require("@dxos/async");
|
|
2763
|
-
var import_client4 = require("@dxos/client");
|
|
2764
2764
|
var import_log10 = require("@dxos/log");
|
|
2765
2765
|
var import_messaging = require("@dxos/messaging");
|
|
2766
2766
|
var import_network_manager3 = require("@dxos/network-manager");
|
|
2767
|
-
var import_rpc2 = require("@dxos/rpc");
|
|
2768
2767
|
var import_util7 = require("@dxos/util");
|
|
2769
2768
|
|
|
2769
|
+
// packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
|
|
2770
|
+
var import_codec_protobuf12 = require("@dxos/codec-protobuf");
|
|
2771
|
+
var import_debug5 = require("@dxos/debug");
|
|
2772
|
+
var import_rpc = require("@dxos/rpc");
|
|
2773
|
+
var ClientRpcServer = class {
|
|
2774
|
+
constructor(params) {
|
|
2775
|
+
this._handlerCache = /* @__PURE__ */ new Map();
|
|
2776
|
+
const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
|
|
2777
|
+
this._handleCall = handleCall;
|
|
2778
|
+
this._handleStream = handleStream;
|
|
2779
|
+
this._serviceRegistry = serviceRegistry;
|
|
2780
|
+
this._rpcPeer = new import_rpc.RpcPeer({
|
|
2781
|
+
...rpcOptions,
|
|
2782
|
+
callHandler: (method, params2) => {
|
|
2783
|
+
const [serviceName, methodName] = (0, import_rpc.parseMethodName)(method);
|
|
2784
|
+
const handler = (method2, params3) => this._getServiceHandler(serviceName).call(method2, params3);
|
|
2785
|
+
if (this._handleCall) {
|
|
2786
|
+
return this._handleCall(methodName, params2, handler);
|
|
2787
|
+
} else {
|
|
2788
|
+
return handler(methodName, params2);
|
|
2789
|
+
}
|
|
2790
|
+
},
|
|
2791
|
+
streamHandler: (method, params2) => {
|
|
2792
|
+
const [serviceName, methodName] = (0, import_rpc.parseMethodName)(method);
|
|
2793
|
+
const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
|
|
2794
|
+
if (this._handleStream) {
|
|
2795
|
+
return import_codec_protobuf12.Stream.unwrapPromise(this._handleStream(methodName, params2, handler));
|
|
2796
|
+
} else {
|
|
2797
|
+
return handler(methodName, params2);
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2802
|
+
async open() {
|
|
2803
|
+
await this._rpcPeer.open();
|
|
2804
|
+
}
|
|
2805
|
+
async close() {
|
|
2806
|
+
await this._rpcPeer.close();
|
|
2807
|
+
}
|
|
2808
|
+
_getServiceHandler(serviceName) {
|
|
2809
|
+
var _a;
|
|
2810
|
+
if (!this._handlerCache.has(serviceName)) {
|
|
2811
|
+
const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : (0, import_debug5.raise)(new Error(`Service not available: ${serviceName}`));
|
|
2812
|
+
const service = this._serviceRegistry.services[key];
|
|
2813
|
+
if (!service) {
|
|
2814
|
+
throw new Error(`Service not available: ${serviceName}`);
|
|
2815
|
+
}
|
|
2816
|
+
this._handlerCache.set(serviceName, descriptor.createServer(service));
|
|
2817
|
+
}
|
|
2818
|
+
return this._handlerCache.get(serviceName);
|
|
2819
|
+
}
|
|
2820
|
+
};
|
|
2821
|
+
|
|
2770
2822
|
// packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
|
|
2771
2823
|
var import_node_assert10 = __toESM(require("node:assert"));
|
|
2772
2824
|
var import_async13 = require("@dxos/async");
|
|
2773
2825
|
var import_client3 = require("@dxos/client");
|
|
2774
2826
|
var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
|
|
2775
|
-
var
|
|
2827
|
+
var import_rpc2 = require("@dxos/rpc");
|
|
2776
2828
|
var ShellRuntimeImpl = class {
|
|
2777
2829
|
constructor(_port) {
|
|
2778
2830
|
this._port = _port;
|
|
@@ -2802,7 +2854,7 @@ var ShellRuntimeImpl = class {
|
|
|
2802
2854
|
await this._appRpc.rpc.AppService.setContext(context);
|
|
2803
2855
|
}
|
|
2804
2856
|
async open() {
|
|
2805
|
-
this._appRpc = (0,
|
|
2857
|
+
this._appRpc = (0, import_rpc2.createProtoRpcPeer)({
|
|
2806
2858
|
requested: import_client3.appServiceBundle,
|
|
2807
2859
|
exposed: import_client3.shellServiceBundle,
|
|
2808
2860
|
handlers: {
|
|
@@ -2845,17 +2897,6 @@ var IFrameHostRuntime = class {
|
|
|
2845
2897
|
this._configProvider = configProvider;
|
|
2846
2898
|
this._appPort = appPort;
|
|
2847
2899
|
this._shellPort = shellPort;
|
|
2848
|
-
this._getService = async (find) => {
|
|
2849
|
-
const error = await this._ready.wait();
|
|
2850
|
-
if (error) {
|
|
2851
|
-
throw error;
|
|
2852
|
-
}
|
|
2853
|
-
const service = await find(this._clientServices.services);
|
|
2854
|
-
if (!service) {
|
|
2855
|
-
throw new Error("Service not found");
|
|
2856
|
-
}
|
|
2857
|
-
return service;
|
|
2858
|
-
};
|
|
2859
2900
|
if (this._shellPort) {
|
|
2860
2901
|
this._shellRuntime = new ShellRuntimeImpl(this._shellPort);
|
|
2861
2902
|
}
|
|
@@ -2870,7 +2911,7 @@ var IFrameHostRuntime = class {
|
|
|
2870
2911
|
var _a;
|
|
2871
2912
|
(0, import_log10.log)("starting...", {}, {
|
|
2872
2913
|
file: "iframe-host-runtime.ts",
|
|
2873
|
-
line:
|
|
2914
|
+
line: 67,
|
|
2874
2915
|
scope: this,
|
|
2875
2916
|
callSite: (f, a) => f(...a)
|
|
2876
2917
|
});
|
|
@@ -2888,21 +2929,30 @@ var IFrameHostRuntime = class {
|
|
|
2888
2929
|
transportFactory: this._transportFactory
|
|
2889
2930
|
})
|
|
2890
2931
|
});
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
SpaceInvitationsService: async () => await this._getService((services) => services.SpaceInvitationsService),
|
|
2901
|
-
SpacesService: async () => await this._getService((services) => services.SpacesService),
|
|
2902
|
-
SystemService: async () => await this._getService((services) => services.SystemService),
|
|
2903
|
-
TracingService: async () => await this._getService((services) => services.TracingService)
|
|
2932
|
+
const middleware = {
|
|
2933
|
+
handleCall: async (method, params, handler) => {
|
|
2934
|
+
const error = await this._ready.wait({
|
|
2935
|
+
timeout: 3e3
|
|
2936
|
+
});
|
|
2937
|
+
if (error) {
|
|
2938
|
+
throw error;
|
|
2939
|
+
}
|
|
2940
|
+
return handler(method, params);
|
|
2904
2941
|
},
|
|
2905
|
-
|
|
2942
|
+
handleStream: async (method, params, handler) => {
|
|
2943
|
+
const error = await this._ready.wait({
|
|
2944
|
+
timeout: 3e3
|
|
2945
|
+
});
|
|
2946
|
+
if (error) {
|
|
2947
|
+
throw error;
|
|
2948
|
+
}
|
|
2949
|
+
return handler(method, params);
|
|
2950
|
+
}
|
|
2951
|
+
};
|
|
2952
|
+
this._clientRpc = new ClientRpcServer({
|
|
2953
|
+
serviceRegistry: this._clientServices.host.serviceRegistry,
|
|
2954
|
+
port: this._appPort,
|
|
2955
|
+
...middleware
|
|
2906
2956
|
});
|
|
2907
2957
|
await Promise.all([
|
|
2908
2958
|
this._clientServices.open(),
|
|
@@ -2912,7 +2962,7 @@ var IFrameHostRuntime = class {
|
|
|
2912
2962
|
this._ready.wake(void 0);
|
|
2913
2963
|
(0, import_log10.log)("started", {}, {
|
|
2914
2964
|
file: "iframe-host-runtime.ts",
|
|
2915
|
-
line:
|
|
2965
|
+
line: 110,
|
|
2916
2966
|
scope: this,
|
|
2917
2967
|
callSite: (f, a) => f(...a)
|
|
2918
2968
|
});
|
|
@@ -2920,7 +2970,7 @@ var IFrameHostRuntime = class {
|
|
|
2920
2970
|
this._ready.wake(err);
|
|
2921
2971
|
import_log10.log.catch(err, {}, {
|
|
2922
2972
|
file: "iframe-host-runtime.ts",
|
|
2923
|
-
line:
|
|
2973
|
+
line: 113,
|
|
2924
2974
|
scope: this,
|
|
2925
2975
|
callSite: (f, a) => f(...a)
|
|
2926
2976
|
});
|
|
@@ -2930,7 +2980,7 @@ var IFrameHostRuntime = class {
|
|
|
2930
2980
|
var _a;
|
|
2931
2981
|
(0, import_log10.log)("stopping...", {}, {
|
|
2932
2982
|
file: "iframe-host-runtime.ts",
|
|
2933
|
-
line:
|
|
2983
|
+
line: 118,
|
|
2934
2984
|
scope: this,
|
|
2935
2985
|
callSite: (f, a) => f(...a)
|
|
2936
2986
|
});
|
|
@@ -2939,7 +2989,7 @@ var IFrameHostRuntime = class {
|
|
|
2939
2989
|
await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
|
|
2940
2990
|
(0, import_log10.log)("stopped", {}, {
|
|
2941
2991
|
file: "iframe-host-runtime.ts",
|
|
2942
|
-
line:
|
|
2992
|
+
line: 122,
|
|
2943
2993
|
scope: this,
|
|
2944
2994
|
callSite: (f, a) => f(...a)
|
|
2945
2995
|
});
|
|
@@ -2950,7 +3000,7 @@ __decorate3([
|
|
|
2950
3000
|
], IFrameHostRuntime.prototype, "origin", void 0);
|
|
2951
3001
|
|
|
2952
3002
|
// packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
|
|
2953
|
-
var
|
|
3003
|
+
var import_client4 = require("@dxos/client");
|
|
2954
3004
|
var import_network_manager4 = require("@dxos/network-manager");
|
|
2955
3005
|
var import_rpc3 = require("@dxos/rpc");
|
|
2956
3006
|
|
|
@@ -3044,7 +3094,7 @@ var import_network_manager5 = require("@dxos/network-manager");
|
|
|
3044
3094
|
// packages/sdk/client-services/src/packlets/vault/worker-session.ts
|
|
3045
3095
|
var import_node_assert11 = __toESM(require("node:assert"));
|
|
3046
3096
|
var import_async16 = require("@dxos/async");
|
|
3047
|
-
var
|
|
3097
|
+
var import_client5 = require("@dxos/client");
|
|
3048
3098
|
var import_log12 = require("@dxos/log");
|
|
3049
3099
|
var import_rpc4 = require("@dxos/rpc");
|
|
3050
3100
|
var import_util8 = require("@dxos/util");
|
|
@@ -3059,40 +3109,48 @@ var __decorate4 = function(decorators, target, key, desc) {
|
|
|
3059
3109
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3060
3110
|
};
|
|
3061
3111
|
var WorkerSession = class {
|
|
3062
|
-
constructor({
|
|
3112
|
+
constructor({ serviceHost, systemPort, appPort, shellPort, readySignal, options = {
|
|
3063
3113
|
heartbeatInterval: 1e3
|
|
3064
3114
|
} }) {
|
|
3065
3115
|
this._startTrigger = new import_async16.Trigger();
|
|
3066
3116
|
this.onClose = new import_util8.Callback();
|
|
3067
3117
|
(0, import_node_assert11.default)(options);
|
|
3068
|
-
(0, import_node_assert11.default)(
|
|
3118
|
+
(0, import_node_assert11.default)(serviceHost);
|
|
3069
3119
|
this._options = options;
|
|
3070
|
-
this.
|
|
3071
|
-
const
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3120
|
+
this._serviceHost = serviceHost;
|
|
3121
|
+
const middleware = {
|
|
3122
|
+
handleCall: async (method, params, handler) => {
|
|
3123
|
+
const error = await readySignal.wait({
|
|
3124
|
+
timeout: 3e3
|
|
3125
|
+
});
|
|
3126
|
+
if (error) {
|
|
3127
|
+
throw error;
|
|
3128
|
+
}
|
|
3129
|
+
return handler(method, params);
|
|
3130
|
+
},
|
|
3131
|
+
handleStream: async (method, params, handler) => {
|
|
3132
|
+
const error = await readySignal.wait({
|
|
3133
|
+
timeout: 3e3
|
|
3134
|
+
});
|
|
3135
|
+
if (error) {
|
|
3136
|
+
throw error;
|
|
3137
|
+
}
|
|
3138
|
+
return handler(method, params);
|
|
3139
|
+
}
|
|
3082
3140
|
};
|
|
3083
|
-
this._clientRpc =
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3141
|
+
this._clientRpc = new ClientRpcServer({
|
|
3142
|
+
serviceRegistry: this._serviceHost.serviceRegistry,
|
|
3143
|
+
port: appPort,
|
|
3144
|
+
...middleware
|
|
3087
3145
|
});
|
|
3088
|
-
this._shellClientRpc =
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3146
|
+
this._shellClientRpc = new ClientRpcServer({
|
|
3147
|
+
serviceRegistry: this._serviceHost.serviceRegistry,
|
|
3148
|
+
port: shellPort,
|
|
3149
|
+
...middleware
|
|
3092
3150
|
});
|
|
3093
3151
|
this._iframeRpc = (0, import_rpc4.createProtoRpcPeer)({
|
|
3094
|
-
requested:
|
|
3095
|
-
exposed:
|
|
3152
|
+
requested: import_client5.iframeServiceBundle,
|
|
3153
|
+
exposed: import_client5.workerServiceBundle,
|
|
3096
3154
|
handlers: {
|
|
3097
3155
|
WorkerService: {
|
|
3098
3156
|
start: async (request) => {
|
|
@@ -3106,7 +3164,7 @@ var WorkerSession = class {
|
|
|
3106
3164
|
} catch (err) {
|
|
3107
3165
|
import_log12.log.catch(err, {}, {
|
|
3108
3166
|
file: "worker-session.ts",
|
|
3109
|
-
line:
|
|
3167
|
+
line: 107,
|
|
3110
3168
|
scope: this,
|
|
3111
3169
|
callSite: (f, a) => f(...a)
|
|
3112
3170
|
});
|
|
@@ -3124,7 +3182,7 @@ var WorkerSession = class {
|
|
|
3124
3182
|
async open() {
|
|
3125
3183
|
import_log12.log.info("opening..", {}, {
|
|
3126
3184
|
file: "worker-session.ts",
|
|
3127
|
-
line:
|
|
3185
|
+
line: 121,
|
|
3128
3186
|
scope: this,
|
|
3129
3187
|
callSite: (f, a) => f(...a)
|
|
3130
3188
|
});
|
|
@@ -3144,7 +3202,7 @@ var WorkerSession = class {
|
|
|
3144
3202
|
err: err1
|
|
3145
3203
|
}, {
|
|
3146
3204
|
file: "worker-session.ts",
|
|
3147
|
-
line:
|
|
3205
|
+
line: 133,
|
|
3148
3206
|
scope: this,
|
|
3149
3207
|
callSite: (f, a) => f(...a)
|
|
3150
3208
|
});
|
|
@@ -3153,7 +3211,7 @@ var WorkerSession = class {
|
|
|
3153
3211
|
} catch (err) {
|
|
3154
3212
|
import_log12.log.catch(err, {}, {
|
|
3155
3213
|
file: "worker-session.ts",
|
|
3156
|
-
line:
|
|
3214
|
+
line: 137,
|
|
3157
3215
|
scope: this,
|
|
3158
3216
|
callSite: (f, a) => f(...a)
|
|
3159
3217
|
});
|
|
@@ -3164,7 +3222,7 @@ var WorkerSession = class {
|
|
|
3164
3222
|
async close() {
|
|
3165
3223
|
import_log12.log.info("closing..", {}, {
|
|
3166
3224
|
file: "worker-session.ts",
|
|
3167
|
-
line:
|
|
3225
|
+
line: 144,
|
|
3168
3226
|
scope: this,
|
|
3169
3227
|
callSite: (f, a) => f(...a)
|
|
3170
3228
|
});
|
|
@@ -3173,7 +3231,7 @@ var WorkerSession = class {
|
|
|
3173
3231
|
} catch (err) {
|
|
3174
3232
|
import_log12.log.catch(err, {}, {
|
|
3175
3233
|
file: "worker-session.ts",
|
|
3176
|
-
line:
|
|
3234
|
+
line: 148,
|
|
3177
3235
|
scope: this,
|
|
3178
3236
|
callSite: (f, a) => f(...a)
|
|
3179
3237
|
});
|
|
@@ -3192,7 +3250,7 @@ var WorkerSession = class {
|
|
|
3192
3250
|
} catch (e) {
|
|
3193
3251
|
import_log12.log.info("No shell connected.", {}, {
|
|
3194
3252
|
file: "worker-session.ts",
|
|
3195
|
-
line:
|
|
3253
|
+
line: 162,
|
|
3196
3254
|
scope: this,
|
|
3197
3255
|
callSite: (f, a) => f(...a)
|
|
3198
3256
|
});
|
|
@@ -3206,7 +3264,7 @@ __decorate4([
|
|
|
3206
3264
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
3207
3265
|
var import_async18 = require("@dxos/async");
|
|
3208
3266
|
var import_credentials12 = require("@dxos/credentials");
|
|
3209
|
-
var
|
|
3267
|
+
var import_debug6 = require("@dxos/debug");
|
|
3210
3268
|
var import_echo_pipeline4 = require("@dxos/echo-pipeline");
|
|
3211
3269
|
var import_feed_store4 = require("@dxos/feed-store");
|
|
3212
3270
|
var import_keyring = require("@dxos/keyring");
|
|
@@ -3240,7 +3298,7 @@ var ServiceContext = class {
|
|
|
3240
3298
|
networkManager: this.networkManager,
|
|
3241
3299
|
getIdentity: () => {
|
|
3242
3300
|
var _a;
|
|
3243
|
-
return (_a = this.identityManager.identity) != null ? _a : (0,
|
|
3301
|
+
return (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
|
|
3244
3302
|
},
|
|
3245
3303
|
acceptIdentity: this._acceptIdentity.bind(this),
|
|
3246
3304
|
keyring: this.keyring
|
|
@@ -3323,7 +3381,7 @@ var ServiceContext = class {
|
|
|
3323
3381
|
scope: this,
|
|
3324
3382
|
callSite: (f, a) => f(...a)
|
|
3325
3383
|
});
|
|
3326
|
-
const identity = (_a = this.identityManager.identity) != null ? _a : (0,
|
|
3384
|
+
const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
|
|
3327
3385
|
const signingContext = {
|
|
3328
3386
|
credentialSigner: identity.getIdentityCredentialSigner(),
|
|
3329
3387
|
identityKey: identity.identityKey,
|
|
@@ -3402,7 +3460,7 @@ var ServiceContext = class {
|
|
|
3402
3460
|
// packages/sdk/client-services/src/packlets/services/service-registry.ts
|
|
3403
3461
|
var ServiceRegistry = class {
|
|
3404
3462
|
// prettier-ignore
|
|
3405
|
-
constructor(_serviceBundle, _handlers) {
|
|
3463
|
+
constructor(_serviceBundle, _handlers = {}) {
|
|
3406
3464
|
this._serviceBundle = _serviceBundle;
|
|
3407
3465
|
this._handlers = _handlers;
|
|
3408
3466
|
}
|
|
@@ -3415,25 +3473,35 @@ var ServiceRegistry = class {
|
|
|
3415
3473
|
setServices(services) {
|
|
3416
3474
|
this._handlers = services;
|
|
3417
3475
|
}
|
|
3476
|
+
addService(name, service) {
|
|
3477
|
+
this._handlers[name] = service;
|
|
3478
|
+
}
|
|
3479
|
+
removeService(name) {
|
|
3480
|
+
delete this._handlers[name];
|
|
3481
|
+
}
|
|
3418
3482
|
};
|
|
3419
3483
|
|
|
3420
3484
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
3421
3485
|
var ClientServicesHost = class {
|
|
3422
3486
|
constructor({
|
|
3423
3487
|
config,
|
|
3424
|
-
modelFactory = (0,
|
|
3488
|
+
modelFactory = (0, import_client6.createDefaultModelFactory)(),
|
|
3425
3489
|
// TODO(burdon): Create ApolloLink abstraction (see Client).
|
|
3426
3490
|
networkManager,
|
|
3427
|
-
storage
|
|
3491
|
+
storage,
|
|
3428
3492
|
// TODO(wittjosiah): Turn this on by default.
|
|
3429
3493
|
lockKey
|
|
3430
|
-
}) {
|
|
3494
|
+
} = {}) {
|
|
3431
3495
|
this._statusUpdate = new import_async19.Event();
|
|
3432
3496
|
this._open = false;
|
|
3433
|
-
this._config = config;
|
|
3434
|
-
this._modelFactory = modelFactory;
|
|
3435
|
-
this._networkManager = networkManager;
|
|
3436
3497
|
this._storage = storage;
|
|
3498
|
+
this._modelFactory = modelFactory;
|
|
3499
|
+
if (config) {
|
|
3500
|
+
this.initialize({
|
|
3501
|
+
config,
|
|
3502
|
+
networkManager
|
|
3503
|
+
});
|
|
3504
|
+
}
|
|
3437
3505
|
this._resourceLock = lockKey ? new VaultResourceLock({
|
|
3438
3506
|
lockKey,
|
|
3439
3507
|
onAcquire: () => this.open(),
|
|
@@ -3456,27 +3524,52 @@ var ClientServicesHost = class {
|
|
|
3456
3524
|
await this._serviceContext.reset();
|
|
3457
3525
|
}
|
|
3458
3526
|
});
|
|
3459
|
-
this._serviceRegistry = new ServiceRegistry(
|
|
3527
|
+
this._serviceRegistry = new ServiceRegistry(import_client6.clientServiceBundle, {
|
|
3460
3528
|
SystemService: this._systemService
|
|
3461
3529
|
});
|
|
3462
3530
|
}
|
|
3463
3531
|
get isOpen() {
|
|
3464
3532
|
return this._open;
|
|
3465
3533
|
}
|
|
3534
|
+
get serviceRegistry() {
|
|
3535
|
+
return this._serviceRegistry;
|
|
3536
|
+
}
|
|
3466
3537
|
get descriptors() {
|
|
3467
3538
|
return this._serviceRegistry.descriptors;
|
|
3468
3539
|
}
|
|
3469
3540
|
get services() {
|
|
3470
3541
|
return this._serviceRegistry.services;
|
|
3471
3542
|
}
|
|
3543
|
+
/**
|
|
3544
|
+
* Initialize the service host with the config.
|
|
3545
|
+
* Config can also be provided in the constructor.
|
|
3546
|
+
* Can only be called once.
|
|
3547
|
+
*/
|
|
3548
|
+
initialize({ config, networkManager }) {
|
|
3549
|
+
(0, import_node_assert12.default)(!this._open, "service host is open");
|
|
3550
|
+
if (config) {
|
|
3551
|
+
(0, import_node_assert12.default)(!this._config, "config already set");
|
|
3552
|
+
this._config = config;
|
|
3553
|
+
if (!this._storage) {
|
|
3554
|
+
this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
if (networkManager) {
|
|
3558
|
+
(0, import_node_assert12.default)(!this._networkManager, "network manager already set");
|
|
3559
|
+
this._networkManager = networkManager;
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3472
3562
|
async open() {
|
|
3473
3563
|
var _a, _b;
|
|
3474
3564
|
if (this._open) {
|
|
3475
3565
|
return;
|
|
3476
3566
|
}
|
|
3567
|
+
(0, import_node_assert12.default)(this._config, "config not set");
|
|
3568
|
+
(0, import_node_assert12.default)(this._storage, "storage not set");
|
|
3569
|
+
(0, import_node_assert12.default)(this._networkManager, "network manager not set");
|
|
3477
3570
|
(0, import_log15.log)("opening...", {}, {
|
|
3478
3571
|
file: "service-host.ts",
|
|
3479
|
-
line:
|
|
3572
|
+
line: 166,
|
|
3480
3573
|
scope: this,
|
|
3481
3574
|
callSite: (f, a) => f(...a)
|
|
3482
3575
|
});
|
|
@@ -3489,10 +3582,10 @@ var ClientServicesHost = class {
|
|
|
3489
3582
|
DeviceInvitationsService: new DeviceInvitationsServiceImpl(this._serviceContext.identityManager, this._serviceContext.deviceInvitations),
|
|
3490
3583
|
SpaceInvitationsService: new SpaceInvitationsServiceImpl(this._serviceContext.identityManager, () => {
|
|
3491
3584
|
var _a2;
|
|
3492
|
-
return (_a2 = this._serviceContext.spaceInvitations) != null ? _a2 : (0,
|
|
3585
|
+
return (_a2 = this._serviceContext.spaceInvitations) != null ? _a2 : (0, import_debug7.raise)(new Error("SpaceInvitations not initialized"));
|
|
3493
3586
|
}, () => {
|
|
3494
3587
|
var _a2;
|
|
3495
|
-
return (_a2 = this._serviceContext.dataSpaceManager) != null ? _a2 : (0,
|
|
3588
|
+
return (_a2 = this._serviceContext.dataSpaceManager) != null ? _a2 : (0, import_debug7.raise)(new Error("SpaceManager not initialized"));
|
|
3496
3589
|
}),
|
|
3497
3590
|
SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
|
|
3498
3591
|
await this._serviceContext.initialized.wait();
|
|
@@ -3516,7 +3609,7 @@ var ClientServicesHost = class {
|
|
|
3516
3609
|
deviceKey
|
|
3517
3610
|
}, {
|
|
3518
3611
|
file: "service-host.ts",
|
|
3519
|
-
line:
|
|
3612
|
+
line: 219,
|
|
3520
3613
|
scope: this,
|
|
3521
3614
|
callSite: (f, a) => f(...a)
|
|
3522
3615
|
});
|
|
@@ -3531,7 +3624,7 @@ var ClientServicesHost = class {
|
|
|
3531
3624
|
deviceKey
|
|
3532
3625
|
}, {
|
|
3533
3626
|
file: "service-host.ts",
|
|
3534
|
-
line:
|
|
3627
|
+
line: 228,
|
|
3535
3628
|
scope: this,
|
|
3536
3629
|
callSite: (f, a) => f(...a)
|
|
3537
3630
|
});
|
|
@@ -3545,7 +3638,7 @@ var ClientServicesHost = class {
|
|
|
3545
3638
|
deviceKey
|
|
3546
3639
|
}, {
|
|
3547
3640
|
file: "service-host.ts",
|
|
3548
|
-
line:
|
|
3641
|
+
line: 233,
|
|
3549
3642
|
scope: this,
|
|
3550
3643
|
callSite: (f, a) => f(...a)
|
|
3551
3644
|
});
|
|
@@ -3563,6 +3656,9 @@ var LocalClientServices = class {
|
|
|
3563
3656
|
get services() {
|
|
3564
3657
|
return this._host.services;
|
|
3565
3658
|
}
|
|
3659
|
+
get host() {
|
|
3660
|
+
return this._host;
|
|
3661
|
+
}
|
|
3566
3662
|
async open() {
|
|
3567
3663
|
await this._host.open();
|
|
3568
3664
|
}
|
|
@@ -3595,7 +3691,7 @@ var createServiceContext = ({ signalContext = new import_messaging4.MemorySignal
|
|
|
3595
3691
|
signalManager: new import_messaging4.MemorySignalManager(signalContext),
|
|
3596
3692
|
transportFactory: import_network_manager7.MemoryTransportFactory
|
|
3597
3693
|
});
|
|
3598
|
-
const modelFactory = (0,
|
|
3694
|
+
const modelFactory = (0, import_client7.createDefaultModelFactory)();
|
|
3599
3695
|
return new ServiceContext(storage, networkManager, modelFactory);
|
|
3600
3696
|
};
|
|
3601
3697
|
var createPeers = async (numPeers) => {
|
|
@@ -3692,7 +3788,7 @@ var createSigningContext = async (keyring) => {
|
|
|
3692
3788
|
// packages/sdk/client-services/src/packlets/testing/invitation-utils.ts
|
|
3693
3789
|
var import_node_assert13 = __toESM(require("node:assert"));
|
|
3694
3790
|
var import_async20 = require("@dxos/async");
|
|
3695
|
-
var
|
|
3791
|
+
var import_debug8 = require("@dxos/debug");
|
|
3696
3792
|
var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
|
|
3697
3793
|
var performInvitation = async (host, guest, context) => {
|
|
3698
3794
|
const done1 = new import_async20.Trigger();
|
|
@@ -3714,19 +3810,19 @@ var performInvitation = async (host, guest, context) => {
|
|
|
3714
3810
|
onSuccess: (invitation) => {
|
|
3715
3811
|
done2.wake(invitation);
|
|
3716
3812
|
},
|
|
3717
|
-
onCancelled: () => (0,
|
|
3718
|
-
onTimeout: (err) => (0,
|
|
3719
|
-
onError: (err) => (0,
|
|
3813
|
+
onCancelled: () => (0, import_debug8.raise)(new Error()),
|
|
3814
|
+
onTimeout: (err) => (0, import_debug8.raise)(err),
|
|
3815
|
+
onError: (err) => (0, import_debug8.raise)(err)
|
|
3720
3816
|
});
|
|
3721
3817
|
},
|
|
3722
3818
|
onConnected: async (invitation1) => {
|
|
3723
3819
|
},
|
|
3724
|
-
onCancelled: () => (0,
|
|
3820
|
+
onCancelled: () => (0, import_debug8.raise)(new Error("cancelled")),
|
|
3725
3821
|
onSuccess: (invitation) => {
|
|
3726
3822
|
done1.wake(invitation);
|
|
3727
3823
|
},
|
|
3728
|
-
onTimeout: (err) => (0,
|
|
3729
|
-
onError: (err) => (0,
|
|
3824
|
+
onTimeout: (err) => (0, import_debug8.raise)(err),
|
|
3825
|
+
onError: (err) => (0, import_debug8.raise)(err)
|
|
3730
3826
|
});
|
|
3731
3827
|
await done1.wait();
|
|
3732
3828
|
await done2.wait();
|
|
@@ -3735,7 +3831,7 @@ var performInvitation = async (host, guest, context) => {
|
|
|
3735
3831
|
// packages/sdk/client-services/src/packlets/testing/test-builder.ts
|
|
3736
3832
|
var import_node_assert14 = __toESM(require("node:assert"));
|
|
3737
3833
|
var import_async21 = require("@dxos/async");
|
|
3738
|
-
var
|
|
3834
|
+
var import_client8 = require("@dxos/client");
|
|
3739
3835
|
var import_config3 = require("@dxos/config");
|
|
3740
3836
|
var import_document_model = require("@dxos/document-model");
|
|
3741
3837
|
var import_echo_db = require("@dxos/echo-db");
|
|
@@ -3756,7 +3852,7 @@ var testConfigWithLocalSignal = new import_config3.Config({
|
|
|
3756
3852
|
});
|
|
3757
3853
|
var TestBuilder = class {
|
|
3758
3854
|
// prettier-ignore
|
|
3759
|
-
constructor(config, _modelFactory = (0,
|
|
3855
|
+
constructor(config, _modelFactory = (0, import_client8.createDefaultModelFactory)(), _signalManagerContext = new import_messaging5.MemorySignalManagerContext()) {
|
|
3760
3856
|
this._modelFactory = _modelFactory;
|
|
3761
3857
|
this._signalManagerContext = _signalManagerContext;
|
|
3762
3858
|
this._config = config != null ? config : new import_config3.Config();
|
|
@@ -3818,8 +3914,8 @@ var TestBuilder = class {
|
|
|
3818
3914
|
handlers: host.services,
|
|
3819
3915
|
port: hostPort
|
|
3820
3916
|
});
|
|
3821
|
-
const client = new
|
|
3822
|
-
services: new
|
|
3917
|
+
const client = new import_client8.Client({
|
|
3918
|
+
services: new import_client8.ClientServicesProxy(proxyPort)
|
|
3823
3919
|
});
|
|
3824
3920
|
return [
|
|
3825
3921
|
client,
|