@hivemagnus/ardent-studio 0.0.0-stage → 0.1.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.
Files changed (159) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +12 -0
  3. package/README.md +133 -2
  4. package/dist/agents/config-edit.d.ts +20 -0
  5. package/dist/agents/config-edit.js +75 -0
  6. package/dist/agents/directory.d.ts +27 -0
  7. package/dist/agents/directory.js +97 -0
  8. package/dist/agents/operations.d.ts +47 -0
  9. package/dist/agents/operations.js +93 -0
  10. package/dist/auth/links.d.ts +27 -0
  11. package/dist/auth/links.js +46 -0
  12. package/dist/auth/oathweave.d.ts +46 -0
  13. package/dist/auth/oathweave.js +123 -0
  14. package/dist/blobs/store.d.ts +45 -0
  15. package/dist/blobs/store.js +159 -0
  16. package/dist/clients/chattermost.d.ts +16 -0
  17. package/dist/clients/chattermost.js +36 -0
  18. package/dist/clients/hivemem.d.ts +85 -0
  19. package/dist/clients/hivemem.js +89 -0
  20. package/dist/clients/magnus.d.ts +851 -0
  21. package/dist/clients/magnus.js +541 -0
  22. package/dist/clients/service-token.d.ts +24 -0
  23. package/dist/clients/service-token.js +87 -0
  24. package/dist/clients/sse.d.ts +8 -0
  25. package/dist/clients/sse.js +42 -0
  26. package/dist/conductor/activity.d.ts +38 -0
  27. package/dist/conductor/activity.js +101 -0
  28. package/dist/conductor/addressing.d.ts +24 -0
  29. package/dist/conductor/addressing.js +42 -0
  30. package/dist/conductor/conductor.d.ts +225 -0
  31. package/dist/conductor/conductor.js +939 -0
  32. package/dist/conductor/follower.d.ts +48 -0
  33. package/dist/conductor/follower.js +154 -0
  34. package/dist/conductor/live.d.ts +23 -0
  35. package/dist/conductor/live.js +32 -0
  36. package/dist/conductor/prompting.d.ts +74 -0
  37. package/dist/conductor/prompting.js +177 -0
  38. package/dist/config.d.ts +52 -0
  39. package/dist/config.js +163 -0
  40. package/dist/db/database.d.ts +12 -0
  41. package/dist/db/database.js +62 -0
  42. package/dist/db/json.d.ts +8 -0
  43. package/dist/db/json.js +13 -0
  44. package/dist/db/migrations.d.ts +6 -0
  45. package/dist/db/migrations.js +571 -0
  46. package/dist/db/repos/agents.d.ts +86 -0
  47. package/dist/db/repos/agents.js +92 -0
  48. package/dist/db/repos/audit.d.ts +37 -0
  49. package/dist/db/repos/audit.js +20 -0
  50. package/dist/db/repos/events.d.ts +29 -0
  51. package/dist/db/repos/events.js +55 -0
  52. package/dist/db/repos/files.d.ts +41 -0
  53. package/dist/db/repos/files.js +72 -0
  54. package/dist/db/repos/idempotency.d.ts +27 -0
  55. package/dist/db/repos/idempotency.js +46 -0
  56. package/dist/db/repos/links.d.ts +47 -0
  57. package/dist/db/repos/links.js +99 -0
  58. package/dist/db/repos/projects.d.ts +44 -0
  59. package/dist/db/repos/projects.js +107 -0
  60. package/dist/db/repos/proposals.d.ts +46 -0
  61. package/dist/db/repos/proposals.js +65 -0
  62. package/dist/db/repos/review.d.ts +191 -0
  63. package/dist/db/repos/review.js +195 -0
  64. package/dist/db/repos/room.d.ts +163 -0
  65. package/dist/db/repos/room.js +151 -0
  66. package/dist/db/repos/sessions.d.ts +36 -0
  67. package/dist/db/repos/sessions.js +30 -0
  68. package/dist/db/repos/summaries.d.ts +22 -0
  69. package/dist/db/repos/summaries.js +105 -0
  70. package/dist/db/repos/tasks.d.ts +103 -0
  71. package/dist/db/repos/tasks.js +112 -0
  72. package/dist/db/repos/team.d.ts +49 -0
  73. package/dist/db/repos/team.js +95 -0
  74. package/dist/db/repos/templates.d.ts +55 -0
  75. package/dist/db/repos/templates.js +120 -0
  76. package/dist/db/store.d.ts +57 -0
  77. package/dist/db/store.js +108 -0
  78. package/dist/events/bus.d.ts +21 -0
  79. package/dist/events/bus.js +31 -0
  80. package/dist/events/types.d.ts +3 -0
  81. package/dist/events/types.js +1 -0
  82. package/dist/ids.d.ts +28 -0
  83. package/dist/ids.js +81 -0
  84. package/dist/index.d.ts +18 -0
  85. package/dist/index.js +17 -0
  86. package/dist/knowledge/extract.d.ts +17 -0
  87. package/dist/knowledge/extract.js +82 -0
  88. package/dist/knowledge/sync.d.ts +40 -0
  89. package/dist/knowledge/sync.js +172 -0
  90. package/dist/logger.d.ts +5 -0
  91. package/dist/logger.js +11 -0
  92. package/dist/main.d.ts +2 -0
  93. package/dist/main.js +42 -0
  94. package/dist/review/anchors.d.ts +16 -0
  95. package/dist/review/anchors.js +67 -0
  96. package/dist/review/context.d.ts +4 -0
  97. package/dist/review/context.js +29 -0
  98. package/dist/review/docx.d.ts +29 -0
  99. package/dist/review/docx.js +21 -0
  100. package/dist/review/export.d.ts +16 -0
  101. package/dist/review/export.js +84 -0
  102. package/dist/review/importer.d.ts +68 -0
  103. package/dist/review/importer.js +215 -0
  104. package/dist/review/index.d.ts +13 -0
  105. package/dist/review/index.js +7 -0
  106. package/dist/server/app.d.ts +5 -0
  107. package/dist/server/app.js +44 -0
  108. package/dist/server/deps.d.ts +43 -0
  109. package/dist/server/deps.js +17 -0
  110. package/dist/server/env.d.ts +6 -0
  111. package/dist/server/env.js +1 -0
  112. package/dist/server/errors.d.ts +12 -0
  113. package/dist/server/errors.js +25 -0
  114. package/dist/server/routes/agent-studio.d.ts +5 -0
  115. package/dist/server/routes/agent-studio.js +441 -0
  116. package/dist/server/routes/agents.d.ts +3 -0
  117. package/dist/server/routes/agents.js +4 -0
  118. package/dist/server/routes/files.d.ts +3 -0
  119. package/dist/server/routes/files.js +88 -0
  120. package/dist/server/routes/health.d.ts +3 -0
  121. package/dist/server/routes/health.js +31 -0
  122. package/dist/server/routes/links.d.ts +3 -0
  123. package/dist/server/routes/links.js +79 -0
  124. package/dist/server/routes/projects.d.ts +3 -0
  125. package/dist/server/routes/projects.js +119 -0
  126. package/dist/server/routes/review.d.ts +3 -0
  127. package/dist/server/routes/review.js +198 -0
  128. package/dist/server/routes/room.d.ts +9 -0
  129. package/dist/server/routes/room.js +224 -0
  130. package/dist/server/routes/stream.d.ts +4 -0
  131. package/dist/server/routes/stream.js +104 -0
  132. package/dist/server/routes/team.d.ts +3 -0
  133. package/dist/server/routes/team.js +183 -0
  134. package/dist/server/routes/templates.d.ts +11 -0
  135. package/dist/server/routes/templates.js +103 -0
  136. package/dist/server/routes/work.d.ts +3 -0
  137. package/dist/server/routes/work.js +139 -0
  138. package/dist/server/routing.d.ts +31 -0
  139. package/dist/server/routing.js +132 -0
  140. package/dist/service.d.ts +34 -0
  141. package/dist/service.js +93 -0
  142. package/dist/shared/browser.d.ts +5824 -0
  143. package/dist/shared/browser.js +1318 -0
  144. package/dist/team/proposals.d.ts +129 -0
  145. package/dist/team/proposals.js +349 -0
  146. package/dist/team/service.d.ts +12 -0
  147. package/dist/team/service.js +13 -0
  148. package/dist/team/validation.d.ts +37 -0
  149. package/dist/team/validation.js +157 -0
  150. package/dist/templates/secrets.d.ts +2 -0
  151. package/dist/templates/secrets.js +23 -0
  152. package/dist/templates/seeds.d.ts +34 -0
  153. package/dist/templates/seeds.js +277 -0
  154. package/dist/url.d.ts +2 -0
  155. package/dist/url.js +7 -0
  156. package/dist/version.d.ts +2 -0
  157. package/dist/version.js +11 -0
  158. package/docs/openapi-browser.json +12658 -0
  159. package/package.json +91 -4
