@holo-js/cli 0.1.9 → 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.
Files changed (46) hide show
  1. package/dist/bin/holo.mjs +165 -81
  2. package/dist/broadcast-WI6PJS5P.mjs +203 -0
  3. package/dist/broadcast-YWS4N5QU.mjs +203 -0
  4. package/dist/{cache-ETOIQ5IG.mjs → cache-KWNQECAA.mjs} +6 -6
  5. package/dist/cache-QARFSW4F.mjs +66 -0
  6. package/dist/{cache-migrations-2GGI4TJK.mjs → cache-migrations-3OXR4FN5.mjs} +50 -30
  7. package/dist/cache-migrations-MDFMDVTK.mjs +173 -0
  8. package/dist/{chunk-IMOGEKB4.mjs → chunk-2DKQKZML.mjs} +188 -106
  9. package/dist/{chunk-7JR73TOH.mjs → chunk-2RGJTPYF.mjs} +36 -25
  10. package/dist/{chunk-ASTSSSL2.mjs → chunk-EWYXSN2C.mjs} +75 -122
  11. package/dist/{chunk-F4MT6GBK.mjs → chunk-FGQ2I2YH.mjs} +1 -1
  12. package/dist/chunk-I7QBCEV7.mjs +33 -0
  13. package/dist/{chunk-R6BWRY3E.mjs → chunk-ILU426CF.mjs} +3 -1
  14. package/dist/{chunk-HB4Q7VYK.mjs → chunk-IUDD5FYL.mjs} +28 -273
  15. package/dist/{chunk-WRZFATUT.mjs → chunk-KWRIBHC3.mjs} +229 -142
  16. package/dist/{chunk-57SJ566R.mjs → chunk-LBJAJLKU.mjs} +1 -1
  17. package/dist/{chunk-BAFQ2GOA.mjs → chunk-LXGQCG56.mjs} +1 -1
  18. package/dist/{chunk-SRPGIWCF.mjs → chunk-ONKESAQA.mjs} +2 -2
  19. package/dist/chunk-QA7TP5EO.mjs +448 -0
  20. package/dist/chunk-UPZH6KCF.mjs +3306 -0
  21. package/dist/{chunk-5EU32E7X.mjs → chunk-VRGB6DIS.mjs} +116 -12
  22. package/dist/{config-ARLE6PKR.mjs → config-TWEO2R4N.mjs} +3 -3
  23. package/dist/{dev-6RG5SSZ7.mjs → dev-2OULECTU.mjs} +7 -7
  24. package/dist/dev-PJMEGTAC.mjs +42 -0
  25. package/dist/{discovery-FCVGQQVD.mjs → discovery-7FXND7Y6.mjs} +3 -3
  26. package/dist/{generators-UI2LJK3O.mjs → generators-4BP7B47W.mjs} +11 -34
  27. package/dist/generators-Z4XLSMC7.mjs +520 -0
  28. package/dist/index.mjs +167 -83
  29. package/dist/{media-migrations-JQSDCC7S.mjs → media-migrations-BFEL7NFG.mjs} +9 -20
  30. package/dist/media-migrations-VR7DLLR6.mjs +106 -0
  31. package/dist/{queue-BY3PLH4I.mjs → queue-SVOJPTRO.mjs} +10 -10
  32. package/dist/queue-YCBQTCYI.mjs +625 -0
  33. package/dist/{queue-migrations-YZUKEZK7.mjs → queue-migrations-HPXOO3NA.mjs} +13 -12
  34. package/dist/queue-migrations-X4P7FZKJ.mjs +167 -0
  35. package/dist/{runtime-BI343WHS.mjs → runtime-CPKR663Y.mjs} +9 -9
  36. package/dist/runtime-GIE56H47.mjs +57 -0
  37. package/dist/{runtime-ZKD6URAV.mjs → runtime-GSXF4NB3.mjs} +1 -1
  38. package/dist/runtime-worker.d.ts +2 -0
  39. package/dist/runtime-worker.mjs +242 -0
  40. package/dist/{scaffold-UBOS2NZR.mjs → scaffold-3QPGYQEQ.mjs} +9 -5
  41. package/dist/scaffold-RGAAHC6I.mjs +139 -0
  42. package/dist/{security-TYPVOYGF.mjs → security-7H5TNHZY.mjs} +6 -6
  43. package/dist/security-BZGD6ONY.mjs +71 -0
  44. package/package.json +9 -7
  45. package/dist/broadcast-VR46UZEL.mjs +0 -84
  46. package/dist/chunk-ZXDU7RHU.mjs +0 -9
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  fileExists
3
- } from "./chunk-57SJ566R.mjs";
3
+ } from "./chunk-LBJAJLKU.mjs";
4
4
  import {
5
5
  prepareProjectDiscovery
6
- } from "./chunk-7JR73TOH.mjs";
6
+ } from "./chunk-2RGJTPYF.mjs";
7
7
  import {
8
8
  loadProjectConfig,
9
9
  resolveGeneratedSchemaPath
10
- } from "./chunk-SRPGIWCF.mjs";
10
+ } from "./chunk-ONKESAQA.mjs";
11
11
  import {
12
12
  loadGeneratedProjectRegistry
13
- } from "./chunk-IMOGEKB4.mjs";
13
+ } from "./chunk-2DKQKZML.mjs";
14
14
  import {
15
15
  CLI_RUNTIME_ROOT,
16
16
  bundleProjectModule
17
- } from "./chunk-R6BWRY3E.mjs";
17
+ } from "./chunk-ILU426CF.mjs";
18
18
 
