@super-line/server 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +45 -0
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +45 -0
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -16761,6 +16761,26 @@ function createSuperLineServer(contract, opts) {
|
|
|
16761
16761
|
const remote = await presenceOrThrow().get(id);
|
|
16762
16762
|
if (!remote) throw new import_core2.SuperLineError("NOT_FOUND", `Unknown connection: ${id}`);
|
|
16763
16763
|
return { descriptor: remote, ctxAvailable: false };
|
|
16764
|
+
},
|
|
16765
|
+
listStores: async () => Object.entries(storeMap).map(([name, store]) => ({ name, model: store.model })),
|
|
16766
|
+
listResources: async (input) => {
|
|
16767
|
+
const store = storeMap[input.store];
|
|
16768
|
+
if (!store) throw new import_core2.SuperLineError("NOT_FOUND", `Unknown store: ${input.store}`);
|
|
16769
|
+
return store.list();
|
|
16770
|
+
},
|
|
16771
|
+
readResource: async (input) => {
|
|
16772
|
+
const { store: name, id } = input;
|
|
16773
|
+
const store = storeMap[name];
|
|
16774
|
+
if (!store) throw new import_core2.SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
|
|
16775
|
+
const resource = await store.read(id);
|
|
16776
|
+
if (!resource) throw new import_core2.SuperLineError("NOT_FOUND", `No resource: ${name}/${id}`);
|
|
16777
|
+
let data = resource.data;
|
|
16778
|
+
if (store.open) {
|
|
16779
|
+
const replica = store.open(id);
|
|
16780
|
+
data = replica.getSnapshot();
|
|
16781
|
+
replica.close();
|
|
16782
|
+
}
|
|
16783
|
+
return { data: safeSnapshot(data), accessRules: resource.accessRules };
|
|
16764
16784
|
}
|
|
16765
16785
|
};
|
|
16766
16786
|
const authHook = async (handshake) => {
|
|
@@ -17136,6 +17156,7 @@ function createSuperLineServer(contract, opts) {
|
|
|
17136
17156
|
storeApi[name] = {
|
|
17137
17157
|
async create(id, data, accessRules) {
|
|
17138
17158
|
await store.create(id, data, accessRules);
|
|
17159
|
+
if (inspectorEnabled) emitInspectorEvent({ type: "store.create", store: name, id });
|
|
17139
17160
|
},
|
|
17140
17161
|
read(id) {
|
|
17141
17162
|
return Promise.resolve(store.read(id));
|
|
@@ -17159,9 +17180,33 @@ function createSuperLineServer(contract, opts) {
|
|
|
17159
17180
|
},
|
|
17160
17181
|
async delete(id) {
|
|
17161
17182
|
await store.delete(id);
|
|
17183
|
+
if (inspectorEnabled) emitInspectorEvent({ type: "store.delete", store: name, id });
|
|
17162
17184
|
},
|
|
17163
17185
|
list() {
|
|
17164
17186
|
return Promise.resolve(store.list());
|
|
17187
|
+
},
|
|
17188
|
+
open(id, openOpts) {
|
|
17189
|
+
if (!store.open)
|
|
17190
|
+
throw new import_core2.SuperLineError("UNSUPPORTED", `Store ${name} does not support reactive open()`);
|
|
17191
|
+
const replica = store.open(id, openOpts);
|
|
17192
|
+
if (!inspectorEnabled) return replica;
|
|
17193
|
+
const origin = openOpts?.origin ?? SERVER_ORIGIN;
|
|
17194
|
+
const emit = (data) => emitInspectorEvent({ type: "store.write", store: name, id, origin, data: safeSnapshot(data) });
|
|
17195
|
+
return {
|
|
17196
|
+
...replica,
|
|
17197
|
+
set: (d) => {
|
|
17198
|
+
replica.set(d);
|
|
17199
|
+
emit(d);
|
|
17200
|
+
},
|
|
17201
|
+
update: (p) => {
|
|
17202
|
+
replica.update(p);
|
|
17203
|
+
emit(p);
|
|
17204
|
+
},
|
|
17205
|
+
delete: (path) => {
|
|
17206
|
+
replica.delete(path);
|
|
17207
|
+
emit({ delete: path });
|
|
17208
|
+
}
|
|
17209
|
+
};
|
|
17165
17210
|
}
|
|
17166
17211
|
};
|
|
17167
17212
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServerMessageDef, RawConn, Serializer, ServerFrame, EmitData, ConnDescriptor, Adapter, PresenceStore, Contract, RoleOf, NodeStat, SharedEvents, SharedServerRequests, ClientInput, Output, SharedRequests, ServerInput, AnyData, RoleRequests, Events, DataOf, RoleTopics, AccessRules, Resource, Perms, SharedTopics, EventData, ServerTransport, Handshake, ServerStore } from '@super-line/core';
|
|
1
|
+
import { ServerMessageDef, RawConn, Serializer, ServerFrame, EmitData, ConnDescriptor, Adapter, PresenceStore, Contract, RoleOf, NodeStat, SharedEvents, SharedServerRequests, ClientInput, Output, SharedRequests, ServerInput, AnyData, RoleRequests, Events, DataOf, RoleTopics, AccessRules, Resource, Perms, ServerReplica, SharedTopics, EventData, ServerTransport, Handshake, ServerStore } from '@super-line/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A single client connection, passed to handlers as the third argument.
|
|
@@ -238,6 +238,15 @@ interface ServerStoreHandle {
|
|
|
238
238
|
delete(id: string): Promise<void>;
|
|
239
239
|
/** All Resource ids in this store. */
|
|
240
240
|
list(): Promise<string[]>;
|
|
241
|
+
/**
|
|
242
|
+
* Open a reactive in-process co-writer over a Resource's canonical state — the server half's mirror of
|
|
243
|
+
* `client.store(name).open(id)`. Reactive reads, merging `update`, and surgical `delete(path)` (the only
|
|
244
|
+
* way to remove a key server-side), all server-authoritative and fanned out to subscribers. `origin`
|
|
245
|
+
* (default `"server"`) tags its Changes for inspector attribution. Throws if the store has no `open`.
|
|
246
|
+
*/
|
|
247
|
+
open(id: string, opts?: {
|
|
248
|
+
origin?: string;
|
|
249
|
+
}): ServerReplica;
|
|
241
250
|
}
|
|
242
251
|
/** Options for {@link createSuperLineServer}. */
|
|
243
252
|
interface SuperLineServerOptions<C extends Contract, A extends AuthResult<C>> {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServerMessageDef, RawConn, Serializer, ServerFrame, EmitData, ConnDescriptor, Adapter, PresenceStore, Contract, RoleOf, NodeStat, SharedEvents, SharedServerRequests, ClientInput, Output, SharedRequests, ServerInput, AnyData, RoleRequests, Events, DataOf, RoleTopics, AccessRules, Resource, Perms, SharedTopics, EventData, ServerTransport, Handshake, ServerStore } from '@super-line/core';
|
|
1
|
+
import { ServerMessageDef, RawConn, Serializer, ServerFrame, EmitData, ConnDescriptor, Adapter, PresenceStore, Contract, RoleOf, NodeStat, SharedEvents, SharedServerRequests, ClientInput, Output, SharedRequests, ServerInput, AnyData, RoleRequests, Events, DataOf, RoleTopics, AccessRules, Resource, Perms, ServerReplica, SharedTopics, EventData, ServerTransport, Handshake, ServerStore } from '@super-line/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A single client connection, passed to handlers as the third argument.
|
|
@@ -238,6 +238,15 @@ interface ServerStoreHandle {
|
|
|
238
238
|
delete(id: string): Promise<void>;
|
|
239
239
|
/** All Resource ids in this store. */
|
|
240
240
|
list(): Promise<string[]>;
|
|
241
|
+
/**
|
|
242
|
+
* Open a reactive in-process co-writer over a Resource's canonical state — the server half's mirror of
|
|
243
|
+
* `client.store(name).open(id)`. Reactive reads, merging `update`, and surgical `delete(path)` (the only
|
|
244
|
+
* way to remove a key server-side), all server-authoritative and fanned out to subscribers. `origin`
|
|
245
|
+
* (default `"server"`) tags its Changes for inspector attribution. Throws if the store has no `open`.
|
|
246
|
+
*/
|
|
247
|
+
open(id: string, opts?: {
|
|
248
|
+
origin?: string;
|
|
249
|
+
}): ServerReplica;
|
|
241
250
|
}
|
|
242
251
|
/** Options for {@link createSuperLineServer}. */
|
|
243
252
|
interface SuperLineServerOptions<C extends Contract, A extends AuthResult<C>> {
|
package/dist/index.js
CHANGED
|
@@ -492,6 +492,26 @@ function createSuperLineServer(contract, opts) {
|
|
|
492
492
|
const remote = await presenceOrThrow().get(id);
|
|
493
493
|
if (!remote) throw new SuperLineError("NOT_FOUND", `Unknown connection: ${id}`);
|
|
494
494
|
return { descriptor: remote, ctxAvailable: false };
|
|
495
|
+
},
|
|
496
|
+
listStores: async () => Object.entries(storeMap).map(([name, store]) => ({ name, model: store.model })),
|
|
497
|
+
listResources: async (input) => {
|
|
498
|
+
const store = storeMap[input.store];
|
|
499
|
+
if (!store) throw new SuperLineError("NOT_FOUND", `Unknown store: ${input.store}`);
|
|
500
|
+
return store.list();
|
|
501
|
+
},
|
|
502
|
+
readResource: async (input) => {
|
|
503
|
+
const { store: name, id } = input;
|
|
504
|
+
const store = storeMap[name];
|
|
505
|
+
if (!store) throw new SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
|
|
506
|
+
const resource = await store.read(id);
|
|
507
|
+
if (!resource) throw new SuperLineError("NOT_FOUND", `No resource: ${name}/${id}`);
|
|
508
|
+
let data = resource.data;
|
|
509
|
+
if (store.open) {
|
|
510
|
+
const replica = store.open(id);
|
|
511
|
+
data = replica.getSnapshot();
|
|
512
|
+
replica.close();
|
|
513
|
+
}
|
|
514
|
+
return { data: safeSnapshot(data), accessRules: resource.accessRules };
|
|
495
515
|
}
|
|
496
516
|
};
|
|
497
517
|
const authHook = async (handshake) => {
|
|
@@ -867,6 +887,7 @@ function createSuperLineServer(contract, opts) {
|
|
|
867
887
|
storeApi[name] = {
|
|
868
888
|
async create(id, data, accessRules) {
|
|
869
889
|
await store.create(id, data, accessRules);
|
|
890
|
+
if (inspectorEnabled) emitInspectorEvent({ type: "store.create", store: name, id });
|
|
870
891
|
},
|
|
871
892
|
read(id) {
|
|
872
893
|
return Promise.resolve(store.read(id));
|
|
@@ -890,9 +911,33 @@ function createSuperLineServer(contract, opts) {
|
|
|
890
911
|
},
|
|
891
912
|
async delete(id) {
|
|
892
913
|
await store.delete(id);
|
|
914
|
+
if (inspectorEnabled) emitInspectorEvent({ type: "store.delete", store: name, id });
|
|
893
915
|
},
|
|
894
916
|
list() {
|
|
895
917
|
return Promise.resolve(store.list());
|
|
918
|
+
},
|
|
919
|
+
open(id, openOpts) {
|
|
920
|
+
if (!store.open)
|
|
921
|
+
throw new SuperLineError("UNSUPPORTED", `Store ${name} does not support reactive open()`);
|
|
922
|
+
const replica = store.open(id, openOpts);
|
|
923
|
+
if (!inspectorEnabled) return replica;
|
|
924
|
+
const origin = openOpts?.origin ?? SERVER_ORIGIN;
|
|
925
|
+
const emit = (data) => emitInspectorEvent({ type: "store.write", store: name, id, origin, data: safeSnapshot(data) });
|
|
926
|
+
return {
|
|
927
|
+
...replica,
|
|
928
|
+
set: (d) => {
|
|
929
|
+
replica.set(d);
|
|
930
|
+
emit(d);
|
|
931
|
+
},
|
|
932
|
+
update: (p) => {
|
|
933
|
+
replica.update(p);
|
|
934
|
+
emit(p);
|
|
935
|
+
},
|
|
936
|
+
delete: (path) => {
|
|
937
|
+
replica.delete(path);
|
|
938
|
+
emit({ delete: path });
|
|
939
|
+
}
|
|
940
|
+
};
|
|
896
941
|
}
|
|
897
942
|
};
|
|
898
943
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-line/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@chainsafe/libp2p-noise": "^17.0.0",
|
|
@@ -68,13 +68,13 @@
|
|
|
68
68
|
"zeromq": "^6.0.0",
|
|
69
69
|
"zod": "^3.24.1",
|
|
70
70
|
"zod-to-json-schema": "^3.25.2",
|
|
71
|
-
"@super-line/
|
|
72
|
-
"@super-line/adapter-zeromq": "0.5.0",
|
|
71
|
+
"@super-line/client": "0.6.0",
|
|
73
72
|
"@super-line/adapter-rabbitmq": "0.5.0",
|
|
73
|
+
"@super-line/adapter-redis": "0.5.0",
|
|
74
|
+
"@super-line/adapter-libp2p": "0.5.0",
|
|
74
75
|
"@super-line/transport-http": "0.5.0",
|
|
76
|
+
"@super-line/adapter-zeromq": "0.5.0",
|
|
75
77
|
"@super-line/transport-loopback": "0.5.0",
|
|
76
|
-
"@super-line/adapter-redis": "0.5.0",
|
|
77
|
-
"@super-line/client": "0.5.0",
|
|
78
78
|
"@super-line/transport-websocket": "0.5.0"
|
|
79
79
|
},
|
|
80
80
|
"optionalDependencies": {
|