@qkix/strapi-plugin-rewind 0.2.0 → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  import { createHash as J } from "node:crypto";
2
2
  import { AsyncLocalStorage as Z } from "node:async_hooks";
3
- const Q = ["id", "documentId", "locale"], S = [
3
+ const Q = ["id", "documentId", "locale"], E = [
4
4
  "createdAt",
5
5
  "updatedAt",
6
6
  "publishedAt",
@@ -10,15 +10,15 @@ const Q = ["id", "documentId", "locale"], S = [
10
10
  "strapi_assignee",
11
11
  "locale",
12
12
  "localizations"
13
- ], I = (e, t) => e.getModel(t), x = (e) => e?.type === "relation" || e?.type === "media", $ = (e) => e?.type === "relation" && String(e.relation ?? "").toLowerCase().startsWith("morph"), F = (e, t) => Object.entries(I(e, t).attributes).filter(
13
+ ], k = (e, t) => e.getModel(t), x = (e) => e?.type === "relation" || e?.type === "media", F = (e) => e?.type === "relation" && String(e.relation ?? "").toLowerCase().startsWith("morph"), _ = (e, t) => Object.entries(k(e, t).attributes).filter(
14
14
  ([, n]) => !["relation", "media", "component", "dynamiczone"].includes(n.type)
15
- ).map(([n]) => n), E = (e, t, n = !0) => {
16
- const i = I(e, t), o = n ? "select" : "fields";
17
- return Object.entries(i.attributes).reduce(
18
- (a, [s, r]) => {
19
- switch (r.type) {
15
+ ).map(([n]) => n), $ = (e, t, n = !0) => {
16
+ const r = k(e, t), o = n ? "select" : "fields";
17
+ return Object.entries(r.attributes).reduce(
18
+ (a, [s, i]) => {
19
+ switch (i.type) {
20
20
  case "relation": {
21
- if ($(r)) break;
21
+ if (F(i)) break;
22
22
  a[s] = { [o]: ["documentId", "locale", "publishedAt"] };
23
23
  break;
24
24
  }
@@ -28,17 +28,17 @@ const Q = ["id", "documentId", "locale"], S = [
28
28
  }
29
29
  case "component": {
30
30
  a[s] = {
31
- populate: E(e, r.component, n),
32
- [o]: F(e, r.component)
31
+ populate: $(e, i.component, n),
32
+ [o]: _(e, i.component)
33
33
  };
34
34
  break;
35
35
  }
36
36
  case "dynamiczone": {
37
37
  a[s] = {
38
- on: (r.components ?? []).reduce(
38
+ on: (i.components ?? []).reduce(
39
39
  (c, l) => (c[l] = {
40
- populate: E(e, l, n),
41
- [o]: F(e, l)
40
+ populate: $(e, l, n),
41
+ [o]: _(e, l)
42
42
  }, c),
43
43
  {}
44
44
  )
@@ -51,99 +51,99 @@ const Q = ["id", "documentId", "locale"], S = [
51
51
  {}
52
52
  );
53
53
  }, ee = (e, t) => {
54
- const n = {}, i = (a) => {
54
+ const n = {}, r = (a) => {
55
55
  if (n[a]) return;
56
- const s = I(e, a).attributes;
57
- n[a] = R(s, S);
58
- for (const r of Object.values(s))
59
- if (r.type === "component" && i(r.component), r.type === "dynamiczone")
60
- for (const c of r.components ?? []) i(c);
61
- }, o = I(e, t).attributes;
56
+ const s = k(e, a).attributes;
57
+ n[a] = N(s, E);
58
+ for (const i of Object.values(s))
59
+ if (i.type === "component" && r(i.component), i.type === "dynamiczone")
60
+ for (const c of i.components ?? []) r(c);
61
+ }, o = k(e, t).attributes;
62
62
  for (const a of Object.values(o))
63
- if (a.type === "component" && i(a.component), a.type === "dynamiczone")
64
- for (const s of a.components ?? []) i(s);
63
+ if (a.type === "component" && r(a.component), a.type === "dynamiczone")
64
+ for (const s of a.components ?? []) r(s);
65
65
  return {
66
- attributes: R(o, S),
66
+ attributes: N(o, E),
67
67
  components: n
68
68
  };
69
- }, R = (e, t) => Object.fromEntries(Object.entries(e ?? {}).filter(([n]) => !t.includes(n))), te = (e, t, n) => (Array.isArray(e) ? e : [e]).filter((o) => !!o).map(
69
+ }, N = (e, t) => Object.fromEntries(Object.entries(e ?? {}).filter(([n]) => !t.includes(n))), te = (e, t, n) => (Array.isArray(e) ? e : [e]).filter((o) => !!o).map(
70
70
  (o) => n ? { id: o.id, targetUid: t } : {
71
71
  documentId: o.documentId,
72
72
  locale: o.locale ?? null,
73
73
  targetUid: t
74
74
  }
75
75
  ), ne = (e, t, n) => {
76
- const i = I(e, t).attributes, o = {}, a = {}, s = R(n, [...S, ...Q]);
77
- for (const [r, c] of Object.entries(s)) {
78
- const l = i[r];
76
+ const r = k(e, t).attributes, o = {}, a = {}, s = N(n, [...E, ...Q]);
77
+ for (const [i, c] of Object.entries(s)) {
78
+ const l = r[i];
79
79
  if (l && x(l)) {
80
- if ($(l)) continue;
80
+ if (F(l)) continue;
81
81
  const d = l.type === "media" ? "plugin::upload.file" : l.target;
82
- a[r] = te(c, d, l.type === "media");
82
+ a[i] = te(c, d, l.type === "media");
83
83
  continue;
84
84
  }
85
- o[r] = l ? Y(e, l, c) : c;
85
+ o[i] = l ? H(e, l, c) : c;
86
86
  }
87
87
  return { data: o, relations: a, schemaSnapshot: ee(e, t) };
88
- }, Y = (e, t, n) => {
88
+ }, H = (e, t, n) => {
89
89
  if (n == null) return n;
90
90
  if (t.type === "component") {
91
- const i = (o) => _(e, t.component, o);
92
- return Array.isArray(n) ? n.map((o) => i(o)) : i(n);
91
+ const r = (o) => j(e, t.component, o);
92
+ return Array.isArray(n) ? n.map((o) => r(o)) : r(n);
93
93
  }
94
- return t.type === "dynamiczone" && Array.isArray(n) ? n.map((i) => {
95
- const o = i;
96
- return _(e, o.__component, o);
94
+ return t.type === "dynamiczone" && Array.isArray(n) ? n.map((r) => {
95
+ const o = r;
96
+ return j(e, o.__component, o);
97
97
  }) : n;
98
- }, _ = (e, t, n) => {
98
+ }, j = (e, t, n) => {
99
99
  if (!n || !t) return n;
100
- const i = I(e, t).attributes, o = {};
100
+ const r = k(e, t).attributes, o = {};
101
101
  for (const [a, s] of Object.entries(n)) {
102
102
  if (a === "id") continue;
103
- const r = i[a];
104
- o[a] = r ? Y(e, r, s) : s;
103
+ const i = r[a];
104
+ o[a] = i ? H(e, i, s) : s;
105
105
  }
106
106
  return o;
107
- }, H = (e) => {
108
- const t = /* @__PURE__ */ new Map(), n = async (i) => {
109
- if (t.has(i)) return t.get(i);
107
+ }, W = (e) => {
108
+ const t = /* @__PURE__ */ new Map(), n = async (r) => {
109
+ if (t.has(r)) return t.get(r);
110
110
  let o;
111
111
  try {
112
- o = (await e.plugin("content-manager").service("content-types").findConfiguration(e.contentTypes[i]))?.settings?.mainField;
112
+ o = (await e.plugin("content-manager").service("content-types").findConfiguration(e.contentTypes[r]))?.settings?.mainField;
113
113
  } catch {
114
114
  }
115
- return t.set(i, o), o;
115
+ return t.set(r, o), o;
116
116
  };
117
- return async (i, o) => {
117
+ return async (r, o) => {
118
118
  if (!o) return null;
119
- const s = [await n(i), "title", "name", "label"].filter(Boolean);
120
- for (const r of s) {
121
- const c = o[r];
119
+ const s = [await n(r), "title", "name", "label"].filter(Boolean);
120
+ for (const i of s) {
121
+ const c = o[i];
122
122
  if (typeof c == "string" && c.trim())
123
123
  return c.trim().slice(0, 255);
124
124
  }
125
125
  return null;
126
126
  };
127
127
  }, v = "plugin::rewind.version", oe = /* @__PURE__ */ new Set(["publish", "unpublish", "discardDraft", "restore"]), se = (e) => J("sha256").update(JSON.stringify(e)).digest("hex"), ie = ({ strapi: e }) => {
128
- const t = H(e), n = (r) => !!e.contentTypes[r]?.options?.draftAndPublish, i = (r) => !!(e.getModel(r)?.pluginOptions?.i18n?.localized ?? e.contentTypes[r]?.pluginOptions?.i18n?.localized), o = async (r, c, l) => {
129
- const d = i(r) && l.filter(Boolean).length > 0 ? { locale: { $in: l.filter(Boolean) } } : {};
130
- return e.db.query(r).findMany({
128
+ const t = W(e), n = (i) => !!e.contentTypes[i]?.options?.draftAndPublish, r = (i) => !!(e.getModel(i)?.pluginOptions?.i18n?.localized ?? e.contentTypes[i]?.pluginOptions?.i18n?.localized), o = async (i, c, l) => {
129
+ const d = r(i) && l.filter(Boolean).length > 0 ? { locale: { $in: l.filter(Boolean) } } : {};
130
+ return e.db.query(i).findMany({
131
131
  where: {
132
132
  documentId: c,
133
133
  ...d,
134
- ...n(r) ? { publishedAt: null } : {}
134
+ ...n(i) ? { publishedAt: null } : {}
135
135
  },
136
- populate: E(e, r)
136
+ populate: $(e, i)
137
137
  });
138
- }, a = async (r, c) => {
138
+ }, a = async (i, c) => {
139
139
  try {
140
- const l = e.plugin("content-manager").service("document-metadata"), d = await l.getMetadata(r, c);
140
+ const l = e.plugin("content-manager").service("document-metadata"), d = await l.getMetadata(i, c);
141
141
  return l.getStatus(c, d.availableStatus);
142
142
  } catch {
143
143
  return "draft";
144
144
  }
145
- }, s = async (r, c, l) => e.db.query(v).findOne({
146
- where: { contentType: r, relatedDocumentId: c, locale: l },
145
+ }, s = async (i, c, l) => e.db.query(v).findOne({
146
+ where: { contentType: i, relatedDocumentId: c, locale: l },
147
147
  orderBy: { createdAt: "desc" }
148
148
  });
149
149
  return {
@@ -154,25 +154,25 @@ const Q = ["id", "documentId", "locale"], S = [
154
154
  * Called from the transaction's commit hook and never awaited by the write
155
155
  * path - a failure here must not be able to reach the editor's save.
156
156
  */
157
- async captureAll(r, c) {
158
- for (const l of r)
157
+ async captureAll(i, c) {
158
+ for (const l of i)
159
159
  await this.capture(l, c);
160
160
  },
161
- async capture(r, c) {
162
- const { uid: l, relatedDocumentId: d, locale: p, origin: b } = r, m = r.before ?? await o(l, d, [p]);
163
- for (const u of m) {
164
- const h = u.locale ?? null, { data: f, relations: w, schemaSnapshot: T } = ne(e, l, u), g = se({ data: f, relations: w });
165
- !oe.has(b) && (await s(l, d, h))?.contentHash === g || await e.db.query(v).create({
161
+ async capture(i, c) {
162
+ const { uid: l, relatedDocumentId: d, locale: f, origin: b } = i, h = i.before ?? await o(l, d, [f]);
163
+ for (const m of h) {
164
+ const T = m.locale ?? null, { data: u, relations: y, schemaSnapshot: w } = ne(e, l, m), p = se({ data: u, relations: y });
165
+ !oe.has(b) && (await s(l, d, T))?.contentHash === p || await e.db.query(v).create({
166
166
  data: {
167
167
  contentType: l,
168
168
  relatedDocumentId: d,
169
- locale: h,
170
- status: await a(l, u),
171
- label: await t(l, f),
172
- data: f,
173
- relations: w,
174
- schemaSnapshot: T,
175
- contentHash: g,
169
+ locale: T,
170
+ status: await a(l, m),
171
+ label: await t(l, u),
172
+ data: u,
173
+ relations: y,
174
+ schemaSnapshot: w,
175
+ contentHash: p,
176
176
  origin: b,
177
177
  userId: c,
178
178
  pinned: !1
@@ -181,7 +181,7 @@ const Q = ["id", "documentId", "locale"], S = [
181
181
  }
182
182
  }
183
183
  };
184
- }, j = [
184
+ }, C = [
185
185
  "restore",
186
186
  "publish",
187
187
  "unpublish",
@@ -189,19 +189,19 @@ const Q = ["id", "documentId", "locale"], S = [
189
189
  "clone",
190
190
  "create",
191
191
  "update"
192
- ], C = /* @__PURE__ */ new WeakMap(), re = (e) => {
193
- let t = C.get(e);
194
- return t || (t = { intents: [], flushRegistered: !1 }, C.set(e, t)), t;
192
+ ], M = /* @__PURE__ */ new WeakMap(), re = (e) => {
193
+ let t = M.get(e);
194
+ return t || (t = { intents: [], flushRegistered: !1 }, M.set(e, t)), t;
195
195
  }, ae = (e) => {
196
196
  const t = /* @__PURE__ */ new Map();
197
197
  for (const n of e) {
198
- const i = `${n.uid}:${n.relatedDocumentId}:${n.locale ?? ""}`, o = t.get(i);
198
+ const r = `${n.uid}:${n.relatedDocumentId}:${n.locale ?? ""}`, o = t.get(r);
199
199
  if (!o) {
200
- t.set(i, n);
200
+ t.set(r, n);
201
201
  continue;
202
202
  }
203
- const a = j.indexOf(n.origin) < j.indexOf(o.origin);
204
- t.set(i, {
203
+ const a = C.indexOf(n.origin) < C.indexOf(o.origin);
204
+ t.set(r, {
205
205
  // A winning `publish` still wants the rows an earlier `discardDraft`
206
206
  // captured - losing them would lose the only copy of that state.
207
207
  ...a ? n : o,
@@ -209,11 +209,11 @@ const Q = ["id", "documentId", "locale"], S = [
209
209
  });
210
210
  }
211
211
  return [...t.values()];
212
- }, W = new Z(), ce = (e) => W.run({ active: !0 }, e), le = () => W.getStore()?.active === !0, de = 200, ue = async (e, t) => {
213
- const n = e.db.query(t), i = await n.count({ where: { label: null } });
214
- if (i === 0) return 0;
215
- e.log.info(`[rewind] labelling ${i} older version(s)…`);
216
- const o = H(e);
212
+ }, K = new Z(), ce = (e) => K.run({ active: !0 }, e), le = () => K.getStore()?.active === !0, de = 200, ue = async (e, t) => {
213
+ const n = e.db.query(t), r = await n.count({ where: { label: null } });
214
+ if (r === 0) return 0;
215
+ e.log.info(`[rewind] labelling ${r} older version(s)…`);
216
+ const o = W(e);
217
217
  let a = 0;
218
218
  for (; ; ) {
219
219
  const s = await n.findMany({
@@ -222,19 +222,19 @@ const Q = ["id", "documentId", "locale"], S = [
222
222
  limit: de
223
223
  });
224
224
  if (s.length === 0) break;
225
- for (const r of s) {
226
- const c = await o(r.contentType, r.data);
225
+ for (const i of s) {
226
+ const c = await o(i.contentType, i.data);
227
227
  await n.update({
228
- where: { id: r.id },
228
+ where: { id: i.id },
229
229
  data: { label: c ?? "" }
230
230
  }), a += 1;
231
231
  }
232
232
  }
233
233
  return e.log.info(`[rewind] labelled ${a} older version(s)`), a;
234
- }, M = { type: "core", key: "persisted_tables" }, fe = async (e, t) => {
235
- const n = await e.store.get(M) ?? [];
234
+ }, U = { type: "core", key: "persisted_tables" }, fe = async (e, t) => {
235
+ const n = await e.store.get(U) ?? [];
236
236
  n.map((o) => typeof o == "string" ? o : o.name).includes(t) || await e.store.set({
237
- ...M,
237
+ ...U,
238
238
  value: [...n, { name: t }]
239
239
  });
240
240
  }, pe = [
@@ -251,28 +251,28 @@ const Q = ["id", "documentId", "locale"], S = [
251
251
  `[rewind] could not label older versions: ${o instanceof Error ? o.message : String(o)}`
252
252
  )
253
253
  ), he(e, t);
254
- const n = () => e.plugin("rewind").service("snapshot"), i = (o) => {
254
+ const n = () => e.plugin("rewind").service("snapshot"), r = (o) => {
255
255
  if (!pe.includes(o.action)) return !1;
256
256
  const a = o.contentType?.uid ?? o.uid ?? "";
257
257
  return !(!a.startsWith("api::") || !t.contentTypes.includes(a) || le() || !t.trackApiWrites && !e.requestContext.get()?.request?.url?.startsWith("/content-manager"));
258
258
  };
259
259
  e.documents.use(async (o, a) => {
260
- if (!i(o)) return a();
261
- const s = o.contentType?.uid ?? o.uid, r = o.params?.locale ?? null, c = o.action === "discardDraft" && o.params?.documentId ? await n().readRows(s, o.params.documentId, [r]) : null, l = await a(), d = o.action === "create" || o.action === "clone" ? l?.documentId : o.params?.documentId;
260
+ if (!r(o)) return a();
261
+ const s = o.contentType?.uid ?? o.uid, i = o.params?.locale ?? null, c = o.action === "discardDraft" && o.params?.documentId ? await n().readRows(s, o.params.documentId, [i]) : null, l = await a(), d = o.action === "create" || o.action === "clone" ? l?.documentId : o.params?.documentId;
262
262
  if (!d) return l;
263
- const p = ge(e);
264
- return await e.db.transaction(async ({ trx: b, onCommit: m }) => {
265
- const u = re(b);
266
- u.intents.push({
263
+ const f = ge(e);
264
+ return await e.db.transaction(async ({ trx: b, onCommit: h }) => {
265
+ const m = re(b);
266
+ m.intents.push({
267
267
  uid: s,
268
268
  relatedDocumentId: d,
269
- locale: r,
269
+ locale: i,
270
270
  origin: o.action,
271
271
  before: c
272
- }), !u.flushRegistered && (u.flushRegistered = !0, m(() => {
273
- const h = u.intents.splice(0, u.intents.length);
274
- n().captureAll(ae(h), p).catch(
275
- (f) => e.log.error("[rewind] failed to record a version", f)
272
+ }), !m.flushRegistered && (m.flushRegistered = !0, h(() => {
273
+ const T = m.intents.splice(0, m.intents.length);
274
+ n().captureAll(ae(T), f).catch(
275
+ (u) => e.log.error("[rewind] failed to record a version", u)
276
276
  );
277
277
  }));
278
278
  }), l;
@@ -296,12 +296,12 @@ const Q = ["id", "documentId", "locale"], S = [
296
296
  const n = e.plugin("rewind").service("lock");
297
297
  if (await n.acquire("prune", 30 * 60 * 1e3))
298
298
  try {
299
- const i = await e.plugin("rewind").service("retention").prune();
300
- i.deleted > 0 && e.log.info(
301
- `[rewind] thinned ${i.deleted} version(s) across ${i.documents} document(s)`
299
+ const r = await e.plugin("rewind").service("retention").prune();
300
+ r.deleted > 0 && e.log.info(
301
+ `[rewind] thinned ${r.deleted} version(s) across ${r.documents} document(s)`
302
302
  );
303
- } catch (i) {
304
- e.log.error("[rewind] thinning failed", i);
303
+ } catch (r) {
304
+ e.log.error("[rewind] thinning failed", r);
305
305
  } finally {
306
306
  await n.release("prune");
307
307
  }
@@ -371,10 +371,10 @@ const Q = ["id", "documentId", "locale"], S = [
371
371
  throw new Error(
372
372
  '[rewind] config.contentTypes must be an array of content type uids, e.g. ["api::article.article"]'
373
373
  );
374
- const i = t.filter((o) => !o.startsWith("api::"));
375
- if (i.length > 0)
374
+ const r = t.filter((o) => !o.startsWith("api::"));
375
+ if (r.length > 0)
376
376
  throw new Error(
377
- `[rewind] config.contentTypes only supports api:: content types, received: ${i.join(", ")}`
377
+ `[rewind] config.contentTypes only supports api:: content types, received: ${r.join(", ")}`
378
378
  );
379
379
  }
380
380
  }, be = "collectionType", Te = "rewind_versions", ve = {
@@ -479,42 +479,44 @@ const Q = ["id", "documentId", "locale"], S = [
479
479
  "createdAt"
480
480
  ], Ee = ({ strapi: e }) => ({
481
481
  async find(t) {
482
- const { contentType: n, documentId: i, locale: o, page: a = 1, pageSize: s = 10 } = t.query;
483
- if (!n || !i)
482
+ const { contentType: n, documentId: r, locale: o, page: a = 1, pageSize: s = 10 } = t.query;
483
+ if (!n || !r)
484
484
  return t.badRequest("contentType and documentId are required.");
485
- const r = {
485
+ const i = {
486
486
  contentType: n,
487
- relatedDocumentId: i,
487
+ relatedDocumentId: r,
488
488
  ...o ? { locale: o } : {}
489
- }, c = Math.min(Number(s) || 10, 100), l = (Math.max(Number(a) || 1, 1) - 1) * c, [d, p] = await Promise.all([
489
+ }, c = Math.min(Number(s) || 10, 100), l = (Math.max(Number(a) || 1, 1) - 1) * c, [d, f] = await Promise.all([
490
490
  e.db.query(v).findMany({
491
491
  select: qe,
492
- where: r,
492
+ where: i,
493
493
  orderBy: { createdAt: "desc" },
494
494
  limit: c,
495
495
  offset: l
496
496
  }),
497
- e.db.query(v).count({ where: r })
497
+ e.db.query(v).count({ where: i })
498
498
  ]);
499
499
  t.body = {
500
- data: await U(e, d),
501
- meta: { page: Number(a) || 1, pageSize: c, total: p }
500
+ data: await B(e, d),
501
+ meta: { page: Number(a) || 1, pageSize: c, total: f }
502
502
  };
503
503
  },
504
504
  async findOne(t) {
505
505
  const n = await e.db.query(v).findOne({ where: { id: Number(t.params.id) } });
506
506
  if (!n) return t.notFound("No such version.");
507
- t.body = { data: (await U(e, [n]))[0] };
507
+ t.body = { data: (await B(e, [n]))[0] };
508
508
  },
509
509
  async diff(t) {
510
510
  const { against: n } = t.query;
511
+ if (n !== void 0 && !Number.isInteger(Number(n)))
512
+ return t.badRequest("against must be a version id.");
511
513
  try {
512
514
  t.body = {
513
515
  data: await e.plugin("rewind").service("diff").between(Number(t.params.id), n ? Number(n) : void 0)
514
516
  };
515
- } catch (i) {
517
+ } catch (r) {
516
518
  return t.badRequest(
517
- i instanceof Error ? i.message : "Could not compare these versions."
519
+ r instanceof Error ? r.message : "Could not compare these versions."
518
520
  );
519
521
  }
520
522
  },
@@ -540,8 +542,8 @@ const Q = ["id", "documentId", "locale"], S = [
540
542
  t.body = {
541
543
  data: await e.plugin("rewind").service("pin").set(Number(t.params.id), n)
542
544
  };
543
- } catch (i) {
544
- return t.notFound(i instanceof Error ? i.message : "No such version.");
545
+ } catch (r) {
546
+ return t.notFound(r instanceof Error ? r.message : "No such version.");
545
547
  }
546
548
  },
547
549
  async restore(t) {
@@ -553,10 +555,10 @@ const Q = ["id", "documentId", "locale"], S = [
553
555
  return t.badRequest(n instanceof Error ? n.message : "Restore failed.");
554
556
  }
555
557
  }
556
- }), U = async (e, t) => {
558
+ }), B = async (e, t) => {
557
559
  const n = [...new Set(t.map((a) => a.userId).filter(Boolean))];
558
560
  if (n.length === 0) return t.map((a) => ({ ...a, user: null }));
559
- const i = await e.db.query("admin::user").findMany({ select: ["id", "firstname", "lastname", "email"], where: { id: n } }), o = new Map(i.map((a) => [a.id, a]));
561
+ const r = await e.db.query("admin::user").findMany({ select: ["id", "firstname", "lastname", "email"], where: { id: n } }), o = new Map(r.map((a) => [a.id, a]));
560
562
  return t.map((a) => {
561
563
  const s = o.get(a.userId);
562
564
  return {
@@ -611,29 +613,29 @@ const Q = ["id", "documentId", "locale"], S = [
611
613
  ]
612
614
  }, Ne = {
613
615
  admin: $e
614
- }, B = (e) => e.match(/\S+\s*/g) ?? [], L = 2500, Fe = (e, t) => {
615
- const n = B(e), i = B(t);
616
- if (n.length > L || i.length > L)
616
+ }, L = (e) => e.match(/\S+\s*/g) ?? [], z = 2500, Fe = (e, t) => {
617
+ const n = L(e), r = L(t);
618
+ if (n.length > z || r.length > z)
617
619
  return [
618
620
  { op: "removed", value: e },
619
621
  { op: "added", value: t }
620
622
  ];
621
623
  const o = Array.from(
622
624
  { length: n.length + 1 },
623
- () => new Array(i.length + 1).fill(0)
625
+ () => new Array(r.length + 1).fill(0)
624
626
  );
625
627
  for (let l = n.length - 1; l >= 0; l -= 1)
626
- for (let d = i.length - 1; d >= 0; d -= 1)
627
- o[l][d] = n[l] === i[d] ? o[l + 1][d + 1] + 1 : Math.max(o[l + 1][d], o[l][d + 1]);
628
+ for (let d = r.length - 1; d >= 0; d -= 1)
629
+ o[l][d] = n[l] === r[d] ? o[l + 1][d + 1] + 1 : Math.max(o[l + 1][d], o[l][d + 1]);
628
630
  const a = [], s = (l, d) => {
629
- const p = a[a.length - 1];
630
- p && p.op === l ? p.value += d : a.push({ op: l, value: d });
631
+ const f = a[a.length - 1];
632
+ f && f.op === l ? f.value += d : a.push({ op: l, value: d });
631
633
  };
632
- let r = 0, c = 0;
633
- for (; r < n.length && c < i.length; )
634
- n[r] === i[c] ? (s("equal", n[r]), r += 1, c += 1) : o[r + 1][c] >= o[r][c + 1] ? (s("removed", n[r]), r += 1) : (s("added", i[c]), c += 1);
635
- for (; r < n.length; ) s("removed", n[r++]);
636
- for (; c < i.length; ) s("added", i[c++]);
634
+ let i = 0, c = 0;
635
+ for (; i < n.length && c < r.length; )
636
+ n[i] === r[c] ? (s("equal", n[i]), i += 1, c += 1) : o[i + 1][c] >= o[i][c + 1] ? (s("removed", n[i]), i += 1) : (s("added", r[c]), c += 1);
637
+ for (; i < n.length; ) s("removed", n[i++]);
638
+ for (; c < r.length; ) s("added", r[c++]);
637
639
  return a;
638
640
  }, _e = /* @__PURE__ */ new Set([
639
641
  "id",
@@ -643,19 +645,19 @@ const Q = ["id", "documentId", "locale"], S = [
643
645
  "level",
644
646
  "language",
645
647
  "url"
646
- ]), q = (e, t = 0) => t > 12 || e == null ? "" : typeof e == "string" ? e : typeof e == "boolean" ? "" : typeof e == "number" ? String(e) : Array.isArray(e) ? e.map((n) => q(n, t + 1)).filter(Boolean).join(" ") : typeof e == "object" ? Object.entries(e).filter(([n]) => !_e.has(n)).map(([, n]) => q(n, t + 1)).filter(Boolean).join(" ") : "", z = (e) => e.replace(/\s+/g, " ").trim(), je = 6, Ce = (e, t = je) => {
648
+ ]), R = (e, t = 0) => t > 12 || e == null ? "" : typeof e == "string" ? e : typeof e == "boolean" ? "" : typeof e == "number" ? String(e) : Array.isArray(e) ? e.map((n) => R(n, t + 1)).filter(Boolean).join(" ") : typeof e == "object" ? Object.entries(e).filter(([n]) => !_e.has(n)).map(([, n]) => R(n, t + 1)).filter(Boolean).join(" ") : "", P = (e) => e.replace(/\s+/g, " ").trim(), je = 6, Ce = (e, t = je) => {
647
649
  const n = [];
648
- return e.forEach((i, o) => {
649
- if (i.op !== "equal") {
650
- n.push(i);
650
+ return e.forEach((r, o) => {
651
+ if (r.op !== "equal") {
652
+ n.push(r);
651
653
  return;
652
654
  }
653
- const a = i.value.match(/\S+\s*/g) ?? [];
655
+ const a = r.value.match(/\S+\s*/g) ?? [];
654
656
  if (a.length <= t * 2 + 1) {
655
- n.push(i);
657
+ n.push(r);
656
658
  return;
657
659
  }
658
- const s = o === 0, r = o === e.length - 1, c = s ? [] : a.slice(0, t), l = r ? [] : a.slice(-t);
660
+ const s = o === 0, i = o === e.length - 1, c = s ? [] : a.slice(0, t), l = i ? [] : a.slice(-t);
659
661
  c.length && n.push({ op: "equal", value: c.join("") }), n.push({ op: "equal", value: " … " }), l.length && n.push({ op: "equal", value: l.join("") });
660
662
  }), n;
661
663
  }, Me = /* @__PURE__ */ new Set([
@@ -673,7 +675,7 @@ const Q = ["id", "documentId", "locale"], S = [
673
675
  "uid",
674
676
  "email",
675
677
  "password"
676
- ]), Ue = (e, t) => e === "text" || e === "richtext" || e === "blocks" || e === "json" || e === "customField" || e === "component" || e === "dynamiczone" || e === "string" && typeof t == "string" && t.length > 80, k = (e) => `${e.targetUid}:${e.documentId ?? e.id}`, Be = ({ strapi: e }) => {
678
+ ]), Ue = (e, t) => e === "text" || e === "richtext" || e === "blocks" || e === "json" || e === "customField" || e === "component" || e === "dynamiczone" || e === "string" && typeof t == "string" && t.length > 80, q = (e) => `${e.targetUid}:${e.documentId ?? e.id}`, Be = ({ strapi: e }) => {
677
679
  const t = (o) => o && {
678
680
  id: o.id,
679
681
  label: o.label ?? null,
@@ -683,7 +685,7 @@ const Q = ["id", "documentId", "locale"], S = [
683
685
  const a = await e.db.query(v).findOne({ where: { id: o } });
684
686
  if (!a) throw new Error(`No version with id ${o}`);
685
687
  return a;
686
- }, i = async (o) => {
688
+ }, r = async (o) => {
687
689
  const [a] = await e.db.query(v).findMany({
688
690
  where: {
689
691
  contentType: o.contentType,
@@ -706,46 +708,51 @@ const Q = ["id", "documentId", "locale"], S = [
706
708
  * change?", is what `restore.preview()` already answers.
707
709
  */
708
710
  async between(o, a) {
709
- const s = await n(o), r = a ? await n(a) : await i(s), c = e.getModel(s.contentType)?.attributes, l = s.data ?? {}, d = r?.data ?? {}, p = s.relations ?? {}, b = r?.relations ?? {}, m = [];
710
- for (const u of /* @__PURE__ */ new Set([...Object.keys(d), ...Object.keys(l)])) {
711
- const h = d[u], f = l[u];
712
- if (JSON.stringify(h) === JSON.stringify(f)) continue;
713
- const w = c?.[u]?.type ?? "unknown", T = c?.[u]?.customField, g = h === void 0 ? "added" : f === void 0 ? "removed" : "changed";
714
- if (Me.has(w) && !Ue(w, h ?? f)) {
715
- m.push({ field: u, type: w, customField: T, kind: g, before: h, after: f });
711
+ const s = await n(o), i = a ? await n(a) : null;
712
+ if (i && (i.contentType !== s.contentType || i.relatedDocumentId !== s.relatedDocumentId || i.locale !== s.locale))
713
+ throw new Error("Those two versions are not of the same document and locale.");
714
+ let c, l;
715
+ i ? (c = i.id < s.id ? i : s, l = i.id < s.id ? s : i) : (c = await r(s), l = s);
716
+ const d = e.getModel(l.contentType)?.attributes, f = l.data ?? {}, b = c?.data ?? {}, h = l.relations ?? {}, m = c?.relations ?? {}, T = [];
717
+ for (const u of /* @__PURE__ */ new Set([...Object.keys(b), ...Object.keys(f)])) {
718
+ const y = b[u], w = f[u];
719
+ if (JSON.stringify(y) === JSON.stringify(w)) continue;
720
+ const p = d?.[u]?.type ?? "unknown", D = d?.[u]?.customField, A = y === void 0 ? "added" : w === void 0 ? "removed" : "changed";
721
+ if (Me.has(p) && !Ue(p, y ?? w)) {
722
+ T.push({ field: u, type: p, customField: D, kind: A, before: y, after: w });
716
723
  continue;
717
724
  }
718
- const D = z(q(h)), A = z(q(f));
719
- if (D === A) {
720
- m.push({ field: u, type: w, customField: T, kind: g, before: void 0, after: void 0 });
725
+ const I = P(R(y)), O = P(R(w));
726
+ if (I === O) {
727
+ T.push({ field: u, type: p, customField: D, kind: A, before: void 0, after: void 0 });
721
728
  continue;
722
729
  }
723
- m.push({
730
+ T.push({
724
731
  field: u,
725
- type: w,
726
- customField: T,
727
- kind: g,
732
+ type: p,
733
+ customField: D,
734
+ kind: A,
728
735
  // Collapsed here rather than in the panel: sending an entire article
729
736
  // to highlight one word wastes the payload as well as the reader's
730
737
  // attention.
731
- spans: Ce(Fe(D, A))
738
+ spans: Ce(Fe(I, O))
732
739
  });
733
740
  }
734
- for (const u of /* @__PURE__ */ new Set([...Object.keys(b), ...Object.keys(p)])) {
735
- const h = b[u] ?? [], f = p[u] ?? [], w = new Set(h.map(k)), T = new Set(f.map(k)), g = f.filter((A) => !w.has(k(A))), D = h.filter((A) => !T.has(k(A)));
736
- g.length === 0 && D.length === 0 || m.push({
741
+ for (const u of /* @__PURE__ */ new Set([...Object.keys(m), ...Object.keys(h)])) {
742
+ const y = m[u] ?? [], w = h[u] ?? [], p = new Set(y.map(q)), D = new Set(w.map(q)), A = w.filter((O) => !p.has(q(O))), I = y.filter((O) => !D.has(q(O)));
743
+ A.length === 0 && I.length === 0 || T.push({
737
744
  field: u,
738
- type: c?.[u]?.type ?? "relation",
745
+ type: d?.[u]?.type ?? "relation",
739
746
  kind: "changed",
740
- linked: g,
741
- unlinked: D
747
+ linked: A,
748
+ unlinked: I
742
749
  });
743
750
  }
744
751
  return {
745
- from: r ? t(r) : null,
746
- to: t(s),
747
- changes: m,
748
- identical: m.length === 0
752
+ from: c ? t(c) : null,
753
+ to: t(l),
754
+ changes: T,
755
+ identical: T.length === 0
749
756
  };
750
757
  }
751
758
  };
@@ -756,11 +763,11 @@ const Q = ["id", "documentId", "locale"], S = [
756
763
  key: `lock:${n}`
757
764
  });
758
765
  return {
759
- async acquire(n, i) {
766
+ async acquire(n, r) {
760
767
  const o = await e.store.get(t(n));
761
768
  return o && o.expires > Date.now() ? !1 : (await e.store.set({
762
769
  ...t(n),
763
- value: { expires: Date.now() + i }
770
+ value: { expires: Date.now() + r }
764
771
  }), !0);
765
772
  },
766
773
  async release(n) {
@@ -771,46 +778,46 @@ const Q = ["id", "documentId", "locale"], S = [
771
778
  async set(t, n) {
772
779
  if (!Number.isInteger(t))
773
780
  throw new Error("A version id is required.");
774
- const i = await e.db.query(v).findOne({ where: { id: t }, select: ["id", "pinned"] });
775
- if (!i)
781
+ const r = await e.db.query(v).findOne({ where: { id: t }, select: ["id", "pinned"] });
782
+ if (!r)
776
783
  throw new Error(`No version with id ${t}`);
777
- return !!i.pinned === n ? { id: t, pinned: n } : (await e.db.query(v).update({ where: { id: t }, data: { pinned: n } }), { id: t, pinned: n });
784
+ return !!r.pinned === n ? { id: t, pinned: n } : (await e.db.query(v).update({ where: { id: t }, data: { pinned: n } }), { id: t, pinned: n });
778
785
  }
779
- }), K = {
786
+ }), G = {
780
787
  keepAllDays: 7,
781
788
  dailyUntilDays: 30,
782
789
  maxAgeDays: 365,
783
790
  keepAnchors: !0
784
- }, Pe = /* @__PURE__ */ new Set(["publish", "unpublish", "discardDraft", "restore"]), G = 24 * 60 * 60 * 1e3, Ye = (e, t) => (t.getTime() - new Date(e).getTime()) / G, He = (e) => e.toISOString().slice(0, 10), We = (e) => {
791
+ }, Pe = /* @__PURE__ */ new Set(["publish", "unpublish", "discardDraft", "restore"]), V = 24 * 60 * 60 * 1e3, Ye = (e, t) => (t.getTime() - new Date(e).getTime()) / V, He = (e) => e.toISOString().slice(0, 10), We = (e) => {
785
792
  const t = new Date(Date.UTC(e.getUTCFullYear(), e.getUTCMonth(), e.getUTCDate())), n = t.getUTCDay() || 7;
786
793
  t.setUTCDate(t.getUTCDate() + 4 - n);
787
- const i = new Date(Date.UTC(t.getUTCFullYear(), 0, 1)), o = Math.ceil(((t.getTime() - i.getTime()) / G + 1) / 7);
794
+ const r = new Date(Date.UTC(t.getUTCFullYear(), 0, 1)), o = Math.ceil(((t.getTime() - r.getTime()) / V + 1) / 7);
788
795
  return `${t.getUTCFullYear()}-W${o}`;
789
- }, Ke = (e, t, n = K) => {
790
- const i = /* @__PURE__ */ new Map(), o = [], a = [...e].sort(
791
- (s, r) => new Date(r.createdAt).getTime() - new Date(s.createdAt).getTime()
796
+ }, Ke = (e, t, n = G) => {
797
+ const r = /* @__PURE__ */ new Map(), o = [], a = [...e].sort(
798
+ (s, i) => new Date(i.createdAt).getTime() - new Date(s.createdAt).getTime()
792
799
  );
793
800
  for (const s of a) {
794
801
  if (s.pinned || n.keepAnchors && Pe.has(s.origin)) continue;
795
- const r = Ye(s.createdAt, t);
796
- if (r <= n.keepAllDays) continue;
797
- if (r > n.maxAgeDays) {
802
+ const i = Ye(s.createdAt, t);
803
+ if (i <= n.keepAllDays) continue;
804
+ if (i > n.maxAgeDays) {
798
805
  o.push(s.id);
799
806
  continue;
800
807
  }
801
- const c = new Date(s.createdAt), l = r <= n.dailyUntilDays ? `d:${He(c)}` : `w:${We(c)}`;
802
- i.has(l) ? o.push(s.id) : i.set(l, s);
808
+ const c = new Date(s.createdAt), l = i <= n.dailyUntilDays ? `d:${He(c)}` : `w:${We(c)}`;
809
+ r.has(l) ? o.push(s.id) : r.set(l, s);
803
810
  }
804
811
  return o;
805
- }, P = 500, Ge = ({ strapi: e }) => {
806
- const t = () => e.db.query(v), n = async (i) => {
812
+ }, Y = 500, Ge = ({ strapi: e }) => {
813
+ const t = () => e.db.query(v), n = async (r) => {
807
814
  const o = await t().findMany({
808
815
  select: ["contentType", "relatedDocumentId", "locale"],
809
- where: { createdAt: { $lt: i } }
816
+ where: { createdAt: { $lt: r } }
810
817
  }), a = /* @__PURE__ */ new Map();
811
818
  for (const s of o) {
812
- const r = `${s.contentType}|${s.relatedDocumentId}|${s.locale ?? ""}`;
813
- a.has(r) || a.set(r, {
819
+ const i = `${s.contentType}|${s.relatedDocumentId}|${s.locale ?? ""}`;
820
+ a.has(i) || a.set(i, {
814
821
  contentType: s.contentType,
815
822
  relatedDocumentId: s.relatedDocumentId,
816
823
  locale: s.locale ?? null
@@ -825,14 +832,14 @@ const Q = ["id", "documentId", "locale"], S = [
825
832
  * Returns what it did rather than logging and forgetting, so the cron can
826
833
  * report it and a test can assert on it.
827
834
  */
828
- async prune(i = /* @__PURE__ */ new Date()) {
829
- const o = e.config.get("plugin::rewind"), a = { ...K, ...o?.retention };
835
+ async prune(r = /* @__PURE__ */ new Date()) {
836
+ const o = e.config.get("plugin::rewind"), a = { ...G, ...o?.retention };
830
837
  if (o?.retention?.enabled === !1)
831
838
  return { scanned: 0, deleted: 0, documents: 0 };
832
- const s = new Date(i.getTime() - a.keepAllDays * 24 * 60 * 60 * 1e3), r = await n(s);
839
+ const s = new Date(r.getTime() - a.keepAllDays * 24 * 60 * 60 * 1e3), i = await n(s);
833
840
  let c = 0, l = 0;
834
- for (const d of r) {
835
- const p = await t().findMany({
841
+ for (const d of i) {
842
+ const f = await t().findMany({
836
843
  select: ["id", "createdAt", "origin", "pinned"],
837
844
  where: {
838
845
  contentType: d.contentType,
@@ -840,23 +847,23 @@ const Q = ["id", "documentId", "locale"], S = [
840
847
  locale: d.locale
841
848
  }
842
849
  });
843
- c += p.length;
844
- const b = Ke(p, i, a);
845
- for (let m = 0; m < b.length; m += P) {
846
- const u = b.slice(m, m + P);
847
- await t().deleteMany({ where: { id: { $in: u } } }), l += u.length;
850
+ c += f.length;
851
+ const b = Ke(f, r, a);
852
+ for (let h = 0; h < b.length; h += Y) {
853
+ const m = b.slice(h, h + Y);
854
+ await t().deleteMany({ where: { id: { $in: m } } }), l += m.length;
848
855
  }
849
856
  }
850
- return { scanned: c, deleted: l, documents: r.length };
857
+ return { scanned: c, deleted: l, documents: i.length };
851
858
  }
852
859
  };
853
860
  }, Ve = ({ strapi: e }) => {
854
861
  const t = (s) => e.getModel(s), n = async (s) => {
855
- const r = await e.db.query(v).findOne({ where: { id: s } });
856
- if (!r)
862
+ const i = await e.db.query(v).findOne({ where: { id: s } });
863
+ if (!i)
857
864
  throw new Error(`No version with id ${s}`);
858
- return r;
859
- }, i = (s) => s?.pluginOptions?.i18n?.localized === !0, o = (s) => e.contentTypes[s]?.pluginOptions?.i18n?.localized === !0, a = async (s) => s.targetUid === "plugin::upload.file" ? !!await e.db.query("plugin::upload.file").findOne({ where: { id: s.id } }) : !!await e.db.query(s.targetUid).findOne({
865
+ return i;
866
+ }, r = (s) => s?.pluginOptions?.i18n?.localized === !0, o = (s) => e.contentTypes[s]?.pluginOptions?.i18n?.localized === !0, a = async (s) => s.targetUid === "plugin::upload.file" ? !!await e.db.query("plugin::upload.file").findOne({ where: { id: s.id } }) : !!await e.db.query(s.targetUid).findOne({
860
867
  where: {
861
868
  documentId: s.documentId,
862
869
  ...s.locale ? { locale: s.locale } : {}
@@ -872,21 +879,21 @@ const Q = ["id", "documentId", "locale"], S = [
872
879
  * version of a document quietly rewrites a field in every other language.
873
880
  */
874
881
  async preview(s) {
875
- const r = await n(s), c = r.contentType, l = t(c).attributes, d = r.schemaSnapshot?.attributes ?? {}, p = r.data ?? {}, b = r.relations ?? {}, m = Object.keys(l).filter((y) => !S.includes(y)), u = Object.keys(d), h = u.filter((y) => !m.includes(y)), f = m.filter((y) => !u.includes(y)), w = u.filter((y) => m.includes(y)), T = w.filter((y) => $(l[y])), g = w.filter((y) => !T.includes(y)), D = o(c) ? g.filter((y) => !i(l[y])) : [], A = [], N = [];
876
- for (const [y, X] of Object.entries(b))
877
- if (g.includes(y))
878
- for (const O of X)
879
- await a(O) || (O.targetUid === "plugin::upload.file" ? N.push(O) : A.push(O));
880
- const V = D.length ? await e.plugin("i18n")?.service("locales").find() : [];
882
+ const i = await n(s), c = i.contentType, l = t(c).attributes, d = i.schemaSnapshot?.attributes ?? {}, f = i.data ?? {}, b = i.relations ?? {}, h = Object.keys(l).filter((g) => !E.includes(g)), m = Object.keys(d), T = m.filter((g) => !h.includes(g)), u = h.filter((g) => !m.includes(g)), y = m.filter((g) => h.includes(g)), w = y.filter((g) => F(l[g])), p = y.filter((g) => !w.includes(g)), D = o(c) ? p.filter((g) => !r(l[g])) : [], A = [], I = [];
883
+ for (const [g, X] of Object.entries(b))
884
+ if (p.includes(g))
885
+ for (const S of X)
886
+ await a(S) || (S.targetUid === "plugin::upload.file" ? I.push(S) : A.push(S));
887
+ const O = D.length ? await e.plugin("i18n")?.service("locales").find() : [];
881
888
  return {
882
- fieldsToRestore: g.filter((y) => y in p),
883
- fieldsKeptAsIs: f,
884
- fieldsDropped: h,
889
+ fieldsToRestore: p.filter((g) => g in f),
890
+ fieldsKeptAsIs: u,
891
+ fieldsDropped: T,
885
892
  crossLocaleFields: D,
886
- unsupportedFields: T,
893
+ unsupportedFields: w,
887
894
  brokenRelations: A,
888
- missingMedia: N,
889
- affectedLocales: V.map((y) => y.code)
895
+ missingMedia: I,
896
+ affectedLocales: O.map((g) => g.code)
890
897
  };
891
898
  },
892
899
  /**
@@ -895,8 +902,8 @@ const Q = ["id", "documentId", "locale"], S = [
895
902
  * The document lands in "modified" and publishing stays a deliberate act -
896
903
  * restoring must never change what the public sees on its own.
897
904
  */
898
- async apply(s, r) {
899
- const c = await n(s), l = c.contentType, d = await this.preview(s), p = [];
905
+ async apply(s, i) {
906
+ const c = await n(s), l = c.contentType, d = await this.preview(s), f = [];
900
907
  await e.plugin("rewind").service("snapshot").capture(
901
908
  {
902
909
  uid: l,
@@ -905,30 +912,30 @@ const Q = ["id", "documentId", "locale"], S = [
905
912
  origin: "restore",
906
913
  before: null
907
914
  },
908
- r
915
+ i
909
916
  );
910
- const b = {}, m = c.data ?? {}, u = c.relations ?? {};
911
- for (const f of d.fieldsToRestore)
912
- b[f] = m[f];
913
- const h = new Set(
917
+ const b = {}, h = c.data ?? {}, m = c.relations ?? {};
918
+ for (const u of d.fieldsToRestore)
919
+ b[u] = h[u];
920
+ const T = new Set(
914
921
  [...d.brokenRelations, ...d.missingMedia].map(
915
- (f) => `${f.targetUid}:${f.documentId ?? f.id}`
922
+ (u) => `${u.targetUid}:${u.documentId ?? u.id}`
916
923
  )
917
924
  );
918
- for (const [f, w] of Object.entries(u)) {
919
- if (d.unsupportedFields.includes(f) || d.fieldsDropped.includes(f)) continue;
920
- const T = w.filter(
921
- (g) => !h.has(`${g.targetUid}:${g.documentId ?? g.id}`)
925
+ for (const [u, y] of Object.entries(m)) {
926
+ if (d.unsupportedFields.includes(u) || d.fieldsDropped.includes(u)) continue;
927
+ const w = y.filter(
928
+ (p) => !T.has(`${p.targetUid}:${p.documentId ?? p.id}`)
922
929
  );
923
- T.length !== w.length && p.push(
924
- `${w.length - T.length} target(s) of "${f}" no longer exist and were skipped.`
925
- ), b[f] = T.map(
926
- (g) => g.targetUid === "plugin::upload.file" ? g.id : g.documentId
930
+ w.length !== y.length && f.push(
931
+ `${y.length - w.length} target(s) of "${u}" no longer exist and were skipped.`
932
+ ), b[u] = w.map(
933
+ (p) => p.targetUid === "plugin::upload.file" ? p.id : p.documentId
927
934
  );
928
935
  }
929
- return d.fieldsDropped.length && p.push(
936
+ return d.fieldsDropped.length && f.push(
930
937
  `Skipped ${d.fieldsDropped.length} field(s) no longer in the model: ${d.fieldsDropped.join(", ")}.`
931
- ), d.crossLocaleFields.length && p.push(
938
+ ), d.crossLocaleFields.length && f.push(
932
939
  `${d.crossLocaleFields.join(", ")} are not localised, so they changed in every locale.`
933
940
  ), await ce(async () => {
934
941
  await e.documents(l).update({
@@ -939,7 +946,7 @@ const Q = ["id", "documentId", "locale"], S = [
939
946
  status: "draft",
940
947
  data: b
941
948
  });
942
- }), { documentId: c.relatedDocumentId, warnings: p };
949
+ }), { documentId: c.relatedDocumentId, warnings: f };
943
950
  }
944
951
  };
945
952
  }, Xe = {