19
19
  // src/runtime.ts
20
20
  import { spawn } from "child_process";
@@ -189,270 +189,6 @@ async function getRuntimeEnvironment(projectRoot) {
189
189
  }
190
190
  };
191
191
  }
192
- var nodeRuntimeScript = `
193
- import { mkdir, writeFile } from 'node:fs/promises'
194
- import { dirname } from 'node:path'
195
- import {
196
- configureDB,
197
- createSchemaService,
198
- createMigrationService,
199
- createSeederService,
200
- registerGeneratedTables,
201
- renderGeneratedSchemaModule,
202
- resetDB,
203
- resolveRuntimeConnectionManagerOptions,
204
- } from '@holo-js/db'
205
-
206
- const payload = JSON.parse(process.env.HOLO_RUNTIME_PAYLOAD ?? '{}')
207
- process.chdir(payload.projectRoot)
208
-
209
- function isRecord(value) {
210
- return !!value && typeof value === 'object' && !Array.isArray(value)
211
- }
212
-
213
- async function loadModule(path) {
214
- return import(\`\${path}?t=\${Date.now()}\`)
215
- }
216
-
217
- function resolveExport(moduleValue, matcher) {
218
- if (isRecord(moduleValue) && matcher(moduleValue.default)) {
219
- return moduleValue.default
220
- }
221
-
222
- if (isRecord(moduleValue)) {
223
- for (const value of Object.values(moduleValue)) {
224
- if (matcher(value)) {
225
- return value
226
- }
227
- }
228
- }
229
-
230
- return undefined
231
- }
232
-
233
- const isModel = (value) => isRecord(value) && isRecord(value.definition) && value.definition.kind === 'model' && typeof value.prune === 'function'
234
- const isMigration = (value) => isRecord(value) && typeof value.up === 'function'
235
- const isSeeder = (value) => isRecord(value) && typeof value.name === 'string' && typeof value.run === 'function'
236
- const isTable = (value) => isRecord(value) && value.kind === 'table' && typeof value.tableName === 'string' && isRecord(value.columns)
237
- const RUNTIME_MIGRATION_NAME_PATTERN = ${RUNTIME_MIGRATION_NAME_PATTERN}
238
- const inferRuntimeMigrationName = ${inferRuntimeMigrationName.toString()}
239
- const normalizeRuntimeMigration = ${normalizeRuntimeMigration.toString()}
240
- const compileFreshDropIdentifierPath = ${compileFreshDropIdentifierPath.toString()}
241
- const dropAllTablesForFresh = ${dropAllTablesForFresh.toString()}
242
-
243
- function extractTables(moduleValue) {
244
- if (isRecord(moduleValue) && isRecord(moduleValue.tables)) {
245
- return Object.values(moduleValue.tables).filter(isTable)
246
- }
247
-
248
- if (isRecord(moduleValue) && isTable(moduleValue.default)) {
249
- return [moduleValue.default]
250
- }
251
-
252
- if (isRecord(moduleValue)) {
253
- return Object.values(moduleValue).filter(isTable)
254
- }
255
-
256
- return []
257
- }
258
-
259
- async function preloadGeneratedSchema(manager, entry) {
260
- if (!entry) {
261
- return
262
- }
263
-
264
- const tables = extractTables(await loadModule(entry))
265
- for (const table of tables) {
266
- manager.connection().getSchemaRegistry().replace(table)
267
- }
268
- }
269
-
270
- async function writeGeneratedSchemaArtifact(manager, outputPath) {
271
- if (!outputPath) {
272
- return
273
- }
274
-
275
- const source = renderGeneratedSchemaModule(manager.connection().getSchemaRegistry().list())
276
- await mkdir(dirname(outputPath), { recursive: true })
277
- await writeFile(outputPath, source, 'utf8')
278
- }
279
-
280
- function syncGeneratedSchemaFromManager(manager) {
281
- registerGeneratedTables(Object.fromEntries(
282
- manager.connection().getSchemaRegistry().list().map(table => [table.tableName, table]),
283
- ))
284
- }
285
-
286
- const manager = resolveRuntimeConnectionManagerOptions(payload.runtimeConfig)
287
- configureDB(manager)
288
-
289
- try {
290
- await manager.initializeAll()
291
-
292
- if (payload.kind === 'migrate') {
293
- await preloadGeneratedSchema(manager, payload.generatedSchema)
294
- const migrations = []
295
- for (const entry of payload.migrations) {
296
- const migration = resolveExport(await loadModule(entry), isMigration)
297
- if (!migration) {
298
- throw new Error(\`Registered migration "\${entry}" does not export a Holo migration.\`)
299
- }
300
- migrations.push(normalizeRuntimeMigration(entry, migration))
301
- }
302
-
303
- const executed = await createMigrationService(manager.connection(), migrations).migrate(payload.options ?? {})
304
- await writeGeneratedSchemaArtifact(manager, payload.generatedSchemaOutputPath)
305
- if (executed.length === 0) {
306
- console.log('No migrations were executed.')
307
- } else {
308
- console.log('Migrations executed:')
309
- for (const item of executed) {
310
- console.log(\` \${item.name}\`)
311
- }
312
- }
313
- } else if (payload.kind === 'fresh') {
314
- const migrations = []
315
- for (const entry of payload.migrations) {
316
- const migration = resolveExport(await loadModule(entry), isMigration)
317
- if (!migration) {
318
- throw new Error(\`Registered migration "\${entry}" does not export a Holo migration.\`)
319
- }
320
- migrations.push(normalizeRuntimeMigration(entry, migration))
321
- }
322
-
323
- const schema = createSchemaService(manager.connection())
324
- await dropAllTablesForFresh(manager.connection(), schema)
325
- manager.connection().getSchemaRegistry().clear()
326
-
327
- const executed = await createMigrationService(manager.connection(), migrations).migrate({})
328
- await writeGeneratedSchemaArtifact(manager, payload.generatedSchemaOutputPath)
329
- syncGeneratedSchemaFromManager(manager)
330
- if (executed.length === 0) {
331
- console.log('No migrations were executed.')
332
- } else {
333
- console.log('Migrations executed:')
334
- for (const item of executed) {
335
- console.log(\` \${item.name}\`)
336
- }
337
- }
338
-
339
- if (payload.options?.seed) {
340
- const seeders = []
341
- for (const entry of payload.seeders) {
342
- const seeder = resolveExport(await loadModule(entry), isSeeder)
343
- if (!seeder) {
344
- throw new Error(\`Registered seeder "\${entry}" does not export a Holo seeder.\`)
345
- }
346
- seeders.push(seeder)
347
- }
348
-
349
- const seeded = await createSeederService(manager.connection(), seeders).seed({
350
- ...(Array.isArray(payload.options.only) ? { only: payload.options.only } : {}),
351
- quietly: payload.options.quietly === true,
352
- force: payload.options.force === true,
353
- environment: payload.options.environment ?? 'development',
354
- })
355
- if (seeded.length === 0) {
356
- console.log('No seeders were executed.')
357
- } else {
358
- console.log('Seeders executed:')
359
- for (const item of seeded) {
360
- console.log(\` \${item.name}\`)
361
- }
362
- }
363
- }
364
- } else if (payload.kind === 'rollback') {
365
- await preloadGeneratedSchema(manager, payload.generatedSchema)
366
- const migrations = []
367
- for (const entry of payload.migrations) {
368
- const migration = resolveExport(await loadModule(entry), isMigration)
369
- if (!migration) {
370
- throw new Error(\`Registered migration "\${entry}" does not export a Holo migration.\`)
371
- }
372
- migrations.push(normalizeRuntimeMigration(entry, migration))
373
- }
374
-
375
- const rolledBack = await createMigrationService(manager.connection(), migrations).rollback(payload.options ?? {})
376
- await writeGeneratedSchemaArtifact(manager, payload.generatedSchemaOutputPath)
377
- if (rolledBack.length === 0) {
378
- console.log('No migrations were rolled back.')
379
- } else {
380
- console.log('Migrations rolled back:')
381
- for (const item of rolledBack) {
382
- console.log(\` \${item.name}\`)
383
- }
384
- }
385
- } else if (payload.kind === 'seed') {
386
- if (payload.generatedSchema) {
387
- await preloadGeneratedSchema(manager, payload.generatedSchema)
388
- }
389
-
390
- const seeders = []
391
- for (const entry of payload.seeders) {
392
- const seeder = resolveExport(await loadModule(entry), isSeeder)
393
- if (!seeder) {
394
- throw new Error(\`Registered seeder "\${entry}" does not export a Holo seeder.\`)
395
- }
396
- seeders.push(seeder)
397
- }
398
-
399
- const executed = await createSeederService(manager.connection(), seeders).seed(payload.options ?? {})
400
- if (executed.length === 0) {
401
- console.log('No seeders were executed.')
402
- } else {
403
- console.log('Seeders executed:')
404
- for (const item of executed) {
405
- console.log(\` \${item.name}\`)
406
- }
407
- }
408
- } else if (payload.kind === 'prune') {
409
- const models = []
410
- for (const entry of payload.models) {
411
- const model = resolveExport(await loadModule(entry), isModel)
412
- if (!model) {
413
- throw new Error(\`Registered model "\${entry}" does not export a Holo model.\`)
414
- }
415
- models.push(model)
416
- }
417
-
418
- const byName = new Map(models.map(model => [model.definition.name, model]))
419
- const requested = payload.options?.models ?? []
420
- const selected = []
421
-
422
- if (requested.length === 0) {
423
- selected.push(...models.filter(model => Boolean(model.definition.prunable)))
424
- } else {
425
- for (const name of requested) {
426
- const model = byName.get(name)
427
- if (!model) {
428
- throw new Error(\`Unknown model "\${name}".\`)
429
- }
430
- if (!model.definition.prunable) {
431
- throw new Error(\`Model "\${name}" does not define a prunable query.\`)
432
- }
433
- selected.push(model)
434
- }
435
- }
436
-
437
- if (selected.length === 0) {
438
- console.log('No prunable models were registered.')
439
- } else {
440
- let total = 0
441
- for (const model of selected) {
442
- const deleted = await model.prune()
443
- total += deleted
444
- console.log(\`\${model.definition.name}: deleted \${deleted}\`)
445
- }
446
- console.log(\`Total deleted: \${total}\`)
447
- }
448
- } else {
449
- throw new Error(\`Unknown runtime command "\${payload.kind}".\`)
450
- }
451
- } finally {
452
- await manager.disconnectAll()
453
- resetDB()
454
- }
455
- `;
456
192
  async function resolvePackageRootFromSpecifier(specifier) {
457
193
  let current = dirname(fileURLToPath(import.meta.resolve(specifier)));
458
194
  while (true) {
@@ -526,10 +262,29 @@ async function cleanupRuntimeDependencyLink(projectRoot) {
526
262
  await writeFile(refPath, String(nextReferences), "utf8");
527
263
  });
528
264
  }
