@marktiderman/genesis-features 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.
- package/README.md +55 -0
- package/dist/blocks.d.ts +235 -0
- package/dist/blocks.js +4 -0
- package/dist/blocks.js.map +1 -0
- package/dist/chunk-2ARZER3G.js +55 -0
- package/dist/chunk-2ARZER3G.js.map +1 -0
- package/dist/chunk-EF72JS5S.js +155 -0
- package/dist/chunk-EF72JS5S.js.map +1 -0
- package/dist/{chunk-6IAFRAJE.js → chunk-KCUQY5UZ.js} +7 -19
- package/dist/chunk-KCUQY5UZ.js.map +1 -0
- package/dist/index.d.ts +43 -3
- package/dist/index.js +3 -1
- package/dist/{model-QoeUrIss.d.ts → model-CW3d2gsf.d.ts} +3 -9
- package/dist/node.d.ts +2 -1
- package/dist/node.js +2 -1
- package/dist/node.js.map +1 -1
- package/dist/platforms-NR0liM8L.d.ts +10 -0
- package/dist/react.d.ts +2 -1
- package/dist/react.js +2 -1
- package/dist/react.js.map +1 -1
- package/package.json +9 -5
- package/dist/chunk-6IAFRAJE.js.map +0 -1
package/README.md
CHANGED
|
@@ -120,6 +120,61 @@ The flag scan ignores comments and test files. List the flags runtime itself (th
|
|
|
120
120
|
|
|
121
121
|
The CLI loads TypeScript itself, so the registry needs no build step. Keep its imports to packages, with no path aliases.
|
|
122
122
|
|
|
123
|
+
## Blocks
|
|
124
|
+
|
|
125
|
+
A block is a feature an app adds whole: account, push, observability, support, updates. It is
|
|
126
|
+
declared once, by its FeatureId, with what it needs and what it contributes. The app shell, the
|
|
127
|
+
navigation tree and Settings read the contributions by FeatureId; the app still decides where they
|
|
128
|
+
go. `@marktiderman/genesis-features/blocks` has no zod in it, so it ships to phones (the root
|
|
129
|
+
re-exports it).
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { defineBlock, resolveBlocks } from "@marktiderman/genesis-features/blocks";
|
|
133
|
+
import type { FeatureId } from "./features";
|
|
134
|
+
|
|
135
|
+
export const supportBlock = defineBlock<FeatureId>({
|
|
136
|
+
id: "support",
|
|
137
|
+
requires: ["account"], // other blocks, or app features that aren't blocks
|
|
138
|
+
platforms: ["web", "native"], // default: everywhere
|
|
139
|
+
contributes: {
|
|
140
|
+
nav: [{ id: "help", label: "Help", path: "/help" }],
|
|
141
|
+
settings: [{ id: "contact-support", section: "about", title: "Contact support", href: "/support" }],
|
|
142
|
+
routes: [{ path: "/support", signedIn: true }],
|
|
143
|
+
slots: { fatal: SupportFatalScreen }, // fills the host shell's slots; the app's own slots win
|
|
144
|
+
migrations: [{ package: "@acme/support", file: "migrations/0001_support.sql" }],
|
|
145
|
+
skills: [".claude/skills/support/SKILL.md"],
|
|
146
|
+
privacy: { collects: [{ type: "email address", purposes: ["app functionality"], linked: true, tracking: false }] },
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const blocks = resolveBlocks([accountBlock, supportBlock], enabledIds, { platform: "native", features });
|
|
151
|
+
blocks.nav; // [{ feature: "support", id: "help", … }]: place them in your nav tree
|
|
152
|
+
blocks.settings; // by `order`, then dependency order
|
|
153
|
+
blocks.dropped; // with { missing: "drop" }: what was left out and why
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`defineBlock` validates one block and freezes it. `resolveBlocks(blocks, enabled?, options?)`
|
|
157
|
+
takes the blocks that exist, the ids that are on (a list, a predicate, or every block when left
|
|
158
|
+
out) and returns the enabled ones in dependency order with their contributions merged, each tagged
|
|
159
|
+
with its `feature`. It throws a `BlockError` listing every problem at once:
|
|
160
|
+
|
|
161
|
+
- a bad id, a block requiring itself, an unknown contribution key, a duplicate id;
|
|
162
|
+
- a cycle through `requires` (the registry's own check, from `graph.ts`);
|
|
163
|
+
- with `features` (the registry), a block id or requirement that isn't a feature;
|
|
164
|
+
- an enabled block whose requirement is off, or doesn't run on `platform`. With `missing: "drop"` the
|
|
165
|
+
block (and everything needing it) is left out instead and listed in `dropped`: for switches that
|
|
166
|
+
change at run time, such as a tenant turning a feature off;
|
|
167
|
+
- two enabled blocks contributing the same nav entry, Settings row, route or slot, or (with `slots`)
|
|
168
|
+
a fill for a slot the host doesn't have.
|
|
169
|
+
|
|
170
|
+
A requirement that isn't one of the blocks is a feature the app owns: it is met only when
|
|
171
|
+
`enabled` lists it, so a block that was never passed is an error, not a silent pass. With `slots`
|
|
172
|
+
(the host's slot names), a fill for any other slot is an error too.
|
|
173
|
+
|
|
174
|
+
Blocks shipped so far: `createUpdates(…)` (`app-updates`, in `@marktiderman/genesis-native/updates`),
|
|
175
|
+
`accountBlock` and `tenantFeaturesBlock` (in `@marktiderman/genesis-supabase`).
|
|
176
|
+
`<GenesisNativeApp blocks={…}>` runs them; see that package's README.
|
|
177
|
+
|
|
123
178
|
## The page
|
|
124
179
|
|
|
125
180
|
```tsx
|
package/dist/blocks.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { F as FeaturePlatform } from './platforms-NR0liM8L.js';
|
|
2
|
+
export { a as FEATURE_PLATFORMS } from './platforms-NR0liM8L.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A navigation entry a block offers. The app's nav tree places it (by the
|
|
6
|
+
* block's FeatureId and this id); a block never decides where it goes.
|
|
7
|
+
* `id`, `label` and `path` match genesis-core's `NavigationNode`.
|
|
8
|
+
*
|
|
9
|
+
* @stability Beta
|
|
10
|
+
*/
|
|
11
|
+
interface BlockNavItem {
|
|
12
|
+
/** Unique across every enabled block. */
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
path: string;
|
|
16
|
+
/** An icon name the app's icon set knows. */
|
|
17
|
+
icon?: string;
|
|
18
|
+
/** Lower first. Default 0. */
|
|
19
|
+
order?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A Settings row a block offers, placed in the section with id `section`
|
|
23
|
+
* (`"account"`, `"about"`, or one of the app's own; an unknown id becomes a
|
|
24
|
+
* new section at the end).
|
|
25
|
+
*
|
|
26
|
+
* @stability Beta
|
|
27
|
+
*/
|
|
28
|
+
interface BlockSettingsRow {
|
|
29
|
+
/** Unique across every enabled block. */
|
|
30
|
+
id: string;
|
|
31
|
+
section: string;
|
|
32
|
+
title: string;
|
|
33
|
+
subtitle?: string;
|
|
34
|
+
/**
|
|
35
|
+
* A hook giving a subtitle that changes (a version, a count). It is called
|
|
36
|
+
* on every render of the Settings screen, in block order, so the set of
|
|
37
|
+
* blocks must not change while the app runs (shells read them once).
|
|
38
|
+
*/
|
|
39
|
+
useSubtitle?: () => string | null | undefined;
|
|
40
|
+
/** Where tapping the row goes, as a path. */
|
|
41
|
+
href?: string;
|
|
42
|
+
/** Lower first within its section. Default 0. */
|
|
43
|
+
order?: number;
|
|
44
|
+
testID?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A screen a block's feature needs the app to route to. On file-based
|
|
48
|
+
* routers the app owns the route file; this is the declaration a check (or
|
|
49
|
+
* a deep-link allowlist) reads.
|
|
50
|
+
*
|
|
51
|
+
* @stability Beta
|
|
52
|
+
*/
|
|
53
|
+
interface BlockRoute {
|
|
54
|
+
path: string;
|
|
55
|
+
/** What the screen is for, in a few words. */
|
|
56
|
+
description?: string;
|
|
57
|
+
/** `true` when only a signed-in person can open it. */
|
|
58
|
+
signedIn?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A SQL migration a block needs, shipped in a package: copy it into the
|
|
62
|
+
* app's `supabase/migrations/` under a timestamped name.
|
|
63
|
+
*
|
|
64
|
+
* @stability Beta
|
|
65
|
+
*/
|
|
66
|
+
interface BlockMigration {
|
|
67
|
+
/** The npm package that ships it, e.g. `@marktiderman/genesis-supabase`. */
|
|
68
|
+
package: string;
|
|
69
|
+
/** Its path in the package, e.g. `migrations/0002_genesis_app_release_policy.sql`. */
|
|
70
|
+
file: string;
|
|
71
|
+
/** Its pgTAP test in the package, if any. */
|
|
72
|
+
test?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* One kind of data a block collects, for the App Store privacy label and the
|
|
76
|
+
* Play data safety form.
|
|
77
|
+
*
|
|
78
|
+
* @stability Beta
|
|
79
|
+
*/
|
|
80
|
+
interface BlockDataUse {
|
|
81
|
+
/** What, in the stores' words: `"email address"`, `"user id"`, `"crash data"`. */
|
|
82
|
+
type: string;
|
|
83
|
+
/** Why: `"app functionality"`, `"analytics"`, … */
|
|
84
|
+
purposes: readonly string[];
|
|
85
|
+
/** Tied to the person's identity. */
|
|
86
|
+
linked: boolean;
|
|
87
|
+
/** Used to track the person across other companies' apps. */
|
|
88
|
+
tracking: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** What a block means for privacy. @stability Beta */
|
|
91
|
+
interface BlockPrivacy {
|
|
92
|
+
collects?: readonly BlockDataUse[];
|
|
93
|
+
/** Anything a reviewer or a privacy policy should say, one sentence each. */
|
|
94
|
+
notes?: readonly string[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* What a block adds to an app. Every key is optional. `S` is what a slot is
|
|
98
|
+
* filled with on the consuming platform (a React component on native and web).
|
|
99
|
+
*
|
|
100
|
+
* @stability Beta
|
|
101
|
+
*/
|
|
102
|
+
interface BlockContributions<S = unknown> {
|
|
103
|
+
nav?: readonly BlockNavItem[];
|
|
104
|
+
settings?: readonly BlockSettingsRow[];
|
|
105
|
+
routes?: readonly BlockRoute[];
|
|
106
|
+
/**
|
|
107
|
+
* Fills for the host shell's slots, by slot name (e.g. `fatal` on
|
|
108
|
+
* `GenesisNativeApp`). The app's own `slots` always win over a block's.
|
|
109
|
+
*/
|
|
110
|
+
slots?: Readonly<Record<string, S>>;
|
|
111
|
+
migrations?: readonly BlockMigration[];
|
|
112
|
+
/** Agent skills that come with it: repo or package paths to a `SKILL.md`. */
|
|
113
|
+
skills?: readonly string[];
|
|
114
|
+
privacy?: BlockPrivacy;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* One block. `id` is the block's FeatureId: the same id as its entry in the
|
|
118
|
+
* feature registry.
|
|
119
|
+
*
|
|
120
|
+
* @stability Beta
|
|
121
|
+
*/
|
|
122
|
+
interface BlockDef<Id extends string = string, S = unknown> {
|
|
123
|
+
readonly id: Id;
|
|
124
|
+
/**
|
|
125
|
+
* What must be on with it: other blocks' ids, or features the app owns that
|
|
126
|
+
* aren't blocks. A requirement that is a block must be enabled (and on this
|
|
127
|
+
* platform); one that isn't a block must be listed in `enabled`. A
|
|
128
|
+
* requirement that is neither is an error, so a forgotten block is loud.
|
|
129
|
+
*/
|
|
130
|
+
readonly requires?: readonly string[];
|
|
131
|
+
readonly contributes?: BlockContributions<S>;
|
|
132
|
+
/** Where it runs. Default every platform. */
|
|
133
|
+
readonly platforms?: readonly FeaturePlatform[];
|
|
134
|
+
}
|
|
135
|
+
/** Thrown by {@link defineBlock} and {@link resolveBlocks}; lists every problem at once. @stability Beta */
|
|
136
|
+
declare class BlockError extends Error {
|
|
137
|
+
readonly problems: string[];
|
|
138
|
+
constructor(problems: string[]);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Declare a block. Validates it (id, requirements, platforms, contribution
|
|
142
|
+
* keys and duplicate ids within the block) and returns it frozen, so a
|
|
143
|
+
* typo fails where the block is written rather than where it is used:
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* export const supportBlock = defineBlock({
|
|
147
|
+
* id: "support",
|
|
148
|
+
* requires: ["account"],
|
|
149
|
+
* platforms: ["web", "native"],
|
|
150
|
+
* contributes: {
|
|
151
|
+
* settings: [{ id: "contact-support", section: "about", title: "Contact support", href: "/support" }],
|
|
152
|
+
* routes: [{ path: "/support", signedIn: true }],
|
|
153
|
+
* migrations: [{ package: "@acme/support", file: "migrations/0001_support.sql" }],
|
|
154
|
+
* },
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* To check `id` against the app's registry at compile time, give the
|
|
159
|
+
* FeatureId: `defineBlock<FeatureId>({ … })`. `S` is what slots are filled
|
|
160
|
+
* with, inferred from `contributes.slots` (a component on native and web).
|
|
161
|
+
*
|
|
162
|
+
* @stability Beta
|
|
163
|
+
*/
|
|
164
|
+
declare function defineBlock<const Id extends string, S = never>(block: BlockDef<Id, S>): BlockDef<Id, S>;
|
|
165
|
+
/** Which blocks are on: ids, a predicate, or (left out) every block given. @stability Beta */
|
|
166
|
+
type EnabledBlocks = Iterable<string> | ((id: string) => boolean);
|
|
167
|
+
/** @stability Beta */
|
|
168
|
+
interface ResolveBlocksOptions {
|
|
169
|
+
/** Keep only blocks that run here. A required block that doesn't is a missing requirement. */
|
|
170
|
+
platform?: FeaturePlatform;
|
|
171
|
+
/**
|
|
172
|
+
* The app's feature registry (`features` from `defineFeatures`): every block
|
|
173
|
+
* id and requirement must be one of its ids.
|
|
174
|
+
*/
|
|
175
|
+
features?: Readonly<Record<string, unknown>>;
|
|
176
|
+
/**
|
|
177
|
+
* A block whose requirement is off: `throw` (default: a set-up mistake, found
|
|
178
|
+
* at launch) or `drop` it, and every block needing it, listing each in
|
|
179
|
+
* `dropped` (for switches that change at run time, such as a tenant turning
|
|
180
|
+
* a feature off).
|
|
181
|
+
*/
|
|
182
|
+
missing?: "throw" | "drop";
|
|
183
|
+
/**
|
|
184
|
+
* The host's slot names (e.g. `GenesisNativeApp`'s). A block filling any
|
|
185
|
+
* other slot is an error, so a typo doesn't fill nothing silently.
|
|
186
|
+
*/
|
|
187
|
+
slots?: readonly string[];
|
|
188
|
+
}
|
|
189
|
+
/** A contribution with the FeatureId of the block it came from. @stability Beta */
|
|
190
|
+
type Contributed<T, Id extends string = string> = T & {
|
|
191
|
+
readonly feature: Id;
|
|
192
|
+
};
|
|
193
|
+
/** @stability Beta */
|
|
194
|
+
interface ResolvedBlocks<B extends BlockDef<string, unknown> = BlockDef> {
|
|
195
|
+
/** The enabled blocks, in dependency order (a block after what it requires). */
|
|
196
|
+
readonly blocks: readonly B[];
|
|
197
|
+
readonly ids: ReadonlySet<B["id"]>;
|
|
198
|
+
has(id: string): boolean;
|
|
199
|
+
/** One block's contributions, or `undefined` when it isn't on. */
|
|
200
|
+
contributionsOf(id: B["id"]): NonNullable<B["contributes"]> | undefined;
|
|
201
|
+
/** Nav entries by `order`, then block order. Place them in the app's tree by `feature` and `id`. */
|
|
202
|
+
readonly nav: readonly Contributed<BlockNavItem, B["id"]>[];
|
|
203
|
+
/** Settings rows by `order`, then block order. */
|
|
204
|
+
readonly settings: readonly Contributed<BlockSettingsRow, B["id"]>[];
|
|
205
|
+
readonly routes: readonly Contributed<BlockRoute, B["id"]>[];
|
|
206
|
+
/** Slot fills by slot name. Two blocks filling one slot is an error. */
|
|
207
|
+
readonly slots: Readonly<Record<string, SlotOf<B>>>;
|
|
208
|
+
readonly migrations: readonly Contributed<BlockMigration, B["id"]>[];
|
|
209
|
+
readonly skills: readonly Contributed<{
|
|
210
|
+
path: string;
|
|
211
|
+
}, B["id"]>[];
|
|
212
|
+
readonly privacy: readonly Contributed<BlockPrivacy, B["id"]>[];
|
|
213
|
+
/** With `missing: "drop"`: blocks left out, and the requirements that were off. */
|
|
214
|
+
readonly dropped: readonly {
|
|
215
|
+
id: B["id"];
|
|
216
|
+
missing: readonly string[];
|
|
217
|
+
}[];
|
|
218
|
+
}
|
|
219
|
+
type SlotOf<B> = B extends BlockDef<string, infer S> ? S : never;
|
|
220
|
+
/**
|
|
221
|
+
* The blocks that are on, checked and merged:
|
|
222
|
+
*
|
|
223
|
+
* - every block is valid ({@link defineBlock}'s checks, for blocks built by hand) and its id is unique;
|
|
224
|
+
* - `requires` has no cycles, and with `features`, names real features;
|
|
225
|
+
* - every enabled block's requirements are on (see {@link ResolveBlocksOptions.missing});
|
|
226
|
+
* - no two enabled blocks contribute the same nav id, settings row id, route path or slot.
|
|
227
|
+
*
|
|
228
|
+
* `enabled` left out means every block given is on (and no app feature that
|
|
229
|
+
* isn't a block). Throws a {@link BlockError} listing every problem at once.
|
|
230
|
+
*
|
|
231
|
+
* @stability Beta
|
|
232
|
+
*/
|
|
233
|
+
declare function resolveBlocks<B extends BlockDef<string, unknown>>(blocks: readonly B[], enabled?: EnabledBlocks, options?: ResolveBlocksOptions): ResolvedBlocks<B>;
|
|
234
|
+
|
|
235
|
+
export { type BlockContributions, type BlockDataUse, type BlockDef, BlockError, type BlockMigration, type BlockNavItem, type BlockPrivacy, type BlockRoute, type BlockSettingsRow, type Contributed, type EnabledBlocks, FeaturePlatform, type ResolveBlocksOptions, type ResolvedBlocks, defineBlock, resolveBlocks };
|
package/dist/blocks.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"blocks.js"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/graph.ts
|
|
2
|
+
function requiresProblems(nodes, options) {
|
|
3
|
+
const { skip = /* @__PURE__ */ new Set() } = options;
|
|
4
|
+
const problems = [];
|
|
5
|
+
for (const [id, node] of Object.entries(nodes)) {
|
|
6
|
+
if (skip.has(id)) continue;
|
|
7
|
+
for (const req of node.requires ?? []) {
|
|
8
|
+
const problem = requirementProblem(nodes, id, req, options);
|
|
9
|
+
if (problem) problems.push(problem);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return [...problems, ...cycleProblems(nodes, skip)];
|
|
13
|
+
}
|
|
14
|
+
function requirementProblem(nodes, id, req, options) {
|
|
15
|
+
const known = options.isKnown ?? ((r) => Object.hasOwn(nodes, r));
|
|
16
|
+
if (req === id) return `${id}.requires: a ${options.noun} can't require itself`;
|
|
17
|
+
if (!known(req)) return `${id}.requires: ${options.unknown ? options.unknown(req, id) : `"${req}" is not a ${options.noun}`}`;
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
function cycleProblems(nodes, skip = /* @__PURE__ */ new Set()) {
|
|
21
|
+
const has = (id) => Object.hasOwn(nodes, id);
|
|
22
|
+
const problems = [];
|
|
23
|
+
const state = /* @__PURE__ */ new Map();
|
|
24
|
+
const visit = (id, path) => {
|
|
25
|
+
state.set(id, "open");
|
|
26
|
+
if (skip.has(id)) return;
|
|
27
|
+
for (const req of nodes[id]?.requires ?? []) {
|
|
28
|
+
if (!has(req) || req === id) continue;
|
|
29
|
+
if (state.get(req) === "open") problems.push(`${id}.requires: a cycle: ${[...path.slice(path.indexOf(req)), id, req].join(" \u2192 ")}`);
|
|
30
|
+
else if (!state.has(req)) visit(req, [...path, id]);
|
|
31
|
+
}
|
|
32
|
+
state.set(id, "done");
|
|
33
|
+
};
|
|
34
|
+
for (const id of Object.keys(nodes)) if (!state.has(id)) visit(id, []);
|
|
35
|
+
return problems;
|
|
36
|
+
}
|
|
37
|
+
function dependencyOrder(nodes) {
|
|
38
|
+
const order = [];
|
|
39
|
+
const seen = /* @__PURE__ */ new Set();
|
|
40
|
+
const visit = (id) => {
|
|
41
|
+
if (seen.has(id)) return;
|
|
42
|
+
seen.add(id);
|
|
43
|
+
for (const req of nodes[id]?.requires ?? []) if (Object.hasOwn(nodes, req)) visit(req);
|
|
44
|
+
order.push(id);
|
|
45
|
+
};
|
|
46
|
+
for (const id of Object.keys(nodes)) visit(id);
|
|
47
|
+
return order;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/platforms.ts
|
|
51
|
+
var FEATURE_PLATFORMS = ["web", "native", "server", "cli"];
|
|
52
|
+
|
|
53
|
+
export { FEATURE_PLATFORMS, cycleProblems, dependencyOrder, requirementProblem, requiresProblems };
|
|
54
|
+
//# sourceMappingURL=chunk-2ARZER3G.js.map
|
|
55
|
+
//# sourceMappingURL=chunk-2ARZER3G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/graph.ts","../src/platforms.ts"],"names":[],"mappings":";AA6BO,SAAS,gBAAA,CAAiB,OAA+C,OAAA,EAA4C;AAC1H,EAAA,MAAM,EAAE,IAAA,mBAAO,IAAI,GAAA,IAAc,GAAI,OAAA;AACrC,EAAA,MAAM,WAAqB,EAAC;AAC5B,EAA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A,IAAI,IAAA,CAAK,GAAA,CAAI,EAAE,CAAA,EAAG;AAClB,IAAA,IAAA,CAAK,IAAI,EAAE,CAAA;AACX,IAAA,KAAA,MAAW,GAAA,IAAO,KAAA,CAAM,EAAE,CAAA,EAAG,YAAY,EAAC,EAAG,IAAI,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,GAAG,CAAA,QAAS,GAAG,CAAA;AACrF,IAAA,KAAA,CAAM,KAAK,EAAE,CAAA;AAAA,EACf,CAAA;AACA,EAAA,KAAA,MAAW,MAAM,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,QAAS,EAAE,CAAA;AAC7C,EAAA,OAAO,KAAA;AACT;;;ACrFO,IAAM,iBAAA,GAAoB,CAAC,KAAA,EAAO,QAAA,EAAU,UAAU,KAAK","file":"chunk-2ARZER3G.js","sourcesContent":["/**\n * The `requires` graph checks shared by the feature registry\n * (`defineFeatures`) and blocks (`resolveBlocks`). No zod here: blocks import\n * this from a platform-neutral entry that ships to phones.\n */\n\n/** A node with the ids it needs. */\nexport interface RequiresNode {\n readonly requires?: readonly string[];\n}\n\nexport interface RequiresProblemsOptions {\n /** What a node is called in messages: `feature` or `block`. */\n noun: string;\n /** Whether an id may be required. Default: it is a node of the graph. */\n isKnown?: (id: string) => boolean;\n /** The message for a requirement `isKnown` refuses. Default `\"x\" is not a <noun>`. */\n unknown?: (req: string, id: string) => string;\n /** Nodes already reported invalid: their edges can't be trusted, so they are skipped. */\n skip?: ReadonlySet<string>;\n}\n\n/**\n * Self-requirements, unknown requirements and cycles through `requires`, as\n * problem strings (`a.requires: …`). Each cycle is reported once, from where\n * the depth-first search found it: `a.requires: a cycle: a → b → a`.\n *\n * @stability Beta\n */\nexport function requiresProblems(nodes: Readonly<Record<string, RequiresNode>>, options: RequiresProblemsOptions): string[] {\n const { skip = new Set<string>() } = options;\n const problems: string[] = [];\n for (const [id, node] of Object.entries(nodes)) {\n if (skip.has(id)) continue;\n for (const req of node.requires ?? []) {\n const problem = requirementProblem(nodes, id, req, options);\n if (problem) problems.push(problem);\n }\n }\n return [...problems, ...cycleProblems(nodes, skip)];\n}\n\n/** One requirement's problem (itself, or an unknown id), or undefined when it is fine. @stability Beta */\nexport function requirementProblem(\n nodes: Readonly<Record<string, RequiresNode>>,\n id: string,\n req: string,\n options: RequiresProblemsOptions,\n): string | undefined {\n const known = options.isKnown ?? ((r: string) => Object.hasOwn(nodes, r));\n if (req === id) return `${id}.requires: a ${options.noun} can't require itself`;\n if (!known(req)) return `${id}.requires: ${options.unknown ? options.unknown(req, id) : `\"${req}\" is not a ${options.noun}`}`;\n return undefined;\n}\n\n/** Cycles through `requires`, each reported once, from where the depth-first search found it. @stability Beta */\nexport function cycleProblems(nodes: Readonly<Record<string, RequiresNode>>, skip: ReadonlySet<string> = new Set()): string[] {\n const has = (id: string) => Object.hasOwn(nodes, id);\n const problems: string[] = [];\n const state = new Map<string, \"open\" | \"done\">();\n const visit = (id: string, path: string[]): void => {\n state.set(id, \"open\");\n if (skip.has(id)) return;\n for (const req of nodes[id]?.requires ?? []) {\n if (!has(req) || req === id) continue;\n if (state.get(req) === \"open\") problems.push(`${id}.requires: a cycle: ${[...path.slice(path.indexOf(req)), id, req].join(\" → \")}`);\n else if (!state.has(req)) visit(req, [...path, id]);\n }\n state.set(id, \"done\");\n };\n for (const id of Object.keys(nodes)) if (!state.has(id)) visit(id, []);\n return problems;\n}\n\n/**\n * The ids in dependency order (what a node requires comes first), ties kept\n * in the given order. Requirements outside `nodes` are ignored. Assumes no\n * cycles ({@link requiresProblems} reports them).\n */\nexport function dependencyOrder(nodes: Readonly<Record<string, RequiresNode>>): string[] {\n const order: string[] = [];\n const seen = new Set<string>();\n const visit = (id: string) => {\n if (seen.has(id)) return;\n seen.add(id);\n for (const req of nodes[id]?.requires ?? []) if (Object.hasOwn(nodes, req)) visit(req);\n order.push(id);\n };\n for (const id of Object.keys(nodes)) visit(id);\n return order;\n}\n","/**\n * Where a feature runs. `server` covers Node, edge functions and the database.\n *\n * @stability Beta\n */\nexport const FEATURE_PLATFORMS = [\"web\", \"native\", \"server\", \"cli\"] as const;\n\n/** @stability Beta */\nexport type FeaturePlatform = (typeof FEATURE_PLATFORMS)[number];\n"]}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { requirementProblem, cycleProblems, dependencyOrder, FEATURE_PLATFORMS } from './chunk-2ARZER3G.js';
|
|
2
|
+
|
|
3
|
+
// src/blocks.ts
|
|
4
|
+
var BlockError = class extends Error {
|
|
5
|
+
constructor(problems) {
|
|
6
|
+
super(`Invalid blocks:
|
|
7
|
+
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
8
|
+
this.problems = problems;
|
|
9
|
+
this.name = "BlockError";
|
|
10
|
+
}
|
|
11
|
+
problems;
|
|
12
|
+
};
|
|
13
|
+
var ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
14
|
+
var CONTRIBUTION_KEYS = ["nav", "settings", "routes", "slots", "migrations", "skills", "privacy"];
|
|
15
|
+
function duplicates(values) {
|
|
16
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17
|
+
const dup = /* @__PURE__ */ new Set();
|
|
18
|
+
for (const v of values) (seen.has(v) ? dup : seen).add(v);
|
|
19
|
+
return [...dup];
|
|
20
|
+
}
|
|
21
|
+
function blockProblems(block) {
|
|
22
|
+
const { id } = block;
|
|
23
|
+
const problems = [];
|
|
24
|
+
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 .`);
|
|
25
|
+
for (const req of block.requires ?? []) {
|
|
26
|
+
if (req === id) problems.push(`${id}.requires: a block can't require itself`);
|
|
27
|
+
else if (!ID.test(req)) problems.push(`${id}.requires: "${req}" is not a feature id`);
|
|
28
|
+
}
|
|
29
|
+
for (const p of block.platforms ?? []) {
|
|
30
|
+
if (!FEATURE_PLATFORMS.includes(p)) problems.push(`${id}.platforms: "${p}" is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
31
|
+
}
|
|
32
|
+
if (block.platforms && block.platforms.length === 0) problems.push(`${id}.platforms: an empty list runs nowhere; leave it out for every platform`);
|
|
33
|
+
const c = block.contributes ?? {};
|
|
34
|
+
for (const key of Object.keys(c)) {
|
|
35
|
+
if (!CONTRIBUTION_KEYS.includes(key)) problems.push(`${id}.contributes.${key}: not a contribution (${CONTRIBUTION_KEYS.join(", ")})`);
|
|
36
|
+
}
|
|
37
|
+
for (const d of duplicates((c.nav ?? []).map((n) => n.id))) problems.push(`${id}.contributes.nav: "${d}" appears twice`);
|
|
38
|
+
for (const d of duplicates((c.settings ?? []).map((r) => r.id))) problems.push(`${id}.contributes.settings: "${d}" appears twice`);
|
|
39
|
+
for (const d of duplicates((c.routes ?? []).map((r) => r.path))) problems.push(`${id}.contributes.routes: "${d}" appears twice`);
|
|
40
|
+
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`);
|
|
41
|
+
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`);
|
|
42
|
+
for (const m of c.migrations ?? []) if (!m.package || !m.file) problems.push(`${id}.contributes.migrations: every migration needs a package and a file`);
|
|
43
|
+
return problems;
|
|
44
|
+
}
|
|
45
|
+
function defineBlock(block) {
|
|
46
|
+
const problems = blockProblems(block);
|
|
47
|
+
if (problems.length) throw new BlockError(problems);
|
|
48
|
+
return Object.freeze(block);
|
|
49
|
+
}
|
|
50
|
+
function enabledPredicate(enabled) {
|
|
51
|
+
if (enabled === void 0) return void 0;
|
|
52
|
+
if (typeof enabled === "function") return enabled;
|
|
53
|
+
const set = new Set(enabled);
|
|
54
|
+
return (id) => set.has(id);
|
|
55
|
+
}
|
|
56
|
+
var byOrder = (items) => items.sort((a, b) => (a.item.order ?? 0) - (b.item.order ?? 0) || a.at - b.at).map((x) => x.item);
|
|
57
|
+
function resolveBlocks(blocks, enabled, options = {}) {
|
|
58
|
+
const { platform, features, missing = "throw", slots: slotNames } = options;
|
|
59
|
+
const problems = [];
|
|
60
|
+
const byId = /* @__PURE__ */ new Map();
|
|
61
|
+
for (const block of blocks) {
|
|
62
|
+
problems.push(...blockProblems(block));
|
|
63
|
+
if (byId.has(block.id)) problems.push(`${block.id}: two blocks have this id`);
|
|
64
|
+
else byId.set(block.id, block);
|
|
65
|
+
}
|
|
66
|
+
const isFeature = features ? (id) => Object.hasOwn(features, id) : void 0;
|
|
67
|
+
if (isFeature) {
|
|
68
|
+
for (const id of byId.keys()) if (!isFeature(id)) problems.push(`${id}: not a feature in the registry`);
|
|
69
|
+
}
|
|
70
|
+
const graph = Object.fromEntries([...byId].map(([id, b]) => [id, { requires: b.requires }]));
|
|
71
|
+
const known = { noun: "block", isKnown: (req) => byId.has(req) || !isFeature || isFeature(req) };
|
|
72
|
+
for (const [id, node] of Object.entries(graph)) {
|
|
73
|
+
for (const req of node.requires ?? []) {
|
|
74
|
+
if (req !== id && requirementProblem(graph, id, req, known)) problems.push(`${id}.requires: "${req}" is neither a block nor a feature in the registry`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
problems.push(...cycleProblems(graph));
|
|
78
|
+
if (problems.length) throw new BlockError(problems);
|
|
79
|
+
const isOn = enabledPredicate(enabled);
|
|
80
|
+
const runsHere = (b) => !platform || !b.platforms || b.platforms.includes(platform);
|
|
81
|
+
const active = /* @__PURE__ */ new Set();
|
|
82
|
+
for (const [id, b] of byId) if ((!isOn || isOn(id)) && runsHere(b)) active.add(id);
|
|
83
|
+
const order = dependencyOrder(graph);
|
|
84
|
+
const dropped = [];
|
|
85
|
+
for (const id of order) {
|
|
86
|
+
if (!active.has(id)) continue;
|
|
87
|
+
const off = (byId.get(id).requires ?? []).filter((req) => {
|
|
88
|
+
if (byId.has(req)) return !active.has(req);
|
|
89
|
+
return !isOn || !isOn(req);
|
|
90
|
+
});
|
|
91
|
+
if (!off.length) continue;
|
|
92
|
+
if (missing === "drop") {
|
|
93
|
+
active.delete(id);
|
|
94
|
+
dropped.push({ id, missing: off });
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
for (const req of off) {
|
|
98
|
+
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";
|
|
99
|
+
problems.push(`${id}.requires: "${req}" ${why}; turn it on or turn ${id} off`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (problems.length) throw new BlockError(problems);
|
|
103
|
+
const on = order.filter((id) => active.has(id)).map((id) => byId.get(id));
|
|
104
|
+
const nav = [];
|
|
105
|
+
const settings = [];
|
|
106
|
+
const routes = [];
|
|
107
|
+
const migrations = [];
|
|
108
|
+
const skills = [];
|
|
109
|
+
const privacy = [];
|
|
110
|
+
const slots = {};
|
|
111
|
+
const owner = { nav: /* @__PURE__ */ new Map(), settings: /* @__PURE__ */ new Map(), routes: /* @__PURE__ */ new Map(), slots: /* @__PURE__ */ new Map() };
|
|
112
|
+
const claim = (kind, key, id, what) => {
|
|
113
|
+
const first = owner[kind].get(key);
|
|
114
|
+
if (first !== void 0) problems.push(`${id}.contributes.${kind}: ${what} "${key}" is already contributed by ${first}`);
|
|
115
|
+
else owner[kind].set(key, id);
|
|
116
|
+
return first === void 0;
|
|
117
|
+
};
|
|
118
|
+
on.forEach((block, at) => {
|
|
119
|
+
const feature = block.id;
|
|
120
|
+
const c = block.contributes ?? {};
|
|
121
|
+
for (const n of c.nav ?? []) if (claim("nav", n.id, feature, "the nav entry")) nav.push({ item: { ...n, feature }, at });
|
|
122
|
+
for (const r of c.settings ?? []) if (claim("settings", r.id, feature, "the settings row")) settings.push({ item: { ...r, feature }, at });
|
|
123
|
+
for (const r of c.routes ?? []) if (claim("routes", r.path, feature, "the route")) routes.push({ ...r, feature });
|
|
124
|
+
for (const [name, fill] of Object.entries(c.slots ?? {})) {
|
|
125
|
+
if (slotNames && !slotNames.includes(name)) {
|
|
126
|
+
problems.push(`${feature}.contributes.slots: "${name}" is not a slot here (${slotNames.join(", ")})`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (claim("slots", name, feature, "the slot")) slots[name] = fill;
|
|
130
|
+
}
|
|
131
|
+
for (const m of c.migrations ?? []) migrations.push({ ...m, feature });
|
|
132
|
+
for (const path of c.skills ?? []) skills.push({ path, feature });
|
|
133
|
+
if (c.privacy) privacy.push({ ...c.privacy, feature });
|
|
134
|
+
});
|
|
135
|
+
if (problems.length) throw new BlockError(problems);
|
|
136
|
+
const ids = new Set(on.map((b) => b.id));
|
|
137
|
+
return Object.freeze({
|
|
138
|
+
blocks: Object.freeze(on),
|
|
139
|
+
ids,
|
|
140
|
+
has: (id) => ids.has(id),
|
|
141
|
+
contributionsOf: (id) => ids.has(id) ? byId.get(id).contributes ?? {} : void 0,
|
|
142
|
+
nav: Object.freeze(byOrder(nav)),
|
|
143
|
+
settings: Object.freeze(byOrder(settings)),
|
|
144
|
+
routes: Object.freeze(routes),
|
|
145
|
+
slots: Object.freeze(slots),
|
|
146
|
+
migrations: Object.freeze(migrations),
|
|
147
|
+
skills: Object.freeze(skills),
|
|
148
|
+
privacy: Object.freeze(privacy),
|
|
149
|
+
dropped: Object.freeze(dropped)
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { BlockError, defineBlock, resolveBlocks };
|
|
154
|
+
//# sourceMappingURL=chunk-EF72JS5S.js.map
|
|
155
|
+
//# sourceMappingURL=chunk-EF72JS5S.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/blocks.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,CA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AO,MAAA,CAAO,OAAA,CAAQ,QAAQ,CAAC,CAAA;AAAA,IACzC,MAAA,EAAQ,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AAAA,IAC5B,KAAA,EAAO,MAAA,CAAO,MAAA,CAAO,KAAK,CAAA;AAAA,IAC1B,UAAA,EAAY,MAAA,CAAO,MAAA,CAAO,UAAU,CAAA;AAAA,IACpC,MAAA,EAAQ,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AAAA,IAC5B,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA;AAAA,IAC9B,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,OAAO;AAAA,GAC/B,CAAA;AACH","file":"chunk-EF72JS5S.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"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { FEATURE_PLATFORMS, requirementProblem, cycleProblems } from './chunk-2ARZER3G.js';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
|
|
3
|
-
// src/model.ts
|
|
4
4
|
var FEATURE_STATUSES = ["idea", "planned", "building", "beta", "live", "deprecated", "retired"];
|
|
5
5
|
var FEATURE_HORIZONS = ["now", "next", "later"];
|
|
6
|
-
var FEATURE_PLATFORMS = ["web", "native", "server", "cli"];
|
|
7
6
|
var FEATURE_LAYERS = ["token", "primitive", "pattern", "layout", "hook", "provider", "block", "service", "tool"];
|
|
8
7
|
var FLAG_KINDS = ["release", "experiment", "ops", "permission"];
|
|
9
8
|
var ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
@@ -127,25 +126,14 @@ function relationProblems(features, skip) {
|
|
|
127
126
|
else if (!has(def.extends)) problems.push(`${id}.extends: "${def.extends}" is not a feature`);
|
|
128
127
|
}
|
|
129
128
|
for (const req of def.requires ?? []) {
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
const problem = requirementProblem(features, id, req, { noun: "feature" });
|
|
130
|
+
if (problem) problems.push(problem);
|
|
132
131
|
else if (!skip.has(req) && (def.status === "beta" || def.status === "live") && UNSHIPPED.includes(features[req].status)) {
|
|
133
132
|
problems.push(`${id}.requires: a ${def.status} feature can't require "${req}", which is ${features[req].status}`);
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
|
-
|
|
138
|
-
const visit = (id, path) => {
|
|
139
|
-
state.set(id, "open");
|
|
140
|
-
if (skip.has(id)) return;
|
|
141
|
-
for (const req of features[id]?.requires ?? []) {
|
|
142
|
-
if (!has(req) || req === id) continue;
|
|
143
|
-
if (state.get(req) === "open") problems.push(`${id}.requires: a cycle: ${[...path.slice(path.indexOf(req)), id, req].join(" \u2192 ")}`);
|
|
144
|
-
else if (!state.has(req)) visit(req, [...path, id]);
|
|
145
|
-
}
|
|
146
|
-
state.set(id, "done");
|
|
147
|
-
};
|
|
148
|
-
for (const id of Object.keys(features)) if (!state.has(id)) visit(id, []);
|
|
136
|
+
problems.push(...cycleProblems(features, skip));
|
|
149
137
|
return problems;
|
|
150
138
|
}
|
|
151
139
|
function defineFlags(features, flags) {
|
|
@@ -387,6 +375,6 @@ description: Find, add, change and retire this repo's features in ${source}, and
|
|
|
387
375
|
`;
|
|
388
376
|
}
|
|
389
377
|
|
|
390
|
-
export { AGENTS_BLOCK_END, AGENTS_BLOCK_START, BrokenBlockError, FEATURE_HORIZONS, FEATURE_LAYERS,
|
|
391
|
-
//# sourceMappingURL=chunk-
|
|
392
|
-
//# sourceMappingURL=chunk-
|
|
378
|
+
export { AGENTS_BLOCK_END, AGENTS_BLOCK_START, BrokenBlockError, FEATURE_HORIZONS, FEATURE_LAYERS, FEATURE_STATUSES, FLAG_KINDS, FeatureRegistryError, MARKETING_BLOCK_END, MARKETING_BLOCK_START, OPENFEATURE_MANIFEST_SCHEMA, defineFeatures, defineFlags, expiredFlags, featureSchema, findFeatures, flagSchema, flagsForFeature, marketingRecords, readAgentsBlock, readBlock, replaceAgentsBlock, replaceBlock, statusOn, toAgentsMarkdown, toJson, toMarketingMarkdown, toOpenFeatureManifest, toRecords, toSkillMarkdown };
|
|
379
|
+
//# sourceMappingURL=chunk-KCUQY5UZ.js.map
|
|
380
|
+
//# sourceMappingURL=chunk-KCUQY5UZ.js.map
|