@holo-js/cli 0.1.3 → 0.1.5

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 (56) hide show
  1. package/dist/bin/holo.mjs +192 -35
  2. package/dist/{broadcast-YZS4OFCM.mjs → broadcast-RT5KVZWP.mjs} +5 -5
  3. package/dist/{cache-V43YMG4K.mjs → cache-NHCCHT44.mjs} +5 -5
  4. package/dist/{cache-migrations-ZUOI2A7N.mjs → cache-migrations-R2RL2RVD.mjs} +15 -16
  5. package/dist/{chunk-EUIVXVJL.mjs → chunk-57SJ566R.mjs} +1 -1
  6. package/dist/chunk-5BLEC66P.mjs +284 -0
  7. package/dist/{chunk-JX2ZH6XY.mjs → chunk-5EU32E7X.mjs} +3 -3
  8. package/dist/{chunk-Q5F6C2D4.mjs → chunk-BAFQ2GOA.mjs} +1 -1
  9. package/dist/{chunk-CUL4RJTG.mjs → chunk-F4MT6GBK.mjs} +1 -1
  10. package/dist/{chunk-3OTCSFDG.mjs → chunk-MXKNQACM.mjs} +544 -82
  11. package/dist/{chunk-QYLSMF7V.mjs → chunk-OZUDZEAW.mjs} +142 -28
  12. package/dist/{chunk-66FHW725.mjs → chunk-R6BWRY3E.mjs} +28 -2
  13. package/dist/{chunk-RB65DLR4.mjs → chunk-SCCPDJGO.mjs} +156 -16
  14. package/dist/{chunk-VT5IDQG6.mjs → chunk-UZTDQKIY.mjs} +61 -44
  15. package/dist/{chunk-HE6FYNVN.mjs → chunk-VCEO6N5T.mjs} +3563 -2505
  16. package/dist/{config-LS5USBRB.mjs → config-5JSC6KJG.mjs} +3 -3
  17. package/dist/{dev-KGRIGLJY.mjs → dev-OSLYSBTL.mjs} +7 -7
  18. package/dist/{discovery-GBLAUTXS.mjs → discovery-JLT2EOGH.mjs} +3 -3
  19. package/dist/{generators-WSF23UKM.mjs → generators-ZIWACCBE.mjs} +134 -16
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.mjs +189 -32
  22. package/dist/media-migrations-UBAL2YVV.mjs +117 -0
  23. package/dist/{queue-6N7HQMRL.mjs → queue-I66EISVS.mjs} +14 -14
  24. package/dist/{queue-migrations-O6QSSDPQ.mjs → queue-migrations-UIAMAB6E.mjs} +24 -20
  25. package/dist/{runtime-RI4OWTIT.mjs → runtime-MMQGO4PP.mjs} +9 -7
  26. package/dist/{runtime-OOSJ5JBY.mjs → runtime-ZKD6URAV.mjs} +1 -1
  27. package/dist/{scaffold-IYWZKT3W.mjs → scaffold-ISDVICNQ.mjs} +18 -4
  28. package/dist/{security-AE6LGNC4.mjs → security-OZXTMYXF.mjs} +10 -7
  29. package/package.json +13 -12
  30. package/dist/broadcast-ZYFKUFM5.mjs +0 -85
  31. package/dist/cache-ODBZT6IP.mjs +0 -67
  32. package/dist/cache-migrations-KPOEH6GP.mjs +0 -155
  33. package/dist/chunk-BWW5TDFI.mjs +0 -4
  34. package/dist/chunk-D4GG556Y.mjs +0 -23
  35. package/dist/chunk-ET7UXHHQ.mjs +0 -166
  36. package/dist/chunk-G5ADO27Q.mjs +0 -463
  37. package/dist/chunk-GSQ3HTRO.mjs +0 -165
  38. package/dist/chunk-H7TJ4FB3.mjs +0 -848
  39. package/dist/chunk-ICJR7TS4.mjs +0 -66
  40. package/dist/chunk-ICKN56JY.mjs +0 -342
  41. package/dist/chunk-M7J3YTHR.mjs +0 -26
  42. package/dist/chunk-S7P7EBM3.mjs +0 -787
  43. package/dist/chunk-SRWJU3A5.mjs +0 -11
  44. package/dist/chunk-T4OVZZEE.mjs +0 -3204
  45. package/dist/chunk-URK7C3VQ.mjs +0 -538
  46. package/dist/chunk-XUYKPU5Q.mjs +0 -272
  47. package/dist/config-DMWBMMGD.mjs +0 -26
  48. package/dist/dev-LVHDCPVS.mjs +0 -43
  49. package/dist/discovery-R733D2PO.mjs +0 -29
  50. package/dist/generators-32R45P6Z.mjs +0 -426
  51. package/dist/queue-QG5EXOG4.mjs +0 -626
  52. package/dist/queue-migrations-JWKU45Y3.mjs +0 -163
  53. package/dist/runtime-ANBO7VQM.mjs +0 -33
  54. package/dist/runtime-ZRPK5DIT.mjs +0 -56
  55. package/dist/scaffold-ULATB4CA.mjs +0 -121
  56. package/dist/security-OCOPEH2V.mjs +0 -69
