@marktiderman/genesis-features 0.6.1 → 0.8.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/README.md +38 -20
- package/dist/blocks.d.ts +230 -144
- package/dist/blocks.js +1 -1
- package/dist/chunk-6TSENYUN.js +493 -0
- package/dist/chunk-6TSENYUN.js.map +1 -0
- package/dist/{chunk-JMXJZT6O.js → chunk-SEFG2QV6.js} +47 -12
- package/dist/chunk-SEFG2QV6.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -2
- package/dist/{model-8dMGbgtM.d.ts → model-sTRmrxz3.d.ts} +78 -8
- package/dist/node.d.ts +2 -1
- package/dist/node.js +4 -3
- package/dist/node.js.map +1 -1
- package/dist/packages-CWhdXtzS.d.ts +203 -0
- package/dist/react.d.ts +2 -1
- package/dist/react.js +1 -1
- package/package.json +41 -7
- package/dist/chunk-JMXJZT6O.js.map +0 -1
- package/dist/chunk-OBVR6AZR.js +0 -261
- package/dist/chunk-OBVR6AZR.js.map +0 -1
package/dist/chunk-OBVR6AZR.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { requirementProblem, cycleProblems, dependencyOrder } from './chunk-VYUX7VAX.js';
|
|
2
|
-
import { FEATURE_PLATFORMS } from './chunk-B6WRD3WF.js';
|
|
3
|
-
|
|
4
|
-
// src/blocks.ts
|
|
5
|
-
var BlockError = class extends Error {
|
|
6
|
-
constructor(problems) {
|
|
7
|
-
super(`Invalid blocks:
|
|
8
|
-
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
9
|
-
this.problems = problems;
|
|
10
|
-
this.name = "BlockError";
|
|
11
|
-
}
|
|
12
|
-
problems;
|
|
13
|
-
};
|
|
14
|
-
var ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
15
|
-
var CONTRIBUTION_KEYS = ["nav", "settings", "routes", "slots", "migrations", "skills", "privacy"];
|
|
16
|
-
function duplicates(values) {
|
|
17
|
-
const seen = /* @__PURE__ */ new Set();
|
|
18
|
-
const dup = /* @__PURE__ */ new Set();
|
|
19
|
-
for (const v of values) (seen.has(v) ? dup : seen).add(v);
|
|
20
|
-
return [...dup];
|
|
21
|
-
}
|
|
22
|
-
function blockProblems(block) {
|
|
23
|
-
const { id } = block;
|
|
24
|
-
const problems = [];
|
|
25
|
-
if (typeof id !== "string" || !ID.test(id)) problems.push(`${String(id)}: a block id is a feature id: lowercase letters and digits, joined by -, _ or .`);
|
|
26
|
-
for (const req of block.requires ?? []) {
|
|
27
|
-
if (req === id) problems.push(`${id}.requires: a block can't require itself`);
|
|
28
|
-
else if (!ID.test(req)) problems.push(`${id}.requires: "${req}" is not a feature id`);
|
|
29
|
-
}
|
|
30
|
-
for (const p of block.platforms ?? []) {
|
|
31
|
-
if (!FEATURE_PLATFORMS.includes(p)) problems.push(`${id}.platforms: "${p}" is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
32
|
-
}
|
|
33
|
-
if (block.platforms && block.platforms.length === 0) problems.push(`${id}.platforms: an empty list runs nowhere; leave it out for every platform`);
|
|
34
|
-
const c = block.contributes ?? {};
|
|
35
|
-
for (const key of Object.keys(c)) {
|
|
36
|
-
if (!CONTRIBUTION_KEYS.includes(key)) problems.push(`${id}.contributes.${key}: not a contribution (${CONTRIBUTION_KEYS.join(", ")})`);
|
|
37
|
-
}
|
|
38
|
-
for (const d of duplicates((c.nav ?? []).map((n) => n.id))) problems.push(`${id}.contributes.nav: "${d}" appears twice`);
|
|
39
|
-
for (const d of duplicates((c.settings ?? []).map((r) => r.id))) problems.push(`${id}.contributes.settings: "${d}" appears twice`);
|
|
40
|
-
for (const d of duplicates((c.routes ?? []).map((r) => r.path))) problems.push(`${id}.contributes.routes: "${d}" appears twice`);
|
|
41
|
-
for (const n of c.nav ?? []) if (!n.id || !n.label || !n.path) problems.push(`${id}.contributes.nav: every entry needs an id, a label and a path`);
|
|
42
|
-
for (const r of c.settings ?? []) if (!r.id || !r.section || !r.title) problems.push(`${id}.contributes.settings: every row needs an id, a section and a title`);
|
|
43
|
-
for (const m of c.migrations ?? []) if (!m.package || !m.file) problems.push(`${id}.contributes.migrations: every migration needs a package and a file`);
|
|
44
|
-
return problems;
|
|
45
|
-
}
|
|
46
|
-
function defineBlock(block) {
|
|
47
|
-
const problems = blockProblems(block);
|
|
48
|
-
if (problems.length) throw new BlockError(problems);
|
|
49
|
-
return Object.freeze(block);
|
|
50
|
-
}
|
|
51
|
-
function enabledPredicate(enabled) {
|
|
52
|
-
if (enabled === void 0) return void 0;
|
|
53
|
-
if (typeof enabled === "function") return enabled;
|
|
54
|
-
const set = new Set(enabled);
|
|
55
|
-
return (id) => set.has(id);
|
|
56
|
-
}
|
|
57
|
-
var byOrder = (items) => items.sort((a, b) => (a.item.order ?? 0) - (b.item.order ?? 0) || a.at - b.at).map((x) => x.item);
|
|
58
|
-
function resolveBlocks(blocks, enabled, options = {}) {
|
|
59
|
-
const { platform, features, missing = "throw", slots: slotNames } = options;
|
|
60
|
-
const problems = [];
|
|
61
|
-
const byId = /* @__PURE__ */ new Map();
|
|
62
|
-
for (const block of blocks) {
|
|
63
|
-
problems.push(...blockProblems(block));
|
|
64
|
-
if (byId.has(block.id)) problems.push(`${block.id}: two blocks have this id`);
|
|
65
|
-
else byId.set(block.id, block);
|
|
66
|
-
}
|
|
67
|
-
const isFeature = features ? (id) => Object.hasOwn(features, id) : void 0;
|
|
68
|
-
if (isFeature) {
|
|
69
|
-
for (const id of byId.keys()) if (!isFeature(id)) problems.push(`${id}: not a feature in the registry`);
|
|
70
|
-
}
|
|
71
|
-
const graph = Object.fromEntries([...byId].map(([id, b]) => [id, { requires: b.requires }]));
|
|
72
|
-
const known = { noun: "block", isKnown: (req) => byId.has(req) || !isFeature || isFeature(req) };
|
|
73
|
-
for (const [id, node] of Object.entries(graph)) {
|
|
74
|
-
for (const req of node.requires ?? []) {
|
|
75
|
-
if (req !== id && requirementProblem(graph, id, req, known)) problems.push(`${id}.requires: "${req}" is neither a block nor a feature in the registry`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
problems.push(...cycleProblems(graph));
|
|
79
|
-
if (problems.length) throw new BlockError(problems);
|
|
80
|
-
const isOn = enabledPredicate(enabled);
|
|
81
|
-
const runsHere = (b) => !platform || !b.platforms || b.platforms.includes(platform);
|
|
82
|
-
const active = /* @__PURE__ */ new Set();
|
|
83
|
-
for (const [id, b] of byId) if ((!isOn || isOn(id)) && runsHere(b)) active.add(id);
|
|
84
|
-
const order = dependencyOrder(graph);
|
|
85
|
-
const dropped = [];
|
|
86
|
-
for (const id of order) {
|
|
87
|
-
if (!active.has(id)) continue;
|
|
88
|
-
const off = (byId.get(id).requires ?? []).filter((req) => {
|
|
89
|
-
if (byId.has(req)) return !active.has(req);
|
|
90
|
-
return !isOn || !isOn(req);
|
|
91
|
-
});
|
|
92
|
-
if (!off.length) continue;
|
|
93
|
-
if (missing === "drop") {
|
|
94
|
-
active.delete(id);
|
|
95
|
-
dropped.push({ id, missing: off });
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
for (const req of off) {
|
|
99
|
-
const why = !byId.has(req) ? isOn ? "is not enabled" : "is not one of the blocks given (pass it, or list the app feature in enabled)" : !runsHere(byId.get(req)) ? `doesn't run on ${platform}` : "is off";
|
|
100
|
-
problems.push(`${id}.requires: "${req}" ${why}; turn it on or turn ${id} off`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (problems.length) throw new BlockError(problems);
|
|
104
|
-
const on = order.filter((id) => active.has(id)).map((id) => byId.get(id));
|
|
105
|
-
const nav = [];
|
|
106
|
-
const settings = [];
|
|
107
|
-
const routes = [];
|
|
108
|
-
const migrations = [];
|
|
109
|
-
const skills = [];
|
|
110
|
-
const privacy = [];
|
|
111
|
-
const slots = {};
|
|
112
|
-
const owner = { nav: /* @__PURE__ */ new Map(), settings: /* @__PURE__ */ new Map(), routes: /* @__PURE__ */ new Map(), slots: /* @__PURE__ */ new Map() };
|
|
113
|
-
const claim = (kind, key, id, what) => {
|
|
114
|
-
const first = owner[kind].get(key);
|
|
115
|
-
if (first !== void 0) problems.push(`${id}.contributes.${kind}: ${what} "${key}" is already contributed by ${first}`);
|
|
116
|
-
else owner[kind].set(key, id);
|
|
117
|
-
return first === void 0;
|
|
118
|
-
};
|
|
119
|
-
on.forEach((block, at) => {
|
|
120
|
-
const feature = block.id;
|
|
121
|
-
const c = block.contributes ?? {};
|
|
122
|
-
for (const n of c.nav ?? []) if (claim("nav", n.id, feature, "the nav entry")) nav.push({ item: { ...n, feature }, at });
|
|
123
|
-
for (const r of c.settings ?? []) if (claim("settings", r.id, feature, "the settings row")) settings.push({ item: { ...r, feature }, at });
|
|
124
|
-
for (const r of c.routes ?? []) if (claim("routes", r.path, feature, "the route")) routes.push({ ...r, feature });
|
|
125
|
-
for (const [name, fill] of Object.entries(c.slots ?? {})) {
|
|
126
|
-
if (slotNames && !slotNames.includes(name)) {
|
|
127
|
-
problems.push(`${feature}.contributes.slots: "${name}" is not a slot here (${slotNames.join(", ")})`);
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
if (claim("slots", name, feature, "the slot")) slots[name] = fill;
|
|
131
|
-
}
|
|
132
|
-
for (const m of c.migrations ?? []) migrations.push({ ...m, feature });
|
|
133
|
-
for (const path of c.skills ?? []) skills.push({ path, feature });
|
|
134
|
-
if (c.privacy) privacy.push({ ...c.privacy, feature });
|
|
135
|
-
});
|
|
136
|
-
if (problems.length) throw new BlockError(problems);
|
|
137
|
-
const ids = new Set(on.map((b) => b.id));
|
|
138
|
-
return Object.freeze({
|
|
139
|
-
blocks: Object.freeze(on),
|
|
140
|
-
ids,
|
|
141
|
-
has: (id) => ids.has(id),
|
|
142
|
-
contributionsOf: (id) => ids.has(id) ? byId.get(id).contributes ?? {} : void 0,
|
|
143
|
-
nav: Object.freeze(byOrder(nav)),
|
|
144
|
-
settings: Object.freeze(byOrder(settings)),
|
|
145
|
-
routes: Object.freeze(routes),
|
|
146
|
-
slots: Object.freeze(slots),
|
|
147
|
-
migrations: Object.freeze(migrations),
|
|
148
|
-
skills: Object.freeze(skills),
|
|
149
|
-
privacy: Object.freeze(privacy),
|
|
150
|
-
dropped: Object.freeze(dropped)
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// src/content-packs.ts
|
|
155
|
-
var CONTENT_PACK_FIELD_TARGETS = {
|
|
156
|
-
pursuits: "pursuits",
|
|
157
|
-
work_items: "pursuits",
|
|
158
|
-
metrics: "metrics",
|
|
159
|
-
sessions: "sessions"
|
|
160
|
-
};
|
|
161
|
-
var ContentPackError = class extends Error {
|
|
162
|
-
constructor(problems) {
|
|
163
|
-
super(`Invalid content pack:
|
|
164
|
-
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
165
|
-
this.problems = problems;
|
|
166
|
-
this.name = "ContentPackError";
|
|
167
|
-
}
|
|
168
|
-
problems;
|
|
169
|
-
};
|
|
170
|
-
var KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
171
|
-
var KEY = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
172
|
-
var SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
173
|
-
var SECTION_BLOCK = { sessionTypes: "sessions", metricTemplates: "metrics", forms: "forms", roadmapTemplates: "roadmap" };
|
|
174
|
-
function keyProblems(where, items) {
|
|
175
|
-
const problems = [];
|
|
176
|
-
const seen = /* @__PURE__ */ new Set();
|
|
177
|
-
for (const [i, item] of (items ?? []).entries()) {
|
|
178
|
-
if (typeof item?.key !== "string" || !KEY.test(item.key)) problems.push(`${where}[${i}].key: "${String(item?.key)}" is not a key (lowercase, dots, dashes or underscores)`);
|
|
179
|
-
else if (seen.has(item.key)) problems.push(`${where}: the key "${item.key}" is used twice`);
|
|
180
|
-
else seen.add(item.key);
|
|
181
|
-
}
|
|
182
|
-
return problems;
|
|
183
|
-
}
|
|
184
|
-
function contentPackBlocks(pack) {
|
|
185
|
-
const needed = /* @__PURE__ */ new Set();
|
|
186
|
-
for (const [section, block] of Object.entries(SECTION_BLOCK)) {
|
|
187
|
-
const items = pack[section];
|
|
188
|
-
if (items && items.length) needed.add(block);
|
|
189
|
-
}
|
|
190
|
-
for (const f of pack.fieldDefinitions ?? []) {
|
|
191
|
-
const block = CONTENT_PACK_FIELD_TARGETS[f.target];
|
|
192
|
-
if (block) needed.add(block);
|
|
193
|
-
}
|
|
194
|
-
return [...needed].sort();
|
|
195
|
-
}
|
|
196
|
-
function test(blocks) {
|
|
197
|
-
if (typeof blocks === "function") return blocks;
|
|
198
|
-
const set = new Set(blocks);
|
|
199
|
-
return (id) => set.has(id);
|
|
200
|
-
}
|
|
201
|
-
function contentPackProblems(pack, installed) {
|
|
202
|
-
const at = `content pack ${typeof pack?.id === "string" ? pack.id : "?"}`;
|
|
203
|
-
const problems = [];
|
|
204
|
-
if (typeof pack?.id !== "string" || !KEBAB.test(pack.id)) problems.push(`${at}: id must be kebab-case`);
|
|
205
|
-
if (typeof pack?.name !== "string" || !pack.name.trim()) problems.push(`${at}: needs a name`);
|
|
206
|
-
if (typeof pack?.version !== "string" || !SEMVER.test(pack.version)) problems.push(`${at}: version "${String(pack?.version)}" isn't semver`);
|
|
207
|
-
if (typeof pack?.publisher !== "string" || !pack.publisher.trim()) problems.push(`${at}: needs a publisher (its package name)`);
|
|
208
|
-
if (!Array.isArray(pack?.requires)) {
|
|
209
|
-
problems.push(`${at}: requires must list the blocks it fills`);
|
|
210
|
-
return problems;
|
|
211
|
-
}
|
|
212
|
-
for (const [label, text] of Object.entries(pack.labels ?? {})) {
|
|
213
|
-
if (!KEY.test(label)) problems.push(`${at}: label key "${label}" is not a key`);
|
|
214
|
-
if (typeof text !== "string" || !text.trim()) problems.push(`${at}: label "${label}" needs display text`);
|
|
215
|
-
}
|
|
216
|
-
problems.push(
|
|
217
|
-
...keyProblems(`${at}.sessionTypes`, pack.sessionTypes),
|
|
218
|
-
...keyProblems(`${at}.metricTemplates`, pack.metricTemplates),
|
|
219
|
-
...keyProblems(`${at}.fieldDefinitions`, pack.fieldDefinitions),
|
|
220
|
-
...keyProblems(`${at}.forms`, pack.forms),
|
|
221
|
-
...keyProblems(`${at}.roadmapTemplates`, pack.roadmapTemplates)
|
|
222
|
-
);
|
|
223
|
-
for (const s of pack.sessionTypes ?? []) {
|
|
224
|
-
problems.push(...keyProblems(`${at}.sessionTypes.${s.key}.agenda`, s.agenda));
|
|
225
|
-
for (const item of s.agenda ?? []) {
|
|
226
|
-
if (!(typeof item.minutes === "number" && item.minutes > 0)) problems.push(`${at}.sessionTypes.${s.key}.agenda.${item.key}: minutes must be more than 0`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
for (const f of pack.fieldDefinitions ?? []) {
|
|
230
|
-
if (!Object.hasOwn(CONTENT_PACK_FIELD_TARGETS, f.target)) problems.push(`${at}.fieldDefinitions.${f.key}: target "${String(f.target)}" isn't one of ${Object.keys(CONTENT_PACK_FIELD_TARGETS).join(", ")}`);
|
|
231
|
-
if (typeof f.field?.type !== "string") problems.push(`${at}.fieldDefinitions.${f.key}: field needs a genesis-forms type`);
|
|
232
|
-
if (!["tenant", "app", "private"].includes(f.visibility)) problems.push(`${at}.fieldDefinitions.${f.key}: visibility must be tenant, app or private`);
|
|
233
|
-
}
|
|
234
|
-
for (const r of pack.roadmapTemplates ?? []) {
|
|
235
|
-
problems.push(...keyProblems(`${at}.roadmapTemplates.${r.key}.items`, r.items));
|
|
236
|
-
const keys = new Set((r.items ?? []).map((i) => i.key));
|
|
237
|
-
for (const item of r.items ?? []) {
|
|
238
|
-
if (item.ref !== void 0 && (!keys.has(item.ref) || item.ref === item.key)) {
|
|
239
|
-
problems.push(`${at}.roadmapTemplates.${r.key}.items.${item.key}: ref "${item.ref}" isn't another item in this template`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
const declared = new Set(pack.requires);
|
|
244
|
-
for (const block of contentPackBlocks(pack)) {
|
|
245
|
-
if (!declared.has(block)) problems.push(`${at}: fills the ${block} block but doesn't list it in requires`);
|
|
246
|
-
}
|
|
247
|
-
if (installed !== void 0) {
|
|
248
|
-
const has = test(installed);
|
|
249
|
-
for (const block of pack.requires) if (!has(block)) problems.push(`${at}: needs the ${block} block, which isn't installed`);
|
|
250
|
-
}
|
|
251
|
-
return problems;
|
|
252
|
-
}
|
|
253
|
-
function defineContentPack(pack) {
|
|
254
|
-
const problems = contentPackProblems(pack);
|
|
255
|
-
if (problems.length) throw new ContentPackError(problems);
|
|
256
|
-
return pack;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export { BlockError, CONTENT_PACK_FIELD_TARGETS, ContentPackError, contentPackBlocks, contentPackProblems, defineBlock, defineContentPack, resolveBlocks };
|
|
260
|
-
//# sourceMappingURL=chunk-OBVR6AZR.js.map
|
|
261
|
-
//# sourceMappingURL=chunk-OBVR6AZR.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/blocks.ts","../src/content-packs.ts"],"names":[],"mappings":";;;;AAwJO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpC,YAAqB,QAAA,EAAoB;AACvC,IAAA,KAAA,CAAM,CAAA;AAAA,EAAoB,QAAA,CAAS,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,IAAA,EAAO,CAAC,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AADnD,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAEnB,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AAAA,EACd;AAAA,EAHqB,QAAA;AAIvB;AAGA,IAAM,EAAA,GAAK,qCAAA;AAEX,IAAM,iBAAA,GAAoB,CAAC,KAAA,EAAO,UAAA,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A,EAAe,KAAK,CAAA,6BAAA,CAA+B,CAAA;AAAA,EAC5H;AACA,EAAA,OAAO,QAAA;AACT;AAmBO,SAAS,kBAAkD,IAAA,EAAY;AAC5E,EAAA,MAAM,QAAA,GAAW,oBAAoB,IAAI,CAAA;AACzC,EAAA,IAAI,QAAA,CAAS,MAAA,EAAQ,MAAM,IAAI,iBAAiB,QAAQ,CAAA;AACxD,EAAA,OAAO,IAAA;AACT","file":"chunk-OBVR6AZR.js","sourcesContent":["/**\n * Blocks: a feature an app adds whole (account, push, observability, support,\n * updates), declared once with what it needs and what it contributes. The app\n * shell, the navigation tree and Settings consume contributions by FeatureId;\n * the app still owns where they go.\n *\n * Platform-neutral and free of zod, so it ships to phones:\n * `@marktiderman/genesis-features/blocks` (also re-exported from the root).\n */\nimport { cycleProblems, dependencyOrder, requirementProblem } from \"./graph\";\nimport { FEATURE_PLATFORMS, type FeaturePlatform } from \"./platforms\";\n\n/**\n * A navigation entry a block offers. The app's nav tree places it (by the\n * block's FeatureId and this id); a block never decides where it goes.\n * `id`, `label` and `path` match genesis-core's `NavigationNode`.\n *\n * @stability Beta\n */\nexport interface BlockNavItem {\n /** Unique across every enabled block. */\n id: string;\n label: string;\n path: string;\n /** An icon name the app's icon set knows. */\n icon?: string;\n /** Lower first. Default 0. */\n order?: number;\n}\n\n/**\n * A Settings row a block offers, placed in the section with id `section`\n * (`\"account\"`, `\"about\"`, or one of the app's own; an unknown id becomes a\n * new section at the end).\n *\n * @stability Beta\n */\nexport interface BlockSettingsRow {\n /** Unique across every enabled block. */\n id: string;\n section: string;\n title: string;\n subtitle?: string;\n /**\n * A hook giving a subtitle that changes (a version, a count). It is called\n * on every render of the Settings screen, in block order, so the set of\n * blocks must not change while the app runs (shells read them once).\n */\n useSubtitle?: () => string | null | undefined;\n /** Where tapping the row goes, as a path. */\n href?: string;\n /** Lower first within its section. Default 0. */\n order?: number;\n testID?: string;\n}\n\n/**\n * A screen a block's feature needs the app to route to. On file-based\n * routers the app owns the route file; this is the declaration a check (or\n * a deep-link allowlist) reads.\n *\n * @stability Beta\n */\nexport interface BlockRoute {\n path: string;\n /** What the screen is for, in a few words. */\n description?: string;\n /** `true` when only a signed-in person can open it. */\n signedIn?: boolean;\n}\n\n/**\n * A SQL migration a block needs, shipped in a package: copy it into the\n * app's `supabase/migrations/` under a timestamped name.\n *\n * @stability Beta\n */\nexport interface BlockMigration {\n /** The npm package that ships it, e.g. `@marktiderman/genesis-supabase`. */\n package: string;\n /** Its path in the package, e.g. `migrations/0002_genesis_app_release_policy.sql`. */\n file: string;\n /** Its pgTAP test in the package, if any. */\n test?: string;\n}\n\n/**\n * One kind of data a block collects, for the App Store privacy label and the\n * Play data safety form.\n *\n * @stability Beta\n */\nexport interface BlockDataUse {\n /** What, in the stores' words: `\"email address\"`, `\"user id\"`, `\"crash data\"`. */\n type: string;\n /** Why: `\"app functionality\"`, `\"analytics\"`, … */\n purposes: readonly string[];\n /** Tied to the person's identity. */\n linked: boolean;\n /** Used to track the person across other companies' apps. */\n tracking: boolean;\n}\n\n/** What a block means for privacy. @stability Beta */\nexport interface BlockPrivacy {\n collects?: readonly BlockDataUse[];\n /** Anything a reviewer or a privacy policy should say, one sentence each. */\n notes?: readonly string[];\n}\n\n/**\n * What a block adds to an app. Every key is optional. `S` is what a slot is\n * filled with on the consuming platform (a React component on native and web).\n *\n * @stability Beta\n */\nexport interface BlockContributions<S = unknown> {\n nav?: readonly BlockNavItem[];\n settings?: readonly BlockSettingsRow[];\n routes?: readonly BlockRoute[];\n /**\n * Fills for the host shell's slots, by slot name (e.g. `fatal` on\n * `GenesisNativeApp`). The app's own `slots` always win over a block's.\n */\n slots?: Readonly<Record<string, S>>;\n migrations?: readonly BlockMigration[];\n /** Agent skills that come with it: repo or package paths to a `SKILL.md`. */\n skills?: readonly string[];\n privacy?: BlockPrivacy;\n}\n\n/**\n * One block. `id` is the block's FeatureId: the same id as its entry in the\n * feature registry.\n *\n * @stability Beta\n */\nexport interface BlockDef<Id extends string = string, S = unknown> {\n readonly id: Id;\n /**\n * What must be on with it: other blocks' ids, or features the app owns that\n * aren't blocks. A requirement that is a block must be enabled (and on this\n * platform); one that isn't a block must be listed in `enabled`. A\n * requirement that is neither is an error, so a forgotten block is loud.\n */\n readonly requires?: readonly string[];\n readonly contributes?: BlockContributions<S>;\n /** Where it runs. Default every platform. */\n readonly platforms?: readonly FeaturePlatform[];\n}\n\n/** Thrown by {@link defineBlock} and {@link resolveBlocks}; lists every problem at once. @stability Beta */\nexport class BlockError extends Error {\n constructor(readonly problems: string[]) {\n super(`Invalid blocks:\\n${problems.map((p) => ` - ${p}`).join(\"\\n\")}`);\n this.name = \"BlockError\";\n }\n}\n\n// The feature registry's id rule (model.ts), repeated so this file stays free of zod.\nconst ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;\n\nconst CONTRIBUTION_KEYS = [\"nav\", \"settings\", \"routes\", \"slots\", \"migrations\", \"skills\", \"privacy\"] as const;\n\nfunction duplicates(values: readonly string[]): string[] {\n const seen = new Set<string>();\n const dup = new Set<string>();\n for (const v of values) (seen.has(v) ? dup : seen).add(v);\n return [...dup];\n}\n\nfunction blockProblems(block: BlockDef<string, unknown>): string[] {\n const { id } = block;\n const problems: string[] = [];\n if (typeof id !== \"string\" || !ID.test(id)) problems.push(`${String(id)}: a block id is a feature id: lowercase letters and digits, joined by -, _ or .`);\n for (const req of block.requires ?? []) {\n if (req === id) problems.push(`${id}.requires: a block can't require itself`);\n else if (!ID.test(req)) problems.push(`${id}.requires: \"${req}\" is not a feature id`);\n }\n for (const p of block.platforms ?? []) {\n if (!(FEATURE_PLATFORMS as readonly string[]).includes(p)) problems.push(`${id}.platforms: \"${p}\" is not one of ${FEATURE_PLATFORMS.join(\", \")}`);\n }\n if (block.platforms && block.platforms.length === 0) problems.push(`${id}.platforms: an empty list runs nowhere; leave it out for every platform`);\n const c = block.contributes ?? {};\n for (const key of Object.keys(c)) {\n if (!(CONTRIBUTION_KEYS as readonly string[]).includes(key)) problems.push(`${id}.contributes.${key}: not a contribution (${CONTRIBUTION_KEYS.join(\", \")})`);\n }\n for (const d of duplicates((c.nav ?? []).map((n) => n.id))) problems.push(`${id}.contributes.nav: \"${d}\" appears twice`);\n for (const d of duplicates((c.settings ?? []).map((r) => r.id))) problems.push(`${id}.contributes.settings: \"${d}\" appears twice`);\n for (const d of duplicates((c.routes ?? []).map((r) => r.path))) problems.push(`${id}.contributes.routes: \"${d}\" appears twice`);\n for (const n of c.nav ?? []) if (!n.id || !n.label || !n.path) problems.push(`${id}.contributes.nav: every entry needs an id, a label and a path`);\n for (const r of c.settings ?? []) if (!r.id || !r.section || !r.title) problems.push(`${id}.contributes.settings: every row needs an id, a section and a title`);\n for (const m of c.migrations ?? []) if (!m.package || !m.file) problems.push(`${id}.contributes.migrations: every migration needs a package and a file`);\n return problems;\n}\n\n/**\n * Declare a block. Validates it (id, requirements, platforms, contribution\n * keys and duplicate ids within the block) and returns it frozen, so a\n * typo fails where the block is written rather than where it is used:\n *\n * ```ts\n * export const supportBlock = defineBlock({\n * id: \"support\",\n * requires: [\"account\"],\n * platforms: [\"web\", \"native\"],\n * contributes: {\n * settings: [{ id: \"contact-support\", section: \"about\", title: \"Contact support\", href: \"/support\" }],\n * routes: [{ path: \"/support\", signedIn: true }],\n * migrations: [{ package: \"@acme/support\", file: \"migrations/0001_support.sql\" }],\n * },\n * });\n * ```\n *\n * To check `id` against the app's registry at compile time, give the\n * FeatureId: `defineBlock<FeatureId>({ … })`. `S` is what slots are filled\n * with, inferred from `contributes.slots` (a component on native and web).\n *\n * @stability Beta\n */\nexport function defineBlock<const Id extends string, S = never>(block: BlockDef<Id, S>): BlockDef<Id, S> {\n const problems = blockProblems(block as BlockDef<string, unknown>);\n if (problems.length) throw new BlockError(problems);\n return Object.freeze(block);\n}\n\n/** Which blocks are on: ids, a predicate, or (left out) every block given. @stability Beta */\nexport type EnabledBlocks = Iterable<string> | ((id: string) => boolean);\n\n/** @stability Beta */\nexport interface ResolveBlocksOptions {\n /** Keep only blocks that run here. A required block that doesn't is a missing requirement. */\n platform?: FeaturePlatform;\n /**\n * The app's feature registry (`features` from `defineFeatures`): every block\n * id and requirement must be one of its ids.\n */\n features?: Readonly<Record<string, unknown>>;\n /**\n * A block whose requirement is off: `throw` (default: a set-up mistake, found\n * at launch) or `drop` it, and every block needing it, listing each in\n * `dropped` (for switches that change at run time, such as a tenant turning\n * a feature off).\n */\n missing?: \"throw\" | \"drop\";\n /**\n * The host's slot names (e.g. `GenesisNativeApp`'s). A block filling any\n * other slot is an error, so a typo doesn't fill nothing silently.\n */\n slots?: readonly string[];\n}\n\n/** A contribution with the FeatureId of the block it came from. @stability Beta */\nexport type Contributed<T, Id extends string = string> = T & { readonly feature: Id };\n\n/** @stability Beta */\nexport interface ResolvedBlocks<B extends BlockDef<string, unknown> = BlockDef> {\n /** The enabled blocks, in dependency order (a block after what it requires). */\n readonly blocks: readonly B[];\n readonly ids: ReadonlySet<B[\"id\"]>;\n has(id: string): boolean;\n /** One block's contributions, or `undefined` when it isn't on. */\n contributionsOf(id: B[\"id\"]): NonNullable<B[\"contributes\"]> | undefined;\n /** Nav entries by `order`, then block order. Place them in the app's tree by `feature` and `id`. */\n readonly nav: readonly Contributed<BlockNavItem, B[\"id\"]>[];\n /** Settings rows by `order`, then block order. */\n readonly settings: readonly Contributed<BlockSettingsRow, B[\"id\"]>[];\n readonly routes: readonly Contributed<BlockRoute, B[\"id\"]>[];\n /** Slot fills by slot name. Two blocks filling one slot is an error. */\n readonly slots: Readonly<Record<string, SlotOf<B>>>;\n readonly migrations: readonly Contributed<BlockMigration, B[\"id\"]>[];\n readonly skills: readonly Contributed<{ path: string }, B[\"id\"]>[];\n readonly privacy: readonly Contributed<BlockPrivacy, B[\"id\"]>[];\n /** With `missing: \"drop\"`: blocks left out, and the requirements that were off. */\n readonly dropped: readonly { id: B[\"id\"]; missing: readonly string[] }[];\n}\n\ntype SlotOf<B> = B extends BlockDef<string, infer S> ? S : never;\n\nfunction enabledPredicate(enabled: EnabledBlocks | undefined): ((id: string) => boolean) | undefined {\n if (enabled === undefined) return undefined;\n if (typeof enabled === \"function\") return enabled;\n const set = new Set(enabled);\n return (id) => set.has(id);\n}\n\nconst byOrder = <T extends { order?: number }>(items: { item: T; at: number }[]) =>\n items.sort((a, b) => (a.item.order ?? 0) - (b.item.order ?? 0) || a.at - b.at).map((x) => x.item);\n\n/**\n * The blocks that are on, checked and merged:\n *\n * - every block is valid ({@link defineBlock}'s checks, for blocks built by hand) and its id is unique;\n * - `requires` has no cycles, and with `features`, names real features;\n * - every enabled block's requirements are on (see {@link ResolveBlocksOptions.missing});\n * - no two enabled blocks contribute the same nav id, settings row id, route path or slot.\n *\n * `enabled` left out means every block given is on (and no app feature that\n * isn't a block). Throws a {@link BlockError} listing every problem at once.\n *\n * @stability Beta\n */\nexport function resolveBlocks<B extends BlockDef<string, unknown>>(\n blocks: readonly B[],\n enabled?: EnabledBlocks,\n options: ResolveBlocksOptions = {},\n): ResolvedBlocks<B> {\n const { platform, features, missing = \"throw\", slots: slotNames } = options;\n const problems: string[] = [];\n const byId = new Map<string, B>();\n for (const block of blocks) {\n problems.push(...blockProblems(block));\n if (byId.has(block.id)) problems.push(`${block.id}: two blocks have this id`);\n else byId.set(block.id, block);\n }\n const isFeature = features ? (id: string) => Object.hasOwn(features, id) : undefined;\n if (isFeature) for (const id of byId.keys()) if (!isFeature(id)) problems.push(`${id}: not a feature in the registry`);\n const graph = Object.fromEntries([...byId].map(([id, b]) => [id, { requires: b.requires }]));\n // Self-requirements are already reported by blockProblems; here, unknown ids and cycles.\n const known = { noun: \"block\", isKnown: (req: string) => byId.has(req) || !isFeature || isFeature(req) };\n for (const [id, node] of Object.entries(graph)) {\n for (const req of node.requires ?? []) {\n if (req !== id && requirementProblem(graph, id, req, known)) problems.push(`${id}.requires: \"${req}\" is neither a block nor a feature in the registry`);\n }\n }\n problems.push(...cycleProblems(graph));\n if (problems.length) throw new BlockError(problems);\n\n const isOn = enabledPredicate(enabled);\n const runsHere = (b: B) => !platform || !b.platforms || b.platforms.includes(platform);\n const active = new Set<string>();\n for (const [id, b] of byId) if ((!isOn || isOn(id)) && runsHere(b)) active.add(id);\n\n // In dependency order, so dropping a block also drops what needs it.\n const order = dependencyOrder(graph);\n const dropped: { id: B[\"id\"]; missing: string[] }[] = [];\n for (const id of order) {\n if (!active.has(id)) continue;\n const off = (byId.get(id)!.requires ?? []).filter((req) => {\n if (byId.has(req)) return !active.has(req);\n return !isOn || !isOn(req);\n });\n if (!off.length) continue;\n if (missing === \"drop\") {\n active.delete(id);\n dropped.push({ id, missing: off });\n continue;\n }\n for (const req of off) {\n const why = !byId.has(req)\n ? isOn\n ? \"is not enabled\"\n : \"is not one of the blocks given (pass it, or list the app feature in enabled)\"\n : !runsHere(byId.get(req)!)\n ? `doesn't run on ${platform}`\n : \"is off\";\n problems.push(`${id}.requires: \"${req}\" ${why}; turn it on or turn ${id} off`);\n }\n }\n if (problems.length) throw new BlockError(problems);\n\n const on = order.filter((id) => active.has(id)).map((id) => byId.get(id)!);\n const nav: { item: Contributed<BlockNavItem, B[\"id\"]>; at: number }[] = [];\n const settings: { item: Contributed<BlockSettingsRow, B[\"id\"]>; at: number }[] = [];\n const routes: Contributed<BlockRoute, B[\"id\"]>[] = [];\n const migrations: Contributed<BlockMigration, B[\"id\"]>[] = [];\n const skills: Contributed<{ path: string }, B[\"id\"]>[] = [];\n const privacy: Contributed<BlockPrivacy, B[\"id\"]>[] = [];\n const slots: Record<string, SlotOf<B>> = {};\n const owner = { nav: new Map<string, string>(), settings: new Map<string, string>(), routes: new Map<string, string>(), slots: new Map<string, string>() };\n const claim = (kind: keyof typeof owner, key: string, id: string, what: string) => {\n const first = owner[kind].get(key);\n if (first !== undefined) problems.push(`${id}.contributes.${kind}: ${what} \"${key}\" is already contributed by ${first}`);\n else owner[kind].set(key, id);\n return first === undefined;\n };\n on.forEach((block, at) => {\n const feature = block.id;\n const c = block.contributes ?? {};\n for (const n of c.nav ?? []) if (claim(\"nav\", n.id, feature, \"the nav entry\")) nav.push({ item: { ...n, feature }, at });\n for (const r of c.settings ?? []) if (claim(\"settings\", r.id, feature, \"the settings row\")) settings.push({ item: { ...r, feature }, at });\n for (const r of c.routes ?? []) if (claim(\"routes\", r.path, feature, \"the route\")) routes.push({ ...r, feature });\n for (const [name, fill] of Object.entries(c.slots ?? {})) {\n if (slotNames && !slotNames.includes(name)) {\n problems.push(`${feature}.contributes.slots: \"${name}\" is not a slot here (${slotNames.join(\", \")})`);\n continue;\n }\n if (claim(\"slots\", name, feature, \"the slot\")) slots[name] = fill as SlotOf<B>;\n }\n for (const m of c.migrations ?? []) migrations.push({ ...m, feature });\n for (const path of c.skills ?? []) skills.push({ path, feature });\n if (c.privacy) privacy.push({ ...c.privacy, feature });\n });\n if (problems.length) throw new BlockError(problems);\n\n const ids = new Set(on.map((b) => b.id)) as ReadonlySet<B[\"id\"]>;\n return Object.freeze({\n blocks: Object.freeze(on),\n ids,\n has: (id: string) => ids.has(id as B[\"id\"]),\n contributionsOf: (id: B[\"id\"]) => (ids.has(id) ? ((byId.get(id)!.contributes ?? {}) as NonNullable<B[\"contributes\"]>) : undefined),\n nav: Object.freeze(byOrder(nav)),\n settings: Object.freeze(byOrder(settings)),\n routes: Object.freeze(routes),\n slots: Object.freeze(slots),\n migrations: Object.freeze(migrations),\n skills: Object.freeze(skills),\n privacy: Object.freeze(privacy),\n dropped: Object.freeze(dropped),\n });\n}\n","/**\n * Content packs: versioned data that fills installed blocks (session types and\n * agendas, metric templates, custom field definitions, forms, roadmap templates,\n * labels). A pack is code, reviewed like any other: the publishing package\n * exports it, and an installer copies it into a tenant's editable rows, keeping\n * each row's source (pack, version, key) so an update can tell what a person\n * changed.\n *\n * `defineContentPack` checks a pack's shape; `contentPackProblems` with the\n * installed blocks also checks that every block it fills is there. Keys, not\n * ids, link things together, and stay the same across versions.\n *\n * No zod here: packs ship to phones with `/blocks`.\n */\nimport type { EnabledBlocks } from \"./blocks\";\n\n/** A content pack's settings for one session type, with its agenda. @stability Beta */\nexport interface ContentPackSessionType {\n key: string;\n kind: string;\n name: string;\n description?: string;\n defaultMinutes?: number;\n agenda: readonly { key: string; title: string; minutes: number }[];\n}\n\n/** A metric to start from. @stability Beta */\nexport interface ContentPackMetricTemplate {\n key: string;\n name: string;\n unitType: string;\n unit?: string;\n cadence: string;\n goalDirection: string;\n goalValue?: number;\n goalMax?: number;\n measureKind?: string;\n rollup?: string;\n}\n\n/** Where a custom field lives, and the block that owns that table. @stability Beta */\nexport const CONTENT_PACK_FIELD_TARGETS = {\n pursuits: \"pursuits\",\n work_items: \"pursuits\",\n metrics: \"metrics\",\n sessions: \"sessions\",\n} as const;\n\n/** @stability Beta */\nexport type ContentPackFieldTarget = keyof typeof CONTENT_PACK_FIELD_TARGETS;\n\n/** A custom field: a genesis-forms serializable field, on one of the work tables. @stability Beta */\nexport interface ContentPackFieldDefinition {\n key: string;\n target: ContentPackFieldTarget;\n label: string;\n /** A genesis-forms serializable field: type, options, validation. */\n field: { readonly type: string; readonly [key: string]: unknown };\n required?: boolean;\n visibility: \"tenant\" | \"app\" | \"private\";\n}\n\n/** A worksheet, assessment or form: a genesis-forms definition. @stability Beta */\nexport interface ContentPackForm {\n key: string;\n kind: \"worksheet\" | \"assessment\" | \"form\";\n title: string;\n definition: { readonly [key: string]: unknown };\n scoring?: unknown;\n}\n\n/** A roadmap to start from: items that release by a rule, linked to each other by key. @stability Beta */\nexport interface ContentPackRoadmapTemplate {\n key: string;\n name: string;\n items: readonly {\n key: string;\n kind: string;\n title: string;\n /** Another item's key in this template. */\n ref?: string;\n release: { rule: string; afterDays?: number; anchor?: string };\n }[];\n}\n\n/** One content pack, as its publisher defines it. @stability Beta */\nexport interface ContentPackDef {\n /** Kebab-case, unique per publisher. */\n id: string;\n name: string;\n description?: string;\n /** Semver. Updates are additive. */\n version: string;\n /** The package that publishes it. */\n publisher: string;\n /** The block ids it fills; installing is refused unless every one is installed. */\n requires: readonly string[];\n /** Taxonomy: label key → display text, e.g. `\"pursuit.quarter\": \"Rocks\"`. */\n labels?: Readonly<Record<string, string>>;\n sessionTypes?: readonly ContentPackSessionType[];\n metricTemplates?: readonly ContentPackMetricTemplate[];\n fieldDefinitions?: readonly ContentPackFieldDefinition[];\n forms?: readonly ContentPackForm[];\n roadmapTemplates?: readonly ContentPackRoadmapTemplate[];\n}\n\n/** Thrown by {@link defineContentPack}; lists every problem at once. @stability Beta */\nexport class ContentPackError extends Error {\n constructor(readonly problems: string[]) {\n super(`Invalid content pack:\\n${problems.map((p) => ` - ${p}`).join(\"\\n\")}`);\n this.name = \"ContentPackError\";\n }\n}\n\nconst KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\nconst KEY = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;\nconst SEMVER = /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/;\n\n/** The block each section fills. */\nconst SECTION_BLOCK = { sessionTypes: \"sessions\", metricTemplates: \"metrics\", forms: \"forms\", roadmapTemplates: \"roadmap\" } as const;\n\nfunction keyProblems(where: string, items: readonly { key: string }[] | undefined): string[] {\n const problems: string[] = [];\n const seen = new Set<string>();\n for (const [i, item] of (items ?? []).entries()) {\n if (typeof item?.key !== \"string\" || !KEY.test(item.key)) problems.push(`${where}[${i}].key: \"${String(item?.key)}\" is not a key (lowercase, dots, dashes or underscores)`);\n else if (seen.has(item.key)) problems.push(`${where}: the key \"${item.key}\" is used twice`);\n else seen.add(item.key);\n }\n return problems;\n}\n\n/** The block ids a pack's sections need, whatever it declares. @stability Beta */\nexport function contentPackBlocks(pack: ContentPackDef): string[] {\n const needed = new Set<string>();\n for (const [section, block] of Object.entries(SECTION_BLOCK)) {\n const items = pack[section as keyof typeof SECTION_BLOCK];\n if (items && items.length) needed.add(block);\n }\n for (const f of pack.fieldDefinitions ?? []) {\n const block = CONTENT_PACK_FIELD_TARGETS[f.target];\n if (block) needed.add(block);\n }\n return [...needed].sort();\n}\n\nfunction test(blocks: EnabledBlocks): (id: string) => boolean {\n if (typeof blocks === \"function\") return blocks;\n const set = new Set(blocks);\n return (id) => set.has(id);\n}\n\n/**\n * Every problem with a pack: its shape and, given the installed blocks, any\n * block it fills that isn't installed. An empty list means it can be installed.\n *\n * @stability Beta\n */\nexport function contentPackProblems(pack: ContentPackDef, installed?: EnabledBlocks): string[] {\n const at = `content pack ${typeof pack?.id === \"string\" ? pack.id : \"?\"}`;\n const problems: string[] = [];\n if (typeof pack?.id !== \"string\" || !KEBAB.test(pack.id)) problems.push(`${at}: id must be kebab-case`);\n if (typeof pack?.name !== \"string\" || !pack.name.trim()) problems.push(`${at}: needs a name`);\n if (typeof pack?.version !== \"string\" || !SEMVER.test(pack.version)) problems.push(`${at}: version \"${String(pack?.version)}\" isn't semver`);\n if (typeof pack?.publisher !== \"string\" || !pack.publisher.trim()) problems.push(`${at}: needs a publisher (its package name)`);\n if (!Array.isArray(pack?.requires)) {\n problems.push(`${at}: requires must list the blocks it fills`);\n return problems;\n }\n for (const [label, text] of Object.entries(pack.labels ?? {})) {\n if (!KEY.test(label)) problems.push(`${at}: label key \"${label}\" is not a key`);\n if (typeof text !== \"string\" || !text.trim()) problems.push(`${at}: label \"${label}\" needs display text`);\n }\n problems.push(\n ...keyProblems(`${at}.sessionTypes`, pack.sessionTypes),\n ...keyProblems(`${at}.metricTemplates`, pack.metricTemplates),\n ...keyProblems(`${at}.fieldDefinitions`, pack.fieldDefinitions),\n ...keyProblems(`${at}.forms`, pack.forms),\n ...keyProblems(`${at}.roadmapTemplates`, pack.roadmapTemplates),\n );\n for (const s of pack.sessionTypes ?? []) {\n problems.push(...keyProblems(`${at}.sessionTypes.${s.key}.agenda`, s.agenda));\n for (const item of s.agenda ?? []) {\n if (!(typeof item.minutes === \"number\" && item.minutes > 0)) problems.push(`${at}.sessionTypes.${s.key}.agenda.${item.key}: minutes must be more than 0`);\n }\n }\n for (const f of pack.fieldDefinitions ?? []) {\n if (!Object.hasOwn(CONTENT_PACK_FIELD_TARGETS, f.target)) problems.push(`${at}.fieldDefinitions.${f.key}: target \"${String(f.target)}\" isn't one of ${Object.keys(CONTENT_PACK_FIELD_TARGETS).join(\", \")}`);\n if (typeof f.field?.type !== \"string\") problems.push(`${at}.fieldDefinitions.${f.key}: field needs a genesis-forms type`);\n if (![\"tenant\", \"app\", \"private\"].includes(f.visibility)) problems.push(`${at}.fieldDefinitions.${f.key}: visibility must be tenant, app or private`);\n }\n for (const r of pack.roadmapTemplates ?? []) {\n problems.push(...keyProblems(`${at}.roadmapTemplates.${r.key}.items`, r.items));\n const keys = new Set((r.items ?? []).map((i) => i.key));\n for (const item of r.items ?? []) {\n if (item.ref !== undefined && (!keys.has(item.ref) || item.ref === item.key)) {\n problems.push(`${at}.roadmapTemplates.${r.key}.items.${item.key}: ref \"${item.ref}\" isn't another item in this template`);\n }\n }\n }\n // Every block a section fills must be declared, and (when known) installed.\n const declared = new Set(pack.requires);\n for (const block of contentPackBlocks(pack)) {\n if (!declared.has(block)) problems.push(`${at}: fills the ${block} block but doesn't list it in requires`);\n }\n if (installed !== undefined) {\n const has = test(installed);\n for (const block of pack.requires) if (!has(block)) problems.push(`${at}: needs the ${block} block, which isn't installed`);\n }\n return problems;\n}\n\n/**\n * Declare a content pack: returns it unchanged, typed, after checking its\n * shape (throws a {@link ContentPackError} listing every problem). Whether its\n * blocks are installed is checked at install time with\n * {@link contentPackProblems}.\n *\n * ```ts\n * export const weeklyTeamRhythm = defineContentPack({\n * id: \"weekly-team-rhythm\", name: \"Weekly team rhythm\", version: \"1.0.0\",\n * publisher: \"@marktiderman/genesis-content\", requires: [\"sessions\", \"metrics\"],\n * labels: { \"pursuit.quarter\": \"Rocks\" },\n * sessionTypes: [{ key: \"weekly\", kind: \"team\", name: \"Weekly meeting\", agenda: [{ key: \"check-in\", title: \"Check in\", minutes: 5 }] }],\n * });\n * ```\n *\n * @stability Beta\n */\nexport function defineContentPack<const T extends ContentPackDef>(pack: T): T {\n const problems = contentPackProblems(pack);\n if (problems.length) throw new ContentPackError(problems);\n return pack;\n}\n"]}
|