Aller au contenu
Krizaka TS
Krizaka TS

@krizaka/settings

La configuration comme donnée : un registre typé, utilisateur avant espace avant global, chaque changement audité.

Installer

bashTerminal
npm install @krizaka/settings

Le README ci-dessous est celui du paquet sur npm, en anglais.

A product's configuration as data: a typed registry of settings (flags, integers, choices, subsets, bilingual texts), resolved user → workspace → global → default, changed by an administrator without a redeploy, every change leaving an audit line (who, what, when, before, after). A JSON-safe description of the registry is what an admin screen draws from.

import { defineSettings, flag, integer, postgresSettings, settingsMigration, GLOBAL, WORKSPACE_SCOPES } from "@krizaka/settings";

const settings = defineSettings({ "features.apiKeys": flag("features", true, WORKSPACE_SCOPES), "limits.maxFileMb": integer("limits", 10, { min: 1, max: 10, unit: "MB" }) } as const);
await db.query(settingsMigration()); // once, in your migrations (idempotent)
const service = postgresSettings(settings, { query, workspaceOf, clock: () => performance.now() });
await service.get("features.apiKeys", { userId });            // typed: boolean
await service.set({ id: adminId, label: email }, GLOBAL, "features.apiKeys", false, now);

What stays in the product: its registry (the keys, groups, defaults), the checks it makes at its own boundary (« the server refuses what is off »), who may be an administrator, the HTTP routes. The clock is passed in; nothing here reads it.

Exports

Les 36 noms que le paquet exporte, lus dans ses types.

NomNatureCe que c’est
Actortype
ALL_SCOPESconstante
AuditEntrytype
bilingualfonction
choicefonction
Contexttype
Deftype
defineSettingsfonctionThe tools over one registry: what is a key, its definition, the keys of a group.
describeSettingsfonction
flagfonction
GLOBALconstante
GLOBAL_ONLYconstante
integerfonction
KeyOftype
Kindtype
KINDconstante
LayerstypeWhat each scope has set for one key (absent = not overridden there).
postgresSettingsfonctionThe adapter over the product's PostgreSQL (app_settings, settings_audit; see settingsMigration).
PostgresSettingsDepstype
QuerytypeA SQL executor: the rows of a statement and its parameters (the product's pool).
RegistrytypeA registry: keys to definitions (write it as const satisfies Registry to keep the keys and the value types).
Resolvedtype
resolveValuefonctionThe effective value: user, then workspace, then global, then the default.
Scopetype
SCOPEconstanteA product's settings as a typed registry: its key, its type, its default and the scopes it can be overridden at.
ScopeReftype
SCOPES_BY_SPECIFICITYconstanteThe order a value is looked up in: the most specific wins (user, then workspace, then global).
seedLegacySettingsfonctionA deployment that was configured by environment before settings existed keeps behaving the same: at server start, each legacy value that differs from the reg…
SettingDescriptiontypeA setting as an administration screen draws it: JSON-safe (no schema), so it can cross to the browser.
SettingsDefinitiontype
SettingsErrorclasse
settingsMigrationfonctionThe tables of the settings: the overrides (global, for a workspace, for one user — the most specific wins) and the audit of every change (who, what, when, be…
SettingsServicetypeThe service: the app asks for a setting (user, then workspace, then global, then the default); an administrator changes it, every change leaving an audit line.
subsetfonction
ValueOftype
WORKSPACE_SCOPESconstante

Paquet

Version sur npm0.1.0 (npm)
LicenceApache-2.0
Node.js>=22
Dépendancesaucune
Dépendances à fournirzod >=3.23
Code sourcesettings

Journal des versions

0.1.0

Minor changes

  • First release: the typed registry, resolution user > workspace > global > default, the audit of every change, the admin description, the PostgreSQL adapter and its migration.

Sur cette page