@soulcraft/sdk 1.0.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/client/index.d.ts +62 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +60 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/ai/index.d.ts +55 -0
- package/dist/modules/ai/index.d.ts.map +1 -0
- package/dist/modules/ai/index.js +263 -0
- package/dist/modules/ai/index.js.map +1 -0
- package/dist/modules/ai/types.d.ts +216 -0
- package/dist/modules/ai/types.d.ts.map +1 -0
- package/dist/modules/ai/types.js +30 -0
- package/dist/modules/ai/types.js.map +1 -0
- package/dist/modules/auth/backchannel.d.ts +85 -0
- package/dist/modules/auth/backchannel.d.ts.map +1 -0
- package/dist/modules/auth/backchannel.js +168 -0
- package/dist/modules/auth/backchannel.js.map +1 -0
- package/dist/modules/auth/config.d.ts +122 -0
- package/dist/modules/auth/config.d.ts.map +1 -0
- package/dist/modules/auth/config.js +158 -0
- package/dist/modules/auth/config.js.map +1 -0
- package/dist/modules/auth/middleware.d.ts +146 -0
- package/dist/modules/auth/middleware.d.ts.map +1 -0
- package/dist/modules/auth/middleware.js +204 -0
- package/dist/modules/auth/middleware.js.map +1 -0
- package/dist/modules/auth/types.d.ts +162 -0
- package/dist/modules/auth/types.d.ts.map +1 -0
- package/dist/modules/auth/types.js +14 -0
- package/dist/modules/auth/types.js.map +1 -0
- package/dist/modules/billing/types.d.ts +7 -0
- package/dist/modules/billing/types.d.ts.map +1 -0
- package/dist/modules/billing/types.js +7 -0
- package/dist/modules/billing/types.js.map +1 -0
- package/dist/modules/brainy/auth.d.ts +104 -0
- package/dist/modules/brainy/auth.d.ts.map +1 -0
- package/dist/modules/brainy/auth.js +144 -0
- package/dist/modules/brainy/auth.js.map +1 -0
- package/dist/modules/brainy/errors.d.ts +118 -0
- package/dist/modules/brainy/errors.d.ts.map +1 -0
- package/dist/modules/brainy/errors.js +142 -0
- package/dist/modules/brainy/errors.js.map +1 -0
- package/dist/modules/brainy/events.d.ts +63 -0
- package/dist/modules/brainy/events.d.ts.map +1 -0
- package/dist/modules/brainy/events.js +14 -0
- package/dist/modules/brainy/events.js.map +1 -0
- package/dist/modules/brainy/proxy.d.ts +48 -0
- package/dist/modules/brainy/proxy.d.ts.map +1 -0
- package/dist/modules/brainy/proxy.js +95 -0
- package/dist/modules/brainy/proxy.js.map +1 -0
- package/dist/modules/brainy/types.d.ts +83 -0
- package/dist/modules/brainy/types.d.ts.map +1 -0
- package/dist/modules/brainy/types.js +21 -0
- package/dist/modules/brainy/types.js.map +1 -0
- package/dist/modules/events/index.d.ts +41 -0
- package/dist/modules/events/index.d.ts.map +1 -0
- package/dist/modules/events/index.js +53 -0
- package/dist/modules/events/index.js.map +1 -0
- package/dist/modules/events/types.d.ts +129 -0
- package/dist/modules/events/types.d.ts.map +1 -0
- package/dist/modules/events/types.js +32 -0
- package/dist/modules/events/types.js.map +1 -0
- package/dist/modules/formats/types.d.ts +7 -0
- package/dist/modules/formats/types.d.ts.map +1 -0
- package/dist/modules/formats/types.js +7 -0
- package/dist/modules/formats/types.js.map +1 -0
- package/dist/modules/hall/types.d.ts +56 -0
- package/dist/modules/hall/types.d.ts.map +1 -0
- package/dist/modules/hall/types.js +16 -0
- package/dist/modules/hall/types.js.map +1 -0
- package/dist/modules/kits/types.d.ts +7 -0
- package/dist/modules/kits/types.d.ts.map +1 -0
- package/dist/modules/kits/types.js +7 -0
- package/dist/modules/kits/types.js.map +1 -0
- package/dist/modules/license/types.d.ts +7 -0
- package/dist/modules/license/types.d.ts.map +1 -0
- package/dist/modules/license/types.js +7 -0
- package/dist/modules/license/types.js.map +1 -0
- package/dist/modules/notifications/types.d.ts +7 -0
- package/dist/modules/notifications/types.d.ts.map +1 -0
- package/dist/modules/notifications/types.js +7 -0
- package/dist/modules/notifications/types.js.map +1 -0
- package/dist/modules/skills/index.d.ts +60 -0
- package/dist/modules/skills/index.d.ts.map +1 -0
- package/dist/modules/skills/index.js +253 -0
- package/dist/modules/skills/index.js.map +1 -0
- package/dist/modules/skills/types.d.ts +127 -0
- package/dist/modules/skills/types.d.ts.map +1 -0
- package/dist/modules/skills/types.js +23 -0
- package/dist/modules/skills/types.js.map +1 -0
- package/dist/modules/versions/types.d.ts +31 -0
- package/dist/modules/versions/types.d.ts.map +1 -0
- package/dist/modules/versions/types.js +9 -0
- package/dist/modules/versions/types.js.map +1 -0
- package/dist/modules/vfs/types.d.ts +26 -0
- package/dist/modules/vfs/types.d.ts.map +1 -0
- package/dist/modules/vfs/types.js +11 -0
- package/dist/modules/vfs/types.js.map +1 -0
- package/dist/server/create-sdk.d.ts +70 -0
- package/dist/server/create-sdk.d.ts.map +1 -0
- package/dist/server/create-sdk.js +125 -0
- package/dist/server/create-sdk.js.map +1 -0
- package/dist/server/hall-handlers.d.ts +195 -0
- package/dist/server/hall-handlers.d.ts.map +1 -0
- package/dist/server/hall-handlers.js +239 -0
- package/dist/server/hall-handlers.js.map +1 -0
- package/dist/server/handlers.d.ts +216 -0
- package/dist/server/handlers.d.ts.map +1 -0
- package/dist/server/handlers.js +214 -0
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/index.d.ts +52 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +50 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/instance-pool.d.ts +299 -0
- package/dist/server/instance-pool.d.ts.map +1 -0
- package/dist/server/instance-pool.js +359 -0
- package/dist/server/instance-pool.js.map +1 -0
- package/dist/transports/http.d.ts +86 -0
- package/dist/transports/http.d.ts.map +1 -0
- package/dist/transports/http.js +134 -0
- package/dist/transports/http.js.map +1 -0
- package/dist/transports/local.d.ts +76 -0
- package/dist/transports/local.d.ts.map +1 -0
- package/dist/transports/local.js +101 -0
- package/dist/transports/local.js.map +1 -0
- package/dist/transports/sse.d.ts +99 -0
- package/dist/transports/sse.d.ts.map +1 -0
- package/dist/transports/sse.js +192 -0
- package/dist/transports/sse.js.map +1 -0
- package/dist/transports/transport.d.ts +68 -0
- package/dist/transports/transport.d.ts.map +1 -0
- package/dist/transports/transport.js +14 -0
- package/dist/transports/transport.js.map +1 -0
- package/dist/transports/ws.d.ts +135 -0
- package/dist/transports/ws.d.ts.map +1 -0
- package/dist/transports/ws.js +331 -0
- package/dist/transports/ws.js.map +1 -0
- package/dist/types.d.ts +152 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/docs/ADR-001-sdk-design.md +282 -0
- package/docs/IMPLEMENTATION-PLAN.md +708 -0
- package/docs/USAGE.md +646 -0
- package/docs/kit-sdk-guide.md +474 -0
- package/package.json +61 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/brainy/errors
|
|
3
|
+
* @description Typed error classes for @soulcraft/sdk Brainy operations.
|
|
4
|
+
*
|
|
5
|
+
* All errors thrown by SDK transports and handlers extend `SDKError` so callers
|
|
6
|
+
* can distinguish Soulcraft-specific failures from generic `Error`s with a single
|
|
7
|
+
* `instanceof` check. Machine-readable `code` fields allow programmatic handling.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* try {
|
|
12
|
+
* await sdk.brainy.find({ query: 'inventory items' })
|
|
13
|
+
* } catch (err) {
|
|
14
|
+
* if (err instanceof SDKTimeoutError) {
|
|
15
|
+
* showToast('Connection slow — please retry')
|
|
16
|
+
* } else if (err instanceof SDKError) {
|
|
17
|
+
* console.error('SDK error:', err.code, err.message)
|
|
18
|
+
* } else {
|
|
19
|
+
* throw err // unexpected
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Base class for all @soulcraft/sdk errors.
|
|
26
|
+
*
|
|
27
|
+
* Carries a machine-readable `code` for programmatic error handling.
|
|
28
|
+
* All SDK errors extend this class so callers can use a single `instanceof SDKError` check.
|
|
29
|
+
*/
|
|
30
|
+
export class SDKError extends Error {
|
|
31
|
+
/** Machine-readable error code (e.g. `'DISCONNECTED'`, `'TIMEOUT'`). */
|
|
32
|
+
code;
|
|
33
|
+
/**
|
|
34
|
+
* @param code - Machine-readable identifier.
|
|
35
|
+
* @param message - Human-readable description.
|
|
36
|
+
*/
|
|
37
|
+
constructor(code, message) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = 'SDKError';
|
|
40
|
+
this.code = code;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Thrown when an RPC call is attempted while the transport is not connected.
|
|
45
|
+
*
|
|
46
|
+
* Occurs for the HTTP transport when the server is unreachable, or for the
|
|
47
|
+
* WebSocket transport when the connection is in a disconnected or closed state.
|
|
48
|
+
*/
|
|
49
|
+
export class SDKDisconnectedError extends SDKError {
|
|
50
|
+
constructor() {
|
|
51
|
+
super('DISCONNECTED', 'SDK: not connected to a Brainy server');
|
|
52
|
+
this.name = 'SDKDisconnectedError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Thrown when an RPC call exceeds the configured response timeout.
|
|
57
|
+
*
|
|
58
|
+
* The call is cancelled on the client side; the server may still process it.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* if (err instanceof SDKTimeoutError) {
|
|
63
|
+
* console.error(`Timed out waiting for: ${err.method}`)
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export class SDKTimeoutError extends SDKError {
|
|
68
|
+
/** The Brainy method name that timed out (e.g. `'find'`, `'vfs.readdir'`). */
|
|
69
|
+
method;
|
|
70
|
+
/**
|
|
71
|
+
* @param method - Dot-separated Brainy method name that timed out.
|
|
72
|
+
*/
|
|
73
|
+
constructor(method) {
|
|
74
|
+
super('TIMEOUT', `SDK: RPC timeout for '${method}' (30s exceeded)`);
|
|
75
|
+
this.name = 'SDKTimeoutError';
|
|
76
|
+
this.method = method;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Thrown when the server rejects an RPC call due to authentication failure.
|
|
81
|
+
*
|
|
82
|
+
* For WebSocket transport: server sends close code 4001 (unauthorized).
|
|
83
|
+
* For HTTP transport: server responds with HTTP 401.
|
|
84
|
+
*/
|
|
85
|
+
export class SDKAuthError extends SDKError {
|
|
86
|
+
/**
|
|
87
|
+
* @param detail - Optional detail appended to the error message.
|
|
88
|
+
*/
|
|
89
|
+
constructor(detail) {
|
|
90
|
+
super('UNAUTHORIZED', `SDK: authentication rejected${detail ? ` — ${detail}` : ''}`);
|
|
91
|
+
this.name = 'SDKAuthError';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Thrown when the server rejects an RPC call due to insufficient permissions.
|
|
96
|
+
*
|
|
97
|
+
* For WebSocket transport: server sends close code 4003 (forbidden).
|
|
98
|
+
* For HTTP transport: server responds with HTTP 403.
|
|
99
|
+
*/
|
|
100
|
+
export class SDKForbiddenError extends SDKError {
|
|
101
|
+
/**
|
|
102
|
+
* @param detail - Optional detail appended to the error message.
|
|
103
|
+
*/
|
|
104
|
+
constructor(detail) {
|
|
105
|
+
super('FORBIDDEN', `SDK: insufficient permissions${detail ? ` — ${detail}` : ''}`);
|
|
106
|
+
this.name = 'SDKForbiddenError';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Thrown when a remote RPC call fails on the server side.
|
|
111
|
+
*
|
|
112
|
+
* Wraps the server's error code and message for client-side inspection.
|
|
113
|
+
*/
|
|
114
|
+
export class SDKRpcError extends SDKError {
|
|
115
|
+
/** The server-side error code returned in the RPC error response. */
|
|
116
|
+
serverCode;
|
|
117
|
+
/**
|
|
118
|
+
* @param serverCode - The error code returned by the server.
|
|
119
|
+
* @param serverMessage - The human-readable message returned by the server.
|
|
120
|
+
*/
|
|
121
|
+
constructor(serverCode, serverMessage) {
|
|
122
|
+
super('RPC_ERROR', `SDK: remote error [${serverCode}] ${serverMessage}`);
|
|
123
|
+
this.name = 'SDKRpcError';
|
|
124
|
+
this.serverCode = serverCode;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Thrown when a method path cannot be resolved on the target Brainy instance.
|
|
129
|
+
*
|
|
130
|
+
* Occurs in the local transport when the dot-separated method string resolves
|
|
131
|
+
* to a non-existent or non-callable property.
|
|
132
|
+
*/
|
|
133
|
+
export class SDKMethodNotFoundError extends SDKError {
|
|
134
|
+
/**
|
|
135
|
+
* @param method - The dot-separated method path that could not be resolved.
|
|
136
|
+
*/
|
|
137
|
+
constructor(method) {
|
|
138
|
+
super('METHOD_NOT_FOUND', `SDK: method '${method}' not found on Brainy instance`);
|
|
139
|
+
this.name = 'SDKMethodNotFoundError';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/modules/brainy/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;GAKG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,wEAAwE;IACxD,IAAI,CAAQ;IAE5B;;;OAGG;IACH,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,oBAAqB,SAAQ,QAAQ;IAChD;QACE,KAAK,CAAC,cAAc,EAAE,uCAAuC,CAAC,CAAA;QAC9D,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAC3C,8EAA8E;IAC9D,MAAM,CAAQ;IAE9B;;OAEG;IACH,YAAY,MAAc;QACxB,KAAK,CAAC,SAAS,EAAE,yBAAyB,MAAM,kBAAkB,CAAC,CAAA;QACnE,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,QAAQ;IACxC;;OAEG;IACH,YAAY,MAAe;QACzB,KAAK,CAAC,cAAc,EAAE,+BAA+B,MAAM,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QACpF,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;IAC5B,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SAAQ,QAAQ;IAC7C;;OAEG;IACH,YAAY,MAAe;QACzB,KAAK,CAAC,WAAW,EAAE,gCAAgC,MAAM,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QAClF,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,QAAQ;IACvC,qEAAqE;IACrD,UAAU,CAAQ;IAElC;;;OAGG;IACH,YAAY,UAAkB,EAAE,aAAqB;QACnD,KAAK,CAAC,WAAW,EAAE,sBAAsB,UAAU,KAAK,aAAa,EAAE,CAAC,CAAA;QACxE,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,sBAAuB,SAAQ,QAAQ;IAClD;;OAEG;IACH,YAAY,MAAc;QACxB,KAAK,CAAC,kBAAkB,EAAE,gBAAgB,MAAM,gCAAgC,CAAC,CAAA;QACjF,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/brainy/events
|
|
3
|
+
* @description Brainy change event types pushed from a Brainy server to connected clients.
|
|
4
|
+
*
|
|
5
|
+
* These events are emitted by the server-side WebSocket handler whenever a write
|
|
6
|
+
* operation modifies Brainy data. Clients receive them via `onDataChange()` on the
|
|
7
|
+
* `SoulcraftBrainy` instance, enabling real-time UI updates without polling.
|
|
8
|
+
*
|
|
9
|
+
* The WebSocket wire format uses `{ type: 'change', event, entity?, relation? }` so
|
|
10
|
+
* that the server can multiplex RPC responses and change push events on a single
|
|
11
|
+
* binary MessagePack stream.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* An entity snapshot carried inside a {@link BrainyChangeEvent}.
|
|
15
|
+
*
|
|
16
|
+
* Contains enough information to update a local cache without a round-trip.
|
|
17
|
+
*/
|
|
18
|
+
export interface BrainyChangeEntity {
|
|
19
|
+
/** Brainy entity UUID. */
|
|
20
|
+
id: string;
|
|
21
|
+
/** NounType string (e.g. `'Thing'`, `'Person'`, `'Document'`). */
|
|
22
|
+
nounType: string;
|
|
23
|
+
/** The entity's indexed metadata fields. */
|
|
24
|
+
metadata: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A relation snapshot carried inside a {@link BrainyChangeEvent}.
|
|
28
|
+
*/
|
|
29
|
+
export interface BrainyChangeRelation {
|
|
30
|
+
/** Source entity UUID. */
|
|
31
|
+
from: string;
|
|
32
|
+
/** Target entity UUID. */
|
|
33
|
+
to: string;
|
|
34
|
+
/** VerbType string (e.g. `'Contains'`, `'References'`). */
|
|
35
|
+
verbType: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* An unsolicited push event sent from a Brainy server to all connected WebSocket
|
|
39
|
+
* clients whenever Brainy data is mutated.
|
|
40
|
+
*
|
|
41
|
+
* Exactly one of `entity` or `relation` will be populated, depending on whether
|
|
42
|
+
* the mutation affected an entity or a relationship.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* sdk.brainy.onDataChange((event) => {
|
|
47
|
+
* if (event.event === 'add' && event.entity?.nounType === 'InventoryItem') {
|
|
48
|
+
* invalidateInventoryCache()
|
|
49
|
+
* }
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export interface BrainyChangeEvent {
|
|
54
|
+
/** Always `'change'` — used to distinguish from RPC responses on the wire. */
|
|
55
|
+
type: 'change';
|
|
56
|
+
/** The mutation operation that triggered this event. */
|
|
57
|
+
event: 'add' | 'update' | 'delete' | 'relate' | 'unrelate';
|
|
58
|
+
/** Populated for entity mutations (add, update, delete). */
|
|
59
|
+
entity?: BrainyChangeEntity;
|
|
60
|
+
/** Populated for relationship mutations (relate, unrelate). */
|
|
61
|
+
relation?: BrainyChangeRelation;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/modules/brainy/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAA;IAChB,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,IAAI,EAAE,QAAQ,CAAA;IACd,wDAAwD;IACxD,KAAK,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC1D,4DAA4D;IAC5D,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,oBAAoB,CAAA;CAChC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/brainy/events
|
|
3
|
+
* @description Brainy change event types pushed from a Brainy server to connected clients.
|
|
4
|
+
*
|
|
5
|
+
* These events are emitted by the server-side WebSocket handler whenever a write
|
|
6
|
+
* operation modifies Brainy data. Clients receive them via `onDataChange()` on the
|
|
7
|
+
* `SoulcraftBrainy` instance, enabling real-time UI updates without polling.
|
|
8
|
+
*
|
|
9
|
+
* The WebSocket wire format uses `{ type: 'change', event, entity?, relation? }` so
|
|
10
|
+
* that the server can multiplex RPC responses and change push events on a single
|
|
11
|
+
* binary MessagePack stream.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/modules/brainy/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/brainy/proxy
|
|
3
|
+
* @description JavaScript Proxy factory that maps any property access chain into a
|
|
4
|
+
* transport RPC call.
|
|
5
|
+
*
|
|
6
|
+
* Accessing `sdk.brainy.vfs.readdir('/')` never enumerates the Brainy API:
|
|
7
|
+
* 1. `sdk.brainy.vfs` → new Proxy with namespace `'vfs'`
|
|
8
|
+
* 2. `.readdir` → new Proxy with namespace `'vfs.readdir'`
|
|
9
|
+
* 3. Called with `['/']` → dispatches `transport.call('vfs.readdir', ['/'])`
|
|
10
|
+
*
|
|
11
|
+
* This means every current and future Brainy method is automatically supported
|
|
12
|
+
* across all transports without any per-method wiring.
|
|
13
|
+
*
|
|
14
|
+
* Special properties handled at the root level without RPC:
|
|
15
|
+
* - `close()` → `transport.close()`
|
|
16
|
+
* - `isAlive()` → `transport.isAlive()`
|
|
17
|
+
* - `onDataChange(h)` → `transport.onEvent(h)`
|
|
18
|
+
* - `offDataChange(h)` → `transport.offEvent(h)`
|
|
19
|
+
* - `_transport` → returns the underlying transport (for `connect()` on WS)
|
|
20
|
+
* - `then` → `undefined` (prevents `await sdk.brainy` from hanging)
|
|
21
|
+
*/
|
|
22
|
+
import type { SDKTransport } from '../../transports/transport.js';
|
|
23
|
+
import type { SoulcraftBrainy } from './types.js';
|
|
24
|
+
/**
|
|
25
|
+
* Creates a `SoulcraftBrainy` proxy backed by the given transport.
|
|
26
|
+
*
|
|
27
|
+
* All property accesses on the returned object are intercepted and accumulated
|
|
28
|
+
* into a dot-separated method name; when the proxy is invoked as a function
|
|
29
|
+
* the accumulated name is dispatched to `transport.call()`.
|
|
30
|
+
*
|
|
31
|
+
* @param transport - The transport that will handle all RPC dispatches.
|
|
32
|
+
* @returns A `SoulcraftBrainy` proxy ready for Brainy API calls.
|
|
33
|
+
*
|
|
34
|
+
* @example Server-mode (local transport, zero overhead)
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const brain = await pool.forUser(userId, workspaceId)
|
|
37
|
+
* const brainy = createBrainyProxy(new LocalTransport(brain))
|
|
38
|
+
* const results = await brainy.find({ query: 'candle kits' })
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example Client-mode (HTTP transport)
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const brainy = createBrainyProxy(new HttpTransport(baseUrl, token))
|
|
44
|
+
* const entity = await brainy.get(entityId)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function createBrainyProxy(transport: SDKTransport): SoulcraftBrainy;
|
|
48
|
+
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/modules/brainy/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAEjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,YAAY,GAAG,eAAe,CAE1E"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/brainy/proxy
|
|
3
|
+
* @description JavaScript Proxy factory that maps any property access chain into a
|
|
4
|
+
* transport RPC call.
|
|
5
|
+
*
|
|
6
|
+
* Accessing `sdk.brainy.vfs.readdir('/')` never enumerates the Brainy API:
|
|
7
|
+
* 1. `sdk.brainy.vfs` → new Proxy with namespace `'vfs'`
|
|
8
|
+
* 2. `.readdir` → new Proxy with namespace `'vfs.readdir'`
|
|
9
|
+
* 3. Called with `['/']` → dispatches `transport.call('vfs.readdir', ['/'])`
|
|
10
|
+
*
|
|
11
|
+
* This means every current and future Brainy method is automatically supported
|
|
12
|
+
* across all transports without any per-method wiring.
|
|
13
|
+
*
|
|
14
|
+
* Special properties handled at the root level without RPC:
|
|
15
|
+
* - `close()` → `transport.close()`
|
|
16
|
+
* - `isAlive()` → `transport.isAlive()`
|
|
17
|
+
* - `onDataChange(h)` → `transport.onEvent(h)`
|
|
18
|
+
* - `offDataChange(h)` → `transport.offEvent(h)`
|
|
19
|
+
* - `_transport` → returns the underlying transport (for `connect()` on WS)
|
|
20
|
+
* - `then` → `undefined` (prevents `await sdk.brainy` from hanging)
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Creates a `SoulcraftBrainy` proxy backed by the given transport.
|
|
24
|
+
*
|
|
25
|
+
* All property accesses on the returned object are intercepted and accumulated
|
|
26
|
+
* into a dot-separated method name; when the proxy is invoked as a function
|
|
27
|
+
* the accumulated name is dispatched to `transport.call()`.
|
|
28
|
+
*
|
|
29
|
+
* @param transport - The transport that will handle all RPC dispatches.
|
|
30
|
+
* @returns A `SoulcraftBrainy` proxy ready for Brainy API calls.
|
|
31
|
+
*
|
|
32
|
+
* @example Server-mode (local transport, zero overhead)
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const brain = await pool.forUser(userId, workspaceId)
|
|
35
|
+
* const brainy = createBrainyProxy(new LocalTransport(brain))
|
|
36
|
+
* const results = await brainy.find({ query: 'candle kits' })
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Client-mode (HTTP transport)
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const brainy = createBrainyProxy(new HttpTransport(baseUrl, token))
|
|
42
|
+
* const entity = await brainy.get(entityId)
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function createBrainyProxy(transport) {
|
|
46
|
+
return _createProxy(transport, '');
|
|
47
|
+
}
|
|
48
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
49
|
+
// Internal recursive proxy factory
|
|
50
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
51
|
+
/**
|
|
52
|
+
* Recursively builds a proxy that accumulates a dot-separated namespace and
|
|
53
|
+
* dispatches RPC calls when invoked.
|
|
54
|
+
*
|
|
55
|
+
* @param transport - The underlying transport instance.
|
|
56
|
+
* @param namespace - Dot-separated method path accumulated so far (empty at root).
|
|
57
|
+
* @returns A Proxy that behaves like the Brainy API at this namespace depth.
|
|
58
|
+
*/
|
|
59
|
+
function _createProxy(transport, namespace) {
|
|
60
|
+
// Use a no-op function as the Proxy target so the Proxy is callable.
|
|
61
|
+
return new Proxy(function () { }, {
|
|
62
|
+
get(_target, prop) {
|
|
63
|
+
// Pass through symbols — avoids breaking spread, iteration, Symbol.toPrimitive, etc.
|
|
64
|
+
if (typeof prop === 'symbol')
|
|
65
|
+
return undefined;
|
|
66
|
+
// Prevent accidental Promise treatment: `await sdk.brainy` must not hang.
|
|
67
|
+
if (prop === 'then')
|
|
68
|
+
return undefined;
|
|
69
|
+
const propStr = String(prop);
|
|
70
|
+
// Root-level special cases — resolved locally, never sent over the wire.
|
|
71
|
+
if (namespace === '') {
|
|
72
|
+
if (propStr === 'close')
|
|
73
|
+
return () => transport.close();
|
|
74
|
+
if (propStr === 'isAlive')
|
|
75
|
+
return () => transport.isAlive();
|
|
76
|
+
if (propStr === 'onDataChange') {
|
|
77
|
+
return (h) => transport.onEvent(h);
|
|
78
|
+
}
|
|
79
|
+
if (propStr === 'offDataChange') {
|
|
80
|
+
return (h) => transport.offEvent(h);
|
|
81
|
+
}
|
|
82
|
+
// Expose the underlying transport for callers needing connect() on WsTransport.
|
|
83
|
+
if (propStr === '_transport')
|
|
84
|
+
return transport;
|
|
85
|
+
}
|
|
86
|
+
const nextNamespace = namespace ? `${namespace}.${propStr}` : propStr;
|
|
87
|
+
return _createProxy(transport, nextNamespace);
|
|
88
|
+
},
|
|
89
|
+
apply(_target, _thisArg, args) {
|
|
90
|
+
// The proxy was invoked as a function — dispatch as an RPC call.
|
|
91
|
+
return transport.call(namespace, args);
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/modules/brainy/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAuB;IACvD,OAAO,YAAY,CAAC,SAAS,EAAE,EAAE,CAAoB,CAAA;AACvD,CAAC;AAED,gFAAgF;AAChF,mCAAmC;AACnC,gFAAgF;AAEhF;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,SAAuB,EAAE,SAAiB;IAC9D,qEAAqE;IACrE,OAAO,IAAI,KAAK,CAAC,cAAa,CAAC,EAAE;QAC/B,GAAG,CAAC,OAAO,EAAE,IAAqB;YAChC,qFAAqF;YACrF,IAAI,OAAO,IAAI,KAAK,QAAQ;gBAAE,OAAO,SAAS,CAAA;YAE9C,0EAA0E;YAC1E,IAAI,IAAI,KAAK,MAAM;gBAAE,OAAO,SAAS,CAAA;YAErC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;YAE5B,yEAAyE;YACzE,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;gBACrB,IAAI,OAAO,KAAK,OAAO;oBAAE,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA;gBACvD,IAAI,OAAO,KAAK,SAAS;oBAAE,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,CAAA;gBAC3D,IAAI,OAAO,KAAK,cAAc,EAAE,CAAC;oBAC/B,OAAO,CAAC,CAAiC,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;gBACpE,CAAC;gBACD,IAAI,OAAO,KAAK,eAAe,EAAE,CAAC;oBAChC,OAAO,CAAC,CAAiC,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;gBACrE,CAAC;gBACD,gFAAgF;gBAChF,IAAI,OAAO,KAAK,YAAY;oBAAE,OAAO,SAAS,CAAA;YAChD,CAAC;YAED,MAAM,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAA;YACrE,OAAO,YAAY,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;QAC/C,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAe;YACtC,iEAAiE;YACjE,OAAO,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;QACxC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/brainy/types
|
|
3
|
+
* @description Type definitions for `sdk.brainy.*` — the Brainy API proxy surface
|
|
4
|
+
* exposed by @soulcraft/sdk.
|
|
5
|
+
*
|
|
6
|
+
* `SoulcraftBrainy` is a `Pick<Brainy, ...>` over all supported methods, meaning it
|
|
7
|
+
* stays in sync with whatever version of `@soulcraft/brainy` the consuming project
|
|
8
|
+
* installs. Adding a method to the Pick list is the only change needed when Brainy
|
|
9
|
+
* exposes a new API.
|
|
10
|
+
*
|
|
11
|
+
* Sub-APIs (`vfs`, `versions`, `neural`, `counts`) are included via their getter
|
|
12
|
+
* property names so that `sdk.brainy.vfs.readdir('/')` is fully typed — the Proxy
|
|
13
|
+
* intercepts the property access and routes subsequent calls as `'vfs.readdir'`.
|
|
14
|
+
*
|
|
15
|
+
* Additional SDK-specific methods not on Brainy itself:
|
|
16
|
+
* - `onDataChange` / `offDataChange` — real-time change push subscriptions
|
|
17
|
+
* - `isAlive` — connection health check
|
|
18
|
+
* - `close` — graceful disconnect
|
|
19
|
+
*/
|
|
20
|
+
import type { Brainy } from '@soulcraft/brainy';
|
|
21
|
+
import type { BrainyChangeEvent } from './events.js';
|
|
22
|
+
export type { Entity, Relation, Result, AddParams, UpdateParams, RelateParams, FindParams, BrainyConfig, AggregateDefinition, DiagnosticsResult, } from '@soulcraft/brainy';
|
|
23
|
+
export type { MigrationResult, MigrateOptions, MigrationPreview } from '@soulcraft/brainy';
|
|
24
|
+
export type { NounType, VerbType } from '@soulcraft/brainy';
|
|
25
|
+
export type { BrainyChangeEvent, BrainyChangeEntity, BrainyChangeRelation } from './events.js';
|
|
26
|
+
/**
|
|
27
|
+
* The public Brainy API surface exposed by @soulcraft/sdk across all four transports.
|
|
28
|
+
*
|
|
29
|
+
* Extends `Pick<Brainy, ...>` so TypeScript types are always derived from the
|
|
30
|
+
* installed `@soulcraft/brainy` version. The runtime implementation is a JavaScript
|
|
31
|
+
* `Proxy` that maps any method call to `transport.call(methodName, args)`, so
|
|
32
|
+
* every current and future Brainy method is forwarded without additional per-method code.
|
|
33
|
+
*
|
|
34
|
+
* Sub-APIs are accessed via their getter names:
|
|
35
|
+
* - `brainy.vfs` — Virtual filesystem (`VirtualFileSystem`)
|
|
36
|
+
* - `brainy.versions` — Entity version history (`VersioningAPI`)
|
|
37
|
+
* - `brainy.neural()` — Neural extraction and analysis
|
|
38
|
+
* - `brainy.counts` — Entity and relationship count helpers
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { createSDK } from '@soulcraft/sdk/server'
|
|
43
|
+
*
|
|
44
|
+
* const sdk = createSDK({ mode: 'server', product: 'workshop', ... })
|
|
45
|
+
*
|
|
46
|
+
* const results = await sdk.brainy.find({ query: 'candle kits', limit: 10 })
|
|
47
|
+
* const entity = await sdk.brainy.get(id)
|
|
48
|
+
* const files = await sdk.brainy.vfs.readdir('/documents')
|
|
49
|
+
* const versions = await sdk.brainy.versions.list(entityId)
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export type SoulcraftBrainy = Pick<Brainy, 'add' | 'get' | 'batchGet' | 'update' | 'delete' | 'find' | 'similar' | 'embed' | 'embedBatch' | 'similarity' | 'relate' | 'unrelate' | 'getRelations' | 'neighbors' | 'addMany' | 'deleteMany' | 'updateMany' | 'relateMany' | 'indexStats' | 'findDuplicates' | 'cluster' | 'defineAggregate' | 'removeAggregate' | 'vfs' | 'versions' | 'neural' | 'counts' | 'flush' | 'migrate' | 'diagnostics' | 'clear'> & {
|
|
53
|
+
/**
|
|
54
|
+
* Registers a listener for real-time change events pushed from the server.
|
|
55
|
+
*
|
|
56
|
+
* No-op for the local transport — in-process mutations are synchronous.
|
|
57
|
+
* WebSocket and SSE transports dispatch events as they arrive from the server.
|
|
58
|
+
*
|
|
59
|
+
* @param handler - Called with each {@link BrainyChangeEvent} as it arrives.
|
|
60
|
+
*/
|
|
61
|
+
onDataChange(handler: (event: BrainyChangeEvent) => void): void;
|
|
62
|
+
/**
|
|
63
|
+
* Removes a previously registered change event listener.
|
|
64
|
+
*
|
|
65
|
+
* @param handler - The same function reference passed to `onDataChange`.
|
|
66
|
+
*/
|
|
67
|
+
offDataChange(handler: (event: BrainyChangeEvent) => void): void;
|
|
68
|
+
/**
|
|
69
|
+
* Returns `true` if the client has an active connection to a Brainy instance.
|
|
70
|
+
*
|
|
71
|
+
* Always `true` for local and HTTP transports.
|
|
72
|
+
* Returns `true` only when the WebSocket is in the connected state.
|
|
73
|
+
*/
|
|
74
|
+
isAlive(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Gracefully disconnects from the Brainy server and releases resources.
|
|
77
|
+
*
|
|
78
|
+
* No-op for local transport (Brainy instance lifecycle is managed by the
|
|
79
|
+
* server's instance pool). Closes the WebSocket with code 1000 for WS transport.
|
|
80
|
+
*/
|
|
81
|
+
close(): Promise<void>;
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/brainy/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAKpD,YAAY,EACV,MAAM,EACN,QAAQ,EACR,MAAM,EACN,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,mBAAmB,CAAA;AAE1B,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC1F,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAE9F;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,MAAM,EAEJ,KAAK,GACL,KAAK,GACL,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,SAAS,GACT,OAAO,GACP,YAAY,GACZ,YAAY,GAEZ,QAAQ,GACR,UAAU,GACV,cAAc,GACd,WAAW,GAEX,SAAS,GACT,YAAY,GACZ,YAAY,GACZ,YAAY,GAEZ,YAAY,GACZ,gBAAgB,GAChB,SAAS,GACT,iBAAiB,GACjB,iBAAiB,GAEjB,KAAK,GACL,UAAU,GACV,QAAQ,GACR,QAAQ,GAER,OAAO,GACP,SAAS,GACT,aAAa,GACb,OAAO,CACV,GAAG;IACF;;;;;;;OAOG;IACH,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GAAG,IAAI,CAAA;IAE/D;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GAAG,IAAI,CAAA;IAEhE;;;;;OAKG;IACH,OAAO,IAAI,OAAO,CAAA;IAElB;;;;;OAKG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/brainy/types
|
|
3
|
+
* @description Type definitions for `sdk.brainy.*` — the Brainy API proxy surface
|
|
4
|
+
* exposed by @soulcraft/sdk.
|
|
5
|
+
*
|
|
6
|
+
* `SoulcraftBrainy` is a `Pick<Brainy, ...>` over all supported methods, meaning it
|
|
7
|
+
* stays in sync with whatever version of `@soulcraft/brainy` the consuming project
|
|
8
|
+
* installs. Adding a method to the Pick list is the only change needed when Brainy
|
|
9
|
+
* exposes a new API.
|
|
10
|
+
*
|
|
11
|
+
* Sub-APIs (`vfs`, `versions`, `neural`, `counts`) are included via their getter
|
|
12
|
+
* property names so that `sdk.brainy.vfs.readdir('/')` is fully typed — the Proxy
|
|
13
|
+
* intercepts the property access and routes subsequent calls as `'vfs.readdir'`.
|
|
14
|
+
*
|
|
15
|
+
* Additional SDK-specific methods not on Brainy itself:
|
|
16
|
+
* - `onDataChange` / `offDataChange` — real-time change push subscriptions
|
|
17
|
+
* - `isAlive` — connection health check
|
|
18
|
+
* - `close` — graceful disconnect
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/brainy/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/events
|
|
3
|
+
* @description Platform event bus implementation for @soulcraft/sdk.
|
|
4
|
+
*
|
|
5
|
+
* Backed by Node's built-in `EventEmitter`. Provides a fully-typed publish/
|
|
6
|
+
* subscribe interface via {@link EventsModule}. All built-in platform events
|
|
7
|
+
* (`brainy:change`, `vfs:write`, `vfs:delete`, `vfs:rename`) are emitted
|
|
8
|
+
* by the SDK itself when the corresponding Brainy or VFS mutations occur.
|
|
9
|
+
*
|
|
10
|
+
* Application code and kit integrations can add custom events by extending
|
|
11
|
+
* the {@link SoulcraftEventMap} interface with declaration merging.
|
|
12
|
+
*
|
|
13
|
+
* The returned `EventsModule` instance is bound to a single `EventEmitter`,
|
|
14
|
+
* so all subscribers on the same SDK instance share a single event stream.
|
|
15
|
+
* For multi-tenant server deployments, create one SDK instance (and therefore
|
|
16
|
+
* one event bus) per Brainy scope.
|
|
17
|
+
*/
|
|
18
|
+
import type { EventsModule } from './types.js';
|
|
19
|
+
/**
|
|
20
|
+
* Creates an `EventsModule` backed by a new Node `EventEmitter`.
|
|
21
|
+
*
|
|
22
|
+
* The emitter's default max-listener limit is raised to 100 to support
|
|
23
|
+
* large numbers of concurrent subscribers in server deployments.
|
|
24
|
+
*
|
|
25
|
+
* @returns A typed event bus implementing {@link EventsModule}.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const events = createEventsModule()
|
|
30
|
+
*
|
|
31
|
+
* events.on('vfs:write', ({ path, content }) => {
|
|
32
|
+
* console.log('VFS write:', path)
|
|
33
|
+
* })
|
|
34
|
+
*
|
|
35
|
+
* events.emit('vfs:write', { path: '/notes/todo.txt', content: 'Buy candles' })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function createEventsModule(): EventsModule;
|
|
39
|
+
export type { EventsModule, SoulcraftEventMap, SoulcraftEventName } from './types.js';
|
|
40
|
+
export type { VfsWriteEvent, VfsDeleteEvent, VfsRenameEvent } from './types.js';
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAqB,MAAM,YAAY,CAAA;AAEjE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAuBjD;AAED,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACrF,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/events
|
|
3
|
+
* @description Platform event bus implementation for @soulcraft/sdk.
|
|
4
|
+
*
|
|
5
|
+
* Backed by Node's built-in `EventEmitter`. Provides a fully-typed publish/
|
|
6
|
+
* subscribe interface via {@link EventsModule}. All built-in platform events
|
|
7
|
+
* (`brainy:change`, `vfs:write`, `vfs:delete`, `vfs:rename`) are emitted
|
|
8
|
+
* by the SDK itself when the corresponding Brainy or VFS mutations occur.
|
|
9
|
+
*
|
|
10
|
+
* Application code and kit integrations can add custom events by extending
|
|
11
|
+
* the {@link SoulcraftEventMap} interface with declaration merging.
|
|
12
|
+
*
|
|
13
|
+
* The returned `EventsModule` instance is bound to a single `EventEmitter`,
|
|
14
|
+
* so all subscribers on the same SDK instance share a single event stream.
|
|
15
|
+
* For multi-tenant server deployments, create one SDK instance (and therefore
|
|
16
|
+
* one event bus) per Brainy scope.
|
|
17
|
+
*/
|
|
18
|
+
import { EventEmitter } from 'node:events';
|
|
19
|
+
/**
|
|
20
|
+
* Creates an `EventsModule` backed by a new Node `EventEmitter`.
|
|
21
|
+
*
|
|
22
|
+
* The emitter's default max-listener limit is raised to 100 to support
|
|
23
|
+
* large numbers of concurrent subscribers in server deployments.
|
|
24
|
+
*
|
|
25
|
+
* @returns A typed event bus implementing {@link EventsModule}.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const events = createEventsModule()
|
|
30
|
+
*
|
|
31
|
+
* events.on('vfs:write', ({ path, content }) => {
|
|
32
|
+
* console.log('VFS write:', path)
|
|
33
|
+
* })
|
|
34
|
+
*
|
|
35
|
+
* events.emit('vfs:write', { path: '/notes/todo.txt', content: 'Buy candles' })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function createEventsModule() {
|
|
39
|
+
const emitter = new EventEmitter();
|
|
40
|
+
emitter.setMaxListeners(100);
|
|
41
|
+
return {
|
|
42
|
+
on(event, handler) {
|
|
43
|
+
emitter.on(event, handler);
|
|
44
|
+
},
|
|
45
|
+
off(event, handler) {
|
|
46
|
+
emitter.off(event, handler);
|
|
47
|
+
},
|
|
48
|
+
emit(event, payload) {
|
|
49
|
+
emitter.emit(event, payload);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAA;IAClC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;IAE5B,OAAO;QACL,EAAE,CACA,KAAQ,EACR,OAAgD;YAEhD,OAAO,CAAC,EAAE,CAAC,KAAe,EAAE,OAAO,CAAC,CAAA;QACtC,CAAC;QAED,GAAG,CACD,KAAQ,EACR,OAAgD;YAEhD,OAAO,CAAC,GAAG,CAAC,KAAe,EAAE,OAAO,CAAC,CAAA;QACvC,CAAC;QAED,IAAI,CAAoC,KAAQ,EAAE,OAA6B;YAC7E,OAAO,CAAC,IAAI,CAAC,KAAe,EAAE,OAAO,CAAC,CAAA;QACxC,CAAC;KACF,CAAA;AACH,CAAC"}
|