@mdrv/db-config 0.2.0
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/bun.lock +15 -0
- package/index.ts +78 -0
- package/package.json +18 -0
package/bun.lock
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 2,
|
|
3
|
+
"configVersion": 1,
|
|
4
|
+
"workspaces": {
|
|
5
|
+
"": {
|
|
6
|
+
"name": "@mdrv/db-config",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"smol-toml": "^1.3.1",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
"packages": {
|
|
13
|
+
"smol-toml": ["smol-toml@1.8.0", "", {}, "sha512-kCZr2V3ch9i00x8zXRhjUNVcjG9ijES5dDudkXvUVCT5QlJNQWElSJdZqyPemffHoLNUYwOcou0Fy+ojN0uHSQ=="],
|
|
14
|
+
}
|
|
15
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mdrv/db-config — typed config + hooks layer.
|
|
3
|
+
* Static fleet config lives in ~/.config/mdrv-db/config.toml (read by
|
|
4
|
+
* @mdrv/db-maintenance); dynamic hooks live in hooks/<slug>.ts and run inside
|
|
5
|
+
* each Bun app. The daemon never executes scripts.
|
|
6
|
+
*/
|
|
7
|
+
import { parse } from 'smol-toml'
|
|
8
|
+
|
|
9
|
+
export type Durability = 'per-write' | 'group-commit-10ms'
|
|
10
|
+
|
|
11
|
+
export interface BackupPolicy {
|
|
12
|
+
cron: string
|
|
13
|
+
retention_days: number
|
|
14
|
+
mode?: 'online-or-offline' | 'online' | 'offline'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Circle membership = AND of label predicates. */
|
|
18
|
+
export interface CircleConfig {
|
|
19
|
+
labels: Array<[string, string]>
|
|
20
|
+
observers: string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface RpcConfig {
|
|
24
|
+
/** Owner app's maintenance endpoint, e.g. http://127.0.0.1:3111/mdrv/rpc */
|
|
25
|
+
url: string
|
|
26
|
+
/** Env var holding the shared token (read by both owner and daemon) */
|
|
27
|
+
token_env: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DbConfig {
|
|
31
|
+
name?: string
|
|
32
|
+
owner: string
|
|
33
|
+
/** Absolute data dir override; default <sched.data_root>/<slug> */
|
|
34
|
+
data_dir?: string
|
|
35
|
+
/** Maintenance RPC on the owner app; absent = offline-only */
|
|
36
|
+
rpc?: RpcConfig
|
|
37
|
+
durability?: Durability
|
|
38
|
+
backup?: BackupPolicy
|
|
39
|
+
verify?: 'weekly' | 'daily' | 'off'
|
|
40
|
+
mid?: {
|
|
41
|
+
admins?: string[]
|
|
42
|
+
session?: { access_ttl_min?: number; refresh_ttl_days?: number; max_per_user?: number }
|
|
43
|
+
mid?: {
|
|
44
|
+
min_len?: number
|
|
45
|
+
max_len?: number
|
|
46
|
+
rename_cooldown_days?: number
|
|
47
|
+
renames_per_period?: number
|
|
48
|
+
period_days?: number
|
|
49
|
+
squat_days?: number
|
|
50
|
+
}
|
|
51
|
+
privacy?: { ip?: 'prefix' | 'none' }
|
|
52
|
+
outbox?: { retention_days?: number }
|
|
53
|
+
circle?: Record<string, CircleConfig>
|
|
54
|
+
}
|
|
55
|
+
[key: string]: unknown
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface MdrvConfig {
|
|
59
|
+
defaults?: { durability?: Durability; verify?: string }
|
|
60
|
+
sched?: { data_root?: string; backup_root?: string }
|
|
61
|
+
db: Record<string, DbConfig>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface MdrvEvent {
|
|
65
|
+
seq: number
|
|
66
|
+
type: string
|
|
67
|
+
member_id: string
|
|
68
|
+
payload: Record<string, unknown>
|
|
69
|
+
created_at: number
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface MdrvHooks {
|
|
73
|
+
onEvent?: (evt: MdrvEvent, mdrv: unknown) => void | Promise<void>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function loadConfig(text: string): MdrvConfig {
|
|
77
|
+
return parse(text) as unknown as MdrvConfig
|
|
78
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdrv/db-config",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Typed config + event hooks for the mdrv-db suite",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"smol-toml": "^1.3.1"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/mdrv/mdrv-db.git",
|
|
13
|
+
"directory": "packages/db-config/package.json"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
}
|
|
18
|
+
}
|