529
- function createRuntimeInvocation(script) {
265
+ function resolveRuntimeWorkerPath() {
266
+ const runtimePath = fileURLToPath(import.meta.url);
267
+ return runtimePath.endsWith("/src/runtime.ts") ? resolve(dirname(runtimePath), "runtime-worker.ts") : resolve(dirname(runtimePath), "runtime-worker.mjs");
268
+ }
269
+ function supportsNodeTypeStripping(version = process.versions.node) {
270
+ const [major = "0", minor = "0"] = version.split(".");
271
+ const majorVersion = Number.parseInt(major, 10);
272
+ const minorVersion = Number.parseInt(minor, 10);
273
+ return majorVersion > 22 || majorVersion === 22 && minorVersion >= 6;
274
+ }
275
+ function resolveCompiledRuntimeWorkerPath(workerPath) {
276
+ return resolve(dirname(workerPath), "../dist/runtime-worker.mjs");
277
+ }
278
+ function createRuntimeInvocation(workerPath = resolveRuntimeWorkerPath()) {
279
+ if (workerPath.endsWith(".ts")) {
280
+ return {
281
+ command: "node",
282
+ args: supportsNodeTypeStripping() ? ["--experimental-strip-types", workerPath] : [resolveCompiledRuntimeWorkerPath(workerPath)]
283
+ };
284
+ }
530
285
  return {
531
286
  command: "node",
532
- args: ["--input-type=module", "--eval", script]
287
+ args: [workerPath]
533
288
  };
534
289
  }
535
290
  function runRuntimeInvocation(command, args, options) {
@@ -624,7 +379,7 @@ async function withRuntimeEnvironment(projectRoot, kind, options, callback) {
624
379
  generatedSchemaOutputPath: resolveGeneratedSchemaPath(projectRoot, environment.project.config),
625
380
  options
626
381
  });
627
- const runtime = createRuntimeInvocation(nodeRuntimeScript);
382
+ const runtime = createRuntimeInvocation();
628
383
  const result = await runRuntimeInvocation(runtime.command, runtime.args, {
629
384
  cwd: runtimeRoot,
630
385
  env: {
@@ -660,10 +415,10 @@ export {
660
415
  compileFreshDropIdentifierPath,
661
416
  dropAllTablesForFresh,
662
417
  getRuntimeEnvironment,
663
- nodeRuntimeScript,
664
418
  resolvePackageRootFromSpecifier,
665
419
  ensureRuntimeDependencyLink,
666
420
  cleanupRuntimeDependencyLink,
421
+ resolveRuntimeWorkerPath,
667
422
  createRuntimeInvocation,
668
423
  runRuntimeInvocation,
669
424
  getRuntimeFailureMessage,