@bhooai/nexus-data 0.1.4 → 2.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/package.json +4 -3
- package/src/index.ts +0 -6
- package/src/projects.ts +0 -66
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
2
|
"name": "@bhooai/nexus-data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"test": "vitest run"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@bhooai/nexus-core": "^0.
|
|
21
|
+
"@bhooai/nexus-core": "^2.0.0",
|
|
22
22
|
"mongodb": "^6.9.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
@@ -27,3 +27,4 @@
|
|
|
27
27
|
"vitest": "^2.1.1"
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
|
package/src/index.ts
CHANGED
|
@@ -25,12 +25,6 @@ export {
|
|
|
25
25
|
dropProjectDatabase,
|
|
26
26
|
closeProjectInfo,
|
|
27
27
|
type ProjectInfo,
|
|
28
|
-
type ClusterNodeRecord,
|
|
29
|
-
getClusterNodesCollection,
|
|
30
|
-
upsertClusterNode,
|
|
31
|
-
deleteClusterNode,
|
|
32
|
-
listClusterNodes,
|
|
33
|
-
syncClusterNodes,
|
|
34
28
|
} from './projects.js';
|
|
35
29
|
|
|
36
30
|
let defaultConnection: Connection | undefined;
|
package/src/projects.ts
CHANGED
|
@@ -117,69 +117,3 @@ export async function dropProjectDatabase(dbName: string): Promise<boolean> {
|
|
|
117
117
|
export async function closeProjectInfo(): Promise<void> {
|
|
118
118
|
if (connectionManager.has(CONNECTION_NAME)) await connectionManager.get(CONNECTION_NAME).close();
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
// ── cluster node registry (mirror of cluster.runtime.json in Mongo) ───────
|
|
122
|
-
|
|
123
|
-
const CLUSTER_NODES_COLLECTION = 'cluster_nodes';
|
|
124
|
-
|
|
125
|
-
/** One linked cluster node's registry record (mirrors cluster.runtime.json). */
|
|
126
|
-
export interface ClusterNodeRecord {
|
|
127
|
-
/** Stable node id (e.g. `<host>-<role>`). */
|
|
128
|
-
id: string;
|
|
129
|
-
role: string;
|
|
130
|
-
tier: string;
|
|
131
|
-
version?: string;
|
|
132
|
-
baseUrl: string;
|
|
133
|
-
services?: Record<string, string>;
|
|
134
|
-
status: string;
|
|
135
|
-
enabled: boolean;
|
|
136
|
-
registeredAt: string;
|
|
137
|
-
lastSeenAt: string;
|
|
138
|
-
lastHealth?: unknown;
|
|
139
|
-
lastMetrics?: unknown;
|
|
140
|
-
updatedAt: string;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** The cluster_nodes collection (call `connectProjectInfo` first). */
|
|
144
|
-
export function getClusterNodesCollection(): Promise<Collection<ClusterNodeRecord>> {
|
|
145
|
-
return connectionManager.get(CONNECTION_NAME).db.then((db) => db.collection<ClusterNodeRecord>(CLUSTER_NODES_COLLECTION));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
let clusterNodesIndexEnsured = false;
|
|
149
|
-
|
|
150
|
-
/** Upsert a cluster node record by id (mirrors registry.save for one node). */
|
|
151
|
-
export async function upsertClusterNode(node: ClusterNodeRecord): Promise<void> {
|
|
152
|
-
const coll = await getClusterNodesCollection();
|
|
153
|
-
if (!clusterNodesIndexEnsured) {
|
|
154
|
-
await coll.createIndex({ id: 1 }, { unique: true });
|
|
155
|
-
clusterNodesIndexEnsured = true;
|
|
156
|
-
}
|
|
157
|
-
await coll.updateOne({ id: node.id }, { $set: node }, { upsert: true });
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** Delete a cluster node record by id (mirrors registry.remove). */
|
|
161
|
-
export async function deleteClusterNode(id: string): Promise<boolean> {
|
|
162
|
-
const coll = await getClusterNodesCollection();
|
|
163
|
-
const r = await coll.deleteOne({ id });
|
|
164
|
-
return r.deletedCount > 0;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/** List all cluster node records (mirrors registry.list). */
|
|
168
|
-
export async function listClusterNodes(): Promise<ClusterNodeRecord[]> {
|
|
169
|
-
const coll = await getClusterNodesCollection();
|
|
170
|
-
return coll.find({}).sort({ role: 1, id: 1 }).toArray();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/** Replace all cluster node records (bulk sync — used after a full reload). */
|
|
174
|
-
export async function syncClusterNodes(nodes: ClusterNodeRecord[]): Promise<void> {
|
|
175
|
-
const coll = await getClusterNodesCollection();
|
|
176
|
-
if (!clusterNodesIndexEnsured) {
|
|
177
|
-
await coll.createIndex({ id: 1 }, { unique: true });
|
|
178
|
-
clusterNodesIndexEnsured = true;
|
|
179
|
-
}
|
|
180
|
-
const ops = nodes.map((n) => ({ updateOne: { filter: { id: n.id }, update: { $set: n }, upsert: true } }));
|
|
181
|
-
if (ops.length) await coll.bulkWrite(ops as never);
|
|
182
|
-
// Remove records no longer in the registry.
|
|
183
|
-
const ids = nodes.map((n) => n.id);
|
|
184
|
-
await coll.deleteMany({ id: { $nin: ids } });
|
|
185
|
-
}
|