@@ -1,538 +0,0 @@
1
- import {
2
- fileExists
3
- } from "./chunk-EUIVXVJL.mjs";
4
- import {
5
- prepareProjectDiscovery
6
- } from "./chunk-S7P7EBM3.mjs";
7
- import {
8
- loadProjectConfig,
9
- resolveGeneratedSchemaPath
10
- } from "./chunk-GSQ3HTRO.mjs";
11
- import {
12
- loadGeneratedProjectRegistry
13
- } from "./chunk-H7TJ4FB3.mjs";
14
- import {
15
- CLI_RUNTIME_ROOT,
16
- bundleProjectModule
17
- } from "./chunk-G5ADO27Q.mjs";
18
-
19
- // src/runtime.ts
20
- import { spawnSync } from "child_process";
21
- import { mkdir, rm, symlink } from "fs/promises";
22
- import { dirname, join, resolve } from "path";
23
- import { fileURLToPath, pathToFileURL } from "url";
24
- import { writeConfigCache } from "@holo-js/config";
25
- var runtimeImportMeta = import.meta;
26
- function resolveConfigModuleUrl(runtimeResolve = runtimeImportMeta.resolve?.bind(runtimeImportMeta)) {
27
- if (typeof runtimeResolve === "function") {
28
- const resolved = runtimeResolve("@holo-js/config");
29
- if (resolved.startsWith("file://")) {
30
- const resolvedPath = fileURLToPath(resolved);
31
- const normalized = resolvedPath.replace(/\\/g, "/");
32
- if (normalized.endsWith("/src/index.ts") || normalized.endsWith("/src/index.mts") || normalized.endsWith("/src/index.js") || normalized.endsWith("/src/index.mjs")) {
33
- return pathToFileURL(resolve(dirname(dirname(resolvedPath)), "dist/index.mjs")).href;
34
- }
35
- }
36
- return resolved;
37
- }
38
- return pathToFileURL(resolve(dirname(fileURLToPath(import.meta.url)), "../node_modules/@holo-js/config/dist/index.mjs")).href;
39
- }
40
- async function initializeProjectRuntime(projectRoot, options = {}) {
41
- const { initializeHolo } = await import("@holo-js/core");
42
- return initializeHolo(projectRoot, options);
43
- }
44
- function parseBooleanEnv(value) {
45
- if (value === "true") return true;
46
- if (value === "false") return false;
47
- return void 0;
48
- }
49
- async function cacheProjectConfig(projectRoot, cacheWriter = writeConfigCache) {
50
- try {
51
- return await cacheWriter(projectRoot, { processEnv: process.env });
52
- } catch (error) {
53
- throw new Error(error instanceof Error && error.message ? error.message : "Failed to cache config.");
54
- }
55
- }
56
- function createEnvRuntimeConfig() {
57
- return {
58
- db: {
59
- defaultConnection: "default",
60
- connections: {
61
- default: {
62
- driver: process.env.DB_DRIVER,
63
- url: process.env.DB_URL,
64
- host: process.env.DB_HOST,
65
- port: process.env.DB_PORT,
66
- username: process.env.DB_USERNAME,
67
- password: process.env.DB_PASSWORD,
68
- database: process.env.DB_DATABASE,
69
- schema: process.env.DB_SCHEMA,
70
- ssl: parseBooleanEnv(process.env.DB_SSL),
71
- logging: parseBooleanEnv(process.env.DB_LOGGING)
72
- }
73
- }
74
- }
75
- };
76
- }
77
- function normalizeRuntimeConnectionInput(connection) {
78
- if (typeof connection === "string") {
79
- return { url: connection };
80
- }
81
- return connection ? { ...connection } : {};
82
- }
83
- function isDefined(value) {
84
- return value !== void 0;
85
- }
86
- function filterDefinedRuntimeConnectionInput(connection) {
87
- return Object.fromEntries(
88
- Object.entries(connection).filter(([, value]) => isDefined(value))
89
- );
90
- }
91
- function mergeRuntimeDatabaseConfig(config, envRuntimeConfig) {
92
- const envDefault = envRuntimeConfig.db.connections.default;
93
- const hasEnvOverrides = Object.values(envDefault).some(isDefined);
94
- if (!config) {
95
- return envRuntimeConfig.db;
96
- }
97
- if (!hasEnvOverrides) {
98
- return config;
99
- }
100
- const defaultConnection = config.defaultConnection ?? "default";
101
- const connections = { ...config.connections ?? {} };
102
- connections[defaultConnection] = {
103
- ...normalizeRuntimeConnectionInput(connections[defaultConnection]),
104
- ...filterDefinedRuntimeConnectionInput(envDefault)
105
- };
106
- return {
107
- ...config,
108
- defaultConnection,
109
- connections
110
- };
111
- }
112
- var RUNTIME_MIGRATION_NAME_PATTERN = /^\d{4}_\d{2}_\d{2}_\d{6}_[a-z0-9_]+$/;
113
- function inferRuntimeMigrationName(entry) {
114
- const fileName = entry.split("/").pop()?.replace(/\.[^.]+$/, "");
115
- if (!fileName || !RUNTIME_MIGRATION_NAME_PATTERN.test(fileName)) {
116
- throw new Error(`Registered migration "${entry}" must use a timestamped file name matching YYYY_MM_DD_HHMMSS_description.`);
117
- }
118
- return fileName;
119
- }
120
- function normalizeRuntimeMigration(entry, migration) {
121
- return {
122
- ...migration,
123
- name: typeof migration.name === "string" ? migration.name : inferRuntimeMigrationName(entry)
124
- };
125
- }
126
- function compileFreshDropIdentifierPath(quoteIdentifier, identifier) {
127
- if (!identifier.includes(".")) {
128
- return quoteIdentifier(identifier);
129
- }
130
- return identifier.split(".").map((part) => quoteIdentifier(part)).join(".");
131
- }
132
- async function dropAllTablesForFresh(connection, schema) {
133
- const tables = await schema.getTables();
134
- if (connection.getDialect().name === "postgres") {
135
- const schemaName = connection.getSchemaName();
136
- const quoteIdentifier = connection.getDialect().quoteIdentifier;
137
- for (const tableName of tables) {
138
- const qualifiedTableName = schemaName ? `${schemaName}.${tableName}` : tableName;
139
- await connection.executeCompiled({
140
- sql: `DROP TABLE IF EXISTS ${compileFreshDropIdentifierPath(quoteIdentifier, qualifiedTableName)} CASCADE`,
141
- source: `schema:dropTableFresh:${qualifiedTableName}`
142
- });
143
- }
144
- return;
145
- }
146
- await schema.withoutForeignKeyConstraints(async () => {
147
- for (const tableName of tables) {
148
- await schema.dropTable(tableName);
149
- }
150
- });
151
- }
152
- async function getRuntimeEnvironment(projectRoot) {
153
- let project = await loadProjectConfig(projectRoot, { required: true });
154
- if (!await loadGeneratedProjectRegistry(projectRoot)) {
155
- await prepareProjectDiscovery(projectRoot, project.config);
156
- project = await loadProjectConfig(projectRoot, { required: true });
157
- }
158
- const generatedSchemaPath = resolveGeneratedSchemaPath(projectRoot, project.config);
159
- const hasGeneratedSchema = await fileExists(generatedSchemaPath);
160
- const bundleInputs = [
161
- ...project.config.models.map((entry) => resolve(projectRoot, entry)),
162
- ...project.config.migrations.map((entry) => resolve(projectRoot, entry)),
163
- ...project.config.seeders.map((entry) => resolve(projectRoot, entry)),
164
- ...hasGeneratedSchema ? [generatedSchemaPath] : []
165
- ];
166
- const bundled = [];
167
- try {
168
- for (const entryPath of bundleInputs) {
169
- bundled.push(await bundleProjectModule(projectRoot, entryPath, { external: ["@holo-js/db"] }));
170
- }
171
- } catch (error) {
172
- await Promise.all(bundled.map((entry) => entry.cleanup()));
173
- throw error;
174
- }
175
- const bundledModels = bundled.slice(0, project.config.models.length).map((entry) => entry.path);
176
- const bundledMigrations = bundled.slice(project.config.models.length, project.config.models.length + project.config.migrations.length).map((entry) => entry.path);
177
- const bundledSeeders = bundled.slice(project.config.models.length + project.config.migrations.length).slice(0, project.config.seeders.length).map((entry) => entry.path);
178
- const bundledGeneratedSchema = hasGeneratedSchema ? bundled[project.config.models.length + project.config.migrations.length + project.config.seeders.length]?.path : void 0;
179
- return {
180
- project,
181
- bundledModels,
182
- bundledMigrations,
183
- bundledSeeders,
184
- ...bundledGeneratedSchema ? { bundledGeneratedSchema } : {},
185
- async cleanup() {
186
- await Promise.all(bundled.map((entry) => entry.cleanup()));
187
- }
188
- };
189
- }
190
- var nodeRuntimeScript = `
191
- import { mkdir, writeFile } from 'node:fs/promises'
192
- import { dirname } from 'node:path'
193
- import {
194
- configureDB,
195
- createSchemaService,
196
- createMigrationService,
197
- createSeederService,
198
- renderGeneratedSchemaModule,
199
- resetDB,
200
- resolveRuntimeConnectionManagerOptions,
201
- } from '@holo-js/db'
202
-
203
- const payload = JSON.parse(process.env.HOLO_RUNTIME_PAYLOAD ?? '{}')
204
- process.chdir(payload.projectRoot)
205
-
206
- function isRecord(value) {
207
- return !!value && typeof value === 'object' && !Array.isArray(value)
208
- }
209
-
210
- async function loadModule(path) {
211
- return import(\`\${path}?t=\${Date.now()}\`)
212
- }
213
-
214
- function resolveExport(moduleValue, matcher) {
215
- if (isRecord(moduleValue) && matcher(moduleValue.default)) {
216
- return moduleValue.default
217
- }
218
-
219
- if (isRecord(moduleValue)) {
220
- for (const value of Object.values(moduleValue)) {
221
- if (matcher(value)) {
222
- return value
223
- }
224
- }
225
- }
226
-
227
- return undefined
228
- }
229
-
230
- const isModel = (value) => isRecord(value) && isRecord(value.definition) && value.definition.kind === 'model' && typeof value.prune === 'function'
231
- const isMigration = (value) => isRecord(value) && typeof value.up === 'function'
232
- const isSeeder = (value) => isRecord(value) && typeof value.name === 'string' && typeof value.run === 'function'
233
- const isTable = (value) => isRecord(value) && value.kind === 'table' && typeof value.tableName === 'string' && isRecord(value.columns)
234
- const RUNTIME_MIGRATION_NAME_PATTERN = ${RUNTIME_MIGRATION_NAME_PATTERN}
235
- const inferRuntimeMigrationName = ${inferRuntimeMigrationName.toString()}
236
- const normalizeRuntimeMigration = ${normalizeRuntimeMigration.toString()}
237
- const compileFreshDropIdentifierPath = ${compileFreshDropIdentifierPath.toString()}
238
- const dropAllTablesForFresh = ${dropAllTablesForFresh.toString()}
239
-
240
- function extractTables(moduleValue) {
241
- if (isRecord(moduleValue) && isRecord(moduleValue.tables)) {
242
- return Object.values(moduleValue.tables).filter(isTable)
243
- }
244
-
245
- if (isRecord(moduleValue) && isTable(moduleValue.default)) {
246
- return [moduleValue.default]
247
- }
248
-
249
- if (isRecord(moduleValue)) {
250
- return Object.values(moduleValue).filter(isTable)
251
- }
252
-
253
- return []
254
- }
255
-
256
- async function preloadGeneratedSchema(manager, entry) {
257
- if (!entry) {
258
- return
259
- }
260
-
261
- const tables = extractTables(await loadModule(entry))
262
- for (const table of tables) {
263
- manager.connection().getSchemaRegistry().replace(table)
264
- }
265
- }
266
-
267
- async function writeGeneratedSchemaArtifact(manager, outputPath) {
268
- if (!outputPath) {
269
- return
270
- }
271
-
272
- const source = renderGeneratedSchemaModule(manager.connection().getSchemaRegistry().list())
273
- await mkdir(dirname(outputPath), { recursive: true })
274
- await writeFile(outputPath, source, 'utf8')
275
- }
276
-
277
- const manager = resolveRuntimeConnectionManagerOptions(payload.runtimeConfig)
278
- configureDB(manager)
279
-
280
- try {
281
- await manager.initializeAll()
282
-
283
- if (payload.kind === 'migrate') {
284
- await preloadGeneratedSchema(manager, payload.generatedSchema)
285
- const migrations = []
286
- for (const entry of payload.migrations) {
287
- const migration = resolveExport(await loadModule(entry), isMigration)
288
- if (!migration) {
289
- throw new Error(\`Registered migration "\${entry}" does not export a Holo migration.\`)
290
- }
291
- migrations.push(normalizeRuntimeMigration(entry, migration))
292
- }
293
-
294
- const executed = await createMigrationService(manager.connection(), migrations).migrate(payload.options ?? {})
295
- await writeGeneratedSchemaArtifact(manager, payload.generatedSchemaOutputPath)
296
- if (executed.length === 0) {
297
- console.log('No migrations were executed.')
298
- } else {
299
- console.log(\`Migrations executed: \${executed.map(item => item.name).join(', ')}\`)
300
- }
301
- } else if (payload.kind === 'fresh') {
302
- const migrations = []
303
- for (const entry of payload.migrations) {
304
- const migration = resolveExport(await loadModule(entry), isMigration)
305
- if (!migration) {
306
- throw new Error(\`Registered migration "\${entry}" does not export a Holo migration.\`)
307
- }
308
- migrations.push(normalizeRuntimeMigration(entry, migration))
309
- }
310
-
311
- const schema = createSchemaService(manager.connection())
312
- await dropAllTablesForFresh(manager.connection(), schema)
313
- manager.connection().getSchemaRegistry().clear()
314
-
315
- const executed = await createMigrationService(manager.connection(), migrations).migrate({})
316
- await writeGeneratedSchemaArtifact(manager, payload.generatedSchemaOutputPath)
317
- if (executed.length === 0) {
318
- console.log('No migrations were executed.')
319
- } else {
320
- console.log(\`Migrations executed: \${executed.map(item => item.name).join(', ')}\`)
321
- }
322
-
323
- if (payload.options?.seed) {
324
- const seeders = []
325
- for (const entry of payload.seeders) {
326
- const seeder = resolveExport(await loadModule(entry), isSeeder)
327
- if (!seeder) {
328
- throw new Error(\`Registered seeder "\${entry}" does not export a Holo seeder.\`)
329
- }
330
- seeders.push(seeder)
331
- }
332
-
333
- const seeded = await createSeederService(manager.connection(), seeders).seed({
334
- ...(Array.isArray(payload.options.only) ? { only: payload.options.only } : {}),
335
- quietly: payload.options.quietly === true,
336
- force: payload.options.force === true,
337
- environment: payload.options.environment ?? 'development',
338
- })
339
- if (seeded.length === 0) {
340
- console.log('No seeders were executed.')
341
- } else {
342
- console.log(\`Seeders executed: \${seeded.map(item => item.name).join(', ')}\`)
343
- }
344
- }
345
- } else if (payload.kind === 'rollback') {
346
- await preloadGeneratedSchema(manager, payload.generatedSchema)
347
- const migrations = []
348
- for (const entry of payload.migrations) {
349
- const migration = resolveExport(await loadModule(entry), isMigration)
350
- if (!migration) {
351
- throw new Error(\`Registered migration "\${entry}" does not export a Holo migration.\`)
352
- }
353
- migrations.push(normalizeRuntimeMigration(entry, migration))
354
- }
355
-
356
- const rolledBack = await createMigrationService(manager.connection(), migrations).rollback(payload.options ?? {})
357
- await writeGeneratedSchemaArtifact(manager, payload.generatedSchemaOutputPath)
358
- if (rolledBack.length === 0) {
359
- console.log('No migrations were executed.')
360
- } else {
361
- console.log(\`Migrations executed: \${rolledBack.map(item => item.name).join(', ')}\`)
362
- }
363
- } else if (payload.kind === 'seed') {
364
- const seeders = []
365
- for (const entry of payload.seeders) {
366
- const seeder = resolveExport(await loadModule(entry), isSeeder)
367
- if (!seeder) {
368
- throw new Error(\`Registered seeder "\${entry}" does not export a Holo seeder.\`)
369
- }
370
- seeders.push(seeder)
371
- }
372
-
373
- const executed = await createSeederService(manager.connection(), seeders).seed(payload.options ?? {})
374
- if (executed.length === 0) {
375
- console.log('No seeders were executed.')
376
- } else {
377
- console.log(\`Seeders executed: \${executed.map(item => item.name).join(', ')}\`)
378
- }
379
- } else if (payload.kind === 'prune') {
380
- const models = []
381
- for (const entry of payload.models) {
382
- const model = resolveExport(await loadModule(entry), isModel)
383
- if (!model) {
384
- throw new Error(\`Registered model "\${entry}" does not export a Holo model.\`)
385
- }
386
- models.push(model)
387
- }
388
-
389
- const byName = new Map(models.map(model => [model.definition.name, model]))
390
- const requested = payload.options?.models ?? []
391
- const selected = []
392
-
393
- if (requested.length === 0) {
394
- selected.push(...models.filter(model => Boolean(model.definition.prunable)))
395
- } else {
396
- for (const name of requested) {
397
- const model = byName.get(name)
398
- if (!model) {
399
- throw new Error(\`Unknown model "\${name}".\`)
400
- }
401
- if (!model.definition.prunable) {
402
- throw new Error(\`Model "\${name}" does not define a prunable query.\`)
403
- }
404
- selected.push(model)
405
- }
406
- }
407
-
408
- if (selected.length === 0) {
409
- console.log('No prunable models were registered.')
410
- } else {
411
- let total = 0
412
- for (const model of selected) {
413
- const deleted = await model.prune()
414
- total += deleted
415
- console.log(\`\${model.definition.name}: deleted \${deleted}\`)
416
- }
417
- console.log(\`Total deleted: \${total}\`)
418
- }
419
- } else {
420
- throw new Error(\`Unknown runtime command "\${payload.kind}".\`)
421
- }
422
- } finally {
423
- await manager.disconnectAll()
424
- resetDB()
425
- }
426
- `;
427
- async function resolvePackageRootFromSpecifier(specifier) {
428
- let current = dirname(fileURLToPath(import.meta.resolve(specifier)));
429
- while (true) {
430
- if (await fileExists(join(current, "package.json"))) {
431
- return current;
432
- }
433
- const parent = dirname(current);
434
- if (parent === current) {
435
- throw new Error(`Could not resolve package root for "${specifier}".`);
436
- }
437
- current = parent;
438
- }
439
- }
440
- async function ensureRuntimeDependencyLink(projectRoot) {
441
- const runtimeRoot = join(projectRoot, CLI_RUNTIME_ROOT);
442
- const packageRoot = await resolvePackageRootFromSpecifier("@holo-js/db");
443
- const namespaceDir = join(runtimeRoot, "node_modules", "@holo-js");
444
- const targetPath = join(namespaceDir, "db");
445
- await mkdir(namespaceDir, { recursive: true });
446
- await rm(targetPath, { recursive: true, force: true });
447
- await symlink(packageRoot, targetPath, "junction");
448
- return runtimeRoot;
449
- }
450
- async function cleanupRuntimeDependencyLink(projectRoot) {
451
- await rm(join(projectRoot, CLI_RUNTIME_ROOT, "node_modules"), { recursive: true, force: true });
452
- }
453
- function createRuntimeInvocation(script) {
454
- return {
455
- command: "node",
456
- args: ["--input-type=module", "--eval", script]
457
- };
458
- }
459
- function getRuntimeFailureMessage(kind, result) {
460
- const stderr = result.stderr?.trim();
461
- if (stderr) {
462
- return stderr;
463
- }
464
- const stdout = result.stdout?.trim();
465
- if (stdout) {
466
- return stdout;
467
- }
468
- const errorCode = result.error && "code" in result.error ? result.error.code : void 0;
469
- if (typeof errorCode === "string" && errorCode.length > 0) {
470
- return `Failed to launch runtime command "${kind}": ${errorCode}.`;
471
- }
472
- return `Runtime command "${kind}" failed.`;
473
- }
474
- async function withRuntimeEnvironment(projectRoot, kind, options, callback) {
475
- const environment = await getRuntimeEnvironment(projectRoot);
476
- try {
477
- const envRuntimeConfig = createEnvRuntimeConfig();
478
- const runtimeDatabaseConfig = mergeRuntimeDatabaseConfig(
479
- environment.project.config.database,
480
- envRuntimeConfig
481
- );
482
- const runtimeRoot = await ensureRuntimeDependencyLink(projectRoot);
483
- const runtimePayload = JSON.stringify({
484
- kind,
485
- projectRoot,
486
- runtimeConfig: {
487
- db: runtimeDatabaseConfig
488
- },
489
- models: environment.bundledModels.map((entry) => pathToFileURL(entry).href),
490
- migrations: environment.bundledMigrations.map((entry) => pathToFileURL(entry).href),
491
- seeders: environment.bundledSeeders.map((entry) => pathToFileURL(entry).href),
492
- generatedSchema: environment.bundledGeneratedSchema ? pathToFileURL(environment.bundledGeneratedSchema).href : void 0,
493
- generatedSchemaOutputPath: resolveGeneratedSchemaPath(projectRoot, environment.project.config),
494
- options
495
- });
496
- const runtime = createRuntimeInvocation(nodeRuntimeScript);
497
- const result = spawnSync(runtime.command, runtime.args, {
498
- cwd: runtimeRoot,
499
- env: {
500
- ...process.env,
501
- HOLO_RUNTIME_PAYLOAD: runtimePayload
502
- },
503
- encoding: "utf8"
504
- });
505
- if (result.status !== 0) {
506
- throw new Error(getRuntimeFailureMessage(kind, result));
507
- }
508
- return await callback(result.stdout.trim());
509
- } finally {
510
- await cleanupRuntimeDependencyLink(projectRoot);
511
- await environment.cleanup();
512
- }
513
- }
514
-
515
- export {
516
- resolveConfigModuleUrl,
517
- initializeProjectRuntime,
518
- parseBooleanEnv,
519
- cacheProjectConfig,
520
- createEnvRuntimeConfig,
521
- normalizeRuntimeConnectionInput,
522
- isDefined,
523
- filterDefinedRuntimeConnectionInput,
524
- mergeRuntimeDatabaseConfig,
525
- RUNTIME_MIGRATION_NAME_PATTERN,
526
- inferRuntimeMigrationName,
527
- normalizeRuntimeMigration,
528
- compileFreshDropIdentifierPath,
529
- dropAllTablesForFresh,
530
- getRuntimeEnvironment,
531
- nodeRuntimeScript,
532
- resolvePackageRootFromSpecifier,
533
- ensureRuntimeDependencyLink,
534
- cleanupRuntimeDependencyLink,
535
- createRuntimeInvocation,
536
- getRuntimeFailureMessage,
537
- withRuntimeEnvironment
538
- };