@alexify/migronaut 2.2.0 → 2.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/README.md +41 -3
  3. package/bullmq.d.ts +484 -8
  4. package/index.d.ts +1264 -9
  5. package/migronaut.schema.json +93 -1
  6. package/package.json +9 -2
  7. package/src/bullmq/background-processor.js +541 -0
  8. package/src/bullmq/index.js +12 -0
  9. package/src/bullmq/jobs.js +254 -7
  10. package/src/bullmq/processor.js +348 -21
  11. package/src/bullmq/producer.js +185 -13
  12. package/src/bullmq/service.js +484 -45
  13. package/src/cli/commands/background.js +500 -0
  14. package/src/cli/commands/create.js +6 -0
  15. package/src/cli/exit-codes.js +6 -0
  16. package/src/cli/index.js +2 -0
  17. package/src/core/audit.js +11 -1
  18. package/src/core/background-audit.js +139 -0
  19. package/src/core/background-drift.js +126 -0
  20. package/src/core/background-dry-run.js +375 -0
  21. package/src/core/background-engine.js +849 -0
  22. package/src/core/background-kit.js +432 -0
  23. package/src/core/background-partition.js +298 -0
  24. package/src/core/background-runner.js +305 -0
  25. package/src/core/background-sandbox.js +701 -0
  26. package/src/core/background-shard.js +542 -0
  27. package/src/core/background-spec.js +597 -0
  28. package/src/core/background-store.js +951 -0
  29. package/src/core/background-throttle.js +269 -0
  30. package/src/core/background-watch-plan.js +164 -0
  31. package/src/core/background-watch-store.js +78 -0
  32. package/src/core/background-watch.js +610 -0
  33. package/src/core/background.js +1127 -0
  34. package/src/core/bson-peer.js +23 -0
  35. package/src/core/changelog.js +32 -0
  36. package/src/core/collections.js +78 -8
  37. package/src/core/config.js +102 -12
  38. package/src/core/converge-plan.js +86 -7
  39. package/src/core/converge.js +88 -0
  40. package/src/core/lock.js +48 -21
  41. package/src/core/migration-logger.js +279 -0
  42. package/src/core/migrator.js +1027 -22
  43. package/src/core/options.js +36 -0
  44. package/src/core/run-recorder.js +6 -1
  45. package/src/core/run.js +26 -12
  46. package/src/core/runner.js +34 -8
  47. package/src/core/server-info.js +9 -2
  48. package/src/core/shard-info.js +76 -0
  49. package/src/core/versioning-spec.js +181 -0
  50. package/src/errors/index.js +88 -0
  51. package/src/index.js +16 -0
  52. package/src/utils/error.js +11 -2
  53. package/src/utils/job-ref.js +44 -0
  54. package/src/utils/loader.js +77 -9
  55. package/src/utils/migration-name.js +33 -1
  56. package/src/utils/redact.js +140 -3
  57. package/src/utils/telemetry.js +110 -0
  58. package/src/utils/template.js +62 -1
  59. package/src/versioning/config.js +155 -0
  60. package/src/versioning/document.js +326 -0
  61. package/src/versioning/index.js +50 -0
  62. package/src/versioning/internal.js +279 -0
  63. package/src/versioning/mongoose.js +151 -0
  64. package/src/versioning/occ.js +318 -0
  65. package/src/versioning/registry.js +187 -0
  66. package/src/versioning/upcaster.js +213 -0
  67. package/versioning.d.ts +666 -0
  68. package/versioning.js +1 -0
@@ -182,6 +182,43 @@
182
182
  "minimum": 1,
183
183
  "default": 600000,
184
184
  "description": "How long waitForSearchIndexes waits, in milliseconds, before the converge fails (the build goes on)"
185
+ },
186
+ "backgroundCollection": {
187
+ "type": "string",
188
+ "minLength": 1,
189
+ "pattern": "^(?!system\\.)[^$\\u0000]+$",
190
+ "default": "_migronaut_background",
191
+ "description": "Where background migrations keep their state — and, named after it, their partitions (<name>_partitions) and drift-watch resume tokens (<name>_watch). Experimental"
192
+ },
193
+ "backgroundInline": {
194
+ "type": "boolean",
195
+ "default": false,
196
+ "description": "Run a background migration to the end inside the up that registers it, under the migration lock (small collections, tests). Experimental"
197
+ },
198
+ "backgroundOnDrift": {
199
+ "enum": [
200
+ "reopen",
201
+ "report"
202
+ ],
203
+ "default": "reopen",
204
+ "description": "What the drift watch does with old-shape documents after a background migration completed: reopen it, or only report. Experimental"
205
+ },
206
+ "backgroundDrift": {
207
+ "enum": [
208
+ "poll",
209
+ "stream",
210
+ "both"
211
+ ],
212
+ "default": "poll",
213
+ "description": "How drift is watched: a periodic check (poll), change streams (stream, with the poll as a backstop), or both in full. Experimental"
214
+ },
215
+ "backgroundShardAware": {
216
+ "enum": [
217
+ "auto",
218
+ "off"
219
+ ],
220
+ "default": "auto",
221
+ "description": "Partition a sharded collection by its shard key and target each write at one shard (auto), or treat it like any other (off). Experimental"
185
222
  }
