@volter/teams 0.2.37 → 0.2.38
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 +1 -1
- package/server/core.mjs +1 -1
- package/server/machine-events.mjs +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/teams",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
|
|
6
6
|
"license": "MIT",
|
package/server/core.mjs
CHANGED
|
@@ -64,7 +64,7 @@ export async function maintain(api,{budgetMs=MAINTAIN_BUDGET_MS}={}){const now=a
|
|
|
64
64
|
const failed=[];let more=false;const counts={};
|
|
65
65
|
const left=()=>Date.now()<deadline;
|
|
66
66
|
const q=(sql,params=[])=>api.store.query(sql,params),one=(sql,params=[])=>api.store.one(sql,params),tx=(statements)=>api.store.transaction(statements);
|
|
67
|
-
const step=async(name,work)=>{if(!left()){more=true;return;}try{await work();}catch(error){failed.push(name);console.error(`maintain ${name}: ${error.message}`);}};
|
|
67
|
+
const step=async(name,work)=>{if(!left()){more=true;return;}try{await (api.work?api.work(`maintain.${name}`,work):work());}catch(error){failed.push(name);console.error(`maintain ${name}: ${error.message}`);}};
|
|
68
68
|
const count=(name,n)=>{if(n>0)counts[name]=(counts[name]??0)+n;};
|
|
69
69
|
// Deletes go first, each in a transaction of its own: on a full database an insert fails, and a run that begins with
|
|
70
70
|
// one never reaches the deletes that would make room.
|
|
@@ -4,7 +4,7 @@ import { writeSse, holdStream } from './events.mjs';
|
|
|
4
4
|
export function machineTransition(api, team, machine, linked) {
|
|
5
5
|
// Serialize the read/change/event across asynchronous store calls. A replaced
|
|
6
6
|
// link remains linked; only the current link's close records a departure.
|
|
7
|
-
const
|
|
7
|
+
const work = async () => {
|
|
8
8
|
const row = await api.store.one('SELECT name,revoked_at FROM machines WHERE team_id=? AND id=?', [team, machine]);
|
|
9
9
|
if (!row) return;
|
|
10
10
|
const present = linked ?? api.machineLinks?.has(`${team}\0${machine}`);
|
|
@@ -17,7 +17,8 @@ export function machineTransition(api, team, machine, linked) {
|
|
|
17
17
|
{ sql: 'INSERT INTO machine_presence_events(team_id,machine_id,name,linked,created_at) VALUES (?,?,?,?,?)', params: [team,machine,row.name,value,at] },
|
|
18
18
|
]);
|
|
19
19
|
api.events.publish(team, { type: 'machine_transition' });
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
|
+
const next = (api.machineTransitionWork ?? Promise.resolve()).then(() => api.work ? api.work('machineTransition', work) : work());
|
|
21
22
|
api.machineTransitionWork = next.catch(error => { console.error(`machine transition ${machine}: ${error.message}`); });
|
|
22
23
|
return next;
|
|
23
24
|
}
|