@voltro/cms 0.84.0 → 0.86.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.
- package/CHANGELOG.md +1215 -0
- package/THIRD-PARTY-NOTICES.md +118 -600
- package/dist/ContentForm.js +282 -0
- package/dist/RichDocumentEditor.js +550 -0
- package/dist/RichDocumentView.js +132 -0
- package/dist/RichTextSurface.js +135 -0
- package/dist/aiCandidates.js +199 -0
- package/dist/aiOperations.js +152 -0
- package/dist/audiences.js +31 -0
- package/dist/availability.js +121 -0
- package/dist/blueprint.js +166 -0
- package/dist/bulk.js +281 -0
- package/dist/cacheIdentity.js +152 -0
- package/dist/changes.js +90 -0
- package/dist/cmsContext.js +229 -0
- package/dist/collections.js +224 -0
- package/dist/consent.js +29 -0
- package/dist/contentType.js +191 -0
- package/dist/contentfulImport.js +162 -0
- package/dist/copies.js +89 -0
- package/dist/cutover.js +202 -0
- package/dist/deliveryChecks.js +138 -0
- package/dist/domains.js +145 -0
- package/dist/draftTexts.js +164 -0
- package/dist/duplicates.js +78 -0
- package/dist/edgePurge.js +69 -0
- package/dist/editHistory.js +113 -0
- package/dist/effectForm.js +11 -0
- package/dist/environments.js +109 -0
- package/dist/errors.js +67 -0
- package/dist/experiments.js +528 -0
- package/dist/exposure.js +28 -0
- package/dist/extensionManifest.js +81 -0
- package/dist/extensions.js +314 -0
- package/dist/fieldSchema.js +199 -0
- package/dist/formStrings.js +74 -0
- package/dist/glossary.js +73 -0
- package/dist/history.js +54 -0
- package/dist/htmlImport.js +297 -0
- package/dist/index.d.ts +2266 -170
- package/dist/index.js +73 -3947
- package/dist/media.js +29 -0
- package/dist/metrics.js +46 -0
- package/dist/migration.js +193 -0
- package/dist/migrationStages.js +13 -0
- package/dist/presenceAnchors.js +68 -0
- package/dist/preview.js +31 -0
- package/dist/promotion.js +107 -0
- package/dist/quality.js +188 -0
- package/dist/recurrence.js +78 -0
- package/dist/redirects.js +99 -0
- package/dist/referenceGraph.js +223 -0
- package/dist/references.js +173 -0
- package/dist/release.js +205 -0
- package/dist/rest.js +52 -0
- package/dist/review.js +160 -0
- package/dist/richDocument.js +491 -0
- package/dist/richInline.js +100 -0
- package/dist/schedule.js +80 -0
- package/dist/search.js +148 -0
- package/dist/selectionIntent.js +164 -0
- package/dist/seo.js +31 -0
- package/dist/series.js +105 -0
- package/dist/share.js +112 -0
- package/dist/stewardship.js +146 -0
- package/dist/taxonomy.js +36 -0
- package/dist/team.js +103 -0
- package/dist/templates.js +106 -0
- package/dist/trackChanges.js +197 -0
- package/dist/translation.js +64 -0
- package/dist/tree.js +87 -0
- package/dist/usage.js +50 -0
- package/dist/validation.js +192 -0
- package/dist/visualEditing.js +60 -0
- package/dist/web.d.ts +927 -131
- package/dist/web.js +33 -2
- package/dist/workflow.js +322 -0
- package/dist/write.js +394 -0
- package/dist/xliff.js +325 -0
- package/package.json +6 -6
- package/dist/extensionManifest-BK3ZcL2P.js +0 -2782
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/recurrence.ts
|
|
2
|
+
var e = 100, t = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/, n = /^\d{4}-\d{2}-\d{2}$/, r = 6e4, i = /* @__PURE__ */ new Map(), a = (e) => {
|
|
3
|
+
let t = i.get(e);
|
|
4
|
+
return t === void 0 && (t = new Intl.DateTimeFormat("en-US", {
|
|
5
|
+
timeZone: e,
|
|
6
|
+
hourCycle: "h23",
|
|
7
|
+
year: "numeric",
|
|
8
|
+
month: "2-digit",
|
|
9
|
+
day: "2-digit",
|
|
10
|
+
hour: "2-digit",
|
|
11
|
+
minute: "2-digit",
|
|
12
|
+
second: "2-digit"
|
|
13
|
+
}), i.set(e, t)), t;
|
|
14
|
+
}, o = (e) => {
|
|
15
|
+
try {
|
|
16
|
+
return a(e), !0;
|
|
17
|
+
} catch {
|
|
18
|
+
return !1;
|
|
19
|
+
}
|
|
20
|
+
}, s = (e, t) => {
|
|
21
|
+
let n = a(t).formatToParts(new Date(e)), i = (e) => Number(n.find((t) => t.type === e)?.value);
|
|
22
|
+
return (Date.UTC(i("year"), i("month") - 1, i("day"), i("hour"), i("minute"), i("second")) - Math.floor(e / 1e3) * 1e3) / r;
|
|
23
|
+
}, c = (e, n) => {
|
|
24
|
+
let i = t.exec(e);
|
|
25
|
+
if (i === null) throw RangeError(`not a local wall time (YYYY-MM-DDTHH:mm): ${e}`);
|
|
26
|
+
let a = Date.UTC(Number(i[1]), Number(i[2]) - 1, Number(i[3]), Number(i[4]), Number(i[5])), o = s(a - 720 * r, n), c = s(a + 720 * r, n), l = [.../* @__PURE__ */ new Set([o, c])].map((e) => a - e * r).filter((e) => s(e, n) * r === a - e).sort((e, t) => e - t);
|
|
27
|
+
return l.length === 0 ? {
|
|
28
|
+
instant: /* @__PURE__ */ new Date(a - o * r),
|
|
29
|
+
adjusted: "gap"
|
|
30
|
+
} : l.length > 1 ? {
|
|
31
|
+
instant: new Date(l[0]),
|
|
32
|
+
adjusted: "fold"
|
|
33
|
+
} : { instant: new Date(l[0]) };
|
|
34
|
+
}, l = (e) => String(e).padStart(2, "0"), u = (e, t) => new Date(Date.UTC(e, t, 0)).getUTCDate(), d = (e, t, n) => {
|
|
35
|
+
let [r, i, a, o, s] = [
|
|
36
|
+
1,
|
|
37
|
+
2,
|
|
38
|
+
3,
|
|
39
|
+
4,
|
|
40
|
+
5
|
|
41
|
+
].map((t) => Number(e[t]));
|
|
42
|
+
if (t === "month") {
|
|
43
|
+
let e = i - 1 + n, t = r + Math.floor(e / 12), c = e % 12 + 1, d = Math.min(a, u(t, c));
|
|
44
|
+
return {
|
|
45
|
+
local: `${t}-${l(c)}-${l(d)}T${l(o)}:${l(s)}`,
|
|
46
|
+
clamped: d !== a
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
let c = new Date(Date.UTC(r, i - 1, a + n * (t === "week" ? 7 : 1)));
|
|
50
|
+
return {
|
|
51
|
+
local: `${c.getUTCFullYear()}-${l(c.getUTCMonth() + 1)}-${l(c.getUTCDate())}T${l(o)}:${l(s)}`,
|
|
52
|
+
clamped: !1
|
|
53
|
+
};
|
|
54
|
+
}, f = (e, t) => t * (e === "day" ? 1440 : e === "week" ? 10080 : 40320), p = (e) => {
|
|
55
|
+
let r = [], i = e.interval ?? 1;
|
|
56
|
+
t.test(e.start) || r.push("start must be a local wall time, YYYY-MM-DDTHH:mm"), o(e.zone) || r.push(`unknown time zone '${e.zone}'`), (!Number.isInteger(e.count) || e.count < 1 || e.count > 100) && r.push("count must be between 1 and 100"), (!Number.isInteger(i) || i < 1 || i > 52) && r.push("interval must be between 1 and 52"), !Number.isInteger(e.durationMinutes) || e.durationMinutes < 1 ? r.push("an occurrence must last at least a minute") : e.durationMinutes >= f(e.every, i) && r.push("an occurrence must end before the next one starts");
|
|
57
|
+
for (let t of e.except ?? []) n.test(t) || r.push(`not a local date (YYYY-MM-DD): ${t}`);
|
|
58
|
+
return r;
|
|
59
|
+
}, m = (e) => {
|
|
60
|
+
let n = p(e);
|
|
61
|
+
if (n.length > 0) throw RangeError(n.join("; "));
|
|
62
|
+
let i = t.exec(e.start), a = e.interval ?? 1, o = new Set(e.except ?? []), s = [];
|
|
63
|
+
for (let t = 0; t < e.count; t++) {
|
|
64
|
+
let { local: n, clamped: l } = d(i, e.every, t * a);
|
|
65
|
+
if (o.has(n.slice(0, 10))) continue;
|
|
66
|
+
let { instant: u, adjusted: f } = c(n, e.zone), p = f ?? (l ? "clamped" : void 0);
|
|
67
|
+
s.push({
|
|
68
|
+
index: t,
|
|
69
|
+
local: n,
|
|
70
|
+
startsAt: u,
|
|
71
|
+
endsAt: new Date(u.getTime() + e.durationMinutes * r),
|
|
72
|
+
...p === void 0 ? {} : { adjusted: p }
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return s;
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { e as MAX_OCCURRENCES, o as isKnownZone, m as occurrencesOf, p as recurrenceProblems, c as zonedInstant };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { asTyped as e } from "./effectForm.js";
|
|
2
|
+
import { buildTree as t } from "./tree.js";
|
|
3
|
+
import { and as n, eq as r, id as i, neq as a, table as o, text as s } from "@voltro/database";
|
|
4
|
+
import { tenant as c } from "@voltro/plugin-multitenancy/mixin";
|
|
5
|
+
//#region src/redirects.ts
|
|
6
|
+
var l = "cms_paths", u = "cms_redirects", d = o(l, {
|
|
7
|
+
id: i({ prefix: "cpth" }),
|
|
8
|
+
contentType: s().maxLength(64),
|
|
9
|
+
documentId: s().maxLength(64),
|
|
10
|
+
site: s().maxLength(64),
|
|
11
|
+
environment: s().maxLength(64),
|
|
12
|
+
locale: s().maxLength(64),
|
|
13
|
+
path: s()
|
|
14
|
+
}).with(c()).index("cms_paths_by_document", [
|
|
15
|
+
"contentType",
|
|
16
|
+
"documentId",
|
|
17
|
+
"site",
|
|
18
|
+
"environment",
|
|
19
|
+
"locale"
|
|
20
|
+
]), f = o(u, {
|
|
21
|
+
id: i({ prefix: "crdr" }),
|
|
22
|
+
contentType: s().maxLength(64),
|
|
23
|
+
site: s().maxLength(64),
|
|
24
|
+
environment: s().maxLength(64),
|
|
25
|
+
locale: s().maxLength(64),
|
|
26
|
+
fromPath: s(),
|
|
27
|
+
documentId: s().maxLength(64)
|
|
28
|
+
}).with(c()).index("cms_redirects_by_path", [
|
|
29
|
+
"contentType",
|
|
30
|
+
"site",
|
|
31
|
+
"environment",
|
|
32
|
+
"locale",
|
|
33
|
+
"fromPath"
|
|
34
|
+
]), p = (e, t, n) => e.query({
|
|
35
|
+
table: t,
|
|
36
|
+
predicate: n,
|
|
37
|
+
order: [],
|
|
38
|
+
take: void 0,
|
|
39
|
+
skip: void 0,
|
|
40
|
+
projection: void 0
|
|
41
|
+
}), m = (e) => [
|
|
42
|
+
r("site", e.site),
|
|
43
|
+
r("environment", e.environment),
|
|
44
|
+
r("locale", e.locale)
|
|
45
|
+
], h = async (e, i, o, s) => {
|
|
46
|
+
if (i.tree === void 0 && i.address === void 0) return;
|
|
47
|
+
let c = await p(e, `${i.name}_published`, n(...m(o), a("status", "archived"))), d = i.address, f = i.tree === void 0 ? { nodes: c.filter((e) => typeof e[d] == "string" && e[d] !== "").map((e) => ({
|
|
48
|
+
documentId: String(e.documentId),
|
|
49
|
+
path: String(e[d])
|
|
50
|
+
})) } : t(c.map((e) => ({
|
|
51
|
+
row: e,
|
|
52
|
+
locale: o.locale,
|
|
53
|
+
fallback: !1
|
|
54
|
+
})), i.tree), h = new Map((await p(e, l, n(r("contentType", i.name), ...m(o)))).map((e) => [String(e.documentId), e])), g = s == null ? {} : { tenantId: s };
|
|
55
|
+
for (let t of f.nodes) {
|
|
56
|
+
let a = h.get(t.documentId);
|
|
57
|
+
if (a === void 0) {
|
|
58
|
+
await e.insert(l, {
|
|
59
|
+
contentType: i.name,
|
|
60
|
+
documentId: t.documentId,
|
|
61
|
+
...o,
|
|
62
|
+
path: t.path,
|
|
63
|
+
...g
|
|
64
|
+
});
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (a.path === t.path) continue;
|
|
68
|
+
let s = String(a.path), [c] = await p(e, u, n(r("contentType", i.name), ...m(o), r("fromPath", s)));
|
|
69
|
+
c === void 0 ? await e.insert(u, {
|
|
70
|
+
contentType: i.name,
|
|
71
|
+
...o,
|
|
72
|
+
fromPath: s,
|
|
73
|
+
documentId: t.documentId,
|
|
74
|
+
...g
|
|
75
|
+
}) : await e.update(u, String(c.id), { documentId: t.documentId }), await e.update(l, String(a.id), { path: t.path });
|
|
76
|
+
}
|
|
77
|
+
}, g = async (e, t, i, a, o, s) => {
|
|
78
|
+
let c = a.replace(/^\/+|\/+$/g, "");
|
|
79
|
+
if (c === "") return;
|
|
80
|
+
let l = s == null ? {} : { tenantId: s }, [d] = await p(e, u, n(r("contentType", t.name), ...m(i), r("fromPath", c)));
|
|
81
|
+
d === void 0 ? await e.insert(u, {
|
|
82
|
+
contentType: t.name,
|
|
83
|
+
...i,
|
|
84
|
+
fromPath: c,
|
|
85
|
+
documentId: o,
|
|
86
|
+
...l
|
|
87
|
+
}) : await e.update(u, String(d.id), { documentId: o });
|
|
88
|
+
}, _ = async (e, t, i, a, o) => {
|
|
89
|
+
let s = o === void 0 ? [] : [r("tenantId", o)], [c] = await p(e, u, n(r("contentType", t), ...m(a), r("fromPath", i), ...s));
|
|
90
|
+
return c === void 0 ? null : String(c.documentId);
|
|
91
|
+
}, v = async (e, t, i, a) => {
|
|
92
|
+
let o = a.replace(/^\/+|\/+$/g, ""), [s] = await p(e, u, n(r("contentType", t.name), ...m(i), r("fromPath", o)));
|
|
93
|
+
return s !== void 0 && (await e.delete(u, String(s.id)), !0);
|
|
94
|
+
}, y = async (e, t, i, a, o) => {
|
|
95
|
+
let s = o === void 0 ? [] : [r("tenantId", o)], [c] = await p(e, l, n(r("contentType", t), ...m(a), r("path", i), ...s));
|
|
96
|
+
return c !== void 0 || await _(e, t, i, a, o) !== null;
|
|
97
|
+
}, b = (e, t, i) => p(e, u, n(r("contentType", t), ...m(i))), x = (...t) => e(() => g(...t)), S = (...t) => e(() => y(...t)), C = (...t) => e(() => b(...t)), w = (...t) => e(() => h(...t)), T = (...t) => e(() => _(...t)), E = (...t) => e(() => v(...t));
|
|
98
|
+
//#endregion
|
|
99
|
+
export { l as CMS_PATHS_TABLE, u as CMS_REDIRECTS_TABLE, g as addRedirect, x as addRedirectEffect, d as cmsPathsTable, f as cmsRedirectsTable, y as hadAddress, S as hadAddressEffect, b as listRedirects, C as listRedirectsEffect, h as recordPaths, w as recordPathsEffect, _ as redirectTarget, T as redirectTargetEffect, v as removeRedirect, E as removeRedirectEffect };
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { asTyped as e } from "./effectForm.js";
|
|
2
|
+
import { ContentNotFound as t, ContentValidationFailed as n, RevisionMismatch as r } from "./errors.js";
|
|
3
|
+
import { CMS_REVISIONS_TABLE as i } from "./contentType.js";
|
|
4
|
+
import { CMS_PATHS_TABLE as a, CMS_REDIRECTS_TABLE as o } from "./redirects.js";
|
|
5
|
+
import { CMS_REFERENCES_TABLE as s, referencesOf as c, usedBy as l } from "./references.js";
|
|
6
|
+
import { pickDeclared as u, saveDraft as d } from "./write.js";
|
|
7
|
+
import { CMS_RELEASES_TABLE as f, CMS_RELEASE_ITEMS_TABLE as p } from "./release.js";
|
|
8
|
+
import { and as m, eq as h, inSet as g } from "@voltro/database";
|
|
9
|
+
//#region src/referenceGraph.ts
|
|
10
|
+
var _ = (e, t, n) => e.query({
|
|
11
|
+
table: t,
|
|
12
|
+
predicate: n,
|
|
13
|
+
order: [],
|
|
14
|
+
take: void 0,
|
|
15
|
+
skip: void 0,
|
|
16
|
+
projection: void 0
|
|
17
|
+
}), v = (e) => [h("site", e.site), h("environment", e.environment)], y = (e, t, n, r) => {
|
|
18
|
+
if (t != null) {
|
|
19
|
+
if (e.kind === "components" && Array.isArray(t)) {
|
|
20
|
+
let i = new Map((e.components ?? []).map((e) => [e.id, e]));
|
|
21
|
+
t.forEach((e, t) => {
|
|
22
|
+
let a = e;
|
|
23
|
+
if (typeof a.componentId != "string") return;
|
|
24
|
+
r.push({
|
|
25
|
+
path: `${n}[${t}]`,
|
|
26
|
+
componentId: a.componentId
|
|
27
|
+
});
|
|
28
|
+
let o = i.get(a.componentId);
|
|
29
|
+
if (o !== void 0 && typeof a.props == "object" && a.props !== null) for (let [e, i] of Object.entries(o.props)) y(i, a.props[e], `${n}[${t}].props.${e}`, r);
|
|
30
|
+
});
|
|
31
|
+
} else if (e.kind === "array" && e.element !== void 0 && Array.isArray(t)) t.forEach((t, i) => y(e.element, t, `${n}[${i}]`, r));
|
|
32
|
+
else if (e.kind === "struct" && e.struct !== void 0 && typeof t == "object") for (let [i, a] of Object.entries(e.struct)) y(a, t[i], `${n}.${i}`, r);
|
|
33
|
+
}
|
|
34
|
+
}, b = (e, t) => {
|
|
35
|
+
let n = [];
|
|
36
|
+
for (let [r, i] of Object.entries(e.fields)) y(i, t[r], r, n);
|
|
37
|
+
return n;
|
|
38
|
+
}, x = async (e, t, n, r) => {
|
|
39
|
+
let i = [];
|
|
40
|
+
if (t.length === 0) return i;
|
|
41
|
+
for (let a of await _(e, s, m(h("stage", "draft"), h("targetType", n.type), h("targetDocumentId", n.documentId), g("sourceType", t.map((e) => e.name)), ...v(r)))) i.push({
|
|
42
|
+
sourceType: String(a.sourceType),
|
|
43
|
+
sourceDocumentId: String(a.sourceDocumentId),
|
|
44
|
+
sourceVariantId: String(a.sourceVariantId),
|
|
45
|
+
locale: String(a.locale),
|
|
46
|
+
path: String(a.path),
|
|
47
|
+
revisionId: typeof a.revisionId == "string" ? a.revisionId : null
|
|
48
|
+
});
|
|
49
|
+
return i.sort((e, t) => e.sourceType.localeCompare(t.sourceType) || e.sourceDocumentId.localeCompare(t.sourceDocumentId) || e.locale.localeCompare(t.locale) || e.path.localeCompare(t.path));
|
|
50
|
+
}, S = async (e, t, n, r) => {
|
|
51
|
+
let i = [];
|
|
52
|
+
if (t.length === 0) return i;
|
|
53
|
+
for (let a of await _(e, s, m(h("stage", "revision"), h("targetType", n.type), h("targetDocumentId", n.documentId), g("sourceType", t.map((e) => e.name)), ...v(r)))) i.push({
|
|
54
|
+
sourceType: String(a.sourceType),
|
|
55
|
+
sourceDocumentId: String(a.sourceDocumentId),
|
|
56
|
+
locale: String(a.locale),
|
|
57
|
+
revisionId: String(a.revisionId),
|
|
58
|
+
number: Number(a.revisionNumber),
|
|
59
|
+
path: String(a.path)
|
|
60
|
+
});
|
|
61
|
+
return i.sort((e, t) => e.sourceType.localeCompare(t.sourceType) || e.sourceDocumentId.localeCompare(t.sourceDocumentId) || t.number - e.number || e.path.localeCompare(t.path));
|
|
62
|
+
}, C = async (e, t, n, r, s = "published") => {
|
|
63
|
+
let { type: u, documentId: d } = n, y = m(h("documentId", d), h("site", r.site), h("environment", r.environment), h("locale", r.locale)), S = null, C = null;
|
|
64
|
+
if (s === "published" || s === "draft") {
|
|
65
|
+
let [t] = await _(e, `${u.name}_${s === "draft" ? "drafts" : "published"}`, y);
|
|
66
|
+
if (t !== void 0 && (S = t, typeof t.revisionId == "string")) {
|
|
67
|
+
let [n] = await _(e, i, h("id", t.revisionId));
|
|
68
|
+
C = {
|
|
69
|
+
id: t.revisionId,
|
|
70
|
+
number: Number(n?.number ?? t.revision ?? 0)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
let [t] = await _(e, i, h("id", s.revisionId));
|
|
75
|
+
t !== void 0 && t.contentType === u.name && t.documentId === d && t.site === r.site && t.environment === r.environment && t.locale === r.locale && typeof t.values == "object" && t.values !== null && (S = t.values, C = {
|
|
76
|
+
id: String(t.id),
|
|
77
|
+
number: Number(t.number)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
let w = {
|
|
81
|
+
type: u.name,
|
|
82
|
+
documentId: d
|
|
83
|
+
}, T = s === "draft" ? await x(e, t, w, r) : (await l(e, w, r)).map((e) => ({
|
|
84
|
+
...e,
|
|
85
|
+
revisionId: null
|
|
86
|
+
})), [E] = await _(e, a, m(h("contentType", u.name), y)), D = (await _(e, o, m(h("contentType", u.name), y))).map((e) => String(e.fromPath)).sort(), O = (await _(e, `${u.name}_drafts`, m(h("documentId", d), ...v(r)))).map((e) => String(e.id)), k = O.length === 0 ? [] : await _(e, p, m(h("contentType", u.name), g("variantId", O))), A = [...new Set(k.map((e) => String(e.releaseId)))], j = A.length === 0 ? [] : await _(e, f, g("id", A)), M = new Map(j.map((e) => [String(e.id), e]));
|
|
87
|
+
return {
|
|
88
|
+
found: S !== null,
|
|
89
|
+
perspective: typeof s == "string" ? s : "revision",
|
|
90
|
+
revision: C,
|
|
91
|
+
references: S === null ? [] : c(u, S),
|
|
92
|
+
components: S === null ? [] : b(u, S),
|
|
93
|
+
usedBy: T,
|
|
94
|
+
routes: {
|
|
95
|
+
path: typeof E?.path == "string" ? E.path : null,
|
|
96
|
+
formerPaths: D
|
|
97
|
+
},
|
|
98
|
+
releases: k.flatMap((e) => {
|
|
99
|
+
let t = M.get(String(e.releaseId));
|
|
100
|
+
return t === void 0 ? [] : [{
|
|
101
|
+
releaseId: String(t.id),
|
|
102
|
+
name: String(t.name),
|
|
103
|
+
status: String(t.status),
|
|
104
|
+
action: String(e.action),
|
|
105
|
+
revisionId: typeof e.revisionId == "string" ? e.revisionId : null,
|
|
106
|
+
locale: String(e.locale)
|
|
107
|
+
}];
|
|
108
|
+
}).sort((e, t) => e.name.localeCompare(t.name) || e.locale.localeCompare(t.locale))
|
|
109
|
+
};
|
|
110
|
+
}, w = /([^.[\]]+)|\[(\d+)\]/g, T = (e, t, n) => {
|
|
111
|
+
let r = [...t.matchAll(w)].map((e) => e[2] === void 0 ? e[1] : Number(e[2])), i = (e, t) => {
|
|
112
|
+
if (t === r.length) {
|
|
113
|
+
if (typeof e == "string") return n;
|
|
114
|
+
if (typeof e == "object" && e && "target" in e) return {
|
|
115
|
+
...e,
|
|
116
|
+
target: n
|
|
117
|
+
};
|
|
118
|
+
if (typeof e == "object" && e && "asset" in e) return {
|
|
119
|
+
...e,
|
|
120
|
+
asset: n
|
|
121
|
+
};
|
|
122
|
+
throw Error("no reference here");
|
|
123
|
+
}
|
|
124
|
+
let a = r[t];
|
|
125
|
+
if (typeof a == "number") {
|
|
126
|
+
if (!Array.isArray(e) || a >= e.length) throw Error("no element here");
|
|
127
|
+
return e.map((e, n) => n === a ? i(e, t + 1) : e);
|
|
128
|
+
}
|
|
129
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw Error("no object here");
|
|
130
|
+
return {
|
|
131
|
+
...e,
|
|
132
|
+
[a]: i(e[a], t + 1)
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
try {
|
|
136
|
+
return i(e, 0);
|
|
137
|
+
} catch {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}, E = async (e, t, n, r, i) => {
|
|
141
|
+
if (n.type !== r.type) return {
|
|
142
|
+
ok: !1,
|
|
143
|
+
reason: "typeMismatch"
|
|
144
|
+
};
|
|
145
|
+
if (n.documentId === r.documentId) return {
|
|
146
|
+
ok: !1,
|
|
147
|
+
reason: "sameDocument"
|
|
148
|
+
};
|
|
149
|
+
let a = /* @__PURE__ */ new Map();
|
|
150
|
+
for (let r of await x(e, t, n, i)) {
|
|
151
|
+
let e = a.get(r.sourceVariantId);
|
|
152
|
+
a.set(r.sourceVariantId, e === void 0 ? {
|
|
153
|
+
type: r.sourceType,
|
|
154
|
+
documentId: r.sourceDocumentId,
|
|
155
|
+
variantId: r.sourceVariantId,
|
|
156
|
+
locale: r.locale,
|
|
157
|
+
revisionId: r.revisionId,
|
|
158
|
+
paths: [r.path]
|
|
159
|
+
} : {
|
|
160
|
+
...e,
|
|
161
|
+
paths: [...e.paths, r.path]
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
ok: !0,
|
|
166
|
+
items: [...a.values()]
|
|
167
|
+
};
|
|
168
|
+
}, D = async (e, i, a, o, s) => {
|
|
169
|
+
let c = new Map(i.map((e) => [e.name, e])), l = [];
|
|
170
|
+
for (let i of a) {
|
|
171
|
+
let a = c.get(i.type), f = {
|
|
172
|
+
site: s.site,
|
|
173
|
+
environment: s.environment,
|
|
174
|
+
locale: i.locale
|
|
175
|
+
};
|
|
176
|
+
try {
|
|
177
|
+
if (a === void 0) throw new t({
|
|
178
|
+
contentType: i.type,
|
|
179
|
+
id: i.variantId,
|
|
180
|
+
stage: "draft"
|
|
181
|
+
});
|
|
182
|
+
let n = await e.transactional(async (e) => {
|
|
183
|
+
let [n] = await _(e, `${a.name}_drafts`, m(h("id", i.variantId), h("site", f.site), h("environment", f.environment), h("locale", f.locale)));
|
|
184
|
+
if (n === void 0) throw new t({
|
|
185
|
+
contentType: i.type,
|
|
186
|
+
id: i.variantId,
|
|
187
|
+
stage: "draft"
|
|
188
|
+
});
|
|
189
|
+
let r = { ...u(a, n) };
|
|
190
|
+
for (let e of i.paths) r = r === null ? null : T(r, e, o);
|
|
191
|
+
return r === null ? null : d(e, a, {
|
|
192
|
+
...r,
|
|
193
|
+
id: i.variantId
|
|
194
|
+
}, f, i.revisionId === null ? {} : { expectedRevision: i.revisionId });
|
|
195
|
+
});
|
|
196
|
+
l.push(n === null ? {
|
|
197
|
+
...i,
|
|
198
|
+
outcome: "failed",
|
|
199
|
+
reason: "pathGone",
|
|
200
|
+
newRevisionId: null,
|
|
201
|
+
detail: []
|
|
202
|
+
} : {
|
|
203
|
+
...i,
|
|
204
|
+
outcome: "done",
|
|
205
|
+
reason: null,
|
|
206
|
+
newRevisionId: String(n.revisionId),
|
|
207
|
+
detail: []
|
|
208
|
+
});
|
|
209
|
+
} catch (e) {
|
|
210
|
+
let a = e instanceof r ? "revisionMoved" : e instanceof n ? "incomplete" : e instanceof t ? "notFound" : "failed", o = e instanceof n ? e.violations.map((e) => e.field) : a === "failed" ? [e instanceof Error ? e.message : String(e)] : [];
|
|
211
|
+
l.push({
|
|
212
|
+
...i,
|
|
213
|
+
outcome: "failed",
|
|
214
|
+
reason: a,
|
|
215
|
+
newRevisionId: null,
|
|
216
|
+
detail: o
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return l;
|
|
221
|
+
}, O = (...t) => e(() => C(...t)), k = (...t) => e(() => x(...t)), A = (...t) => e(() => S(...t)), j = (...t) => e(() => E(...t)), M = (...t) => e(() => D(...t));
|
|
222
|
+
//#endregion
|
|
223
|
+
export { b as componentsOf, C as documentGraph, O as documentGraphEffect, x as draftUses, k as draftUsesEffect, E as planReferenceReplacement, j as planReferenceReplacementEffect, D as replaceReferences, M as replaceReferencesEffect, S as revisionsReferencing, A as revisionsReferencingEffect, T as withReferenceAt };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { richDocumentProblems as e, richDocumentReferences as t } from "./richDocument.js";
|
|
2
|
+
import { asTyped as n } from "./effectForm.js";
|
|
3
|
+
import { and as r, eq as i, gt as a, id as o, integer as s, table as c, text as l } from "@voltro/database";
|
|
4
|
+
import { tenant as u } from "@voltro/plugin-multitenancy/mixin";
|
|
5
|
+
//#region src/references.ts
|
|
6
|
+
var d = "cms_references", f = c(d, {
|
|
7
|
+
id: o({ prefix: "cref" }),
|
|
8
|
+
sourceType: l().maxLength(64),
|
|
9
|
+
sourceDocumentId: l().maxLength(64),
|
|
10
|
+
sourceVariantId: l().maxLength(64),
|
|
11
|
+
stage: l().maxLength(16).oneOf([
|
|
12
|
+
"published",
|
|
13
|
+
"draft",
|
|
14
|
+
"revision"
|
|
15
|
+
]).default("published"),
|
|
16
|
+
revisionId: l().maxLength(64).nullable(),
|
|
17
|
+
revisionNumber: s().nullable(),
|
|
18
|
+
site: l().maxLength(64),
|
|
19
|
+
environment: l().maxLength(64),
|
|
20
|
+
locale: l().maxLength(64),
|
|
21
|
+
path: l(),
|
|
22
|
+
targetType: l().maxLength(64),
|
|
23
|
+
targetDocumentId: l().maxLength(64)
|
|
24
|
+
}).with(u()).index("cms_references_by_target", [
|
|
25
|
+
"tenantId",
|
|
26
|
+
"stage",
|
|
27
|
+
"site",
|
|
28
|
+
"environment",
|
|
29
|
+
"targetType",
|
|
30
|
+
"targetDocumentId"
|
|
31
|
+
]).index("cms_references_by_source", [
|
|
32
|
+
"stage",
|
|
33
|
+
"sourceType",
|
|
34
|
+
"sourceVariantId",
|
|
35
|
+
"site",
|
|
36
|
+
"environment",
|
|
37
|
+
"locale"
|
|
38
|
+
]), p = (n, r, i, a) => {
|
|
39
|
+
if (r != null) switch (n.kind) {
|
|
40
|
+
case "reference":
|
|
41
|
+
typeof r == "string" && r !== "" && n.referenceType !== void 0 && a.push({
|
|
42
|
+
path: i,
|
|
43
|
+
targetType: n.referenceType,
|
|
44
|
+
targetDocumentId: r
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
case "array":
|
|
48
|
+
n.element !== void 0 && Array.isArray(r) && r.forEach((e, t) => p(n.element, e, `${i}[${t}]`, a));
|
|
49
|
+
return;
|
|
50
|
+
case "struct":
|
|
51
|
+
if (n.struct !== void 0 && typeof r == "object") for (let [e, t] of Object.entries(n.struct)) p(t, r[e], `${i}.${e}`, a);
|
|
52
|
+
return;
|
|
53
|
+
case "richText": {
|
|
54
|
+
let o = n.richText ?? {};
|
|
55
|
+
if (e(i, r, o).length > 0) return;
|
|
56
|
+
let s = r;
|
|
57
|
+
a.push(...t(i, s, o));
|
|
58
|
+
let c = new Map((o.profile?.components ?? []).map((e) => [e.id, e]));
|
|
59
|
+
s.blocks.forEach((e, t) => {
|
|
60
|
+
let n = e.type === "component" ? c.get(e.componentId) : void 0;
|
|
61
|
+
if (n !== void 0 && e.type === "component") for (let [r, o] of Object.entries(n.props)) p(o, e.props[r], `${i}.blocks[${t}].props.${r}`, a);
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
case "components": {
|
|
66
|
+
if (!Array.isArray(r)) return;
|
|
67
|
+
let e = new Map((n.components ?? []).map((e) => [e.id, e]));
|
|
68
|
+
r.forEach((t, n) => {
|
|
69
|
+
let r = t, o = e.get(String(r.componentId));
|
|
70
|
+
if (o !== void 0 && typeof r.props == "object" && r.props !== null) for (let [e, t] of Object.entries(o.props)) p(t, r.props[e], `${i}[${n}].props.${e}`, a);
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
default: return;
|
|
75
|
+
}
|
|
76
|
+
}, m = (e, t) => {
|
|
77
|
+
let n = [];
|
|
78
|
+
for (let [r, i] of Object.entries(e.fields)) p(i, t[r], r, n);
|
|
79
|
+
return n;
|
|
80
|
+
}, h = (e, t, n, a) => ({
|
|
81
|
+
table: d,
|
|
82
|
+
predicate: r(i("sourceType", e.name), i("stage", a), i("sourceVariantId", t), i("site", n.site), i("environment", n.environment), i("locale", n.locale)),
|
|
83
|
+
order: [],
|
|
84
|
+
take: void 0,
|
|
85
|
+
skip: void 0,
|
|
86
|
+
projection: void 0
|
|
87
|
+
}), g = async (e, t, n, r, i = "published") => {
|
|
88
|
+
await e.deleteMany(d, { where: h(t, n, r, i).predicate });
|
|
89
|
+
}, _ = async (e, t, n, r, i = "published") => {
|
|
90
|
+
let a = n.id;
|
|
91
|
+
await g(e, t, a, r, i), await v(e, t, n, r, i);
|
|
92
|
+
}, v = async (e, t, n, r, i) => {
|
|
93
|
+
let a = n.id, o = n.tenantId, s = m(t, n).map((e) => ({
|
|
94
|
+
sourceType: t.name,
|
|
95
|
+
sourceDocumentId: n.documentId,
|
|
96
|
+
sourceVariantId: a,
|
|
97
|
+
stage: i,
|
|
98
|
+
revisionId: typeof n.revisionId == "string" ? n.revisionId : null,
|
|
99
|
+
revisionNumber: typeof n.revision == "number" ? n.revision : null,
|
|
100
|
+
site: r.site,
|
|
101
|
+
environment: r.environment,
|
|
102
|
+
locale: r.locale,
|
|
103
|
+
path: e.path,
|
|
104
|
+
targetType: e.targetType,
|
|
105
|
+
targetDocumentId: e.targetDocumentId,
|
|
106
|
+
...o == null ? {} : { tenantId: o }
|
|
107
|
+
}));
|
|
108
|
+
s.length > 0 && await e.insertMany(d, s);
|
|
109
|
+
}, y = (e) => {
|
|
110
|
+
let t = (e) => e.kind === "reference" || e.kind === "richText" || e.element !== void 0 && t(e.element) || Object.values(e.struct ?? {}).some(t) || (e.components ?? []).some((e) => Object.values(e.props).some(t));
|
|
111
|
+
return Object.values(e.fields).some(t);
|
|
112
|
+
}, b = async (e, t, n, r) => {
|
|
113
|
+
let i = n.values;
|
|
114
|
+
if (typeof i != "object" || !i) return;
|
|
115
|
+
let a = m(t, i).map((e) => ({
|
|
116
|
+
sourceType: t.name,
|
|
117
|
+
sourceDocumentId: n.documentId,
|
|
118
|
+
sourceVariantId: n.id,
|
|
119
|
+
stage: "revision",
|
|
120
|
+
revisionId: n.id,
|
|
121
|
+
revisionNumber: n.number,
|
|
122
|
+
...r,
|
|
123
|
+
...e,
|
|
124
|
+
...n.tenantId !== void 0 && n.tenantId !== null ? { tenantId: n.tenantId } : {}
|
|
125
|
+
}));
|
|
126
|
+
a.length > 0 && await e.insertMany(d, a);
|
|
127
|
+
}, x = async (e, t, n) => {
|
|
128
|
+
async function* o(t, n) {
|
|
129
|
+
let i;
|
|
130
|
+
for (;;) {
|
|
131
|
+
let o = await e.query({
|
|
132
|
+
table: t,
|
|
133
|
+
predicate: i === void 0 ? n : r(n, a("id", i)),
|
|
134
|
+
order: [{
|
|
135
|
+
column: "id",
|
|
136
|
+
direction: "asc"
|
|
137
|
+
}],
|
|
138
|
+
take: 500,
|
|
139
|
+
skip: void 0,
|
|
140
|
+
projection: void 0
|
|
141
|
+
});
|
|
142
|
+
for (let e of o) yield e;
|
|
143
|
+
if (o.length < 500) return;
|
|
144
|
+
i = String(o.at(-1).id);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
for (let a of t) {
|
|
148
|
+
for (let t of ["draft", "revision"]) await e.deleteMany(d, { where: r(i("stage", t), i("sourceType", a.name), i("site", n.site), i("environment", n.environment)) });
|
|
149
|
+
for await (let t of o(`${a.name}_drafts`, r(i("site", n.site), i("environment", n.environment)))) t.status !== "archived" && await v(e, a, t, {
|
|
150
|
+
...n,
|
|
151
|
+
locale: String(t.locale)
|
|
152
|
+
}, "draft");
|
|
153
|
+
for await (let t of o("cms_revisions", r(i("contentType", a.name), i("site", n.site), i("environment", n.environment)))) await b(e, a, t, {
|
|
154
|
+
...n,
|
|
155
|
+
locale: String(t.locale)
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}, S = async (e, t, n) => (await e.query({
|
|
159
|
+
table: d,
|
|
160
|
+
predicate: r(i("targetType", t.type), i("stage", "published"), i("targetDocumentId", t.documentId), i("site", n.site), i("environment", n.environment)),
|
|
161
|
+
order: [],
|
|
162
|
+
take: void 0,
|
|
163
|
+
skip: void 0,
|
|
164
|
+
projection: void 0
|
|
165
|
+
})).map((e) => ({
|
|
166
|
+
sourceType: e.sourceType,
|
|
167
|
+
sourceDocumentId: e.sourceDocumentId,
|
|
168
|
+
sourceVariantId: e.sourceVariantId,
|
|
169
|
+
locale: e.locale,
|
|
170
|
+
path: e.path
|
|
171
|
+
})).sort((e, t) => e.sourceType.localeCompare(t.sourceType) || e.sourceDocumentId.localeCompare(t.sourceDocumentId) || e.locale.localeCompare(t.locale) || e.path.localeCompare(t.path)), C = (...e) => n(() => S(...e)), w = (...e) => n(() => x(...e));
|
|
172
|
+
//#endregion
|
|
173
|
+
export { d as CMS_REFERENCES_TABLE, g as clearReferences, f as cmsReferencesTable, y as hasReferenceFields, x as rebuildReferenceIndex, w as rebuildReferenceIndexEffect, m as referencesOf, S as usedBy, C as usedByEffect, _ as writeReferences, b as writeRevisionReferences };
|