186
223
  },
187
224
  "definitions": {
@@ -206,6 +243,11 @@
206
243
  "required": [
207
244
  "searchIndexes"
208
245
  ]
246
+ },
247
+ {
248
+ "required": [
249
+ "versioning"
250
+ ]
209
251
  }
210
252
  ],
211
253
  "properties": {
@@ -246,7 +288,7 @@
246
288
  "strict",
247
289
  "moderate"
248
290
  ],
249
- "description": "How the validator applies to updates. Defaults to 'strict'"
291
+ "description": "How the validator applies to updates. Defaults to 'strict' — 'moderate' when the only rules are the ones versioning adds"
250
292
  },
251
293
  "validationAction": {
252
294
  "enum": [
@@ -259,6 +301,56 @@
259
301
  "prune": {
260
302
  "type": "boolean",
261
303
  "description": "Drop indexes (and search indexes, when declared) this definition does not declare — otherwise they are kept and reported"
304
+ },
305
+ "versioning": {
306
+ "$ref": "#/definitions/versioning"
307
+ }
308
+ }
309
+ },
310
+ "versioning": {
311
+ "type": "object",
312
+ "required": [
313
+ "current"
314
+ ],
315
+ "additionalProperties": false,
316
+ "description": "Document shape versioning: a validator rule and an index for the version field (and the revision field, for optimistic concurrency). Experimental",
317
+ "properties": {
318
+ "current": {
319
+ "type": "integer",
320
+ "minimum": 1,
321
+ "description": "The shape version new documents are written at"
322
+ },
323
+ "min": {
324
+ "type": "integer",
325
+ "minimum": 0,
326
+ "default": 1,
327
+ "description": "The oldest shape version still allowed — 0 types the fields without requiring them. Converge refuses to raise it while documents below it remain"
328
+ },
329
+ "field": {
330
+ "type": "string",
331
+ "minLength": 1,
332
+ "maxLength": 64,
333
+ "pattern": "^(?!\\$)(?!_id$)[^.\\u0000]+$",
334
+ "default": "__v",
335
+ "description": "The version field"
336
+ },
337
+ "revision": {
338
+ "type": "boolean",
339
+ "default": true,
340
+ "description": "Also manage a revision field for optimistic concurrency"
341
+ },
342
+ "revisionField": {
343
+ "type": "string",
344
+ "minLength": 1,
345
+ "maxLength": 64,
346
+ "pattern": "^(?!\\$)(?!_id$)[^.\\u0000]+$",
347
+ "default": "__rev",
348
+ "description": "The revision field"
349
+ },
350
+ "index": {
351
+ "type": "boolean",
352
+ "default": true,
353
+ "description": "Declare the { <field>: 1, _id: 1 } index background migrations scan"
262
354
  }
263
355
  }
264
356
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexify/migronaut",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "Elegant, fast, fully-typed, zero-dependency MongoDB migrations for Node.js — adopts an existing migrate-mongo changelog in one command",
5
5
  "license": "MIT",
6
6
  "author": "Alex Dolid <dolid.sasha@gmail.com>",
@@ -28,6 +28,10 @@
28
28
  "./bullmq": {
29
29
  "types": "./bullmq.d.ts",
30
30
  "default": "./bullmq.js"
31
+ },
32
+ "./versioning": {
33
+ "types": "./versioning.d.ts",
34
+ "default": "./versioning.js"
31
35
  }
32
36
  },
33
37
  "directories": {
@@ -38,6 +42,8 @@
38
42
  "index.d.ts",
39
43
  "bullmq.js",
40
44
  "bullmq.d.ts",
45
+ "versioning.js",
46
+ "versioning.d.ts",
41
47
  "migronaut.schema.json",
42
48
  "bin",
43
49
  "src",
@@ -96,6 +102,7 @@
96
102
  "c8": "^10.1.3",
97
103
  "esbuild": "^0.28.1",
98
104
  "ioredis": "^5.11.1",
105
+ "mermaid": "^11.17.2",
99
106
  "mongodb": "^6.12.0",
100
107
  "mongodb-memory-server": "10.4.3",
101
108
  "mongoose": "^8.9.2",
@@ -112,7 +119,7 @@
112
119
  "test:integration": "node scripts/node-test.js --test-concurrency=1 \"tests/integration/**/*.test.js\"",
113
120
  "test:coverage": "c8 --all --include 'src/**' --check-coverage --lines 90 --branches 90 --functions 90 --reporter text --reporter lcov node scripts/node-test.js --test-concurrency=1 \"tests/unit/**/*.test.js\" \"tests/integration/**/*.test.js\"",
114
121
  "test:types": "tsd",
115
- "check:dts": "tsc --noEmit --strict --skipLibCheck false index.d.ts bullmq.d.ts",
122
+ "check:dts": "tsc --noEmit --strict --skipLibCheck false index.d.ts bullmq.d.ts versioning.d.ts",
116
123
  "lint": "oxlint src bin scripts tests bench examples",
117
124
  "format": "oxfmt src bin scripts tests bench examples",
118
125
  "format:check": "oxfmt --check src bin scripts tests bench examples",