@constructive-io/sdk 0.20.7 → 0.20.9
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/admin/orm/client.d.ts +30 -0
- package/admin/orm/client.js +41 -1
- package/admin/orm/realtime.d.ts +142 -0
- package/admin/orm/realtime.js +104 -0
- package/auth/orm/client.d.ts +30 -0
- package/auth/orm/client.js +41 -1
- package/auth/orm/realtime.d.ts +142 -0
- package/auth/orm/realtime.js +104 -0
- package/esm/admin/orm/client.d.ts +30 -0
- package/esm/admin/orm/client.js +39 -0
- package/esm/admin/orm/realtime.d.ts +142 -0
- package/esm/admin/orm/realtime.js +100 -0
- package/esm/auth/orm/client.d.ts +30 -0
- package/esm/auth/orm/client.js +39 -0
- package/esm/auth/orm/realtime.d.ts +142 -0
- package/esm/auth/orm/realtime.js +100 -0
- package/esm/objects/orm/client.d.ts +30 -0
- package/esm/objects/orm/client.js +39 -0
- package/esm/objects/orm/realtime.d.ts +142 -0
- package/esm/objects/orm/realtime.js +100 -0
- package/esm/public/orm/client.d.ts +30 -0
- package/esm/public/orm/client.js +39 -0
- package/esm/public/orm/index.d.ts +0 -5
- package/esm/public/orm/input-types.d.ts +0 -11
- package/esm/public/orm/mutation/index.d.ts +1 -9
- package/esm/public/orm/mutation/index.js +0 -12
- package/esm/public/orm/realtime.d.ts +142 -0
- package/esm/public/orm/realtime.js +100 -0
- package/objects/orm/client.d.ts +30 -0
- package/objects/orm/client.js +41 -1
- package/objects/orm/realtime.d.ts +142 -0
- package/objects/orm/realtime.js +104 -0
- package/package.json +2 -2
- package/public/orm/client.d.ts +30 -0
- package/public/orm/client.js +41 -1
- package/public/orm/index.d.ts +0 -5
- package/public/orm/input-types.d.ts +0 -11
- package/public/orm/mutation/index.d.ts +1 -9
- package/public/orm/mutation/index.js +0 -12
- package/public/orm/realtime.d.ts +142 -0
- package/public/orm/realtime.js +104 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Realtime Manager - WebSocket subscription support
|
|
4
|
+
* @generated by @constructive-io/graphql-codegen
|
|
5
|
+
* DO NOT EDIT - changes will be overwritten
|
|
6
|
+
*/
|
|
7
|
+
// Minimal type shims so this module compiles without graphql-ws
|
|
8
|
+
// installed. Consumers supply a WsClient via RealtimeConfig;
|
|
9
|
+
// the SDK itself never imports or requires graphql-ws.
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.RealtimeManager = void 0;
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// RealtimeManager
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Manages a graphql-ws WebSocket client and multiplexes
|
|
17
|
+
* subscriptions over it. Created by OrmClient when `realtime`
|
|
18
|
+
* config is provided.
|
|
19
|
+
*/
|
|
20
|
+
class RealtimeManager {
|
|
21
|
+
wsClient;
|
|
22
|
+
connectionState = 'disconnected';
|
|
23
|
+
stateListeners = new Set();
|
|
24
|
+
activeSubscriptions = 0;
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.wsClient = config.client;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to a GraphQL subscription operation.
|
|
30
|
+
* Models call this with typed metadata and documents.
|
|
31
|
+
*/
|
|
32
|
+
subscribe(meta, document, variables, options) {
|
|
33
|
+
this.activeSubscriptions++;
|
|
34
|
+
let disposed = false;
|
|
35
|
+
const cleanup = this.wsClient.subscribe({ query: document, variables }, {
|
|
36
|
+
next: (result) => {
|
|
37
|
+
if (disposed)
|
|
38
|
+
return;
|
|
39
|
+
if (result.errors) {
|
|
40
|
+
options.onError?.(new Error(result.errors.map((e) => e.message).join('; ')));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const payload = result.data?.[meta.fieldName];
|
|
44
|
+
if (!payload)
|
|
45
|
+
return;
|
|
46
|
+
const event = {
|
|
47
|
+
operation: payload.event ?? 'UPDATE',
|
|
48
|
+
data: payload[meta.dataFieldName] ?? null,
|
|
49
|
+
previousValues: payload.previousValues,
|
|
50
|
+
timestamp: payload.timestamp ?? new Date().toISOString(),
|
|
51
|
+
};
|
|
52
|
+
options.onEvent(event);
|
|
53
|
+
},
|
|
54
|
+
error: (err) => {
|
|
55
|
+
if (disposed)
|
|
56
|
+
return;
|
|
57
|
+
options.onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
58
|
+
},
|
|
59
|
+
complete: () => {
|
|
60
|
+
if (disposed)
|
|
61
|
+
return;
|
|
62
|
+
options.onComplete?.();
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
return () => {
|
|
66
|
+
if (disposed)
|
|
67
|
+
return;
|
|
68
|
+
disposed = true;
|
|
69
|
+
this.activeSubscriptions--;
|
|
70
|
+
cleanup();
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Register a listener for connection state changes */
|
|
74
|
+
onConnectionStateChange(listener) {
|
|
75
|
+
this.stateListeners.add(listener);
|
|
76
|
+
return () => {
|
|
77
|
+
this.stateListeners.delete(listener);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Get current connection state */
|
|
81
|
+
getConnectionState() {
|
|
82
|
+
return this.connectionState;
|
|
83
|
+
}
|
|
84
|
+
/** Number of active subscriptions */
|
|
85
|
+
getActiveSubscriptionCount() {
|
|
86
|
+
return this.activeSubscriptions;
|
|
87
|
+
}
|
|
88
|
+
/** Dispose the manager and close the WebSocket connection */
|
|
89
|
+
dispose() {
|
|
90
|
+
this.wsClient.dispose();
|
|
91
|
+
this.stateListeners.clear();
|
|
92
|
+
this.activeSubscriptions = 0;
|
|
93
|
+
this.setConnectionState('disconnected');
|
|
94
|
+
}
|
|
95
|
+
setConnectionState(state) {
|
|
96
|
+
if (this.connectionState === state)
|
|
97
|
+
return;
|
|
98
|
+
this.connectionState = state;
|
|
99
|
+
for (const listener of this.stateListeners) {
|
|
100
|
+
listener(state);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.RealtimeManager = RealtimeManager;
|