agent-relay 2.0.37 → 2.1.1
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/dist/index.cjs +32003 -33977
- package/dist/src/cli/index.js +36 -51
- package/dist/src/cli/index.js.map +1 -1
- package/package.json +18 -19
- package/packages/api-types/package.json +1 -1
- package/packages/benchmark/package.json +4 -4
- package/packages/bridge/package.json +8 -8
- package/packages/cli-tester/package.json +1 -1
- package/packages/config/dist/project-namespace.d.ts +28 -0
- package/packages/config/dist/project-namespace.d.ts.map +1 -1
- package/packages/config/dist/project-namespace.js +42 -0
- package/packages/config/dist/project-namespace.js.map +1 -1
- package/packages/config/package.json +2 -2
- package/packages/config/src/project-namespace.ts +65 -0
- package/packages/continuity/dist/formatter.d.ts +8 -2
- package/packages/continuity/dist/formatter.d.ts.map +1 -1
- package/packages/continuity/dist/formatter.js +142 -7
- package/packages/continuity/dist/formatter.js.map +1 -1
- package/packages/continuity/dist/index.d.ts +1 -0
- package/packages/continuity/dist/index.d.ts.map +1 -1
- package/packages/continuity/dist/index.js +2 -0
- package/packages/continuity/dist/index.js.map +1 -1
- package/packages/continuity/package.json +4 -1
- package/packages/continuity/src/formatter.ts +175 -10
- package/packages/continuity/src/index.ts +3 -0
- package/packages/daemon/dist/enhanced-features.d.ts +2 -3
- package/packages/daemon/dist/enhanced-features.d.ts.map +1 -1
- package/packages/daemon/dist/enhanced-features.js +1 -0
- package/packages/daemon/dist/enhanced-features.js.map +1 -1
- package/packages/daemon/dist/index.d.ts +0 -2
- package/packages/daemon/dist/index.d.ts.map +1 -1
- package/packages/daemon/dist/index.js +0 -3
- package/packages/daemon/dist/index.js.map +1 -1
- package/packages/daemon/dist/server.d.ts +0 -6
- package/packages/daemon/dist/server.d.ts.map +1 -1
- package/packages/daemon/dist/server.js +20 -119
- package/packages/daemon/dist/server.js.map +1 -1
- package/packages/daemon/package.json +12 -14
- package/packages/daemon/src/enhanced-features.ts +4 -4
- package/packages/daemon/src/index.ts +0 -4
- package/packages/daemon/src/server.ts +19 -127
- package/packages/daemon/vitest.config.ts +9 -0
- package/packages/hooks/package.json +4 -4
- package/packages/mcp/package.json +3 -3
- package/packages/memory/package.json +2 -2
- package/packages/policy/package.json +2 -2
- package/packages/protocol/package.json +1 -1
- package/packages/resiliency/package.json +1 -1
- package/packages/sdk/package.json +2 -2
- package/packages/spawner/package.json +1 -1
- package/packages/state/package.json +1 -1
- package/packages/storage/dist/adapter.d.ts +5 -5
- package/packages/storage/dist/adapter.js +9 -9
- package/packages/storage/dist/adapter.js.map +1 -1
- package/packages/storage/package.json +2 -2
- package/packages/storage/src/adapter.ts +9 -9
- package/packages/telemetry/package.json +1 -1
- package/packages/trajectory/package.json +2 -2
- package/packages/user-directory/package.json +2 -2
- package/packages/utils/dist/cjs/relay-pty-path.js +111 -55
- package/packages/utils/dist/relay-pty-path.d.ts +17 -12
- package/packages/utils/dist/relay-pty-path.d.ts.map +1 -1
- package/packages/utils/dist/relay-pty-path.js +144 -94
- package/packages/utils/dist/relay-pty-path.js.map +1 -1
- package/packages/utils/package.json +2 -2
- package/packages/utils/src/relay-pty-path.test.ts +373 -0
- package/packages/utils/src/relay-pty-path.ts +182 -91
- package/packages/wrapper/package.json +6 -6
- package/scripts/build-cjs.mjs +2 -0
- package/packages/daemon/dist/migrations/index.d.ts +0 -73
- package/packages/daemon/dist/migrations/index.d.ts.map +0 -1
- package/packages/daemon/dist/migrations/index.js +0 -241
- package/packages/daemon/dist/migrations/index.js.map +0 -1
- package/packages/daemon/dist/relay-ledger.d.ts +0 -263
- package/packages/daemon/dist/relay-ledger.d.ts.map +0 -1
- package/packages/daemon/dist/relay-ledger.js +0 -538
- package/packages/daemon/dist/relay-ledger.js.map +0 -1
- package/packages/daemon/dist/relay-watchdog.d.ts +0 -125
- package/packages/daemon/dist/relay-watchdog.d.ts.map +0 -1
- package/packages/daemon/dist/relay-watchdog.js +0 -611
- package/packages/daemon/dist/relay-watchdog.js.map +0 -1
- package/packages/daemon/src/migrations/0001_initial.sql +0 -72
- package/packages/daemon/src/migrations/index.test.ts +0 -195
- package/packages/daemon/src/migrations/index.ts +0 -286
- package/packages/daemon/src/relay-ledger.test.ts +0 -358
- package/packages/daemon/src/relay-ledger.ts +0 -713
- package/packages/daemon/src/relay-watchdog.test.ts +0 -881
- package/packages/daemon/src/relay-watchdog.ts +0 -785
|
@@ -5,17 +5,34 @@
|
|
|
5
5
|
* - packages/bridge/src/spawner.ts (AgentSpawner)
|
|
6
6
|
* - packages/wrapper/src/relay-pty-orchestrator.ts (RelayPtyOrchestrator)
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* Supports all installation scenarios:
|
|
9
|
+
* - npx agent-relay (no postinstall, uses platform-specific binary)
|
|
10
|
+
* - npm install -g agent-relay (nvm, volta, fnm, n, asdf, Homebrew, system)
|
|
11
|
+
* - npm install agent-relay (local project)
|
|
12
|
+
* - pnpm/yarn global
|
|
13
|
+
* - Development (monorepo with Rust builds)
|
|
14
|
+
* - Docker containers
|
|
13
15
|
*/
|
|
14
16
|
|
|
15
17
|
import fs from 'node:fs';
|
|
16
18
|
import os from 'node:os';
|
|
17
19
|
import path from 'node:path';
|
|
18
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Supported platforms and their binary names.
|
|
23
|
+
* Windows is not supported (relay-pty requires PTY which doesn't work on Windows).
|
|
24
|
+
*/
|
|
25
|
+
const SUPPORTED_PLATFORMS: Record<string, Record<string, string>> = {
|
|
26
|
+
darwin: {
|
|
27
|
+
arm64: 'relay-pty-darwin-arm64',
|
|
28
|
+
x64: 'relay-pty-darwin-x64',
|
|
29
|
+
},
|
|
30
|
+
linux: {
|
|
31
|
+
arm64: 'relay-pty-linux-arm64',
|
|
32
|
+
x64: 'relay-pty-linux-x64',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
19
36
|
/**
|
|
20
37
|
* Get the platform-specific binary name for the current system.
|
|
21
38
|
* Returns null if the platform is not supported.
|
|
@@ -24,13 +41,29 @@ function getPlatformBinaryName(): string | null {
|
|
|
24
41
|
const platform = os.platform();
|
|
25
42
|
const arch = os.arch();
|
|
26
43
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (platform === 'darwin' && arch === 'x64') return 'relay-pty-darwin-x64';
|
|
30
|
-
if (platform === 'linux' && arch === 'arm64') return 'relay-pty-linux-arm64';
|
|
31
|
-
if (platform === 'linux' && arch === 'x64') return 'relay-pty-linux-x64';
|
|
44
|
+
return SUPPORTED_PLATFORMS[platform]?.[arch] ?? null;
|
|
45
|
+
}
|
|
32
46
|
|
|
33
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Check if the current platform is supported.
|
|
49
|
+
*/
|
|
50
|
+
export function isPlatformSupported(): boolean {
|
|
51
|
+
const platform = os.platform();
|
|
52
|
+
const arch = os.arch();
|
|
53
|
+
return SUPPORTED_PLATFORMS[platform]?.[arch] !== undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get a human-readable description of supported platforms.
|
|
58
|
+
*/
|
|
59
|
+
export function getSupportedPlatforms(): string {
|
|
60
|
+
const platforms: string[] = [];
|
|
61
|
+
for (const [os, archs] of Object.entries(SUPPORTED_PLATFORMS)) {
|
|
62
|
+
for (const arch of Object.keys(archs)) {
|
|
63
|
+
platforms.push(`${os}-${arch}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return platforms.join(', ');
|
|
34
67
|
}
|
|
35
68
|
|
|
36
69
|
/** Cached result of relay-pty binary check */
|
|
@@ -51,13 +84,8 @@ export function getLastSearchPaths(): string[] {
|
|
|
51
84
|
/**
|
|
52
85
|
* Find the relay-pty binary.
|
|
53
86
|
*
|
|
54
|
-
* Search order
|
|
55
|
-
*
|
|
56
|
-
* 2. bin/relay-pty in package root (installed by postinstall)
|
|
57
|
-
* 3. relay-pty/target/release/relay-pty (local Rust build)
|
|
58
|
-
* 4. /usr/local/bin/relay-pty (global install)
|
|
59
|
-
* 5. In node_modules when installed as dependency
|
|
60
|
-
* 6. Global npm installs (nvm) - both scoped and root packages
|
|
87
|
+
* Search order prioritizes platform-specific binaries FIRST because npx doesn't run postinstall.
|
|
88
|
+
* This ensures `npx agent-relay up` works without requiring global installation.
|
|
61
89
|
*
|
|
62
90
|
* @param callerDirname - The __dirname of the calling module (needed to resolve relative paths)
|
|
63
91
|
* @returns Path to relay-pty binary, or null if not found
|
|
@@ -65,99 +93,149 @@ export function getLastSearchPaths(): string[] {
|
|
|
65
93
|
export function findRelayPtyBinary(callerDirname: string): string | null {
|
|
66
94
|
// Check for explicit environment variable override first
|
|
67
95
|
const envOverride = process.env.RELAY_PTY_BINARY;
|
|
68
|
-
if (envOverride &&
|
|
96
|
+
if (envOverride && isExecutable(envOverride)) {
|
|
69
97
|
lastSearchPaths = [envOverride];
|
|
70
98
|
return envOverride;
|
|
71
99
|
}
|
|
72
|
-
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
packageRoot = path.join(callerDirname, '..', '..', '..');
|
|
100
|
+
|
|
101
|
+
// Get platform-specific binary name (critical for npx where postinstall doesn't run)
|
|
102
|
+
const platformBinary = getPlatformBinaryName();
|
|
103
|
+
|
|
104
|
+
// Normalize path separators for cross-platform regex matching
|
|
105
|
+
const normalizedCaller = callerDirname.replace(/\\/g, '/');
|
|
106
|
+
|
|
107
|
+
// Collect all possible package root locations
|
|
108
|
+
const packageRoots: string[] = [];
|
|
109
|
+
|
|
110
|
+
// Find node_modules root from caller path
|
|
111
|
+
// Matches: /path/to/node_modules/@agent-relay/bridge/dist/
|
|
112
|
+
// Or: /path/to/node_modules/agent-relay/dist/src/cli/
|
|
113
|
+
const scopedMatch = normalizedCaller.match(/^(.+?\/node_modules)\/@agent-relay\//);
|
|
114
|
+
const directMatch = normalizedCaller.match(/^(.+?\/node_modules\/agent-relay)/);
|
|
115
|
+
|
|
116
|
+
if (scopedMatch) {
|
|
117
|
+
// Running from @agent-relay/* package - binary is in sibling agent-relay package
|
|
118
|
+
packageRoots.push(path.join(scopedMatch[1], 'agent-relay'));
|
|
92
119
|
}
|
|
93
120
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// Use non-greedy match (.+?) to get the FIRST node_modules, not the last
|
|
98
|
-
let nodeModulesRoot: string | null = null;
|
|
99
|
-
const nodeModulesMatch = callerDirname.match(/^(.+?\/node_modules)\/@agent-relay\//);
|
|
100
|
-
if (nodeModulesMatch) {
|
|
101
|
-
nodeModulesRoot = nodeModulesMatch[1];
|
|
121
|
+
if (directMatch) {
|
|
122
|
+
// Running from agent-relay package directly
|
|
123
|
+
packageRoots.push(directMatch[1]);
|
|
102
124
|
}
|
|
103
125
|
|
|
104
|
-
//
|
|
105
|
-
|
|
126
|
+
// Development: packages/{package}/dist/ -> project root
|
|
127
|
+
if (!normalizedCaller.includes('node_modules')) {
|
|
128
|
+
packageRoots.push(path.join(callerDirname, '..', '..', '..'));
|
|
129
|
+
}
|
|
106
130
|
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
path.join(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// Add candidate for root agent-relay package when running from scoped @agent-relay/* packages
|
|
126
|
-
if (nodeModulesRoot) {
|
|
127
|
-
candidates.push(path.join(nodeModulesRoot, 'agent-relay', 'bin', 'relay-pty'));
|
|
131
|
+
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
132
|
+
|
|
133
|
+
// npx cache locations - npm stores packages here when running via npx
|
|
134
|
+
if (home) {
|
|
135
|
+
const npxCacheBase = path.join(home, '.npm', '_npx');
|
|
136
|
+
if (fs.existsSync(npxCacheBase)) {
|
|
137
|
+
try {
|
|
138
|
+
const entries = fs.readdirSync(npxCacheBase);
|
|
139
|
+
for (const entry of entries) {
|
|
140
|
+
const npxPackage = path.join(npxCacheBase, entry, 'node_modules', 'agent-relay');
|
|
141
|
+
if (fs.existsSync(npxPackage)) {
|
|
142
|
+
packageRoots.push(npxPackage);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
// Ignore read errors
|
|
147
|
+
}
|
|
148
|
+
}
|
|
128
149
|
}
|
|
129
150
|
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
151
|
+
// Add cwd-based paths for local installs
|
|
152
|
+
packageRoots.push(path.join(process.cwd(), 'node_modules', 'agent-relay'));
|
|
153
|
+
|
|
154
|
+
// Global install locations - support ALL major Node version managers
|
|
155
|
+
if (home) {
|
|
156
|
+
// nvm (most common)
|
|
157
|
+
packageRoots.push(
|
|
158
|
+
path.join(home, '.nvm', 'versions', 'node', process.version, 'lib', 'node_modules', 'agent-relay')
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// volta (increasingly popular)
|
|
162
|
+
packageRoots.push(
|
|
163
|
+
path.join(home, '.volta', 'tools', 'image', 'packages', 'agent-relay', 'lib', 'node_modules', 'agent-relay')
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
// fnm (fast Node manager)
|
|
167
|
+
packageRoots.push(
|
|
168
|
+
path.join(home, '.fnm', 'node-versions', process.version, 'installation', 'lib', 'node_modules', 'agent-relay')
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// n (simple Node version manager)
|
|
172
|
+
packageRoots.push(
|
|
173
|
+
path.join(home, 'n', 'lib', 'node_modules', 'agent-relay')
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
// asdf (universal version manager)
|
|
177
|
+
packageRoots.push(
|
|
178
|
+
path.join(home, '.asdf', 'installs', 'nodejs', process.version.replace('v', ''), 'lib', 'node_modules', 'agent-relay')
|
|
179
|
+
);
|
|
180
|
+
|
|
135
181
|
// pnpm global
|
|
136
|
-
|
|
182
|
+
packageRoots.push(
|
|
183
|
+
path.join(home, '.local', 'share', 'pnpm', 'global', 'node_modules', 'agent-relay')
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
// yarn global (yarn 1.x)
|
|
187
|
+
packageRoots.push(
|
|
188
|
+
path.join(home, '.config', 'yarn', 'global', 'node_modules', 'agent-relay')
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// yarn global (alternative location)
|
|
192
|
+
packageRoots.push(
|
|
193
|
+
path.join(home, '.yarn', 'global', 'node_modules', 'agent-relay')
|
|
194
|
+
);
|
|
137
195
|
}
|
|
138
196
|
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
197
|
+
// Homebrew npm (macOS)
|
|
198
|
+
packageRoots.push('/usr/local/lib/node_modules/agent-relay');
|
|
199
|
+
packageRoots.push('/opt/homebrew/lib/node_modules/agent-relay');
|
|
200
|
+
|
|
201
|
+
// Linux system-wide npm
|
|
202
|
+
packageRoots.push('/usr/lib/node_modules/agent-relay');
|
|
203
|
+
|
|
204
|
+
// Build candidates list - PRIORITIZE platform-specific binaries
|
|
205
|
+
// This is critical for npx since postinstall doesn't run
|
|
206
|
+
const candidates: string[] = [];
|
|
207
|
+
|
|
208
|
+
for (const root of packageRoots) {
|
|
209
|
+
// Platform-specific binary FIRST (works without postinstall)
|
|
210
|
+
if (platformBinary) {
|
|
211
|
+
candidates.push(path.join(root, 'bin', platformBinary));
|
|
153
212
|
}
|
|
213
|
+
// Generic binary (requires postinstall to have run)
|
|
214
|
+
candidates.push(path.join(root, 'bin', 'relay-pty'));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Development: local Rust builds
|
|
218
|
+
const devRoot = normalizedCaller.includes('node_modules')
|
|
219
|
+
? null
|
|
220
|
+
: path.join(callerDirname, '..', '..', '..');
|
|
221
|
+
if (devRoot) {
|
|
222
|
+
candidates.push(path.join(devRoot, 'relay-pty', 'target', 'release', 'relay-pty'));
|
|
223
|
+
candidates.push(path.join(devRoot, 'relay-pty', 'target', 'debug', 'relay-pty'));
|
|
154
224
|
}
|
|
225
|
+
candidates.push(path.join(process.cwd(), 'relay-pty', 'target', 'release', 'relay-pty'));
|
|
226
|
+
|
|
227
|
+
// Docker container (CI tests)
|
|
228
|
+
candidates.push('/app/bin/relay-pty');
|
|
229
|
+
|
|
230
|
+
// System-wide installs
|
|
231
|
+
candidates.push('/usr/local/bin/relay-pty');
|
|
232
|
+
candidates.push('/usr/bin/relay-pty');
|
|
155
233
|
|
|
156
234
|
// Store search paths for debugging
|
|
157
235
|
lastSearchPaths = candidates;
|
|
158
236
|
|
|
159
237
|
for (const candidate of candidates) {
|
|
160
|
-
if (
|
|
238
|
+
if (isExecutable(candidate)) {
|
|
161
239
|
return candidate;
|
|
162
240
|
}
|
|
163
241
|
}
|
|
@@ -165,6 +243,19 @@ export function findRelayPtyBinary(callerDirname: string): string | null {
|
|
|
165
243
|
return null;
|
|
166
244
|
}
|
|
167
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Check if a file exists and is executable.
|
|
248
|
+
*/
|
|
249
|
+
function isExecutable(filePath: string): boolean {
|
|
250
|
+
try {
|
|
251
|
+
fs.accessSync(filePath, fs.constants.X_OK);
|
|
252
|
+
return true;
|
|
253
|
+
} catch {
|
|
254
|
+
// File doesn't exist or isn't executable
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
168
259
|
/**
|
|
169
260
|
* Check if relay-pty binary is available (cached).
|
|
170
261
|
* Returns true if the binary exists, false otherwise.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-relay/wrapper",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "CLI agent wrappers for Agent Relay - tmux, pty integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"clean": "rm -rf dist"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@agent-relay/api-types": "2.
|
|
34
|
-
"@agent-relay/protocol": "2.
|
|
35
|
-
"@agent-relay/config": "2.
|
|
36
|
-
"@agent-relay/continuity": "2.
|
|
37
|
-
"@agent-relay/resiliency": "2.
|
|
33
|
+
"@agent-relay/api-types": "2.1.1",
|
|
34
|
+
"@agent-relay/protocol": "2.1.1",
|
|
35
|
+
"@agent-relay/config": "2.1.1",
|
|
36
|
+
"@agent-relay/continuity": "2.1.1",
|
|
37
|
+
"@agent-relay/resiliency": "2.1.1",
|
|
38
38
|
"zod": "^3.23.8"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
package/scripts/build-cjs.mjs
CHANGED
|
@@ -14,6 +14,8 @@ await build({
|
|
|
14
14
|
bundle: true,
|
|
15
15
|
target: 'node18',
|
|
16
16
|
logLevel: 'info',
|
|
17
|
+
// Exclude native dependencies from bundle - they're loaded dynamically at runtime
|
|
18
|
+
external: ['better-sqlite3'],
|
|
17
19
|
banner: {
|
|
18
20
|
js: "const import_meta_url = require('node:url').pathToFileURL(__filename).href;",
|
|
19
21
|
},
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLite Migration Runner for Relay Ledger
|
|
3
|
-
*
|
|
4
|
-
* Provides a lightweight migration system for the relay-ledger.db SQLite database.
|
|
5
|
-
* Tracks applied migrations in a __migrations table and runs them in order.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Sequential migration execution by name
|
|
9
|
-
* - Idempotent (safe to run multiple times)
|
|
10
|
-
* - Tracks applied migrations with timestamps
|
|
11
|
-
* - Embedded SQL for portability (no file dependencies)
|
|
12
|
-
*/
|
|
13
|
-
import type Database from 'better-sqlite3';
|
|
14
|
-
export interface MigrationRecord {
|
|
15
|
-
id: number;
|
|
16
|
-
name: string;
|
|
17
|
-
appliedAt: number;
|
|
18
|
-
checksum: string;
|
|
19
|
-
}
|
|
20
|
-
export interface MigrationFile {
|
|
21
|
-
name: string;
|
|
22
|
-
sql: string;
|
|
23
|
-
checksum: string;
|
|
24
|
-
}
|
|
25
|
-
export interface MigrationResult {
|
|
26
|
-
applied: string[];
|
|
27
|
-
skipped: string[];
|
|
28
|
-
errors: Array<{
|
|
29
|
-
name: string;
|
|
30
|
-
error: string;
|
|
31
|
-
}>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Create the migrations tracking table if it doesn't exist
|
|
35
|
-
*/
|
|
36
|
-
export declare function ensureMigrationsTable(db: Database.Database): void;
|
|
37
|
-
/**
|
|
38
|
-
* Get all applied migrations
|
|
39
|
-
*/
|
|
40
|
-
export declare function getAppliedMigrations(db: Database.Database): MigrationRecord[];
|
|
41
|
-
/**
|
|
42
|
-
* Check if a specific migration has been applied
|
|
43
|
-
*/
|
|
44
|
-
export declare function isMigrationApplied(db: Database.Database, name: string): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Record a migration as applied
|
|
47
|
-
*/
|
|
48
|
-
export declare function recordMigration(db: Database.Database, name: string, checksum: string): void;
|
|
49
|
-
/**
|
|
50
|
-
* Calculate a simple checksum for migration content
|
|
51
|
-
*/
|
|
52
|
-
export declare function calculateChecksum(sql: string): string;
|
|
53
|
-
/**
|
|
54
|
-
* Load migrations from embedded definitions
|
|
55
|
-
*/
|
|
56
|
-
export declare function loadMigrationFiles(): MigrationFile[];
|
|
57
|
-
/**
|
|
58
|
-
* Run all pending migrations
|
|
59
|
-
*/
|
|
60
|
-
export declare function runMigrations(db: Database.Database): MigrationResult;
|
|
61
|
-
/**
|
|
62
|
-
* Get pending migrations that haven't been applied yet
|
|
63
|
-
*/
|
|
64
|
-
export declare function getPendingMigrations(db: Database.Database): MigrationFile[];
|
|
65
|
-
/**
|
|
66
|
-
* Verify migration checksums match what was originally applied
|
|
67
|
-
*/
|
|
68
|
-
export declare function verifyMigrations(db: Database.Database): Array<{
|
|
69
|
-
name: string;
|
|
70
|
-
expected: string;
|
|
71
|
-
actual: string;
|
|
72
|
-
}>;
|
|
73
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAM3C,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AAsGD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CASjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,eAAe,EAAE,CAW7E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAG/E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAI3F;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CASrD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,aAAa,EAAE,CAMpD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,eAAe,CAwCpE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,aAAa,EAAE,CAI3E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAkBjH"}
|