mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
refactor(plugins): install-time gates, the capability-audit hash chain and the registry through repositories
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type BetterSqlite3 from 'better-sqlite3';
|
||||
import type { PluginSettingsFieldsRepository } from '../../db/repositories/PluginSettingsFields.repository';
|
||||
|
||||
/** What a settings-field `default` may be — the JSON scalars the manifest accepts. */
|
||||
export type SettingDefault = string | number | boolean;
|
||||
@@ -32,15 +32,11 @@ export function parseDefaultValue(raw: unknown): SettingDefault | undefined {
|
||||
/** The declared defaults for one plugin and scope, keyed by field. Null-prototype so a
|
||||
* field key can never resolve off Object.prototype (see plugin-config-parse.ts). */
|
||||
export async function settingDefaults(
|
||||
db: BetterSqlite3.Database,
|
||||
settingsFields: PluginSettingsFieldsRepository,
|
||||
pluginId: string,
|
||||
scope: 'instance' | 'user',
|
||||
): Promise<Record<string, SettingDefault>> {
|
||||
const rows = db
|
||||
.prepare(
|
||||
'SELECT field_key, default_value FROM plugin_settings_fields WHERE plugin_id = ? AND scope = ? AND secret = 0 AND default_value IS NOT NULL',
|
||||
)
|
||||
.all(pluginId, scope) as Array<{ field_key: string; default_value: string }>;
|
||||
const rows = await settingsFields.listDefaults(pluginId, scope);
|
||||
const out: Record<string, SettingDefault> = Object.create(null);
|
||||
for (const r of rows) {
|
||||
const v = parseDefaultValue(r.default_value);
|
||||
|
||||
Reference in New Issue
Block a user