Spreadsheet-UX op een echte relationele engine
Deze repository wordt als momentopname gepubliceerd: een clone bevat de volledige inhoud, maar geen commitgeschiedenis.
import { buildApp } from './app.js';
import { config } from './config.js';
import { pruneExpiredSessions } from './control/sessions.js';
import { pruneStaleInvites } from './control/invites.js';
import { listAllWorkspaces } from './control/workspaces.js';
import { licenceNotice } from './licence/index.js';
import { openInstallation } from './tenancy/install.js';
const install = openInstallation();
const { control, registry } = install;
if (install.adoption.adopted) {
const workspace = install.adoption.workspace!;
console.log('');
console.log(` Wellformed adopted ${config.legacyDbPath} as its first workspace.`);
console.log(` address: /w/${workspace.slug}`);
console.log(` accounts: ${install.adoption.accountsMoved} moved to the control database`);
console.log(' Everyone signs in with the password they already had.');
console.log('');
}
const app = await buildApp({ control, registry });
const housekeeping = setInterval(
() => {
pruneExpiredSessions(control);
pruneStaleInvites(control);
registry.sweep();
},
10 * 60 * 1000,
);
housekeeping.unref();
async function shutdown(signal: string): Promise<void> {
app.log.info(`${signal} received, shutting down`);
clearInterval(housekeeping);
try {
await app.close();
} finally {
install.close();
}
process.exit(0);
}
for (const signal of ['SIGINT', 'SIGTERM'] as const) {
process.on(signal, () => {
void shutdown(signal);
});
}
try {
await app.listen({ port: config.port, host: config.host });
const origin = `http://${config.host}:${config.port}`;
const workspaces = listAllWorkspaces(control);
console.log(`[wellformed] listening on ${origin}`);
console.log(`[wellformed] control ${config.controlDbPath}`);
console.log(`[wellformed] workspaces ${config.tenantsDir} (${workspaces.length})`);
for (const line of licenceNotice(config.licence)) console.log(line);
if (workspaces.length === 0) {
console.log('');
if (config.signupsOpen) {
console.log(` No workspaces yet. Create the first one at ${origin}/signup`);
} else {
console.log(' No workspaces yet, and signups are closed. Create one with:');
console.log(' npm run provision -- --email you@example.com --password <password>');
}
console.log('');
}
} catch (err) {
app.log.error(err);
install.close();
process.exit(1);
}