spindb 0.3.6 → 0.4.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.
@@ -0,0 +1,358 @@
1
+ /**
2
+ * OS-level dependency registry for database engines
3
+ *
4
+ * This module defines the system packages required for each database engine
5
+ * across different operating systems and package managers.
6
+ */
7
+
8
+ export type PackageManagerId = 'brew' | 'apt' | 'yum' | 'dnf' | 'pacman'
9
+
10
+ export type Platform = 'darwin' | 'linux'
11
+
12
+ /**
13
+ * Package definition for a specific package manager
14
+ */
15
+ export type PackageDefinition = {
16
+ /** Package name to install */
17
+ package: string
18
+ /** Optional post-install commands (e.g., brew link) */
19
+ postInstall?: string[]
20
+ /** Optional pre-install commands */
21
+ preInstall?: string[]
22
+ }
23
+
24
+ /**
25
+ * A single dependency (e.g., psql, pg_dump)
26
+ */
27
+ export type Dependency = {
28
+ /** Human-readable name */
29
+ name: string
30
+ /** Binary name to check for in PATH */
31
+ binary: string
32
+ /** Description of what this tool does */
33
+ description: string
34
+ /** Package definitions per package manager */
35
+ packages: Partial<Record<PackageManagerId, PackageDefinition>>
36
+ /** Alternative installation instructions when no package manager is available */
37
+ manualInstall: Partial<Record<Platform, string[]>>
38
+ }
39
+
40
+ /**
41
+ * Engine dependency configuration
42
+ */
43
+ export type EngineDependencies = {
44
+ /** Engine identifier */
45
+ engine: string
46
+ /** Human-readable engine name */
47
+ displayName: string
48
+ /** List of dependencies for this engine */
49
+ dependencies: Dependency[]
50
+ }
51
+
52
+ /**
53
+ * Package manager configuration
54
+ */
55
+ export type PackageManagerConfig = {
56
+ id: PackageManagerId
57
+ name: string
58
+ /** Command to check if this package manager is installed */
59
+ checkCommand: string
60
+ /** Platforms this package manager is available on */
61
+ platforms: Platform[]
62
+ /** Command template to install a package */
63
+ installTemplate: string
64
+ /** Command template to update/upgrade a package */
65
+ updateTemplate: string
66
+ }
67
+
68
+ // =============================================================================
69
+ // Package Manager Definitions
70
+ // =============================================================================
71
+
72
+ export const packageManagers: PackageManagerConfig[] = [
73
+ {
74
+ id: 'brew',
75
+ name: 'Homebrew',
76
+ checkCommand: 'brew --version',
77
+ platforms: ['darwin'],
78
+ installTemplate: 'brew install {package}',
79
+ updateTemplate: 'brew upgrade {package}',
80
+ },
81
+ {
82
+ id: 'apt',
83
+ name: 'APT',
84
+ checkCommand: 'apt --version',
85
+ platforms: ['linux'],
86
+ installTemplate: 'sudo apt update && sudo apt install -y {package}',
87
+ updateTemplate: 'sudo apt update && sudo apt upgrade -y {package}',
88
+ },
89
+ {
90
+ id: 'yum',
91
+ name: 'YUM',
92
+ checkCommand: 'yum --version',
93
+ platforms: ['linux'],
94
+ installTemplate: 'sudo yum install -y {package}',
95
+ updateTemplate: 'sudo yum update -y {package}',
96
+ },
97
+ {
98
+ id: 'dnf',
99
+ name: 'DNF',
100
+ checkCommand: 'dnf --version',
101
+ platforms: ['linux'],
102
+ installTemplate: 'sudo dnf install -y {package}',
103
+ updateTemplate: 'sudo dnf upgrade -y {package}',
104
+ },
105
+ {
106
+ id: 'pacman',
107
+ name: 'Pacman',
108
+ checkCommand: 'pacman --version',
109
+ platforms: ['linux'],
110
+ installTemplate: 'sudo pacman -S --noconfirm {package}',
111
+ updateTemplate: 'sudo pacman -Syu --noconfirm {package}',
112
+ },
113
+ ]
114
+
115
+ // =============================================================================
116
+ // PostgreSQL Dependencies
117
+ // =============================================================================
118
+
119
+ const postgresqlDependencies: EngineDependencies = {
120
+ engine: 'postgresql',
121
+ displayName: 'PostgreSQL',
122
+ dependencies: [
123
+ {
124
+ name: 'psql',
125
+ binary: 'psql',
126
+ description: 'PostgreSQL interactive terminal',
127
+ packages: {
128
+ brew: {
129
+ package: 'postgresql@17',
130
+ postInstall: ['brew link --overwrite postgresql@17'],
131
+ },
132
+ apt: { package: 'postgresql-client' },
133
+ yum: { package: 'postgresql' },
134
+ dnf: { package: 'postgresql' },
135
+ pacman: { package: 'postgresql-libs' },
136
+ },
137
+ manualInstall: {
138
+ darwin: [
139
+ 'Install Homebrew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
140
+ 'Then run: brew install postgresql@17 && brew link --overwrite postgresql@17',
141
+ 'Or install Postgres.app: https://postgresapp.com/downloads.html',
142
+ ],
143
+ linux: [
144
+ 'Ubuntu/Debian: sudo apt install postgresql-client',
145
+ 'CentOS/RHEL: sudo yum install postgresql',
146
+ 'Fedora: sudo dnf install postgresql',
147
+ 'Arch: sudo pacman -S postgresql-libs',
148
+ ],
149
+ },
150
+ },
151
+ {
152
+ name: 'pg_dump',
153
+ binary: 'pg_dump',
154
+ description: 'PostgreSQL database backup utility',
155
+ packages: {
156
+ brew: {
157
+ package: 'postgresql@17',
158
+ postInstall: ['brew link --overwrite postgresql@17'],
159
+ },
160
+ apt: { package: 'postgresql-client' },
161
+ yum: { package: 'postgresql' },
162
+ dnf: { package: 'postgresql' },
163
+ pacman: { package: 'postgresql-libs' },
164
+ },
165
+ manualInstall: {
166
+ darwin: [
167
+ 'Install Homebrew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
168
+ 'Then run: brew install postgresql@17 && brew link --overwrite postgresql@17',
169
+ 'Or install Postgres.app: https://postgresapp.com/downloads.html',
170
+ ],
171
+ linux: [
172
+ 'Ubuntu/Debian: sudo apt install postgresql-client',
173
+ 'CentOS/RHEL: sudo yum install postgresql',
174
+ 'Fedora: sudo dnf install postgresql',
175
+ 'Arch: sudo pacman -S postgresql-libs',
176
+ ],
177
+ },
178
+ },
179
+ {
180
+ name: 'pg_restore',
181
+ binary: 'pg_restore',
182
+ description: 'PostgreSQL database restore utility',
183
+ packages: {
184
+ brew: {
185
+ package: 'postgresql@17',
186
+ postInstall: ['brew link --overwrite postgresql@17'],
187
+ },
188
+ apt: { package: 'postgresql-client' },
189
+ yum: { package: 'postgresql' },
190
+ dnf: { package: 'postgresql' },
191
+ pacman: { package: 'postgresql-libs' },
192
+ },
193
+ manualInstall: {
194
+ darwin: [
195
+ 'Install Homebrew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
196
+ 'Then run: brew install postgresql@17 && brew link --overwrite postgresql@17',
197
+ 'Or install Postgres.app: https://postgresapp.com/downloads.html',
198
+ ],
199
+ linux: [
200
+ 'Ubuntu/Debian: sudo apt install postgresql-client',
201
+ 'CentOS/RHEL: sudo yum install postgresql',
202
+ 'Fedora: sudo dnf install postgresql',
203
+ 'Arch: sudo pacman -S postgresql-libs',
204
+ ],
205
+ },
206
+ },
207
+ {
208
+ name: 'pg_basebackup',
209
+ binary: 'pg_basebackup',
210
+ description: 'PostgreSQL base backup utility for physical backups',
211
+ packages: {
212
+ brew: {
213
+ package: 'postgresql@17',
214
+ postInstall: ['brew link --overwrite postgresql@17'],
215
+ },
216
+ apt: { package: 'postgresql-client' },
217
+ yum: { package: 'postgresql' },
218
+ dnf: { package: 'postgresql' },
219
+ pacman: { package: 'postgresql-libs' },
220
+ },
221
+ manualInstall: {
222
+ darwin: [
223
+ 'Install Homebrew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
224
+ 'Then run: brew install postgresql@17 && brew link --overwrite postgresql@17',
225
+ 'Or install Postgres.app: https://postgresapp.com/downloads.html',
226
+ ],
227
+ linux: [
228
+ 'Ubuntu/Debian: sudo apt install postgresql-client',
229
+ 'CentOS/RHEL: sudo yum install postgresql',
230
+ 'Fedora: sudo dnf install postgresql',
231
+ 'Arch: sudo pacman -S postgresql-libs',
232
+ ],
233
+ },
234
+ },
235
+ ],
236
+ }
237
+
238
+ // =============================================================================
239
+ // MySQL Dependencies (placeholder for future)
240
+ // =============================================================================
241
+
242
+ const mysqlDependencies: EngineDependencies = {
243
+ engine: 'mysql',
244
+ displayName: 'MySQL',
245
+ dependencies: [
246
+ {
247
+ name: 'mysql',
248
+ binary: 'mysql',
249
+ description: 'MySQL command-line client',
250
+ packages: {
251
+ brew: { package: 'mysql-client' },
252
+ apt: { package: 'mysql-client' },
253
+ yum: { package: 'mysql' },
254
+ dnf: { package: 'mysql' },
255
+ pacman: { package: 'mariadb-clients' },
256
+ },
257
+ manualInstall: {
258
+ darwin: [
259
+ 'Install Homebrew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
260
+ 'Then run: brew install mysql-client',
261
+ ],
262
+ linux: [
263
+ 'Ubuntu/Debian: sudo apt install mysql-client',
264
+ 'CentOS/RHEL: sudo yum install mysql',
265
+ 'Fedora: sudo dnf install mysql',
266
+ 'Arch: sudo pacman -S mariadb-clients',
267
+ ],
268
+ },
269
+ },
270
+ {
271
+ name: 'mysqldump',
272
+ binary: 'mysqldump',
273
+ description: 'MySQL database backup utility',
274
+ packages: {
275
+ brew: { package: 'mysql-client' },
276
+ apt: { package: 'mysql-client' },
277
+ yum: { package: 'mysql' },
278
+ dnf: { package: 'mysql' },
279
+ pacman: { package: 'mariadb-clients' },
280
+ },
281
+ manualInstall: {
282
+ darwin: [
283
+ 'Install Homebrew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
284
+ 'Then run: brew install mysql-client',
285
+ ],
286
+ linux: [
287
+ 'Ubuntu/Debian: sudo apt install mysql-client',
288
+ 'CentOS/RHEL: sudo yum install mysql',
289
+ 'Fedora: sudo dnf install mysql',
290
+ 'Arch: sudo pacman -S mariadb-clients',
291
+ ],
292
+ },
293
+ },
294
+ ],
295
+ }
296
+
297
+ // =============================================================================
298
+ // Registry
299
+ // =============================================================================
300
+
301
+ /**
302
+ * All engine dependencies registry
303
+ */
304
+ export const engineDependencies: EngineDependencies[] = [
305
+ postgresqlDependencies,
306
+ mysqlDependencies,
307
+ ]
308
+
309
+ /**
310
+ * Get dependencies for a specific engine
311
+ */
312
+ export function getEngineDependencies(
313
+ engine: string,
314
+ ): EngineDependencies | undefined {
315
+ return engineDependencies.find((e) => e.engine === engine)
316
+ }
317
+
318
+ /**
319
+ * Get all dependencies across all engines
320
+ */
321
+ export function getAllDependencies(): Dependency[] {
322
+ return engineDependencies.flatMap((e) => e.dependencies)
323
+ }
324
+
325
+ /**
326
+ * Get unique dependencies (deduplicated by binary name)
327
+ */
328
+ export function getUniqueDependencies(): Dependency[] {
329
+ const seen = new Set<string>()
330
+ const unique: Dependency[] = []
331
+
332
+ for (const dep of getAllDependencies()) {
333
+ if (!seen.has(dep.binary)) {
334
+ seen.add(dep.binary)
335
+ unique.push(dep)
336
+ }
337
+ }
338
+
339
+ return unique
340
+ }
341
+
342
+ /**
343
+ * Get package manager config by ID
344
+ */
345
+ export function getPackageManager(
346
+ id: PackageManagerId,
347
+ ): PackageManagerConfig | undefined {
348
+ return packageManagers.find((pm) => pm.id === id)
349
+ }
350
+
351
+ /**
352
+ * Get package managers available for a platform
353
+ */
354
+ export function getPackageManagersForPlatform(
355
+ platform: Platform,
356
+ ): PackageManagerConfig[] {
357
+ return packageManagers.filter((pm) => pm.platforms.includes(platform))
358
+ }