@super-line/server 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +49 -11
- package/dist/index.js +49 -10
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -16276,7 +16276,6 @@ __export(index_exports, {
|
|
|
16276
16276
|
resolvePrincipal: () => resolvePrincipal
|
|
16277
16277
|
});
|
|
16278
16278
|
module.exports = __toCommonJS(index_exports);
|
|
16279
|
-
var import_node_crypto = require("crypto");
|
|
16280
16279
|
var import_core2 = require("@super-line/core");
|
|
16281
16280
|
|
|
16282
16281
|
// src/conn.ts
|
|
@@ -16448,12 +16447,17 @@ function createInMemoryAdapter(bus = new MemoryBus()) {
|
|
|
16448
16447
|
}
|
|
16449
16448
|
|
|
16450
16449
|
// src/index.ts
|
|
16450
|
+
var randomUUID = () => globalThis.crypto.randomUUID();
|
|
16451
16451
|
var ROOM = "r:";
|
|
16452
16452
|
var TOPIC = "t:";
|
|
16453
16453
|
var CONN = "c:";
|
|
16454
16454
|
var USER = "u:";
|
|
16455
16455
|
var REPLY = "reply:";
|
|
16456
16456
|
var INSPECT = "i:";
|
|
16457
|
+
var inspectorEncoder = new TextEncoder();
|
|
16458
|
+
function encodedByteSize(encoded) {
|
|
16459
|
+
return typeof encoded === "string" ? inspectorEncoder.encode(encoded).length : encoded.byteLength;
|
|
16460
|
+
}
|
|
16457
16461
|
var STORE = "s:";
|
|
16458
16462
|
var SERVER_ORIGIN = "server";
|
|
16459
16463
|
function createSuperLineServer(contract, opts) {
|
|
@@ -16469,8 +16473,9 @@ function createSuperLineServer(contract, opts) {
|
|
|
16469
16473
|
const inspectorConns = /* @__PURE__ */ new Set();
|
|
16470
16474
|
const members = /* @__PURE__ */ new Map();
|
|
16471
16475
|
const busListeners = /* @__PURE__ */ new Map();
|
|
16472
|
-
const instanceId =
|
|
16473
|
-
const
|
|
16476
|
+
const instanceId = randomUUID();
|
|
16477
|
+
const envNodeName = typeof process !== "undefined" ? process.env.SUPER_LINE_NODE_NAME : void 0;
|
|
16478
|
+
const nodeName = opts.nodeName ?? envNodeName ?? instanceId.slice(0, 8);
|
|
16474
16479
|
const replyChannel = REPLY + instanceId;
|
|
16475
16480
|
let impl = {};
|
|
16476
16481
|
let closing = false;
|
|
@@ -16572,12 +16577,13 @@ function createSuperLineServer(contract, opts) {
|
|
|
16572
16577
|
}
|
|
16573
16578
|
if (inspectorEnabled)
|
|
16574
16579
|
emitInspectorEvent(
|
|
16575
|
-
env.ok ? { type: "msg.serverReply", target: conn.id, name: r.name, ok: true, output: safeSnapshot(env.d) } : {
|
|
16580
|
+
env.ok ? { type: "msg.serverReply", target: conn.id, name: r.name, ok: true, output: safeSnapshot(env.d), reqId: r.corrId } : {
|
|
16576
16581
|
type: "msg.serverReply",
|
|
16577
16582
|
target: conn.id,
|
|
16578
16583
|
name: r.name,
|
|
16579
16584
|
ok: false,
|
|
16580
|
-
error: { code: env.code, message: env.m }
|
|
16585
|
+
error: { code: env.code, message: env.m },
|
|
16586
|
+
reqId: r.corrId
|
|
16581
16587
|
}
|
|
16582
16588
|
);
|
|
16583
16589
|
void adapter.publish(REPLY + r.origin, serializer.encode(env));
|
|
@@ -16602,7 +16608,14 @@ function createSuperLineServer(contract, opts) {
|
|
|
16602
16608
|
}
|
|
16603
16609
|
function emitInspectorEvent(event) {
|
|
16604
16610
|
if (!inspectorEnabled) return;
|
|
16605
|
-
|
|
16611
|
+
const payload = (0, import_core2.eventPayload)(event);
|
|
16612
|
+
const envelope = {
|
|
16613
|
+
event,
|
|
16614
|
+
ts: Date.now(),
|
|
16615
|
+
originNodeId: instanceId,
|
|
16616
|
+
byteSize: payload === void 0 ? void 0 : encodedByteSize(serializer.encode(payload))
|
|
16617
|
+
};
|
|
16618
|
+
void adapter.publish(INSPECT + "events", serializer.encode({ t: "pub", c: "events", d: envelope }));
|
|
16606
16619
|
}
|
|
16607
16620
|
function joinChannel(conn, channel) {
|
|
16608
16621
|
conn.channels.add(channel);
|
|
@@ -16761,6 +16774,26 @@ function createSuperLineServer(contract, opts) {
|
|
|
16761
16774
|
const remote = await presenceOrThrow().get(id);
|
|
16762
16775
|
if (!remote) throw new import_core2.SuperLineError("NOT_FOUND", `Unknown connection: ${id}`);
|
|
16763
16776
|
return { descriptor: remote, ctxAvailable: false };
|
|
16777
|
+
},
|
|
16778
|
+
listStores: async () => Object.entries(storeMap).map(([name, store]) => ({ name, model: store.model })),
|
|
16779
|
+
listResources: async (input) => {
|
|
16780
|
+
const store = storeMap[input.store];
|
|
16781
|
+
if (!store) throw new import_core2.SuperLineError("NOT_FOUND", `Unknown store: ${input.store}`);
|
|
16782
|
+
return store.list();
|
|
16783
|
+
},
|
|
16784
|
+
readResource: async (input) => {
|
|
16785
|
+
const { store: name, id } = input;
|
|
16786
|
+
const store = storeMap[name];
|
|
16787
|
+
if (!store) throw new import_core2.SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
|
|
16788
|
+
const resource = await store.read(id);
|
|
16789
|
+
if (!resource) throw new import_core2.SuperLineError("NOT_FOUND", `No resource: ${name}/${id}`);
|
|
16790
|
+
let data = resource.data;
|
|
16791
|
+
if (store.open) {
|
|
16792
|
+
const replica = store.open(id);
|
|
16793
|
+
data = replica.getSnapshot();
|
|
16794
|
+
replica.close();
|
|
16795
|
+
}
|
|
16796
|
+
return { data: safeSnapshot(data), accessRules: resource.accessRules };
|
|
16764
16797
|
}
|
|
16765
16798
|
};
|
|
16766
16799
|
const authHook = async (handshake) => {
|
|
@@ -16775,7 +16808,7 @@ function createSuperLineServer(contract, opts) {
|
|
|
16775
16808
|
raw.close();
|
|
16776
16809
|
return;
|
|
16777
16810
|
}
|
|
16778
|
-
const connId =
|
|
16811
|
+
const connId = randomUUID();
|
|
16779
16812
|
const conn = new Conn(
|
|
16780
16813
|
raw,
|
|
16781
16814
|
connId,
|
|
@@ -16880,7 +16913,8 @@ function createSuperLineServer(contract, opts) {
|
|
|
16880
16913
|
connId: conn.id,
|
|
16881
16914
|
name: info.name,
|
|
16882
16915
|
ok: false,
|
|
16883
|
-
error: { code: e.code, message: e.message }
|
|
16916
|
+
error: { code: e.code, message: e.message },
|
|
16917
|
+
reqId: id
|
|
16884
16918
|
});
|
|
16885
16919
|
}
|
|
16886
16920
|
}
|
|
@@ -16899,7 +16933,8 @@ function createSuperLineServer(contract, opts) {
|
|
|
16899
16933
|
connId: conn.id,
|
|
16900
16934
|
role: conn.role,
|
|
16901
16935
|
name: frame.m,
|
|
16902
|
-
input: safeSnapshot(input)
|
|
16936
|
+
input: safeSnapshot(input),
|
|
16937
|
+
reqId: frame.i
|
|
16903
16938
|
});
|
|
16904
16939
|
const output = await handler(input, conn.ctx, conn);
|
|
16905
16940
|
if (inspectorEnabled)
|
|
@@ -16908,7 +16943,8 @@ function createSuperLineServer(contract, opts) {
|
|
|
16908
16943
|
connId: conn.id,
|
|
16909
16944
|
name: frame.m,
|
|
16910
16945
|
ok: true,
|
|
16911
|
-
output: safeSnapshot(output)
|
|
16946
|
+
output: safeSnapshot(output),
|
|
16947
|
+
reqId: frame.i
|
|
16912
16948
|
});
|
|
16913
16949
|
conn.send({ t: "res", i: frame.i, d: output });
|
|
16914
16950
|
});
|
|
@@ -17121,7 +17157,7 @@ function createSuperLineServer(contract, opts) {
|
|
|
17121
17157
|
{ once: true }
|
|
17122
17158
|
);
|
|
17123
17159
|
if (inspectorEnabled)
|
|
17124
|
-
emitInspectorEvent({ type: "msg.serverRequest", target: id, name, input: safeSnapshot(input) });
|
|
17160
|
+
emitInspectorEvent({ type: "msg.serverRequest", target: id, name, input: safeSnapshot(input), reqId });
|
|
17125
17161
|
const env = { p: "req", o: instanceId, i: reqId, m: name, d: input };
|
|
17126
17162
|
void adapter.publish(CONN + id, serializer.encode(env));
|
|
17127
17163
|
});
|
|
@@ -17136,6 +17172,7 @@ function createSuperLineServer(contract, opts) {
|
|
|
17136
17172
|
storeApi[name] = {
|
|
17137
17173
|
async create(id, data, accessRules) {
|
|
17138
17174
|
await store.create(id, data, accessRules);
|
|
17175
|
+
if (inspectorEnabled) emitInspectorEvent({ type: "store.create", store: name, id });
|
|
17139
17176
|
},
|
|
17140
17177
|
read(id) {
|
|
17141
17178
|
return Promise.resolve(store.read(id));
|
|
@@ -17159,6 +17196,7 @@ function createSuperLineServer(contract, opts) {
|
|
|
17159
17196
|
},
|
|
17160
17197
|
async delete(id) {
|
|
17161
17198
|
await store.delete(id);
|
|
17199
|
+
if (inspectorEnabled) emitInspectorEvent({ type: "store.delete", store: name, id });
|
|
17162
17200
|
},
|
|
17163
17201
|
list() {
|
|
17164
17202
|
return Promise.resolve(store.list());
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "./chunk-MLKGABMK.js";
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { randomUUID } from "crypto";
|
|
5
4
|
import {
|
|
6
5
|
jsonSerializer,
|
|
7
6
|
validate,
|
|
8
7
|
SuperLineError,
|
|
9
8
|
INSPECTOR_ROLE,
|
|
10
|
-
classifyContract
|
|
9
|
+
classifyContract,
|
|
10
|
+
eventPayload
|
|
11
11
|
} from "@super-line/core";
|
|
12
12
|
|
|
13
13
|
// src/conn.ts
|
|
@@ -179,12 +179,17 @@ function createInMemoryAdapter(bus = new MemoryBus()) {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
// src/index.ts
|
|
182
|
+
var randomUUID = () => globalThis.crypto.randomUUID();
|
|
182
183
|
var ROOM = "r:";
|
|
183
184
|
var TOPIC = "t:";
|
|
184
185
|
var CONN = "c:";
|
|
185
186
|
var USER = "u:";
|
|
186
187
|
var REPLY = "reply:";
|
|
187
188
|
var INSPECT = "i:";
|
|
189
|
+
var inspectorEncoder = new TextEncoder();
|
|
190
|
+
function encodedByteSize(encoded) {
|
|
191
|
+
return typeof encoded === "string" ? inspectorEncoder.encode(encoded).length : encoded.byteLength;
|
|
192
|
+
}
|
|
188
193
|
var STORE = "s:";
|
|
189
194
|
var SERVER_ORIGIN = "server";
|
|
190
195
|
function createSuperLineServer(contract, opts) {
|
|
@@ -201,7 +206,8 @@ function createSuperLineServer(contract, opts) {
|
|
|
201
206
|
const members = /* @__PURE__ */ new Map();
|
|
202
207
|
const busListeners = /* @__PURE__ */ new Map();
|
|
203
208
|
const instanceId = randomUUID();
|
|
204
|
-
const
|
|
209
|
+
const envNodeName = typeof process !== "undefined" ? process.env.SUPER_LINE_NODE_NAME : void 0;
|
|
210
|
+
const nodeName = opts.nodeName ?? envNodeName ?? instanceId.slice(0, 8);
|
|
205
211
|
const replyChannel = REPLY + instanceId;
|
|
206
212
|
let impl = {};
|
|
207
213
|
let closing = false;
|
|
@@ -303,12 +309,13 @@ function createSuperLineServer(contract, opts) {
|
|
|
303
309
|
}
|
|
304
310
|
if (inspectorEnabled)
|
|
305
311
|
emitInspectorEvent(
|
|
306
|
-
env.ok ? { type: "msg.serverReply", target: conn.id, name: r.name, ok: true, output: safeSnapshot(env.d) } : {
|
|
312
|
+
env.ok ? { type: "msg.serverReply", target: conn.id, name: r.name, ok: true, output: safeSnapshot(env.d), reqId: r.corrId } : {
|
|
307
313
|
type: "msg.serverReply",
|
|
308
314
|
target: conn.id,
|
|
309
315
|
name: r.name,
|
|
310
316
|
ok: false,
|
|
311
|
-
error: { code: env.code, message: env.m }
|
|
317
|
+
error: { code: env.code, message: env.m },
|
|
318
|
+
reqId: r.corrId
|
|
312
319
|
}
|
|
313
320
|
);
|
|
314
321
|
void adapter.publish(REPLY + r.origin, serializer.encode(env));
|
|
@@ -333,7 +340,14 @@ function createSuperLineServer(contract, opts) {
|
|
|
333
340
|
}
|
|
334
341
|
function emitInspectorEvent(event) {
|
|
335
342
|
if (!inspectorEnabled) return;
|
|
336
|
-
|
|
343
|
+
const payload = eventPayload(event);
|
|
344
|
+
const envelope = {
|
|
345
|
+
event,
|
|
346
|
+
ts: Date.now(),
|
|
347
|
+
originNodeId: instanceId,
|
|
348
|
+
byteSize: payload === void 0 ? void 0 : encodedByteSize(serializer.encode(payload))
|
|
349
|
+
};
|
|
350
|
+
void adapter.publish(INSPECT + "events", serializer.encode({ t: "pub", c: "events", d: envelope }));
|
|
337
351
|
}
|
|
338
352
|
function joinChannel(conn, channel) {
|
|
339
353
|
conn.channels.add(channel);
|
|
@@ -492,6 +506,26 @@ function createSuperLineServer(contract, opts) {
|
|
|
492
506
|
const remote = await presenceOrThrow().get(id);
|
|
493
507
|
if (!remote) throw new SuperLineError("NOT_FOUND", `Unknown connection: ${id}`);
|
|
494
508
|
return { descriptor: remote, ctxAvailable: false };
|
|
509
|
+
},
|
|
510
|
+
listStores: async () => Object.entries(storeMap).map(([name, store]) => ({ name, model: store.model })),
|
|
511
|
+
listResources: async (input) => {
|
|
512
|
+
const store = storeMap[input.store];
|
|
513
|
+
if (!store) throw new SuperLineError("NOT_FOUND", `Unknown store: ${input.store}`);
|
|
514
|
+
return store.list();
|
|
515
|
+
},
|
|
516
|
+
readResource: async (input) => {
|
|
517
|
+
const { store: name, id } = input;
|
|
518
|
+
const store = storeMap[name];
|
|
519
|
+
if (!store) throw new SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
|
|
520
|
+
const resource = await store.read(id);
|
|
521
|
+
if (!resource) throw new SuperLineError("NOT_FOUND", `No resource: ${name}/${id}`);
|
|
522
|
+
let data = resource.data;
|
|
523
|
+
if (store.open) {
|
|
524
|
+
const replica = store.open(id);
|
|
525
|
+
data = replica.getSnapshot();
|
|
526
|
+
replica.close();
|
|
527
|
+
}
|
|
528
|
+
return { data: safeSnapshot(data), accessRules: resource.accessRules };
|
|
495
529
|
}
|
|
496
530
|
};
|
|
497
531
|
const authHook = async (handshake) => {
|
|
@@ -611,7 +645,8 @@ function createSuperLineServer(contract, opts) {
|
|
|
611
645
|
connId: conn.id,
|
|
612
646
|
name: info.name,
|
|
613
647
|
ok: false,
|
|
614
|
-
error: { code: e.code, message: e.message }
|
|
648
|
+
error: { code: e.code, message: e.message },
|
|
649
|
+
reqId: id
|
|
615
650
|
});
|
|
616
651
|
}
|
|
617
652
|
}
|
|
@@ -630,7 +665,8 @@ function createSuperLineServer(contract, opts) {
|
|
|
630
665
|
connId: conn.id,
|
|
631
666
|
role: conn.role,
|
|
632
667
|
name: frame.m,
|
|
633
|
-
input: safeSnapshot(input)
|
|
668
|
+
input: safeSnapshot(input),
|
|
669
|
+
reqId: frame.i
|
|
634
670
|
});
|
|
635
671
|
const output = await handler(input, conn.ctx, conn);
|
|
636
672
|
if (inspectorEnabled)
|
|
@@ -639,7 +675,8 @@ function createSuperLineServer(contract, opts) {
|
|
|
639
675
|
connId: conn.id,
|
|
640
676
|
name: frame.m,
|
|
641
677
|
ok: true,
|
|
642
|
-
output: safeSnapshot(output)
|
|
678
|
+
output: safeSnapshot(output),
|
|
679
|
+
reqId: frame.i
|
|
643
680
|
});
|
|
644
681
|
conn.send({ t: "res", i: frame.i, d: output });
|
|
645
682
|
});
|
|
@@ -852,7 +889,7 @@ function createSuperLineServer(contract, opts) {
|
|
|
852
889
|
{ once: true }
|
|
853
890
|
);
|
|
854
891
|
if (inspectorEnabled)
|
|
855
|
-
emitInspectorEvent({ type: "msg.serverRequest", target: id, name, input: safeSnapshot(input) });
|
|
892
|
+
emitInspectorEvent({ type: "msg.serverRequest", target: id, name, input: safeSnapshot(input), reqId });
|
|
856
893
|
const env = { p: "req", o: instanceId, i: reqId, m: name, d: input };
|
|
857
894
|
void adapter.publish(CONN + id, serializer.encode(env));
|
|
858
895
|
});
|
|
@@ -867,6 +904,7 @@ function createSuperLineServer(contract, opts) {
|
|
|
867
904
|
storeApi[name] = {
|
|
868
905
|
async create(id, data, accessRules) {
|
|
869
906
|
await store.create(id, data, accessRules);
|
|
907
|
+
if (inspectorEnabled) emitInspectorEvent({ type: "store.create", store: name, id });
|
|
870
908
|
},
|
|
871
909
|
read(id) {
|
|
872
910
|
return Promise.resolve(store.read(id));
|
|
@@ -890,6 +928,7 @@ function createSuperLineServer(contract, opts) {
|
|
|
890
928
|
},
|
|
891
929
|
async delete(id) {
|
|
892
930
|
await store.delete(id);
|
|
931
|
+
if (inspectorEnabled) emitInspectorEvent({ type: "store.delete", store: name, id });
|
|
893
932
|
},
|
|
894
933
|
list() {
|
|
895
934
|
return Promise.resolve(store.list());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-line/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Typesafe WebSocket server for super-line — rooms, topics, middleware, pluggable adapters.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@super-line/core": "^0.
|
|
50
|
+
"@super-line/core": "^0.7.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@chainsafe/libp2p-noise": "^17.0.0",
|
|
@@ -68,14 +68,14 @@
|
|
|
68
68
|
"zeromq": "^6.0.0",
|
|
69
69
|
"zod": "^3.24.1",
|
|
70
70
|
"zod-to-json-schema": "^3.25.2",
|
|
71
|
-
"@super-line/adapter-zeromq": "0.5.0",
|
|
72
|
-
"@super-line/client": "0.6.0",
|
|
73
|
-
"@super-line/adapter-rabbitmq": "0.5.0",
|
|
74
71
|
"@super-line/adapter-libp2p": "0.5.0",
|
|
72
|
+
"@super-line/adapter-redis": "0.5.0",
|
|
73
|
+
"@super-line/adapter-rabbitmq": "0.5.0",
|
|
75
74
|
"@super-line/transport-websocket": "0.5.0",
|
|
76
|
-
"@super-line/transport-http": "0.5.0",
|
|
77
75
|
"@super-line/transport-loopback": "0.5.0",
|
|
78
|
-
"@super-line/
|
|
76
|
+
"@super-line/client": "0.6.0",
|
|
77
|
+
"@super-line/transport-http": "0.5.0",
|
|
78
|
+
"@super-line/adapter-zeromq": "0.5.0"
|
|
79
79
|
},
|
|
80
80
|
"optionalDependencies": {
|
|
81
81
|
"@standard-community/standard-json": "^0.3.5"
|