@stackedapp/utils 1.15.6 → 1.15.7

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 (2) hide show
  1. package/dist/apply_delta.js +17 -13
  2. package/package.json +1 -1
@@ -184,6 +184,23 @@ function applyDelta(target, delta) {
184
184
  deleteNestedValue(target, path);
185
185
  }
186
186
  }
187
+ // Apply $pull operations BEFORE addToSet/push
188
+ // This is critical for the identifier_link pattern where we:
189
+ // 1. Remove existing item (pull)
190
+ // 2. Add updated item (addToSet)
191
+ // If addToSet ran first, it would see the duplicate and not add.
192
+ if (delta.pull) {
193
+ for (const [path, criteriaList] of Object.entries(delta.pull)) {
194
+ const current = getNestedValue(target, path);
195
+ if (!Array.isArray(current)) {
196
+ continue;
197
+ }
198
+ const array = current;
199
+ // Filter out items that match ANY of the criteria
200
+ const filtered = array.filter((item) => !criteriaList.some((criteria) => itemMatchesCriteria(item, criteria)));
201
+ setNestedValue(target, path, filtered);
202
+ }
203
+ }
187
204
  // Apply $addToSet operations (add unique items to array)
188
205
  if (delta.addToSet) {
189
206
  for (const [path, items] of Object.entries(delta.addToSet)) {
@@ -213,19 +230,6 @@ function applyDelta(target, delta) {
213
230
  array.push(...items);
214
231
  }
215
232
  }
216
- // Apply $pull operations (remove matching items from array)
217
- if (delta.pull) {
218
- for (const [path, criteriaList] of Object.entries(delta.pull)) {
219
- const current = getNestedValue(target, path);
220
- if (!Array.isArray(current)) {
221
- continue;
222
- }
223
- const array = current;
224
- // Filter out items that match ANY of the criteria
225
- const filtered = array.filter((item) => !criteriaList.some((criteria) => itemMatchesCriteria(item, criteria)));
226
- setNestedValue(target, path, filtered);
227
- }
228
- }
229
233
  return target;
230
234
  }
231
235
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackedapp/utils",
3
- "version": "1.15.6",
3
+ "version": "1.15.7",
4
4
  "description": "Public utilities for Stacked platform SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",