@lowdefy/codemods 5.4.0 → 5.5.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/codemods",
3
- "version": "5.4.0",
3
+ "version": "5.5.1",
4
4
  "description": "Codemod scripts and migration prompts for Lowdefy version upgrades",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/registry.json CHANGED
@@ -1,5 +1,17 @@
1
1
  {
2
2
  "versions": [
3
+ {
4
+ "version": "5.5.0",
5
+ "from": ">=5.1.0 <5.5.0",
6
+ "description": "MongoDBUpdateOne throws a no-match error by default; opt out per request with disableNoMatchError",
7
+ "codemods": [
8
+ {
9
+ "id": "add-disable-no-match-error",
10
+ "description": "Add disableNoMatchError: true to existing MongoDBUpdateOne requests to preserve pre-5.5.0 behavior, with a per-request report for author review. No-op for apps using @lowdefy/community-plugin-mongodb.",
11
+ "path": "v5-5-0/01-add-disable-no-match-error.md"
12
+ }
13
+ ]
14
+ },
3
15
  {
4
16
  "version": "5.1.0",
5
17
  "from": ">=5.0.0 <5.1.0",
@@ -0,0 +1,128 @@
1
+ # Migration: Preserve `MongoDBUpdateOne` no-match behavior with `disableNoMatchError`
2
+
3
+ ## Context
4
+
5
+ From Lowdefy v5.5.0, the `MongoDBUpdateOne` and `MongoDBVersionedUpdateOne` requests throw `No matching record to update.` when the filter matches no document (and `upsert` is not set). Before v5.5.0, `MongoDBUpdateOne` silently returned `matchedCount: 0`. The new default fails loudly because a no-match update usually indicates a bug — a wrong filter or a missing document.
6
+
7
+ Requests can opt out of the error with the request property `disableNoMatchError: true`.
8
+
9
+ Apps already using `@lowdefy/community-plugin-mongodb` have always had this throwing behavior and need **no changes** — for those apps this codemod is a no-op.
10
+
11
+ ## What to Do
12
+
13
+ ### Step 1: Check whether the app uses the community plugin
14
+
15
+ ```bash
16
+ grep -rn 'community-plugin-mongodb' lowdefy.yaml lowdefy.yml package.json 2>/dev/null
17
+ grep -rn 'community-plugin-mongodb' --include='*.yaml' --include='*.yml' . | grep -i 'plugin'
18
+ ```
19
+
20
+ If the app lists `@lowdefy/community-plugin-mongodb` as a plugin, **stop — no changes needed**. The app already has the throwing behavior and the same `disableNoMatchError` flag.
21
+
22
+ ### Step 2: Find all MongoDBUpdateOne requests
23
+
24
+ ```bash
25
+ grep -rn 'type:\s*MongoDBUpdateOne' --include='*.yaml' --include='*.yml' --include='*.njk' .
26
+ ```
27
+
28
+ ### Step 3: Add `disableNoMatchError: true` to each request
29
+
30
+ For every request found, add `disableNoMatchError: true` to the request `properties`, so the app behaves exactly as before the upgrade. Skip requests that:
31
+
32
+ - already set `disableNoMatchError` (either value), or
33
+ - set `upsert: true` in `options` (upserts never throw the no-match error).
34
+
35
+ ### Step 4: Report
36
+
37
+ Produce a report with one entry per modified request:
38
+
39
+ - File path + line number of the request definition.
40
+ - The request `id`.
41
+ - Whether the flag was added, or why it was skipped (`upsert`, already set).
42
+
43
+ Share the report with the app author. For each request, the author should decide whether to **remove** the flag and adopt the new fail-loudly default — for most update requests the throw is the better behavior, since a silent no-op update hides bugs. The flag should only stay on requests where "update if exists" is the intended logic.
44
+
45
+ ### Step 5: Verify
46
+
47
+ ```bash
48
+ grep -rn -A 10 'type:\s*MongoDBUpdateOne' --include='*.yaml' --include='*.yml' --include='*.njk' . | grep -c 'disableNoMatchError\|upsert'
49
+ ```
50
+
51
+ Every `MongoDBUpdateOne` request should now either set `disableNoMatchError`, set `upsert: true`, or have been deliberately left to throw by the author.
52
+
53
+ ## Scope
54
+
55
+ `app` — all YAML config files including Nunjucks templates (`.yaml.njk`), shared components, module files, and API endpoint definitions. Also check directories referenced by `_ref` paths outside the main app directory (e.g., `modules/`, `shared/`). Requests can be defined on pages and in `api:` endpoints — both count.
56
+
57
+ ## Files to Check
58
+
59
+ Glob: `**/*.{yaml,yml,njk}`
60
+ Grep: `type:\s*MongoDBUpdateOne`
61
+
62
+ **Do not forget `.yaml.njk` files** — Nunjucks templates contain the same request structures.
63
+
64
+ ## Examples
65
+
66
+ ### Before
67
+
68
+ ```yaml
69
+ requests:
70
+ - id: update_status
71
+ type: MongoDBUpdateOne
72
+ connectionId: orders
73
+ properties:
74
+ filter:
75
+ _id:
76
+ _state: order_id
77
+ update:
78
+ $set:
79
+ status: shipped
80
+ ```
81
+
82
+ ### After
83
+
84
+ ```yaml
85
+ requests:
86
+ - id: update_status
87
+ type: MongoDBUpdateOne
88
+ connectionId: orders
89
+ properties:
90
+ disableNoMatchError: true
91
+ filter:
92
+ _id:
93
+ _state: order_id
94
+ update:
95
+ $set:
96
+ status: shipped
97
+ ```
98
+
99
+ ### Skipped — upsert request (never throws)
100
+
101
+ ```yaml
102
+ requests:
103
+ - id: upsert_setting
104
+ type: MongoDBUpdateOne
105
+ connectionId: settings
106
+ properties:
107
+ filter:
108
+ key: theme
109
+ update:
110
+ $set:
111
+ value: dark
112
+ options:
113
+ upsert: true
114
+ ```
115
+
116
+ ## Edge Cases
117
+
118
+ - Requests whose `properties` are built with operators (e.g., a `_ref` to a shared request file): follow the `_ref` and add the flag in the referenced file. If the referenced file is shared by multiple requests, adding the flag there changes all of them — list this in the report for author review instead of editing blindly.
119
+ - Requests with `options` set via an operator (e.g., `options: { _if: ... }`) where `upsert` cannot be determined statically: add the flag and note it in the report.
120
+ - `MongoDBVersionedUpdateOne` is new in v5.5.0, so no existing configs reference it — only `MongoDBUpdateOne` needs migration.
121
+
122
+ ## Verification
123
+
124
+ ```bash
125
+ grep -rn 'type:\s*MongoDBUpdateOne' --include='*.yaml' --include='*.yml' --include='*.njk' .
126
+ ```
127
+
128
+ Cross-check the report against this list — every request is either modified, skipped for `upsert`, or explicitly signed off by the author to adopt the throwing default.