22 lines
2.5 KiB
JavaScript
22 lines
2.5 KiB
JavaScript
import {fixture} from './rebellion-fixture.mjs';
|
|
import {initializeClanCharters} from '../node/clan-charters.mjs';
|
|
import {initializePassiveOrders} from '../node/political-passive-orders.mjs';
|
|
import {POLITICAL_APPOINTMENT_SCHEMA} from '../node/political-appointments.mjs';
|
|
import {boardPublicationRecords} from '../node/board-state-keys.mjs';
|
|
export async function boardFixture(){
|
|
const f=await fixture();
|
|
for(const [table,columns]of Object.entries({site_clans:{version:'INTEGER DEFAULT 1',tag:"TEXT DEFAULT 'TEST'",description:"TEXT DEFAULT ''",created_at:'BIGINT DEFAULT 0'},site_clan_members:{joined_at:'BIGINT DEFAULT 1'},site_clan_deeds:{heir_account_id:'TEXT',consort_account_id:'TEXT',heir_joined_at:'BIGINT',consort_joined_at:'BIGINT',envoy_account_id:'TEXT',envoy_joined_at:'BIGINT',arms_account_id:'TEXT',arms_joined_at:'BIGINT',claims_use_mother:'INTEGER DEFAULT 0',primary_color:'TEXT',secondary_color:'TEXT',trim_color:'TEXT'}}))for(const [name,type]of Object.entries(columns))await f.db.query('ALTER TABLE '+table+' ADD COLUMN '+name+' '+type);
|
|
await initializeClanCharters(f.db,{mysql:false});await initializePassiveOrders(f.db);for(const sql of POLITICAL_APPOINTMENT_SCHEMA)await f.db.query(sql);
|
|
const companyId=await f.create(),nativeBoards=new Map();let policy='a'.repeat(64),loseAcknowledgement=false,writes=0,calls=0;
|
|
const native={
|
|
capabilities:async()=>({protocol:1,template:'private-organisation',templateVersion:1,kinds:['clan','company','politics']}),
|
|
inspect:async()=>({protocol:1,groupsRevision:policy}),
|
|
async publish(refs){
|
|
calls++;const verified=await boardPublicationRecords(f.db,refs,{clock:f.now}),records=[];
|
|
for(const row of verified.records){let current=nativeBoards.get(row.keyId);if(!current){const n=nativeBoards.size;current={native:{forumId:50+n,memberGroupId:100+n*2,leaderGroupId:101+n*2}};nativeBoards.set(row.keyId,current);}if(current.revision!==row.revision||current.fingerprint!==row.fingerprint){current.revision=row.revision;current.fingerprint=row.fingerprint;writes++;}records.push({keyId:row.keyId,revision:row.revision,fingerprint:row.fingerprint,state:'applied',native:current.native});}
|
|
if(loseAcknowledgement){loseAcknowledgement=false;throw Error('Acknowledgement lost after native commit');}
|
|
return {protocol:1,groupsRevision:policy,records:[...records,...verified.rejected]};
|
|
}
|
|
};
|
|
return {...f,companyId,native,nativeBoards,nativeWrites:()=>writes,publisherCalls:()=>calls,loseAcknowledgement:()=>loseAcknowledgement=true,changeNativeGroups:()=>policy='b'.repeat(64)};
|
|
}
|

Staff