@alexify/migronaut 2.0.0 → 2.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 (54) hide show
  1. package/CHANGELOG.md +436 -0
  2. package/README.md +235 -6
  3. package/bullmq.d.ts +860 -0
  4. package/bullmq.js +1 -0
  5. package/index.d.ts +888 -19
  6. package/migronaut.schema.json +238 -1
  7. package/package.json +21 -5
  8. package/src/bullmq/index.js +55 -0
  9. package/src/bullmq/jobs.js +454 -0
  10. package/src/bullmq/processor.js +632 -0
  11. package/src/bullmq/producer.js +427 -0
  12. package/src/bullmq/service.js +653 -0
  13. package/src/bullmq/wait.js +124 -0
  14. package/src/cli/args.js +12 -2
  15. package/src/cli/commands/converge.js +188 -0
  16. package/src/cli/commands/down.js +2 -0
  17. package/src/cli/commands/lock.js +2 -1
  18. package/src/cli/commands/redo.js +8 -1
  19. package/src/cli/commands/up.js +14 -1
  20. package/src/cli/exit-codes.js +9 -2
  21. package/src/cli/index.js +2 -0
  22. package/src/cli/shared.js +14 -4
  23. package/src/cli/table.js +164 -0
  24. package/src/core/audit.js +88 -3
  25. package/src/core/changelog.js +71 -6
  26. package/src/core/collections.js +396 -0
  27. package/src/core/config.js +130 -25
  28. package/src/core/converge-log.js +47 -0
  29. package/src/core/converge-plan.js +686 -0
  30. package/src/core/converge-search-run.js +440 -0
  31. package/src/core/converge-search.js +404 -0
  32. package/src/core/converge.js +1024 -0
  33. package/src/core/index-spec.js +507 -0
  34. package/src/core/lock-wait.js +260 -0
  35. package/src/core/lock.js +95 -28
  36. package/src/core/migrator.js +600 -287
  37. package/src/core/options.js +266 -0
  38. package/src/core/run-recorder.js +157 -0
  39. package/src/core/run.js +58 -90
  40. package/src/core/search-index-spec.js +758 -0
  41. package/src/core/sequence.js +134 -0
  42. package/src/core/server-info.js +63 -0
  43. package/src/errors/index.js +60 -0
  44. package/src/index.js +8 -0
  45. package/src/utils/actor.js +48 -0
  46. package/src/utils/canonical.js +212 -0
  47. package/src/utils/collection-name.js +21 -0
  48. package/src/utils/error.js +18 -1
  49. package/src/utils/id.js +77 -0
  50. package/src/utils/loader.js +39 -21
  51. package/src/utils/migration-name.js +32 -0
  52. package/src/utils/redact.js +21 -1
  53. package/src/utils/telemetry.js +410 -0
  54. package/src/utils/template.js +43 -2
@@ -332,6 +332,8 @@ function configBody(values, createExtension) {
332
332
  // ── Bookkeeping collections ─────────────────────────────────
333
333
  migrationsCollection: '_migronaut_migrations',
334
334
  lockCollection: '_migronaut_locks',
335
+ // What each \`migronaut converge\` changed — see \`converge --history\`.
336
+ convergeLogCollection: '_migronaut_converge',
335
337
  // Seconds before a held lock is considered stale and reclaimable.
336
338
  lockTTLSeconds: 60,
337
339
 
@@ -342,6 +344,28 @@ function configBody(values, createExtension) {
342
344
  // \`export const useTransaction = true\`.
343
345
  useTransaction: false,
344
346
 
347
+ // ── Declared collections (experimental) ─────────────────────
348
+ // Indexes and validators as the end state you want: \`migronaut converge\`
349
+ // compares them with the database and makes the difference — no migration
350
+ // file per change. Here, in a directory of one file per collection, or both.
351
+ // collections: [
352
+ // {
353
+ // name: 'users',
354
+ // indexes: [{ key: { email: 1 }, unique: true }],
355
+ // validator: { $jsonSchema: { bsonType: 'object', required: ['email'] } },
356
+ // },
357
+ // ],
358
+ // collectionsDir: './collections',
359
+ // Converge at the end of every bulk \`migronaut up\`.
360
+ // convergeAfterUp: false,
361
+ // Search indexes declared for a server without Atlas Search: refuse the
362
+ // converge ('fail'), or converge everything else and skip them ('skip').
363
+ // onSearchUnavailable: 'fail',
364
+ // Hold converge until every declared search index is queryable — for at
365
+ // most searchIndexWaitTimeoutMs (10 minutes by default).
366
+ // waitForSearchIndexes: false,
367
+ // searchIndexWaitTimeoutMs: 600000,
368
+
345
369
  // ── Lifecycle hooks (code only — not available in JSON config) ──
346
370
  // hooks: {
347
371
  // beforeAll: async (ctx) => {},
@@ -349,6 +373,21 @@ function configBody(values, createExtension) {
349
373
  // beforeEach: async (name, ctx, info) => {}, // info: { direction, index, total }
350
374
  // afterEach: async (name, duration, ctx, info) => {},
351
375
  // onError: async (name, error, ctx) => {},
376
+ // },
377
+
378
+ // ── Identifiers (code only — not available in JSON config) ──
379
+ // Run ids are random UUIDs. Pass a generator for another format (ULID,
380
+ // CUID, …): called with no arguments, it must return a unique string
381
+ // synchronously — so \`generateId: ulid\` works as is.
382
+ // generateId: () => crypto.randomUUID(),
383
+
384
+ // ── OpenTelemetry (code only — not available in JSON config) ──
385
+ // Pass a tracer and/or a meter from your own @opentelemetry/api: every run
386
+ // and every migration becomes a span, and their durations become metrics.
387
+ // (\`trace\` and \`metrics\` come from '@opentelemetry/api' — import them at the top)
388
+ // telemetry: {
389
+ // tracer: trace.getTracer('@alexify/migronaut'),
390
+ // meter: metrics.getMeter('@alexify/migronaut'),
352
391
  // },`;
353
392
  }
354
393
 
@@ -388,8 +427,8 @@ ${exportStatement(esm, 'config')}
388
427
 
389
428
  /**
390
429
  * The built-in JSON config template. JSON cannot hold comments or functions, so
391
- * the `hooks`, `mongoose`, and `logger` options are unavailable here — use a
392
- * `.ts`/`.js` config if you need them.
430
+ * the `hooks`, `mongoose`, `logger`, `generateId` and `telemetry` options are
431
+ * unavailable here — use a `.ts`/`.js` config if you need them.
393
432
  */
394
433
  function defaultConfigJson(values = {}) {
395
434
  const { uri, dbName, migrationsDir } = configFields(values);
@@ -404,6 +443,7 @@ function defaultConfigJson(values = {}) {
404
443
  sequential: false,
405
444
  migrationsCollection: '_migronaut_migrations',
406
445
  lockCollection: '_migronaut_locks',
446
+ convergeLogCollection: '_migronaut_converge',
407
447
  lockTTLSeconds: 60,
408
448
  strict: false,
409
449
  useTransaction: false,
@@ -453,6 +493,7 @@ function secretConfigOptions(createExtension, migrationsDir) {
453
493
  // ── Bookkeeping collections ─────────────────────────────
454
494
  migrationsCollection: '_migronaut_migrations',
455
495
  lockCollection: '_migronaut_locks',
496
+ convergeLogCollection: '_migronaut_converge',
456
497
  lockTTLSeconds: 60,
457
498
 
458
499
  // ── Behavior ────────────────────────────────────────────