package/dist/config.js ADDED
@@ -0,0 +1,163 @@
1
+ import { isAbsolute, resolve } from 'node:path';
2
+ import { z } from 'zod';
3
+ import { parseIdentityLinks } from './auth/links.js';
4
+ import { trimTrailingSlashes } from './url.js';
5
+ export const DEFAULT_PORT = 8097;
6
+ export const DEFAULT_MAX_BLOB_BYTES = 64 * 1024 * 1024;
7
+ export const DEFAULT_EVENT_RETENTION_DAYS = 30;
8
+ export class ConfigError extends Error {
9
+ issues;
10
+ constructor(issues) {
11
+ super(`Invalid ArdentStudio configuration:\n${issues.map(issue => ` ${issue.name}: ${issue.message}`).join('\n')}`);
12
+ this.issues = issues;
13
+ this.name = 'ConfigError';
14
+ }
15
+ }
16
+ /** Every variable the service reads. Secrets are marked so tooling never prints their values. */
17
+ export const ENV_CATALOG = [
18
+ { name: 'ARDENT_STUDIO_DATA', required: true, secret: false, description: 'Data directory holding studio.sqlite and blobs/. The container uses /data.' },
19
+ { name: 'ARDENT_STUDIO_HOST', required: false, secret: false, description: 'Listen address. Default 127.0.0.1; the container uses 0.0.0.0.' },
20
+ { name: 'ARDENT_STUDIO_PORT', required: false, secret: false, description: `Listen port. Default ${DEFAULT_PORT}.` },
21
+ { name: 'ARDENT_STUDIO_MAX_BLOB_BYTES', required: false, secret: false, description: 'Largest stored file in bytes. Default 67108864 (64 MiB).' },
22
+ { name: 'ARDENT_STUDIO_EVENT_RETENTION_DAYS', required: false, secret: false, description: 'Days of project events kept for stream replay. Default 30.' },
23
+ { name: 'ARDENT_STUDIO_LOG_LEVEL', required: false, secret: false, description: 'debug, info, warn or error. Default info.' },
24
+ { name: 'OATHWEAVE_ISSUER', required: true, secret: false, description: 'Oathweave browser issuer (HTTPS).' },
25
+ { name: 'OATHWEAVE_JWKS_URL', required: true, secret: false, description: 'Oathweave JWKS URL (HTTPS).' },
26
+ { name: 'OATHWEAVE_USERINFO_URL', required: true, secret: false, description: 'Oathweave userinfo URL (HTTPS), used for online session revocation.' },
27
+ { name: 'ARDENT_STUDIO_OATHWEAVE_IDENTITIES_JSON', required: true, secret: false, description: 'JSON array of explicit account links: [{issuer, subject, localUserId, displayName?, permissions?}].' },
28
+ { name: 'ARDENT_STUDIO_OATHWEAVE_TOKEN_URL', required: true, secret: false, description: 'Oathweave OAuth token endpoint for the client_credentials grant.' },
29
+ { name: 'ARDENT_STUDIO_MAGNUS_URL', required: true, secret: false, description: 'Magnus control API base URL (the origin that serves /api/v1).' },
30
+ { name: 'ARDENT_STUDIO_MAGNUS_CLIENT_ID', required: true, secret: false, description: 'Oathweave machine client whose tokens carry the audience magnus.' },
31
+ { name: 'ARDENT_STUDIO_MAGNUS_CLIENT_SECRET', required: true, secret: true, description: 'Secret of the Magnus machine client.' },
32
+ { name: 'ARDENT_STUDIO_MAGNUS_SCOPE', required: false, secret: false, description: 'Scope for Magnus service tokens. Default magnus:ardent.' },
33
+ { name: 'ARDENT_STUDIO_HIVEMEM_URL', required: true, secret: false, description: 'HiveMem base URL (the origin that serves /v1).' },
34
+ { name: 'ARDENT_STUDIO_HIVEMEM_CLIENT_ID', required: true, secret: false, description: 'Oathweave machine client whose tokens carry the audience hivemem.' },
35
+ { name: 'ARDENT_STUDIO_HIVEMEM_CLIENT_SECRET', required: true, secret: true, description: 'Secret of the HiveMem machine client.' },
36
+ { name: 'ARDENT_STUDIO_HIVEMEM_SCOPE', required: false, secret: false, description: 'Scope for HiveMem service tokens. Default "hivemem:workspaces:write hivemem:memories:write".' },
37
+ { name: 'ARDENT_STUDIO_CHATTERMOST_WEBHOOK_URL', required: false, secret: true, description: 'Optional ChatterMost incoming-webhook URL for one-way announcements. The URL contains its secret.' },
38
+ { name: 'ARDENT_STUDIO_ALLOW_PLAINTEXT_SERVICES', required: false, secret: false, description: 'true allows http:// service URLs on non-loopback hosts (isolated container networks only). Default false.' },
39
+ ];
40
+ const LOOPBACK = new Set(['127.0.0.1', '::1', '[::1]', 'localhost']);
41
+ function urlIssue(value, options) {
42
+ let url;
43
+ try {
44
+ url = new URL(value);
45
+ }
46
+ catch {
47
+ return 'must be an absolute URL';
48
+ }
49
+ if (url.username || url.password)
50
+ return 'must not contain credentials';
51
+ if (url.hash)
52
+ return 'must not contain a fragment';
53
+ if (url.protocol === 'https:')
54
+ return undefined;
55
+ if (url.protocol !== 'http:')
56
+ return 'must use https';
57
+ if (options.httpsOnly)
58
+ return 'must use https';
59
+ if (LOOPBACK.has(url.hostname) || options.allowPlaintext)
60
+ return undefined;
61
+ return 'must use https (http is accepted only for loopback hosts or with ARDENT_STUDIO_ALLOW_PLAINTEXT_SERVICES=true)';
62
+ }
63
+ const integer = (min, max) => z.string().regex(/^\d+$/).transform(Number).pipe(z.number().int().min(min).max(max));
64
+ /** Read and validate the environment. Throws ConfigError naming every problem; values are never echoed. */
65
+ export function loadConfig(env = process.env) {
66
+ const issues = [];
67
+ const value = (name) => {
68
+ const raw = env[name];
69
+ return raw === undefined || raw.trim() === '' ? undefined : raw.trim();
70
+ };
71
+ const required = (name) => {
72
+ const raw = value(name);
73
+ if (raw === undefined)
74
+ issues.push({ name, message: 'is required' });
75
+ return raw ?? '';
76
+ };
77
+ const numeric = (name, fallback, min, max) => {
78
+ const raw = value(name);
79
+ if (raw === undefined)
80
+ return fallback;
81
+ const parsed = integer(min, max).safeParse(raw);
82
+ if (!parsed.success) {
83
+ issues.push({ name, message: `must be an integer from ${min} to ${max}` });
84
+ return fallback;
85
+ }
86
+ return parsed.data;
87
+ };
88
+ const allowPlaintext = value('ARDENT_STUDIO_ALLOW_PLAINTEXT_SERVICES') === 'true';
89
+ const url = (name, httpsOnly, exact = false) => {
90
+ const raw = required(name);
91
+ if (!raw)
92
+ return raw;
93
+ const problem = urlIssue(raw, { httpsOnly, allowPlaintext });
94
+ if (problem)
95
+ issues.push({ name, message: problem });
96
+ return exact ? raw : trimTrailingSlashes(raw);
97
+ };
98
+ const dataRaw = required('ARDENT_STUDIO_DATA');
99
+ if (dataRaw && !isAbsolute(dataRaw))
100
+ issues.push({ name: 'ARDENT_STUDIO_DATA', message: 'must be an absolute path' });
101
+ const logLevel = value('ARDENT_STUDIO_LOG_LEVEL') ?? 'info';
102
+ if (!['debug', 'info', 'warn', 'error'].includes(logLevel))
103
+ issues.push({ name: 'ARDENT_STUDIO_LOG_LEVEL', message: 'must be debug, info, warn or error' });
104
+ const issuer = url('OATHWEAVE_ISSUER', true, true);
105
+ const jwksUrl = url('OATHWEAVE_JWKS_URL', true);
106
+ const userinfoUrl = url('OATHWEAVE_USERINFO_URL', true);
107
+ const tokenUrl = url('ARDENT_STUDIO_OATHWEAVE_TOKEN_URL', false);
108
+ let identities = [];
109
+ const identitiesRaw = required('ARDENT_STUDIO_OATHWEAVE_IDENTITIES_JSON');
110
+ if (identitiesRaw) {
111
+ try {
112
+ identities = parseIdentityLinks(identitiesRaw);
113
+ // Compared exactly, as tokens carry it.
114
+ if (issuer && identities.some(link => link.issuer !== issuer)) {
115
+ issues.push({ name: 'ARDENT_STUDIO_OATHWEAVE_IDENTITIES_JSON', message: 'every link issuer must exactly equal OATHWEAVE_ISSUER' });
116
+ }
117
+ }
118
+ catch (error) {
119
+ issues.push({ name: 'ARDENT_STUDIO_OATHWEAVE_IDENTITIES_JSON', message: error instanceof Error && error.name === 'IdentityLinkError'
120
+ ? error.message : 'must be a JSON array of {issuer, subject, localUserId, displayName?, permissions?}' });
121
+ }
122
+ }
123
+ const defaultScopes = { MAGNUS: 'magnus:ardent', HIVEMEM: 'hivemem:workspaces:write hivemem:memories:write' };
124
+ const service = (prefix) => ({
125
+ url: url(`ARDENT_STUDIO_${prefix}_URL`, false),
126
+ clientId: required(`ARDENT_STUDIO_${prefix}_CLIENT_ID`),
127
+ clientSecret: required(`ARDENT_STUDIO_${prefix}_CLIENT_SECRET`),
128
+ scope: value(`ARDENT_STUDIO_${prefix}_SCOPE`) ?? defaultScopes[prefix],
129
+ });
130
+ const magnus = service('MAGNUS');
131
+ const hivemem = service('HIVEMEM');
132
+ for (const [name, id] of [['ARDENT_STUDIO_MAGNUS_CLIENT_ID', magnus.clientId], ['ARDENT_STUDIO_HIVEMEM_CLIENT_ID', hivemem.clientId]]) {
133
+ if (id && !/^[A-Za-z0-9_-]{1,100}$/.test(id))
134
+ issues.push({ name, message: 'must be an Oathweave client ID ([A-Za-z0-9_-], at most 100)' });
135
+ }
136
+ let chattermost;
137
+ const webhook = value('ARDENT_STUDIO_CHATTERMOST_WEBHOOK_URL');
138
+ if (webhook) {
139
+ const problem = urlIssue(webhook, { httpsOnly: false, allowPlaintext });
140
+ if (problem)
141
+ issues.push({ name: 'ARDENT_STUDIO_CHATTERMOST_WEBHOOK_URL', message: problem });
142
+ else if (!/\/hooks\/|\/webhooks\/incoming\//.test(new URL(webhook).pathname)) {
143
+ issues.push({ name: 'ARDENT_STUDIO_CHATTERMOST_WEBHOOK_URL', message: 'must be an incoming-webhook URL' });
144
+ }
145
+ else
146
+ chattermost = { webhookUrl: webhook };
147
+ }
148
+ const config = {
149
+ host: value('ARDENT_STUDIO_HOST') ?? '127.0.0.1',
150
+ port: numeric('ARDENT_STUDIO_PORT', DEFAULT_PORT, 1, 65535),
151
+ dataDir: dataRaw ? resolve(dataRaw) : '',
152
+ maxBlobBytes: numeric('ARDENT_STUDIO_MAX_BLOB_BYTES', DEFAULT_MAX_BLOB_BYTES, 1024, 1024 * 1024 * 1024),
153
+ eventRetentionDays: numeric('ARDENT_STUDIO_EVENT_RETENTION_DAYS', DEFAULT_EVENT_RETENTION_DAYS, 1, 3650),
154
+ logLevel: logLevel,
155
+ oathweave: { issuer, jwksUrl, userinfoUrl, tokenUrl, identities },
156
+ magnus,
157
+ hivemem,
158
+ chattermost,
159
+ };
160
+ if (issues.length)
161
+ throw new ConfigError(issues);
162
+ return config;
163
+ }
@@ -0,0 +1,12 @@
1
+ import Database from 'better-sqlite3';
2
+ import { type Migration } from './migrations.js';
3
+ export type Db = Database.Database;
4
+ export declare class MigrationError extends Error {
5
+ name: string;
6
+ }
7
+ export declare function migrationChecksum(migration: Migration): string;
8
+ /** Open the database (WAL, foreign keys) and apply pending migrations. */
9
+ export declare function openDatabase(path: string, migrations?: readonly Migration[]): Db;
10
+ /** Apply pending migrations in order, each in its own transaction. Refuses changed or unknown history. */
11
+ export declare function migrate(db: Db, migrations?: readonly Migration[]): number[];
12
+ export declare function schemaVersion(db: Db): number;
@@ -0,0 +1,62 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { chmodSync, mkdirSync } from 'node:fs';
3
+ import { dirname } from 'node:path';
4
+ import Database from 'better-sqlite3';
5
+ import { MIGRATIONS } from './migrations.js';
6
+ export class MigrationError extends Error {
7
+ name = 'MigrationError';
8
+ }
9
+ export function migrationChecksum(migration) {
10
+ return createHash('sha256').update(`${migration.id}\n${migration.name}\n${migration.sql}`).digest('hex');
11
+ }
12
+ /** Open the database (WAL, foreign keys) and apply pending migrations. */
13
+ export function openDatabase(path, migrations = MIGRATIONS) {
14
+ if (path !== ':memory:')
15
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
16
+ const db = new Database(path);
17
+ try {
18
+ if (path !== ':memory:')
19
+ chmodSync(path, 0o600);
20
+ db.pragma('journal_mode = WAL');
21
+ db.pragma('synchronous = FULL');
22
+ db.pragma('foreign_keys = ON');
23
+ db.pragma('busy_timeout = 5000');
24
+ migrate(db, migrations);
25
+ return db;
26
+ }
27
+ catch (error) {
28
+ db.close();
29
+ throw error;
30
+ }
31
+ }
32
+ /** Apply pending migrations in order, each in its own transaction. Refuses changed or unknown history. */
33
+ export function migrate(db, migrations = MIGRATIONS) {
34
+ for (const [index, migration] of migrations.entries()) {
35
+ if (migration.id !== index + 1)
36
+ throw new MigrationError('Migrations must be numbered 1, 2, 3, … without gaps');
37
+ }
38
+ db.exec(`CREATE TABLE IF NOT EXISTS schema_migrations (
39
+ id INTEGER PRIMARY KEY, name TEXT NOT NULL, checksum TEXT NOT NULL, applied_at TEXT NOT NULL)`);
40
+ const applied = db.prepare('SELECT id, name, checksum FROM schema_migrations ORDER BY id').all();
41
+ for (const row of applied) {
42
+ const known = migrations[row.id - 1];
43
+ if (!known)
44
+ throw new MigrationError(`Database has migration ${row.id} (${row.name}), which this version does not know. Upgrade ArdentStudio instead of downgrading.`);
45
+ if (migrationChecksum(known) !== row.checksum)
46
+ throw new MigrationError(`Migration ${row.id} (${row.name}) differs from the one applied to this database`);
47
+ }
48
+ const ran = [];
49
+ const record = db.prepare('INSERT INTO schema_migrations (id, name, checksum, applied_at) VALUES (?, ?, ?, ?)');
50
+ for (const migration of migrations.slice(applied.length)) {
51
+ db.transaction(() => {
52
+ db.exec(migration.sql);
53
+ record.run(migration.id, migration.name, migrationChecksum(migration), new Date().toISOString());
54
+ })();
55
+ ran.push(migration.id);
56
+ }
57
+ return ran;
58
+ }
59
+ export function schemaVersion(db) {
60
+ const row = db.prepare('SELECT MAX(id) AS id FROM schema_migrations').get();
61
+ return row.id ?? 0;
62
+ }
@@ -0,0 +1,8 @@
1
+ /** JSON columns hold values this service wrote, validated when they came in. */
2
+ export declare function readJson<T>(text: string | null | undefined, fallback: T): T;
3
+ export declare function writeJson(value: unknown): string;
4
+ export interface Clock {
5
+ now(): Date;
6
+ }
7
+ export declare const systemClock: Clock;
8
+ export declare function iso(clock: Clock): string;
@@ -0,0 +1,13 @@
1
+ /** JSON columns hold values this service wrote, validated when they came in. */
2
+ export function readJson(text, fallback) {
3
+ if (text === null || text === undefined || text === '')
4
+ return fallback;
5
+ return JSON.parse(text);
6
+ }
7
+ export function writeJson(value) {
8
+ return JSON.stringify(value);
9
+ }
10
+ export const systemClock = { now: () => new Date() };
11
+ export function iso(clock) {
12
+ return clock.now().toISOString();
13
+ }
@@ -0,0 +1,6 @@
1
+ export interface Migration {
2
+ id: number;
3
+ name: string;
4
+ sql: string;
5
+ }
6
+ export declare const MIGRATIONS: readonly Migration[];